X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1542ea396a625766c59d683adbb1d613c1344d50..e0976f6db35b304f16519437c9d9e2450a373783:/samples/shaped/shaped.cpp?ds=sidebyside diff --git a/samples/shaped/shaped.cpp b/samples/shaped/shaped.cpp index c43c71ff45..cc8ed4a232 100644 --- a/samples/shaped/shaped.cpp +++ b/samples/shaped/shaped.cpp @@ -17,11 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma implementation "shaped.cpp" - #pragma interface "shaped.cpp" -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -39,9 +34,11 @@ #include "wx/menu.h" #include "wx/layout.h" #include "wx/msgdlg.h" + #include "wx/image.h" #endif #include "wx/dcclient.h" +#include "wx/image.h" // ---------------------------------------------------------------------------- // private classes @@ -83,16 +80,16 @@ private: wxBitmap m_bmp; wxPoint m_delta; - // any class wishing to process wxWindows events must use this macro + // any class wishing to process wxWidgets events must use this macro DECLARE_EVENT_TABLE() }; // ---------------------------------------------------------------------------- -// event tables and other macros for wxWindows +// event tables and other macros for wxWidgets // ---------------------------------------------------------------------------- -// the event tables connect the wxWindows events with the functions (event +// the event tables connect the wxWidgets events with the functions (event // 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(ShapedFrame, wxFrame) @@ -110,7 +107,7 @@ BEGIN_EVENT_TABLE(ShapedFrame, wxFrame) END_EVENT_TABLE() -// Create a new application object: this macro will allow wxWindows to create +// Create a new application object: this macro will allow wxWidgets to create // the application object during program execution (it's better than using a // static object for many reasons) and also declares the accessor function // wxGetApp() which will return the reference of the right type (i.e. MyApp and @@ -128,16 +125,20 @@ IMPLEMENT_APP(MyApp) // `Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + wxInitAllImageHandlers(); // Create the main application window ShapedFrame *frame = new ShapedFrame(); - frame->Show(TRUE); + frame->Show(true); + SetTopWindow(frame); // success: wxApp::OnRun() will be called which will enter the main message - // loop and the application will run. If we returned FALSE here, the + // loop and the application will run. If we returned false here, the // application would exit immediately. - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -146,18 +147,25 @@ bool MyApp::OnInit() // frame constructor ShapedFrame::ShapedFrame() - : wxFrame((wxFrame *)NULL, -1, wxEmptyString, - wxDefaultPosition, wxDefaultSize, - wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR) + : wxFrame((wxFrame *)NULL, wxID_ANY, wxEmptyString, + wxDefaultPosition, wxSize(100, 100), //wxDefaultSize, + 0 + | wxFRAME_SHAPED + | wxSIMPLE_BORDER + | wxFRAME_NO_TASKBAR + | wxSTAY_ON_TOP + ) { - m_hasShape = FALSE; - m_bmp = wxBitmap("star.png", wxBITMAP_TYPE_PNG); + m_hasShape = false; + m_bmp = wxBitmap(_T("star.png"), wxBITMAP_TYPE_PNG); SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight())); SetToolTip(wxT("Right-click to exit")); -#ifdef __wxMSW__ + +#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 it - // has been created so we set the shape now. + // 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 } @@ -168,13 +176,13 @@ void ShapedFrame::SetWindowShape() m_hasShape = SetShape(region); } -void ShapedFrame::OnDoubleClick(wxMouseEvent& evt) +void ShapedFrame::OnDoubleClick(wxMouseEvent& WXUNUSED(evt)) { if (m_hasShape) { wxRegion region; SetShape(region); - m_hasShape = FALSE; + m_hasShape = false; } else SetWindowShape(); @@ -183,6 +191,7 @@ void ShapedFrame::OnDoubleClick(wxMouseEvent& evt) void ShapedFrame::OnLeftDown(wxMouseEvent& evt) { CaptureMouse(); + //printf("Mouse captured\n"); wxPoint pos = ClientToScreen(evt.GetPosition()); wxPoint origin = GetPosition(); int dx = pos.x - origin.x; @@ -190,33 +199,38 @@ void ShapedFrame::OnLeftDown(wxMouseEvent& evt) m_delta = wxPoint(dx, dy); } -void ShapedFrame::OnLeftUp(wxMouseEvent& evt) +void ShapedFrame::OnLeftUp(wxMouseEvent& WXUNUSED(evt)) { if (HasCapture()) + { ReleaseMouse(); + //printf("Mouse released\n"); + } } void ShapedFrame::OnMouseMove(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + //printf("x:%d y:%d\n", pt.x, pt.y); if (evt.Dragging() && evt.LeftIsDown()) { - wxPoint pos = ClientToScreen(evt.GetPosition()); + wxPoint pos = ClientToScreen(pt); Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y)); } } -void ShapedFrame::OnExit(wxMouseEvent& evt) +void ShapedFrame::OnExit(wxMouseEvent& WXUNUSED(evt)) { Close(); } -void ShapedFrame::OnPaint(wxPaintEvent& evt) +void ShapedFrame::OnPaint(wxPaintEvent& WXUNUSED(evt)) { wxPaintDC dc(this); - dc.DrawBitmap(m_bmp, 0, 0, TRUE); + dc.DrawBitmap(m_bmp, 0, 0, true); } -void ShapedFrame::OnWindowCreate(wxWindowCreateEvent& evt) +void ShapedFrame::OnWindowCreate(wxWindowCreateEvent& WXUNUSED(evt)) { SetWindowShape(); }