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"
17 #include "wx/popupwin.h"
19 #include "wx/settings.h"
21 #include "wx/x11/private.h"
22 #include "X11/Xatom.h"
23 #include "X11/Xutil.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
32 wxPopupWindow::~wxPopupWindow()
36 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
38 if (!CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
40 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
44 // All dialogs should really have this style
45 m_windowStyle
= style
;
46 m_windowStyle
|= wxTAB_TRAVERSAL
;
54 if (m_parent
) m_parent
->AddChild( this );
56 Display
*xdisplay
= wxGlobalDisplay();
57 int xscreen
= DefaultScreen( xdisplay
);
58 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
59 Window xparent
= RootWindow( xdisplay
, xscreen
);
60 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
63 bool need_two_windows
=
64 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
66 bool need_two_windows
= false;
70 long xattributes_mask
= 0;
73 XSetWindowAttributes xattributes
;
74 long xattributes_mask
= 0;
76 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
77 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
79 m_foregroundColour
= *wxBLACK
;
80 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
82 xattributes_mask
|= CWBackPixel
;
83 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
85 xattributes_mask
|= CWBorderPixel
;
86 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
88 xattributes_mask
|= CWOverrideRedirect
| CWSaveUnder
;
89 xattributes
.override_redirect
= True
;
90 xattributes
.save_under
= True
;
92 xattributes_mask
|= CWEventMask
;
98 xattributes
.event_mask
=
99 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
102 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
103 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
106 XSelectInput( xdisplay
, xwindow
,
107 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
108 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
109 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
110 PropertyChangeMask
);
113 // Set background to None which will prevent X11 from clearing the
114 // background comletely.
115 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
117 m_mainWindow
= (WXWindow
) xwindow
;
118 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
120 // XMapWindow( xdisplay, xwindow );
122 xattributes
.event_mask
=
123 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
124 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
125 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
126 PropertyChangeMask
| VisibilityChangeMask
;
129 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
136 if (HasFlag( wxSIMPLE_BORDER
))
148 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
149 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
151 // Set background to None which will prevent X11 from clearing the
152 // background comletely.
153 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
156 XSelectInput( xdisplay
, xwindow
,
157 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
158 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
159 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
160 PropertyChangeMask
);
163 m_clientWindow
= (WXWindow
) xwindow
;
164 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
167 XMapWindow( xdisplay
, xwindow
);
173 xattributes
.event_mask
=
174 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
175 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
176 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
177 PropertyChangeMask
| VisibilityChangeMask
;
180 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
181 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
184 XSelectInput( xdisplay
, xwindow
,
185 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
186 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
187 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
188 PropertyChangeMask
);
191 // Set background to None which will prevent X11 from clearing the
192 // background comletely.
193 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
195 m_mainWindow
= (WXWindow
) xwindow
;
196 m_clientWindow
= (WXWindow
) xwindow
;
197 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
200 // XMapWindow( xdisplay, xwindow );
203 XSetTransientForHint( xdisplay
, (Window
) m_mainWindow
, xparent
);
207 wxSetWMDecorations( (Window
) m_mainWindow
, 0 );
210 wm_hints
.flags
= InputHint
| StateHint
/* | WindowGroupHint */;
211 wm_hints
.input
= True
;
212 wm_hints
.initial_state
= NormalState
;
213 XSetWMHints( xdisplay
, (Window
) m_mainWindow
, &wm_hints
);
219 void wxPopupWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
221 wxWindowX11::DoMoveWindow( x
, y
, width
, height
);
224 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
226 wxWindowX11::DoSetSize(x
, y
, width
, height
, sizeFlags
);
229 bool wxPopupWindow::Show( bool show
)
231 bool ret
= wxWindowX11::Show( show
);
238 #endif // wxUSE_POPUPWIN