Small changes to wxX11
[wxWidgets.git] / src / x11 / popupwin.cpp
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"
19 #include "wx/app.h"
20
21 #include "wx/x11/private.h"
22
23 //-----------------------------------------------------------------------------
24 // wxPopupWindow
25 //-----------------------------------------------------------------------------
26
27 BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase)
28 END_EVENT_TABLE()
29
30 IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow)
31
32 bool wxPopupWindow::Create( wxWindow *parent, int style )
33 {
34 if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, "popup" ))
35 {
36 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
37 return FALSE;
38 }
39
40 // All dialogs should really have this style
41 m_windowStyle = style;
42 m_windowStyle |= wxTAB_TRAVERSAL;
43
44 m_parent = parent;
45 if (m_parent) m_parent->AddChild( this );
46
47 wxTopLevelWindows.Append(this);
48
49 Display *xdisplay = wxGlobalDisplay();
50 int xscreen = DefaultScreen( xdisplay );
51 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
52 Window xparent = RootWindow( xdisplay, xscreen );
53
54 XSetWindowAttributes xattributes;
55 XSizeHints size_hints;
56 XWMHints wm_hints;
57
58 long xattributes_mask =
59 CWEventMask |
60 CWBorderPixel | CWBackPixel;
61 xattributes.background_pixel = BlackPixel( xdisplay, xscreen );
62 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
63 xattributes.override_redirect = False;
64
65 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
66 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
67
68 XSelectInput( xdisplay, xwindow,
69 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
70 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
71 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
72 PropertyChangeMask );
73
74 m_mainWindow = (WXWindow) xwindow;
75 wxAddWindowToTable( xwindow, (wxWindow*) this );
76
77 XSetTransientForHint( xdisplay, xwindow, xparent );
78
79 size_hints.flags = PSize;
80 size_hints.width = size.x;
81 size_hints.height = size.y;
82 XSetWMNormalHints( xdisplay, xwindow, &size_hints);
83
84 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
85 wm_hints.input = True;
86 wm_hints.initial_state = NormalState;
87 XSetWMHints( xdisplay, xwindow, &wm_hints);
88
89 Atom wm_delete_window = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False);
90 XSetWMProtocols( xdisplay, xwindow, &wm_delete_window, 1);
91
92 wxSetWMDecorations((Window) GetMainWindow(), style);
93
94 return TRUE;
95 }
96
97 void wxPopupWindow::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
98 {
99 wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") );
100 }
101
102 void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
103 {
104 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
105 }
106
107 bool wxPopupWindow::Show( bool show )
108 {
109 return wxWindow11::Show( show );
110 }
111
112 #endif // wxUSE_POPUPWIN