1 /////////////////////////////////////////////////////////////////////////////
2 // Name: motif/frame.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "frame.h"
26 #define XtDisplay XTDISPLAY
27 #define XtWindow XTWINDOW
28 #define XtScreen XTSCREEN
32 #include "wx/statusbr.h"
33 #include "wx/toolbar.h"
35 #include "wx/settings.h"
42 #pragma message disable nosimpint
45 #if defined(__ultrix) || defined(__sgi)
50 #include <X11/Shell.h>
57 #include <Xm/MwmUtil.h>
58 #include <Xm/BulletinB.h>
61 #include <Xm/RowColumn.h>
63 #include <Xm/AtomMgr.h>
64 #include <Xm/LabelG.h>
67 #include <Xm/Protocols.h>
71 #pragma message enable nosimpint
74 #include "wx/motif/private.h"
75 #include "wx/unix/utilsx11.h"
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
82 XCrossingEvent
* event
);
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 extern wxList wxModelessWindows
;
89 extern wxList wxPendingDelete
;
91 // TODO: this should be tidied so that any frame can be the
93 // static bool wxTopLevelUsed = FALSE;
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
100 EVT_ACTIVATE(wxFrame::OnActivate
)
101 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
104 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
111 // frame construction
112 // ----------------------------------------------------------------------------
119 m_frameShell
= (WXWidget
) NULL
;
120 m_mainWidget
= (WXWidget
) NULL
;;
121 m_workArea
= (WXWidget
) NULL
;;
122 m_clientArea
= (WXWidget
) NULL
;;
123 // m_visibleStatus = TRUE;
126 bool wxFrame::Create(wxWindow
*parent
,
128 const wxString
& title
,
132 const wxString
& name
)
134 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
139 wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
140 m_foregroundColour
= *wxBLACK
;
141 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
143 int x
= pos
.x
, y
= pos
.y
;
144 int width
= size
.x
, height
= size
.y
;
146 // Set reasonable values for position and size if defaults have been
149 // MB TODO: something better than these arbitrary values ?
150 // VZ should use X resources for this...
156 int displayW
, displayH
;
157 wxDisplaySize( &displayW
, &displayH
);
161 x
= (displayW
- width
) / 2;
166 y
= (displayH
- height
) / 2;
172 wxLogTrace(wxTRACE_Messages
,
173 "Created frame (0x%p) with work area 0x%p and client "
174 "area 0x%p", m_mainWidget
, m_workArea
, m_clientArea
);
176 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
177 wxUniversalRepaintProc
, (XtPointer
) this);
180 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
182 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
184 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
186 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
190 ChangeBackgroundColour();
194 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
195 sizeEvent
.SetEventObject(this);
197 GetEventHandler()->ProcessEvent(sizeEvent
);
202 bool wxFrame::DoCreate( wxWindow
* parent
, wxWindowID id
,
203 const wxString
& title
,
207 const wxString
& name
)
209 static bool wxTopLevelUsed
= FALSE
; /* this is global */
214 // Change suggested by Matthew Flatt
215 frameShell
= (WXWidget
)XtAppCreateShell( name
,
216 wxTheApp
->GetClassName(),
217 topLevelShellWidgetClass
,
218 (Display
*) wxGetDisplay(),
223 frameShell
= wxTheApp
->GetTopLevelWidget();
224 wxTopLevelUsed
= TRUE
;
227 XtVaSetValues((Widget
) frameShell
,
228 // Allows menu to resize
229 XmNallowShellResize
, True
,
230 XmNdeleteResponse
, XmDO_NOTHING
,
231 XmNmappedWhenManaged
, False
,
232 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
235 m_frameShell
= frameShell
;
237 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
238 xmMainWindowWidgetClass
, (Widget
) frameShell
,
239 XmNresizePolicy
, XmRESIZE_NONE
,
242 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
243 xmFormWidgetClass
, (Widget
) m_mainWidget
,
244 XmNresizePolicy
, XmRESIZE_NONE
,
247 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
248 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
251 XmNrightAttachment
, XmATTACH_FORM
,
252 XmNleftAttachment
, XmATTACH_FORM
,
253 XmNtopAttachment
, XmATTACH_FORM
,
254 XmNbottomAttachment
, XmATTACH_FORM
,
257 XtVaSetValues((Widget
) m_mainWidget
,
258 XmNworkWindow
, (Widget
) m_workArea
,
261 XtManageChild((Widget
) m_clientArea
);
262 XtManageChild((Widget
) m_workArea
);
264 XtTranslations ptr
= XtParseTranslationTable( "<Configure>: resize()" );
265 XtOverrideTranslations( (Widget
) m_workArea
, ptr
);
266 XtFree( (char *)ptr
);
268 /* Part of show-&-hide fix */
269 XtAddEventHandler( (Widget
)frameShell
, StructureNotifyMask
,
270 False
, (XtEventHandler
)wxFrameMapProc
,
273 XtRealizeWidget((Widget
) frameShell
);
275 wxAddWindowToTable( (Widget
)m_workArea
, this);
276 wxAddWindowToTable( (Widget
)m_clientArea
, this);
278 wxModelessWindows
.Append( this );
285 m_isBeingDeleted
= TRUE
;
289 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
290 wxUniversalRepaintProc
, (XtPointer
) this);
298 m_frameMenuBar
->DestroyMenuBar();
300 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
301 #if MOTIF_MENUBAR_DELETE_FIX
302 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
304 delete m_frameMenuBar
;
305 m_frameMenuBar
= NULL
;
308 if (m_frameStatusBar
)
310 delete m_frameStatusBar
;
311 m_frameStatusBar
= NULL
;
318 void wxFrame::DoDestroy()
320 Widget frameShell
= (Widget
)GetShellWidget();
323 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
324 False
, (XtEventHandler
)wxFrameMapProc
,
329 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
330 XtDestroyWidget( (Widget
)m_clientArea
);
335 XtVaSetValues( (Widget
)m_mainWidget
,
336 XmNworkWindow
, (Widget
)NULL
,
339 wxDeleteWindowFromTable( (Widget
)m_workArea
);
340 XtDestroyWidget( (Widget
)m_workArea
);
344 XtDestroyWidget( (Widget
)m_mainWidget
);
347 XtDestroyWidget( frameShell
);
350 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
351 void wxFrame::DoGetClientSize(int *x
, int *y
) const
354 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
356 if (m_frameStatusBar
)
359 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
366 m_frameToolBar
->GetSize(& tbw
, & tbh
);
367 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
372 #endif // wxUSE_TOOLBAR
376 // Set the client size (i.e. leave the calculation of borders etc.
378 void wxFrame::DoSetClientSize(int width
, int height
)
380 // Calculate how large the new main window should be
381 // by finding the difference between the client area and the
382 // main window area, and adding on to the new client area
384 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
388 if (m_frameStatusBar
)
391 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
398 m_frameToolBar
->GetSize(& tbw
, & tbh
);
399 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
404 #endif // wxUSE_TOOLBAR
406 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
410 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
411 sizeEvent
.SetEventObject(this);
413 GetEventHandler()->ProcessEvent(sizeEvent
);
417 void wxFrame::DoGetSize(int *width
, int *height
) const
420 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
421 *width
= xx
; *height
= yy
;
424 void wxFrame::DoGetPosition(int *x
, int *y
) const
426 Window parent_window
= XtWindow((Widget
) m_frameShell
),
427 next_parent
= XtWindow((Widget
) m_frameShell
),
428 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
430 // search for the parent that is child of ROOT, because the WM may
431 // reparent twice and notify only the next parent (like FVWM)
432 while (next_parent
!= root
) {
433 Window
*theChildren
; unsigned int n
;
434 parent_window
= next_parent
;
435 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
436 &next_parent
, &theChildren
, &n
);
437 XFree(theChildren
); // not needed
439 int xx
, yy
; unsigned int dummy
;
440 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
441 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
446 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
449 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
451 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
453 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
455 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
457 if (!(height
== -1 && width
== -1))
463 bool wxFrame::Show( bool show
)
465 if( !wxTopLevelWindowMotif::Show( show
) )
470 Widget shell
= (Widget
)GetShellWidget();
472 return wxWindow::Show(show
);
474 SetVisibleStatus(show
);
478 XRaiseWindow (XtDisplay(shell
), XtWindow(shell
));
482 XtUnmapWidget(shell
);
488 void wxFrame::SetTitle(const wxString
& title
)
490 wxString oldTitle
= GetTitle();
491 if( title
== oldTitle
)
494 wxTopLevelWindow::SetTitle( title
);
497 XtVaSetValues( (Widget
)m_frameShell
,
498 XmNtitle
, title
.c_str(),
499 XmNiconName
, title
.c_str(),
503 void wxFrame::DoSetIcon(const wxIcon
& icon
)
508 if (!icon
.Ok() || !icon
.GetPixmap())
511 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
514 void wxFrame::SetIcon(const wxIcon
& icon
)
516 SetIcons( wxIconBundle( icon
) );
519 void wxFrame::SetIcons(const wxIconBundle
& icons
)
521 wxFrameBase::SetIcons( icons
);
526 DoSetIcon( m_icons
.GetIcon( -1 ) );
527 wxSetIconsX11(GetXDisplay(),
528 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
531 void wxFrame::PositionStatusBar()
533 if (!m_frameStatusBar
)
537 GetClientSize(&w
, &h
);
539 m_frameStatusBar
->GetSize(&sw
, &sh
);
541 // Since we wish the status bar to be directly under the client area,
542 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
543 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
546 WXWidget
wxFrame::GetMenuBarWidget() const
549 return GetMenuBar()->GetMainWidget();
551 return (WXWidget
) NULL
;
554 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
558 m_frameMenuBar
= NULL
;
562 // Currently can't set it twice
563 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
567 m_frameMenuBar
->DestroyMenuBar();
568 delete m_frameMenuBar
;
571 m_frameMenuBar
= menuBar
;
572 m_frameMenuBar
->CreateMenuBar(this);
575 // Responds to colour changes, and passes event on to children.
576 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
578 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
581 if ( m_frameStatusBar
)
583 wxSysColourChangedEvent event2
;
584 event2
.SetEventObject( m_frameStatusBar
);
585 m_frameStatusBar
->ProcessEvent(event2
);
588 // Propagate the event to the non-top-level children
589 wxWindow::OnSysColourChanged(event
);
592 // Default activation behaviour - set the focus for the first child
594 void wxFrame::OnActivate(wxActivateEvent
& event
)
596 if (!event
.GetActive())
599 for(wxWindowList::Node
*node
= GetChildren().GetFirst(); node
;
600 node
= node
->GetNext())
602 // Find a child that's a subwindow, but not a dialog box.
603 wxWindow
*child
= node
->GetData();
604 if (!child
->IsTopLevel())
612 void wxFrame::SendSizeEvent()
614 wxSizeEvent
event(GetSize(), GetId());
615 event
.SetEventObject(this);
616 GetEventHandler()->AddPendingEvent(event
);
621 wxToolBar
* wxFrame::CreateToolBar(long style
,
623 const wxString
& name
)
625 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
630 return m_frameToolBar
;
633 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
635 wxFrameBase::SetToolBar(toolbar
);
639 void wxFrame::PositionToolBar()
641 wxToolBar
* tb
= GetToolBar();
645 GetClientSize(& cw
, &ch
);
648 tb
->GetSize(& tw
, & th
);
650 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
652 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
653 // means, pretend we don't have toolbar/status bar, so we
654 // have the original client size.
659 // Use the 'real' position
663 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
666 #endif // wxUSE_TOOLBAR
669 bool wxFrame::PreResize()
673 #endif // wxUSE_TOOLBAR
677 #endif // wxUSE_STATUSBAR
682 WXWidget
wxFrame::GetClientWidget() const
687 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
692 void wxFrame::ChangeBackgroundColour()
694 if (GetClientWidget())
695 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
698 void wxFrame::ChangeForegroundColour()
700 if (GetClientWidget())
701 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
704 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
705 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
706 XCrossingEvent
* event
)
708 wxFrame
*tli
= (wxFrame
*)clientData
;
710 XEvent
*e
= (XEvent
*)event
;
712 if( e
->xany
.type
== MapNotify
)
715 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
716 if( !tli
->GetVisibleStatus() )
718 /* We really wanted this to be hidden! */
719 XtUnmapWidget( frameShell
);
722 else if( e
->xany
.type
== UnmapNotify
)
724 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);