]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/render/render.cpp
fixing multilib build
[wxWidgets.git] / samples / render / render.cpp
index 89461121d621222a59c9628ad7ac390a0be8a411..7cb63278bee4df57e1d208d917367c498625b818 100644 (file)
@@ -35,6 +35,7 @@
     #include "wx/log.h"
     #include "wx/msgdlg.h"
     #include "wx/icon.h"
+    #include "wx/image.h"
 #endif
 
 #include "wx/apptrait.h"
@@ -105,7 +106,19 @@ public:
     MyFrame();
     virtual ~MyFrame();
 
+private:
     // event handlers (these functions should _not_ be virtual)
+    void OnDrawDisabled(wxCommandEvent& event)
+        { OnToggleDrawFlag(event, wxCONTROL_DISABLED); }
+    void OnDrawFocused(wxCommandEvent& event)
+        { OnToggleDrawFlag(event, wxCONTROL_FOCUSED); }
+    void OnDrawPressed(wxCommandEvent& event)
+        { OnToggleDrawFlag(event, wxCONTROL_PRESSED); }
+    void OnDrawChecked(wxCommandEvent& event)
+        { OnToggleDrawFlag(event, wxCONTROL_CHECKED); }
+    void OnDrawHot(wxCommandEvent& event)
+        { OnToggleDrawFlag(event, wxCONTROL_CURRENT); }
+
 #if wxUSE_DYNLIB_CLASS
     void OnLoad(wxCommandEvent& event);
     void OnUnload(wxCommandEvent& event);
@@ -113,8 +126,9 @@ public:
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
 
-private:
-    wxPanel *m_panel;
+    void OnToggleDrawFlag(wxCommandEvent& event, int flag);
+
+    class MyPanel *m_panel;
 
     // any class wishing to process wxWidgets events must use this macro
     DECLARE_EVENT_TABLE()
@@ -124,21 +138,87 @@ private:
 class MyPanel : public wxPanel
 {
 public:
-    MyPanel(wxWindow *parent) : wxPanel(parent) { }
+    MyPanel(wxWindow *parent) : wxPanel(parent) { m_flags = 0; }
 
+    int GetFlags() const { return m_flags; }
+    void SetFlags(int flags) { m_flags = flags; }
+
+private:
     void OnPaint(wxPaintEvent&)
     {
         wxPaintDC dc(this);
 
-        dc.DrawText(wxT("Below is the standard header button drawn"), 10, 10);
-        dc.DrawText(wxT("using the current renderer:"), 10, 40);
-
         wxRendererNative& renderer = wxRendererNative::Get();
-        const wxCoord height = renderer.GetHeaderButtonHeight(this);
 
-        renderer.DrawHeaderButton(this, dc, wxRect(20, 70, 100, height));
+        int x1 = 10,    // text offset
+            x2 = 200,   // drawing offset
+            y = 10;
+
+        const int lineHeight = dc.GetCharHeight();
+        dc.DrawText("Demonstration of various wxRenderer functions:", x1, y);
+        y += lineHeight;
+        wxString flagsString;
+        if ( m_flags & wxCONTROL_DISABLED )
+            flagsString += "wxCONTROL_DISABLED ";
+        if ( m_flags & wxCONTROL_FOCUSED )
+            flagsString += "wxCONTROL_FOCUSED ";
+        if ( m_flags & wxCONTROL_PRESSED )
+            flagsString += "wxCONTROL_PRESSED ";
+        if ( m_flags & wxCONTROL_CURRENT )
+            flagsString += "wxCONTROL_CURRENT ";
+        if ( m_flags & wxCONTROL_CHECKED )
+            flagsString += "wxCONTROL_CHECKED ";
+        if ( flagsString.empty() )
+            flagsString = "(none)";
+        dc.DrawText("Using flags: " + flagsString, x1, y);
+        y += lineHeight*3;
+
+        dc.DrawText("DrawHeaderButton() (overridden)", x1, y);
+        const wxCoord heightHdr = renderer.GetHeaderButtonHeight(this);
+        renderer.DrawHeaderButton(this, dc,
+                                  wxRect(x2, y, 100, heightHdr), m_flags);
+        y += lineHeight + heightHdr;
+
+        dc.DrawText("DrawCheckBox()", x1, y);
+        const wxSize sizeCheck = renderer.GetCheckBoxSize(this);
+        renderer.DrawCheckBox(this, dc,
+                              wxRect(wxPoint(x2, y), sizeCheck), m_flags);
+        y += lineHeight + sizeCheck.y;
+
+        dc.DrawText("DrawRadioBitmap()", x1, y);
+        renderer.DrawRadioBitmap(this, dc,
+                                 wxRect(wxPoint(x2, y), sizeCheck), m_flags);
+        y += lineHeight + sizeCheck.y;
+
+        dc.DrawText("DrawTreeItemButton()", x1, y);
+        renderer.DrawTreeItemButton(this, dc,
+                                    wxRect(x2, y, 20, 20), m_flags);
+        y += lineHeight + 20;
+
+#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
+        dc.DrawText("DrawTitleBarBitmap()", x1, y);
+        wxRect rBtn(x2, y, 21, 21);
+        renderer.DrawTitleBarBitmap(this, dc, rBtn,
+                                    wxTITLEBAR_BUTTON_HELP, m_flags);
+        rBtn.x += 2*rBtn.width;
+        renderer.DrawTitleBarBitmap(this, dc, rBtn,
+                                    wxTITLEBAR_BUTTON_ICONIZE, m_flags);
+        rBtn.x += 2*rBtn.width;
+        renderer.DrawTitleBarBitmap(this, dc, rBtn,
+                                    wxTITLEBAR_BUTTON_RESTORE, m_flags);
+        rBtn.x += 2*rBtn.width;
+        renderer.DrawTitleBarBitmap(this, dc, rBtn,
+                                    wxTITLEBAR_BUTTON_MAXIMIZE, m_flags);
+        rBtn.x += 2*rBtn.width;
+        renderer.DrawTitleBarBitmap(this, dc, rBtn,
+                                    wxTITLEBAR_BUTTON_CLOSE, m_flags);
+
+        y += lineHeight + rBtn.height;
+#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
     }
 
+    int m_flags;
+
     DECLARE_EVENT_TABLE()
 };
 
@@ -154,8 +234,14 @@ END_EVENT_TABLE()
 enum
 {
     // our menu items
+    Render_DrawDisabled = 100,
+    Render_DrawFocused,
+    Render_DrawPressed,
+    Render_DrawChecked,
+    Render_DrawHot,
+
 #if wxUSE_DYNLIB_CLASS
-    Render_Load = 100,
+    Render_Load,
     Render_Unload,
 #endif // wxUSE_DYNLIB_CLASS
 
@@ -176,6 +262,12 @@ enum
 // handlers) which process them. It can be also done at run-time, but for the
 // simple menu events like this the static method is much simpler.
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+    EVT_MENU(Render_DrawDisabled, MyFrame::OnDrawDisabled)
+    EVT_MENU(Render_DrawFocused, MyFrame::OnDrawFocused)
+    EVT_MENU(Render_DrawPressed, MyFrame::OnDrawPressed)
+    EVT_MENU(Render_DrawChecked, MyFrame::OnDrawChecked)
+    EVT_MENU(Render_DrawHot, MyFrame::OnDrawHot)
+
 #if wxUSE_DYNLIB_CLASS
     EVT_MENU(Render_Load,  MyFrame::OnLoad)
     EVT_MENU(Render_Unload,MyFrame::OnUnload)
@@ -206,6 +298,13 @@ bool MyApp::OnInit()
     if ( !wxApp::OnInit() )
         return false;
 
+#ifdef __WXOSX__
+    // currently the images used by DrawTitleBarBitmap() are hard coded as PNG
+    // images inside the library itself so we need to enable PNG support to use
+    // this function
+    wxImage::AddHandler(new wxPNGHandler);
+#endif // OS X
+
     // create the main application window
     new MyFrame;
 
@@ -230,15 +329,27 @@ MyFrame::MyFrame()
 #if wxUSE_MENUS
     // create a menu bar
     wxMenu *menuFile = new wxMenu;
+    menuFile->AppendCheckItem(Render_DrawDisabled,
+                              "Draw in &disabled state\tCtrl-D");
+    menuFile->AppendCheckItem(Render_DrawFocused,
+                              "Draw in &focused state\tCtrl-F");
+    menuFile->AppendCheckItem(Render_DrawPressed,
+                              "Draw in &pressed state\tCtrl-P");
+    menuFile->AppendCheckItem(Render_DrawChecked,
+                              "Draw in &checked state\tCtrl-C");
+    menuFile->AppendCheckItem(Render_DrawHot,
+                              "Draw in &hot state\tCtrl-H");
+    menuFile->AppendSeparator();
 #if wxUSE_DYNLIB_CLASS
     menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L"));
     menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U"));
+    menuFile->AppendSeparator();
 #endif // wxUSE_DYNLIB_CLASS
-    menuFile->Append(Render_Quit, wxT("E&xit\tCtrl-Q"), wxT("Quit this program"));
+    menuFile->Append(Render_Quit);
 
     // the "About" item should be in the help menu
     wxMenu *helpMenu = new wxMenu;
-    helpMenu->Append(Render_About, wxT("&About...\tF1"), wxT("Show about dialog"));
+    helpMenu->Append(Render_About);
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar();
@@ -268,6 +379,18 @@ MyFrame::~MyFrame()
 
 // event handlers
 
+void MyFrame::OnToggleDrawFlag(wxCommandEvent& event, int flag)
+{
+    int flags = m_panel->GetFlags();
+    if ( event.IsChecked() )
+        flags |= flag;
+    else
+        flags &= ~flag;
+
+    m_panel->SetFlags(flags);
+    m_panel->Refresh();
+}
+
 #if wxUSE_DYNLIB_CLASS
 
 void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))