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