]> git.saurik.com Git - wxWidgets.git/commitdiff
Corrected double clicks (always on the same window).
authorRobert Roebling <robert@roebling.de>
Sun, 5 May 2002 11:36:33 +0000 (11:36 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 5 May 2002 11:36:33 +0000 (11:36 +0000)
  Corrected mouse up events (same window as mouse down).

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

src/mac/carbon/textctrl.cpp
src/mac/carbon/toplevel.cpp
src/mac/carbon/window.cpp
src/mac/textctrl.cpp
src/mac/toplevel.cpp
src/mac/window.cpp

index 0c742d371990ddf9d1dd0112153276d79562a89b..7ab64897097f3cc205d29f6bee79fa5730cedf58 100644 (file)
@@ -183,7 +183,9 @@ void wxTextCtrl::SetValue(const wxString& st)
     else
         value = st ;
     ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+
     MacRedrawControl() ;
+    Update();
 }
 
 // Clipboard operations
@@ -194,10 +196,10 @@ void wxTextCtrl::Copy()
         TEHandle teH ;
         long size ;
    
-                 ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-                   TECopy( teH ) ;
+          ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECopy( teH ) ;
         ClearCurrentScrap();
-                   TEToScrap() ;
+            TEToScrap() ;
     }
 }
 
@@ -208,12 +210,12 @@ void wxTextCtrl::Cut()
         TEHandle teH ;
         long size ;
    
-                 ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-                   TECut( teH ) ;
+          ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECut( teH ) ;
         ClearCurrentScrap();
-                   TEToScrap() ;
-                   //  MacInvalidateControl() ;
-         }
+            TEToScrap() ;
+            //  MacInvalidateControl() ;
+      }
 }
 
 void wxTextCtrl::Paste()
@@ -1277,40 +1279,40 @@ bail:
 
 
 /* mUPOpenControl initializes a user pane control so it will be drawn
-       and will behave as a scrolling text edit field inside of a window.
-       This routine performs all of the initialization steps necessary,
-       except it does not create the user pane control itself.  theControl
-       should refer to a user pane control that you have either created
-       yourself or extracted from a dialog's control heirarchy using
-       the GetDialogItemAsControl routine.  */
+    and will behave as a scrolling text edit field inside of a window.
+    This routine performs all of the initialization steps necessary,
+    except it does not create the user pane control itself.  theControl
+    should refer to a user pane control that you have either created
+    yourself or extracted from a dialog's control heirarchy using
+    the GetDialogItemAsControl routine.  */
 OSStatus mUPOpenControl(ControlHandle theControl, bool multiline) {
-       Rect bounds;
-       WindowPtr theWindow;
-       STPTextPaneVars **tpvars, *varsp;
-       OSStatus err;
-       RGBColor rgbWhite = {0xFFFF, 0xFFFF, 0xFFFF};
-       TXNBackground tback;
-       
-               /* set up our globals */
-       if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc);
-       if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(TPPaneHitTestProc);
-       if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(TPPaneTrackingProc);
-       if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(TPPaneIdleProc);
-       if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc);
-       if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(TPPaneActivateProc);
-       if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc);
-               
-               /* allocate our private storage */
-       tpvars = (STPTextPaneVars **) NewHandleClear(sizeof(STPTextPaneVars));
-       SetControlReference(theControl, (long) tpvars);
-       HLock((Handle) tpvars);
-       varsp = *tpvars;
-               /* set the initial settings for our private data */
-       varsp->fInFocus = false;
-       varsp->fIsActive = true;
-       varsp->fTEActive = false;
-       varsp->fUserPaneRec = theControl;
-       theWindow = varsp->fOwner = GetControlOwner(theControl);
+    Rect bounds;
+    WindowPtr theWindow;
+    STPTextPaneVars **tpvars, *varsp;
+    OSStatus err;
+    RGBColor rgbWhite = {0xFFFF, 0xFFFF, 0xFFFF};
+    TXNBackground tback;
+    
+        /* set up our globals */
+    if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc);
+    if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(TPPaneHitTestProc);
+    if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(TPPaneTrackingProc);
+    if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(TPPaneIdleProc);
+    if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc);
+    if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(TPPaneActivateProc);
+    if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc);
+        
+        /* allocate our private storage */
+    tpvars = (STPTextPaneVars **) NewHandleClear(sizeof(STPTextPaneVars));
+    SetControlReference(theControl, (long) tpvars);
+    HLock((Handle) tpvars);
+    varsp = *tpvars;
+        /* set the initial settings for our private data */
+    varsp->fInFocus = false;
+    varsp->fIsActive = true;
+    varsp->fTEActive = false;
+    varsp->fUserPaneRec = theControl;
+    theWindow = varsp->fOwner = GetControlOwner(theControl);
 #if TARGET_CARBON
     varsp->fDrawingEnvironment = GetWindowPort(varsp->fOwner);
 #else
@@ -1838,16 +1840,16 @@ void wxTextCtrl::Copy()
             TEHandle teH ;
             long size ;
        
-                ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-               TECopy( teH ) ;
-               ClearCurrentScrap();
-               TEToScrap() ;
-       }
-       else
-       {
-         mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
-       }
-       }
+             ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECopy( teH ) ;
+            ClearCurrentScrap();
+            TEToScrap() ;
+        }
+        else
+        {
+          mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
+        }
+    }
 }
 
 void wxTextCtrl::Cut()
@@ -1859,17 +1861,17 @@ void wxTextCtrl::Cut()
             TEHandle teH ;
             long size ;
        
-                       ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-               TECut( teH ) ;
-               ClearCurrentScrap();
-               TEToScrap() ;
-               //      MacInvalidateControl() ;
+            ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECut( teH ) ;
+            ClearCurrentScrap();
+            TEToScrap() ;
+            //  MacInvalidateControl() ;
+    }
+        else
+        {
+          mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
+        }
     }
-       else
-       {
-         mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
-       }
-       }
 }
 
 void wxTextCtrl::Paste()
@@ -1881,16 +1883,16 @@ void wxTextCtrl::Paste()
             TEHandle teH ;
             long size ;
      
-               ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-               TEFromScrap() ;
-               TEPaste( teH ) ;
+            ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        TEFromScrap() ;
+        TEPaste( teH ) ;
       MacRedrawControl() ;
-       }
-       else
-       {
-         mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
-       }
-       }
+    }
+    else
+    {
+      mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
+    }
+    }
 }
 
 bool wxTextCtrl::CanCopy() const
@@ -1986,22 +1988,22 @@ long wxTextCtrl::GetLastPosition() const
   }
   else
   {
-     STPTextPaneVars** tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
+     STPTextPaneVars**  tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
     int actualsize = 0 ;
-       Handle theText ;
-       OSErr err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
-               /* all done */
-       if ( err )
-       {
-         actualsize = 0 ;
-       }
-       else
-       {
-         actualsize = GetHandleSize( theText ) ;
-         DisposeHandle( theText ) ;
-       }
-       return actualsize ;
+    Handle theText ;
+    OSErr err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
+        /* all done */
+    if ( err )
+    {
+      actualsize = 0 ;
+    }
+    else
+    {
+      actualsize = GetHandleSize( theText ) ;
+      DisposeHandle( theText ) ;
+    }
+    return actualsize ;
   }
 }
 
@@ -2014,19 +2016,19 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
     ControlEditTextSelectionRec selection ;
    
-       selection.selStart = from ;
-       selection.selEnd = to ;
-       ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-               ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-       TESetSelect( from , to  , teH ) ;
-       TEDelete( teH ) ;
-               TEInsert( value , value.Length() , teH ) ;
-       }
-       else
-       {
-         // TODO
-       }
-       Refresh() ;
+    selection.selStart = from ;
+    selection.selEnd = to ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    TESetSelect( from , to  , teH ) ;
+    TEDelete( teH ) ;
+        TEInsert( value , value.Length() , teH ) ;
+    }
+    else
+    {
+      // TODO
+    }
+    Refresh() ;
 }
 
 void wxTextCtrl::Remove(long from, long to)
@@ -2038,11 +2040,11 @@ void wxTextCtrl::Remove(long from, long to)
    
     ControlEditTextSelectionRec selection ;
    
-       selection.selStart = from ;
-       selection.selEnd = to ;
-       ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-       ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-       TEDelete( teH ) ;
+    selection.selStart = from ;
+    selection.selEnd = to ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    TEDelete( teH ) ;
   }
   else
   {
@@ -2134,7 +2136,7 @@ void wxTextCtrl::Clear()
   {
     mUPDoEditCommand( (ControlHandle) m_macControl , kmUPClear) ;
   }
-       Refresh() ;
+    Refresh() ;
 }
 
 bool wxTextCtrl::IsModified() const
@@ -2219,13 +2221,13 @@ int wxTextCtrl::GetNumberOfLines() const
 {
   // TODO change this if possible to reflect real lines
   wxString content = GetValue() ;
-       
-       int count = 1;
-       for (int i = 0; i < content.Length() ; i++)
-       {
-           if (content[i] == '\r') count++;
-       }
-       
+    
+    int count = 1;
+    for (int i = 0; i < content.Length() ; i++)
+    {
+        if (content[i] == '\r') count++;
+    }
+    
   return count;
 }
 
@@ -2249,25 +2251,25 @@ int wxTextCtrl::GetLineLength(long lineNo) const
 {
   // TODO change this if possible to reflect real lines
   wxString content = GetValue() ;
-       
-       // Find line first
-       int count = 0;
-       for (int i = 0; i < content.Length() ; i++)
-       {
-           if (count == lineNo)
-           {
-               // Count chars in line then
-               count = 0;
-               for (int j = i; j < content.Length(); j++)
-               {
-                   count++;
-                   if (content[j] == '\r') return count;
-               }
-               
-               return count;
-           }
-           if (content[i] == '\r') count++;
-       }
+    
+    // Find line first
+    int count = 0;
+    for (int i = 0; i < content.Length() ; i++)
+    {
+        if (count == lineNo)
+        {
+            // Count chars in line then
+            count = 0;
+            for (int j = i; j < content.Length(); j++)
+            {
+                count++;
+                if (content[j] == '\r') return count;
+            }
+            
+            return count;
+        }
+        if (content[i] == '\r') count++;
+    }
     return 0;
 }
 
@@ -2276,27 +2278,27 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
   // TODO change this if possible to reflect real lines
   wxString content = GetValue() ;
 
-       // Find line first
-       int count = 0;
-       for (int i = 0; i < content.Length() ; i++)
-       {
-           if (count == lineNo)
-           {
-               // Add chars in line then
-               wxString tmp("");
-               
-               for (int j = i; j < content.Length(); j++)
-               {
-                   if (content[j] == '\r')
-                       return tmp;
-                       
-                   tmp += content[j];
-               }
-               
-               return tmp;
-           }
-           if (content[i] == '\r') count++;
-       }
+    // Find line first
+    int count = 0;
+    for (int i = 0; i < content.Length() ; i++)
+    {
+        if (count == lineNo)
+        {
+            // Add chars in line then
+            wxString tmp("");
+            
+            for (int j = i; j < content.Length(); j++)
+            {
+                if (content[j] == '\r')
+                    return tmp;
+                    
+                tmp += content[j];
+            }
+            
+            return tmp;
+        }
+        if (content[i] == '\r') count++;
+    }
     return wxString("");
 }
 
index 8db3f7e902143b929de3273c07e21413c9e0cef5..06ed4068548df4bc109e181a9935b9cc4f065949 100644 (file)
 // ----------------------------------------------------------------------------
 
 // list of all frames and modeless dialogs
-wxWindowList wxModelessWindows;
+wxWindowList       wxModelessWindows;
+
+// double click testing
+static   Point     gs_lastWhere;
+static   long      gs_lastWhen = 0;
+
+// cursor stuff
+extern   int       wxBusyCursorCount;
+
 
 // ============================================================================
 // wxTopLevelWindowMac implementation
@@ -347,10 +355,6 @@ void wxTopLevelWindowMac::Lower()
     ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
 }
 
-Point lastWhere ;
-long lastWhen = 0 ;
-extern int wxBusyCursorCount ;
-
 void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
 {
     EventRecord *ev = (EventRecord*) evr ;
@@ -397,22 +401,25 @@ void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
 
     if ( ev->what == mouseDown )
     {
-        if ( ev->when - lastWhen <= GetDblTime() )
+        if ( ev->when - gs_lastWhen <= GetDblTime() )
         {
-            if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
+            if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
             {
+                // This is not right if the second mouse down
+                // event occured in a differen window. We
+                // correct this in MacDispatchMouseEvent.
                 if ( controlDown )
                     event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
                 else
                     event.SetEventType(wxEVT_LEFT_DCLICK ) ;
             }
-            lastWhen = 0 ;
+            gs_lastWhen = 0 ;
         }
         else
         {
-            lastWhen = ev->when ;
+            gs_lastWhen = ev->when ;
         }
-        lastWhere = localwhere ;
+        gs_lastWhere = localwhere ;
     }
 
     event.m_x = localwhere.h;
index 9d9fdb5cc6e1a2208b6bf25cb708a92df80dd327..e6b1ba5c7c6113f7002a79c448e23989ac9fb78c 100644 (file)
@@ -1386,6 +1386,7 @@ bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMa
 }
 
 extern int wxBusyCursorCount ;
+static wxWindow *gs_lastWhich = NULL;
 
 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
 {
@@ -1438,6 +1439,23 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
         wxToolTip::RelayEvent( this , event);
 #endif // wxUSE_TOOLTIPS
 
+    if (gs_lastWhich != this)
+    {
+        gs_lastWhich = this;
+        
+        // Double clicks must always occur on the same window
+        if (event.GetEventType() == wxEVT_LEFT_DCLICK)
+            event.SetEventType( wxEVT_LEFT_DOWN );
+        if (event.GetEventType() == wxEVT_RIGHT_DCLICK)
+            event.SetEventType( wxEVT_RIGHT_DOWN );
+            
+        // Same for mouse up events
+        if (event.GetEventType() == wxEVT_LEFT_UP)
+            return TRUE;
+        if (event.GetEventType() == wxEVT_RIGHT_UP)
+            return TRUE;
+    }
+
     GetEventHandler()->ProcessEvent( event ) ;
 
     return TRUE;
index 0c742d371990ddf9d1dd0112153276d79562a89b..7ab64897097f3cc205d29f6bee79fa5730cedf58 100644 (file)
@@ -183,7 +183,9 @@ void wxTextCtrl::SetValue(const wxString& st)
     else
         value = st ;
     ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+
     MacRedrawControl() ;
+    Update();
 }
 
 // Clipboard operations
@@ -194,10 +196,10 @@ void wxTextCtrl::Copy()
         TEHandle teH ;
         long size ;
    
-                 ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-                   TECopy( teH ) ;
+          ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECopy( teH ) ;
         ClearCurrentScrap();
-                   TEToScrap() ;
+            TEToScrap() ;
     }
 }
 
@@ -208,12 +210,12 @@ void wxTextCtrl::Cut()
         TEHandle teH ;
         long size ;
    
-                 ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-                   TECut( teH ) ;
+          ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECut( teH ) ;
         ClearCurrentScrap();
-                   TEToScrap() ;
-                   //  MacInvalidateControl() ;
-         }
+            TEToScrap() ;
+            //  MacInvalidateControl() ;
+      }
 }
 
 void wxTextCtrl::Paste()
@@ -1277,40 +1279,40 @@ bail:
 
 
 /* mUPOpenControl initializes a user pane control so it will be drawn
-       and will behave as a scrolling text edit field inside of a window.
-       This routine performs all of the initialization steps necessary,
-       except it does not create the user pane control itself.  theControl
-       should refer to a user pane control that you have either created
-       yourself or extracted from a dialog's control heirarchy using
-       the GetDialogItemAsControl routine.  */
+    and will behave as a scrolling text edit field inside of a window.
+    This routine performs all of the initialization steps necessary,
+    except it does not create the user pane control itself.  theControl
+    should refer to a user pane control that you have either created
+    yourself or extracted from a dialog's control heirarchy using
+    the GetDialogItemAsControl routine.  */
 OSStatus mUPOpenControl(ControlHandle theControl, bool multiline) {
-       Rect bounds;
-       WindowPtr theWindow;
-       STPTextPaneVars **tpvars, *varsp;
-       OSStatus err;
-       RGBColor rgbWhite = {0xFFFF, 0xFFFF, 0xFFFF};
-       TXNBackground tback;
-       
-               /* set up our globals */
-       if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc);
-       if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(TPPaneHitTestProc);
-       if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(TPPaneTrackingProc);
-       if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(TPPaneIdleProc);
-       if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc);
-       if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(TPPaneActivateProc);
-       if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc);
-               
-               /* allocate our private storage */
-       tpvars = (STPTextPaneVars **) NewHandleClear(sizeof(STPTextPaneVars));
-       SetControlReference(theControl, (long) tpvars);
-       HLock((Handle) tpvars);
-       varsp = *tpvars;
-               /* set the initial settings for our private data */
-       varsp->fInFocus = false;
-       varsp->fIsActive = true;
-       varsp->fTEActive = false;
-       varsp->fUserPaneRec = theControl;
-       theWindow = varsp->fOwner = GetControlOwner(theControl);
+    Rect bounds;
+    WindowPtr theWindow;
+    STPTextPaneVars **tpvars, *varsp;
+    OSStatus err;
+    RGBColor rgbWhite = {0xFFFF, 0xFFFF, 0xFFFF};
+    TXNBackground tback;
+    
+        /* set up our globals */
+    if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc);
+    if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(TPPaneHitTestProc);
+    if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(TPPaneTrackingProc);
+    if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(TPPaneIdleProc);
+    if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc);
+    if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(TPPaneActivateProc);
+    if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc);
+        
+        /* allocate our private storage */
+    tpvars = (STPTextPaneVars **) NewHandleClear(sizeof(STPTextPaneVars));
+    SetControlReference(theControl, (long) tpvars);
+    HLock((Handle) tpvars);
+    varsp = *tpvars;
+        /* set the initial settings for our private data */
+    varsp->fInFocus = false;
+    varsp->fIsActive = true;
+    varsp->fTEActive = false;
+    varsp->fUserPaneRec = theControl;
+    theWindow = varsp->fOwner = GetControlOwner(theControl);
 #if TARGET_CARBON
     varsp->fDrawingEnvironment = GetWindowPort(varsp->fOwner);
 #else
@@ -1838,16 +1840,16 @@ void wxTextCtrl::Copy()
             TEHandle teH ;
             long size ;
        
-                ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-               TECopy( teH ) ;
-               ClearCurrentScrap();
-               TEToScrap() ;
-       }
-       else
-       {
-         mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
-       }
-       }
+             ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECopy( teH ) ;
+            ClearCurrentScrap();
+            TEToScrap() ;
+        }
+        else
+        {
+          mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
+        }
+    }
 }
 
 void wxTextCtrl::Cut()
@@ -1859,17 +1861,17 @@ void wxTextCtrl::Cut()
             TEHandle teH ;
             long size ;
        
-                       ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-               TECut( teH ) ;
-               ClearCurrentScrap();
-               TEToScrap() ;
-               //      MacInvalidateControl() ;
+            ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECut( teH ) ;
+            ClearCurrentScrap();
+            TEToScrap() ;
+            //  MacInvalidateControl() ;
+    }
+        else
+        {
+          mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
+        }
     }
-       else
-       {
-         mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
-       }
-       }
 }
 
 void wxTextCtrl::Paste()
@@ -1881,16 +1883,16 @@ void wxTextCtrl::Paste()
             TEHandle teH ;
             long size ;
      
-               ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-               TEFromScrap() ;
-               TEPaste( teH ) ;
+            ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        TEFromScrap() ;
+        TEPaste( teH ) ;
       MacRedrawControl() ;
-       }
-       else
-       {
-         mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
-       }
-       }
+    }
+    else
+    {
+      mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
+    }
+    }
 }
 
 bool wxTextCtrl::CanCopy() const
@@ -1986,22 +1988,22 @@ long wxTextCtrl::GetLastPosition() const
   }
   else
   {
-     STPTextPaneVars** tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
+     STPTextPaneVars**  tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
     int actualsize = 0 ;
-       Handle theText ;
-       OSErr err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
-               /* all done */
-       if ( err )
-       {
-         actualsize = 0 ;
-       }
-       else
-       {
-         actualsize = GetHandleSize( theText ) ;
-         DisposeHandle( theText ) ;
-       }
-       return actualsize ;
+    Handle theText ;
+    OSErr err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
+        /* all done */
+    if ( err )
+    {
+      actualsize = 0 ;
+    }
+    else
+    {
+      actualsize = GetHandleSize( theText ) ;
+      DisposeHandle( theText ) ;
+    }
+    return actualsize ;
   }
 }
 
@@ -2014,19 +2016,19 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
     ControlEditTextSelectionRec selection ;
    
-       selection.selStart = from ;
-       selection.selEnd = to ;
-       ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-               ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-       TESetSelect( from , to  , teH ) ;
-       TEDelete( teH ) ;
-               TEInsert( value , value.Length() , teH ) ;
-       }
-       else
-       {
-         // TODO
-       }
-       Refresh() ;
+    selection.selStart = from ;
+    selection.selEnd = to ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    TESetSelect( from , to  , teH ) ;
+    TEDelete( teH ) ;
+        TEInsert( value , value.Length() , teH ) ;
+    }
+    else
+    {
+      // TODO
+    }
+    Refresh() ;
 }
 
 void wxTextCtrl::Remove(long from, long to)
@@ -2038,11 +2040,11 @@ void wxTextCtrl::Remove(long from, long to)
    
     ControlEditTextSelectionRec selection ;
    
-       selection.selStart = from ;
-       selection.selEnd = to ;
-       ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-       ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-       TEDelete( teH ) ;
+    selection.selStart = from ;
+    selection.selEnd = to ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    TEDelete( teH ) ;
   }
   else
   {
@@ -2134,7 +2136,7 @@ void wxTextCtrl::Clear()
   {
     mUPDoEditCommand( (ControlHandle) m_macControl , kmUPClear) ;
   }
-       Refresh() ;
+    Refresh() ;
 }
 
 bool wxTextCtrl::IsModified() const
@@ -2219,13 +2221,13 @@ int wxTextCtrl::GetNumberOfLines() const
 {
   // TODO change this if possible to reflect real lines
   wxString content = GetValue() ;
-       
-       int count = 1;
-       for (int i = 0; i < content.Length() ; i++)
-       {
-           if (content[i] == '\r') count++;
-       }
-       
+    
+    int count = 1;
+    for (int i = 0; i < content.Length() ; i++)
+    {
+        if (content[i] == '\r') count++;
+    }
+    
   return count;
 }
 
@@ -2249,25 +2251,25 @@ int wxTextCtrl::GetLineLength(long lineNo) const
 {
   // TODO change this if possible to reflect real lines
   wxString content = GetValue() ;
-       
-       // Find line first
-       int count = 0;
-       for (int i = 0; i < content.Length() ; i++)
-       {
-           if (count == lineNo)
-           {
-               // Count chars in line then
-               count = 0;
-               for (int j = i; j < content.Length(); j++)
-               {
-                   count++;
-                   if (content[j] == '\r') return count;
-               }
-               
-               return count;
-           }
-           if (content[i] == '\r') count++;
-       }
+    
+    // Find line first
+    int count = 0;
+    for (int i = 0; i < content.Length() ; i++)
+    {
+        if (count == lineNo)
+        {
+            // Count chars in line then
+            count = 0;
+            for (int j = i; j < content.Length(); j++)
+            {
+                count++;
+                if (content[j] == '\r') return count;
+            }
+            
+            return count;
+        }
+        if (content[i] == '\r') count++;
+    }
     return 0;
 }
 
@@ -2276,27 +2278,27 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
   // TODO change this if possible to reflect real lines
   wxString content = GetValue() ;
 
-       // Find line first
-       int count = 0;
-       for (int i = 0; i < content.Length() ; i++)
-       {
-           if (count == lineNo)
-           {
-               // Add chars in line then
-               wxString tmp("");
-               
-               for (int j = i; j < content.Length(); j++)
-               {
-                   if (content[j] == '\r')
-                       return tmp;
-                       
-                   tmp += content[j];
-               }
-               
-               return tmp;
-           }
-           if (content[i] == '\r') count++;
-       }
+    // Find line first
+    int count = 0;
+    for (int i = 0; i < content.Length() ; i++)
+    {
+        if (count == lineNo)
+        {
+            // Add chars in line then
+            wxString tmp("");
+            
+            for (int j = i; j < content.Length(); j++)
+            {
+                if (content[j] == '\r')
+                    return tmp;
+                    
+                tmp += content[j];
+            }
+            
+            return tmp;
+        }
+        if (content[i] == '\r') count++;
+    }
     return wxString("");
 }
 
index 8db3f7e902143b929de3273c07e21413c9e0cef5..06ed4068548df4bc109e181a9935b9cc4f065949 100644 (file)
 // ----------------------------------------------------------------------------
 
 // list of all frames and modeless dialogs
-wxWindowList wxModelessWindows;
+wxWindowList       wxModelessWindows;
+
+// double click testing
+static   Point     gs_lastWhere;
+static   long      gs_lastWhen = 0;
+
+// cursor stuff
+extern   int       wxBusyCursorCount;
+
 
 // ============================================================================
 // wxTopLevelWindowMac implementation
@@ -347,10 +355,6 @@ void wxTopLevelWindowMac::Lower()
     ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
 }
 
-Point lastWhere ;
-long lastWhen = 0 ;
-extern int wxBusyCursorCount ;
-
 void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
 {
     EventRecord *ev = (EventRecord*) evr ;
@@ -397,22 +401,25 @@ void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
 
     if ( ev->what == mouseDown )
     {
-        if ( ev->when - lastWhen <= GetDblTime() )
+        if ( ev->when - gs_lastWhen <= GetDblTime() )
         {
-            if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
+            if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
             {
+                // This is not right if the second mouse down
+                // event occured in a differen window. We
+                // correct this in MacDispatchMouseEvent.
                 if ( controlDown )
                     event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
                 else
                     event.SetEventType(wxEVT_LEFT_DCLICK ) ;
             }
-            lastWhen = 0 ;
+            gs_lastWhen = 0 ;
         }
         else
         {
-            lastWhen = ev->when ;
+            gs_lastWhen = ev->when ;
         }
-        lastWhere = localwhere ;
+        gs_lastWhere = localwhere ;
     }
 
     event.m_x = localwhere.h;
index 9d9fdb5cc6e1a2208b6bf25cb708a92df80dd327..e6b1ba5c7c6113f7002a79c448e23989ac9fb78c 100644 (file)
@@ -1386,6 +1386,7 @@ bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMa
 }
 
 extern int wxBusyCursorCount ;
+static wxWindow *gs_lastWhich = NULL;
 
 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
 {
@@ -1438,6 +1439,23 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
         wxToolTip::RelayEvent( this , event);
 #endif // wxUSE_TOOLTIPS
 
+    if (gs_lastWhich != this)
+    {
+        gs_lastWhich = this;
+        
+        // Double clicks must always occur on the same window
+        if (event.GetEventType() == wxEVT_LEFT_DCLICK)
+            event.SetEventType( wxEVT_LEFT_DOWN );
+        if (event.GetEventType() == wxEVT_RIGHT_DCLICK)
+            event.SetEventType( wxEVT_RIGHT_DOWN );
+            
+        // Same for mouse up events
+        if (event.GetEventType() == wxEVT_LEFT_UP)
+            return TRUE;
+        if (event.GetEventType() == wxEVT_RIGHT_UP)
+            return TRUE;
+    }
+
     GetEventHandler()->ProcessEvent( event ) ;
 
     return TRUE;