Added stubs for mapi32, msimg32, sti and url.
[wine] / dlls / x11drv / desktop.c
1 /*
2  * X11DRV desktop window handling
3  *
4  * Copyright 2001 Alexandre Julliard
5  */
6
7 #include "config.h"
8 #include <X11/cursorfont.h>
9
10 #include "ts_xlib.h"
11
12 #include "wine/winuser16.h"
13 #include "win.h"
14 #include "x11drv.h"
15 #include "debugtools.h"
16
17 DEFAULT_DEBUG_CHANNEL(x11drv);
18
19
20 /* desktop window procedure */
21 static LRESULT WINAPI desktop_winproc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
22 {
23     switch(message)
24     {
25     case WM_ERASEBKGND:
26         PaintDesktop( (HDC)wParam );
27         ValidateRect( hwnd, NULL );
28         break;
29
30     case WM_SYSCOMMAND:
31         if ((wParam & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 );
32         break;
33
34     case WM_SETCURSOR:
35         return SetCursor( LoadCursorA( 0, IDC_ARROWA ) );
36
37     case WM_NCHITTEST:
38         return HTCLIENT;
39     }
40     return 0;
41 }
42
43
44 /* desktop window manager thread */
45 static DWORD CALLBACK desktop_thread( LPVOID driver_data )
46 {
47     Display *display;
48     MSG msg;
49     HWND hwnd;
50     WND *win;
51
52     NtCurrentTeb()->driver_data = driver_data;
53     display = thread_display();
54     hwnd = GetDesktopWindow();
55
56     /* patch the desktop window queue to point to our queue */
57     win = WIN_FindWndPtr( hwnd );
58     win->tid = GetCurrentThreadId();
59     win->hmemTaskQ = InitThreadInput16( 0, 0 );
60     X11DRV_register_window( display, hwnd, win->pDriverData );
61     WIN_ReleaseWndPtr( win );
62
63     SetWindowLongW( hwnd, GWL_WNDPROC, (LONG)desktop_winproc );
64     wine_tsx11_lock();
65     XSetWMProtocols( display, root_window, &wmDeleteWindow, 1 );
66     XMapWindow( display, root_window );
67     wine_tsx11_unlock();
68
69     while (GetMessageW( &msg, hwnd, 0, 0 )) DispatchMessageW( &msg );
70     return 0;
71 }
72
73
74 /***********************************************************************
75  *              X11DRV_create_desktop_thread
76  *
77  * Create the thread that manages the desktop window
78  */
79 void X11DRV_create_desktop_thread(void)
80 {
81     HANDLE handle = CreateThread( NULL, 0, desktop_thread, NtCurrentTeb()->driver_data, 0, NULL );
82     if (!handle)
83     {
84         MESSAGE( "Could not create desktop thread\n" );
85         ExitProcess(1);
86     }
87     /* we transferred our driver data to the new thread */
88     NtCurrentTeb()->driver_data = NULL;
89     CloseHandle( handle );
90 }
91
92
93 /***********************************************************************
94  *              X11DRV_create_desktop
95  *
96  * Create the X11 desktop window for the desktop mode.
97  */
98 Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry )
99 {
100     int x = 0, y = 0, flags;
101     unsigned int width = 640, height = 480;  /* Default size = 640x480 */
102     char *name = "Wine desktop";
103     XSizeHints *size_hints;
104     XWMHints   *wm_hints;
105     XClassHint *class_hints;
106     XSetWindowAttributes win_attr;
107     XTextProperty window_name;
108     Window win;
109     Display *display = thread_display();
110
111     wine_tsx11_lock();
112     flags = XParseGeometry( geometry, &x, &y, &width, &height );
113     screen_width  = width;
114     screen_height = height;
115
116     /* Create window */
117     win_attr.background_pixel = BlackPixel(display, 0);
118     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
119                           PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
120     win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
121
122     if (desktop_vi)
123         win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
124                                              visual, AllocNone );
125     else
126         win_attr.colormap = None;
127
128     win = XCreateWindow( display, DefaultRootWindow(display),
129                          x, y, width, height, 0, screen_depth, InputOutput, visual,
130                          CWBackPixel | CWEventMask | CWCursor | CWColormap, &win_attr );
131
132     /* Set window manager properties */
133     size_hints  = XAllocSizeHints();
134     wm_hints    = XAllocWMHints();
135     class_hints = XAllocClassHint();
136     if (!size_hints || !wm_hints || !class_hints)
137     {
138         MESSAGE("Not enough memory for window manager hints.\n" );
139         ExitProcess(1);
140     }
141     size_hints->min_width = size_hints->max_width = width;
142     size_hints->min_height = size_hints->max_height = height;
143     size_hints->flags = PMinSize | PMaxSize;
144     if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
145     if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
146     else size_hints->flags |= PSize;
147
148     wm_hints->flags = InputHint | StateHint;
149     wm_hints->input = True;
150     wm_hints->initial_state = NormalState;
151     class_hints->res_name  = "wine";
152     class_hints->res_class = "Wine";
153
154     XStringListToTextProperty( &name, 1, &window_name );
155     XSetWMProperties( display, win, &window_name, &window_name,
156                       NULL, 0, size_hints, wm_hints, class_hints );
157     XFree( size_hints );
158     XFree( wm_hints );
159     XFree( class_hints );
160     XFlush( display );
161     wine_tsx11_unlock();
162     return win;
163 }