1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/popupwin.h"
17 #include "wx/settings.h"
19 #include "wx/x11/private.h"
20 #include "X11/Xatom.h"
21 #include "X11/Xutil.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
30 wxPopupWindow::~wxPopupWindow()
34 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
36 if (!CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
38 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
42 // All dialogs should really have this style
43 m_windowStyle
= style
;
44 m_windowStyle
|= wxTAB_TRAVERSAL
;
52 if (m_parent
) m_parent
->AddChild( this );
54 Display
*xdisplay
= wxGlobalDisplay();
55 int xscreen
= DefaultScreen( xdisplay
);
56 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
57 Window xparent
= RootWindow( xdisplay
, xscreen
);
58 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
61 bool need_two_windows
=
62 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
64 bool need_two_windows
= FALSE
;
68 long xattributes_mask
= 0;
71 XSetWindowAttributes xattributes
;
72 long xattributes_mask
= 0;
74 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
75 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
77 m_foregroundColour
= *wxBLACK
;
78 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
80 xattributes_mask
|= CWBackPixel
;
81 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
83 xattributes_mask
|= CWBorderPixel
;
84 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
86 xattributes_mask
|= CWOverrideRedirect
| CWSaveUnder
;
87 xattributes
.override_redirect
= True
;
88 xattributes
.save_under
= True
;
90 xattributes_mask
|= CWEventMask
;
96 xattributes
.event_mask
=
97 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
100 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
101 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
104 XSelectInput( xdisplay
, xwindow
,
105 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
106 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
107 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
108 PropertyChangeMask
);
111 // Set background to None which will prevent X11 from clearing the
112 // background comletely.
113 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
115 m_mainWindow
= (WXWindow
) xwindow
;
116 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
118 // XMapWindow( xdisplay, xwindow );
120 xattributes
.event_mask
=
121 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
122 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
123 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
124 PropertyChangeMask
| VisibilityChangeMask
;
127 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
134 if (HasFlag( wxSIMPLE_BORDER
))
146 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
147 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
149 // Set background to None which will prevent X11 from clearing the
150 // background comletely.
151 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
154 XSelectInput( xdisplay
, xwindow
,
155 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
156 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
157 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
158 PropertyChangeMask
);
161 m_clientWindow
= (WXWindow
) xwindow
;
162 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
165 XMapWindow( xdisplay
, xwindow
);
171 xattributes
.event_mask
=
172 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
173 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
174 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
175 PropertyChangeMask
| VisibilityChangeMask
;
178 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
179 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
182 XSelectInput( xdisplay
, xwindow
,
183 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
184 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
185 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
186 PropertyChangeMask
);
189 // Set background to None which will prevent X11 from clearing the
190 // background comletely.
191 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
193 m_mainWindow
= (WXWindow
) xwindow
;
194 m_clientWindow
= (WXWindow
) xwindow
;
195 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
198 // XMapWindow( xdisplay, xwindow );
201 XSetTransientForHint( xdisplay
, (Window
) m_mainWindow
, xparent
);
205 wxSetWMDecorations( (Window
) m_mainWindow
, 0 );
208 wm_hints
.flags
= InputHint
| StateHint
/* | WindowGroupHint */;
209 wm_hints
.input
= True
;
210 wm_hints
.initial_state
= NormalState
;
211 XSetWMHints( xdisplay
, (Window
) m_mainWindow
, &wm_hints
);
217 void wxPopupWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
219 wxWindowX11::DoMoveWindow( x
, y
, width
, height
);
222 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
224 wxWindowX11::DoSetSize(x
, y
, width
, height
, sizeFlags
);
227 bool wxPopupWindow::Show( bool show
)
229 bool ret
= wxWindowX11::Show( show
);
236 #endif // wxUSE_POPUPWIN