comparison mac/dw.m @ 1474:cd3d7e341467

Initial implementation of dw_window_set_gravity() on Mac.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 20 Dec 2011 16:31:04 +0000
parents c22477fe7347
children 7216f4301364
comparison
equal deleted inserted replaced
1473:4468ac1db710 1474:cd3d7e341467
8480 { 8480 {
8481 _control_size(handle, width, height); 8481 _control_size(handle, width, height);
8482 } 8482 }
8483 8483
8484 /* 8484 /*
8485 * Sets the gravity of a given window (widget).
8486 * Gravity controls which corner of the screen and window the position is relative to.
8487 * Parameters:
8488 * handle: Window (widget) handle.
8489 * horz: DW_GRAV_LEFT (default), DW_GRAV_RIGHT or DW_GRAV_CENTER.
8490 * vert: DW_GRAV_TOP (default), DW_GRAV_BOTTOM or DW_GRAV_CENTER.
8491 */
8492 void API dw_window_set_gravity(HWND handle, int horz, int vert)
8493 {
8494 dw_window_set_data(handle, "_dw_grav_horz", DW_INT_TO_POINTER(horz));
8495 dw_window_set_data(handle, "_dw_grav_vert", DW_INT_TO_POINTER(vert));
8496 }
8497
8498 /* Convert the coordinates based on gravity */
8499 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height)
8500 {
8501 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
8502 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
8503
8504 /* Do any gravity calculations */
8505 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM)
8506 {
8507 long newx = *x, newy = *y;
8508
8509 /* Handle horizontal center gravity */
8510 if((horz & 0xf) == DW_GRAV_CENTER)
8511 newx += ((dw_screen_width() / 2) - (width / 2));
8512 /* Handle right gravity */
8513 else if((horz & 0xf) == DW_GRAV_RIGHT)
8514 newx = dw_screen_width() - width - *x;
8515 /* Handle vertical center gravity */
8516 if((vert & 0xf) == DW_GRAV_CENTER)
8517 newy += ((dw_screen_height() / 2) - (height / 2));
8518 else if((vert & 0xf) == DW_GRAV_TOP)
8519 newy = dw_screen_height() - height - *y;
8520
8521 /* Save the new values */
8522 *x = newx;
8523 *y = newy;
8524 }
8525 }
8526
8527 /*
8485 * Sets the position of a given window (widget). 8528 * Sets the position of a given window (widget).
8486 * Parameters: 8529 * Parameters:
8487 * handle: Window (widget) handle. 8530 * handle: Window (widget) handle.
8488 * x: X location from the bottom left. 8531 * x: X location from the bottom left.
8489 * y: Y location from the bottom left. 8532 * y: Y location from the bottom left.
8491 void API dw_window_set_pos(HWND handle, LONG x, LONG y) 8534 void API dw_window_set_pos(HWND handle, LONG x, LONG y)
8492 { 8535 {
8493 int _locked_by_me = FALSE; 8536 int _locked_by_me = FALSE;
8494 DW_MUTEX_LOCK; 8537 DW_MUTEX_LOCK;
8495 NSObject *object = handle; 8538 NSObject *object = handle;
8496 NSPoint point; 8539
8497 point.x = x;
8498 point.y = [[NSScreen mainScreen] frame].size.height - y;
8499
8500 if([ object isKindOfClass:[ NSWindow class ] ]) 8540 if([ object isKindOfClass:[ NSWindow class ] ])
8501 { 8541 {
8502 NSWindow *window = handle; 8542 NSWindow *window = handle;
8503 point.y -= [window frame].size.height; 8543 NSPoint point;
8544 NSSize size = [window frame].size;
8545
8546 _handle_gravity(handle, &x, &y, (unsigned long)size.width, (unsigned long)size.height);
8547
8548 point.x = x;
8549 point.y = y;
8550
8504 [window setFrameOrigin:point]; 8551 [window setFrameOrigin:point];
8505 } 8552 }
8506 DW_MUTEX_UNLOCK; 8553 DW_MUTEX_UNLOCK;
8507 } 8554 }
8508 8555