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