comparison mac/dw.m @ 1494:cf960e266444

Fixes for gravity obstacles on Mac.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 25 Dec 2011 03:55:24 +0000
parents 1608c2a9c2b8
children 99a53823079f
comparison
equal deleted inserted replaced
1493:ac43d9a9eee7 1494:cf960e266444
7597 rect = [window frame]; 7597 rect = [window frame];
7598 7598
7599 /* If the position was not set... generate a default 7599 /* If the position was not set... generate a default
7600 * default one in a similar pattern to SHELLPOSITION. 7600 * default one in a similar pattern to SHELLPOSITION.
7601 */ 7601 */
7602 if(rect.origin.x <= 1 || rect.origin.y <= 1) 7602 if(rect.origin.x <= 1 && rect.origin.y <= 1)
7603 { 7603 {
7604 static int defaultx = 0, defaulty; 7604 static int defaultx = 0, defaulty;
7605 int cx = dw_screen_width(), cy = dw_screen_height(); 7605 int cx = dw_screen_width(), cy = dw_screen_height();
7606 int maxx = cx / 4, maxy = cy / 4; 7606 int maxx = cx / 4, maxy = cy / 4;
7607 NSPoint point; 7607 NSPoint point;
8472 { 8472 {
8473 int _locked_by_me = FALSE; 8473 int _locked_by_me = FALSE;
8474 DW_MUTEX_LOCK; 8474 DW_MUTEX_LOCK;
8475 NSObject *object = handle; 8475 NSObject *object = handle;
8476 8476
8477 if([ object isKindOfClass:[ NSWindow class ] ]) 8477 if([ object isMemberOfClass:[ DWWindow class ] ])
8478 { 8478 {
8479 NSWindow *window = handle; 8479 DWWindow *window = handle;
8480 Box *thisbox; 8480 Box *thisbox;
8481 NSRect content, frame = NSMakeRect(0, 0, width, height); 8481 NSRect content, frame = NSMakeRect(0, 0, width, height);
8482 8482
8483 /* Convert the external frame size to internal content size */ 8483 /* Convert the external frame size to internal content size */
8484 content = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]]; 8484 content = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]];
8499 if(height < 1) content.size.height = thisbox->minheight; 8499 if(height < 1) content.size.height = thisbox->minheight;
8500 } 8500 }
8501 8501
8502 /* Finally set the size */ 8502 /* Finally set the size */
8503 [window setContentSize:content.size]; 8503 [window setContentSize:content.size];
8504 /* Size set manually... don't auto-position */
8505 [window setShown:YES];
8504 } 8506 }
8505 DW_MUTEX_UNLOCK; 8507 DW_MUTEX_UNLOCK;
8506 } 8508 }
8507 8509
8508 /* 8510 /*
8534 /* Convert the coordinates based on gravity */ 8536 /* Convert the coordinates based on gravity */
8535 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height) 8537 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height)
8536 { 8538 {
8537 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz")); 8539 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
8538 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert")); 8540 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
8539 NSRect visiblerect = [[NSScreen mainScreen] visibleFrame];
8540 NSRect totalrect = [[NSScreen mainScreen] frame];
8541 8541
8542 /* Do any gravity calculations */ 8542 /* Do any gravity calculations */
8543 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM) 8543 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM)
8544 { 8544 {
8545 long newx = *x, newy = *y; 8545 long newx = *x, newy = *y;
8559 /* Save the new values */ 8559 /* Save the new values */
8560 *x = newx; 8560 *x = newx;
8561 *y = newy; 8561 *y = newy;
8562 } 8562 }
8563 /* Adjust the values to avoid Dock/Menubar if requested */ 8563 /* Adjust the values to avoid Dock/Menubar if requested */
8564 if(horz & DW_GRAV_OBSTACLES) 8564 if((horz | vert) & DW_GRAV_OBSTACLES)
8565 { 8565 {
8566 if((horz & 0xf) == DW_GRAV_LEFT) 8566 NSRect visiblerect = [[NSScreen mainScreen] visibleFrame];
8567 *x += visiblerect.origin.x; 8567 NSRect totalrect = [[NSScreen mainScreen] frame];
8568 else if((horz & 0xf) == DW_GRAV_RIGHT) 8568
8569 *x -= (totalrect.origin.x + totalrect.size.width) - (visiblerect.origin.x + visiblerect.size.width); 8569 if(horz & DW_GRAV_OBSTACLES)
8570 } 8570 {
8571 if(vert & DW_GRAV_OBSTACLES) 8571 if((horz & 0xf) == DW_GRAV_LEFT)
8572 { 8572 *x += visiblerect.origin.x;
8573 if((vert & 0xf) == DW_GRAV_BOTTOM) 8573 else if((horz & 0xf) == DW_GRAV_RIGHT)
8574 *y += visiblerect.origin.y; 8574 *x -= (totalrect.origin.x + totalrect.size.width) - (visiblerect.origin.x + visiblerect.size.width);
8575 else if((vert & 0xf) == DW_GRAV_RIGHT) 8575 }
8576 *y -= (totalrect.origin.y + totalrect.size.height) - (visiblerect.origin.y + visiblerect.size.height); 8576 if(vert & DW_GRAV_OBSTACLES)
8577 {
8578 if((vert & 0xf) == DW_GRAV_BOTTOM)
8579 *y += visiblerect.origin.y;
8580 else if((vert & 0xf) == DW_GRAV_TOP)
8581 *y -= (totalrect.origin.y + totalrect.size.height) - (visiblerect.origin.y + visiblerect.size.height);
8582 }
8577 } 8583 }
8578 } 8584 }
8579 8585
8580 /* 8586 /*
8581 * Sets the position of a given window (widget). 8587 * Sets the position of a given window (widget).