1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/frame.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
24 #define XtDisplay XTDISPLAY
25 #define XtWindow XTWINDOW
26 #define XtScreen XTSCREEN
37 #include "wx/statusbr.h"
38 #include "wx/toolbar.h"
40 #include "wx/settings.h"
44 #pragma message disable nosimpint
47 #if defined(__ultrix) || defined(__sgi)
52 #include <X11/Shell.h>
59 #include <Xm/MwmUtil.h>
60 #include <Xm/BulletinB.h>
63 #include <Xm/RowColumn.h>
65 #include <Xm/AtomMgr.h>
66 #include <Xm/LabelG.h>
69 #include <Xm/Protocols.h>
73 #pragma message enable nosimpint
76 #include "wx/motif/private.h"
77 #include "wx/unix/utilsx11.h"
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
84 XCrossingEvent
* event
);
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 extern wxList wxModelessWindows
;
91 extern wxList wxPendingDelete
;
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
98 EVT_ACTIVATE(wxFrame::OnActivate
)
99 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
102 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
104 // ============================================================================
106 // ============================================================================
108 // ----------------------------------------------------------------------------
109 // frame construction
110 // ----------------------------------------------------------------------------
117 m_frameShell
= (WXWidget
) NULL
;
118 m_mainWidget
= (WXWidget
) NULL
;
119 m_workArea
= (WXWidget
) NULL
;
120 m_clientArea
= (WXWidget
) NULL
;
123 bool wxFrame::Create(wxWindow
*parent
,
125 const wxString
& title
,
129 const wxString
& name
)
131 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
136 wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
137 m_foregroundColour
= *wxBLACK
;
138 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
140 int x
= pos
.x
, y
= pos
.y
;
141 int width
= size
.x
, height
= size
.y
;
143 // Set reasonable values for position and size if defaults have been
146 // MB TODO: something better than these arbitrary values ?
147 // VZ should use X resources for this...
153 int displayW
, displayH
;
154 wxDisplaySize( &displayW
, &displayH
);
158 x
= (displayW
- width
) / 2;
163 y
= (displayH
- height
) / 2;
169 wxLogTrace(wxTRACE_Messages
,
170 "Created frame (0x%p) with work area 0x%p and client "
171 "area 0x%p", m_mainWidget
, m_workArea
, m_clientArea
);
173 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,False
,
174 wxUniversalRepaintProc
, (XtPointer
) this);
177 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
179 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
181 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
183 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
187 ChangeBackgroundColour();
191 wxSize
newSize(width
, height
);
192 wxSizeEvent
sizeEvent(newSize
, GetId());
193 sizeEvent
.SetEventObject(this);
195 GetEventHandler()->ProcessEvent(sizeEvent
);
200 bool wxFrame::XmDoCreateTLW(wxWindow
* WXUNUSED(parent
),
201 wxWindowID
WXUNUSED(id
),
202 const wxString
& WXUNUSED(title
),
203 const wxPoint
& WXUNUSED(pos
),
204 const wxSize
& WXUNUSED(size
),
206 const wxString
& name
)
210 frameShell
= XtCreatePopupShell( name
, topLevelShellWidgetClass
,
211 (Widget
)wxTheApp
->GetTopLevelWidget(),
214 XtVaSetValues(frameShell
,
215 // Allows menu to resize
216 XmNallowShellResize
, True
,
217 XmNdeleteResponse
, XmDO_NOTHING
,
218 XmNmappedWhenManaged
, False
,
219 XmNiconic
, (style
& wxICONIZE
) ? True
: False
,
222 m_frameShell
= (WXWidget
)frameShell
;
224 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
225 xmMainWindowWidgetClass
, frameShell
,
226 XmNresizePolicy
, XmRESIZE_NONE
,
229 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
230 xmFormWidgetClass
, (Widget
) m_mainWidget
,
231 XmNresizePolicy
, XmRESIZE_NONE
,
234 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
235 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
238 XmNrightAttachment
, XmATTACH_FORM
,
239 XmNleftAttachment
, XmATTACH_FORM
,
240 XmNtopAttachment
, XmATTACH_FORM
,
241 XmNbottomAttachment
, XmATTACH_FORM
,
244 XtVaSetValues((Widget
) m_mainWidget
,
245 XmNworkWindow
, (Widget
) m_workArea
,
248 XtManageChild((Widget
) m_clientArea
);
249 XtManageChild((Widget
) m_workArea
);
251 XtTranslations ptr
= XtParseTranslationTable( "<Configure>: resize()" );
252 XtOverrideTranslations( (Widget
) m_workArea
, ptr
);
253 XtFree( (char *)ptr
);
255 /* Part of show-&-hide fix */
256 XtAddEventHandler( frameShell
, StructureNotifyMask
,
257 False
, (XtEventHandler
)wxFrameMapProc
,
260 XtRealizeWidget(frameShell
);
262 wxAddWindowToTable( (Widget
)m_workArea
, this);
263 wxAddWindowToTable( (Widget
)m_clientArea
, this);
265 wxModelessWindows
.Append( this );
272 m_isBeingDeleted
= true;
276 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, False
,
277 wxUniversalRepaintProc
, (XtPointer
) this);
285 m_frameMenuBar
->DestroyMenuBar();
286 delete m_frameMenuBar
;
287 m_frameMenuBar
= NULL
;
290 if (m_frameStatusBar
)
292 delete m_frameStatusBar
;
293 m_frameStatusBar
= NULL
;
298 Widget frameShell
= (Widget
)GetShellWidget();
301 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
302 False
, (XtEventHandler
)wxFrameMapProc
,
307 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
308 XtDestroyWidget( (Widget
)m_clientArea
);
313 XtVaSetValues( (Widget
)m_mainWidget
,
314 XmNworkWindow
, (Widget
)NULL
,
317 wxDeleteWindowFromTable( (Widget
)m_workArea
);
318 XtDestroyWidget( (Widget
)m_workArea
);
322 XtDestroyWidget( (Widget
)m_mainWidget
);
325 XtDestroyWidget( frameShell
);
328 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
329 void wxFrame::DoGetClientSize(int *x
, int *y
) const
332 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
334 if (m_frameStatusBar
)
337 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
338 yy
= (Dimension
)(yy
- sbh
);
344 m_frameToolBar
->GetSize(& tbw
, & tbh
);
345 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
346 xx
= (Dimension
)(xx
- tbw
);
348 yy
= (Dimension
)(yy
- tbh
);
350 #endif // wxUSE_TOOLBAR
352 //CE found a call here with NULL y pointer
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 wxSize
newSize(width
, height
);
394 wxSizeEvent
sizeEvent(newSize
, GetId());
395 sizeEvent
.SetEventObject(this);
397 GetEventHandler()->ProcessEvent(sizeEvent
);
401 void wxFrame::DoGetSize(int *width
, int *height
) const
404 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
405 *width
= xx
; *height
= yy
;
408 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
411 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
413 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
415 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
417 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
419 if (!(height
== -1 && width
== -1))
425 bool wxFrame::Show( bool show
)
427 if( !wxWindowBase::Show( show
) )
432 Widget shell
= (Widget
)GetShellWidget();
434 return wxWindow::Show(show
);
436 SetVisibleStatus(show
);
439 XtPopup(shell
, XtGrabNone
);
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
);