]>
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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #if !defined(__WXMSW__) && !defined(__WXPM__)
24 #include "../sample.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
);
51 void OnLogs(wxCommandEvent
& event
);
53 void OnBrowser(wxCommandEvent
& event
);
54 void OnPlugProvider(wxCommandEvent
& event
);
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // IDs for the controls and the menu commands
66 ID_Quit
= wxID_HIGHEST
,
72 // ----------------------------------------------------------------------------
73 // event tables and other macros for wxWidgets
74 // ----------------------------------------------------------------------------
76 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
77 EVT_MENU(ID_Quit
, MyFrame::OnQuit
)
79 EVT_MENU(ID_Logs
, MyFrame::OnLogs
)
81 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
82 EVT_MENU(ID_Browser
, MyFrame::OnBrowser
)
83 EVT_MENU(ID_PlugProvider
, MyFrame::OnPlugProvider
)
88 // ============================================================================
90 // ============================================================================
92 // ----------------------------------------------------------------------------
93 // the application class
94 // ----------------------------------------------------------------------------
96 // 'Main program' equivalent: the program execution "starts" here
99 if ( !wxApp::OnInit() )
102 // create the main application window
103 MyFrame
*frame
= new MyFrame(wxT("wxArtProvider sample"),
104 wxPoint(50, 50), wxSize(450, 340));
109 // ----------------------------------------------------------------------------
110 // custom art provider
111 // ----------------------------------------------------------------------------
113 class MyArtProvider
: public wxArtProvider
116 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
122 #include "warning.xpm"
123 #include "question.xpm"
125 wxBitmap
MyArtProvider::CreateBitmap(const wxArtID
& id
,
126 const wxArtClient
& client
,
127 const wxSize
& WXUNUSED(size
))
129 if ( client
== wxART_MESSAGE_BOX
)
131 if ( id
== wxART_INFORMATION
)
132 return wxBitmap(info_xpm
);
133 if ( id
== wxART_ERROR
)
134 return wxBitmap(error_xpm
);
135 if ( id
== wxART_WARNING
)
136 return wxBitmap(warning_xpm
);
137 if ( id
== wxART_QUESTION
)
138 return wxBitmap(question_xpm
);
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
150 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
)
151 : wxFrame(NULL
, wxID_ANY
, title
, pos
, size
, style
)
153 SetIcon(wxICON(sample
));
156 wxMenu
*menuFile
= new wxMenu
;
158 // the "About" item should be in the help menu
159 wxMenu
*helpMenu
= new wxMenu
;
160 helpMenu
->Append(wxID_ABOUT
, wxT("&About\tF1"), wxT("Show about dialog"));
162 menuFile
->AppendCheckItem(ID_PlugProvider
, wxT("&Plug-in art provider"), wxT("Enable custom art provider"));
163 menuFile
->AppendSeparator();
166 menuFile
->Append(ID_Logs
, wxT("&Logging test"), wxT("Show some logging output"));
168 menuFile
->Append(ID_Browser
, wxT("&Resources browser"), wxT("Browse all available icons"));
169 menuFile
->AppendSeparator();
171 menuFile
->Append(ID_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
173 // now append the freshly created menu to the menu bar...
174 wxMenuBar
*menuBar
= new wxMenuBar();
175 menuBar
->Append(menuFile
, wxT("&File"));
176 menuBar
->Append(helpMenu
, wxT("&Help"));
178 // ... and attach this menu bar to the frame
185 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
187 // true is to force the frame to close
192 void MyFrame::OnLogs(wxCommandEvent
& WXUNUSED(event
))
194 wxLogMessage(wxT("Some information."));
195 wxLogError(wxT("This is an error."));
196 wxLogWarning(wxT("A warning."));
197 wxLogError(wxT("Yet another error."));
198 wxLog::GetActiveTarget()->Flush();
199 wxLogMessage(wxT("Check/uncheck 'File/Plug-in art provider' and try again."));
203 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
206 msg
.Printf( wxT("This is the about dialog of wxArtProvider sample.\n")
207 wxT("Welcome to %s"), wxVERSION_STRING
);
209 wxMessageBox(msg
, wxT("About wxArtProvider sample"),
210 wxOK
| wxICON_INFORMATION
, this);
213 void MyFrame::OnBrowser(wxCommandEvent
& WXUNUSED(event
))
215 wxArtBrowserDialog
dlg(this);
219 void MyFrame::OnPlugProvider(wxCommandEvent
& event
)
221 if ( event
.IsChecked() )
222 wxArtProvider::Push(new MyArtProvider
);
224 wxArtProvider::Pop();