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
30 #include "wx/statusbr.h"
31 #include "wx/toolbar.h"
33 #include "wx/settings.h"
40 #pragma message disable nosimpint
43 #if defined(__ultrix) || defined(__sgi)
48 #include <X11/Shell.h>
55 #include <Xm/MwmUtil.h>
56 #include <Xm/BulletinB.h>
59 #include <Xm/RowColumn.h>
61 #include <Xm/AtomMgr.h>
62 #include <Xm/LabelG.h>
65 #include <Xm/Protocols.h>
69 #pragma message enable nosimpint
72 #include "wx/motif/private.h"
73 #include "wx/unix/utilsx11.h"
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
80 XCrossingEvent
* event
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 extern wxList wxModelessWindows
;
87 extern wxList wxPendingDelete
;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
94 EVT_ACTIVATE(wxFrame::OnActivate
)
95 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
98 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
100 // ============================================================================
102 // ============================================================================
104 // ----------------------------------------------------------------------------
105 // frame construction
106 // ----------------------------------------------------------------------------
113 m_frameShell
= (WXWidget
) NULL
;
114 m_mainWidget
= (WXWidget
) NULL
;
115 m_workArea
= (WXWidget
) NULL
;
116 m_clientArea
= (WXWidget
) NULL
;
119 bool wxFrame::Create(wxWindow
*parent
,
121 const wxString
& title
,
125 const wxString
& name
)
127 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
132 wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
133 m_foregroundColour
= *wxBLACK
;
134 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
136 int x
= pos
.x
, y
= pos
.y
;
137 int width
= size
.x
, height
= size
.y
;
139 // Set reasonable values for position and size if defaults have been
142 // MB TODO: something better than these arbitrary values ?
143 // VZ should use X resources for this...
149 int displayW
, displayH
;
150 wxDisplaySize( &displayW
, &displayH
);
154 x
= (displayW
- width
) / 2;
159 y
= (displayH
- height
) / 2;
165 wxLogTrace(wxTRACE_Messages
,
166 "Created frame (0x%p) with work area 0x%p and client "
167 "area 0x%p", m_mainWidget
, m_workArea
, m_clientArea
);
169 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,False
,
170 wxUniversalRepaintProc
, (XtPointer
) this);
173 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
175 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
177 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
179 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
183 ChangeBackgroundColour();
187 wxSize
newSize(width
, height
);
188 wxSizeEvent
sizeEvent(newSize
, GetId());
189 sizeEvent
.SetEventObject(this);
191 GetEventHandler()->ProcessEvent(sizeEvent
);
196 bool wxFrame::XmDoCreateTLW(wxWindow
* WXUNUSED(parent
),
197 wxWindowID
WXUNUSED(id
),
198 const wxString
& WXUNUSED(title
),
199 const wxPoint
& WXUNUSED(pos
),
200 const wxSize
& WXUNUSED(size
),
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();
282 delete m_frameMenuBar
;
283 m_frameMenuBar
= NULL
;
286 if (m_frameStatusBar
)
288 delete m_frameStatusBar
;
289 m_frameStatusBar
= NULL
;
294 Widget frameShell
= (Widget
)GetShellWidget();
297 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
298 False
, (XtEventHandler
)wxFrameMapProc
,
303 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
304 XtDestroyWidget( (Widget
)m_clientArea
);
309 XtVaSetValues( (Widget
)m_mainWidget
,
310 XmNworkWindow
, (Widget
)NULL
,
313 wxDeleteWindowFromTable( (Widget
)m_workArea
);
314 XtDestroyWidget( (Widget
)m_workArea
);
318 XtDestroyWidget( (Widget
)m_mainWidget
);
321 XtDestroyWidget( frameShell
);
324 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
325 void wxFrame::DoGetClientSize(int *x
, int *y
) const
328 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
330 if (m_frameStatusBar
)
333 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
334 yy
= (Dimension
)(yy
- sbh
);
340 m_frameToolBar
->GetSize(& tbw
, & tbh
);
341 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
342 xx
= (Dimension
)(xx
- tbw
);
344 yy
= (Dimension
)(yy
- tbh
);
346 #endif // wxUSE_TOOLBAR
348 //CE found a call here with NULL y pointer
355 // Set the client size (i.e. leave the calculation of borders etc.
357 void wxFrame::DoSetClientSize(int width
, int height
)
359 // Calculate how large the new main window should be
360 // by finding the difference between the client area and the
361 // main window area, and adding on to the new client area
363 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
367 if (m_frameStatusBar
)
370 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
377 m_frameToolBar
->GetSize(& tbw
, & tbh
);
378 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
383 #endif // wxUSE_TOOLBAR
385 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
389 wxSize
newSize(width
, height
);
390 wxSizeEvent
sizeEvent(newSize
, GetId());
391 sizeEvent
.SetEventObject(this);
393 GetEventHandler()->ProcessEvent(sizeEvent
);
397 void wxFrame::DoGetSize(int *width
, int *height
) const
400 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
401 *width
= xx
; *height
= yy
;
404 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
407 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
409 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
411 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
413 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
415 if (!(height
== -1 && width
== -1))
421 bool wxFrame::Show( bool show
)
423 if( !wxWindowBase::Show( show
) )
428 Widget shell
= (Widget
)GetShellWidget();
430 return wxWindow::Show(show
);
432 SetVisibleStatus(show
);
435 XtPopup(shell
, XtGrabNone
);
445 void wxFrame::SetTitle(const wxString
& title
)
447 wxString oldTitle
= GetTitle();
448 if( title
== oldTitle
)
451 wxTopLevelWindow::SetTitle( title
);
454 XtVaSetValues( (Widget
)m_frameShell
,
455 XmNtitle
, title
.c_str(),
456 XmNiconName
, title
.c_str(),
460 void wxFrame::DoSetIcon(const wxIcon
& icon
)
465 if (!icon
.Ok() || !icon
.GetDrawable())
468 XtVaSetValues((Widget
) m_frameShell
,
469 XtNiconPixmap
, icon
.GetDrawable(),
473 void wxFrame::SetIcon(const wxIcon
& icon
)
475 SetIcons( wxIconBundle( icon
) );
478 void wxFrame::SetIcons(const wxIconBundle
& icons
)
480 wxFrameBase::SetIcons( icons
);
485 DoSetIcon( m_icons
.GetIcon( -1 ) );
486 wxSetIconsX11(GetXDisplay(),
487 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
490 void wxFrame::PositionStatusBar()
492 if (!m_frameStatusBar
)
496 GetClientSize(&w
, &h
);
498 m_frameStatusBar
->GetSize(&sw
, &sh
);
500 // Since we wish the status bar to be directly under the client area,
501 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
502 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
505 WXWidget
wxFrame::GetMenuBarWidget() const
508 return GetMenuBar()->GetMainWidget();
510 return (WXWidget
) NULL
;
513 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
517 m_frameMenuBar
= NULL
;
521 // Currently can't set it twice
522 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
526 m_frameMenuBar
->DestroyMenuBar();
527 delete m_frameMenuBar
;
530 m_frameMenuBar
= menuBar
;
531 m_frameMenuBar
->CreateMenuBar(this);
534 // Responds to colour changes, and passes event on to children.
535 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
537 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
540 if ( m_frameStatusBar
)
542 wxSysColourChangedEvent event2
;
543 event2
.SetEventObject( m_frameStatusBar
);
544 m_frameStatusBar
->ProcessEvent(event2
);
547 // Propagate the event to the non-top-level children
548 wxWindow::OnSysColourChanged(event
);
551 // Default activation behaviour - set the focus for the first child
553 void wxFrame::OnActivate(wxActivateEvent
& event
)
555 if (!event
.GetActive())
558 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
;
559 node
= node
->GetNext())
561 // Find a child that's a subwindow, but not a dialog box.
562 wxWindow
*child
= node
->GetData();
563 if (!child
->IsTopLevel())
571 void wxFrame::SendSizeEvent()
573 wxSizeEvent
event(GetSize(), GetId());
574 event
.SetEventObject(this);
575 GetEventHandler()->AddPendingEvent(event
);
580 wxToolBar
* wxFrame::CreateToolBar(long style
,
582 const wxString
& name
)
584 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
589 return m_frameToolBar
;
592 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
594 wxFrameBase::SetToolBar(toolbar
);
598 void wxFrame::PositionToolBar()
600 wxToolBar
* tb
= GetToolBar();
604 GetClientSize(& cw
, &ch
);
607 tb
->GetSize(& tw
, & th
);
609 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
611 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
612 // means, pretend we don't have toolbar/status bar, so we
613 // have the original client size.
618 // Use the 'real' position
622 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
625 #endif // wxUSE_TOOLBAR
628 bool wxFrame::PreResize()
632 #endif // wxUSE_TOOLBAR
636 #endif // wxUSE_STATUSBAR
641 WXWidget
wxFrame::GetClientWidget() const
646 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
651 void wxFrame::ChangeBackgroundColour()
653 if (GetClientWidget())
654 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
657 void wxFrame::ChangeForegroundColour()
659 if (GetClientWidget())
660 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
663 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
664 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
665 XCrossingEvent
* event
)
667 wxFrame
*tli
= (wxFrame
*)clientData
;
669 XEvent
*e
= (XEvent
*)event
;
671 if( e
->xany
.type
== MapNotify
)
674 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
675 if( !tli
->GetVisibleStatus() )
677 /* We really wanted this to be hidden! */
678 XtUnmapWidget( frameShell
);
681 else if( e
->xany
.type
== UnmapNotify
)
683 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);