Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32window.c @ 1719:5b9f50c957ed SDL-1.3
You can now create multiple windows on Win32
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 28 Jun 2006 08:12:07 +0000 |
parents | ed4d4f1ea201 |
children | a1ebb17f9c52 |
comparison
equal
deleted
inserted
replaced
1718:ed4d4f1ea201 | 1719:5b9f50c957ed |
---|---|
24 #include "../SDL_sysvideo.h" | 24 #include "../SDL_sysvideo.h" |
25 | 25 |
26 #include "SDL_win32video.h" | 26 #include "SDL_win32video.h" |
27 | 27 |
28 | 28 |
29 static int | |
30 SetupWindowData(SDL_Window * window, HWND hwnd, BOOL created) | |
31 { | |
32 SDL_WindowData *data; | |
33 | |
34 /* Allocate the window data */ | |
35 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); | |
36 if (!data) { | |
37 SDL_OutOfMemory(); | |
38 return -1; | |
39 } | |
40 data->window = window; | |
41 data->hwnd = hwnd; | |
42 data->created = created; | |
43 | |
44 /* Associate the data with the window */ | |
45 if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) { | |
46 SDL_free(data); | |
47 WIN_SetError("SetProp() failed"); | |
48 return -1; | |
49 } | |
50 | |
51 /* Set up the window proc function */ | |
52 data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); | |
53 if (data->wndproc == NULL) { | |
54 data->wndproc = DefWindowProc; | |
55 } else { | |
56 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc); | |
57 } | |
58 | |
59 /* Fill in the SDL window with the window data */ | |
60 { | |
61 POINT point; | |
62 if (ClientToScreen(hwnd, &point)) { | |
63 window->x = point.x; | |
64 window->y = point.y; | |
65 } | |
66 } | |
67 { | |
68 RECT rect; | |
69 if (GetClientRect(hwnd, &rect)) { | |
70 window->w = rect.right; | |
71 window->h = rect.bottom; | |
72 } | |
73 } | |
74 { | |
75 DWORD style = GetWindowLong(hwnd, GWL_STYLE); | |
76 if (style & WS_VISIBLE) { | |
77 window->flags |= SDL_WINDOW_SHOWN; | |
78 } else { | |
79 window->flags &= ~SDL_WINDOW_SHOWN; | |
80 } | |
81 if (style & (WS_BORDER | WS_THICKFRAME)) { | |
82 window->flags &= ~SDL_WINDOW_BORDERLESS; | |
83 } else { | |
84 window->flags |= SDL_WINDOW_BORDERLESS; | |
85 } | |
86 if (style & WS_THICKFRAME) { | |
87 window->flags |= SDL_WINDOW_RESIZABLE; | |
88 } else { | |
89 window->flags &= ~SDL_WINDOW_RESIZABLE; | |
90 } | |
91 if (style & WS_MAXIMIZE) { | |
92 window->flags |= SDL_WINDOW_MAXIMIZED; | |
93 } else { | |
94 window->flags &= ~SDL_WINDOW_MAXIMIZED; | |
95 } | |
96 if (style & WS_MINIMIZE) { | |
97 window->flags |= SDL_WINDOW_MINIMIZED; | |
98 } else { | |
99 window->flags &= ~SDL_WINDOW_MINIMIZED; | |
100 } | |
101 } | |
102 | |
103 /* All done! */ | |
104 window->driverdata = data; | |
105 return 0; | |
106 } | |
107 | |
29 int | 108 int |
30 WIN_CreateWindow(_THIS, SDL_Window * window) | 109 WIN_CreateWindow(_THIS, SDL_Window * window) |
31 { | 110 { |
111 HWND hwnd; | |
112 LPTSTR title = NULL; | |
113 HWND top; | |
114 RECT rect; | |
115 DWORD style = 0; | |
116 int x, y; | |
117 int w, h; | |
118 | |
119 if (window->title) { | |
120 title = WIN_UTF8ToString(window->title); | |
121 } else { | |
122 title = NULL; | |
123 } | |
124 | |
125 if (window->flags & SDL_WINDOW_SHOWN) { | |
126 style |= WS_VISIBLE; | |
127 } | |
128 if ((window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS))) { | |
129 style |= WS_POPUP; | |
130 } else { | |
131 style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); | |
132 } | |
133 if (window->flags & SDL_WINDOW_RESIZABLE) { | |
134 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); | |
135 } | |
136 if (window->flags & SDL_WINDOW_MAXIMIZED) { | |
137 style |= WS_MAXIMIZE; | |
138 } | |
139 if (window->flags & SDL_WINDOW_MINIMIZED) { | |
140 style |= WS_MINIMIZE; | |
141 } | |
142 | |
143 /* Figure out what the window area will be */ | |
144 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
145 top = HWND_TOPMOST; | |
146 } else { | |
147 top = HWND_NOTOPMOST; | |
148 } | |
149 rect.left = 0; | |
150 rect.top = 0; | |
151 rect.right = window->w; | |
152 rect.bottom = window->h; | |
153 AdjustWindowRectEx(&rect, style, FALSE, 0); | |
154 w = (rect.right - rect.left); | |
155 h = (rect.bottom - rect.top); | |
156 | |
157 if ((window->flags & SDL_WINDOW_FULLSCREEN) || | |
158 window->x == SDL_WINDOWPOS_CENTERED) { | |
159 x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; | |
160 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { | |
161 x = CW_USEDEFAULT; | |
162 } else { | |
163 x = window->x + rect.left; | |
164 } | |
165 if ((window->flags & SDL_WINDOW_FULLSCREEN) || | |
166 window->y == SDL_WINDOWPOS_CENTERED) { | |
167 y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; | |
168 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) { | |
169 y = CW_USEDEFAULT; | |
170 } else { | |
171 y = window->y + rect.top; | |
172 } | |
173 | |
174 hwnd = CreateWindow(SDL_Appname, | |
175 title ? title : TEXT(""), | |
176 style, x, y, w, h, NULL, NULL, SDL_Instance, NULL); | |
177 if (title) { | |
178 SDL_free(title); | |
179 } | |
180 | |
181 if (!hwnd) { | |
182 WIN_SetError("Couldn't create window"); | |
183 return -1; | |
184 } | |
185 | |
186 if (SetupWindowData(window, hwnd, TRUE) < 0) { | |
187 DestroyWindow(hwnd); | |
188 return -1; | |
189 } | |
190 return 0; | |
32 } | 191 } |
33 | 192 |
34 int | 193 int |
35 WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) | 194 WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) |
36 { | 195 { |
196 HWND hwnd = (HWND) data; | |
197 LPTSTR title; | |
198 int titleLen; | |
199 | |
200 /* Query the title from the existing window */ | |
201 titleLen = GetWindowTextLength(hwnd); | |
202 title = SDL_stack_alloc(TCHAR, titleLen + 1); | |
203 if (title) { | |
204 titleLen = GetWindowText(hwnd, title, titleLen); | |
205 } else { | |
206 titleLen = 0; | |
207 } | |
208 if (titleLen > 0) { | |
209 window->title = WIN_StringToUTF8(title); | |
210 } | |
211 if (title) { | |
212 SDL_stack_free(title); | |
213 } | |
214 | |
215 if (SetupWindowData(window, hwnd, FALSE) < 0) { | |
216 return -1; | |
217 } | |
218 return 0; | |
37 } | 219 } |
38 | 220 |
39 void | 221 void |
40 WIN_SetWindowTitle(_THIS, SDL_Window * window) | 222 WIN_SetWindowTitle(_THIS, SDL_Window * window) |
41 { | 223 { |
224 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
225 LPTSTR title; | |
226 | |
227 if (window->title) { | |
228 title = WIN_UTF8ToString(window->title); | |
229 } else { | |
230 title = NULL; | |
231 } | |
232 SetWindowText(hwnd, title ? title : TEXT("")); | |
233 if (title) { | |
234 SDL_free(title); | |
235 } | |
42 } | 236 } |
43 | 237 |
44 void | 238 void |
45 WIN_SetWindowPosition(_THIS, SDL_Window * window) | 239 WIN_SetWindowPosition(_THIS, SDL_Window * window) |
46 { | 240 { |
241 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
242 RECT rect; | |
243 DWORD style; | |
244 HWND top; | |
245 int x, y; | |
246 int w, h; | |
247 | |
248 /* Figure out what the window area will be */ | |
249 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
250 top = HWND_TOPMOST; | |
251 } else { | |
252 top = HWND_NOTOPMOST; | |
253 } | |
254 style = GetWindowLong(hwnd, GWL_STYLE); | |
255 rect.left = 0; | |
256 rect.top = 0; | |
257 rect.right = window->w; | |
258 rect.bottom = window->h; | |
259 AdjustWindowRectEx(&rect, style, | |
260 (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != | |
261 NULL), 0); | |
262 w = (rect.right - rect.left); | |
263 h = (rect.bottom - rect.top); | |
264 | |
265 if ((window->flags & SDL_WINDOW_FULLSCREEN) || | |
266 window->x == SDL_WINDOWPOS_CENTERED) { | |
267 x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; | |
268 window->x = x - rect.left; | |
269 } else { | |
270 x = window->x + rect.left; | |
271 } | |
272 if ((window->flags & SDL_WINDOW_FULLSCREEN) || | |
273 window->y == SDL_WINDOWPOS_CENTERED) { | |
274 y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; | |
275 window->y = y - rect.top; | |
276 } else { | |
277 y = window->y + rect.top; | |
278 } | |
279 SetWindowPos(hwnd, top, x, y, h, w, (SWP_NOCOPYBITS | SWP_NOSIZE)); | |
47 } | 280 } |
48 | 281 |
49 void | 282 void |
50 WIN_SetWindowSize(_THIS, SDL_Window * window) | 283 WIN_SetWindowSize(_THIS, SDL_Window * window) |
51 { | 284 { |
285 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
286 RECT rect; | |
287 DWORD style; | |
288 HWND top; | |
289 int w, h; | |
290 | |
291 /* Figure out what the window area will be */ | |
292 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
293 top = HWND_TOPMOST; | |
294 } else { | |
295 top = HWND_NOTOPMOST; | |
296 } | |
297 style = GetWindowLong(hwnd, GWL_STYLE); | |
298 rect.left = 0; | |
299 rect.top = 0; | |
300 rect.right = window->w; | |
301 rect.bottom = window->h; | |
302 AdjustWindowRectEx(&rect, style, | |
303 (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != | |
304 NULL), 0); | |
305 w = (rect.right - rect.left); | |
306 h = (rect.bottom - rect.top); | |
307 | |
308 SetWindowPos(hwnd, top, 0, 0, h, w, (SWP_NOCOPYBITS | SWP_NOMOVE)); | |
52 } | 309 } |
53 | 310 |
54 void | 311 void |
55 WIN_ShowWindow(_THIS, SDL_Window * window) | 312 WIN_ShowWindow(_THIS, SDL_Window * window) |
56 { | 313 { |
314 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
315 | |
316 ShowWindow(hwnd, SW_SHOW); | |
57 } | 317 } |
58 | 318 |
59 void | 319 void |
60 WIN_HideWindow(_THIS, SDL_Window * window) | 320 WIN_HideWindow(_THIS, SDL_Window * window) |
61 { | 321 { |
322 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
323 | |
324 ShowWindow(hwnd, SW_HIDE); | |
62 } | 325 } |
63 | 326 |
64 void | 327 void |
65 WIN_RaiseWindow(_THIS, SDL_Window * window) | 328 WIN_RaiseWindow(_THIS, SDL_Window * window) |
66 { | 329 { |
330 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
331 HWND top; | |
332 | |
333 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
334 top = HWND_TOPMOST; | |
335 } else { | |
336 top = HWND_NOTOPMOST; | |
337 } | |
338 SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE)); | |
67 } | 339 } |
68 | 340 |
69 void | 341 void |
70 WIN_MaximizeWindow(_THIS, SDL_Window * window) | 342 WIN_MaximizeWindow(_THIS, SDL_Window * window) |
71 { | 343 { |
344 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
345 | |
346 ShowWindow(hwnd, SW_MAXIMIZE); | |
72 } | 347 } |
73 | 348 |
74 void | 349 void |
75 WIN_MinimizeWindow(_THIS, SDL_Window * window) | 350 WIN_MinimizeWindow(_THIS, SDL_Window * window) |
76 { | 351 { |
352 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
353 | |
354 ShowWindow(hwnd, SW_MINIMIZE); | |
77 } | 355 } |
78 | 356 |
79 void | 357 void |
80 WIN_RestoreWindow(_THIS, SDL_Window * window) | 358 WIN_RestoreWindow(_THIS, SDL_Window * window) |
81 { | 359 { |
360 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
361 | |
362 ShowWindow(hwnd, SW_RESTORE); | |
82 } | 363 } |
83 | 364 |
84 void | 365 void |
85 WIN_SetWindowGrab(_THIS, SDL_Window * window) | 366 WIN_SetWindowGrab(_THIS, SDL_Window * window) |
86 { | 367 { |
368 /* FIXME! */ | |
87 } | 369 } |
88 | 370 |
89 void | 371 void |
90 WIN_DestroyWindow(_THIS, SDL_Window * window) | 372 WIN_DestroyWindow(_THIS, SDL_Window * window) |
91 { | 373 { |
374 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; | |
375 | |
376 if (data) { | |
377 if (data->created) { | |
378 DestroyWindow(data->hwnd); | |
379 } | |
380 SDL_free(data); | |
381 } | |
92 } | 382 } |
93 | 383 |
94 SDL_bool | 384 SDL_bool |
95 WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) | 385 WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) |
96 { | 386 { |
387 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; | |
388 /* FIXME! */ | |
389 #if 0 | |
390 if (info->version.major <= SDL_MAJOR_VERSION) { | |
391 info->window = hwnd; | |
392 /* FIXME! */ | |
393 info->hglrc = NULL; | |
394 return SDL_TRUE; | |
395 } else { | |
396 SDL_SetError("Application not compiled with SDL %d.%d\n", | |
397 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); | |
398 return SDL_FALSE; | |
399 } | |
400 #endif | |
97 } | 401 } |
98 | 402 |
99 /* vi: set ts=4 sw=4 expandtab: */ | 403 /* vi: set ts=4 sw=4 expandtab: */ |