dialog_about.cpp 13.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/***************************************************************
 * Name:      dialog_about.cpp
 * Purpose:   Code for Application Frame
 * Author:    Rafael Sokolowski (rafael.sokolowski@web.de)
 * Created:   2010-08-06
 * Copyright: Rafael Sokolowski ()
 * License:
 **************************************************************/
#include "dialog_about.h"

///////////////////////////////////////////////////////////////////////////////
/// Class dialog_about methods
///////////////////////////////////////////////////////////////////////////////

dialog_about::dialog_about(wxWindow *parent, AboutAppInfo& appInfo)
    : dialog_about_base(parent), info(appInfo)
{
18 19 20 21 22 23
    picInformation = KiBitmap( info_xpm );
    picDevelopers  = KiBitmap( preference_xpm );
    picDocWriters  = KiBitmap( editor_xpm );
    picArtists     = KiBitmap( palette_xpm );
    picTranslators = KiBitmap( language_xpm );
    picLicense     = KiBitmap( tools_xpm );
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

    m_bitmapApp->SetBitmap( info.GetIcon() );

    m_staticTextAppTitle->SetLabel( info.GetAppName() );
    m_staticTextCopyright->SetLabel( info.GetCopyright() );
    m_staticTextBuildVersion->SetLabel( info.GetBuildVersion() );
    m_staticTextLibVersion->SetLabel( info.GetLibVersion() );

    /* Affects m_titlepanel the parent of some wxStaticText.
     * Changing the text afterwards makes it under Windows necessary to call 'Layout()'
     * so that the new text gets properly layout.
     */
/*    m_staticTextCopyright->GetParent()->Layout();
    m_staticTextBuildVersion->GetParent()->Layout();
    m_staticTextLibVersion->GetParent()->Layout();
*/
    DeleteNotebooks();
    CreateNotebooks();
    GetSizer()->SetSizeHints(this);
    m_auiNotebook->Update();
44
    SetFocus();
45 46 47 48 49 50 51 52 53 54 55
    Centre();
}

dialog_about::~dialog_about()
{
}

wxFlexGridSizer* dialog_about::CreateFlexGridSizer()
{
    // three colums with vertical and horizontal extra space of two pixels
    wxFlexGridSizer* fgSizer1 = new wxFlexGridSizer( 3, 2, 2 );
56 57
    fgSizer1->SetFlexibleDirection( wxHORIZONTAL );
    fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    return fgSizer1;
}

void dialog_about::DeleteNotebooks()
{
    for( size_t i=0; i<m_auiNotebook->GetPageCount(); ++i )
        m_auiNotebook->DeletePage(i);
}

void dialog_about::CreateNotebooks()
{
    CreateNotebookHtmlPage( m_auiNotebook, _("Information"), picInformation, info.GetDescription() );

    CreateNotebookPage( m_auiNotebook, _("Developers") , picDevelopers, info.GetDevelopers() );
    CreateNotebookPage( m_auiNotebook, _("Doc Writers"), picDocWriters, info.GetDocWriters() );

    CreateNotebookPageByCategory( m_auiNotebook, _("Artists")    , picArtists,     info.GetArtists() );
    CreateNotebookPageByCategory( m_auiNotebook, _("Translators"), picTranslators, info.GetTranslators() );

    CreateNotebookHtmlPage( m_auiNotebook, _("License"), picLicense, info.GetLicense() );
}

void dialog_about::CreateNotebookPage(wxAuiNotebook* parent, const wxString& caption, const wxBitmap& icon, const Contributors& contributors)
{
    wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );

85 86
    wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
    m_scrolledWindow1->SetScrollRate( 5, 5 );
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

    /* Panel for additional space at the left,
     * but can also be used to show an additional bitmap.
     */
    wxPanel* panel1 = new wxPanel(m_scrolledWindow1);

    wxFlexGridSizer* fgSizer1 = CreateFlexGridSizer();

    for ( size_t i=0; i<contributors.GetCount(); ++i)
    {
        Contributor* contributor = &contributors.Item(i);

        // Icon at first column
        wxStaticBitmap* m_bitmap1 = CreateStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
        fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );

        // Name of contributor at second column
        if ( contributor->GetName() != wxEmptyString )
        {
            wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY, contributor->GetName(), wxDefaultPosition, wxDefaultSize, 0 );
            m_staticText1->Wrap( -1 );
            fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
        }
        else {
            fgSizer1->AddSpacer(5);
        }

        // Email address of contributor at third column
        if ( contributor->GetEMail() != wxEmptyString )
        {
            wxHyperlinkCtrl* hyperlink = CreateHyperlink( m_scrolledWindow1, contributor->GetEMail() );
            fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
        }
        else {
            fgSizer1->AddSpacer(5);
        }
    }

    bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
    bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
    m_scrolledWindow1->SetSizer( bSizer );
128 129
    m_scrolledWindow1->Layout();
    bSizer->Fit( m_scrolledWindow1 );
130

131
    parent->AddPage( m_scrolledWindow1, caption, false, icon );
132 133 134 135 136 137
}

void dialog_about::CreateNotebookPageByCategory(wxAuiNotebook* parent, const wxString& caption, const wxBitmap& icon, const Contributors& contributors)
{
    wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );

138 139
    wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
    m_scrolledWindow1->SetScrollRate( 5, 5 );
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

    /* Panel for additional space at the left,
     * but can also be used to show an additional bitmap.
     */
    wxPanel* panel1 = new wxPanel(m_scrolledWindow1);

    wxFlexGridSizer* fgSizer1 = CreateFlexGridSizer();

    for ( size_t i=0; i<contributors.GetCount(); ++i)
    {
        Contributor* contributor = &contributors.Item(i);

        wxBitmap* icon = contributor->GetIcon();
        wxString category = contributor->GetCategory();

        /* to construct the next row we expect to have
         * a category and a contributor that was not considered up to now
         */
        if ( ( category != wxEmptyString ) && !( contributor->IsChecked() ) )
        {
            // Icon at first column
            wxStaticBitmap* m_bitmap1 = CreateStaticBitmap( m_scrolledWindow1, icon );
            fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );

            // Category name at second column
            wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY, contributor->GetCategory() + wxT(":"), wxDefaultPosition, wxDefaultSize, 0 );
            m_staticText1->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) ); // bold font
            m_staticText1->Wrap( -1 );
            fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );

            // Nothing at third column
            fgSizer1->AddSpacer(5);

            // Now, all contributors of the same category will follow
            for ( size_t j=0; j<contributors.GetCount(); ++j )
            {
                Contributor* contributor = &contributors.Item(j);

                if ( contributor->GetCategory() == category )
                {
                    // First column is empty
                    fgSizer1->AddSpacer(5);

                    // Name of contributor at second column
                    wxStaticText* m_staticText2 = new wxStaticText( m_scrolledWindow1, wxID_ANY, wxT(" • ") + contributor->GetName(), wxDefaultPosition, wxDefaultSize, 0 );
                    m_staticText1->Wrap( -1 );
                    fgSizer1->Add( m_staticText2, 0, wxALIGN_LEFT|wxBOTTOM, 2 );

                    // Email address of contributor at third column
                    if ( contributor->GetEMail() != wxEmptyString )
                    {
                        wxHyperlinkCtrl* hyperlink = CreateHyperlink( m_scrolledWindow1, contributor->GetEMail() );
                        fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
                    }
                    else {
                        fgSizer1->AddSpacer(5);
                    }

                    /* this contributor was added to the gui,
                     * thus can be ignored next time
                     */
                    contributor->SetChecked( true );
                }
            }
        }
        else {
            continue;
        }
    }

    /* Now, lets list the remaining contributors that have not been considered
     * because they were not assigned to any category.
     */
    for ( size_t k=0; k<contributors.GetCount(); ++k )
    {
        Contributor* contributor = &contributors.Item(k);

        if ( contributor->IsChecked() )
            continue;

        // Icon at first column
        wxStaticBitmap* m_bitmap1 = CreateStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
        fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );

        // Name of contributor at second column
        if ( contributor->GetName() != wxEmptyString )
        {
            wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY, contributor->GetName(), wxDefaultPosition, wxDefaultSize, 0 );
            m_staticText1->Wrap( -1 );
            fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
        }
        else {
            fgSizer1->AddSpacer(5);
        }

        // Email address of contributor at third column
        if ( contributor->GetEMail() != wxEmptyString )
        {
            wxHyperlinkCtrl* hyperlink = CreateHyperlink( m_scrolledWindow1, contributor->GetEMail() );
            fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
        }
        else {
            fgSizer1->AddSpacer(5);
        }
    }

    bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
    bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
    m_scrolledWindow1->SetSizer( bSizer );
249 250
    m_scrolledWindow1->Layout();
    bSizer->Fit( m_scrolledWindow1 );
251 252 253 254 255 256 257 258 259 260

    parent->AddPage( m_scrolledWindow1, caption, false, icon );
}

void dialog_about::CreateNotebookHtmlPage(wxAuiNotebook* parent, const wxString& caption, const wxBitmap& icon, const wxString& html)
{
    wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );

    wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );

261
    wxString htmlPage = wxEmptyString, htmlContent = html;
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

    // to have a unique look background color for HTML pages is set to the default as it is used for all the other widgets
    wxString htmlColor = ( this->GetBackgroundColour() ).GetAsString( wxC2S_HTML_SYNTAX );

    // beginning of html structure
    htmlPage.Append( wxT("<html><body bgcolor='") + htmlColor + wxT("'>") );

    htmlPage.Append( htmlContent );

    // end of html structure indicated by closing tags
    htmlPage.Append( wxT("</body></html>") );

    // the html page is going to be created with previously created html content
    wxHtmlWindow* htmlWindow = new wxHtmlWindow( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION );

    // HTML font set to font properties as they are used for widgets to have an unique look under different platforms with HTML
    wxFont font = this->GetFont();
    htmlWindow->SetStandardFonts( font.GetPointSize(), font.GetFaceName(), font.GetFaceName() );
    htmlWindow->SetPage( htmlPage );

    // the HTML window shall not be used to open external links, thus this task is delegated to users default browser
    htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( dialog_about::OnHtmlLinkClicked ), NULL, this );

    // no additional space around the html window as it is also the case by the other notebook pages
    bSizer->Add( htmlWindow, 1, wxALL|wxEXPAND, 0 );
    panel->SetSizer( bSizer );
288 289
    panel->Layout();
    bSizer->Fit( panel );
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

    parent->AddPage( panel, caption, false, icon );
}

wxHyperlinkCtrl* dialog_about::CreateHyperlink(wxScrolledWindow* parent, const wxString& email)
{
    wxHyperlinkCtrl* hyperlink = new wxHyperlinkCtrl(
                                        parent, wxID_ANY,
                                        wxT("<") + email + wxT(">"), /* the label */
                                        wxT("mailto:") + email
                                        + wxT("?subject=KiCad - ")
                                        + info.GetBuildVersion()
                                        + wxT( " ,  ") + info.GetLibVersion()
                                        ); /* the url */

    return hyperlink;
}

wxStaticBitmap* dialog_about::CreateStaticBitmap(wxScrolledWindow* parent, wxBitmap* icon)
{
    wxStaticBitmap* bitmap = new wxStaticBitmap( parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
311 312

    if( icon )
313 314 315
    {
        bitmap->SetBitmap( *icon );
    }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
316 317 318
    else
    {
        bitmap->SetBitmap( KiBitmap( right_xpm ) );
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    }
    return bitmap;
}

///////////////////////////////////////////////////////////////////////////////
/// Event handlers
///////////////////////////////////////////////////////////////////////////////

void dialog_about::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void dialog_about::OnOkClick(wxCommandEvent &event)
{
    Destroy();
}

void dialog_about::OnHtmlLinkClicked( wxHtmlLinkEvent& event )
{
    ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );
}