1 /////////////////////////////////////////////////////////////////////////////
2 // Name: motif/frame.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
96 EVT_ACTIVATE(wxFrame::OnActivate
)
97 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
100 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
102 // ============================================================================
104 // ============================================================================
106 // ----------------------------------------------------------------------------
107 // frame construction
108 // ----------------------------------------------------------------------------
115 m_frameShell
= (WXWidget
) NULL
;
116 m_mainWidget
= (WXWidget
) NULL
;;
117 m_workArea
= (WXWidget
) NULL
;;
118 m_clientArea
= (WXWidget
) NULL
;;
121 bool wxFrame::Create(wxWindow
*parent
,
123 const wxString
& title
,
127 const wxString
& name
)
129 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
134 wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
135 m_foregroundColour
= *wxBLACK
;
136 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
138 int x
= pos
.x
, y
= pos
.y
;
139 int width
= size
.x
, height
= size
.y
;
141 // Set reasonable values for position and size if defaults have been
144 // MB TODO: something better than these arbitrary values ?
145 // VZ should use X resources for this...
151 int displayW
, displayH
;
152 wxDisplaySize( &displayW
, &displayH
);
156 x
= (displayW
- width
) / 2;
161 y
= (displayH
- height
) / 2;
167 wxLogTrace(wxTRACE_Messages
,
168 "Created frame (0x%p) with work area 0x%p and client "
169 "area 0x%p", m_mainWidget
, m_workArea
, m_clientArea
);
171 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
172 wxUniversalRepaintProc
, (XtPointer
) this);
175 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
177 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
179 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
181 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
185 ChangeBackgroundColour();
189 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
190 sizeEvent
.SetEventObject(this);
192 GetEventHandler()->ProcessEvent(sizeEvent
);
197 bool wxFrame::DoCreate( wxWindow
* parent
, wxWindowID id
,
198 const wxString
& title
,
202 const wxString
& name
)
206 frameShell
= XtCreatePopupShell( name
, topLevelShellWidgetClass
,
207 (Widget
)wxTheApp
->GetTopLevelWidget(),
210 XtVaSetValues(frameShell
,
211 // Allows menu to resize
212 XmNallowShellResize
, True
,
213 XmNdeleteResponse
, XmDO_NOTHING
,
214 XmNmappedWhenManaged
, False
,
215 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
218 m_frameShell
= (WXWidget
)frameShell
;
220 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
221 xmMainWindowWidgetClass
, frameShell
,
222 XmNresizePolicy
, XmRESIZE_NONE
,
225 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
226 xmFormWidgetClass
, (Widget
) m_mainWidget
,
227 XmNresizePolicy
, XmRESIZE_NONE
,
230 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
231 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
234 XmNrightAttachment
, XmATTACH_FORM
,
235 XmNleftAttachment
, XmATTACH_FORM
,
236 XmNtopAttachment
, XmATTACH_FORM
,
237 XmNbottomAttachment
, XmATTACH_FORM
,
240 XtVaSetValues((Widget
) m_mainWidget
,
241 XmNworkWindow
, (Widget
) m_workArea
,
244 XtManageChild((Widget
) m_clientArea
);
245 XtManageChild((Widget
) m_workArea
);
247 XtTranslations ptr
= XtParseTranslationTable( "<Configure>: resize()" );
248 XtOverrideTranslations( (Widget
) m_workArea
, ptr
);
249 XtFree( (char *)ptr
);
251 /* Part of show-&-hide fix */
252 XtAddEventHandler( frameShell
, StructureNotifyMask
,
253 False
, (XtEventHandler
)wxFrameMapProc
,
256 XtRealizeWidget(frameShell
);
258 wxAddWindowToTable( (Widget
)m_workArea
, this);
259 wxAddWindowToTable( (Widget
)m_clientArea
, this);
261 wxModelessWindows
.Append( this );
268 m_isBeingDeleted
= TRUE
;
272 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
273 wxUniversalRepaintProc
, (XtPointer
) this);
281 m_frameMenuBar
->DestroyMenuBar();
283 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
284 #if MOTIF_MENUBAR_DELETE_FIX
285 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
287 delete m_frameMenuBar
;
288 m_frameMenuBar
= NULL
;
291 if (m_frameStatusBar
)
293 delete m_frameStatusBar
;
294 m_frameStatusBar
= NULL
;
301 void wxFrame::DoDestroy()
303 Widget frameShell
= (Widget
)GetShellWidget();
306 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
307 False
, (XtEventHandler
)wxFrameMapProc
,
312 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
313 XtDestroyWidget( (Widget
)m_clientArea
);
318 XtVaSetValues( (Widget
)m_mainWidget
,
319 XmNworkWindow
, (Widget
)NULL
,
322 wxDeleteWindowFromTable( (Widget
)m_workArea
);
323 XtDestroyWidget( (Widget
)m_workArea
);
327 XtDestroyWidget( (Widget
)m_mainWidget
);
330 XtDestroyWidget( frameShell
);
333 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
334 void wxFrame::DoGetClientSize(int *x
, int *y
) const
337 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
339 if (m_frameStatusBar
)
342 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
349 m_frameToolBar
->GetSize(& tbw
, & tbh
);
350 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
355 #endif // wxUSE_TOOLBAR
359 // Set the client size (i.e. leave the calculation of borders etc.
361 void wxFrame::DoSetClientSize(int width
, int height
)
363 // Calculate how large the new main window should be
364 // by finding the difference between the client area and the
365 // main window area, and adding on to the new client area
367 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
371 if (m_frameStatusBar
)
374 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
381 m_frameToolBar
->GetSize(& tbw
, & tbh
);
382 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
387 #endif // wxUSE_TOOLBAR
389 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
393 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
394 sizeEvent
.SetEventObject(this);
396 GetEventHandler()->ProcessEvent(sizeEvent
);
400 void wxFrame::DoGetSize(int *width
, int *height
) const
403 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
404 *width
= xx
; *height
= yy
;
407 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
410 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
412 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
414 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
416 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
418 if (!(height
== -1 && width
== -1))
424 bool wxFrame::Show( bool show
)
426 if( !wxTopLevelWindowMotif::Show( show
) )
431 Widget shell
= (Widget
)GetShellWidget();
433 return wxWindow::Show(show
);
435 SetVisibleStatus(show
);
439 XRaiseWindow (XtDisplay(shell
), XtWindow(shell
));
443 XtUnmapWidget(shell
);
449 void wxFrame::SetTitle(const wxString
& title
)
451 wxString oldTitle
= GetTitle();
452 if( title
== oldTitle
)
455 wxTopLevelWindow::SetTitle( title
);
458 XtVaSetValues( (Widget
)m_frameShell
,
459 XmNtitle
, title
.c_str(),
460 XmNiconName
, title
.c_str(),
464 void wxFrame::DoSetIcon(const wxIcon
& icon
)
469 if (!icon
.Ok() || !icon
.GetDrawable())
472 XtVaSetValues((Widget
) m_frameShell
,
473 XtNiconPixmap
, icon
.GetDrawable(),
477 void wxFrame::SetIcon(const wxIcon
& icon
)
479 SetIcons( wxIconBundle( icon
) );
482 void wxFrame::SetIcons(const wxIconBundle
& icons
)
484 wxFrameBase::SetIcons( icons
);
489 DoSetIcon( m_icons
.GetIcon( -1 ) );
490 wxSetIconsX11(GetXDisplay(),
491 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
494 void wxFrame::PositionStatusBar()
496 if (!m_frameStatusBar
)
500 GetClientSize(&w
, &h
);
502 m_frameStatusBar
->GetSize(&sw
, &sh
);
504 // Since we wish the status bar to be directly under the client area,
505 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
506 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
509 WXWidget
wxFrame::GetMenuBarWidget() const
512 return GetMenuBar()->GetMainWidget();
514 return (WXWidget
) NULL
;
517 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
521 m_frameMenuBar
= NULL
;
525 // Currently can't set it twice
526 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
530 m_frameMenuBar
->DestroyMenuBar();
531 delete m_frameMenuBar
;
534 m_frameMenuBar
= menuBar
;
535 m_frameMenuBar
->CreateMenuBar(this);
538 // Responds to colour changes, and passes event on to children.
539 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
541 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
544 if ( m_frameStatusBar
)
546 wxSysColourChangedEvent event2
;
547 event2
.SetEventObject( m_frameStatusBar
);
548 m_frameStatusBar
->ProcessEvent(event2
);
551 // Propagate the event to the non-top-level children
552 wxWindow::OnSysColourChanged(event
);
555 // Default activation behaviour - set the focus for the first child
557 void wxFrame::OnActivate(wxActivateEvent
& event
)
559 if (!event
.GetActive())
562 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
;
563 node
= node
->GetNext())
565 // Find a child that's a subwindow, but not a dialog box.
566 wxWindow
*child
= node
->GetData();
567 if (!child
->IsTopLevel())
575 void wxFrame::SendSizeEvent()
577 wxSizeEvent
event(GetSize(), GetId());
578 event
.SetEventObject(this);
579 GetEventHandler()->AddPendingEvent(event
);
584 wxToolBar
* wxFrame::CreateToolBar(long style
,
586 const wxString
& name
)
588 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
593 return m_frameToolBar
;
596 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
598 wxFrameBase::SetToolBar(toolbar
);
602 void wxFrame::PositionToolBar()
604 wxToolBar
* tb
= GetToolBar();
608 GetClientSize(& cw
, &ch
);
611 tb
->GetSize(& tw
, & th
);
613 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
615 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
616 // means, pretend we don't have toolbar/status bar, so we
617 // have the original client size.
622 // Use the 'real' position
626 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
629 #endif // wxUSE_TOOLBAR
632 bool wxFrame::PreResize()
636 #endif // wxUSE_TOOLBAR
640 #endif // wxUSE_STATUSBAR
645 WXWidget
wxFrame::GetClientWidget() const
650 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
655 void wxFrame::ChangeBackgroundColour()
657 if (GetClientWidget())
658 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
661 void wxFrame::ChangeForegroundColour()
663 if (GetClientWidget())
664 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
667 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
668 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
669 XCrossingEvent
* event
)
671 wxFrame
*tli
= (wxFrame
*)clientData
;
673 XEvent
*e
= (XEvent
*)event
;
675 if( e
->xany
.type
== MapNotify
)
678 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
679 if( !tli
->GetVisibleStatus() )
681 /* We really wanted this to be hidden! */
682 XtUnmapWidget( frameShell
);
685 else if( e
->xany
.type
== UnmapNotify
)
687 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);