]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/window.cpp
1. wxMenu{Item|Bar} modifications for wxMotif
[wxWidgets.git] / src / motif / window.cpp
index 87a3090c26fdddafba7d0f154cc63d6515f22d1a..0959d93286fffd8195c1c65ea24888c5fb0794c7 100644 (file)
@@ -40,8 +40,6 @@
 #include "wx/menuitem.h"
 #include "wx/log.h"
 
-#include "wx/listimpl.cpp"
-
 #if  wxUSE_DRAG_AND_DROP
     #include "wx/dnd.h"
 #endif
@@ -80,7 +78,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,
-                                XmScaleCallbackStruct *cbs);
+                                XmScrollBarCallbackStruct *cbs);
 static void wxPanelItemEventHandler(Widget    wid,
                                     XtPointer client_data,
                                     XEvent*   event,
@@ -117,9 +115,9 @@ static int str16len(const char *s)
 // ----------------------------------------------------------------------------
 
 #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()
@@ -129,12 +127,6 @@ static int str16len(const char *s)
 // implementation
 // ============================================================================
 
-// ----------------------------------------------------------------------------
-// list types
-// ----------------------------------------------------------------------------
-
-WX_DEFINE_LIST(wxRectList);
-
 // ----------------------------------------------------------------------------
 // helper functions
 // ----------------------------------------------------------------------------
@@ -183,7 +175,8 @@ void wxWindow::Init()
     m_winCaptured = FALSE;
 
     m_isShown = TRUE;
-
+    m_isBeingDeleted = FALSE;
+    
     m_hScrollBar =
     m_vScrollBar =
     m_borderWidget =
@@ -217,7 +210,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
 {
     wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
 
-    CreateBase(parent, id, pos, size, style, name);
+    CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
 
     parent->AddChild(this);
 
@@ -360,6 +353,8 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
 // Destructor
 wxWindow::~wxWindow()
 {
+    m_isBeingDeleted = TRUE;
+    
     // Motif-specific actions first
     WXWidget wMain = GetMainWidget();
     if ( wMain )
@@ -399,6 +394,15 @@ wxWindow::~wxWindow()
             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);
@@ -467,6 +471,8 @@ void wxWindow::CreateScrollbar(wxOrientation orientation)
             NULL);
 
         m_hScroll = TRUE;
+
+        wxAddWindowToTable( hScrollBar, this );
     }
 
     if (orientation == wxVERTICAL)
@@ -500,6 +506,8 @@ void wxWindow::CreateScrollbar(wxOrientation orientation)
             NULL);
 
         m_vScroll = TRUE;
+
+        wxAddWindowToTable( vScrollBar, this );
     }
 
     XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
@@ -515,6 +523,7 @@ void wxWindow::DestroyScrollbar(wxOrientation orientation)
     {
         if (m_hScrollBar)
         {
+            wxDeleteWindowFromTable((Widget)m_hScrollBar);
             XtDestroyWidget((Widget) m_hScrollBar);
         }
         m_hScrollBar = (WXWidget) 0;
@@ -530,6 +539,7 @@ void wxWindow::DestroyScrollbar(wxOrientation orientation)
     {
         if (m_vScrollBar)
         {
+            wxDeleteWindowFromTable((Widget)m_vScrollBar);
             XtDestroyWidget((Widget) m_vScrollBar);
         }
         m_vScrollBar = (WXWidget) 0;
@@ -701,7 +711,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor)
     }
 
     wxASSERT_MSG( m_cursor.Ok(),
-                  _T("cursor must be valid after call to the base version"));
+                  wxT("cursor must be valid after call to the base version"));
 
     WXDisplay *dpy = GetXDisplay();
     WXCursor x_cursor = m_cursor.GetXCursor(dpy);
@@ -1381,12 +1391,12 @@ void wxWindow::GetTextExtent(const wxString& string,
         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;
-    int slen;
+    int slen = string.Len();
 
 #if 0
     if (use16)
@@ -1405,6 +1415,7 @@ void wxWindow::GetTextExtent(const wxString& string,
         *descent = descent2;
     if (externalLeading)
         *externalLeading = 0;
+
 }
 
 // ----------------------------------------------------------------------------
@@ -1572,7 +1583,7 @@ void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
     }
 }
 
-void wxWindow::OnIdle(wxIdleEvent& event)
+void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
 {
     // This calls the UI-update mechanism (querying windows for
     // menu/toolbar/control state information)
@@ -1671,6 +1682,9 @@ bool wxAddWindowToTable(Widget w, wxWindow *win)
 
     wxWidgetHashTable->Put((long) w, win);
 
+    wxLogDebug("Widget 0x%08x <-> window %p (%s)",
+               w, win, win->GetClassInfo()->GetClassName());
+
     return TRUE;
 }
 
@@ -1689,7 +1703,7 @@ void wxDeleteWindowFromTable(Widget w)
 // ----------------------------------------------------------------------------
 
 // Add to hash table, add event handler
-bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget,
+bool wxWindow::AttachWidget (wxWindow* WXUNUSED(parent), WXWidget mainWidget,
                              WXWidget formWidget, int x, int y, int width, int height)
 {
     wxAddWindowToTable((Widget) mainWidget, this);
@@ -1803,7 +1817,7 @@ WXWidget wxWindow::GetLabelWidget() const
 
 // All widgets should have this as their resize proc.
 // OnSize sent to wxWindow via client data.
-void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args)
+void wxWidgetResizeProc(Widget w, XConfigureEvent *WXUNUSED(event), String WXUNUSED(args)[], int *WXUNUSED(num_args))
 {
     wxWindow *win = wxGetWindowFromTable(w);
     if (!win)
@@ -1833,22 +1847,14 @@ static void wxCanvasRepaintProc(Widget drawingArea,
     {
     case Expose:
         {
+            win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
+                               event->xexpose.width, event->xexpose.height);
+            
             if (event -> xexpose.count == 0)
             {
-#if 0
-                wxPaintEvent event(win->GetId());
-                event.SetEventObject(win);
-                win->GetEventHandler()->ProcessEvent(event);
-#endif // 0
-
                 win->DoPaint();
                 win->ClearUpdateRects();
             }
-            else
-            {
-                win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
-                                   event->xexpose.width, event->xexpose.height);
-            }
             break;
         }
     }
@@ -1856,7 +1862,7 @@ static void wxCanvasRepaintProc(Widget drawingArea,
 
 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
 static void wxCanvasEnterLeave(Widget drawingArea,
-                               XtPointer clientData,
+                               XtPointer WXUNUSED(clientData),
                                XCrossingEvent * event)
 {
     XmDrawingAreaCallbackStruct cbs;
@@ -1871,7 +1877,7 @@ static void wxCanvasEnterLeave(Widget drawingArea,
 }
 
 // Fix to make it work under Motif 1.0 (!)
-static void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event)
+static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea), XButtonEvent * WXUNUSED(event))
 {
 #if XmVersion <= 1000
     XmDrawingAreaCallbackStruct cbs;
@@ -1886,7 +1892,7 @@ static void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event)
 }
 
 static void wxCanvasInputEvent(Widget drawingArea,
-                               XtPointer data,
+                               XtPointer WXUNUSED(data),
                                XmDrawingAreaCallbackStruct * cbs)
 {
     wxWindow *canvas = wxGetWindowFromTable(drawingArea);
@@ -1908,6 +1914,9 @@ static void wxCanvasInputEvent(Widget drawingArea,
     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)
@@ -1919,7 +1928,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
             }
             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();
@@ -2169,7 +2178,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
 }
 
 static void wxPanelItemEventHandler(Widget    wid,
-                                    XtPointer client_data,
+                                    XtPointer WXUNUSED(client_data),
                                     XEvent*   event,
                                     Boolean  *continueToDispatch)
 {
@@ -2197,7 +2206,7 @@ static void wxPanelItemEventHandler(Widget    wid,
 
 static void wxScrollBarCallback(Widget scrollbar,
                                 XtPointer clientData,
-                                XmScaleCallbackStruct *cbs)
+                                XmScrollBarCallbackStruct *cbs)
 {
     wxWindow *win = wxGetWindowFromTable(scrollbar);
     int orientation = (int) clientData;
@@ -2207,44 +2216,44 @@ static void wxScrollBarCallback(Widget scrollbar,
     {
     case XmCR_INCREMENT:
         {
-            eventType = wxEVT_SCROLL_LINEDOWN;
+            eventType = wxEVT_SCROLLWIN_LINEDOWN;
             break;
         }
     case XmCR_DECREMENT:
         {
-            eventType = wxEVT_SCROLL_LINEUP;
+            eventType = wxEVT_SCROLLWIN_LINEUP;
             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?
-            eventType = wxEVT_SCROLL_THUMBTRACK;
+            eventType = wxEVT_SCROLLWIN_THUMBTRACK;
             break;
         }
     case XmCR_PAGE_INCREMENT:
         {
-            eventType = wxEVT_SCROLL_PAGEDOWN;
+            eventType = wxEVT_SCROLLWIN_PAGEDOWN;
             break;
         }
     case XmCR_PAGE_DECREMENT:
         {
-            eventType = wxEVT_SCROLL_PAGEUP;
+            eventType = wxEVT_SCROLLWIN_PAGEUP;
             break;
         }
     case XmCR_TO_TOP:
         {
-            eventType = wxEVT_SCROLL_TOP;
+            eventType = wxEVT_SCROLLWIN_TOP;
             break;
         }
     case XmCR_TO_BOTTOM:
         {
-            eventType = wxEVT_SCROLL_BOTTOM;
+            eventType = wxEVT_SCROLLWIN_BOTTOM;
             break;
         }
     default:
@@ -2255,11 +2264,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);
 }
 
@@ -2528,14 +2537,16 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
 {
     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;
 
+            // FIXME: this is never true I think - MB
+            //
             if (xevent->xany.type == LeaveNotify)
             {
                 win->SetButton1(FALSE);
@@ -2549,20 +2560,59 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
             }
             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);
+                    button = 1;
                 }
                 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);
+                    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)
@@ -2623,17 +2673,24 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
 
             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 FALSE;
 }
 
-bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
+bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget WXUNUSED(widget), XEvent *xevent)
 {
     switch (xevent->xany.type)
     {
     case KeyPress:
+    case KeyRelease:
         {
             char buf[20];
 
@@ -2871,3 +2928,7 @@ wxWindow *wxGetActiveWindow()
 // ----------------------------------------------------------------------------
 
 int wxNoOptimize::ms_count = 0;
+
+
+
+