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/settings.h"
38 #include "wx/toolbar.h"
39 #include "wx/statusbr.h"
43 #pragma message disable nosimpint
46 #if defined(__ultrix) || defined(__sgi)
51 #include <X11/Shell.h>
58 #include <Xm/MwmUtil.h>
59 #include <Xm/BulletinB.h>
62 #include <Xm/RowColumn.h>
64 #include <Xm/AtomMgr.h>
65 #include <Xm/LabelG.h>
68 #include <Xm/Protocols.h>
72 #pragma message enable nosimpint
75 #include "wx/motif/private.h"
76 #include "wx/unix/utilsx11.h"
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
83 XCrossingEvent
* event
);
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 extern wxList wxModelessWindows
;
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 wxSize
newSize(width
, height
);
190 wxSizeEvent
sizeEvent(newSize
, GetId());
191 sizeEvent
.SetEventObject(this);
193 GetEventHandler()->ProcessEvent(sizeEvent
);
198 bool wxFrame::XmDoCreateTLW(wxWindow
* WXUNUSED(parent
),
199 wxWindowID
WXUNUSED(id
),
200 const wxString
& WXUNUSED(title
),
201 const wxPoint
& WXUNUSED(pos
),
202 const wxSize
& WXUNUSED(size
),
204 const wxString
& name
)
208 frameShell
= XtCreatePopupShell( name
, topLevelShellWidgetClass
,
209 (Widget
)wxTheApp
->GetTopLevelWidget(),
212 XtVaSetValues(frameShell
,
213 // Allows menu to resize
214 XmNallowShellResize
, True
,
215 XmNdeleteResponse
, XmDO_NOTHING
,
216 XmNmappedWhenManaged
, False
,
217 XmNiconic
, (style
& wxICONIZE
) ? True
: False
,
220 m_frameShell
= (WXWidget
)frameShell
;
222 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
223 xmMainWindowWidgetClass
, frameShell
,
224 XmNresizePolicy
, XmRESIZE_NONE
,
227 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
228 xmFormWidgetClass
, (Widget
) m_mainWidget
,
229 XmNresizePolicy
, XmRESIZE_NONE
,
232 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
233 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
236 XmNrightAttachment
, XmATTACH_FORM
,
237 XmNleftAttachment
, XmATTACH_FORM
,
238 XmNtopAttachment
, XmATTACH_FORM
,
239 XmNbottomAttachment
, XmATTACH_FORM
,
242 XtVaSetValues((Widget
) m_mainWidget
,
243 XmNworkWindow
, (Widget
) m_workArea
,
246 XtManageChild((Widget
) m_clientArea
);
247 XtManageChild((Widget
) m_workArea
);
249 XtTranslations ptr
= XtParseTranslationTable( "<Configure>: resize()" );
250 XtOverrideTranslations( (Widget
) m_workArea
, ptr
);
251 XtFree( (char *)ptr
);
253 /* Part of show-&-hide fix */
254 XtAddEventHandler( frameShell
, StructureNotifyMask
,
255 False
, (XtEventHandler
)wxFrameMapProc
,
258 XtRealizeWidget(frameShell
);
260 wxAddWindowToTable( (Widget
)m_workArea
, this);
261 wxAddWindowToTable( (Widget
)m_clientArea
, this);
263 wxModelessWindows
.Append( this );
270 m_isBeingDeleted
= true;
274 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, False
,
275 wxUniversalRepaintProc
, (XtPointer
) this);
283 m_frameMenuBar
->DestroyMenuBar();
284 delete m_frameMenuBar
;
285 m_frameMenuBar
= NULL
;
288 if (m_frameStatusBar
)
290 delete m_frameStatusBar
;
291 m_frameStatusBar
= NULL
;
296 Widget frameShell
= (Widget
)GetShellWidget();
299 XtRemoveEventHandler( frameShell
, StructureNotifyMask
,
300 False
, (XtEventHandler
)wxFrameMapProc
,
305 wxDeleteWindowFromTable( (Widget
)m_clientArea
);
306 XtDestroyWidget( (Widget
)m_clientArea
);
311 XtVaSetValues( (Widget
)m_mainWidget
,
312 XmNworkWindow
, (Widget
)NULL
,
315 wxDeleteWindowFromTable( (Widget
)m_workArea
);
316 XtDestroyWidget( (Widget
)m_workArea
);
320 XtDestroyWidget( (Widget
)m_mainWidget
);
323 XtDestroyWidget( frameShell
);
326 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
327 void wxFrame::DoGetClientSize(int *x
, int *y
) const
330 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
332 if (m_frameStatusBar
)
335 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
336 yy
= (Dimension
)(yy
- sbh
);
342 m_frameToolBar
->GetSize(& tbw
, & tbh
);
343 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
344 xx
= (Dimension
)(xx
- tbw
);
346 yy
= (Dimension
)(yy
- tbh
);
348 #endif // wxUSE_TOOLBAR
350 //CE found a call here with NULL y pointer
357 // Set the client size (i.e. leave the calculation of borders etc.
359 void wxFrame::DoSetClientSize(int width
, int height
)
361 // Calculate how large the new main window should be
362 // by finding the difference between the client area and the
363 // main window area, and adding on to the new client area
365 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
369 if (m_frameStatusBar
)
372 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
379 m_frameToolBar
->GetSize(& tbw
, & tbh
);
380 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
385 #endif // wxUSE_TOOLBAR
387 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
391 wxSize
newSize(width
, height
);
392 wxSizeEvent
sizeEvent(newSize
, GetId());
393 sizeEvent
.SetEventObject(this);
395 GetEventHandler()->ProcessEvent(sizeEvent
);
399 void wxFrame::DoGetSize(int *width
, int *height
) const
402 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
403 *width
= xx
; *height
= yy
;
406 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
409 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
411 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
413 XtVaSetValues((Widget
) m_mainWidget
, XmNwidth
, width
, NULL
);
415 XtVaSetValues((Widget
) m_mainWidget
, XmNheight
, height
, NULL
);
417 if (!(height
== -1 && width
== -1))
423 bool wxFrame::Show( bool show
)
425 if( !wxWindowBase::Show( show
) )
430 Widget shell
= (Widget
)GetShellWidget();
432 return wxWindow::Show(show
);
434 SetVisibleStatus(show
);
437 XtPopup(shell
, XtGrabNone
);
447 void wxFrame::SetTitle(const wxString
& title
)
449 wxString oldTitle
= GetTitle();
450 if( title
== oldTitle
)
453 wxTopLevelWindow::SetTitle( title
);
456 XtVaSetValues( (Widget
)m_frameShell
,
457 XmNtitle
, title
.c_str(),
458 XmNiconName
, title
.c_str(),
462 void wxFrame::DoSetIcon(const wxIcon
& icon
)
467 if (!icon
.Ok() || !icon
.GetDrawable())
470 XtVaSetValues((Widget
) m_frameShell
,
471 XtNiconPixmap
, icon
.GetDrawable(),
475 void wxFrame::SetIcon(const wxIcon
& icon
)
477 SetIcons( wxIconBundle( icon
) );
480 void wxFrame::SetIcons(const wxIconBundle
& icons
)
482 wxFrameBase::SetIcons( icons
);
487 DoSetIcon( m_icons
.GetIcon( -1 ) );
488 wxSetIconsX11(GetXDisplay(),
489 (WXWindow
) XtWindow( (Widget
) m_frameShell
), icons
);
492 void wxFrame::PositionStatusBar()
494 if (!m_frameStatusBar
)
498 GetClientSize(&w
, &h
);
500 m_frameStatusBar
->GetSize(&sw
, &sh
);
502 // Since we wish the status bar to be directly under the client area,
503 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
504 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
507 WXWidget
wxFrame::GetMenuBarWidget() const
510 return GetMenuBar()->GetMainWidget();
512 return (WXWidget
) NULL
;
515 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
519 m_frameMenuBar
= NULL
;
523 // Currently can't set it twice
524 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
528 m_frameMenuBar
->DestroyMenuBar();
529 delete m_frameMenuBar
;
532 m_frameMenuBar
= menuBar
;
533 m_frameMenuBar
->CreateMenuBar(this);
536 // Responds to colour changes, and passes event on to children.
537 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
539 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
542 if ( m_frameStatusBar
)
544 wxSysColourChangedEvent event2
;
545 event2
.SetEventObject( m_frameStatusBar
);
546 m_frameStatusBar
->ProcessEvent(event2
);
549 // Propagate the event to the non-top-level children
550 wxWindow::OnSysColourChanged(event
);
553 // Default activation behaviour - set the focus for the first child
555 void wxFrame::OnActivate(wxActivateEvent
& event
)
557 if (!event
.GetActive())
560 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
;
561 node
= node
->GetNext())
563 // Find a child that's a subwindow, but not a dialog box.
564 wxWindow
*child
= node
->GetData();
565 if (!child
->IsTopLevel())
573 void wxFrame::SendSizeEvent()
575 wxSizeEvent
event(GetSize(), GetId());
576 event
.SetEventObject(this);
577 GetEventHandler()->AddPendingEvent(event
);
582 wxToolBar
* wxFrame::CreateToolBar(long style
,
584 const wxString
& name
)
586 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
591 return m_frameToolBar
;
594 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
596 wxFrameBase::SetToolBar(toolbar
);
600 void wxFrame::PositionToolBar()
602 wxToolBar
* tb
= GetToolBar();
606 GetClientSize(& cw
, &ch
);
609 tb
->GetSize(& tw
, & th
);
611 if (tb
->GetWindowStyleFlag() & wxTB_VERTICAL
)
613 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
614 // means, pretend we don't have toolbar/status bar, so we
615 // have the original client size.
620 // Use the 'real' position
624 tb
->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS
);
627 #endif // wxUSE_TOOLBAR
630 bool wxFrame::PreResize()
634 #endif // wxUSE_TOOLBAR
638 #endif // wxUSE_STATUSBAR
643 WXWidget
wxFrame::GetClientWidget() const
648 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
653 void wxFrame::ChangeBackgroundColour()
655 if (GetClientWidget())
656 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
659 void wxFrame::ChangeForegroundColour()
661 if (GetClientWidget())
662 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
665 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
666 static void wxFrameMapProc( Widget frameShell
, XtPointer clientData
,
667 XCrossingEvent
* event
)
669 wxFrame
*tli
= (wxFrame
*)clientData
;
671 XEvent
*e
= (XEvent
*)event
;
673 if( e
->xany
.type
== MapNotify
)
676 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
677 if( !tli
->GetVisibleStatus() )
679 /* We really wanted this to be hidden! */
680 XtUnmapWidget( frameShell
);
683 else if( e
->xany
.type
== UnmapNotify
)
685 XtVaSetValues( frameShell
, XmNiconic
, (Boolean
)True
, NULL
);