]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/window.cpp
Added comments
[wxWidgets.git] / src / motif / window.cpp
index f7ed6cb2bb455037f1c9c3b600e6d7e9850d6d15..498fbedec9e832ea37f97f938d1b0b4cde19dd8f 100644 (file)
@@ -80,7 +80,7 @@ static void wxCanvasInputEvent(Widget drawingArea, XtPointer data, XmDrawingArea
 static void wxCanvasMotionEvent(Widget, XButtonEvent * event);
 static void wxCanvasEnterLeave(Widget drawingArea, XtPointer clientData, XCrossingEvent * event);
 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
 static void wxCanvasMotionEvent(Widget, XButtonEvent * event);
 static void wxCanvasEnterLeave(Widget drawingArea, XtPointer clientData, XCrossingEvent * event);
 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
-                                XmScaleCallbackStruct *cbs);
+                                XmScrollBarCallbackStruct *cbs);
 static void wxPanelItemEventHandler(Widget    wid,
                                     XtPointer client_data,
                                     XEvent*   event,
 static void wxPanelItemEventHandler(Widget    wid,
                                     XtPointer client_data,
                                     XEvent*   event,
@@ -117,9 +117,9 @@ static int str16len(const char *s)
 // ----------------------------------------------------------------------------
 
 #if !USE_SHARED_LIBRARY
 // ----------------------------------------------------------------------------
 
 #if !USE_SHARED_LIBRARY
-    IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
+    IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
 
 
-    BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
+    BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
         EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
         EVT_IDLE(wxWindow::OnIdle)
     END_EVENT_TABLE()
         EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
         EVT_IDLE(wxWindow::OnIdle)
     END_EVENT_TABLE()
@@ -402,6 +402,15 @@ wxWindow::~wxWindow()
             wxDeleteWindowFromTable((Widget) m_scrolledWindow);
         }
 
             wxDeleteWindowFromTable((Widget) m_scrolledWindow);
         }
 
+        if (m_hScrollBar)
+        {
+            wxDeleteWindowFromTable((Widget) m_hScrollBar);
+        }
+        if (m_vScrollBar)
+        {
+            wxDeleteWindowFromTable((Widget) m_vScrollBar);
+        }
+
         UnmanageAndDestroy(m_hScrollBar);
         UnmanageAndDestroy(m_vScrollBar);
         UnmanageAndDestroy(m_scrolledWindow);
         UnmanageAndDestroy(m_hScrollBar);
         UnmanageAndDestroy(m_vScrollBar);
         UnmanageAndDestroy(m_scrolledWindow);
@@ -470,6 +479,8 @@ void wxWindow::CreateScrollbar(wxOrientation orientation)
             NULL);
 
         m_hScroll = TRUE;
             NULL);
 
         m_hScroll = TRUE;
+
+        wxAddWindowToTable( hScrollBar, this );
     }
 
     if (orientation == wxVERTICAL)
     }
 
     if (orientation == wxVERTICAL)
@@ -503,6 +514,8 @@ void wxWindow::CreateScrollbar(wxOrientation orientation)
             NULL);
 
         m_vScroll = TRUE;
             NULL);
 
         m_vScroll = TRUE;
+
+        wxAddWindowToTable( vScrollBar, this );
     }
 
     XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
     }
 
     XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
@@ -518,6 +531,7 @@ void wxWindow::DestroyScrollbar(wxOrientation orientation)
     {
         if (m_hScrollBar)
         {
     {
         if (m_hScrollBar)
         {
+            wxDeleteWindowFromTable((Widget)m_hScrollBar);
             XtDestroyWidget((Widget) m_hScrollBar);
         }
         m_hScrollBar = (WXWidget) 0;
             XtDestroyWidget((Widget) m_hScrollBar);
         }
         m_hScrollBar = (WXWidget) 0;
@@ -533,6 +547,7 @@ void wxWindow::DestroyScrollbar(wxOrientation orientation)
     {
         if (m_vScrollBar)
         {
     {
         if (m_vScrollBar)
         {
+            wxDeleteWindowFromTable((Widget)m_vScrollBar);
             XtDestroyWidget((Widget) m_vScrollBar);
         }
         m_vScrollBar = (WXWidget) 0;
             XtDestroyWidget((Widget) m_vScrollBar);
         }
         m_vScrollBar = (WXWidget) 0;
@@ -704,7 +719,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor)
     }
 
     wxASSERT_MSG( m_cursor.Ok(),
     }
 
     wxASSERT_MSG( m_cursor.Ok(),
-                  _T("cursor must be valid after call to the base version"));
+                  T("cursor must be valid after call to the base version"));
 
     WXDisplay *dpy = GetXDisplay();
     WXCursor x_cursor = m_cursor.GetXCursor(dpy);
 
     WXDisplay *dpy = GetXDisplay();
     WXCursor x_cursor = m_cursor.GetXCursor(dpy);
@@ -1384,12 +1399,12 @@ void wxWindow::GetTextExtent(const wxString& string,
         fontToUse = (wxFont *) & m_font;
 
     wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
         fontToUse = (wxFont *) & m_font;
 
     wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
-
+    
     WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
 
     int direction, ascent, descent2;
     XCharStruct overall;
     WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
 
     int direction, ascent, descent2;
     XCharStruct overall;
-    int slen;
+    int slen = string.Len();
 
 #if 0
     if (use16)
 
 #if 0
     if (use16)
@@ -1408,6 +1423,7 @@ void wxWindow::GetTextExtent(const wxString& string,
         *descent = descent2;
     if (externalLeading)
         *externalLeading = 0;
         *descent = descent2;
     if (externalLeading)
         *externalLeading = 0;
+
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
@@ -1839,22 +1855,14 @@ static void wxCanvasRepaintProc(Widget drawingArea,
     {
     case Expose:
         {
     {
     case Expose:
         {
+            win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
+                               event->xexpose.width, event->xexpose.height);
+            
             if (event -> xexpose.count == 0)
             {
             if (event -> xexpose.count == 0)
             {
-#if 0
-                wxPaintEvent event(win->GetId());
-                event.SetEventObject(win);
-                win->GetEventHandler()->ProcessEvent(event);
-#endif // 0
-
                 win->DoPaint();
                 win->ClearUpdateRects();
             }
                 win->DoPaint();
                 win->ClearUpdateRects();
             }
-            else
-            {
-                win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
-                                   event->xexpose.width, event->xexpose.height);
-            }
             break;
         }
     }
             break;
         }
     }
@@ -1914,6 +1922,9 @@ static void wxCanvasInputEvent(Widget drawingArea,
     case ButtonRelease:
     case MotionNotify:
         {
     case ButtonRelease:
     case MotionNotify:
         {
+            // FIXME: most of this mouse event code is more or less
+            // duplicated in wxTranslateMouseEvent
+            //
             wxEventType eventType = wxEVT_NULL;
 
             if (local_event.xany.type == EnterNotify)
             wxEventType eventType = wxEVT_NULL;
 
             if (local_event.xany.type == EnterNotify)
@@ -1925,7 +1936,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
             }
             else if (local_event.xany.type == LeaveNotify)
             {
             }
             else if (local_event.xany.type == LeaveNotify)
             {
-                //if (local_event.xcrossing.mode!=NotifyNormal)
+                //if (local_event.xcrossingr.mode!=NotifyNormal)
                 //  return ; // Ignore grab events
                 eventType = wxEVT_LEAVE_WINDOW;
                 //            canvas->GetEventHandler()->OnKillFocus();
                 //  return ; // Ignore grab events
                 eventType = wxEVT_LEAVE_WINDOW;
                 //            canvas->GetEventHandler()->OnKillFocus();
@@ -2203,7 +2214,7 @@ static void wxPanelItemEventHandler(Widget    wid,
 
 static void wxScrollBarCallback(Widget scrollbar,
                                 XtPointer clientData,
 
 static void wxScrollBarCallback(Widget scrollbar,
                                 XtPointer clientData,
-                                XmScaleCallbackStruct *cbs)
+                                XmScrollBarCallbackStruct *cbs)
 {
     wxWindow *win = wxGetWindowFromTable(scrollbar);
     int orientation = (int) clientData;
 {
     wxWindow *win = wxGetWindowFromTable(scrollbar);
     int orientation = (int) clientData;
@@ -2213,44 +2224,44 @@ static void wxScrollBarCallback(Widget scrollbar,
     {
     case XmCR_INCREMENT:
         {
     {
     case XmCR_INCREMENT:
         {
-            eventType = wxEVT_SCROLL_LINEDOWN;
+            eventType = wxEVT_SCROLLWIN_LINEDOWN;
             break;
         }
     case XmCR_DECREMENT:
         {
             break;
         }
     case XmCR_DECREMENT:
         {
-            eventType = wxEVT_SCROLL_LINEUP;
+            eventType = wxEVT_SCROLLWIN_LINEUP;
             break;
         }
     case XmCR_DRAG:
         {
             break;
         }
     case XmCR_DRAG:
         {
-            eventType = wxEVT_SCROLL_THUMBTRACK;
+            eventType = wxEVT_SCROLLWIN_THUMBTRACK;
             break;
         }
     case XmCR_VALUE_CHANGED:
         {
             // TODO: Should this be intercepted too, or will it cause
             // duplicate events?
             break;
         }
     case XmCR_VALUE_CHANGED:
         {
             // TODO: Should this be intercepted too, or will it cause
             // duplicate events?
-            eventType = wxEVT_SCROLL_THUMBTRACK;
+            eventType = wxEVT_SCROLLWIN_THUMBTRACK;
             break;
         }
     case XmCR_PAGE_INCREMENT:
         {
             break;
         }
     case XmCR_PAGE_INCREMENT:
         {
-            eventType = wxEVT_SCROLL_PAGEDOWN;
+            eventType = wxEVT_SCROLLWIN_PAGEDOWN;
             break;
         }
     case XmCR_PAGE_DECREMENT:
         {
             break;
         }
     case XmCR_PAGE_DECREMENT:
         {
-            eventType = wxEVT_SCROLL_PAGEUP;
+            eventType = wxEVT_SCROLLWIN_PAGEUP;
             break;
         }
     case XmCR_TO_TOP:
         {
             break;
         }
     case XmCR_TO_TOP:
         {
-            eventType = wxEVT_SCROLL_TOP;
+            eventType = wxEVT_SCROLLWIN_TOP;
             break;
         }
     case XmCR_TO_BOTTOM:
         {
             break;
         }
     case XmCR_TO_BOTTOM:
         {
-            eventType = wxEVT_SCROLL_BOTTOM;
+            eventType = wxEVT_SCROLLWIN_BOTTOM;
             break;
         }
     default:
             break;
         }
     default:
@@ -2261,11 +2272,11 @@ static void wxScrollBarCallback(Widget scrollbar,
         }
     }
 
         }
     }
 
-    wxScrollEvent event(eventType, win->GetId());
-    event.SetEventObject(win);
-    event.SetPosition(cbs->value);
-    event.SetOrientation( (orientation == XmHORIZONTAL) ? wxHORIZONTAL : wxVERTICAL );
-
+    wxScrollWinEvent event(eventType,
+                           cbs->value,
+                           ((orientation == XmHORIZONTAL) ?
+                            wxHORIZONTAL : wxVERTICAL));
+    event.SetEventObject( win );
     win->GetEventHandler()->ProcessEvent(event);
 }
 
     win->GetEventHandler()->ProcessEvent(event);
 }
 
@@ -2534,14 +2545,16 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
 {
     switch (xevent->xany.type)
     {
 {
     switch (xevent->xany.type)
     {
-    case EnterNotify:
-    case LeaveNotify:
-    case ButtonPress:
-    case ButtonRelease:
-    case MotionNotify:
+        case EnterNotify:  // never received here - yes ? MB
+        case LeaveNotify:  // never received here - yes ? MB
+        case ButtonPress:
+        case ButtonRelease:
+        case MotionNotify:
         {
             wxEventType eventType = wxEVT_NULL;
 
         {
             wxEventType eventType = wxEVT_NULL;
 
+            // FIXME: this is never true I think - MB
+            //
             if (xevent->xany.type == LeaveNotify)
             {
                 win->SetButton1(FALSE);
             if (xevent->xany.type == LeaveNotify)
             {
                 win->SetButton1(FALSE);
@@ -2555,20 +2568,59 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
             }
             else if (xevent->xany.type == ButtonPress)
             {
             }
             else if (xevent->xany.type == ButtonPress)
             {
+                wxevent.SetTimestamp(xevent->xbutton.time);
+                int button = 0;
                 if (xevent->xbutton.button == Button1)
                 {
                     eventType = wxEVT_LEFT_DOWN;
                     win->SetButton1(TRUE);
                 if (xevent->xbutton.button == Button1)
                 {
                     eventType = wxEVT_LEFT_DOWN;
                     win->SetButton1(TRUE);
+                    button = 1;
                 }
                 else if (xevent->xbutton.button == Button2)
                 {
                     eventType = wxEVT_MIDDLE_DOWN;
                     win->SetButton2(TRUE);
                 }
                 else if (xevent->xbutton.button == Button2)
                 {
                     eventType = wxEVT_MIDDLE_DOWN;
                     win->SetButton2(TRUE);
+                    button = 2;
                 }
                 else if (xevent->xbutton.button == Button3)
                 {
                     eventType = wxEVT_RIGHT_DOWN;
                     win->SetButton3(TRUE);
                 }
                 else if (xevent->xbutton.button == Button3)
                 {
                     eventType = wxEVT_RIGHT_DOWN;
                     win->SetButton3(TRUE);
+                    button = 3;
+                }
+
+                // check for a double click
+                //
+                long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay());
+                long ts = wxevent.GetTimestamp();
+
+                int buttonLast = win->GetLastClickedButton();
+                long lastTS = win->GetLastClickTime();
+                if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
+                {
+                    // I have a dclick
+                    win->SetLastClick(0, ts);
+                    switch ( eventType )
+                    {
+                        case wxEVT_LEFT_DOWN:
+                            eventType = wxEVT_LEFT_DCLICK;
+                            break;
+                        case wxEVT_MIDDLE_DOWN:
+                            eventType = wxEVT_MIDDLE_DCLICK;
+                            break;
+                        case wxEVT_RIGHT_DOWN:
+                            eventType = wxEVT_RIGHT_DCLICK;
+                            break;
+
+                        default :
+                            break;
+                    }
+                    
+                }
+                else
+                {
+                    // not fast enough or different button
+                    win->SetLastClick(button, ts);
                 }
             }
             else if (xevent->xany.type == ButtonRelease)
                 }
             }
             else if (xevent->xany.type == ButtonRelease)
@@ -2629,6 +2681,12 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
 
             wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
             wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
 
             wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
             wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
+            wxevent.m_altDown = xevent->xbutton.state & Mod3Mask;
+            wxevent.m_metaDown = xevent->xbutton.state & Mod1Mask;
+
+            wxevent.SetId(win->GetId());
+            wxevent.SetEventObject(win);
+
             return TRUE;
         }
     }
             return TRUE;
         }
     }
@@ -2878,3 +2936,7 @@ wxWindow *wxGetActiveWindow()
 // ----------------------------------------------------------------------------
 
 int wxNoOptimize::ms_count = 0;
 // ----------------------------------------------------------------------------
 
 int wxNoOptimize::ms_count = 0;
+
+
+
+