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"
31 #include "wx/settings.h"
32 #include "wx/toolbar.h"
33 #include "wx/statusbr.h"
37 #pragma message disable nosimpint
40 #if defined(__ultrix) || defined(__sgi)
45 #include <X11/Shell.h>
52 #include <Xm/MwmUtil.h>
53 #include <Xm/BulletinB.h>
56 #include <Xm/RowColumn.h>
58 #include <Xm/AtomMgr.h>
59 #include <Xm/LabelG.h>
62 #include <Xm/Protocols.h>
66 #pragma message enable nosimpint
69 #include "wx/motif/private.h"
70 #include "wx/unix/utilsx11.h"
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
77 XCrossingEvent
* event
);
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 extern wxList wxModelessWindows
;
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
90 EVT_ACTIVATE(wxFrame::OnActivate
)
91 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
94 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
96 // ============================================================================
98 // ============================================================================
100 // ----------------------------------------------------------------------------
101 // frame construction
102 // ----------------------------------------------------------------------------
109 m_frameShell
= (WXWidget
) NULL
;
110 m_mainWidget
= (WXWidget
) NULL
;
111 m_workArea
= (WXWidget
) NULL
;
112 m_clientArea
= (WXWidget
) NULL
;
115 bool wxFrame::Create(wxWindow
*parent
,
117 const wxString
& title
,
121 const wxString
& name
)
123 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
127 int x
= pos
.x
, y
= pos
.y
;
128 int width
= size
.x
, height
= size
.y
;
130 // Set reasonable values for position and size if defaults have been
133 // MB TODO: something better than these arbitrary values ?
134 // VZ should use X resources for this...
140 int displayW
, displayH
;
141 wxDisplaySize( &displayW
, &displayH
);
145 x
= (displayW
- width
) / 2;
150 y
= (displayH
- height
) / 2;
156 wxLogTrace(wxTRACE_Messages
,
157 "Created frame (0x%p) with work area 0x%p and client "
158 "area 0x%p", m_mainWidget
, m_workArea
, m_clientArea
);
160 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,False
,
161 wxUniversalRepaintProc
, (XtPointer
) this);
164 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
166 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
168 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
170 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
175 wxSize
newSize(width
, height
);
176 wxSizeEvent
sizeEvent(newSize
, GetId());
177 sizeEvent
.SetEventObject(this);
179 HandleWindowEvent(sizeEvent
);
184 bool wxFrame::XmDoCreateTLW(wxWindow
* WXUNUSED(parent
),
185 wxWindowID
WXUNUSED(id
),
186 const wxString
& WXUNUSED(title
),
187 const wxPoint
& WXUNUSED(pos
),
188 const wxSize
& WXUNUSED(size
),
190 const wxString
& name
)
194 frameShell
= XtCreatePopupShell( name
, topLevelShellWidgetClass
,
195 (Widget
)wxTheApp
->GetTopLevelWidget(),
198 XtVaSetValues(frameShell
,
199 // Allows menu to resize
200 XmNallowShellResize
, True
,
201 XmNdeleteResponse
, XmDO_NOTHING
,
202 XmNmappedWhenManaged
, False
,
203 XmNiconic
, (style
& wxICONIZE
) ? True
: False
,
206 m_frameShell
= (WXWidget
)frameShell
;
208 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
209 xmMainWindowWidgetClass
, frameShell
,
210 XmNresizePolicy
, XmRESIZE_NONE
,
213 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
214 xmFormWidgetClass
, (Widget
) m_mainWidget
,
215 XmNresizePolicy
, XmRESIZE_NONE
,
218 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
219 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
222 XmNrightAttachment
, XmATTACH_FORM
,
223 XmNleftAttachment
, XmATTACH_FORM
,
224 XmNtopAttachment
, XmATTACH_FORM
,
225 XmNbottomAttachment
, XmATTACH_FORM
,
228 XtVaSetValues((Widget
) m_mainWidget
,
229 XmNworkWindow
, (Widget
) m_workArea
,
232 XtManageChild((Widget
) m_clientArea
);
233 XtManageChild((Widget
) m_workArea
);
235 XtTranslations ptr
= XtParseTranslationTable( "<Configure>: resize()" );
236 XtOverrideTranslations( (Widget
) m_workArea
, ptr
);
237 XtFree( (char *)ptr
);
239 /* Part of show-&-hide fix */
240 XtAddEventHandler( frameShell
, StructureNotifyMask
,
241 False
, (XtEventHandler
)wxFrameMapProc
,
244 XtRealizeWidget(frameShell
);
246 wxAddWindowToTable( (Widget
)m_workArea
, this);
247 wxAddWindowToTable( (Widget
)m_clientArea
, this);
249 wxModelessWindows
.Append( this );
260 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, False
,
261 wxUniversalRepaintProc
, (XtPointer
) this);
269 m_frameMenuBar
->DestroyMenuBar();
270 wxDELETE(m_frameMenuBar
);
273 wxDELETE(m_frameStatusBar
);
277 Widget frameShell
= (Widget
)GetShellWidget();
280 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
281 False
, (XtEventHandler
)wxFrameMapProc
,
286 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
287 XtDestroyWidget( (Widget
)m_clientArea
);
292 XtVaSetValues( (Widget
)m_mainWidget
,
293 XmNworkWindow
, (Widget
)NULL
,
296 wxDeleteWindowFromTable( (Widget
)m_workArea
);
297 XtDestroyWidget( (Widget
)m_workArea
);
301 XtDestroyWidget( (Widget
)m_mainWidget
);
304 XtDestroyWidget( frameShell
);
307 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
308 void wxFrame::DoGetClientSize(int *x
, int *y
) const
311 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
313 if (m_frameStatusBar
)
316 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
317 yy
= (Dimension
)(yy
- sbh
);
323 m_frameToolBar
->GetSize(& tbw
, & tbh
);
324 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
325 xx
= (Dimension
)(xx
- tbw
);
327 yy
= (Dimension
)(yy
- tbh
);
329 #endif // wxUSE_TOOLBAR
331 //CE found a call here with NULL y pointer
338 // Set the client size (i.e. leave the calculation of borders etc.
340 void wxFrame::DoSetClientSize(int width
, int height
)
342 // Calculate how large the new main window should be
343 // by finding the difference between the client area and the
344 // main window area, and adding on to the new client area
346 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
350 if (m_frameStatusBar
)
353 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
360 m_frameToolBar
->GetSize(& tbw
, & tbh
);
361 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
366 #endif // wxUSE_TOOLBAR
368 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
372 wxSize
newSize(width
, height
);
373 wxSizeEvent
sizeEvent(newSize
, GetId());
374 sizeEvent
.SetEventObject(this);
376 HandleWindowEvent(sizeEvent
);
380 void wxFrame::DoGetSize(int *width
, int *height
) const
384 *width
= -1; *height
= -1;
389 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
390 *width
= xx
; *height
= yy
;
393 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
396 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
398 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
400 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
402 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
404 if (!(height
== -1 && width
== -1))
410 bool wxFrame::Show( bool show
)
412 if( !wxWindowBase::Show( show
) )
417 Widget shell
= (Widget
)GetShellWidget();
419 return wxWindow::Show(show
);
421 SetVisibleStatus(show
);
424 XtPopup(shell
, XtGrabNone
);
434 void wxFrame::SetTitle(const wxString
& title
)
436 wxString oldTitle
= GetTitle();
437 if( title
== oldTitle
)
440 wxTopLevelWindow::SetTitle( title
);
443 XtVaSetValues( (Widget
)m_frameShell
,
444 XmNtitle
, (const char*)title
.mb_str(),
445 XmNiconName
, (const char*)title
.mb_str(),
449 void wxFrame::DoSetIcon(const wxIcon
& icon
)
454 if (!icon
.Ok() || !icon
.GetDrawable())
457 XtVaSetValues((Widget
) m_frameShell
,
458 XtNiconPixmap
, icon
.GetDrawable(),
462 void wxFrame::SetIcons(const wxIconBundle
& icons
)
464 wxFrameBase::SetIcons( icons
);
469 DoSetIcon( m_icons
.GetIcon( -1 ) );
470 wxSetIconsX11(GetXDisplay(),
471 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
474 void wxFrame::PositionStatusBar()
476 if (!m_frameStatusBar
)
480 GetClientSize(&w
, &h
);
482 m_frameStatusBar
->GetSize(&sw
, &sh
);
484 // Since we wish the status bar to be directly under the client area,
485 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
486 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
489 WXWidget
wxFrame::GetMenuBarWidget() const
492 return GetMenuBar()->GetMainWidget();
494 return (WXWidget
) NULL
;
497 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
501 m_frameMenuBar
= NULL
;
505 // Currently can't set it twice
506 // wxASSERT_MSG( (m_frameMenuBar == NULL), "Cannot set the menubar more than once");
510 m_frameMenuBar
->DestroyMenuBar();
511 delete m_frameMenuBar
;
514 m_frameMenuBar
= menuBar
;
515 m_frameMenuBar
->CreateMenuBar(this);
518 // Responds to colour changes, and passes event on to children.
519 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
521 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
524 if ( m_frameStatusBar
)
526 wxSysColourChangedEvent event2
;
527 event2
.SetEventObject( m_frameStatusBar
);
528 m_frameStatusBar
->HandleWindowEvent(event2
);
531 // Propagate the event to the non-top-level children
532 wxWindow::OnSysColourChanged(event
);
535 // Default activation behaviour - set the focus for the first child
537 void wxFrame::OnActivate(wxActivateEvent
& event
)
539 if (!event
.GetActive())
542 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
;
543 node
= node
->GetNext())
545 // Find a child that's a subwindow, but not a dialog box.
546 wxWindow
*child
= node
->GetData();
547 if (!child
->IsTopLevel())
557 wxToolBar
* wxFrame::CreateToolBar(long style
,
559 const wxString
& name
)
561 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
566 return m_frameToolBar
;
569 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
571 wxFrameBase::SetToolBar(toolbar
);
575 void wxFrame::PositionToolBar()
577 wxToolBar
* tb
= GetToolBar();
581 GetClientSize(& cw
, &ch
);
584 tb
->GetSize(& tw
, & th
);
586 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
588 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
589 // means, pretend we don't have toolbar/status bar, so we
590 // have the original client size.
595 // Use the 'real' position
599 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
602 #endif // wxUSE_TOOLBAR
605 bool wxFrame::PreResize()
609 #endif // wxUSE_TOOLBAR
613 #endif // wxUSE_STATUSBAR
618 WXWidget
wxFrame::GetClientWidget() const
623 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
628 void wxFrame::ChangeBackgroundColour()
630 if (GetClientWidget())
631 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
634 void wxFrame::ChangeForegroundColour()
636 if (GetClientWidget())
637 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
640 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
641 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
642 XCrossingEvent
* event
)
644 wxFrame
*tli
= (wxFrame
*)clientData
;
646 XEvent
*e
= (XEvent
*)event
;
648 if( e
->xany
.type
== MapNotify
)
651 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
652 if( !tli
->GetVisibleStatus() )
654 /* We really wanted this to be hidden! */
655 XtUnmapWidget( frameShell
);
658 else if( e
->xany
.type
== UnmapNotify
)
660 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);