]>
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 | |
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 | ||
29 | BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase) | |
30 | END_EVENT_TABLE() | |
31 | ||
32 | IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow) | |
33 | ||
34 | bool 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_NANOX |
60 | ||
61 | #if wxUSE_TWO_WINDOWS | |
62 | bool need_two_windows = | |
63 | ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0); | |
788519c6 | 64 | #else |
97bb82cc RR |
65 | bool need_two_windows = FALSE; |
66 | #endif | |
67 | ||
b28d3abf | 68 | XSetWindowAttributes xattributes; |
97bb82cc | 69 | long xattributes_mask = 0; |
b28d3abf | 70 | |
97bb82cc RR |
71 | xattributes_mask |= CWBackPixel; |
72 | xattributes.background_pixel = m_backgroundColour.GetPixel(); | |
73 | ||
74 | xattributes_mask |= CWBorderPixel; | |
b28d3abf | 75 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); |
97bb82cc RR |
76 | |
77 | xattributes_mask |= CWOverrideRedirect | CWSaveUnder; | |
0d1dff01 RR |
78 | xattributes.override_redirect = True; |
79 | xattributes.save_under = True; | |
788519c6 | 80 | |
97bb82cc | 81 | xattributes_mask |= CWEventMask; |
b28d3abf | 82 | |
97bb82cc RR |
83 | if (need_two_windows) |
84 | { | |
85 | xattributes.event_mask = | |
86 | ExposureMask | StructureNotifyMask | ColormapChangeMask; | |
87 | ||
88 | Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y, | |
89 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
90 | ||
91 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
92 | ||
93 | m_mainWindow = (WXWindow) xwindow; | |
94 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
95 | ||
e97d2576 | 96 | // XMapWindow( xdisplay, xwindow ); |
97bb82cc RR |
97 | |
98 | xattributes.event_mask = | |
99 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
100 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
101 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
102 | PropertyChangeMask | VisibilityChangeMask ; | |
103 | ||
104 | if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER)) | |
105 | { | |
106 | pos2.x = 2; | |
107 | pos2.y = 2; | |
108 | size2.x -= 4; | |
109 | size2.y -= 4; | |
110 | } else | |
111 | if (HasFlag( wxSIMPLE_BORDER )) | |
112 | { | |
113 | pos2.x = 1; | |
114 | pos2.y = 1; | |
115 | size2.x -= 2; | |
116 | size2.y -= 2; | |
117 | } else | |
118 | { | |
119 | pos2.x = 0; | |
120 | pos2.y = 0; | |
121 | } | |
122 | ||
123 | xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, | |
124 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
125 | ||
126 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
127 | ||
128 | m_clientWindow = (WXWindow) xwindow; | |
129 | wxAddClientWindowToTable( xwindow, (wxWindow*) this ); | |
130 | ||
e97d2576 | 131 | m_isShown = FALSE; |
97bb82cc RR |
132 | XMapWindow( xdisplay, xwindow ); |
133 | } | |
134 | else | |
135 | { | |
136 | xattributes.event_mask = | |
137 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
138 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
139 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
140 | PropertyChangeMask | VisibilityChangeMask ; | |
141 | ||
142 | Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y, | |
143 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
144 | ||
145 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
146 | ||
147 | m_mainWindow = (WXWindow) xwindow; | |
148 | m_clientWindow = (WXWindow) xwindow; | |
149 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
150 | ||
e97d2576 RR |
151 | m_isShown = FALSE; |
152 | // XMapWindow( xdisplay, xwindow ); | |
97bb82cc RR |
153 | } |
154 | #else | |
155 | fixme | |
156 | #endif | |
ba696cfa | 157 | |
97bb82cc | 158 | XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent ); |
5e29f97a | 159 | |
70b8ab77 JS |
160 | #if wxUSE_NANOX |
161 | // Switch off WM | |
97bb82cc | 162 | wxSetWMDecorations( (Window) m_mainWindow, 0 ); |
70b8ab77 | 163 | #else |
86fd8bda | 164 | XWMHints wm_hints; |
b28d3abf JS |
165 | wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */; |
166 | wm_hints.input = True; | |
167 | wm_hints.initial_state = NormalState; | |
97bb82cc | 168 | XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints); |
788519c6 JS |
169 | #endif |
170 | ||
1246e28f JS |
171 | return TRUE; |
172 | } | |
173 | ||
27398643 | 174 | void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height ) |
1246e28f | 175 | { |
27398643 | 176 | wxWindowX11::DoMoveWindow( x, y, width, height ); |
1246e28f JS |
177 | } |
178 | ||
179 | void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
180 | { | |
b28d3abf | 181 | wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); |
1246e28f | 182 | } |
b28d3abf | 183 | |
1246e28f JS |
184 | bool wxPopupWindow::Show( bool show ) |
185 | { | |
86fd8bda RR |
186 | bool ret = wxWindowX11::Show( show ); |
187 | ||
90f501b1 | 188 | Raise(); |
86fd8bda RR |
189 | |
190 | return ret; | |
1246e28f JS |
191 | } |
192 | ||
193 | #endif // wxUSE_POPUPWIN |