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