1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frame.h"
17 #include "wx/statusbr.h"
18 #include "wx/toolbar.h"
19 #include "wx/menuitem.h"
21 #include "wx/dcclient.h"
22 #include "wx/dialog.h"
23 #include "wx/settings.h"
27 #if defined(__ultrix) || defined(__sgi)
32 #include <X11/Shell.h>
38 #include <Xm/MwmUtil.h>
39 #include <Xm/BulletinB.h>
42 #include <Xm/RowColumn.h>
44 #include <Xm/AtomMgr.h>
45 #include <Xm/LabelG.h>
48 #include <Xm/Protocols.h>
51 #include "wx/motif/private.h"
53 void wxCloseFrameCallback(Widget
, XtPointer
, XmAnyCallbackStruct
*cbs
);
54 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
55 XmAnyCallbackStruct
*cbs
);
56 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
57 XCrossingEvent
* event
);
59 extern wxList wxModelessWindows
;
60 extern wxList wxPendingDelete
;
62 // TODO: this should be tidied so that any frame can be the
64 static bool wxTopLevelUsed
= FALSE
;
66 #if !USE_SHARED_LIBRARY
67 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
68 EVT_SIZE(wxFrame::OnSize
)
69 EVT_ACTIVATE(wxFrame::OnActivate
)
70 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight
)
71 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
72 EVT_IDLE(wxFrame::OnIdle
)
73 EVT_CLOSE(wxFrame::OnCloseWindow
)
76 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
79 #if wxUSE_NATIVE_STATUSBAR
80 bool wxFrame::m_useNativeStatusBar
= TRUE
;
82 bool wxFrame::m_useNativeStatusBar
= FALSE
;
88 m_frameToolBar
= NULL
;
89 #endif // wxUSE_TOOLBAR
91 m_frameMenuBar
= NULL
;
92 m_frameStatusBar
= NULL
;
98 m_frameShell
= (WXWidget
) NULL
;
99 m_frameWidget
= (WXWidget
) NULL
;;
100 m_workArea
= (WXWidget
) NULL
;;
101 m_clientArea
= (WXWidget
) NULL
;;
102 m_visibleStatus
= TRUE
;
106 bool wxFrame::Create(wxWindow
*parent
,
108 const wxString
& title
,
112 const wxString
& name
)
115 wxTopLevelWindows
.Append(this);
119 m_windowStyle
= style
;
120 m_frameMenuBar
= NULL
;
122 m_frameToolBar
= NULL
;
123 #endif // wxUSE_TOOLBAR
124 m_frameStatusBar
= NULL
;
127 m_frameShell
= (WXWidget
) NULL
;
128 m_frameWidget
= (WXWidget
) NULL
;;
129 m_workArea
= (WXWidget
) NULL
;;
130 m_clientArea
= (WXWidget
) NULL
;;
131 m_visibleStatus
= TRUE
;
134 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
135 m_foregroundColour
= *wxBLACK
;
136 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
141 m_windowId
= (int)NewControlId();
143 if (parent
) parent
->AddChild(this);
145 wxModelessWindows
.Append(this);
147 int x
= pos
.x
; int y
= pos
.y
;
148 int width
= size
.x
; int height
= size
.y
;
152 // Change suggested by Matthew Flatt
153 m_frameShell
= (WXWidget
)XtAppCreateShell
156 wxTheApp
->GetClassName(),
157 topLevelShellWidgetClass
,
158 (Display
*) wxGetDisplay(),
165 m_frameShell
= wxTheApp
->GetTopLevelWidget();
166 wxTopLevelUsed
= TRUE
;
169 XtVaSetValues((Widget
) m_frameShell
,
170 // Allows menu to resize
171 XmNallowShellResize
, True
,
172 XmNdeleteResponse
, XmDO_NOTHING
,
173 XmNmappedWhenManaged
, False
,
174 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
178 XtVaSetValues((Widget
) m_frameShell
,
179 XmNtitle
, (const char*) title
,
182 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
183 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
184 XmNresizePolicy
, XmRESIZE_NONE
,
187 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
188 xmFormWidgetClass
, (Widget
) m_frameWidget
,
189 XmNresizePolicy
, XmRESIZE_NONE
,
192 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
193 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
196 XmNrightAttachment
, XmATTACH_FORM
,
197 XmNleftAttachment
, XmATTACH_FORM
,
198 XmNtopAttachment
, XmATTACH_FORM
,
199 XmNbottomAttachment
, XmATTACH_FORM
,
200 // XmNresizePolicy, XmRESIZE_ANY,
203 wxLogDebug("Created frame (0x%08x) with work area 0x%08x and client "
204 "area 0x%08x", m_frameWidget
, m_workArea
, m_clientArea
);
206 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
207 wxUniversalRepaintProc
, (XtPointer
) this);
209 XtVaSetValues((Widget
) m_frameWidget
,
210 XmNworkWindow
, (Widget
) m_workArea
,
213 XtManageChild((Widget
) m_clientArea
);
214 XtManageChild((Widget
) m_workArea
);
216 wxAddWindowToTable((Widget
) m_workArea
, this);
220 XtOverrideTranslations((Widget
) m_workArea
,
221 ptr
= XtParseTranslationTable("<Configure>: resize()"));
225 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
226 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
228 /* Part of show-&-hide fix */
229 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
230 False
, (XtEventHandler
)wxFrameMapProc
,
231 (XtPointer
)m_workArea
);
234 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
236 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
238 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
240 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
242 m_mainWidget
= m_frameWidget
;
246 // This patch comes from Torsten Liermann lier@lier1.muc.de
247 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
250 if (style
& wxRESIZE_BORDER
)
251 decor
|= MWM_DECOR_RESIZEH
;
252 if (style
& wxSYSTEM_MENU
)
253 decor
|= MWM_DECOR_MENU
;
254 if ((style
& wxCAPTION
) ||
255 (style
& wxTINY_CAPTION_HORIZ
) ||
256 (style
& wxTINY_CAPTION_VERT
))
257 decor
|= MWM_DECOR_TITLE
;
258 if (style
& wxTHICK_FRAME
)
259 decor
|= MWM_DECOR_BORDER
;
260 if (style
& wxTHICK_FRAME
)
261 decor
|= MWM_DECOR_BORDER
;
262 if (style
& wxMINIMIZE_BOX
)
263 decor
|= MWM_DECOR_MINIMIZE
;
264 if (style
& wxMAXIMIZE_BOX
)
265 decor
|= MWM_DECOR_MAXIMIZE
;
266 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
268 // This allows non-Motif window managers to support at least the
269 // no-decorations case.
273 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
275 XtRealizeWidget((Widget
) m_frameShell
);
277 // Intercept CLOSE messages from the window manager
278 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
279 #if (XmREVISION > 1 || XmVERSION > 1)
280 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
283 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
285 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
289 ChangeBackgroundColour();
293 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
294 sizeEvent
.SetEventObject(this);
296 GetEventHandler()->ProcessEvent(sizeEvent
);
304 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
305 wxUniversalRepaintProc
, (XtPointer
) this);
312 m_frameMenuBar
->DestroyMenuBar();
314 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
315 #if MOTIF_MENUBAR_DELETE_FIX
316 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
318 delete m_frameMenuBar
;
319 m_frameMenuBar
= NULL
;
322 wxTopLevelWindows
.DeleteObject(this);
323 wxModelessWindows
.DeleteObject(this);
325 if (m_frameStatusBar
)
326 delete m_frameStatusBar
;
332 for (i = 0; i < wxMAX_STATUS; i++)
333 if (statusTextWidget[i])
334 XtDestroyWidget (statusTextWidget[i]);
337 XtDestroyWidget (statusLineForm);
339 if (statusLineWidget)
340 XtDestroyWidget (statusLineWidget);
345 wxDeleteWindowFromTable((Widget
) m_workArea
);
347 XtDestroyWidget ((Widget
) m_workArea
);
352 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
353 XtDestroyWidget ((Widget
) m_frameWidget
);
357 XtDestroyWidget ((Widget
) m_frameShell
);
359 SetMainWidget((WXWidget
) NULL
);
361 /* Check if it's the last top-level window */
363 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
365 wxTheApp
->SetTopWindow(NULL
);
367 if (wxTheApp
->GetExitOnFrameDelete())
369 // Signal to the app that we're going to close
370 wxTheApp
->ExitMainLoop();
376 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
377 void wxFrame::GetClientSize(int *x
, int *y
) const
380 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
382 if (m_frameStatusBar
)
385 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
392 m_frameToolBar
->GetSize(& tbw
, & tbh
);
393 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
398 #endif // wxUSE_TOOLBAR
400 if (GetMenuBar() != (wxMenuBar*) NULL)
402 // it seems that if a frame holds a panel, the menu bar size
403 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
404 bool hasSubPanel = FALSE;
405 for(wxNode* node = GetChildren().First(); node; node = node->Next())
407 wxWindow *win = (wxWindow *)node->Data();
408 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
415 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
424 // Set the client size (i.e. leave the calculation of borders etc.
426 void wxFrame::DoSetClientSize(int width
, int height
)
428 // Calculate how large the new main window should be
429 // by finding the difference between the client area and the
430 // main window area, and adding on to the new client area
432 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
436 if (m_frameStatusBar
)
439 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
446 m_frameToolBar
->GetSize(& tbw
, & tbh
);
447 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
452 #endif // wxUSE_TOOLBAR
454 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
458 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
459 sizeEvent
.SetEventObject(this);
461 GetEventHandler()->ProcessEvent(sizeEvent
);
465 void wxFrame::GetSize(int *width
, int *height
) const
468 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
469 *width
= xx
; *height
= yy
;
472 void wxFrame::GetPosition(int *x
, int *y
) const
474 Window parent_window
= XtWindow((Widget
) m_frameShell
),
475 next_parent
= XtWindow((Widget
) m_frameShell
),
476 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
478 // search for the parent that is child of ROOT, because the WM may
479 // reparent twice and notify only the next parent (like FVWM)
480 while (next_parent
!= root
) {
481 Window
*theChildren
; unsigned int n
;
482 parent_window
= next_parent
;
483 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
484 &next_parent
, &theChildren
, &n
);
485 XFree(theChildren
); // not needed
487 int xx
, yy
; unsigned int dummy
;
488 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
489 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
494 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
497 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
499 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
501 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
503 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
505 if (!(height
== -1 && width
== -1))
509 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
510 sizeEvent
.SetEventObject(this);
512 GetEventHandler()->ProcessEvent(sizeEvent
);
516 bool wxFrame::Show(bool show
)
519 return wxWindow::Show(show
);
521 m_visibleStatus
= show
; /* show-&-hide fix */
525 XtMapWidget((Widget
) m_frameShell
);
526 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
528 XtUnmapWidget((Widget
) m_frameShell
);
529 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
534 void wxFrame::Iconize(bool iconize
)
540 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
543 // Equivalent to maximize/restore in Windows
544 void wxFrame::Maximize(bool maximize
)
548 if (maximize
&& m_frameShell
)
549 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
552 bool wxFrame::IsIconized() const
558 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
563 bool wxFrame::IsMaximized(void) const
565 // No maximizing in Motif (?)
569 void wxFrame::SetTitle(const wxString
& title
)
571 if (title
== m_title
)
577 XtVaSetValues((Widget
) m_frameShell
,
578 XmNtitle
, (const char*) title
,
579 XmNiconName
, (const char*) title
,
583 void wxFrame::SetIcon(const wxIcon
& icon
)
590 if (!icon
.Ok() || !icon
.GetPixmap())
593 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
596 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
597 const wxString
& name
)
599 wxStatusBar
*statusBar
= NULL
;
601 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
604 // Set the height according to the font and the border size
605 wxClientDC
dc(statusBar
);
606 dc
.SetFont(statusBar
->GetFont());
609 dc
.GetTextExtent("X", &x
, &y
);
611 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
613 statusBar
->SetSize(-1, -1, 100, height
);
615 statusBar
->SetFieldsCount(number
);
619 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
620 const wxString
& name
)
622 // Calling CreateStatusBar twice is an error.
623 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
624 "recreating status bar in wxFrame" );
626 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
628 if ( m_frameStatusBar
)
631 return m_frameStatusBar
;
637 void wxFrame::SetStatusText(const wxString
& text
, int number
)
639 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
641 m_frameStatusBar
->SetStatusText(text
, number
);
644 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
646 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
648 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
652 void wxFrame::PositionStatusBar()
654 if (!m_frameStatusBar
)
658 GetClientSize(&w
, &h
);
660 m_frameStatusBar
->GetSize(&sw
, &sh
);
662 // Since we wish the status bar to be directly under the client area,
663 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
664 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
667 WXWidget
wxFrame::GetMenuBarWidget() const
670 return GetMenuBar()->GetMainWidget();
672 return (WXWidget
) NULL
;
675 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
679 m_frameMenuBar
= NULL
;
683 // Currently can't set it twice
684 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
688 m_frameMenuBar
->DestroyMenuBar();
689 delete m_frameMenuBar
;
692 m_frameMenuBar
= menuBar
;
693 m_frameMenuBar
->CreateMenuBar(this);
698 // Work out max. size
699 wxNode
*node
= GetChildren().First();
704 // Find a child that's a subwindow, but not a dialog box.
705 wxWindow
*win
= (wxWindow
*)node
->Data();
707 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
708 !win
->IsKindOf(CLASSINFO(wxDialog
)))
712 win
->GetSize(&width
, &height
);
713 win
->GetPosition(&x
, &y
);
715 if ((x
+ width
) > max_width
)
716 max_width
= x
+ width
;
717 if ((y
+ height
) > max_height
)
718 max_height
= y
+ height
;
722 SetClientSize(max_width
, max_height
);
725 // Responds to colour changes, and passes event on to children.
726 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
728 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
731 if ( m_frameStatusBar
)
733 wxSysColourChangedEvent event2
;
734 event2
.SetEventObject( m_frameStatusBar
);
735 m_frameStatusBar
->ProcessEvent(event2
);
738 // Propagate the event to the non-top-level children
739 wxWindow::OnSysColourChanged(event
);
742 // Default resizing behaviour - if only ONE subwindow,
743 // resize to client rectangle size
744 void wxFrame::OnSize(wxSizeEvent
& event
)
746 // if we're using constraints - do use them
747 #if wxUSE_CONSTRAINTS
748 if ( GetAutoLayout() ) {
754 // do we have _exactly_ one child?
755 wxWindow
*child
= NULL
;
756 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
758 wxWindow
*win
= (wxWindow
*)node
->Data();
759 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
760 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
761 (win
!= GetStatusBar())
763 && (win
!= GetToolBar())
764 #endif // wxUSE_TOOLBAR
768 return; // it's our second subwindow - nothing to do
774 // we have exactly one child - set it's size to fill the whole frame
775 int clientW
, clientH
;
776 GetClientSize(&clientW
, &clientH
);
781 child
->SetSize(x
, y
, clientW
, clientH
);
785 // Default activation behaviour - set the focus for the first child
787 void wxFrame::OnActivate(wxActivateEvent
& event
)
789 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
791 // Find a child that's a subwindow, but not a dialog box.
792 wxWindow
*child
= (wxWindow
*)node
->Data();
793 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
794 !child
->IsKindOf(CLASSINFO(wxDialog
)))
802 // The default implementation for the close window event.
803 // OnClose for backward compatibility.
805 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
810 // Destroy the window (delayed, if a managed window)
811 bool wxFrame::Destroy()
813 if (!wxPendingDelete
.Member(this))
814 wxPendingDelete
.Append(this);
818 // Default menu selection behaviour - display a help string
819 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
823 if (event
.GetMenuId() == -1)
827 wxMenuBar
*menuBar
= GetMenuBar();
830 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
831 if (helpString
!= "")
832 SetStatusText(helpString
);
838 wxMenuBar
*wxFrame::GetMenuBar() const
840 return m_frameMenuBar
;
843 void wxFrame::Centre(int direction
)
845 int display_width
, display_height
, width
, height
, x
, y
;
846 wxDisplaySize(&display_width
, &display_height
);
848 GetSize(&width
, &height
);
851 if (direction
& wxHORIZONTAL
)
852 x
= (int)((display_width
- width
)/2);
853 if (direction
& wxVERTICAL
)
854 y
= (int)((display_height
- height
)/2);
856 SetSize(x
, y
, width
, height
);
859 // Call this to simulate a menu command
860 void wxFrame::Command(int id
)
865 void wxFrame::ProcessCommand(int id
)
867 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
868 commandEvent
.SetInt( id
);
869 commandEvent
.SetEventObject( this );
871 wxMenuBar
*bar
= GetMenuBar() ;
875 /* TODO: check the menu item if required
876 wxMenuItem *item = bar->FindItemForId(id) ;
877 if (item && item->IsCheckable())
879 bar->Check(id,!bar->Checked(id)) ;
883 wxEvtHandler
* evtHandler
= GetEventHandler();
885 evtHandler
->ProcessEvent(commandEvent
);
888 // Checks if there is a toolbar, and returns the first free client position
889 wxPoint
wxFrame::GetClientAreaOrigin() const
896 GetToolBar()->GetSize(& w
, & h
);
898 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
907 #endif // wxUSE_TOOLBAR
912 void wxFrame::ScreenToClient(int *x
, int *y
) const
914 wxWindow::ScreenToClient(x
, y
);
916 // We may be faking the client origin.
917 // So a window that's really at (0, 30) may appear
918 // (to wxWin apps) to be at (0, 0).
919 wxPoint
pt(GetClientAreaOrigin());
924 void wxFrame::ClientToScreen(int *x
, int *y
) const
926 // We may be faking the client origin.
927 // So a window that's really at (0, 30) may appear
928 // (to wxWin apps) to be at (0, 0).
929 wxPoint
pt1(GetClientAreaOrigin());
933 wxWindow::ClientToScreen(x
, y
);
937 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
939 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
940 "recreating toolbar in wxFrame" );
942 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
955 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
957 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
960 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
962 m_frameToolBar
= toolbar
;
965 wxToolBar
*wxFrame::GetToolBar() const
967 return m_frameToolBar
;
970 void wxFrame::PositionToolBar()
974 GetClientSize(& cw
, &ch
);
979 GetToolBar()->GetSize(& tw
, & th
);
981 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
983 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
984 // means, pretend we don't have toolbar/status bar, so we
985 // have the original client size.
986 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
990 // Use the 'real' position
991 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
995 #endif // wxUSE_TOOLBAR
997 void wxFrame::CaptureMouse()
1002 if (GetMainWidget())
1003 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
1004 m_winCaptured
= TRUE
;
1007 void wxFrame::ReleaseMouse()
1012 if (GetMainWidget())
1013 XtRemoveGrab((Widget
) m_frameShell
);
1014 m_winCaptured
= FALSE
;
1017 void wxFrame::Raise(void)
1019 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1020 next_parent
= XtWindow((Widget
) m_frameShell
),
1021 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1022 // search for the parent that is child of ROOT, because the WM may
1023 // reparent twice and notify only the next parent (like FVWM)
1024 while (next_parent
!= root
) {
1025 Window
*theChildren
; unsigned int n
;
1026 parent_window
= next_parent
;
1027 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1028 &next_parent
, &theChildren
, &n
);
1029 XFree(theChildren
); // not needed
1031 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1034 void wxFrame::Lower(void)
1036 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1037 next_parent
= XtWindow((Widget
) m_frameShell
),
1038 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1039 // search for the parent that is child of ROOT, because the WM may
1040 // reparent twice and notify only the next parent (like FVWM)
1041 while (next_parent
!= root
) {
1042 Window
*theChildren
; unsigned int n
;
1043 parent_window
= next_parent
;
1044 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1045 &next_parent
, &theChildren
, &n
);
1046 XFree(theChildren
); // not needed
1048 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1051 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1052 XmAnyCallbackStruct
*cbs
)
1054 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1056 // wxFrame *frame = (wxFrame *)clientData;
1057 // frame->GetEventHandler()->OnSetFocus();
1060 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1061 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1062 XCrossingEvent
* event
)
1064 wxFrame
*frame
= (wxFrame
*)wxGetWindowFromTable((Widget
)clientData
);
1067 XEvent
*e
= (XEvent
*)event
;
1069 if (e
->xany
.type
== MapNotify
)
1072 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1073 if (!frame
->GetVisibleStatus())
1075 /* We really wanted this to be hidden! */
1076 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1079 else if (e
->xany
.type
== UnmapNotify
)
1081 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1086 bool wxFrame::PreResize()
1090 #endif // wxUSE_TOOLBAR
1091 PositionStatusBar();
1095 WXWidget
wxFrame::GetClientWidget() const
1097 return m_clientArea
;
1100 void wxFrame::ChangeFont(bool keepOriginalSize
)
1105 void wxFrame::ChangeBackgroundColour()
1107 if (GetClientWidget())
1108 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1111 void wxFrame::ChangeForegroundColour()
1113 if (GetClientWidget())
1114 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1117 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1119 wxFrame
*frame
= (wxFrame
*)client_data
;
1121 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1122 closeEvent
.SetEventObject(frame
);
1124 // May delete the frame (with delayed deletion)
1125 frame
->GetEventHandler()->ProcessEvent(closeEvent
);