]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/toplevel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/toplevel.cpp
3 // Purpose: wxTopLevelWindow Motif implementation
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #include "wx/toplevel.h"
30 #define XtDisplay XTDISPLAY
31 #define XtParent XTPARENT
32 #define XtScreen XTSCREEN
33 #define XtWindow XTWINDOW
34 #pragma message disable nosimpint
38 #include <X11/Shell.h>
47 #pragma message enable nosimpint
50 #include "wx/motif/private.h"
52 wxList wxModelessWindows
; // Frames and modeless dialogs
54 // ---------------------------------------------------------------------------
56 // ---------------------------------------------------------------------------
58 static void wxCloseTLWCallback( Widget widget
, XtPointer client_data
,
59 XmAnyCallbackStruct
*cbs
);
60 static void wxTLWEventHandler( Widget wid
,
61 XtPointer client_data
,
63 Boolean
*continueToDispatch
);
65 // ===========================================================================
66 // wxTopLevelWindowMotif implementation
67 // ===========================================================================
69 void wxTopLevelWindowMotif::PreDestroy()
71 wxModelessWindows
.DeleteObject(this);
73 m_icons
.m_icons
.Empty();
77 // MessageDialog and FileDialog do not have a client widget
78 if( GetClientWidget() )
80 XtRemoveEventHandler( (Widget
)GetClientWidget(),
81 ButtonPressMask
| ButtonReleaseMask
|
82 PointerMotionMask
| KeyPressMask
,
89 wxTopLevelWindowMotif::~wxTopLevelWindowMotif()
91 SetMainWidget( (WXWidget
)0 );
94 void wxTopLevelWindowMotif::Init()
99 bool wxTopLevelWindowMotif::Create( wxWindow
*parent
, wxWindowID id
,
100 const wxString
& title
,
104 const wxString
& name
)
107 m_windowStyle
= style
;
110 parent
->AddChild(this);
112 wxTopLevelWindows
.Append(this);
114 m_windowId
= ( id
> -1 ) ? id
: NewControlId();
116 bool retval
= XmDoCreateTLW( parent
, id
, title
, pos
, size
, style
, name
);
118 if( !retval
) return false;
120 // Intercept CLOSE messages from the window manager
121 Widget shell
= (Widget
)GetShellWidget();
122 Atom WM_DELETE_WINDOW
= XmInternAtom( XtDisplay( shell
),
123 "WM_DELETE_WINDOW", False
);
125 // Remove and add WM_DELETE_WINDOW so ours is only handler
126 // This only appears to be necessary for wxDialog, but does not hurt
128 XmRemoveWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
129 XmAddWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
130 XmActivateWMProtocol( shell
, WM_DELETE_WINDOW
);
132 // Modified Steve Hammes for Motif 2.0
133 #if (XmREVISION > 1 || XmVERSION > 1)
134 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
135 (XtCallbackProc
)wxCloseTLWCallback
,
137 #elif XmREVISION == 1
138 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
139 (XtCallbackProc
)wxCloseTLWCallback
,
142 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
143 (void (*)())wxCloseTLWCallback
, (caddr_t
)this );
146 // This patch come from Torsten Liermann lier@lier1.muc.de
147 if( XmIsMotifWMRunning( shell
) )
150 if( !(m_windowStyle
& wxNO_BORDER
) )
151 decor
|= MWM_DECOR_BORDER
;
152 if( m_windowStyle
& wxRESIZE_BORDER
)
153 decor
|= MWM_DECOR_RESIZEH
;
154 if( m_windowStyle
& wxSYSTEM_MENU
)
155 decor
|= MWM_DECOR_MENU
;
156 if( ( m_windowStyle
& wxCAPTION
) ||
157 ( m_windowStyle
& wxTINY_CAPTION_HORIZ
) ||
158 ( m_windowStyle
& wxTINY_CAPTION_VERT
) )
159 decor
|= MWM_DECOR_TITLE
;
160 if( m_windowStyle
& wxRESIZE_BORDER
)
161 decor
|= MWM_DECOR_BORDER
;
162 if( m_windowStyle
& wxMINIMIZE_BOX
)
163 decor
|= MWM_DECOR_MINIMIZE
;
164 if( m_windowStyle
& wxMAXIMIZE_BOX
)
165 decor
|= MWM_DECOR_MAXIMIZE
;
167 XtVaSetValues( shell
,
168 XmNmwmDecorations
, decor
,
173 // This allows non-Motif window managers to support at least the
174 // no-decorations case.
175 if( ( m_windowStyle
& wxCAPTION
) != wxCAPTION
)
176 XtVaSetValues( shell
,
177 XmNoverrideRedirect
, True
,
181 XtAddEventHandler( (Widget
)GetClientWidget(),
182 ButtonPressMask
| ButtonReleaseMask
|
183 PointerMotionMask
| KeyPressMask
,
191 void wxTopLevelWindowMotif::DoGetPosition(int *x
, int *y
) const
193 Widget top
= (Widget
) GetTopWidget();
194 Window parent_window
= XtWindow((Widget
) top
),
195 next_parent
= XtWindow((Widget
) top
),
196 root
= RootWindowOfScreen(XtScreen((Widget
) top
));
198 // search for the parent that is child of ROOT, because the WM may
199 // reparent twice and notify only the next parent (like FVWM)
200 while (next_parent
!= root
) {
201 Window
*theChildren
; unsigned int n
;
202 parent_window
= next_parent
;
203 XQueryTree(XtDisplay((Widget
) top
), parent_window
, &root
,
204 &next_parent
, &theChildren
, &n
);
205 XFree(theChildren
); // not needed
207 int xx
, yy
; unsigned int dummy
;
208 XGetGeometry(XtDisplay((Widget
) top
), parent_window
, &root
,
209 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
214 void wxTopLevelWindowMotif::Raise()
216 Widget top
= (Widget
) GetTopWidget();
217 Window parent_window
= XtWindow( top
),
218 next_parent
= XtWindow( top
),
219 root
= RootWindowOfScreen( XtScreen( top
) );
220 // search for the parent that is child of ROOT, because the WM may
221 // reparent twice and notify only the next parent (like FVWM)
222 while( next_parent
!= root
)
227 parent_window
= next_parent
;
228 XQueryTree( XtDisplay( top
), parent_window
, &root
,
229 &next_parent
, &theChildren
, &n
);
230 XFree( theChildren
); // not needed
232 XRaiseWindow( XtDisplay( top
), parent_window
);
235 void wxTopLevelWindowMotif::Lower()
237 Widget top
= (Widget
) GetTopWidget();
238 Window parent_window
= XtWindow( top
),
239 next_parent
= XtWindow( top
),
240 root
= RootWindowOfScreen( XtScreen( top
) );
241 // search for the parent that is child of ROOT, because the WM may
242 // reparent twice and notify only the next parent (like FVWM)
243 while( next_parent
!= root
)
248 parent_window
= next_parent
;
249 XQueryTree( XtDisplay( top
), parent_window
, &root
,
250 &next_parent
, &theChildren
, &n
);
251 XFree( theChildren
); // not needed
253 XLowerWindow( XtDisplay( top
), parent_window
);
256 static inline Widget
GetShell( const wxTopLevelWindowMotif
* tlw
)
258 Widget main
= (Widget
) tlw
->GetMainWidget();
259 if( !main
) return (Widget
) NULL
;
261 return XtParent( main
);
264 WXWidget
wxTopLevelWindowMotif::GetShellWidget() const
266 return (WXWidget
) GetShell( this );
269 bool wxTopLevelWindowMotif::ShowFullScreen( bool WXUNUSED(show
),
270 long WXUNUSED(style
) )
276 bool wxTopLevelWindowMotif::IsFullScreen() const
282 void wxTopLevelWindowMotif::Restore()
284 Widget shell
= GetShell( this );
287 XtVaSetValues( shell
,
292 void wxTopLevelWindowMotif::Iconize( bool iconize
)
294 Widget shell
= GetShell( this );
300 XtVaSetValues( shell
,
301 XmNiconic
, (Boolean
)iconize
,
305 bool wxTopLevelWindowMotif::IsIconized() const
307 Widget shell
= GetShell( this );
313 XtVaGetValues( shell
,
317 return (iconic
== True
);
320 void wxTopLevelWindowMotif::Maximize( bool maximize
)
328 bool wxTopLevelWindowMotif::IsMaximized() const
333 void wxTopLevelWindowMotif::DoSetSizeHints( int minW
, int minH
,
337 wxTopLevelWindowBase::DoSetSizeHints( minW
, minH
, maxW
, maxH
, incW
, incH
);
342 if( minW
> -1 ) { XtSetArg( args
[count
], XmNminWidth
, minW
); ++count
; }
343 if( minH
> -1 ) { XtSetArg( args
[count
], XmNminHeight
, minH
); ++count
; }
344 if( maxW
> -1 ) { XtSetArg( args
[count
], XmNmaxWidth
, maxW
); ++count
; }
345 if( maxH
> -1 ) { XtSetArg( args
[count
], XmNmaxHeight
, maxH
); ++count
; }
346 if( incW
> -1 ) { XtSetArg( args
[count
], XmNwidthInc
, incW
); ++count
; }
347 if( incH
> -1 ) { XtSetArg( args
[count
], XmNheightInc
, incH
); ++count
; }
349 XtSetValues( (Widget
)GetShellWidget(), args
, count
);
352 bool wxTopLevelWindowMotif::SetShape( const wxRegion
& region
)
354 return wxDoSetShape( (Display
*)GetXDisplay(),
355 XtWindow( (Widget
)GetShellWidget() ),
359 // ---------------------------------------------------------------------------
360 // Callback definition
361 // ---------------------------------------------------------------------------
363 // Handle a close event from the window manager
364 static void wxCloseTLWCallback( Widget
WXUNUSED(widget
), XtPointer client_data
,
365 XmAnyCallbackStruct
*WXUNUSED(cbs
) )
367 wxTopLevelWindowMotif
* tlw
= (wxTopLevelWindowMotif
*)client_data
;
368 wxCloseEvent
closeEvent( wxEVT_CLOSE_WINDOW
, tlw
->GetId() );
369 closeEvent
.SetEventObject( tlw
);
371 // May delete the dialog (with delayed deletion)
372 tlw
->GetEventHandler()->ProcessEvent(closeEvent
);
375 void wxTLWEventHandler( Widget wid
,
376 XtPointer
WXUNUSED(client_data
),
378 Boolean
* continueToDispatch
)
380 wxTopLevelWindowMotif
* tlw
=
381 (wxTopLevelWindowMotif
*)wxGetWindowFromTable( wid
);
385 wxMouseEvent
wxevent( wxEVT_NULL
);
387 if( wxTranslateMouseEvent( wxevent
, tlw
, wid
, event
) )
389 wxevent
.SetEventObject( tlw
);
390 wxevent
.SetId( tlw
->GetId() );
391 tlw
->GetEventHandler()->ProcessEvent( wxevent
);
395 // An attempt to implement OnCharHook by calling OnCharHook first;
396 // if this returns true, set continueToDispatch to False
397 // (don't continue processing).
398 // Otherwise set it to True and call OnChar.
399 wxKeyEvent
keyEvent( wxEVT_CHAR
);
400 if( wxTranslateKeyEvent( keyEvent
, tlw
, wid
, event
))
402 keyEvent
.SetEventObject( tlw
);
403 keyEvent
.SetId( tlw
->GetId() );
404 keyEvent
.SetEventType( wxEVT_CHAR_HOOK
);
405 if( tlw
->GetEventHandler()->ProcessEvent( keyEvent
) )
407 *continueToDispatch
= False
;
412 // For simplicity, OnKeyDown is the same as OnChar
413 // TODO: filter modifier key presses from OnChar
414 keyEvent
.SetEventType( wxEVT_KEY_DOWN
);
416 // Only process OnChar if OnKeyDown didn't swallow it
417 if( !tlw
->GetEventHandler()->ProcessEvent( keyEvent
) )
419 keyEvent
.SetEventType( wxEVT_CHAR
);
420 tlw
->GetEventHandler()->ProcessEvent( keyEvent
);
427 *continueToDispatch
= True
;