OSDN Git Service

* path.cc (conv_path_list): Take cygwin_conv_path_t as third parameter.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / window.cc
1 /* window.cc: hidden windows for signals/itimer support
2
3    Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2010,
4    2011 Red Hat, Inc.
5
6    Written by Sergey Okhapkin <sos@prospect.com.ru>
7
8 This file is part of Cygwin.
9
10 This software is a copyrighted work licensed under the terms of the
11 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
12 details. */
13
14 #include "winsup.h"
15 #include <sys/time.h>
16 #include <wingdi.h>
17 #include <winuser.h>
18 #define USE_SYS_TYPES_FD_SET
19 #include <winsock2.h>
20 #include "perprocess.h"
21 #include "cygtls.h"
22 #include "sync.h"
23 #include "wininfo.h"
24
25 wininfo NO_COPY winmsg;
26
27 muto NO_COPY wininfo::_lock;
28
29 int __stdcall
30 wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
31 {
32 #ifndef NOSTRACE
33   strace.wm (uMsg, wParam, lParam);
34 #endif
35   switch (uMsg)
36     {
37     case WM_PAINT:
38       return 0;
39     case WM_DESTROY:
40       PostQuitMessage (0);
41       return 0;
42     case WM_ASYNCIO:
43       if (WSAGETSELECTEVENT (lParam) == FD_OOB)
44         raise (SIGURG);
45       else
46         raise (SIGIO);
47       return 0;
48     default:
49       return DefWindowProcW (hwnd, uMsg, wParam, lParam);
50     }
51 }
52
53 static LRESULT CALLBACK
54 process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
55 {
56   return winmsg.process (hwnd, uMsg, wParam, lParam);
57 }
58
59 /* Handle windows events.  Inherits ownership of the wininfo lock */
60 DWORD WINAPI
61 wininfo::winthread ()
62 {
63   MSG msg;
64   WNDCLASSW wc;
65   static NO_COPY WCHAR classname[] = L"CygwinWndClass";
66
67   _lock.grab ();
68   /* Register the window class for the main window. */
69
70   wc.style = 0;
71   wc.lpfnWndProc = (WNDPROC) process_window_events;
72   wc.cbClsExtra = 0;
73   wc.cbWndExtra = 0;
74   wc.hInstance = user_data->hmodule;
75   wc.hIcon = NULL;
76   wc.hCursor = NULL;
77   wc.hbrBackground = NULL;
78   wc.lpszMenuName = NULL;
79   wc.lpszClassName = classname;
80
81   if (!RegisterClassW (&wc))
82     api_fatal ("cannot register window class, %E");
83
84   /* Create hidden window. */
85   hwnd = CreateWindowExW (0, classname, classname, WS_POPUP, CW_USEDEFAULT,
86                           CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
87                           (HWND) NULL, (HMENU) NULL, user_data->hmodule,
88                           (LPVOID) NULL);
89   if (!hwnd)
90     api_fatal ("couldn't create window, %E");
91   release ();
92
93   int ret;
94   while ((ret = (int) GetMessageW (&msg, hwnd, 0, 0)) > 0)
95     DispatchMessageW (&msg);
96
97   return 0;
98 }
99
100 static DWORD WINAPI
101 winthread (VOID *arg)
102 {
103   return  ((wininfo *) arg)->winthread ();
104 }
105
106 wininfo::operator
107 HWND ()
108 {
109   if (hwnd)
110     return hwnd;
111
112   lock ();
113   if (!hwnd)
114     {
115       _lock.upforgrabs ();
116       cygthread *h = new cygthread (::winthread, this, "win");
117       h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
118       h->zap_h ();
119       lock ();
120     }
121   release ();
122   return hwnd;
123 }
124
125 void
126 wininfo::lock ()
127 {
128   _lock.init ("wininfo_lock")->acquire ();
129 }
130
131 void
132 wininfo::release ()
133 {
134   _lock.release ();
135 }