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
.GetDrawable())
511 XtVaSetValues((Widget
) m_frameShell
,
512 XtNiconPixmap
, icon
.GetDrawable(),
516 void wxFrame::SetIcon(const wxIcon
& icon
)
518 SetIcons( wxIconBundle( icon
) );
521 void wxFrame::SetIcons(const wxIconBundle
& icons
)
523 wxFrameBase::SetIcons( icons
);
528 DoSetIcon( m_icons
.GetIcon( -1 ) );
529 wxSetIconsX11(GetXDisplay(),
530 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
533 void wxFrame::PositionStatusBar()
535 if (!m_frameStatusBar
)
539 GetClientSize(&w
, &h
);
541 m_frameStatusBar
->GetSize(&sw
, &sh
);
543 // Since we wish the status bar to be directly under the client area,
544 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
545 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
548 WXWidget
wxFrame::GetMenuBarWidget() const
551 return GetMenuBar()->GetMainWidget();
553 return (WXWidget
) NULL
;
556 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
560 m_frameMenuBar
= NULL
;
564 // Currently can't set it twice
565 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
569 m_frameMenuBar
->DestroyMenuBar();
570 delete m_frameMenuBar
;
573 m_frameMenuBar
= menuBar
;
574 m_frameMenuBar
->CreateMenuBar(this);
577 // Responds to colour changes, and passes event on to children.
578 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
580 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
583 if ( m_frameStatusBar
)
585 wxSysColourChangedEvent event2
;
586 event2
.SetEventObject( m_frameStatusBar
);
587 m_frameStatusBar
->ProcessEvent(event2
);
590 // Propagate the event to the non-top-level children
591 wxWindow::OnSysColourChanged(event
);
594 // Default activation behaviour - set the focus for the first child
596 void wxFrame::OnActivate(wxActivateEvent
& event
)
598 if (!event
.GetActive())
601 for(wxWindowList::Node
*node
= GetChildren().GetFirst(); node
;
602 node
= node
->GetNext())
604 // Find a child that's a subwindow, but not a dialog box.
605 wxWindow
*child
= node
->GetData();
606 if (!child
->IsTopLevel())
614 void wxFrame::SendSizeEvent()
616 wxSizeEvent
event(GetSize(), GetId());
617 event
.SetEventObject(this);
618 GetEventHandler()->AddPendingEvent(event
);
623 wxToolBar
* wxFrame::CreateToolBar(long style
,
625 const wxString
& name
)
627 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
632 return m_frameToolBar
;
635 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
637 wxFrameBase::SetToolBar(toolbar
);
641 void wxFrame::PositionToolBar()
643 wxToolBar
* tb
= GetToolBar();
647 GetClientSize(& cw
, &ch
);
650 tb
->GetSize(& tw
, & th
);
652 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
654 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
655 // means, pretend we don't have toolbar/status bar, so we
656 // have the original client size.
661 // Use the 'real' position
665 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
668 #endif // wxUSE_TOOLBAR
671 bool wxFrame::PreResize()
675 #endif // wxUSE_TOOLBAR
679 #endif // wxUSE_STATUSBAR
684 WXWidget
wxFrame::GetClientWidget() const
689 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
694 void wxFrame::ChangeBackgroundColour()
696 if (GetClientWidget())
697 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
700 void wxFrame::ChangeForegroundColour()
702 if (GetClientWidget())
703 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
706 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
707 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
708 XCrossingEvent
* event
)
710 wxFrame
*tli
= (wxFrame
*)clientData
;
712 XEvent
*e
= (XEvent
*)event
;
714 if( e
->xany
.type
== MapNotify
)
717 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
718 if( !tli
->GetVisibleStatus() )
720 /* We really wanted this to be hidden! */
721 XtUnmapWidget( frameShell
);
724 else if( e
->xany
.type
== UnmapNotify
)
726 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);