]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/shaped/shaped.cpp
don't use deprecated toolbar API
[wxWidgets.git] / samples / shaped / shaped.cpp
index ec2caf1f5f562ca38fc8f5612b99697bacc43be6..9ebf3e697c74fb3ed4e4e02c047eb545a16172eb 100644 (file)
@@ -40,6 +40,7 @@
 #include "wx/dcclient.h"
 #include "wx/image.h"
 
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 // menu ids
 enum
 {
-    Show_Shaped,
-    Show_Transparent
+    Show_Shaped = 100,
+    Show_Transparent,
+
+    // must be consecutive and in the same order as wxShowEffect enum elements
+    Show_Effect_First,
+    Show_Effect_Roll = Show_Effect_First,
+    Show_Effect_Slide,
+    Show_Effect_Blend,
+    Show_Effect_Expand,
+    Show_Effect_Last = Show_Effect_Expand
 };
 
 // ----------------------------------------------------------------------------
@@ -78,6 +87,7 @@ public:
 private:
     void OnShowShaped(wxCommandEvent& event);
     void OnShowTransparent(wxCommandEvent& event);
+    void OnShowEffect(wxCommandEvent& event);
 
     DECLARE_EVENT_TABLE()
 };
@@ -98,7 +108,6 @@ public:
     void OnMouseMove(wxMouseEvent& evt);
     void OnExit(wxMouseEvent& evt);
     void OnPaint(wxPaintEvent& evt);
-    void OnWindowCreate(wxWindowCreateEvent& evt);
 
 private:
     bool     m_hasShape;
@@ -137,6 +146,66 @@ private:
     DECLARE_EVENT_TABLE()
 };
 
+class EffectFrame : public wxFrame
+{
+public:
+    EffectFrame(wxWindow *parent,
+                wxShowEffect effect,
+                // TODO: add menu command to the main frame to allow changing
+                //       these parameters
+                unsigned timeout = 1000)
+        : wxFrame(parent, wxID_ANY,
+                  wxString::Format("Frame shown with %s effect",
+                                   GetEffectName(effect)),
+                  wxDefaultPosition, wxSize(450, 300)),
+          m_effect(effect),
+          m_timeout(timeout)
+    {
+        new wxStaticText(this, wxID_ANY,
+                         wxString::Format("Effect: %s", GetEffectName(effect)),
+                         wxPoint(20, 20));
+        new wxStaticText(this, wxID_ANY,
+                         wxString::Format("Timeout: %ums", m_timeout),
+                         wxPoint(20, 60));
+
+        ShowWithEffect(m_effect, m_timeout);
+
+        Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(EffectFrame::OnClose));
+    }
+
+private:
+    static const char *GetEffectName(wxShowEffect effect)
+    {
+        static const char *names[] =
+        {
+            "roll to left",
+            "roll to right",
+            "roll to top",
+            "roll to bottom",
+            "slide to left",
+            "slide to right",
+            "slide to top",
+            "slide to bottom",
+            "fade",
+            "expand",
+        };
+        wxCOMPILE_TIME_ASSERT( WXSIZEOF(names) == wxSHOW_EFFECT_MAX,
+                                EffectNamesMismatch );
+
+        return names[effect];
+    }
+
+    void OnClose(wxCloseEvent& event)
+    {
+        HideWithEffect(m_effect, m_timeout);
+
+        event.Skip();
+    }
+
+    wxShowEffect m_effect;
+    unsigned m_timeout;
+};
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -170,6 +239,7 @@ bool MyApp::OnInit()
 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
     EVT_MENU(Show_Shaped, MainFrame::OnShowShaped)
     EVT_MENU(Show_Transparent, MainFrame::OnShowTransparent)
+    EVT_MENU_RANGE(Show_Effect_First, Show_Effect_Last, MainFrame::OnShowEffect)
 END_EVENT_TABLE()
 
 MainFrame::MainFrame()
@@ -181,6 +251,11 @@ MainFrame::MainFrame()
     menuFrames->Append(Show_Shaped, "Show &shaped window\tCtrl-S");
     menuFrames->Append(Show_Transparent, "Show &transparent window\tCtrl-T");
     menuFrames->AppendSeparator();
+    menuFrames->Append(Show_Effect_Roll, "Show &rolled effect\tCtrl-R");
+    menuFrames->Append(Show_Effect_Slide, "Show s&lide effect\tCtrl-L");
+    menuFrames->Append(Show_Effect_Blend, "Show &fade effect\tCtrl-F");
+    menuFrames->Append(Show_Effect_Expand, "Show &expand effect\tCtrl-E");
+    menuFrames->AppendSeparator();
     menuFrames->Append(wxID_EXIT, "E&xit");
 
     mbar->Append(menuFrames, "&Show");
@@ -201,6 +276,74 @@ void MainFrame::OnShowTransparent(wxCommandEvent& WXUNUSED(event))
     seeThroughFrame->Show(true);
 }
 
+void MainFrame::OnShowEffect(wxCommandEvent& event)
+{
+    int effect = event.GetId();
+    static wxDirection direction = wxLEFT;
+    direction = (wxDirection)(((int)direction)<< 1);
+    if ( direction > wxDOWN )
+        direction = wxLEFT ;
+
+    wxShowEffect eff;
+    switch ( effect )
+    {
+        case Show_Effect_Roll:
+            switch ( direction )
+            {
+                case wxLEFT:
+                    eff = wxSHOW_EFFECT_ROLL_TO_LEFT;
+                    break;
+                case wxRIGHT:
+                    eff = wxSHOW_EFFECT_ROLL_TO_RIGHT;
+                    break;
+                case wxTOP:
+                    eff = wxSHOW_EFFECT_ROLL_TO_TOP;
+                    break;
+                case wxBOTTOM:
+                    eff = wxSHOW_EFFECT_ROLL_TO_BOTTOM;
+                    break;
+                default:
+                    wxFAIL_MSG( "invalid direction" );
+                    return;
+            }
+            break;
+        case Show_Effect_Slide:
+            switch ( direction )
+            {
+                case wxLEFT:
+                    eff = wxSHOW_EFFECT_SLIDE_TO_LEFT;
+                    break;
+                case wxRIGHT:
+                    eff = wxSHOW_EFFECT_SLIDE_TO_RIGHT;
+                    break;
+                case wxTOP:
+                    eff = wxSHOW_EFFECT_SLIDE_TO_TOP;
+                    break;
+                case wxBOTTOM:
+                    eff = wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
+                    break;
+                default:
+                    wxFAIL_MSG( "invalid direction" );
+                    return;
+            }
+            break;
+
+        case Show_Effect_Blend:
+            eff = wxSHOW_EFFECT_BLEND;
+            break;
+
+        case Show_Effect_Expand:
+            eff = wxSHOW_EFFECT_EXPAND;
+            break;
+
+        default:
+            wxFAIL_MSG( "invalid effect" );
+            return;
+    }
+
+    new EffectFrame(this, eff,1000);
+}
+
 // ----------------------------------------------------------------------------
 // shaped frame
 // ----------------------------------------------------------------------------
@@ -211,12 +354,7 @@ BEGIN_EVENT_TABLE(ShapedFrame, wxFrame)
     EVT_LEFT_UP(ShapedFrame::OnLeftUp)
     EVT_MOTION(ShapedFrame::OnMouseMove)
     EVT_RIGHT_UP(ShapedFrame::OnExit)
-
     EVT_PAINT(ShapedFrame::OnPaint)
-
-#ifdef __WXGTK__
-    EVT_WINDOW_CREATE(ShapedFrame::OnWindowCreate)
-#endif
 END_EVENT_TABLE()
 
 
@@ -235,14 +373,7 @@ ShapedFrame::ShapedFrame(wxFrame *parent)
     m_bmp = wxBitmap(_T("star.png"), wxBITMAP_TYPE_PNG);
     SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
     SetToolTip(wxT("Right-click to close"));
-
-#ifndef __WXGTK__
-    // On wxGTK we can't do this yet because the window hasn't been created
-    // yet so we wait until the EVT_WINDOW_CREATE event happens.  On wxMSW and
-    // wxMac the window has been created at this point so we go ahead and set
-    // the shape now.
     SetWindowShape();
-#endif
 }
 
 void ShapedFrame::SetWindowShape()
@@ -302,11 +433,6 @@ void ShapedFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
     dc.DrawBitmap(m_bmp, 0, 0, true);
 }
 
-void ShapedFrame::OnWindowCreate(wxWindowCreateEvent& WXUNUSED(evt))
-{
-    SetWindowShape();
-}
-
 // ----------------------------------------------------------------------------
 // see-through frame
 // ----------------------------------------------------------------------------