]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/window.cpp
added new project file having the new files
[wxWidgets.git] / src / motif / window.cpp
index f251d7492e6022f273483a64166d85c59cb22111..b2f4037d0ee0468160dabd288c1e339242a7ce7e 100644 (file)
     #pragma implementation "window.h"
 #endif
 
     #pragma implementation "window.h"
 #endif
 
+#ifdef __VMS
+#define XtDisplay XTDISPLAY
+#define XtWindow XTWINDOW
+#define XtScreen XTSCREEN
+#endif
+
 #include "wx/setup.h"
 #include "wx/menu.h"
 #include "wx/dc.h"
 #include "wx/setup.h"
 #include "wx/menu.h"
 #include "wx/dc.h"
@@ -74,6 +80,8 @@ static const int SCROLL_MARGIN = 4;
 // ----------------------------------------------------------------------------
 
 extern wxHashTable *wxWidgetHashTable;
 // ----------------------------------------------------------------------------
 
 extern wxHashTable *wxWidgetHashTable;
+static wxWindow* g_captureWindow = NULL;
+
 
 // ----------------------------------------------------------------------------
 // private functions
 
 // ----------------------------------------------------------------------------
 // private functions
@@ -377,6 +385,9 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
 // Destructor
 wxWindow::~wxWindow()
 {
 // Destructor
 wxWindow::~wxWindow()
 {
+    if (g_captureWindow == this)
+       g_captureWindow = NULL;
+    
     m_isBeingDeleted = TRUE;
     
     // Motif-specific actions first
     m_isBeingDeleted = TRUE;
     
     // Motif-specific actions first
@@ -408,10 +419,9 @@ wxWindow::~wxWindow()
         if (w)
         {
             XtDestroyWidget(w);
         if (w)
         {
             XtDestroyWidget(w);
+           m_drawingArea = (WXWidget) 0;
         }
 
         }
 
-        m_mainWidget = (WXWidget) 0;
-
         // Only if we're _really_ a canvas (not a dialog box/panel)
         if (m_scrolledWindow)
         {
         // Only if we're _really_ a canvas (not a dialog box/panel)
         if (m_scrolledWindow)
         {
@@ -421,14 +431,19 @@ wxWindow::~wxWindow()
         if (m_hScrollBar)
         {
             wxDeleteWindowFromTable((Widget) m_hScrollBar);
         if (m_hScrollBar)
         {
             wxDeleteWindowFromTable((Widget) m_hScrollBar);
+           XtUnmanageChild((Widget) m_hScrollBar);
         }
         if (m_vScrollBar)
         {
             wxDeleteWindowFromTable((Widget) m_vScrollBar);
         }
         if (m_vScrollBar)
         {
             wxDeleteWindowFromTable((Widget) m_vScrollBar);
+           XtUnmanageChild((Widget) m_vScrollBar);
         }
 
         }
 
-        UnmanageAndDestroy(m_hScrollBar);
-        UnmanageAndDestroy(m_vScrollBar);
+        if (m_hScrollBar)
+           XtDestroyWidget((Widget) m_hScrollBar);
+        if (m_vScrollBar)
+           XtDestroyWidget((Widget) m_vScrollBar);
+
         UnmanageAndDestroy(m_scrolledWindow);
 
         if (m_borderWidget)
         UnmanageAndDestroy(m_scrolledWindow);
 
         if (m_borderWidget)
@@ -437,6 +452,9 @@ wxWindow::~wxWindow()
             m_borderWidget = (WXWidget) 0;
         }
     }
             m_borderWidget = (WXWidget) 0;
         }
     }
+    else // Why wasn't this here before? JACS 8/3/2000
+        DestroyChildren();
+
 
     // Destroy the window
     if (GetMainWidget())
 
     // Destroy the window
     if (GetMainWidget())
@@ -451,7 +469,8 @@ wxWindow::~wxWindow()
         //   wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
         //   that this call crashed wxMotif under OS/2, so it seems
         //   that leaving it out is the right thing to do.
         //   wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
         //   that this call crashed wxMotif under OS/2, so it seems
         //   that leaving it out is the right thing to do.
-//        XtDestroyWidget((Widget) GetMainWidget());
+        // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
+        XtDestroyWidget((Widget) GetMainWidget());
         SetMainWidget((WXWidget) NULL);
     }
 }
         SetMainWidget((WXWidget) NULL);
     }
 }
@@ -572,7 +591,7 @@ void wxWindow::DestroyScrollbar(wxOrientation orientation)
             XtDestroyWidget((Widget) m_vScrollBar);
         }
         m_vScrollBar = (WXWidget) 0;
             XtDestroyWidget((Widget) m_vScrollBar);
         }
         m_vScrollBar = (WXWidget) 0;
-        m_vScroll = TRUE;
+        m_vScroll = FALSE;
 
         XtVaSetValues((Widget) m_scrolledWindow,
             XmNverticalScrollBar, (Widget) 0,
 
         XtVaSetValues((Widget) m_scrolledWindow,
             XmNverticalScrollBar, (Widget) 0,
@@ -696,6 +715,7 @@ wxString wxWindow::GetTitle() const
 
 void wxWindow::CaptureMouse()
 {
 
 void wxWindow::CaptureMouse()
 {
+    g_captureWindow = this;
     if ( m_winCaptured )
         return;
 
     if ( m_winCaptured )
         return;
 
@@ -708,6 +728,7 @@ void wxWindow::CaptureMouse()
 
 void wxWindow::ReleaseMouse()
 {
 
 void wxWindow::ReleaseMouse()
 {
+    g_captureWindow = NULL;
     if ( !m_winCaptured )
         return;
 
     if ( !m_winCaptured )
         return;
 
@@ -739,11 +760,16 @@ bool wxWindow::SetCursor(const wxCursor& cursor)
         return FALSE;
     }
 
         return FALSE;
     }
 
-    wxASSERT_MSG( m_cursor.Ok(),
-                  wxT("cursor must be valid after call to the base version"));
+    //    wxASSERT_MSG( m_cursor.Ok(),
+    //                  wxT("cursor must be valid after call to the base version"));
+    wxCursor* cursor2 = NULL;
+    if (m_cursor.Ok())
+        cursor2 = & m_cursor;
+    else
+        cursor2 = wxSTANDARD_CURSOR;
 
     WXDisplay *dpy = GetXDisplay();
 
     WXDisplay *dpy = GetXDisplay();
-    WXCursor x_cursor = m_cursor.GetXCursor(dpy);
+    WXCursor x_cursor = cursor2->GetXCursor(dpy);
 
     Widget w = (Widget) GetMainWidget();
     Window win = XtWindow(w);
 
     Widget w = (Widget) GetMainWidget();
     Window win = XtWindow(w);
@@ -1186,7 +1212,7 @@ void wxWindow::DoGetSize(int *x, int *y) const
     Widget widget = (Widget) GetTopWidget();
     Dimension xx, yy;
     XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
     Widget widget = (Widget) GetTopWidget();
     Dimension xx, yy;
     XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
-    *x = xx; *y = yy;
+    if(x) *x = xx; if(y) *y = yy;
 }
 
 void wxWindow::DoGetPosition(int *x, int *y) const
 }
 
 void wxWindow::DoGetPosition(int *x, int *y) const
@@ -1209,7 +1235,7 @@ void wxWindow::DoGetPosition(int *x, int *y) const
         yy -= pt.y;
     }
 
         yy -= pt.y;
     }
 
-    *x = xx; *y = yy;
+    if(x) *x = xx; if(y) *y = yy;
 }
 
 void wxWindow::DoScreenToClient(int *x, int *y) const
 }
 
 void wxWindow::DoScreenToClient(int *x, int *y) const
@@ -1245,7 +1271,7 @@ void wxWindow::DoGetClientSize(int *x, int *y) const
     Widget widget = (Widget) GetClientWidget();
     Dimension xx, yy;
     XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
     Widget widget = (Widget) GetClientWidget();
     Dimension xx, yy;
     XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
-    *x = xx; *y = yy;
+    if(x) *x = xx; if(y) *y = yy;
 }
 
 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 }
 
 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
@@ -1650,8 +1676,8 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
         wxAcceleratorEntry* entry = & (entries[i]);
         if (entry->MatchesEvent(event))
         {
         wxAcceleratorEntry* entry = & (entries[i]);
         if (entry->MatchesEvent(event))
         {
-            // Bingo, we have a match. Now find a control that matches the entry
-            // command id.
+            // Bingo, we have a match. Now find a control that matches the
+           // entry command id.
 
             // Need to go up to the top of the window hierarchy, since it might
             // be e.g. a menu item
 
             // Need to go up to the top of the window hierarchy, since it might
             // be e.g. a menu item
@@ -2080,22 +2106,21 @@ static void wxCanvasInputEvent(Widget drawingArea,
                     {
                         // I have a dclick
                         canvas->SetLastClick(0, ts);
                     {
                         // I have a dclick
                         canvas->SetLastClick(0, ts);
-                        switch ( eventType )
+
+                        wxEventType typeDouble;
+                        if ( eventType == wxEVT_LEFT_DOWN )
+                            typeDouble = wxEVT_LEFT_DCLICK;
+                        else if ( eventType == wxEVT_MIDDLE_DOWN )
+                            typeDouble = wxEVT_MIDDLE_DCLICK;
+                        else if ( eventType == wxEVT_RIGHT_DOWN )
+                            typeDouble = wxEVT_RIGHT_DCLICK;
+                        else
+                            typeDouble = wxEVT_NULL;
+
+                        if ( typeDouble != wxEVT_NULL )
                         {
                         {
-                        case wxEVT_LEFT_DOWN:
-                            wxevent.SetEventType(wxEVT_LEFT_DCLICK);
-                            break;
-                        case wxEVT_MIDDLE_DOWN:
-                            wxevent.SetEventType(wxEVT_MIDDLE_DCLICK);
-                            break;
-                        case wxEVT_RIGHT_DOWN:
-                            wxevent.SetEventType(wxEVT_RIGHT_DCLICK);
-                            break;
-
-                        default :
-                            break;
+                            wxevent.SetEventType(typeDouble);
                         }
                         }
-
                     }
                     else
                     {
                     }
                     else
                     {
@@ -2637,22 +2662,12 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
                 {
                     // I have a dclick
                     win->SetLastClick(0, ts);
                 {
                     // 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;
-                    }
-                    
+                    if ( eventType == wxEVT_LEFT_DOWN )
+                        eventType = wxEVT_LEFT_DCLICK;
+                    else if ( eventType == wxEVT_MIDDLE_DOWN )
+                        eventType = wxEVT_MIDDLE_DCLICK;
+                    else if ( eventType == wxEVT_RIGHT_DOWN )
+                        eventType = wxEVT_RIGHT_DCLICK;
                 }
                 else
                 {
                 }
                 else
                 {
@@ -2965,15 +2980,45 @@ void wxWindow::ChangeFont(bool keepOriginalSize)
 wxWindow *wxGetActiveWindow()
 {
     // TODO
 wxWindow *wxGetActiveWindow()
 {
     // TODO
+    wxFAIL_MSG("Not implemented");
     return NULL;
 }
 
     return NULL;
 }
 
+/* static */
+wxWindow *wxWindowBase::GetCapture()
+{
+    return (wxWindow *)g_captureWindow;
+}
+
+
+// Find the wxWindow at the current mouse position, returning the mouse
+// position.
+wxWindow* wxFindWindowAtPointer(wxPoint& pt)
+{
+    return wxFindWindowAtPoint(wxGetMousePosition());
+}
+
+// Get the current mouse position.
+wxPoint wxGetMousePosition()
+{
+    Display *display = (Display*) wxGetDisplay();
+    Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
+    Window rootReturn, childReturn;
+    int rootX, rootY, winX, winY;
+    unsigned int maskReturn;
+
+    XQueryPointer (display,
+                  rootWindow,
+                  &rootReturn,
+                   &childReturn,
+                   &rootX, &rootY, &winX, &winY, &maskReturn);
+    return wxPoint(rootX, rootY);
+}
+
+
 // ----------------------------------------------------------------------------
 // wxNoOptimize: switch off size optimization
 // ----------------------------------------------------------------------------
 
 int wxNoOptimize::ms_count = 0;
 
 // ----------------------------------------------------------------------------
 // wxNoOptimize: switch off size optimization
 // ----------------------------------------------------------------------------
 
 int wxNoOptimize::ms_count = 0;
 
-
-
-