]> git.saurik.com Git - wxWidgets.git/commitdiff
1. cursor fixes: frame does have hand cursor in the controls sample now,
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 Feb 2000 23:49:41 +0000 (23:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 Feb 2000 23:49:41 +0000 (23:49 +0000)
   modal dialogs don't have busy cursor even if wxIsBusy()
2. wxTextCtrl sets client data field in the generated events
3. added wxEnhMetaFile::SetClipboard()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
include/wx/control.h
include/wx/msw/enhmeta.h
include/wx/msw/private.h
src/common/ctrlcmn.cpp
src/msw/app.cpp
src/msw/cursor.cpp
src/msw/data.cpp
src/msw/dialog.cpp
src/msw/enhmeta.cpp
src/msw/textctrl.cpp
src/msw/utils.cpp
src/msw/window.cpp

index 79adf0144f07812f385467aa797982fb953952dd..7b1d491309475276824f16719b4cc82f132436fe 100644 (file)
@@ -46,6 +46,9 @@ protected:
 
     // inherit colour and font settings from the parent window
     void InheritAttributes();
+
+    // initialize the common fields of wxCommandEvent
+    void InitCommandEvent(wxCommandEvent& event) const;
 };
 
 // ----------------------------------------------------------------------------
index a7f235453dde6db83f468fc1fef0b91c190e6a3f..88f7cfa8a9cedea476e904b95be4e67291cef571 100644 (file)
@@ -51,6 +51,11 @@ public:
 
     const wxString& GetFileName() const { return m_filename; }
 
+    // copy the metafile to the clipboard: the width and height parameters are
+    // for backwards compatibility (with wxMetaFile) only, they are ignored by
+    // this method
+    bool SetClipboard(int width = 0, int height = 0);
+
     // implementation
     WXHANDLE GetHENHMETAFILE() const { return m_hMF; }
     void SetHENHMETAFILE(WXHANDLE hMF) { Free(); m_hMF = hMF; }
@@ -96,7 +101,7 @@ private:
 #if wxUSE_DRAG_AND_DROP
 
 // notice that we want to support both CF_METAFILEPICT and CF_ENHMETAFILE and
-// so we derive from and not from wxDataObjectSimple
+// so we derive from wxDataObject and not from wxDataObjectSimple
 class WXDLLEXPORT wxEnhMetaFileDataObject : public wxDataObject
 {
 public:
index c23c71526614730a9528fd161d8162440872d9c9..6ed5fcb913878f500591ef07ea02d031327c9bd2 100644 (file)
@@ -300,6 +300,9 @@ private:
 #define GetHmenu()              ((HMENU)GetHMenu())
 #define GetHmenuOf(menu)        ((HMENU)menu->GetHMenu())
 
+#define GetHcursor()            ((HCURSOR)GetHCURSOR())
+#define GetHcursorOf(cursor)    ((HCURSOR)(cursor).GetHCURSOR())
+
 // ---------------------------------------------------------------------------
 // global data
 // ---------------------------------------------------------------------------
@@ -326,6 +329,10 @@ WXDLLEXPORT void wxSetInstance(HINSTANCE hInst);
 
 #if wxUSE_GUI
 
+// cursor stuff
+extern HCURSOR wxGetCurrentBusyCursor();    // from msw/utils.cpp
+extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp
+
 WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd);
 
 WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font);
index 8e99dd0b174b334cabb12f0826cdfae27f3c34f0..479e92c1f59d39447043c49a5e33bead31433a9e 100644 (file)
@@ -68,5 +68,28 @@ void wxControlBase::InheritAttributes()
 
 void wxControlBase::Command(wxCommandEvent& event)
 {
-    (void)ProcessEvent(event);
+    (void)GetEventHandler()->ProcessEvent(event);
 }
+
+void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
+{
+    event.SetEventObject((wxControlBase *)this);    // const_cast
+
+    // event.SetId(GetId()); -- this is usuall done in the event ctor
+
+    switch ( m_clientDataType )
+    {
+        case ClientData_Void:
+            event.SetClientData(GetClientData());
+            break;
+
+        case ClientData_Object:
+            event.SetClientObject(GetClientObject());
+            break;
+
+        case ClientData_None:
+            // nothing to do
+            ;
+    }
+}
+
index 94c9239a6dece9889408e2b6528964802c891615..903493b2f10080c36c3beaccad64e48009fe1ae5 100644 (file)
@@ -126,7 +126,6 @@ extern wxChar *wxOsVersion;
 extern wxList *wxWinHandleList;
 extern wxList WXDLLEXPORT wxPendingDelete;
 extern void wxSetKeyboardHook(bool doIt);
-extern wxCursor *g_globalCursor;
 
 MSG s_currentMsg;
 wxApp *wxTheApp = NULL;
@@ -228,8 +227,6 @@ bool wxApp::Initialize()
     Ctl3dAutoSubclass(wxhInstance);
 #endif
 
-    g_globalCursor = new wxCursor;
-
     // VZ: these icons are not in wx.rc anyhow (but should they?)!
 #if 0
     wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME"));
@@ -497,13 +494,6 @@ void wxApp::CleanUp()
     //  wxDefaultResourceTable->ClearTable();
 #endif
 
-    // Indicate that the cursor can be freed, so that cursor won't be deleted
-    // by deleting the bitmap list before g_globalCursor goes out of scope
-    // (double deletion of the cursor).
-    wxSetCursor(wxNullCursor);
-    delete g_globalCursor;
-    g_globalCursor = NULL;
-
     wxDeleteStockObjects();
 
     // Destroy all GDI lists, etc.
index e914dff561f34c9f134cba6ed08ab95e866198b7..1f76183f6eb969c11377db03b3a3075faa256c00 100644 (file)
 // wxWin macros
 // ----------------------------------------------------------------------------
 
-    IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxCursorBase)
+IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxCursorBase)
+
+// ----------------------------------------------------------------------------
+// globals
+// ----------------------------------------------------------------------------
+
+// Current cursor, in order to hang on to cursor handle when setting the cursor
+// globally
+static wxCursor *gs_globalCursor = NULL;
+
+// ----------------------------------------------------------------------------
+// private classes
+// ----------------------------------------------------------------------------
+
+class wxCursorModule : public wxModule
+{
+public:
+    virtual bool OnInit()
+    {
+        gs_globalCursor = new wxCursor;
+
+        return TRUE;
+    }
+
+    virtual void OnExit()
+    {
+        delete gs_globalCursor;
+        gs_globalCursor = (wxCursor *)NULL;
+    }
+};
+
+// ============================================================================
+// implementation
+// ============================================================================
 
 // ----------------------------------------------------------------------------
 // wxCursorRefData
@@ -278,16 +311,19 @@ wxCursor::~wxCursor()
 // Global cursor setting
 // ----------------------------------------------------------------------------
 
-void wxSetCursor(const wxCursor& cursor)
+const wxCursor *wxGetGlobalCursor()
 {
-    extern wxCursor *g_globalCursor;
+    return gs_globalCursor;
+}
 
-    if ( cursor.Ok() && cursor.GetHCURSOR() )
+void wxSetCursor(const wxCursor& cursor)
+{
+    if ( cursor.Ok() )
     {
-        ::SetCursor((HCURSOR) cursor.GetHCURSOR());
+        ::SetCursor(GetHcursorOf(cursor));
 
-        if ( g_globalCursor )
-            (*g_globalCursor) = cursor;
+        if ( gs_globalCursor )
+            *gs_globalCursor = cursor;
     }
 }
 
index 103f694ce0abd2858b26f789a69027847b3c6f41..1b24fc3e3a7c20c905dc1ead6487c9ef765aa2ae 100644 (file)
@@ -37,13 +37,6 @@ wxWindowList wxTopLevelWindows;
 // List of windows pending deletion
 wxList WXDLLEXPORT wxPendingDelete;
 
-// Current cursor, in order to hang on to
-// cursor handle when setting the cursor globally
-wxCursor *g_globalCursor = NULL;
-
-// Message Strings for Internationalization
-char **wx_msg_str = (char**)NULL;
-
 // Custom OS version, as optionally placed in wx.ini/.wxrc
 // Currently this can be Win95, Windows, Win32s, WinNT.
 // For some systems, you can't tell until run-time what services you
index 658003fe30641651b69724c1d9b044fc60b210b2..3463629b49dd4ebc5fcf3a271c3dad03f2175470 100644 (file)
@@ -530,13 +530,28 @@ long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
         case WM_SETCURSOR:
             // we want to override the busy cursor for modal dialogs:
             // typically, wxBeginBusyCursor() is called and then a modal dialog
-            // is shown, but the modal dialog shouldn't have this cursor
+            // is shown, but the modal dialog shouldn't have hourglass cursor
             if ( wxIsBusy() )
             {
-                rc = TRUE;
+                // set our cursor for all windows (but see below)
+                wxCursor cursor = m_cursor;
+                if ( !cursor.Ok() )
+                    cursor = wxCURSOR_ARROW;
 
+                ::SetCursor(GetHcursorOf(cursor));
+
+                // in any case, stop here and don't let wxWindow process this
+                // message (it would set the busy cursor)
                 processed = TRUE;
+
+                // but return FALSE to tell the child window (if the event
+                // comes from one of them and not from ourselves) that it can
+                // set its own cursor if it has one: thus, standard controls
+                // (e.g. text ctrl) still have correct cursors in a dialog
+                // invoked while wxIsBusy()
+                rc = FALSE;
             }
+            break;
     }
 
     if ( !processed )
index 189d2980b83e842988ce71ec4f3151359baed866..0fd8b2d9af796d83a3bb0ed539da9a6a343fe715 100644 (file)
@@ -36,6 +36,7 @@
 #endif //WX_PRECOMP
 
 #include "wx/metafile.h"
+#include "wx/clipbrd.h"
 
 #include "wx/msw/private.h"
 
@@ -161,6 +162,13 @@ wxSize wxEnhMetaFile::GetSize() const
     return size;
 }
 
+bool wxEnhMetaFile::SetClipboard(int WXUNUSED(width), int WXUNUSED(height))
+{
+    wxCHECK_MSG( m_hMF, FALSE, _T("can't copy invalid metafile to clipboard") );
+
+    return wxTheClipboard->AddData(new wxEnhMetaFileDataObject(*this));
+}
+
 // ----------------------------------------------------------------------------
 // wxEnhMetaFileDC
 // ----------------------------------------------------------------------------
index c4969c93942f6fc51158c2cd32afcc6acbcc0df7..91ad4538531b32592f527b9a343fdc850e7fcd39 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        textctrl.cpp
+// Name:        msw/textctrl.cpp
 // Purpose:     wxTextCtrl
 // Author:      Julian Smart
 // Modified by:
@@ -887,7 +887,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
             if ( !(m_windowStyle & wxTE_MULTILINE) )
             {
                 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
-                event.SetEventObject( this );
+                InitCommandEvent(event);
                 if ( GetEventHandler()->ProcessEvent(event) )
                     return;
             }
@@ -934,9 +934,9 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
         case EN_CHANGE:
             {
                 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
-                event.SetEventObject( this );
-                event.SetString( GetValue() );
-                ProcessCommand( event );
+                InitCommandEvent(event);
+                event.SetString(GetValue());
+                ProcessCommand(event);
             }
             break;
 
@@ -1016,27 +1016,27 @@ wxSize wxTextCtrl::DoGetBestSize() const
 // standard handlers for standard edit menu events
 // ----------------------------------------------------------------------------
 
-void wxTextCtrl::OnCut(wxCommandEvent& event)
+void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
 {
     Cut();
 }
 
-void wxTextCtrl::OnCopy(wxCommandEvent& event)
+void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
 {
     Copy();
 }
 
-void wxTextCtrl::OnPaste(wxCommandEvent& event)
+void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
 {
     Paste();
 }
 
-void wxTextCtrl::OnUndo(wxCommandEvent& event)
+void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
 {
     Undo();
 }
 
-void wxTextCtrl::OnRedo(wxCommandEvent& event)
+void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
 {
     Redo();
 }
index 2f56096849254426b5f86bb95ab68d011472e4d9..7126032d69a10c291b13fb363330de093883d310 100644 (file)
@@ -806,10 +806,15 @@ bool wxGetResource(const wxString& section, const wxString& entry, int *value, c
 // helper functions for showing a "busy" cursor
 // ---------------------------------------------------------------------------
 
-HCURSOR gs_wxBusyCursor = 0;     // new, busy cursor
-HCURSOR gs_wxBusyCursorOld = 0;  // old cursor
+static HCURSOR gs_wxBusyCursor = 0;     // new, busy cursor
+static HCURSOR gs_wxBusyCursorOld = 0;  // old cursor
 static int gs_wxBusyCursorCount = 0;
 
+extern HCURSOR wxGetCurrentBusyCursor()
+{
+    return gs_wxBusyCursor;
+}
+
 // Set the cursor to the busy cursor for all windows
 void wxBeginBusyCursor(wxCursor *cursor)
 {
index 163a72e05531deda0fbde9059eea7e78469ed38c..48cf53abc9e6a0402be325d763d70583ad7b200d 100644 (file)
@@ -480,7 +480,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor)
     ::GetWindowRect(hWnd, &rect);
 
     if ( ::PtInRect(&rect, point) && !wxIsBusy() )
-        ::SetCursor((HCURSOR)m_cursor.GetHCURSOR());
+        ::SetCursor(GetHcursorOf(m_cursor));
 
     return TRUE;
 }
@@ -2664,54 +2664,46 @@ bool wxWindow::HandleSetCursor(WXHWND hWnd,
                                short nHitTest,
                                int WXUNUSED(mouseMsg))
 {
-    // don't set cursor for other windows, only for this one: this prevents
-    // children of this window from getting the same cursor as the parent has
-    // (don't forget that this message is propagated by default up the window
-    // parent-child hierarchy)
-    if ( GetHWND() == hWnd )
-    {
-        // don't set cursor when the mouse is not in the client part
-        if ( nHitTest == HTCLIENT || nHitTest == HTERROR )
-        {
-            HCURSOR hcursor = 0;
-            if ( wxIsBusy() )
-            {
-                // from msw\utils.cpp
-                extern HCURSOR gs_wxBusyCursor;
-
-                hcursor = gs_wxBusyCursor;
-            }
-            else
-            {
-                wxCursor *cursor = NULL;
-
-                if ( m_cursor.Ok() )
-                {
-                    cursor = &m_cursor;
-                }
-                else
-                {
-                    // from msw\data.cpp
-                    extern wxCursor *g_globalCursor;
+    // the logic is as follows:
+    //  1. if we have the cursor set it unless wxIsBusy()
+    //  2. if we're a top level window, set some cursor anyhow
+    //  3. if wxIsBusy(), set the busy cursor, otherwise the global one
 
-                    if ( g_globalCursor && g_globalCursor->Ok() )
-                        cursor = g_globalCursor;
-                }
-
-                if ( cursor )
-                    hcursor = (HCURSOR)cursor->GetHCURSOR();
-            }
+    HCURSOR hcursor = 0;
+    bool isBusy = wxIsBusy();
+    if ( m_cursor.Ok() )
+    {
+        hcursor = GetHcursorOf(m_cursor);
+    }
 
-            if ( hcursor )
+    if ( !GetParent() )
+    {
+        if ( isBusy )
+        {
+            hcursor = wxGetCurrentBusyCursor();
+        }
+        else if ( !hcursor )
+        {
+            const wxCursor *cursor = wxGetGlobalCursor();
+            if ( cursor && cursor->Ok() )
             {
-                ::SetCursor(hcursor);
-
-                return TRUE;
+                hcursor = GetHcursorOf(*cursor);
             }
         }
     }
 
-    return FALSE;
+    if ( hcursor )
+    {
+        ::SetCursor(hcursor);
+
+        // cursor set, stop here
+        return TRUE;
+    }
+    else
+    {
+        // pass up the window chain
+        return FALSE;
+    }
 }
 
 // ---------------------------------------------------------------------------