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
;
94 m_windowParent
= 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_windowFont
= 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
;
151 // Change suggested by Matthew Flatt
152 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
155 m_frameShell
= wxTheApp
->GetTopLevelWidget();
156 wxTopLevelUsed
= TRUE
;
159 XtVaSetValues((Widget
) m_frameShell
,
160 // Allows menu to resize
161 XmNallowShellResize
, True
,
162 XmNdeleteResponse
, XmDO_NOTHING
,
163 XmNmappedWhenManaged
, False
,
164 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
168 XtVaSetValues((Widget
) m_frameShell
,
169 XmNtitle
, (const char*) title
,
172 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
173 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
174 XmNresizePolicy
, XmRESIZE_NONE
,
177 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
178 xmFormWidgetClass
, (Widget
) m_frameWidget
,
179 XmNresizePolicy
, XmRESIZE_NONE
,
182 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
183 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
186 XmNrightAttachment
, XmATTACH_FORM
,
187 XmNleftAttachment
, XmATTACH_FORM
,
188 XmNtopAttachment
, XmATTACH_FORM
,
189 XmNbottomAttachment
, XmATTACH_FORM
,
190 // XmNresizePolicy, XmRESIZE_ANY,
193 XtVaSetValues((Widget
) m_frameWidget
,
194 XmNworkWindow
, (Widget
) m_workArea
,
198 XtManageChild((Widget
) m_clientArea
);
199 XtManageChild((Widget
) m_workArea
);
201 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
203 wxAddWindowToTable((Widget
) m_workArea
, this);
207 XtOverrideTranslations((Widget
) m_workArea
,
208 ptr
= XtParseTranslationTable("<Configure>: resize()"));
212 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
213 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
215 /* Part of show-&-hide fix */
216 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
217 False
, (XtEventHandler
)wxFrameMapProc
,
218 (XtPointer
)m_workArea
);
221 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
223 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
225 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
227 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
229 m_mainWidget
= m_frameWidget
;
233 // This patch comes from Torsten Liermann lier@lier1.muc.de
234 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
237 if (style
& wxRESIZE_BORDER
)
238 decor
|= MWM_DECOR_RESIZEH
;
239 if (style
& wxSYSTEM_MENU
)
240 decor
|= MWM_DECOR_MENU
;
241 if ((style
& wxCAPTION
) ||
242 (style
& wxTINY_CAPTION_HORIZ
) ||
243 (style
& wxTINY_CAPTION_VERT
))
244 decor
|= MWM_DECOR_TITLE
;
245 if (style
& wxTHICK_FRAME
)
246 decor
|= MWM_DECOR_BORDER
;
247 if (style
& wxTHICK_FRAME
)
248 decor
|= MWM_DECOR_BORDER
;
249 if (style
& wxMINIMIZE_BOX
)
250 decor
|= MWM_DECOR_MINIMIZE
;
251 if (style
& wxMAXIMIZE_BOX
)
252 decor
|= MWM_DECOR_MAXIMIZE
;
253 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
255 // This allows non-Motif window managers to support at least the
256 // no-decorations case.
260 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
262 XtRealizeWidget((Widget
) m_frameShell
);
264 // Intercept CLOSE messages from the window manager
265 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
266 #if (XmREVISION > 1 || XmVERSION > 1)
267 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
270 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
272 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
276 ChangeBackgroundColour();
280 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
281 sizeEvent
.SetEventObject(this);
283 GetEventHandler()->ProcessEvent(sizeEvent
);
295 m_frameMenuBar
->DestroyMenuBar();
297 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
298 #if MOTIF_MENUBAR_DELETE_FIX
299 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
301 delete m_frameMenuBar
;
302 m_frameMenuBar
= NULL
;
305 wxTopLevelWindows
.DeleteObject(this);
306 wxModelessWindows
.DeleteObject(this);
308 if (m_frameStatusBar
)
309 delete m_frameStatusBar
;
315 for (i = 0; i < wxMAX_STATUS; i++)
316 if (statusTextWidget[i])
317 XtDestroyWidget (statusTextWidget[i]);
320 XtDestroyWidget (statusLineForm);
322 if (statusLineWidget)
323 XtDestroyWidget (statusLineWidget);
328 wxDeleteWindowFromTable((Widget
) m_workArea
);
330 XtDestroyWidget ((Widget
) m_workArea
);
335 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
336 XtDestroyWidget ((Widget
) m_frameWidget
);
340 XtDestroyWidget ((Widget
) m_frameShell
);
342 SetMainWidget((WXWidget
) NULL
);
344 /* Check if it's the last top-level window */
346 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
348 wxTheApp
->SetTopWindow(NULL
);
350 if (wxTheApp
->GetExitOnFrameDelete())
352 // Signal to the app that we're going to close
353 wxTheApp
->ExitMainLoop();
359 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
360 void wxFrame::GetClientSize(int *x
, int *y
) const
363 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
365 if (m_frameStatusBar
)
368 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
375 m_frameToolBar
->GetSize(& tbw
, & tbh
);
376 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
381 #endif // wxUSE_TOOLBAR
383 if (GetMenuBar() != (wxMenuBar*) NULL)
385 // it seems that if a frame holds a panel, the menu bar size
386 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
387 bool hasSubPanel = FALSE;
388 for(wxNode* node = GetChildren().First(); node; node = node->Next())
390 wxWindow *win = (wxWindow *)node->Data();
391 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
398 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
407 // Set the client size (i.e. leave the calculation of borders etc.
409 void wxFrame::SetClientSize(int width
, int height
)
411 // Calculate how large the new main window should be
412 // by finding the difference between the client area and the
413 // main window area, and adding on to the new client area
415 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
419 if (m_frameStatusBar
)
422 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
429 m_frameToolBar
->GetSize(& tbw
, & tbh
);
430 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
435 #endif // wxUSE_TOOLBAR
437 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
441 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
442 sizeEvent
.SetEventObject(this);
444 GetEventHandler()->ProcessEvent(sizeEvent
);
448 void wxFrame::GetSize(int *width
, int *height
) const
451 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
452 *width
= xx
; *height
= yy
;
455 void wxFrame::GetPosition(int *x
, int *y
) const
457 Window parent_window
= XtWindow((Widget
) m_frameShell
),
458 next_parent
= XtWindow((Widget
) m_frameShell
),
459 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
461 // search for the parent that is child of ROOT, because the WM may
462 // reparent twice and notify only the next parent (like FVWM)
463 while (next_parent
!= root
) {
464 Window
*theChildren
; unsigned int n
;
465 parent_window
= next_parent
;
466 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
467 &next_parent
, &theChildren
, &n
);
468 XFree(theChildren
); // not needed
470 int xx
, yy
; unsigned int dummy
;
471 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
472 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
477 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
480 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
482 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
484 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
486 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
488 if (!(height
== -1 && width
== -1))
492 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
493 sizeEvent
.SetEventObject(this);
495 GetEventHandler()->ProcessEvent(sizeEvent
);
499 bool wxFrame::Show(bool show
)
502 return wxWindow::Show(show
);
504 m_visibleStatus
= show
; /* show-&-hide fix */
508 XtMapWidget((Widget
) m_frameShell
);
509 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
511 XtUnmapWidget((Widget
) m_frameShell
);
512 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
517 void wxFrame::Iconize(bool iconize
)
523 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
526 // Equivalent to maximize/restore in Windows
527 void wxFrame::Maximize(bool maximize
)
531 if (maximize
&& m_frameShell
)
532 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
535 bool wxFrame::IsIconized() const
541 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
546 bool wxFrame::IsMaximized(void) const
548 // No maximizing in Motif (?)
552 void wxFrame::SetTitle(const wxString
& title
)
554 if (title
== m_title
)
560 XtVaSetValues((Widget
) m_frameShell
,
561 XmNtitle
, (const char*) title
,
562 XmNiconName
, (const char*) title
,
566 void wxFrame::SetIcon(const wxIcon
& icon
)
573 if (!icon
.Ok() || !icon
.GetPixmap())
576 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
579 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
580 const wxString
& name
)
582 wxStatusBar
*statusBar
= NULL
;
584 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
587 // Set the height according to the font and the border size
588 wxClientDC
dc(statusBar
);
589 dc
.SetFont(statusBar
->GetFont());
592 dc
.GetTextExtent("X", &x
, &y
);
594 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
596 statusBar
->SetSize(-1, -1, 100, height
);
598 statusBar
->SetFieldsCount(number
);
602 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
603 const wxString
& name
)
605 // Calling CreateStatusBar twice is an error.
606 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
607 "recreating status bar in wxFrame" );
609 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
611 if ( m_frameStatusBar
)
614 return m_frameStatusBar
;
620 void wxFrame::SetStatusText(const wxString
& text
, int number
)
622 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
624 m_frameStatusBar
->SetStatusText(text
, number
);
627 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
629 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
631 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
635 void wxFrame::PositionStatusBar()
637 if (!m_frameStatusBar
)
641 GetClientSize(&w
, &h
);
643 m_frameStatusBar
->GetSize(&sw
, &sh
);
645 // Since we wish the status bar to be directly under the client area,
646 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
647 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
650 WXWidget
wxFrame::GetMenuBarWidget() const
653 return GetMenuBar()->GetMainWidget();
655 return (WXWidget
) NULL
;
658 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
662 m_frameMenuBar
= NULL
;
666 // Currently can't set it twice
667 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
671 m_frameMenuBar
->DestroyMenuBar();
672 delete m_frameMenuBar
;
675 m_frameMenuBar
= menuBar
;
676 m_frameMenuBar
->CreateMenuBar(this);
681 // Work out max. size
682 wxNode
*node
= GetChildren().First();
687 // Find a child that's a subwindow, but not a dialog box.
688 wxWindow
*win
= (wxWindow
*)node
->Data();
690 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
691 !win
->IsKindOf(CLASSINFO(wxDialog
)))
695 win
->GetSize(&width
, &height
);
696 win
->GetPosition(&x
, &y
);
698 if ((x
+ width
) > max_width
)
699 max_width
= x
+ width
;
700 if ((y
+ height
) > max_height
)
701 max_height
= y
+ height
;
705 SetClientSize(max_width
, max_height
);
708 // Responds to colour changes, and passes event on to children.
709 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
711 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
714 if ( m_frameStatusBar
)
716 wxSysColourChangedEvent event2
;
717 event2
.SetEventObject( m_frameStatusBar
);
718 m_frameStatusBar
->ProcessEvent(event2
);
721 // Propagate the event to the non-top-level children
722 wxWindow::OnSysColourChanged(event
);
725 // Default resizing behaviour - if only ONE subwindow,
726 // resize to client rectangle size
727 void wxFrame::OnSize(wxSizeEvent
& event
)
729 // if we're using constraints - do use them
730 #if wxUSE_CONSTRAINTS
731 if ( GetAutoLayout() ) {
737 // do we have _exactly_ one child?
738 wxWindow
*child
= NULL
;
739 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
741 wxWindow
*win
= (wxWindow
*)node
->Data();
742 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
743 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
744 (win
!= GetStatusBar())
746 && (win
!= GetToolBar())
747 #endif // wxUSE_TOOLBAR
751 return; // it's our second subwindow - nothing to do
757 // we have exactly one child - set it's size to fill the whole frame
758 int clientW
, clientH
;
759 GetClientSize(&clientW
, &clientH
);
764 child
->SetSize(x
, y
, clientW
, clientH
);
768 // Default activation behaviour - set the focus for the first child
770 void wxFrame::OnActivate(wxActivateEvent
& event
)
772 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
774 // Find a child that's a subwindow, but not a dialog box.
775 wxWindow
*child
= (wxWindow
*)node
->Data();
776 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
777 !child
->IsKindOf(CLASSINFO(wxDialog
)))
785 // The default implementation for the close window event.
786 // OnClose for backward compatibility.
788 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
793 // Destroy the window (delayed, if a managed window)
794 bool wxFrame::Destroy()
796 if (!wxPendingDelete
.Member(this))
797 wxPendingDelete
.Append(this);
801 // Default menu selection behaviour - display a help string
802 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
806 if (event
.GetMenuId() == -1)
810 wxMenuBar
*menuBar
= GetMenuBar();
813 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
814 if (helpString
!= "")
815 SetStatusText(helpString
);
821 wxMenuBar
*wxFrame::GetMenuBar() const
823 return m_frameMenuBar
;
826 void wxFrame::Centre(int direction
)
828 int display_width
, display_height
, width
, height
, x
, y
;
829 wxDisplaySize(&display_width
, &display_height
);
831 GetSize(&width
, &height
);
834 if (direction
& wxHORIZONTAL
)
835 x
= (int)((display_width
- width
)/2);
836 if (direction
& wxVERTICAL
)
837 y
= (int)((display_height
- height
)/2);
839 SetSize(x
, y
, width
, height
);
842 // Call this to simulate a menu command
843 void wxFrame::Command(int id
)
848 void wxFrame::ProcessCommand(int id
)
850 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
851 commandEvent
.SetInt( id
);
852 commandEvent
.SetEventObject( this );
854 wxMenuBar
*bar
= GetMenuBar() ;
858 /* TODO: check the menu item if required
859 wxMenuItem *item = bar->FindItemForId(id) ;
860 if (item && item->IsCheckable())
862 bar->Check(id,!bar->Checked(id)) ;
866 GetEventHandler()->ProcessEvent(commandEvent
);
869 // Checks if there is a toolbar, and returns the first free client position
870 wxPoint
wxFrame::GetClientAreaOrigin() const
877 GetToolBar()->GetSize(& w
, & h
);
879 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
888 #endif // wxUSE_TOOLBAR
893 void wxFrame::ScreenToClient(int *x
, int *y
) const
895 wxWindow::ScreenToClient(x
, y
);
897 // We may be faking the client origin.
898 // So a window that's really at (0, 30) may appear
899 // (to wxWin apps) to be at (0, 0).
900 wxPoint
pt(GetClientAreaOrigin());
905 void wxFrame::ClientToScreen(int *x
, int *y
) const
907 // We may be faking the client origin.
908 // So a window that's really at (0, 30) may appear
909 // (to wxWin apps) to be at (0, 0).
910 wxPoint
pt1(GetClientAreaOrigin());
914 wxWindow::ClientToScreen(x
, y
);
918 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
920 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
921 "recreating toolbar in wxFrame" );
923 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
936 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
938 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
941 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
943 m_frameToolBar
= toolbar
;
946 wxToolBar
*wxFrame::GetToolBar() const
948 return m_frameToolBar
;
951 void wxFrame::PositionToolBar()
955 GetClientSize(& cw
, &ch
);
960 GetToolBar()->GetSize(& tw
, & th
);
962 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
964 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
965 // means, pretend we don't have toolbar/status bar, so we
966 // have the original client size.
967 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
971 // Use the 'real' position
972 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
976 #endif // wxUSE_TOOLBAR
978 void wxFrame::CaptureMouse()
984 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
985 m_winCaptured
= TRUE
;
988 void wxFrame::ReleaseMouse()
994 XtRemoveGrab((Widget
) m_frameShell
);
995 m_winCaptured
= FALSE
;
998 void wxFrame::Raise(void)
1000 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1001 next_parent
= XtWindow((Widget
) m_frameShell
),
1002 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1003 // search for the parent that is child of ROOT, because the WM may
1004 // reparent twice and notify only the next parent (like FVWM)
1005 while (next_parent
!= root
) {
1006 Window
*theChildren
; unsigned int n
;
1007 parent_window
= next_parent
;
1008 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1009 &next_parent
, &theChildren
, &n
);
1010 XFree(theChildren
); // not needed
1012 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1015 void wxFrame::Lower(void)
1017 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1018 next_parent
= XtWindow((Widget
) m_frameShell
),
1019 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1020 // search for the parent that is child of ROOT, because the WM may
1021 // reparent twice and notify only the next parent (like FVWM)
1022 while (next_parent
!= root
) {
1023 Window
*theChildren
; unsigned int n
;
1024 parent_window
= next_parent
;
1025 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1026 &next_parent
, &theChildren
, &n
);
1027 XFree(theChildren
); // not needed
1029 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1032 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1033 XmAnyCallbackStruct
*cbs
)
1035 wxFrame
*frame
= (wxFrame
*)clientData
;
1037 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1039 // frame->GetEventHandler()->OnSetFocus();
1042 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1043 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1044 XCrossingEvent
* event
)
1046 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1049 XEvent
*e
= (XEvent
*)event
;
1051 if (e
->xany
.type
== MapNotify
)
1054 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1055 if (!frame
->GetVisibleStatus())
1057 /* We really wanted this to be hidden! */
1058 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1061 else if (e
->xany
.type
== UnmapNotify
)
1063 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1068 bool wxFrame::PreResize()
1072 #endif // wxUSE_TOOLBAR
1073 PositionStatusBar();
1077 WXWidget
wxFrame::GetClientWidget() const
1079 return m_clientArea
;
1082 void wxFrame::ChangeFont(bool keepOriginalSize
)
1087 void wxFrame::ChangeBackgroundColour()
1089 if (GetClientWidget())
1090 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1093 void wxFrame::ChangeForegroundColour()
1095 if (GetClientWidget())
1096 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1099 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1101 wxFrame
*frame
= (wxFrame
*)client_data
;
1103 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1104 closeEvent
.SetEventObject(frame
);
1106 // May delete the frame (with delayed deletion)
1107 frame
->GetEventHandler()->ProcessEvent(closeEvent
);