]>
git.saurik.com Git - wxWidgets.git/blob - samples/artprov/arttest.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxArtProvider sample
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
24 #include "mondrian.xpm"
27 #include "wx/artprov.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class MyApp
: public wxApp
37 virtual bool OnInit();
40 class MyFrame
: public wxFrame
43 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
44 long style
= wxDEFAULT_FRAME_STYLE
);
47 // event handlers (these functions should _not_ be virtual)
48 void OnQuit(wxCommandEvent
& event
);
49 void OnAbout(wxCommandEvent
& event
);
50 void OnLogs(wxCommandEvent
& event
);
51 void OnBrowser(wxCommandEvent
& event
);
52 void OnPlugProvider(wxCommandEvent
& event
);
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // IDs for the controls and the menu commands
64 ID_Quit
= wxID_HIGHEST
,
70 // ----------------------------------------------------------------------------
71 // event tables and other macros for wxWindows
72 // ----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
75 EVT_MENU(ID_Quit
, MyFrame::OnQuit
)
76 EVT_MENU(ID_Logs
, MyFrame::OnLogs
)
77 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
78 EVT_MENU(ID_Browser
, MyFrame::OnBrowser
)
79 EVT_MENU(ID_PlugProvider
, MyFrame::OnPlugProvider
)
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
89 // the application class
90 // ----------------------------------------------------------------------------
92 // 'Main program' equivalent: the program execution "starts" here
95 // create the main application window
96 MyFrame
*frame
= new MyFrame(_T("wxArtProvider sample"),
97 wxPoint(50, 50), wxSize(450, 340));
102 // ----------------------------------------------------------------------------
103 // custom art provider
104 // ----------------------------------------------------------------------------
106 class MyArtProvider
: public wxArtProvider
109 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
115 #include "warning.xpm"
116 #include "question.xpm"
118 wxBitmap
MyArtProvider::CreateBitmap(const wxArtID
& id
,
119 const wxArtClient
& client
,
120 const wxSize
& WXUNUSED(size
))
122 if ( client
== wxART_MESSAGE_BOX
)
124 if ( id
== wxART_INFORMATION
)
125 return wxBitmap(info_xpm
);
126 if ( id
== wxART_ERROR
)
127 return wxBitmap(error_xpm
);
128 if ( id
== wxART_WARNING
)
129 return wxBitmap(warning_xpm
);
130 if ( id
== wxART_QUESTION
)
131 return wxBitmap(question_xpm
);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
143 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
)
144 : wxFrame(NULL
, -1, title
, pos
, size
, style
)
146 SetIcon(wxICON(mondrian
));
149 wxMenu
*menuFile
= new wxMenu
;
151 // the "About" item should be in the help menu
152 wxMenu
*helpMenu
= new wxMenu
;
153 helpMenu
->Append(wxID_ABOUT
, _T("&About...\tF1"), _T("Show about dialog"));
155 menuFile
->AppendCheckItem(ID_PlugProvider
, _T("&Plug-in art provider"), _T("Enable custom art provider"));
156 menuFile
->AppendSeparator();
158 menuFile
->Append(ID_Logs
, _T("&Logging test"), _T("Show some logging output"));
159 menuFile
->Append(ID_Browser
, _T("&Resources browser"), _T("Browse all available icons"));
160 menuFile
->AppendSeparator();
162 menuFile
->Append(ID_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
164 // now append the freshly created menu to the menu bar...
165 wxMenuBar
*menuBar
= new wxMenuBar();
166 menuBar
->Append(menuFile
, _T("&File"));
167 menuBar
->Append(helpMenu
, _T("&Help"));
169 // ... and attach this menu bar to the frame
176 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
178 // TRUE is to force the frame to close
182 void MyFrame::OnLogs(wxCommandEvent
& WXUNUSED(event
))
184 wxLogMessage(_T("Some information."));
185 wxLogError(_T("This is an error."));
186 wxLogWarning(_T("A warning."));
187 wxLogError(_T("Yet another error."));
188 wxLog::GetActiveTarget()->Flush();
189 wxLogMessage(_T("Check/uncheck 'File/Plug-in art provider' and try again."));
192 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
195 msg
.Printf( _T("This is the about dialog of wxArtProvider sample.\n")
196 _T("Welcome to %s"), wxVERSION_STRING
);
198 wxMessageBox(msg
, _T("About wxArtProvider sample"),
199 wxOK
| wxICON_INFORMATION
, this);
202 void MyFrame::OnBrowser(wxCommandEvent
& WXUNUSED(event
))
204 wxArtBrowserDialog
dlg(this);
208 void MyFrame::OnPlugProvider(wxCommandEvent
& event
)
210 if ( event
.IsChecked() )
211 wxArtProvider::PushProvider(new MyArtProvider
);
213 wxArtProvider::PopProvider();