]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/artprov/arttest.cpp
add unit test for wxTextCtrl::SetSelection()
[wxWidgets.git] / samples / artprov / arttest.cpp
index 0c8ae43d8e8f6e8a5c94e7b66ccf48b73f7fd5ae..45c5d1f45f5bff99d78e7cd7fbe9026d5d9a23ca 100644 (file)
 #include "wx/wx.h"
 #endif
 
-#ifndef __WXMSW__
+#if !defined(__WXMSW__) && !defined(__WXPM__)
     #include "mondrian.xpm"
 #endif
 
 #include "wx/artprov.h"
+#include "artbrows.h"
 
 // ----------------------------------------------------------------------------
 // private classes
@@ -46,7 +47,11 @@ private:
     // event handlers (these functions should _not_ be virtual)
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
+#if wxUSE_LOG
     void OnLogs(wxCommandEvent& event);
+#endif // wxUSE_LOG
+    void OnBrowser(wxCommandEvent& event);
+    void OnPlugProvider(wxCommandEvent& event);
 
     DECLARE_EVENT_TABLE()
 };
@@ -59,17 +64,23 @@ private:
 enum
 {
     ID_Quit = wxID_HIGHEST,
-    ID_Logs
+    ID_Logs,
+    ID_Browser,
+    ID_PlugProvider
 };
 
 // ----------------------------------------------------------------------------
-// event tables and other macros for wxWindows
+// event tables and other macros for wxWidgets
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
-    EVT_MENU(ID_Quit,    MyFrame::OnQuit)
-    EVT_MENU(ID_Logs,    MyFrame::OnLogs)
-    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
+    EVT_MENU(ID_Quit,         MyFrame::OnQuit)
+#if wxUSE_LOG
+    EVT_MENU(ID_Logs,         MyFrame::OnLogs)
+#endif // wxUSE_LOG
+    EVT_MENU(wxID_ABOUT,      MyFrame::OnAbout)
+    EVT_MENU(ID_Browser,      MyFrame::OnBrowser)
+    EVT_MENU(ID_PlugProvider, MyFrame::OnPlugProvider)
 END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
@@ -85,20 +96,59 @@ IMPLEMENT_APP(MyApp)
 // 'Main program' equivalent: the program execution "starts" here
 bool MyApp::OnInit()
 {
+    if ( !wxApp::OnInit() )
+        return false;
+
     // create the main application window
     MyFrame *frame = new MyFrame(_T("wxArtProvider sample"),
                                  wxPoint(50, 50), wxSize(450, 340));
-    frame->Show(TRUE);
-    return TRUE;
+    frame->Show(true);
+    return true;
+}
+
+// ----------------------------------------------------------------------------
+// custom art provider
+// ----------------------------------------------------------------------------
+
+class MyArtProvider : public wxArtProvider
+{
+protected:
+    virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
+                                  const wxSize& size);
+};
+
+#include "info.xpm"
+#include "error.xpm"
+#include "warning.xpm"
+#include "question.xpm"
+
+wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,
+                                     const wxArtClient& client,
+                                     const wxSize& WXUNUSED(size))
+{
+    if ( client == wxART_MESSAGE_BOX )
+    {
+        if ( id == wxART_INFORMATION )
+            return wxBitmap(info_xpm);
+        if ( id == wxART_ERROR )
+            return wxBitmap(error_xpm);
+        if ( id == wxART_WARNING )
+            return wxBitmap(warning_xpm);
+        if ( id == wxART_QUESTION )
+            return wxBitmap(question_xpm);
+    }
+    return wxNullBitmap;
 }
 
+
+
 // ----------------------------------------------------------------------------
 // main frame
 // ----------------------------------------------------------------------------
 
 // frame constructor
 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
-       : wxFrame(NULL, -1, title, pos, size, style)
+       : wxFrame(NULL, wxID_ANY, title, pos, size, style)
 {
     SetIcon(wxICON(mondrian));
 
@@ -109,9 +159,15 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
     wxMenu *helpMenu = new wxMenu;
     helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show about dialog"));
 
+    menuFile->AppendCheckItem(ID_PlugProvider, _T("&Plug-in art provider"), _T("Enable custom art provider"));
+    menuFile->AppendSeparator();
+
+#if wxUSE_LOG
     menuFile->Append(ID_Logs, _T("&Logging test"), _T("Show some logging output"));
+#endif // wxUSE_LOG
+    menuFile->Append(ID_Browser, _T("&Resources browser"), _T("Browse all available icons"));
     menuFile->AppendSeparator();
-    
+
     menuFile->Append(ID_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
 
     // now append the freshly created menu to the menu bar...
@@ -128,10 +184,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
 
 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 {
-    // TRUE is to force the frame to close
-    Close(TRUE);
+    // true is to force the frame to close
+    Close(true);
 }
 
+#if wxUSE_LOG
 void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
 {
     wxLogMessage(_T("Some information."));
@@ -139,8 +196,9 @@ void MyFrame::OnLogs(wxCommandEvent& WXUNUSED(event))
     wxLogWarning(_T("A warning."));
     wxLogError(_T("Yet another error."));
     wxLog::GetActiveTarget()->Flush();
-    wxLogMessage(_T("Check/uncheck 'File/Plug-in provider' and try again."));
+    wxLogMessage(_T("Check/uncheck 'File/Plug-in art provider' and try again."));
 }
+#endif // wxUSE_LOG
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
@@ -148,5 +206,20 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
     msg.Printf( _T("This is the about dialog of wxArtProvider sample.\n")
                 _T("Welcome to %s"), wxVERSION_STRING);
 
-    wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
+    wxMessageBox(msg, _T("About wxArtProvider sample"),
+        wxOK | wxICON_INFORMATION, this);
+}
+
+void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
+{
+    wxArtBrowserDialog dlg(this);
+    dlg.ShowModal();
+}
+
+void MyFrame::OnPlugProvider(wxCommandEvent& event)
+{
+    if ( event.IsChecked() )
+        wxArtProvider::Push(new MyArtProvider);
+    else
+        wxArtProvider::Pop();
 }