Mercurial > dwindows
comparison os2/dw.c @ 1488:6771fa426ba4
Added auto-positioning and auto-sizing code for OS/2.
Fixed existing re-positioning code to handle MDI windows properly.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 24 Dec 2011 16:01:23 +0000 |
parents | 73f2ad84d4ec |
children | 3b4dc98d753b |
comparison
equal
deleted
inserted
replaced
1487:5e4ced521696 | 1488:6771fa426ba4 |
---|---|
4267 { | 4267 { |
4268 WindowData *blah = WinQueryWindowPtr(handle, QWP_USER); | 4268 WindowData *blah = WinQueryWindowPtr(handle, QWP_USER); |
4269 | 4269 |
4270 if(blah && !(blah->flags & DW_OS2_NEW_WINDOW)) | 4270 if(blah && !(blah->flags & DW_OS2_NEW_WINDOW)) |
4271 { | 4271 { |
4272 /* Handle auto-positioning and auto-sizing */ | |
4273 ULONG cx = dw_screen_width(), cy = dw_screen_height(); | |
4274 HWND parent = WinQueryWindow(handle, QW_PARENT); | |
4275 int newx, newy, changed = 0; | |
4276 SWP swp; | |
4277 | |
4278 /* If it is an MDI window... | |
4279 * find the MDI area. | |
4280 */ | |
4281 if(parent && parent != desktop) | |
4282 { | |
4283 WinQueryWindowPos(parent, &swp); | |
4284 cx = swp.cx; | |
4285 cy = swp.cy; | |
4286 /* If the MDI parent isn't visible... | |
4287 * we can't calculate. Drop out. | |
4288 */ | |
4289 if(cx < 1 | cy < 1) | |
4290 { | |
4291 WinSetWindowPos(handle, NULLHANDLE, 0, 0, 0, 0, SWP_MOVE); | |
4292 return rc; | |
4293 } | |
4294 } | |
4295 | |
4296 blah->flags |= DW_OS2_NEW_WINDOW; | |
4297 | |
4298 WinQueryWindowPos(handle, &swp); | |
4299 | |
4300 /* If the size is 0 then auto-size */ | |
4301 if(swp.cx == 0 || swp.cy == 0) | |
4302 { | |
4303 dw_window_set_size(handle, 0, 0); | |
4304 WinQueryWindowPos(handle, &swp); | |
4305 } | |
4306 | |
4307 /* If the position was not set... generate a default | |
4308 * default one in a similar pattern to SHELLPOSITION. | |
4309 */ | |
4310 if(swp.x == -2000 || swp.y == -2000) | |
4311 { | |
4312 static int defaultx = 0, defaulty = 0; | |
4313 int maxx = cx / 4, maxy = cy / 4; | |
4314 | |
4315 defaultx += 20; | |
4316 defaulty += 20; | |
4317 | |
4318 if(defaultx > maxx) | |
4319 defaultx = 20; | |
4320 if(defaulty > maxy) | |
4321 defaulty = 20; | |
4322 | |
4323 newx = defaultx; | |
4324 /* Account for flipped Y */ | |
4325 newy = cy - defaulty - swp.cy; | |
4326 changed = 1; | |
4327 } | |
4328 else | |
4329 { | |
4330 newx = swp.x; | |
4331 newy = swp.y; | |
4332 } | |
4333 | |
4272 /* Make sure windows shown for the first time are | 4334 /* Make sure windows shown for the first time are |
4273 * completely visible if possible. | 4335 * completely visible if possible. |
4274 */ | 4336 */ |
4275 ULONG cx = dw_screen_width(), cy = dw_screen_height(); | 4337 if(swp.cx < cx && (newx+swp.cx) > cx) |
4276 int newx, newy, changed = 0; | |
4277 SWP swp; | |
4278 | |
4279 blah->flags |= DW_OS2_NEW_WINDOW; | |
4280 | |
4281 WinQueryWindowPos(handle, &swp); | |
4282 | |
4283 newx = swp.x; | |
4284 newy = swp.y; | |
4285 | |
4286 if(swp.cx < cx && (swp.x+swp.cx) > cx) | |
4287 { | 4338 { |
4288 newx = (cx - swp.cx)/2; | 4339 newx = (cx - swp.cx)/2; |
4289 changed = 1; | 4340 changed = 1; |
4290 } | 4341 } |
4291 if(swp.cy < cy && (swp.y+swp.cy) > cy) | 4342 if(swp.cy < cy && (newy+swp.cy) > cy) |
4292 { | 4343 { |
4293 newy = (cy - swp.cy)/2; | 4344 newy = (cy - swp.cy)/2; |
4294 changed = 1; | 4345 changed = 1; |
4295 } | 4346 } |
4347 | |
4296 if(changed) | 4348 if(changed) |
4297 WinSetWindowPos(handle, NULLHANDLE, newx, newy, 0, 0, SWP_MOVE); | 4349 WinSetWindowPos(handle, NULLHANDLE, newx, newy, 0, 0, SWP_MOVE); |
4298 } | 4350 } |
4299 } | 4351 } |
4300 return rc; | 4352 return rc; |
4939 } | 4991 } |
4940 | 4992 |
4941 /* Then create the real window window without FCF_SHELLPOSITION */ | 4993 /* Then create the real window window without FCF_SHELLPOSITION */ |
4942 flStyle &= ~FCF_SHELLPOSITION; | 4994 flStyle &= ~FCF_SHELLPOSITION; |
4943 hwndframe = WinCreateStdWindow(hwndOwner, winStyle, &flStyle, (PSZ)ClassName, (PSZ)title, 0L, NULLHANDLE, 0L, &newbox->hwnd); | 4995 hwndframe = WinCreateStdWindow(hwndOwner, winStyle, &flStyle, (PSZ)ClassName, (PSZ)title, 0L, NULLHANDLE, 0L, &newbox->hwnd); |
4996 /* Default the window to a ridiculus place so it can't possibly be intentional */ | |
4997 WinSetWindowPos(hwndframe, NULLHANDLE, -2000, -2000, 0, 0, SWP_MOVE); | |
4944 newbox->hwndtitle = WinWindowFromID(hwndframe, FID_TITLEBAR); | 4998 newbox->hwndtitle = WinWindowFromID(hwndframe, FID_TITLEBAR); |
4945 if(!newbox->titlebar && newbox->hwndtitle) | 4999 if(!newbox->titlebar && newbox->hwndtitle) |
4946 WinSetParent(newbox->hwndtitle, HWND_OBJECT, FALSE); | 5000 WinSetParent(newbox->hwndtitle, HWND_OBJECT, FALSE); |
4947 blah->oldproc = WinSubclassWindow(hwndframe, _sizeproc); | 5001 blah->oldproc = WinSubclassWindow(hwndframe, _sizeproc); |
4948 WinSetWindowPtr(hwndframe, QWP_USER, blah); | 5002 WinSetWindowPtr(hwndframe, QWP_USER, blah); |
5113 hwndframe = WinCreateWindow(HWND_OBJECT, | 5167 hwndframe = WinCreateWindow(HWND_OBJECT, |
5114 WC_FRAME, | 5168 WC_FRAME, |
5115 NULL, | 5169 NULL, |
5116 WS_VISIBLE | WS_CLIPCHILDREN | | 5170 WS_VISIBLE | WS_CLIPCHILDREN | |
5117 FS_NOBYTEALIGN, | 5171 FS_NOBYTEALIGN, |
5118 0,0,2000,1000, | 5172 0,0,0,0, |
5119 NULLHANDLE, | 5173 NULLHANDLE, |
5120 HWND_TOP, | 5174 HWND_TOP, |
5121 id, | 5175 id, |
5122 NULL, | 5176 NULL, |
5123 NULL); | 5177 NULL); |