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