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 static 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 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
134 m_windowId
= (int)NewControlId();
136 if (parent
) parent
->AddChild(this);
138 wxModelessWindows
.Append(this);
140 int x
= pos
.x
; int y
= pos
.y
;
141 int width
= size
.x
; int height
= size
.y
;
144 // Change suggested by Matthew Flatt
145 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
148 m_frameShell
= wxTheApp
->GetTopLevelWidget();
149 wxTopLevelUsed
= TRUE
;
152 XtVaSetValues((Widget
) m_frameShell
,
153 // Allows menu to resize
154 XmNallowShellResize
, True
,
155 XmNdeleteResponse
, XmDO_NOTHING
,
156 XmNmappedWhenManaged
, False
,
157 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
161 XtVaSetValues((Widget
) m_frameShell
,
162 XmNtitle
, (const char*) title
,
165 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
166 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
167 XmNresizePolicy
, XmRESIZE_NONE
,
170 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
171 xmFormWidgetClass
, (Widget
) m_frameWidget
,
172 XmNresizePolicy
, XmRESIZE_NONE
,
175 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
176 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
179 XmNrightAttachment
, XmATTACH_FORM
,
180 XmNleftAttachment
, XmATTACH_FORM
,
181 XmNtopAttachment
, XmATTACH_FORM
,
182 XmNbottomAttachment
, XmATTACH_FORM
,
183 // XmNresizePolicy, XmRESIZE_ANY,
186 XtVaSetValues((Widget
) m_frameWidget
,
187 XmNworkWindow
, (Widget
) m_workArea
,
191 XtManageChild((Widget
) m_clientArea
);
192 XtManageChild((Widget
) m_workArea
);
194 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
196 wxAddWindowToTable((Widget
) m_workArea
, this);
200 XtOverrideTranslations((Widget
) m_workArea
,
201 ptr
= XtParseTranslationTable("<Configure>: resize()"));
205 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
206 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
208 /* Part of show-&-hide fix */
209 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
210 False
, (XtEventHandler
)wxFrameMapProc
,
211 (XtPointer
)m_workArea
);
214 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
216 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
218 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
220 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
222 m_mainWidget
= m_frameWidget
;
224 // This patch comes from Torsten Liermann lier@lier1.muc.de
225 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
228 if (style
& wxRESIZE_BORDER
)
229 decor
|= MWM_DECOR_RESIZEH
;
230 if (style
& wxSYSTEM_MENU
)
231 decor
|= MWM_DECOR_MENU
;
232 if ((style
& wxCAPTION
) ||
233 (style
& wxTINY_CAPTION_HORIZ
) ||
234 (style
& wxTINY_CAPTION_VERT
))
235 decor
|= MWM_DECOR_TITLE
;
236 if (style
& wxTHICK_FRAME
)
237 decor
|= MWM_DECOR_BORDER
;
238 if (style
& wxTHICK_FRAME
)
239 decor
|= MWM_DECOR_BORDER
;
240 if (style
& wxMINIMIZE_BOX
)
241 decor
|= MWM_DECOR_MINIMIZE
;
242 if (style
& wxMAXIMIZE_BOX
)
243 decor
|= MWM_DECOR_MAXIMIZE
;
244 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
246 // This allows non-Motif window managers to support at least the
247 // no-decorations case.
251 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
253 XtRealizeWidget((Widget
) m_frameShell
);
255 // Intercept CLOSE messages from the window manager
256 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
257 #if (XmREVISION > 1 || XmVERSION > 1)
258 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
261 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
263 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
269 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
270 sizeEvent
.SetEventObject(this);
272 GetEventHandler()->ProcessEvent(sizeEvent
);
284 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
285 #if MOTIF_MENUBAR_DELETE_FIX
286 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
288 delete m_frameMenuBar
;
289 m_frameMenuBar
= NULL
;
292 wxTopLevelWindows
.DeleteObject(this);
293 wxModelessWindows
.DeleteObject(this);
295 if (m_frameStatusBar
)
296 delete m_frameStatusBar
;
302 for (i = 0; i < wxMAX_STATUS; i++)
303 if (statusTextWidget[i])
304 XtDestroyWidget (statusTextWidget[i]);
307 XtDestroyWidget (statusLineForm);
309 if (statusLineWidget)
310 XtDestroyWidget (statusLineWidget);
313 wxDeleteWindowFromTable((Widget
) m_workArea
);
315 XtDestroyWidget ((Widget
) m_workArea
);
316 XtDestroyWidget ((Widget
) m_frameWidget
);
318 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
320 XtDestroyWidget ((Widget
) m_frameShell
);
322 SetMainWidget((WXWidget
) NULL
);
324 /* Check if it's the last top-level window */
326 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
328 wxTheApp
->SetTopWindow(NULL
);
330 if (wxTheApp
->GetExitOnFrameDelete())
332 // Signal to the app that we're going to close
333 wxTheApp
->ExitMainLoop();
339 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
340 void wxFrame::GetClientSize(int *x
, int *y
) const
343 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
346 if (status_line_exists)
349 XtVaGetValues(statusLineWidget, XmNheight, &ys, NULL);
354 if (GetMenuBar() != (wxMenuBar
*) NULL
)
356 // it seems that if a frame holds a panel, the menu bar size
357 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
358 bool hasSubPanel
= FALSE
;
359 for(wxNode
* node
= GetChildren()->First(); node
; node
= node
->Next())
361 wxWindow
*win
= (wxWindow
*)node
->Data();
362 hasSubPanel
= (win
->IsKindOf(CLASSINFO(wxPanel
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)));
369 XtVaGetValues((Widget
) GetMenuBarWidget(), XmNheight
, &ys
, NULL
);
377 // Set the client size (i.e. leave the calculation of borders etc.
379 void wxFrame::SetClientSize(int width
, int height
)
381 // Calculate how large the new main window should be
382 // by finding the difference between the client area and the
383 // main window area, and adding on to the new client area
385 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
390 if (status_line_exists)
393 XtVaGetValues(statusLineWidget, XmNheight, &ys, NULL);
397 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
401 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
402 sizeEvent
.SetEventObject(this);
404 GetEventHandler()->ProcessEvent(sizeEvent
);
408 void wxFrame::GetSize(int *width
, int *height
) const
411 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
412 *width
= xx
; *height
= yy
;
415 void wxFrame::GetPosition(int *x
, int *y
) const
417 Window parent_window
= XtWindow((Widget
) m_frameShell
),
418 next_parent
= XtWindow((Widget
) m_frameShell
),
419 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
421 // search for the parent that is child of ROOT, because the WM may
422 // reparent twice and notify only the next parent (like FVWM)
423 while (next_parent
!= root
) {
424 Window
*theChildren
; unsigned int n
;
425 parent_window
= next_parent
;
426 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
427 &next_parent
, &theChildren
, &n
);
428 XFree(theChildren
); // not needed
430 int xx
, yy
; unsigned int dummy
;
431 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
432 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
437 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
440 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
442 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
444 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
446 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
448 if (!(height
== -1 && width
== -1))
451 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
452 sizeEvent
.SetEventObject(this);
454 GetEventHandler()->ProcessEvent(sizeEvent
);
458 bool wxFrame::Show(bool show
)
460 m_visibleStatus
= show
; /* show-&-hide fix */
464 XtMapWidget((Widget
) m_frameShell
);
465 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
467 XtUnmapWidget((Widget
) m_frameShell
);
468 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
473 void wxFrame::Iconize(bool iconize
)
478 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
481 // Equivalent to maximize/restore in Windows
482 void wxFrame::Maximize(bool maximize
)
487 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
490 bool wxFrame::IsIconized() const
493 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
497 void wxFrame::SetTitle(const wxString
& title
)
499 if (title
== m_title
)
505 XtVaSetValues((Widget
) m_frameShell
,
506 XmNtitle
, (const char*) title
,
507 XmNiconName
, (const char*) title
,
511 void wxFrame::SetIcon(const wxIcon
& icon
)
517 if (!icon.Ok() || !icon.GetPixmap())
520 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon->.GetPixmap(), NULL);
524 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
525 const wxString
& name
)
527 wxStatusBar
*statusBar
= NULL
;
529 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
532 // Set the height according to the font and the border size
533 wxClientDC
dc(statusBar
);
534 dc
.SetFont(* statusBar
->GetFont());
537 dc
.GetTextExtent("X", &x
, &y
);
539 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
541 statusBar
->SetSize(-1, -1, 100, height
);
543 statusBar
->SetFieldsCount(number
);
547 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
548 const wxString
& name
)
550 // Calling CreateStatusBar twice is an error.
551 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
552 "recreating status bar in wxFrame" );
554 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
556 if ( m_frameStatusBar
)
559 return m_frameStatusBar
;
565 void wxFrame::SetStatusText(const wxString
& text
, int number
)
567 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
569 m_frameStatusBar
->SetStatusText(text
, number
);
572 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
574 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
576 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
580 void wxFrame::PositionStatusBar()
582 if (!m_frameStatusBar
)
586 GetClientSize(&w
, &h
);
588 m_frameStatusBar
->GetSize(&sw
, &sh
);
590 // Since we wish the status bar to be directly under the client area,
591 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
592 m_frameStatusBar
->SetSize(0-sh
, h
, w
, sh
);
595 WXWidget
wxFrame::GetMenuBarWidget() const
598 return GetMenuBar()->GetMainWidget();
600 return (WXWidget
) NULL
;
603 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
607 m_frameMenuBar
= NULL
;
611 // Currently can't set it twice
612 wxASSERT_MSG( (m_frameMenuBar
== (wxMenuBar
*) NULL
), "Cannot set the menubar more than once");
614 m_frameMenuBar
= menuBar
;
616 Widget menuBarW
= XmCreateMenuBar ((Widget
) m_frameWidget
, "MenuBar", NULL
, 0);
617 m_frameMenuBar
->SetMainWidget( (WXWidget
) menuBarW
);
620 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
622 wxMenu
*menu
= menuBar
->GetMenu(i
);
623 wxString
title(menuBar
->m_titles
[i
]);
624 menu
->SetButtonWidget(menu
->CreateMenu (menuBar
, menuBarW
, menu
, title
, TRUE
));
627 * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
629 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
631 if (strcmp (wxBuffer
, "Help") == 0)
632 XtVaSetValues ((Widget
) menuBarW
, XmNmenuHelpWidget
, (Widget
) menu
->GetButtonWidget(), NULL
);
635 XtRealizeWidget ((Widget
) menuBarW
);
636 XtManageChild ((Widget
) menuBarW
);
637 menuBar
->SetMenuBarFrame(this);
642 // Work out max. size
643 wxNode
*node
= GetChildren()->First();
648 // Find a child that's a subwindow, but not a dialog box.
649 wxWindow
*win
= (wxWindow
*)node
->Data();
651 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
652 !win
->IsKindOf(CLASSINFO(wxDialog
)))
656 win
->GetSize(&width
, &height
);
657 win
->GetPosition(&x
, &y
);
659 if ((x
+ width
) > max_width
)
660 max_width
= x
+ width
;
661 if ((y
+ height
) > max_height
)
662 max_height
= y
+ height
;
666 SetClientSize(max_width
, max_height
);
669 // Responds to colour changes, and passes event on to children.
670 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
672 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
675 if ( m_frameStatusBar
)
677 wxSysColourChangedEvent event2
;
678 event2
.SetEventObject( m_frameStatusBar
);
679 m_frameStatusBar
->ProcessEvent(event2
);
682 // Propagate the event to the non-top-level children
683 wxWindow::OnSysColourChanged(event
);
686 // Default resizing behaviour - if only ONE subwindow,
687 // resize to client rectangle size
688 void wxFrame::OnSize(wxSizeEvent
& event
)
690 // if we're using constraints - do use them
691 #if wxUSE_CONSTRAINTS
692 if ( GetAutoLayout() ) {
698 // do we have _exactly_ one child?
699 wxWindow
*child
= NULL
;
700 for ( wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next() )
702 wxWindow
*win
= (wxWindow
*)node
->Data();
703 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
704 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
705 (win
!= GetStatusBar()) &&
706 (win
!= GetToolBar()) )
709 return; // it's our second subwindow - nothing to do
715 // we have exactly one child - set it's size to fill the whole frame
716 int clientW
, clientH
;
717 GetClientSize(&clientW
, &clientH
);
722 child
->SetSize(x
, y
, clientW
, clientH
);
726 // Default activation behaviour - set the focus for the first child
728 void wxFrame::OnActivate(wxActivateEvent
& event
)
730 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
732 // Find a child that's a subwindow, but not a dialog box.
733 wxWindow
*child
= (wxWindow
*)node
->Data();
734 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
735 !child
->IsKindOf(CLASSINFO(wxDialog
)))
738 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
746 // The default implementation for the close window event - calls
747 // OnClose for backward compatibility.
749 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
752 if ( GetEventHandler()->OnClose() || event
.GetForce())
758 bool wxFrame::OnClose()
763 // Destroy the window (delayed, if a managed window)
764 bool wxFrame::Destroy()
766 if (!wxPendingDelete
.Member(this))
767 wxPendingDelete
.Append(this);
771 // Default menu selection behaviour - display a help string
772 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
776 if (event
.GetMenuId() == -1)
780 wxMenuBar
*menuBar
= GetMenuBar();
783 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
784 if (helpString
!= "")
785 SetStatusText(helpString
);
791 wxMenuBar
*wxFrame::GetMenuBar() const
793 return m_frameMenuBar
;
796 void wxFrame::Centre(int direction
)
798 int display_width
, display_height
, width
, height
, x
, y
;
799 wxDisplaySize(&display_width
, &display_height
);
801 GetSize(&width
, &height
);
804 if (direction
& wxHORIZONTAL
)
805 x
= (int)((display_width
- width
)/2);
806 if (direction
& wxVERTICAL
)
807 y
= (int)((display_height
- height
)/2);
809 SetSize(x
, y
, width
, height
);
812 // Call this to simulate a menu command
813 void wxFrame::Command(int id
)
818 void wxFrame::ProcessCommand(int id
)
820 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
821 commandEvent
.SetInt( id
);
822 commandEvent
.SetEventObject( this );
824 wxMenuBar
*bar
= GetMenuBar() ;
828 /* TODO: check the menu item if required
829 wxMenuItem *item = bar->FindItemForId(id) ;
830 if (item && item->IsCheckable())
832 bar->Check(id,!bar->Checked(id)) ;
836 GetEventHandler()->ProcessEvent(commandEvent
);
839 // Checks if there is a toolbar, and returns the first free client position
840 wxPoint
wxFrame::GetClientAreaOrigin() const
846 GetToolBar()->GetSize(& w
, & h
);
848 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
860 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
862 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
863 "recreating toolbar in wxFrame" );
865 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
878 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
880 return new wxToolBar(this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
883 void wxFrame::PositionToolBar()
887 // TODO: we actually need to use the low-level client size, before
888 // the toolbar/status bar were added.
889 // So DEFINITELY replace the line below with something appropriate.
891 GetClientSize(& cw
, &ch
);
893 if ( GetStatusBar() )
895 int statusX
, statusY
;
896 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
903 GetToolBar()->GetSize(& tw
, & th
);
905 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
907 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
908 // means, pretend we don't have toolbar/status bar, so we
909 // have the original client size.
910 GetToolBar()->SetSize(0, 0, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
914 // Use the 'real' position
915 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
920 void wxFrame::CaptureMouse()
926 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
927 m_winCaptured
= TRUE
;
930 void wxFrame::ReleaseMouse()
936 XtRemoveGrab((Widget
) m_frameShell
);
937 m_winCaptured
= FALSE
;
940 void wxFrame::Raise(void)
942 Window parent_window
= XtWindow((Widget
) m_frameShell
),
943 next_parent
= XtWindow((Widget
) m_frameShell
),
944 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
945 // search for the parent that is child of ROOT, because the WM may
946 // reparent twice and notify only the next parent (like FVWM)
947 while (next_parent
!= root
) {
948 Window
*theChildren
; unsigned int n
;
949 parent_window
= next_parent
;
950 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
951 &next_parent
, &theChildren
, &n
);
952 XFree(theChildren
); // not needed
954 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
957 void wxFrame::Lower(void)
959 Window parent_window
= XtWindow((Widget
) m_frameShell
),
960 next_parent
= XtWindow((Widget
) m_frameShell
),
961 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
962 // search for the parent that is child of ROOT, because the WM may
963 // reparent twice and notify only the next parent (like FVWM)
964 while (next_parent
!= root
) {
965 Window
*theChildren
; unsigned int n
;
966 parent_window
= next_parent
;
967 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
968 &next_parent
, &theChildren
, &n
);
969 XFree(theChildren
); // not needed
971 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
974 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
975 { m_frameToolBar
= toolbar
; }
977 wxToolBar
*wxFrame::GetToolBar() const
978 { return m_frameToolBar
; }
980 static void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
981 XmAnyCallbackStruct
*cbs
)
983 wxFrame
*frame
= (wxFrame
*)clientData
;
985 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
987 // frame->GetEventHandler()->OnSetFocus();
990 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
991 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
992 XCrossingEvent
* event
)
994 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
997 XEvent
*e
= (XEvent
*)event
;
999 if (e
->xany
.type
== MapNotify
)
1002 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1003 if (!frame
->GetVisibleStatus())
1005 /* We really wanted this to be hidden! */
1006 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1009 else if (e
->xany
.type
== UnmapNotify
)
1011 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1016 bool wxFrame::PreResize()
1018 PositionStatusBar();
1022 WXWidget
wxFrame::GetClientWidget() const
1024 return m_clientArea
;
1027 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1029 wxFrame
*frame
= (wxFrame
*)client_data
;
1031 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1032 closeEvent
.SetEventObject(frame
);
1034 // May delete the frame (with delayed deletion)
1035 frame
->GetEventHandler()->ProcessEvent(closeEvent
);