]> git.saurik.com Git - wxWidgets.git/blob - src/x11/popupwin.cpp
Applied patch 1055774 from Paul Cornett for platforms
[wxWidgets.git] / src / x11 / popupwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: popupwin.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "popupwin.h"
12 #endif
13
14 #include "wx/defs.h"
15 #include "wx/log.h"
16
17 #if wxUSE_POPUPWIN
18
19 #include "wx/popupwin.h"
20 #include "wx/app.h"
21 #include "wx/settings.h"
22
23 #include "wx/x11/private.h"
24 #include "X11/Xatom.h"
25 #include "X11/Xutil.h"
26
27 //-----------------------------------------------------------------------------
28 // wxPopupWindow
29 //-----------------------------------------------------------------------------
30
31 BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase)
32 END_EVENT_TABLE()
33
34 IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow)
35
36 wxPopupWindow::~wxPopupWindow()
37 {
38 }
39
40 bool wxPopupWindow::Create( wxWindow *parent, int style )
41 {
42 if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("popup") ))
43 {
44 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
45 return FALSE;
46 }
47
48 // All dialogs should really have this style
49 m_windowStyle = style;
50 m_windowStyle |= wxTAB_TRAVERSAL;
51
52 wxPoint pos( 20,20 );
53 wxSize size( 20,20 );
54 wxPoint pos2 = pos;
55 wxSize size2 = size;
56
57 m_parent = parent;
58 if (m_parent) m_parent->AddChild( this );
59
60 Display *xdisplay = wxGlobalDisplay();
61 int xscreen = DefaultScreen( xdisplay );
62 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
63 Window xparent = RootWindow( xdisplay, xscreen );
64 Colormap cm = DefaultColormap( xdisplay, xscreen);
65
66 #if wxUSE_TWO_WINDOWS
67 bool need_two_windows =
68 ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
69 #else
70 bool need_two_windows = FALSE;
71 #endif
72
73 #if wxUSE_NANOX
74 long xattributes_mask = 0;
75 #else
76
77 XSetWindowAttributes xattributes;
78 long xattributes_mask = 0;
79
80 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
81 m_backgroundColour.CalcPixel( (WXColormap) cm);
82
83 m_foregroundColour = *wxBLACK;
84 m_foregroundColour.CalcPixel( (WXColormap) cm);
85
86 xattributes_mask |= CWBackPixel;
87 xattributes.background_pixel = m_backgroundColour.GetPixel();
88
89 xattributes_mask |= CWBorderPixel;
90 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
91
92 xattributes_mask |= CWOverrideRedirect | CWSaveUnder;
93 xattributes.override_redirect = True;
94 xattributes.save_under = True;
95
96 xattributes_mask |= CWEventMask;
97 #endif
98
99 if (need_two_windows)
100 {
101 #if !wxUSE_NANOX
102 xattributes.event_mask =
103 ExposureMask | StructureNotifyMask | ColormapChangeMask;
104 #endif
105
106 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
107 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
108
109 #if wxUSE_NANOX
110 XSelectInput( xdisplay, xwindow,
111 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
112 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
113 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
114 PropertyChangeMask );
115 #endif
116
117 // Set background to None which will prevent X11 from clearing the
118 // background comletely.
119 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
120
121 m_mainWindow = (WXWindow) xwindow;
122 wxAddWindowToTable( xwindow, (wxWindow*) this );
123
124 // XMapWindow( xdisplay, xwindow );
125 #if !wxUSE_NANOX
126 xattributes.event_mask =
127 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
128 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
129 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
130 PropertyChangeMask | VisibilityChangeMask ;
131 #endif
132
133 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
134 {
135 pos2.x = 2;
136 pos2.y = 2;
137 size2.x -= 4;
138 size2.y -= 4;
139 } else
140 if (HasFlag( wxSIMPLE_BORDER ))
141 {
142 pos2.x = 1;
143 pos2.y = 1;
144 size2.x -= 2;
145 size2.y -= 2;
146 } else
147 {
148 pos2.x = 0;
149 pos2.y = 0;
150 }
151
152 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
153 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
154
155 // Set background to None which will prevent X11 from clearing the
156 // background comletely.
157 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
158
159 #if wxUSE_NANOX
160 XSelectInput( xdisplay, xwindow,
161 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
162 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
163 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
164 PropertyChangeMask );
165 #endif
166
167 m_clientWindow = (WXWindow) xwindow;
168 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
169
170 m_isShown = FALSE;
171 XMapWindow( xdisplay, xwindow );
172 }
173 else
174 {
175 // One window
176 #if !wxUSE_NANOX
177 xattributes.event_mask =
178 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
179 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
180 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
181 PropertyChangeMask | VisibilityChangeMask ;
182 #endif
183
184 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
185 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
186
187 #if wxUSE_NANOX
188 XSelectInput( xdisplay, xwindow,
189 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
190 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
191 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
192 PropertyChangeMask );
193 #endif
194
195 // Set background to None which will prevent X11 from clearing the
196 // background comletely.
197 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
198
199 m_mainWindow = (WXWindow) xwindow;
200 m_clientWindow = (WXWindow) xwindow;
201 wxAddWindowToTable( xwindow, (wxWindow*) this );
202
203 m_isShown = FALSE;
204 // XMapWindow( xdisplay, xwindow );
205 }
206
207 XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent );
208
209 #if wxUSE_NANOX
210 // Switch off WM
211 wxSetWMDecorations( (Window) m_mainWindow, 0 );
212 #else
213 XWMHints wm_hints;
214 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
215 wm_hints.input = True;
216 wm_hints.initial_state = NormalState;
217 XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints);
218 #endif
219
220 return TRUE;
221 }
222
223 void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height )
224 {
225 wxWindowX11::DoMoveWindow( x, y, width, height );
226 }
227
228 void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
229 {
230 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
231 }
232
233 bool wxPopupWindow::Show( bool show )
234 {
235 bool ret = wxWindowX11::Show( show );
236
237 Raise();
238
239 return ret;
240 }
241
242 #endif // wxUSE_POPUPWIN