]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/frame.cpp
Better fix
[wxWidgets.git] / src / motif / frame.cpp
index 3e3b6605d98474f259355f4c6a355f13dfc2b53a..355b54f48a4ab7273bc1b0ac58809fed127233f4 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        motif/frame.cpp
+// Name:        src/motif/frame.cpp
 // Purpose:     wxFrame
 // Author:      Julian Smart
 // Modified by:
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
-    #pragma implementation "frame.h"
-#endif
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
 
+#include "wx/frame.h"
 
-#ifdef __VMS
-#define XtDisplay XTDISPLAY
-#define XtWindow XTWINDOW
-#define XtScreen XTSCREEN
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+    #include "wx/app.h"
+    #include "wx/utils.h"
+    #include "wx/menu.h"
+    #include "wx/icon.h"
+    #include "wx/settings.h"
+    #include "wx/toolbar.h"
+    #include "wx/statusbr.h"
 #endif
 
-#include "wx/frame.h"
-#include "wx/statusbr.h"
-#include "wx/toolbar.h"
-#include "wx/menu.h"
-#include "wx/settings.h"
-#include "wx/utils.h"
-#include "wx/log.h"
-#include "wx/app.h"
-
 #ifdef __VMS__
     #pragma message disable nosimpint
 #endif
@@ -85,11 +81,6 @@ static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
 // ----------------------------------------------------------------------------
 
 extern wxList wxModelessWindows;
-extern wxList wxPendingDelete;
-
-// TODO: this should be tidied so that any frame can be the
-// top frame
-// static bool wxTopLevelUsed = FALSE;
 
 // ----------------------------------------------------------------------------
 // wxWin macros
@@ -100,7 +91,7 @@ BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
     EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
 END_EVENT_TABLE()
 
-IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
+IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
 
 // ============================================================================
 // implementation
@@ -112,14 +103,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
 
 void wxFrame::Init()
 {
-    m_iconized = FALSE;
+    m_iconized = false;
 
     //// Motif-specific
     m_frameShell = (WXWidget) NULL;
-    m_mainWidget = (WXWidget) NULL;;
-    m_workArea = (WXWidget) NULL;;
-    m_clientArea = (WXWidget) NULL;;
-    // m_visibleStatus = TRUE;
+    m_mainWidget = (WXWidget) NULL;
+    m_workArea = (WXWidget) NULL;
+    m_clientArea = (WXWidget) NULL;
 }
 
 bool wxFrame::Create(wxWindow *parent,
@@ -132,12 +122,7 @@ bool wxFrame::Create(wxWindow *parent,
 {
     if( !wxTopLevelWindow::Create( parent, id, title, pos, size, style,
                                    name ) )
-        return FALSE;
-
-    m_backgroundColour = 
-        wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
-    m_foregroundColour = *wxBLACK;
-    m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
+        return false;
 
     int x = pos.x, y = pos.y;
     int width = size.x, height = size.y;
@@ -169,10 +154,10 @@ bool wxFrame::Create(wxWindow *parent,
     SetTitle( title );
 
     wxLogTrace(wxTRACE_Messages,
-               "Created frame (0x%08x) with work area 0x%08x and client "
-               "area 0x%08x", m_mainWidget, m_workArea, m_clientArea);
+               "Created frame (0x%p) with work area 0x%p and client "
+               "area 0x%p", m_mainWidget, m_workArea, m_clientArea);
 
-    XtAddEventHandler((Widget) m_clientArea, ExposureMask,FALSE,
+    XtAddEventHandler((Widget) m_clientArea, ExposureMask,False,
         wxUniversalRepaintProc, (XtPointer) this);
 
     if (x > -1)
@@ -184,57 +169,44 @@ bool wxFrame::Create(wxWindow *parent,
     if (height > -1)
         XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL);
 
-    ChangeFont(FALSE);
-
-    ChangeBackgroundColour();
-
+    PostCreation();
     PreResize();
 
-    wxSizeEvent sizeEvent(wxSize(width, height), GetId());
+    wxSize newSize(width, height);
+    wxSizeEvent sizeEvent(newSize, GetId());
     sizeEvent.SetEventObject(this);
 
-    GetEventHandler()->ProcessEvent(sizeEvent);
+    HandleWindowEvent(sizeEvent);
 
-    return TRUE;
+    return true;
 }
 
-bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id,
-                        const wxString& title,
-                        const wxPoint& pos,
-                        const wxSize& size,
-                        long style,
-                        const wxString& name )
+bool wxFrame::XmDoCreateTLW(wxWindow* WXUNUSED(parent),
+                            wxWindowID WXUNUSED(id),
+                            const wxString& WXUNUSED(title),
+                            const wxPoint& WXUNUSED(pos),
+                            const wxSize& WXUNUSED(size),
+                            long style,
+                            const wxString& name)
 {
-    static bool wxTopLevelUsed = FALSE; /* this is global */
-    WXWidget frameShell;
+    Widget frameShell;
 
-    if (wxTopLevelUsed)
-    {
-        // Change suggested by Matthew Flatt
-        frameShell = (WXWidget)XtAppCreateShell( name,
-                                                 wxTheApp->GetClassName(),
-                                                 topLevelShellWidgetClass,
-                                                 (Display*) wxGetDisplay(),
-                                                 NULL, 0 );
-    }
-    else
-    {
-        frameShell = wxTheApp->GetTopLevelWidget();
-        wxTopLevelUsed = TRUE;
-    }
+    frameShell = XtCreatePopupShell( name, topLevelShellWidgetClass,
+                                     (Widget)wxTheApp->GetTopLevelWidget(),
+                                     NULL, 0 );
 
-    XtVaSetValues((Widget) frameShell,
+    XtVaSetValues(frameShell,
         // Allows menu to resize
         XmNallowShellResize, True,
         XmNdeleteResponse, XmDO_NOTHING,
         XmNmappedWhenManaged, False,
-        XmNiconic, (style & wxICONIZE) ? TRUE : FALSE,
+        XmNiconic, (style & wxICONIZE) ? True : False,
         NULL);
 
-    m_frameShell = frameShell;
+    m_frameShell = (WXWidget)frameShell;
 
     m_mainWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
-        xmMainWindowWidgetClass, (Widget) frameShell,
+        xmMainWindowWidgetClass, frameShell,
         XmNresizePolicy, XmRESIZE_NONE,
         NULL);
 
@@ -265,41 +237,36 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id,
     XtFree( (char *)ptr );
 
     /* Part of show-&-hide fix */
-    XtAddEventHandler( (Widget)frameShell, StructureNotifyMask,
+    XtAddEventHandler( frameShell, StructureNotifyMask,
                        False, (XtEventHandler)wxFrameMapProc,
                        (XtPointer)this );
 
-    XtRealizeWidget((Widget) frameShell);
+    XtRealizeWidget(frameShell);
 
     wxAddWindowToTable( (Widget)m_workArea, this);
     wxAddWindowToTable( (Widget)m_clientArea, this);
 
     wxModelessWindows.Append( this );
 
-    return TRUE;
+    return true;
 }
 
 wxFrame::~wxFrame()
 {
-    m_isBeingDeleted = TRUE;
+    m_isBeingDeleted = true;
 
     if (m_clientArea)
     {
-      XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, FALSE,
+      XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, False,
           wxUniversalRepaintProc, (XtPointer) this);
     }
 
     if (GetMainWidget())
-        Show(FALSE);
+        Show(false);
 
     if (m_frameMenuBar)
     {
         m_frameMenuBar->DestroyMenuBar();
-
-        // Hack to stop core dump on Ultrix, OSF, for some strange reason.
-#if MOTIF_MENUBAR_DELETE_FIX
-        GetMenuBar()->SetMainWidget((WXWidget) NULL);
-#endif
         delete m_frameMenuBar;
         m_frameMenuBar = NULL;
     }
@@ -309,15 +276,15 @@ wxFrame::~wxFrame()
         delete m_frameStatusBar;
         m_frameStatusBar = NULL;
     }
-}
 
-void wxFrame::DoDestroy()
-{
+    PreDestroy();
+
     Widget frameShell = (Widget)GetShellWidget();
 
-    XtRemoveEventHandler( frameShell, StructureNotifyMask,
-                          False, (XtEventHandler)wxFrameMapProc,
-                          (XtPointer)this );
+    if( frameShell )
+        XtRemoveEventHandler( frameShell, StructureNotifyMask,
+                              False, (XtEventHandler)wxFrameMapProc,
+                              (XtPointer)this );
 
     if( m_clientArea )
     {
@@ -352,7 +319,7 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
     {
         int sbw, sbh;
         m_frameStatusBar->GetSize(& sbw, & sbh);
-        yy -= sbh;
+        yy = (Dimension)(yy - sbh);
     }
 #if wxUSE_TOOLBAR
     if (m_frameToolBar)
@@ -360,16 +327,21 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
         int tbw, tbh;
         m_frameToolBar->GetSize(& tbw, & tbh);
         if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
-            xx -= tbw;
+            xx = (Dimension)(xx - tbw);
         else
-            yy -= tbh;
+            yy = (Dimension)(yy - tbh);
     }
 #endif // wxUSE_TOOLBAR
-    *x = xx; *y = yy;
+
+//CE found a call here with NULL y pointer
+    if (x)
+        *x = xx;
+    if (y)
+        *y = yy;
 }
 
 // Set the client size (i.e. leave the calculation of borders etc.
-// to wxWindows)
+// to wxWidgets)
 void wxFrame::DoSetClientSize(int width, int height)
 {
     // Calculate how large the new main window should be
@@ -402,42 +374,27 @@ void wxFrame::DoSetClientSize(int width, int height)
     }
     PreResize();
 
-    wxSizeEvent sizeEvent(wxSize(width, height), GetId());
+    wxSize newSize(width, height);
+    wxSizeEvent sizeEvent(newSize, GetId());
     sizeEvent.SetEventObject(this);
 
-    GetEventHandler()->ProcessEvent(sizeEvent);
+    HandleWindowEvent(sizeEvent);
 
 }
 
 void wxFrame::DoGetSize(int *width, int *height) const
 {
+    if (!m_frameShell)
+    {
+        *width = -1; *height = -1;
+        return;
+    }
+
     Dimension xx, yy;
     XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL);
     *width = xx; *height = yy;
 }
 
-void wxFrame::DoGetPosition(int *x, int *y) const
-{
-    Window parent_window = XtWindow((Widget) m_frameShell),
-        next_parent   = XtWindow((Widget) m_frameShell),
-        root          = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
-
-    // search for the parent that is child of ROOT, because the WM may
-    // reparent twice and notify only the next parent (like FVWM)
-    while (next_parent != root) {
-        Window *theChildren; unsigned int n;
-        parent_window = next_parent;
-        XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
-            &next_parent, &theChildren, &n);
-        XFree(theChildren); // not needed
-    }
-    int xx, yy; unsigned int dummy;
-    XGetGeometry(XtDisplay((Widget) m_frameShell), parent_window, &root,
-        &xx, &yy, &dummy, &dummy, &dummy, &dummy);
-    if (x) *x = xx;
-    if (y) *y = yy;
-}
-
 void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags))
 {
     if (x > -1)
@@ -457,8 +414,8 @@ void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFl
 
 bool wxFrame::Show( bool show )
 {
-    if( !wxTopLevelWindowMotif::Show( show ) )
-        return FALSE;
+    if( !wxWindowBase::Show( show ) )
+        return false;
 
     m_isShown = show;
 
@@ -469,15 +426,14 @@ bool wxFrame::Show( bool show )
     SetVisibleStatus(show);
     if (show)
     {
-        XtMapWidget (shell);
-        XRaiseWindow (XtDisplay(shell), XtWindow(shell));
+        XtPopup(shell, XtGrabNone);
     }
     else
     {
-        XtUnmapWidget(shell);
+        XtPopdown(shell);
     }
 
-    return TRUE;
+    return true;
 }
 
 void wxFrame::SetTitle(const wxString& title)
@@ -490,8 +446,8 @@ void wxFrame::SetTitle(const wxString& title)
 
     if( !title.empty() )
         XtVaSetValues( (Widget)m_frameShell,
-                       XmNtitle, title.c_str(),
-                       XmNiconName, title.c_str(),
+                       XmNtitle, (const char*)title.mb_str(),
+                       XmNiconName, (const char*)title.mb_str(),
                        NULL );
 }
 
@@ -500,15 +456,12 @@ void wxFrame::DoSetIcon(const wxIcon& icon)
     if (!m_frameShell)
         return;
 
-    if (!icon.Ok() || !icon.GetPixmap())
+    if (!icon.Ok() || !icon.GetDrawable())
         return;
 
-    XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL);
-}
-
-void wxFrame::SetIcon(const wxIcon& icon)
-{
-    SetIcons( wxIconBundle( icon ) );
+    XtVaSetValues((Widget) m_frameShell,
+                  XtNiconPixmap, icon.GetDrawable(),
+                  NULL);
 }
 
 void wxFrame::SetIcons(const wxIconBundle& icons)
@@ -577,7 +530,7 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
     {
         wxSysColourChangedEvent event2;
         event2.SetEventObject( m_frameStatusBar );
-        m_frameStatusBar->ProcessEvent(event2);
+        m_frameStatusBar->HandleWindowEvent(event2);
     }
 
     // Propagate the event to the non-top-level children
@@ -591,10 +544,11 @@ void wxFrame::OnActivate(wxActivateEvent& event)
     if (!event.GetActive())
         return;
 
-    for(wxNode *node = GetChildren().First(); node; node = node->Next())
+    for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node;
+        node = node->GetNext())
     {
         // Find a child that's a subwindow, but not a dialog box.
-        wxWindow *child = (wxWindow *)node->Data();
+        wxWindow *child = node->GetData();
         if (!child->IsTopLevel())
         {
             child->SetFocus();
@@ -654,7 +608,7 @@ void wxFrame::PositionToolBar()
             tw = cw;
         }
 
-        tb->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
+        tb->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS);
     }
 }
 #endif // wxUSE_TOOLBAR
@@ -670,7 +624,7 @@ bool wxFrame::PreResize()
     PositionStatusBar();
 #endif // wxUSE_STATUSBAR
 
-    return TRUE;
+    return true;
 }
 
 WXWidget wxFrame::GetClientWidget() const
@@ -686,13 +640,13 @@ void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize))
 void wxFrame::ChangeBackgroundColour()
 {
     if (GetClientWidget())
-        DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour);
+        wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour);
 }
 
 void wxFrame::ChangeForegroundColour()
 {
     if (GetClientWidget())
-        DoChangeForegroundColour(GetClientWidget(), m_foregroundColour);
+        wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour);
 }
 
 /* MATTEW: Used to insure that hide-&-show within an event cycle works */