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
;
87 m_frameToolBar
= NULL
;
88 m_frameMenuBar
= NULL
;
89 m_frameStatusBar
= NULL
;
91 m_windowParent
= NULL
;
95 m_frameShell
= (WXWidget
) NULL
;
96 m_frameWidget
= (WXWidget
) NULL
;;
97 m_workArea
= (WXWidget
) NULL
;;
98 m_clientArea
= (WXWidget
) NULL
;;
99 m_visibleStatus
= TRUE
;
103 bool wxFrame::Create(wxWindow
*parent
,
105 const wxString
& title
,
109 const wxString
& name
)
112 wxTopLevelWindows
.Append(this);
116 m_windowStyle
= style
;
117 m_frameMenuBar
= NULL
;
118 m_frameToolBar
= NULL
;
119 m_frameStatusBar
= NULL
;
122 m_frameShell
= (WXWidget
) NULL
;
123 m_frameWidget
= (WXWidget
) NULL
;;
124 m_workArea
= (WXWidget
) NULL
;;
125 m_clientArea
= (WXWidget
) NULL
;;
126 m_visibleStatus
= TRUE
;
129 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
130 m_foregroundColour
= *wxBLACK
;
131 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
136 m_windowId
= (int)NewControlId();
138 if (parent
) parent
->AddChild(this);
140 wxModelessWindows
.Append(this);
142 int x
= pos
.x
; int y
= pos
.y
;
143 int width
= size
.x
; int height
= size
.y
;
146 // Change suggested by Matthew Flatt
147 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
150 m_frameShell
= wxTheApp
->GetTopLevelWidget();
151 wxTopLevelUsed
= TRUE
;
154 XtVaSetValues((Widget
) m_frameShell
,
155 // Allows menu to resize
156 XmNallowShellResize
, True
,
157 XmNdeleteResponse
, XmDO_NOTHING
,
158 XmNmappedWhenManaged
, False
,
159 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
163 XtVaSetValues((Widget
) m_frameShell
,
164 XmNtitle
, (const char*) title
,
167 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
168 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
169 XmNresizePolicy
, XmRESIZE_NONE
,
172 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
173 xmFormWidgetClass
, (Widget
) m_frameWidget
,
174 XmNresizePolicy
, XmRESIZE_NONE
,
177 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
178 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
181 XmNrightAttachment
, XmATTACH_FORM
,
182 XmNleftAttachment
, XmATTACH_FORM
,
183 XmNtopAttachment
, XmATTACH_FORM
,
184 XmNbottomAttachment
, XmATTACH_FORM
,
185 // XmNresizePolicy, XmRESIZE_ANY,
188 XtVaSetValues((Widget
) m_frameWidget
,
189 XmNworkWindow
, (Widget
) m_workArea
,
193 XtManageChild((Widget
) m_clientArea
);
194 XtManageChild((Widget
) m_workArea
);
196 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
198 wxAddWindowToTable((Widget
) m_workArea
, this);
202 XtOverrideTranslations((Widget
) m_workArea
,
203 ptr
= XtParseTranslationTable("<Configure>: resize()"));
207 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
208 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
210 /* Part of show-&-hide fix */
211 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
212 False
, (XtEventHandler
)wxFrameMapProc
,
213 (XtPointer
)m_workArea
);
216 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
218 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
220 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
222 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
224 m_mainWidget
= m_frameWidget
;
228 // This patch comes from Torsten Liermann lier@lier1.muc.de
229 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
232 if (style
& wxRESIZE_BORDER
)
233 decor
|= MWM_DECOR_RESIZEH
;
234 if (style
& wxSYSTEM_MENU
)
235 decor
|= MWM_DECOR_MENU
;
236 if ((style
& wxCAPTION
) ||
237 (style
& wxTINY_CAPTION_HORIZ
) ||
238 (style
& wxTINY_CAPTION_VERT
))
239 decor
|= MWM_DECOR_TITLE
;
240 if (style
& wxTHICK_FRAME
)
241 decor
|= MWM_DECOR_BORDER
;
242 if (style
& wxTHICK_FRAME
)
243 decor
|= MWM_DECOR_BORDER
;
244 if (style
& wxMINIMIZE_BOX
)
245 decor
|= MWM_DECOR_MINIMIZE
;
246 if (style
& wxMAXIMIZE_BOX
)
247 decor
|= MWM_DECOR_MAXIMIZE
;
248 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
250 // This allows non-Motif window managers to support at least the
251 // no-decorations case.
255 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
257 XtRealizeWidget((Widget
) m_frameShell
);
259 // Intercept CLOSE messages from the window manager
260 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
261 #if (XmREVISION > 1 || XmVERSION > 1)
262 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
265 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
267 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
271 ChangeBackgroundColour();
275 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
276 sizeEvent
.SetEventObject(this);
278 GetEventHandler()->ProcessEvent(sizeEvent
);
290 m_frameMenuBar
->DestroyMenuBar();
292 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
293 #if MOTIF_MENUBAR_DELETE_FIX
294 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
296 delete m_frameMenuBar
;
297 m_frameMenuBar
= NULL
;
300 wxTopLevelWindows
.DeleteObject(this);
301 wxModelessWindows
.DeleteObject(this);
303 if (m_frameStatusBar
)
304 delete m_frameStatusBar
;
310 for (i = 0; i < wxMAX_STATUS; i++)
311 if (statusTextWidget[i])
312 XtDestroyWidget (statusTextWidget[i]);
315 XtDestroyWidget (statusLineForm);
317 if (statusLineWidget)
318 XtDestroyWidget (statusLineWidget);
323 wxDeleteWindowFromTable((Widget
) m_workArea
);
325 XtDestroyWidget ((Widget
) m_workArea
);
330 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
331 XtDestroyWidget ((Widget
) m_frameWidget
);
335 XtDestroyWidget ((Widget
) m_frameShell
);
337 SetMainWidget((WXWidget
) NULL
);
339 /* Check if it's the last top-level window */
341 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
343 wxTheApp
->SetTopWindow(NULL
);
345 if (wxTheApp
->GetExitOnFrameDelete())
347 // Signal to the app that we're going to close
348 wxTheApp
->ExitMainLoop();
354 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
355 void wxFrame::GetClientSize(int *x
, int *y
) const
358 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
360 if (m_frameStatusBar
)
363 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
369 m_frameToolBar
->GetSize(& tbw
, & tbh
);
370 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
376 if (GetMenuBar() != (wxMenuBar*) NULL)
378 // it seems that if a frame holds a panel, the menu bar size
379 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
380 bool hasSubPanel = FALSE;
381 for(wxNode* node = GetChildren().First(); node; node = node->Next())
383 wxWindow *win = (wxWindow *)node->Data();
384 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
391 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
400 // Set the client size (i.e. leave the calculation of borders etc.
402 void wxFrame::SetClientSize(int width
, int height
)
404 // Calculate how large the new main window should be
405 // by finding the difference between the client area and the
406 // main window area, and adding on to the new client area
408 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
412 if (m_frameStatusBar
)
415 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
421 m_frameToolBar
->GetSize(& tbw
, & tbh
);
422 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
428 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
432 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
433 sizeEvent
.SetEventObject(this);
435 GetEventHandler()->ProcessEvent(sizeEvent
);
439 void wxFrame::GetSize(int *width
, int *height
) const
442 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
443 *width
= xx
; *height
= yy
;
446 void wxFrame::GetPosition(int *x
, int *y
) const
448 Window parent_window
= XtWindow((Widget
) m_frameShell
),
449 next_parent
= XtWindow((Widget
) m_frameShell
),
450 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
452 // search for the parent that is child of ROOT, because the WM may
453 // reparent twice and notify only the next parent (like FVWM)
454 while (next_parent
!= root
) {
455 Window
*theChildren
; unsigned int n
;
456 parent_window
= next_parent
;
457 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
458 &next_parent
, &theChildren
, &n
);
459 XFree(theChildren
); // not needed
461 int xx
, yy
; unsigned int dummy
;
462 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
463 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
468 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
471 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
473 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
475 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
477 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
479 if (!(height
== -1 && width
== -1))
483 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
484 sizeEvent
.SetEventObject(this);
486 GetEventHandler()->ProcessEvent(sizeEvent
);
490 bool wxFrame::Show(bool show
)
493 return wxWindow::Show(show
);
495 m_visibleStatus
= show
; /* show-&-hide fix */
499 XtMapWidget((Widget
) m_frameShell
);
500 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
502 XtUnmapWidget((Widget
) m_frameShell
);
503 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
508 void wxFrame::Iconize(bool iconize
)
514 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
517 // Equivalent to maximize/restore in Windows
518 void wxFrame::Maximize(bool maximize
)
522 if (maximize
&& m_frameShell
)
523 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
526 bool wxFrame::IsIconized() const
532 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
537 bool wxFrame::IsMaximized(void) const
539 // No maximizing in Motif (?)
543 void wxFrame::SetTitle(const wxString
& title
)
545 if (title
== m_title
)
551 XtVaSetValues((Widget
) m_frameShell
,
552 XmNtitle
, (const char*) title
,
553 XmNiconName
, (const char*) title
,
557 void wxFrame::SetIcon(const wxIcon
& icon
)
564 if (!icon
.Ok() || !icon
.GetPixmap())
567 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
570 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
571 const wxString
& name
)
573 wxStatusBar
*statusBar
= NULL
;
575 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
578 // Set the height according to the font and the border size
579 wxClientDC
dc(statusBar
);
580 dc
.SetFont(statusBar
->GetFont());
583 dc
.GetTextExtent("X", &x
, &y
);
585 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
587 statusBar
->SetSize(-1, -1, 100, height
);
589 statusBar
->SetFieldsCount(number
);
593 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
594 const wxString
& name
)
596 // Calling CreateStatusBar twice is an error.
597 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
598 "recreating status bar in wxFrame" );
600 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
602 if ( m_frameStatusBar
)
605 return m_frameStatusBar
;
611 void wxFrame::SetStatusText(const wxString
& text
, int number
)
613 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
615 m_frameStatusBar
->SetStatusText(text
, number
);
618 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
620 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
622 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
626 void wxFrame::PositionStatusBar()
628 if (!m_frameStatusBar
)
632 GetClientSize(&w
, &h
);
634 m_frameStatusBar
->GetSize(&sw
, &sh
);
636 // Since we wish the status bar to be directly under the client area,
637 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
638 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
641 WXWidget
wxFrame::GetMenuBarWidget() const
644 return GetMenuBar()->GetMainWidget();
646 return (WXWidget
) NULL
;
649 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
653 m_frameMenuBar
= NULL
;
657 // Currently can't set it twice
658 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
662 m_frameMenuBar
->DestroyMenuBar();
663 delete m_frameMenuBar
;
666 m_frameMenuBar
= menuBar
;
667 m_frameMenuBar
->CreateMenuBar(this);
672 // Work out max. size
673 wxNode
*node
= GetChildren().First();
678 // Find a child that's a subwindow, but not a dialog box.
679 wxWindow
*win
= (wxWindow
*)node
->Data();
681 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
682 !win
->IsKindOf(CLASSINFO(wxDialog
)))
686 win
->GetSize(&width
, &height
);
687 win
->GetPosition(&x
, &y
);
689 if ((x
+ width
) > max_width
)
690 max_width
= x
+ width
;
691 if ((y
+ height
) > max_height
)
692 max_height
= y
+ height
;
696 SetClientSize(max_width
, max_height
);
699 // Responds to colour changes, and passes event on to children.
700 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
702 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
705 if ( m_frameStatusBar
)
707 wxSysColourChangedEvent event2
;
708 event2
.SetEventObject( m_frameStatusBar
);
709 m_frameStatusBar
->ProcessEvent(event2
);
712 // Propagate the event to the non-top-level children
713 wxWindow::OnSysColourChanged(event
);
716 // Default resizing behaviour - if only ONE subwindow,
717 // resize to client rectangle size
718 void wxFrame::OnSize(wxSizeEvent
& event
)
720 // if we're using constraints - do use them
721 #if wxUSE_CONSTRAINTS
722 if ( GetAutoLayout() ) {
728 // do we have _exactly_ one child?
729 wxWindow
*child
= NULL
;
730 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
732 wxWindow
*win
= (wxWindow
*)node
->Data();
733 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
734 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
735 (win
!= GetStatusBar()) &&
736 (win
!= GetToolBar()) )
739 return; // it's our second subwindow - nothing to do
745 // we have exactly one child - set it's size to fill the whole frame
746 int clientW
, clientH
;
747 GetClientSize(&clientW
, &clientH
);
752 child
->SetSize(x
, y
, clientW
, clientH
);
756 // Default activation behaviour - set the focus for the first child
758 void wxFrame::OnActivate(wxActivateEvent
& event
)
760 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
762 // Find a child that's a subwindow, but not a dialog box.
763 wxWindow
*child
= (wxWindow
*)node
->Data();
764 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
765 !child
->IsKindOf(CLASSINFO(wxDialog
)))
773 // The default implementation for the close window event - calls
774 // OnClose for backward compatibility.
776 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
779 if ( GetEventHandler()->OnClose() || event
.GetForce())
785 bool wxFrame::OnClose()
790 // Destroy the window (delayed, if a managed window)
791 bool wxFrame::Destroy()
793 if (!wxPendingDelete
.Member(this))
794 wxPendingDelete
.Append(this);
798 // Default menu selection behaviour - display a help string
799 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
803 if (event
.GetMenuId() == -1)
807 wxMenuBar
*menuBar
= GetMenuBar();
810 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
811 if (helpString
!= "")
812 SetStatusText(helpString
);
818 wxMenuBar
*wxFrame::GetMenuBar() const
820 return m_frameMenuBar
;
823 void wxFrame::Centre(int direction
)
825 int display_width
, display_height
, width
, height
, x
, y
;
826 wxDisplaySize(&display_width
, &display_height
);
828 GetSize(&width
, &height
);
831 if (direction
& wxHORIZONTAL
)
832 x
= (int)((display_width
- width
)/2);
833 if (direction
& wxVERTICAL
)
834 y
= (int)((display_height
- height
)/2);
836 SetSize(x
, y
, width
, height
);
839 // Call this to simulate a menu command
840 void wxFrame::Command(int id
)
845 void wxFrame::ProcessCommand(int id
)
847 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
848 commandEvent
.SetInt( id
);
849 commandEvent
.SetEventObject( this );
851 wxMenuBar
*bar
= GetMenuBar() ;
855 /* TODO: check the menu item if required
856 wxMenuItem *item = bar->FindItemForId(id) ;
857 if (item && item->IsCheckable())
859 bar->Check(id,!bar->Checked(id)) ;
863 GetEventHandler()->ProcessEvent(commandEvent
);
866 // Checks if there is a toolbar, and returns the first free client position
867 wxPoint
wxFrame::GetClientAreaOrigin() const
873 GetToolBar()->GetSize(& w
, & h
);
875 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
887 void wxFrame::ScreenToClient(int *x
, int *y
) const
889 wxWindow::ScreenToClient(x
, y
);
891 // We may be faking the client origin.
892 // So a window that's really at (0, 30) may appear
893 // (to wxWin apps) to be at (0, 0).
894 wxPoint
pt(GetClientAreaOrigin());
899 void wxFrame::ClientToScreen(int *x
, int *y
) const
901 // We may be faking the client origin.
902 // So a window that's really at (0, 30) may appear
903 // (to wxWin apps) to be at (0, 0).
904 wxPoint
pt1(GetClientAreaOrigin());
908 wxWindow::ClientToScreen(x
, y
);
911 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
913 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
914 "recreating toolbar in wxFrame" );
916 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
929 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
931 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
934 void wxFrame::PositionToolBar()
938 GetClientSize(& cw
, &ch
);
943 GetToolBar()->GetSize(& tw
, & th
);
945 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
947 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
948 // means, pretend we don't have toolbar/status bar, so we
949 // have the original client size.
950 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
954 // Use the 'real' position
955 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
960 void wxFrame::CaptureMouse()
966 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
967 m_winCaptured
= TRUE
;
970 void wxFrame::ReleaseMouse()
976 XtRemoveGrab((Widget
) m_frameShell
);
977 m_winCaptured
= FALSE
;
980 void wxFrame::Raise(void)
982 Window parent_window
= XtWindow((Widget
) m_frameShell
),
983 next_parent
= XtWindow((Widget
) m_frameShell
),
984 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
985 // search for the parent that is child of ROOT, because the WM may
986 // reparent twice and notify only the next parent (like FVWM)
987 while (next_parent
!= root
) {
988 Window
*theChildren
; unsigned int n
;
989 parent_window
= next_parent
;
990 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
991 &next_parent
, &theChildren
, &n
);
992 XFree(theChildren
); // not needed
994 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
997 void wxFrame::Lower(void)
999 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1000 next_parent
= XtWindow((Widget
) m_frameShell
),
1001 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1002 // search for the parent that is child of ROOT, because the WM may
1003 // reparent twice and notify only the next parent (like FVWM)
1004 while (next_parent
!= root
) {
1005 Window
*theChildren
; unsigned int n
;
1006 parent_window
= next_parent
;
1007 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1008 &next_parent
, &theChildren
, &n
);
1009 XFree(theChildren
); // not needed
1011 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1014 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
1015 { m_frameToolBar
= toolbar
; }
1017 wxToolBar
*wxFrame::GetToolBar() const
1018 { return m_frameToolBar
; }
1020 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1021 XmAnyCallbackStruct
*cbs
)
1023 wxFrame
*frame
= (wxFrame
*)clientData
;
1025 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1027 // frame->GetEventHandler()->OnSetFocus();
1030 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1031 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1032 XCrossingEvent
* event
)
1034 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1037 XEvent
*e
= (XEvent
*)event
;
1039 if (e
->xany
.type
== MapNotify
)
1042 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1043 if (!frame
->GetVisibleStatus())
1045 /* We really wanted this to be hidden! */
1046 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1049 else if (e
->xany
.type
== UnmapNotify
)
1051 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1056 bool wxFrame::PreResize()
1059 PositionStatusBar();
1063 WXWidget
wxFrame::GetClientWidget() const
1065 return m_clientArea
;
1068 void wxFrame::ChangeFont(bool keepOriginalSize
)
1073 void wxFrame::ChangeBackgroundColour()
1075 if (GetClientWidget())
1076 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1079 void wxFrame::ChangeForegroundColour()
1081 if (GetClientWidget())
1082 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1085 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1087 wxFrame
*frame
= (wxFrame
*)client_data
;
1089 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1090 closeEvent
.SetEventObject(frame
);
1092 // May delete the frame (with delayed deletion)
1093 frame
->GetEventHandler()->ProcessEvent(closeEvent
);