arttest.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: arttest.cpp
  3. // Purpose: wxArtProvider sample
  4. // Author: Vaclav Slavik
  5. // Modified by:
  6. // Created: 2002/03/25
  7. // Copyright: (c) Vaclav Slavik
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // For compilers that support precompilation, includes "wx/wx.h".
  11. #include "wx/wxprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #ifndef WX_PRECOMP
  16. #include "wx/wx.h"
  17. #endif
  18. #ifndef wxHAS_IMAGES_IN_RESOURCES
  19. #include "../sample.xpm"
  20. #endif
  21. #include "wx/artprov.h"
  22. #include "artbrows.h"
  23. // ----------------------------------------------------------------------------
  24. // private classes
  25. // ----------------------------------------------------------------------------
  26. class MyApp : public wxApp
  27. {
  28. public:
  29. virtual bool OnInit();
  30. };
  31. class MyFrame : public wxFrame
  32. {
  33. public:
  34. MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
  35. long style = wxDEFAULT_FRAME_STYLE);
  36. private:
  37. // event handlers (these functions should _not_ be virtual)
  38. void OnQuit(wxCommandEvent& event);
  39. void OnAbout(wxCommandEvent& event);
  40. #if wxUSE_LOG
  41. void OnLogs(wxCommandEvent& event);
  42. #endif // wxUSE_LOG
  43. void OnBrowser(wxCommandEvent& event);
  44. void OnPlugProvider(wxCommandEvent& event);
  45. wxDECLARE_EVENT_TABLE();
  46. };
  47. // ----------------------------------------------------------------------------
  48. // constants
  49. // ----------------------------------------------------------------------------
  50. // IDs for the controls and the menu commands
  51. enum
  52. {
  53. ID_Quit = wxID_EXIT,
  54. ID_Logs = wxID_HIGHEST+1,
  55. ID_Browser,
  56. ID_PlugProvider
  57. };
  58. // ----------------------------------------------------------------------------
  59. // event tables and other macros for wxWidgets
  60. // ----------------------------------------------------------------------------
  61. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  62. EVT_MENU(ID_Quit, MyFrame::OnQuit)
  63. #if wxUSE_LOG
  64. EVT_MENU(ID_Logs, MyFrame::OnLogs)
  65. #endif // wxUSE_LOG
  66. EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
  67. EVT_MENU(ID_Browser, MyFrame::OnBrowser)
  68. EVT_MENU(ID_PlugProvider, MyFrame::OnPlugProvider)
  69. wxEND_EVENT_TABLE()
  70. IMPLEMENT_APP(MyApp)
  71. // ============================================================================
  72. // implementation
  73. // ============================================================================
  74. // ----------------------------------------------------------------------------
  75. // the application class
  76. // ----------------------------------------------------------------------------
  77. // 'Main program' equivalent: the program execution "starts" here
  78. bool MyApp::OnInit()
  79. {
  80. if ( !wxApp::OnInit() )
  81. return false;
  82. // create the main application window
  83. MyFrame *frame = new MyFrame(wxT("wxArtProvider sample"),
  84. wxPoint(50, 50), wxSize(450, 340));
  85. frame->Show(true);
  86. return true;
  87. }
  88. // ----------------------------------------------------------------------------
  89. // custom art provider
  90. // ----------------------------------------------------------------------------
  91. class MyArtProvider : public wxArtProvider
  92. {
  93. protected:
  94. virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
  95. const wxSize& size);
  96. };
  97. #include "info.xpm"
  98. #include "error.xpm"
  99. #include "warning.xpm"
  100. #include "question.xpm"
  101. wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,
  102. const wxArtClient& client,
  103. const wxSize& WXUNUSED(size))
  104. {
  105. if ( client == wxART_MESSAGE_BOX )
  106. {
  107. if ( id == wxART_INFORMATION )
  108. return wxBitmap(info_xpm);
  109. if ( id == wxART_ERROR )
  110. return wxBitmap(error_xpm);
  111. if ( id == wxART_WARNING )
  112. return wxBitmap(warning_xpm);
  113. if ( id == wxART_QUESTION )
  114. return wxBitmap(question_xpm);
  115. }
  116. return wxNullBitmap;
  117. }
  118. // ----------------------------------------------------------------------------
  119. // main frame
  120. // ----------------------------------------------------------------------------
  121. // frame constructor
  122. MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
  123. : wxFrame(NULL, wxID_ANY, title, pos, size, style)
  124. {
  125. SetIcon(wxICON(sample));
  126. // create a menu bar
  127. wxMenu *menuFile = new wxMenu;
  128. // the "About" item should be in the help menu
  129. wxMenu *helpMenu = new wxMenu;
  130. helpMenu->Append(wxID_ABOUT, wxT("&About\tF1"), wxT("Show about dialog"));
  131. menuFile->AppendCheckItem(ID_PlugProvider, wxT("&Plug-in art provider"), wxT("Enable custom art provider"));
  132. menuFile->AppendSeparator();
  133. #if wxUSE_LOG
  134. menuFile->Append(ID_Logs, wxT("&Logging test"), wxT("Show some logging output"));
  135. #endif // wxUSE_LOG
  136. menuFile->Append(ID_Browser, wxT("&Resources browser"), wxT("Browse all available icons"));
  137. menuFile->AppendSeparator();
  138. menuFile->Append(ID_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
  139. // now append the freshly created menu to the menu bar...
  140. wxMenuBar *menuBar = new wxMenuBar();
  141. menuBar->Append(menuFile, wxT("&File"));
  142. menuBar->Append(helpMenu, wxT("&Help"));
  143. // ... and attach this menu bar to the frame
  144. SetMenuBar(menuBar);
  145. }
  146. // event handlers
  147. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  148. {
  149. // true is to force the frame to close
  150. Close(true);
  151. }
  152. #if wxUSE_LOG
  153. void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
  154. {
  155. wxLogMessage(wxT("Some information."));
  156. wxLogError(wxT("This is an error."));
  157. wxLogWarning(wxT("A warning."));
  158. wxLogError(wxT("Yet another error."));
  159. wxLog::GetActiveTarget()->Flush();
  160. wxLogMessage(wxT("Check/uncheck 'File/Plug-in art provider' and try again."));
  161. }
  162. #endif // wxUSE_LOG
  163. void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
  164. {
  165. wxString msg;
  166. msg.Printf( wxT("This is the about dialog of wxArtProvider sample.\n")
  167. wxT("Welcome to %s"), wxVERSION_STRING);
  168. wxMessageBox(msg, wxT("About wxArtProvider sample"),
  169. wxOK | wxICON_INFORMATION, this);
  170. }
  171. void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
  172. {
  173. wxArtBrowserDialog dlg(this);
  174. dlg.ShowModal();
  175. }
  176. void MyFrame::OnPlugProvider(wxCommandEvent& event)
  177. {
  178. if ( event.IsChecked() )
  179. wxArtProvider::Push(new MyArtProvider);
  180. else
  181. wxArtProvider::Pop();
  182. }