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