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