]>
Commit | Line | Data |
---|---|---|
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 | #include "wx/defs.h" | |
11 | #include "wx/log.h" | |
12 | ||
13 | #if wxUSE_POPUPWIN | |
14 | ||
15 | #include "wx/popupwin.h" | |
16 | #include "wx/app.h" | |
17 | #include "wx/settings.h" | |
18 | ||
19 | #include "wx/x11/private.h" | |
20 | #include "X11/Xatom.h" | |
21 | #include "X11/Xutil.h" | |
22 | ||
23 | //----------------------------------------------------------------------------- | |
24 | // wxPopupWindow | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
27 | BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase) | |
28 | END_EVENT_TABLE() | |
29 | ||
30 | wxPopupWindow::~wxPopupWindow() | |
31 | { | |
32 | } | |
33 | ||
34 | bool wxPopupWindow::Create( wxWindow *parent, int style ) | |
35 | { | |
36 | if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("popup") )) | |
37 | { | |
38 | wxFAIL_MSG( wxT("wxPopupWindow creation failed") ); | |
39 | return FALSE; | |
40 | } | |
41 | ||
42 | // All dialogs should really have this style | |
43 | m_windowStyle = style; | |
44 | m_windowStyle |= wxTAB_TRAVERSAL; | |
45 | ||
46 | wxPoint pos( 20,20 ); | |
47 | wxSize size( 20,20 ); | |
48 | wxPoint pos2 = pos; | |
49 | wxSize size2 = size; | |
50 | ||
51 | m_parent = parent; | |
52 | if (m_parent) m_parent->AddChild( this ); | |
53 | ||
54 | Display *xdisplay = wxGlobalDisplay(); | |
55 | int xscreen = DefaultScreen( xdisplay ); | |
56 | Visual *xvisual = DefaultVisual( xdisplay, xscreen ); | |
57 | Window xparent = RootWindow( xdisplay, xscreen ); | |
58 | Colormap cm = DefaultColormap( 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 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
75 | m_backgroundColour.CalcPixel( (WXColormap) cm); | |
76 | ||
77 | m_foregroundColour = *wxBLACK; | |
78 | m_foregroundColour.CalcPixel( (WXColormap) cm); | |
79 | ||
80 | xattributes_mask |= CWBackPixel; | |
81 | xattributes.background_pixel = m_backgroundColour.GetPixel(); | |
82 | ||
83 | xattributes_mask |= CWBorderPixel; | |
84 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); | |
85 | ||
86 | xattributes_mask |= CWOverrideRedirect | CWSaveUnder; | |
87 | xattributes.override_redirect = True; | |
88 | xattributes.save_under = True; | |
89 | ||
90 | xattributes_mask |= CWEventMask; | |
91 | #endif | |
92 | ||
93 | if (need_two_windows) | |
94 | { | |
95 | #if !wxUSE_NANOX | |
96 | xattributes.event_mask = | |
97 | ExposureMask | StructureNotifyMask | ColormapChangeMask; | |
98 | #endif | |
99 | ||
100 | Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y, | |
101 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
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 | |
110 | ||
111 | // Set background to None which will prevent X11 from clearing the | |
112 | // background comletely. | |
113 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
114 | ||
115 | m_mainWindow = (WXWindow) xwindow; | |
116 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
117 | ||
118 | // XMapWindow( xdisplay, xwindow ); | |
119 | #if !wxUSE_NANOX | |
120 | xattributes.event_mask = | |
121 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
122 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
123 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
124 | PropertyChangeMask | VisibilityChangeMask ; | |
125 | #endif | |
126 | ||
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 | ||
149 | // Set background to None which will prevent X11 from clearing the | |
150 | // background comletely. | |
151 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
152 | ||
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 | ||
161 | m_clientWindow = (WXWindow) xwindow; | |
162 | wxAddClientWindowToTable( xwindow, (wxWindow*) this ); | |
163 | ||
164 | m_isShown = FALSE; | |
165 | XMapWindow( xdisplay, xwindow ); | |
166 | } | |
167 | else | |
168 | { | |
169 | // One window | |
170 | #if !wxUSE_NANOX | |
171 | xattributes.event_mask = | |
172 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
173 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
174 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
175 | PropertyChangeMask | VisibilityChangeMask ; | |
176 | #endif | |
177 | ||
178 | Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y, | |
179 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
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. | |
191 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
192 | ||
193 | m_mainWindow = (WXWindow) xwindow; | |
194 | m_clientWindow = (WXWindow) xwindow; | |
195 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
196 | ||
197 | m_isShown = FALSE; | |
198 | // XMapWindow( xdisplay, xwindow ); | |
199 | } | |
200 | ||
201 | XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent ); | |
202 | ||
203 | #if wxUSE_NANOX | |
204 | // Switch off WM | |
205 | wxSetWMDecorations( (Window) m_mainWindow, 0 ); | |
206 | #else | |
207 | XWMHints wm_hints; | |
208 | wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */; | |
209 | wm_hints.input = True; | |
210 | wm_hints.initial_state = NormalState; | |
211 | XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints); | |
212 | #endif | |
213 | ||
214 | return TRUE; | |
215 | } | |
216 | ||
217 | void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height ) | |
218 | { | |
219 | wxWindowX11::DoMoveWindow( x, y, width, height ); | |
220 | } | |
221 | ||
222 | void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
223 | { | |
224 | wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); | |
225 | } | |
226 | ||
227 | bool wxPopupWindow::Show( bool show ) | |
228 | { | |
229 | bool ret = wxWindowX11::Show( show ); | |
230 | ||
231 | Raise(); | |
232 | ||
233 | return ret; | |
234 | } | |
235 | ||
236 | #endif // wxUSE_POPUPWIN |