]>
git.saurik.com Git - wxWidgets.git/blob - samples/artprov/arttest.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxArtProvider sample
4 // Author: Vaclav Slavik
7 // Copyright: (c) Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
22 #ifndef wxHAS_IMAGES_IN_RESOURCES
23 #include "../sample.xpm"
26 #include "wx/artprov.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class MyApp
: public wxApp
36 virtual bool OnInit();
39 class MyFrame
: public wxFrame
42 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
43 long style
= wxDEFAULT_FRAME_STYLE
);
46 // event handlers (these functions should _not_ be virtual)
47 void OnQuit(wxCommandEvent
& event
);
48 void OnAbout(wxCommandEvent
& event
);
50 void OnLogs(wxCommandEvent
& event
);
52 void OnBrowser(wxCommandEvent
& event
);
53 void OnPlugProvider(wxCommandEvent
& event
);
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // IDs for the controls and the menu commands
66 ID_Logs
= wxID_HIGHEST
+1,
71 // ----------------------------------------------------------------------------
72 // event tables and other macros for wxWidgets
73 // ----------------------------------------------------------------------------
75 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
76 EVT_MENU(ID_Quit
, MyFrame::OnQuit
)
78 EVT_MENU(ID_Logs
, MyFrame::OnLogs
)
80 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
81 EVT_MENU(ID_Browser
, MyFrame::OnBrowser
)
82 EVT_MENU(ID_PlugProvider
, MyFrame::OnPlugProvider
)
87 // ============================================================================
89 // ============================================================================
91 // ----------------------------------------------------------------------------
92 // the application class
93 // ----------------------------------------------------------------------------
95 // 'Main program' equivalent: the program execution "starts" here
98 if ( !wxApp::OnInit() )
101 // create the main application window
102 MyFrame
*frame
= new MyFrame(wxT("wxArtProvider sample"),
103 wxPoint(50, 50), wxSize(450, 340));
108 // ----------------------------------------------------------------------------
109 // custom art provider
110 // ----------------------------------------------------------------------------
112 class MyArtProvider
: public wxArtProvider
115 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
121 #include "warning.xpm"
122 #include "question.xpm"
124 wxBitmap
MyArtProvider::CreateBitmap(const wxArtID
& id
,
125 const wxArtClient
& client
,
126 const wxSize
& WXUNUSED(size
))
128 if ( client
== wxART_MESSAGE_BOX
)
130 if ( id
== wxART_INFORMATION
)
131 return wxBitmap(info_xpm
);
132 if ( id
== wxART_ERROR
)
133 return wxBitmap(error_xpm
);
134 if ( id
== wxART_WARNING
)
135 return wxBitmap(warning_xpm
);
136 if ( id
== wxART_QUESTION
)
137 return wxBitmap(question_xpm
);
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
149 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
)
150 : wxFrame(NULL
, wxID_ANY
, title
, pos
, size
, style
)
152 SetIcon(wxICON(sample
));
155 wxMenu
*menuFile
= new wxMenu
;
157 // the "About" item should be in the help menu
158 wxMenu
*helpMenu
= new wxMenu
;
159 helpMenu
->Append(wxID_ABOUT
, wxT("&About\tF1"), wxT("Show about dialog"));
161 menuFile
->AppendCheckItem(ID_PlugProvider
, wxT("&Plug-in art provider"), wxT("Enable custom art provider"));
162 menuFile
->AppendSeparator();
165 menuFile
->Append(ID_Logs
, wxT("&Logging test"), wxT("Show some logging output"));
167 menuFile
->Append(ID_Browser
, wxT("&Resources browser"), wxT("Browse all available icons"));
168 menuFile
->AppendSeparator();
170 menuFile
->Append(ID_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
172 // now append the freshly created menu to the menu bar...
173 wxMenuBar
*menuBar
= new wxMenuBar();
174 menuBar
->Append(menuFile
, wxT("&File"));
175 menuBar
->Append(helpMenu
, wxT("&Help"));
177 // ... and attach this menu bar to the frame
184 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
186 // true is to force the frame to close
191 void MyFrame::OnLogs(wxCommandEvent
& WXUNUSED(event
))
193 wxLogMessage(wxT("Some information."));
194 wxLogError(wxT("This is an error."));
195 wxLogWarning(wxT("A warning."));
196 wxLogError(wxT("Yet another error."));
197 wxLog::GetActiveTarget()->Flush();
198 wxLogMessage(wxT("Check/uncheck 'File/Plug-in art provider' and try again."));
202 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
205 msg
.Printf( wxT("This is the about dialog of wxArtProvider sample.\n")
206 wxT("Welcome to %s"), wxVERSION_STRING
);
208 wxMessageBox(msg
, wxT("About wxArtProvider sample"),
209 wxOK
| wxICON_INFORMATION
, this);
212 void MyFrame::OnBrowser(wxCommandEvent
& WXUNUSED(event
))
214 wxArtBrowserDialog
dlg(this);
218 void MyFrame::OnPlugProvider(wxCommandEvent
& event
)
220 if ( event
.IsChecked() )
221 wxArtProvider::Push(new MyArtProvider
);
223 wxArtProvider::Pop();