initial implementation of wxAboutBox()
[wxWidgets.git] / src / generic / aboutdlgg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/aboutdlgg.cpp
3 // Purpose: implements wxGenericAboutBox() function
4 // Author: Vadim Zeitlin
5 // Created: 2006-10-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_ABOUTDLG
27
28 #ifndef WX_PRECOMP
29 #include "wx/sizer.h"
30
31 #include "wx/statbmp.h"
32 #include "wx/stattext.h"
33 #endif //WX_PRECOMP
34
35 #include "wx/aboutdlg.h"
36 #include "wx/generic/aboutdlgg.h"
37
38 #include "wx/hyperlink.h"
39
40 // ============================================================================
41 // wxAboutDialog implementation
42 // ============================================================================
43
44 bool wxAboutDialog::Create(const wxAboutDialogInfo& info)
45 {
46 // TODO: should we use main frame as parent by default here?
47 if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName()) )
48 return false;
49
50 m_sizerText = new wxBoxSizer(wxVERTICAL);
51 wxString nameAndVersion = info.GetName();
52 if ( info.HasVersion() )
53 nameAndVersion << _T(' ') << info.GetVersion();
54 wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
55 wxFont fontBig(*wxNORMAL_FONT);
56 fontBig.SetPointSize(fontBig.GetPointSize() + 2);
57 fontBig.SetWeight(wxFONTWEIGHT_BOLD);
58 label->SetFont(fontBig);
59
60 m_sizerText->Add(label, wxSizerFlags().Centre().Border());
61 m_sizerText->AddSpacer(5);
62
63 AddText(info.GetCopyright());
64 AddText(info.GetDescription());
65
66 if ( info.HasWebSite() )
67 {
68 #if wxUSE_HYPERLINKCTRL
69 AddControl(new wxHyperlinkCtrl(this, wxID_ANY,
70 info.GetWebSiteDescription(),
71 info.GetWebSiteURL()));
72 #else
73 AddText(info.GetWebSiteURL());
74 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
75 }
76
77 // TODO: add licence
78
79 // TODO: add credits (developers, artists, doc writers, translators)
80
81
82 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
83 #if wxUSE_STATBMP
84 if ( info.HasIcon() )
85 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, info.GetIcon()));
86 #endif // wxUSE_STATBMP
87 sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand());
88
89 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
90 sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border());
91 sizerTop->Add(new wxButton(this, wxID_OK), wxSizerFlags().Right().Border());
92 SetSizerAndFit(sizerTop);
93
94 CentreOnScreen();
95 return true;
96 }
97
98 void wxAboutDialog::AddControl(wxWindow *win)
99 {
100 wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
101 wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
102
103 m_sizerText->Add(win, wxSizerFlags().Border(wxDOWN).Centre());
104 }
105
106 void wxAboutDialog::AddText(const wxString& text)
107 {
108 if ( !text.empty() )
109 AddControl(new wxStaticText(this, wxID_ANY, text));
110 }
111
112 // ----------------------------------------------------------------------------
113 // public functions
114 // ----------------------------------------------------------------------------
115
116 void wxGenericAboutBox(const wxAboutDialogInfo& info)
117 {
118 wxAboutDialog dlg(info);
119 dlg.ShowModal();
120 }
121
122 // currently wxAboutBox is implemented natively only under wxMSW, so we provide
123 // it here for the other platforms (this is going to change when GTK+ and Mac
124 // native versions are implemented)
125 #ifndef __WXMSW__
126
127 void wxAboutBox(const wxAboutDialogInfo& info)
128 {
129 wxGenericAboutBox(info);
130 }
131
132 #endif // platforms without native about dialog
133
134
135 #endif // wxUSE_ABOUTDLG