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