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 // ============================================================================
96 // ============================================================================
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
107 m_frameShell
= (WXWidget
) NULL
;
108 m_mainWidget
= (WXWidget
) NULL
;
109 m_workArea
= (WXWidget
) NULL
;
110 m_clientArea
= (WXWidget
) NULL
;
113 bool wxFrame::Create(wxWindow
*parent
,
115 const wxString
& title
,
119 const wxString
& name
)
121 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
125 int x
= pos
.x
, y
= pos
.y
;
126 int width
= size
.x
, height
= size
.y
;
128 // Set reasonable values for position and size if defaults have been
131 // MB TODO: something better than these arbitrary values ?
132 // VZ should use X resources for this...
138 int displayW
, displayH
;
139 wxDisplaySize( &displayW
, &displayH
);
143 x
= (displayW
- width
) / 2;
148 y
= (displayH
- height
) / 2;
154 wxLogTrace(wxTRACE_Messages
,
155 "Created frame (0x%p) with work area 0x%p and client "
156 "area 0x%p", m_mainWidget
, m_workArea
, m_clientArea
);
158 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,False
,
159 wxUniversalRepaintProc
, (XtPointer
) this);
162 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
164 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
166 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
168 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
173 wxSize
newSize(width
, height
);
174 wxSizeEvent
sizeEvent(newSize
, GetId());
175 sizeEvent
.SetEventObject(this);
177 HandleWindowEvent(sizeEvent
);
182 bool wxFrame::XmDoCreateTLW(wxWindow
* WXUNUSED(parent
),
183 wxWindowID
WXUNUSED(id
),
184 const wxString
& WXUNUSED(title
),
185 const wxPoint
& WXUNUSED(pos
),
186 const wxSize
& WXUNUSED(size
),
188 const wxString
& name
)
192 frameShell
= XtCreatePopupShell( name
, topLevelShellWidgetClass
,
193 (Widget
)wxTheApp
->GetTopLevelWidget(),
196 XtVaSetValues(frameShell
,
197 // Allows menu to resize
198 XmNallowShellResize
, True
,
199 XmNdeleteResponse
, XmDO_NOTHING
,
200 XmNmappedWhenManaged
, False
,
201 XmNiconic
, (style
& wxICONIZE
) ? True
: False
,
204 m_frameShell
= (WXWidget
)frameShell
;
206 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
207 xmMainWindowWidgetClass
, frameShell
,
208 XmNresizePolicy
, XmRESIZE_NONE
,
211 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
212 xmFormWidgetClass
, (Widget
) m_mainWidget
,
213 XmNresizePolicy
, XmRESIZE_NONE
,
216 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
217 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
220 XmNrightAttachment
, XmATTACH_FORM
,
221 XmNleftAttachment
, XmATTACH_FORM
,
222 XmNtopAttachment
, XmATTACH_FORM
,
223 XmNbottomAttachment
, XmATTACH_FORM
,
226 XtVaSetValues((Widget
) m_mainWidget
,
227 XmNworkWindow
, (Widget
) m_workArea
,
230 XtManageChild((Widget
) m_clientArea
);
231 XtManageChild((Widget
) m_workArea
);
233 XtTranslations ptr
= XtParseTranslationTable( "<Configure>: resize()" );
234 XtOverrideTranslations( (Widget
) m_workArea
, ptr
);
235 XtFree( (char *)ptr
);
237 /* Part of show-&-hide fix */
238 XtAddEventHandler( frameShell
, StructureNotifyMask
,
239 False
, (XtEventHandler
)wxFrameMapProc
,
242 XtRealizeWidget(frameShell
);
244 wxAddWindowToTable( (Widget
)m_workArea
, this);
245 wxAddWindowToTable( (Widget
)m_clientArea
, this);
247 wxModelessWindows
.Append( this );
258 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, False
,
259 wxUniversalRepaintProc
, (XtPointer
) this);
267 m_frameMenuBar
->DestroyMenuBar();
268 wxDELETE(m_frameMenuBar
);
271 wxDELETE(m_frameStatusBar
);
275 Widget frameShell
= (Widget
)GetShellWidget();
278 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
279 False
, (XtEventHandler
)wxFrameMapProc
,
284 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
285 XtDestroyWidget( (Widget
)m_clientArea
);
290 XtVaSetValues( (Widget
)m_mainWidget
,
291 XmNworkWindow
, (Widget
)NULL
,
294 wxDeleteWindowFromTable( (Widget
)m_workArea
);
295 XtDestroyWidget( (Widget
)m_workArea
);
299 XtDestroyWidget( (Widget
)m_mainWidget
);
302 XtDestroyWidget( frameShell
);
305 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
306 void wxFrame::DoGetClientSize(int *x
, int *y
) const
309 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
311 if (m_frameStatusBar
)
314 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
315 yy
= (Dimension
)(yy
- sbh
);
321 m_frameToolBar
->GetSize(& tbw
, & tbh
);
322 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
323 xx
= (Dimension
)(xx
- tbw
);
325 yy
= (Dimension
)(yy
- tbh
);
327 #endif // wxUSE_TOOLBAR
329 //CE found a call here with NULL y pointer
336 // Set the client size (i.e. leave the calculation of borders etc.
338 void wxFrame::DoSetClientSize(int width
, int height
)
340 // Calculate how large the new main window should be
341 // by finding the difference between the client area and the
342 // main window area, and adding on to the new client area
344 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
348 if (m_frameStatusBar
)
351 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
358 m_frameToolBar
->GetSize(& tbw
, & tbh
);
359 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
364 #endif // wxUSE_TOOLBAR
366 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
370 wxSize
newSize(width
, height
);
371 wxSizeEvent
sizeEvent(newSize
, GetId());
372 sizeEvent
.SetEventObject(this);
374 HandleWindowEvent(sizeEvent
);
378 void wxFrame::DoGetSize(int *width
, int *height
) const
382 *width
= -1; *height
= -1;
387 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
388 *width
= xx
; *height
= yy
;
391 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
394 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
396 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
398 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
400 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
402 if (!(height
== -1 && width
== -1))
408 bool wxFrame::Show( bool show
)
410 if( !wxWindowBase::Show( show
) )
415 Widget shell
= (Widget
)GetShellWidget();
417 return wxWindow::Show(show
);
419 SetVisibleStatus(show
);
422 XtPopup(shell
, XtGrabNone
);
432 void wxFrame::SetTitle(const wxString
& title
)
434 wxString oldTitle
= GetTitle();
435 if( title
== oldTitle
)
438 wxTopLevelWindow::SetTitle( title
);
441 XtVaSetValues( (Widget
)m_frameShell
,
442 XmNtitle
, (const char*)title
.mb_str(),
443 XmNiconName
, (const char*)title
.mb_str(),
447 void wxFrame::DoSetIcon(const wxIcon
& icon
)
452 if (!icon
.Ok() || !icon
.GetDrawable())
455 XtVaSetValues((Widget
) m_frameShell
,
456 XtNiconPixmap
, icon
.GetDrawable(),
460 void wxFrame::SetIcons(const wxIconBundle
& icons
)
462 wxFrameBase::SetIcons( icons
);
467 DoSetIcon( m_icons
.GetIcon( -1 ) );
468 wxSetIconsX11(GetXDisplay(),
469 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
472 void wxFrame::PositionStatusBar()
474 if (!m_frameStatusBar
)
478 GetClientSize(&w
, &h
);
480 m_frameStatusBar
->GetSize(&sw
, &sh
);
482 // Since we wish the status bar to be directly under the client area,
483 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
484 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
487 WXWidget
wxFrame::GetMenuBarWidget() const
490 return GetMenuBar()->GetMainWidget();
492 return (WXWidget
) NULL
;
495 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
499 m_frameMenuBar
= NULL
;
503 // Currently can't set it twice
504 // wxASSERT_MSG( (m_frameMenuBar == NULL), "Cannot set the menubar more than once");
508 m_frameMenuBar
->DestroyMenuBar();
509 delete m_frameMenuBar
;
512 m_frameMenuBar
= menuBar
;
513 m_frameMenuBar
->CreateMenuBar(this);
516 // Responds to colour changes, and passes event on to children.
517 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
519 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
522 if ( m_frameStatusBar
)
524 wxSysColourChangedEvent event2
;
525 event2
.SetEventObject( m_frameStatusBar
);
526 m_frameStatusBar
->HandleWindowEvent(event2
);
529 // Propagate the event to the non-top-level children
530 wxWindow::OnSysColourChanged(event
);
533 // Default activation behaviour - set the focus for the first child
535 void wxFrame::OnActivate(wxActivateEvent
& event
)
537 if (!event
.GetActive())
540 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
;
541 node
= node
->GetNext())
543 // Find a child that's a subwindow, but not a dialog box.
544 wxWindow
*child
= node
->GetData();
545 if (!child
->IsTopLevel())
555 wxToolBar
* wxFrame::CreateToolBar(long style
,
557 const wxString
& name
)
559 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
564 return m_frameToolBar
;
567 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
569 wxFrameBase::SetToolBar(toolbar
);
573 void wxFrame::PositionToolBar()
575 wxToolBar
* tb
= GetToolBar();
579 GetClientSize(& cw
, &ch
);
582 tb
->GetSize(& tw
, & th
);
584 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
586 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
587 // means, pretend we don't have toolbar/status bar, so we
588 // have the original client size.
593 // Use the 'real' position
597 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
600 #endif // wxUSE_TOOLBAR
603 bool wxFrame::PreResize()
607 #endif // wxUSE_TOOLBAR
611 #endif // wxUSE_STATUSBAR
616 WXWidget
wxFrame::GetClientWidget() const
621 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
626 void wxFrame::ChangeBackgroundColour()
628 if (GetClientWidget())
629 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
632 void wxFrame::ChangeForegroundColour()
634 if (GetClientWidget())
635 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
638 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
639 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
640 XCrossingEvent
* event
)
642 wxFrame
*tli
= (wxFrame
*)clientData
;
644 XEvent
*e
= (XEvent
*)event
;
646 if( e
->xany
.type
== MapNotify
)
649 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
650 if( !tli
->GetVisibleStatus() )
652 /* We really wanted this to be hidden! */
653 XtUnmapWidget( frameShell
);
656 else if( e
->xany
.type
== UnmapNotify
)
658 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);