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