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