]> git.saurik.com Git - wxWidgets.git/blame - src/x11/popupwin.cpp
corrected scrolling problems for controls, switched to separate wxSpinCtrl implementa...
[wxWidgets.git] / src / x11 / popupwin.cpp
CommitLineData
1246e28f
JS
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"
1246e28f 19#include "wx/app.h"
1246e28f
JS
20
21#include "wx/x11/private.h"
6a44bffd
JS
22#include "X11/Xatom.h"
23#include "X11/Xutil.h"
1246e28f
JS
24
25//-----------------------------------------------------------------------------
26// wxPopupWindow
27//-----------------------------------------------------------------------------
28
29BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase)
30END_EVENT_TABLE()
31
32IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow)
33
34bool wxPopupWindow::Create( wxWindow *parent, int style )
35{
1246e28f
JS
36 if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, "popup" ))
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 );
58
97bb82cc
RR
59#if wxUSE_TWO_WINDOWS
60 bool need_two_windows =
61 ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
788519c6 62#else
97bb82cc
RR
63 bool need_two_windows = FALSE;
64#endif
65
8601b2e1
JS
66#if wxUSE_NANOX
67 long xattributes_mask = 0;
68#else
69
b28d3abf 70 XSetWindowAttributes xattributes;
97bb82cc 71 long xattributes_mask = 0;
b28d3abf 72
97bb82cc
RR
73 xattributes_mask |= CWBackPixel;
74 xattributes.background_pixel = m_backgroundColour.GetPixel();
75
76 xattributes_mask |= CWBorderPixel;
b28d3abf 77 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
97bb82cc
RR
78
79 xattributes_mask |= CWOverrideRedirect | CWSaveUnder;
0d1dff01
RR
80 xattributes.override_redirect = True;
81 xattributes.save_under = True;
788519c6 82
97bb82cc 83 xattributes_mask |= CWEventMask;
8601b2e1 84#endif
b28d3abf 85
97bb82cc
RR
86 if (need_two_windows)
87 {
8601b2e1 88#if !wxUSE_NANOX
97bb82cc
RR
89 xattributes.event_mask =
90 ExposureMask | StructureNotifyMask | ColormapChangeMask;
8601b2e1
JS
91#endif
92
97bb82cc
RR
93 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
94 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1
JS
95
96#if wxUSE_NANOX
97 XSelectInput( xdisplay, xwindow,
98 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
99 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
100 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
101 PropertyChangeMask );
102#endif
97bb82cc 103
8601b2e1
JS
104 // Set background to None which will prevent X11 from clearing the
105 // background comletely.
97bb82cc
RR
106 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
107
108 m_mainWindow = (WXWindow) xwindow;
109 wxAddWindowToTable( xwindow, (wxWindow*) this );
110
e97d2576 111 // XMapWindow( xdisplay, xwindow );
8601b2e1 112#if !wxUSE_NANOX
97bb82cc
RR
113 xattributes.event_mask =
114 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
115 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
116 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
117 PropertyChangeMask | VisibilityChangeMask ;
8601b2e1
JS
118#endif
119
97bb82cc
RR
120 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
121 {
122 pos2.x = 2;
123 pos2.y = 2;
124 size2.x -= 4;
125 size2.y -= 4;
126 } else
127 if (HasFlag( wxSIMPLE_BORDER ))
128 {
129 pos2.x = 1;
130 pos2.y = 1;
131 size2.x -= 2;
132 size2.y -= 2;
133 } else
134 {
135 pos2.x = 0;
136 pos2.y = 0;
137 }
138
139 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
140 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
141
8601b2e1
JS
142 // Set background to None which will prevent X11 from clearing the
143 // background comletely.
97bb82cc
RR
144 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
145
8601b2e1
JS
146#if wxUSE_NANOX
147 XSelectInput( xdisplay, xwindow,
148 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
149 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
150 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
151 PropertyChangeMask );
152#endif
153
97bb82cc
RR
154 m_clientWindow = (WXWindow) xwindow;
155 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
156
e97d2576 157 m_isShown = FALSE;
97bb82cc
RR
158 XMapWindow( xdisplay, xwindow );
159 }
160 else
161 {
8601b2e1
JS
162 // One window
163#if !wxUSE_NANOX
97bb82cc
RR
164 xattributes.event_mask =
165 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
166 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
167 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
168 PropertyChangeMask | VisibilityChangeMask ;
8601b2e1
JS
169#endif
170
97bb82cc
RR
171 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
172 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1
JS
173
174#if wxUSE_NANOX
175 XSelectInput( xdisplay, xwindow,
176 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
177 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
178 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
179 PropertyChangeMask );
180#endif
181
182 // Set background to None which will prevent X11 from clearing the
183 // background comletely.
97bb82cc
RR
184 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
185
186 m_mainWindow = (WXWindow) xwindow;
187 m_clientWindow = (WXWindow) xwindow;
188 wxAddWindowToTable( xwindow, (wxWindow*) this );
189
e97d2576
RR
190 m_isShown = FALSE;
191 // XMapWindow( xdisplay, xwindow );
97bb82cc 192 }
ba696cfa 193
97bb82cc 194 XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent );
5e29f97a 195
70b8ab77
JS
196#if wxUSE_NANOX
197 // Switch off WM
97bb82cc 198 wxSetWMDecorations( (Window) m_mainWindow, 0 );
70b8ab77 199#else
86fd8bda 200 XWMHints wm_hints;
b28d3abf
JS
201 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
202 wm_hints.input = True;
203 wm_hints.initial_state = NormalState;
97bb82cc 204 XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints);
788519c6
JS
205#endif
206
1246e28f
JS
207 return TRUE;
208}
209
27398643 210void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height )
1246e28f 211{
27398643 212 wxWindowX11::DoMoveWindow( x, y, width, height );
1246e28f
JS
213}
214
215void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
216{
b28d3abf 217 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
1246e28f 218}
b28d3abf 219
1246e28f
JS
220bool wxPopupWindow::Show( bool show )
221{
86fd8bda
RR
222 bool ret = wxWindowX11::Show( show );
223
90f501b1 224 Raise();
86fd8bda
RR
225
226 return ret;
1246e28f
JS
227}
228
229#endif // wxUSE_POPUPWIN