1 /////////////////////////////////////////////////////////////////////////////
2 // Name: srx/x11/popupwin.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // for compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/popupwin.h"
22 #include "wx/settings.h"
24 #include "wx/x11/private.h"
25 #include "X11/Xatom.h"
26 #include "X11/Xutil.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
35 wxPopupWindow::~wxPopupWindow()
39 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
41 if (!CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
43 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
47 // All dialogs should really have this style
48 m_windowStyle
= style
;
49 m_windowStyle
|= wxTAB_TRAVERSAL
;
57 if (m_parent
) m_parent
->AddChild( this );
59 Display
*xdisplay
= wxGlobalDisplay();
60 int xscreen
= DefaultScreen( xdisplay
);
61 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
62 Window xparent
= RootWindow( xdisplay
, xscreen
);
63 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
66 bool need_two_windows
=
67 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
69 bool need_two_windows
= false;
73 long xattributes_mask
= 0;
76 XSetWindowAttributes xattributes
;
77 long xattributes_mask
= 0;
79 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
80 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
82 m_foregroundColour
= *wxBLACK
;
83 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
85 xattributes_mask
|= CWBackPixel
;
86 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
88 xattributes_mask
|= CWBorderPixel
;
89 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
91 xattributes_mask
|= CWOverrideRedirect
| CWSaveUnder
;
92 xattributes
.override_redirect
= True
;
93 xattributes
.save_under
= True
;
95 xattributes_mask
|= CWEventMask
;
101 xattributes
.event_mask
=
102 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
105 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
106 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
109 XSelectInput( xdisplay
, xwindow
,
110 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
111 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
112 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
113 PropertyChangeMask
);
116 // Set background to None which will prevent X11 from clearing the
117 // background comletely.
118 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
120 m_mainWindow
= (WXWindow
) xwindow
;
121 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
123 // XMapWindow( xdisplay, xwindow );
125 xattributes
.event_mask
=
126 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
127 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
128 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
129 PropertyChangeMask
| VisibilityChangeMask
;
132 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
139 if (HasFlag( wxSIMPLE_BORDER
))
151 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
152 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
154 // Set background to None which will prevent X11 from clearing the
155 // background comletely.
156 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
159 XSelectInput( xdisplay
, xwindow
,
160 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
161 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
162 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
163 PropertyChangeMask
);
166 m_clientWindow
= (WXWindow
) xwindow
;
167 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
170 XMapWindow( xdisplay
, xwindow
);
176 xattributes
.event_mask
=
177 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
178 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
179 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
180 PropertyChangeMask
| VisibilityChangeMask
;
183 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
184 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
187 XSelectInput( xdisplay
, xwindow
,
188 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
189 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
190 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
191 PropertyChangeMask
);
194 // Set background to None which will prevent X11 from clearing the
195 // background comletely.
196 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
198 m_mainWindow
= (WXWindow
) xwindow
;
199 m_clientWindow
= (WXWindow
) xwindow
;
200 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
203 // XMapWindow( xdisplay, xwindow );
206 XSetTransientForHint( xdisplay
, (Window
) m_mainWindow
, xparent
);
210 wxSetWMDecorations( (Window
) m_mainWindow
, 0 );
213 wm_hints
.flags
= InputHint
| StateHint
/* | WindowGroupHint */;
214 wm_hints
.input
= True
;
215 wm_hints
.initial_state
= NormalState
;
216 XSetWMHints( xdisplay
, (Window
) m_mainWindow
, &wm_hints
);
222 void wxPopupWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
224 wxWindowX11::DoMoveWindow( x
, y
, width
, height
);
227 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
229 wxWindowX11::DoSetSize(x
, y
, width
, height
, sizeFlags
);
232 bool wxPopupWindow::Show( bool show
)
234 bool ret
= wxWindowX11::Show( show
);
241 #endif // wxUSE_POPUPWIN