Mercurial > dwindows
comparison mac/dw.m @ 735:b75be4860279
Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
but it is better than invisible. Also make dw_window_function actually run on the main thread.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Mar 2011 19:20:30 +0000 |
parents | 668a88a0b930 |
children | 5b48519a7fb2 |
comparison
equal
deleted
inserted
replaced
734:668a88a0b930 | 735:b75be4860279 |
---|---|
408 { | 408 { |
409 id object = _DWLastDrawable; | 409 id object = _DWLastDrawable; |
410 NSWindow *window = [object window]; | 410 NSWindow *window = [object window]; |
411 [window flushWindow]; | 411 [window flushWindow]; |
412 } | 412 } |
413 } | |
414 -(void)doWindowFunc:(id)param | |
415 { | |
416 NSValue *v = (NSValue *)param; | |
417 void **params = (void **)[v pointerValue]; | |
418 void (* windowfunc)(void *); | |
419 | |
420 if(params) | |
421 { | |
422 windowfunc = params[0]; | |
423 if(windowfunc) | |
424 { | |
425 windowfunc(params[1]); | |
426 } | |
427 } | |
413 } | 428 } |
414 @end | 429 @end |
415 | 430 |
416 DWObject *DWObj; | 431 DWObject *DWObj; |
417 | 432 |
5623 */ | 5638 */ |
5624 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) | 5639 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) |
5625 { | 5640 { |
5626 int _locked_by_me = FALSE; | 5641 int _locked_by_me = FALSE; |
5627 DW_MUTEX_LOCK; | 5642 DW_MUTEX_LOCK; |
5628 NSRect frame = NSMakeRect(1,1,1,1); | 5643 NSRect frame = NSMakeRect(1,1,1,1); |
5629 NSWindow *window = [[NSWindow alloc] | 5644 NSWindow *window = [[NSWindow alloc] |
5630 initWithContentRect:frame | 5645 initWithContentRect:frame |
5631 styleMask:(flStyle | NSTexturedBackgroundWindowMask) | 5646 styleMask:(flStyle | NSTexturedBackgroundWindowMask) |
5632 backing:NSBackingStoreBuffered | 5647 backing:NSBackingStoreBuffered |
5633 defer:false]; | 5648 defer:false]; |
5634 | 5649 |
5635 [window setTitle:[ NSString stringWithUTF8String:title ]]; | 5650 [window setTitle:[ NSString stringWithUTF8String:title ]]; |
5636 | 5651 |
5637 DWView *view = [[DWView alloc] init]; | 5652 DWView *view = [[DWView alloc] init]; |
5638 | 5653 |
5639 [window setContentView:view]; | 5654 [window setContentView:view]; |
5640 [window setDelegate:view]; | 5655 [window setDelegate:view]; |
5641 [window makeKeyAndOrderFront:nil]; | |
5642 #ifdef BUILDING_FOR_SNOW_LEOPARD | 5656 #ifdef BUILDING_FOR_SNOW_LEOPARD |
5643 [window setAllowsConcurrentViewDrawing:NO]; | 5657 [window setAllowsConcurrentViewDrawing:NO]; |
5644 #endif | 5658 #endif |
5645 [view release]; | 5659 [view release]; |
5646 | 5660 |
5647 /* If it isn't a toplevel window... */ | 5661 /* If it isn't a toplevel window... */ |
5648 if(hwndOwner) | 5662 if(hwndOwner) |
5655 /* Set the window level to be floating */ | 5669 /* Set the window level to be floating */ |
5656 [window setLevel:NSFloatingWindowLevel]; | 5670 [window setLevel:NSFloatingWindowLevel]; |
5657 [window setHidesOnDeactivate:YES]; | 5671 [window setHidesOnDeactivate:YES]; |
5658 } | 5672 } |
5659 } | 5673 } |
5660 DW_MUTEX_UNLOCK; | 5674 DW_MUTEX_UNLOCK; |
5661 return (HWND)window; | 5675 return (HWND)window; |
5662 } | 5676 } |
5663 | 5677 |
5664 /* | 5678 /* |
5665 * Call a function from the window (widget)'s context. | 5679 * Call a function from the window (widget)'s context. |
5666 * Parameters: | 5680 * Parameters: |
5668 * function: Function pointer to be called. | 5682 * function: Function pointer to be called. |
5669 * data: Pointer to the data to be passed to the function. | 5683 * data: Pointer to the data to be passed to the function. |
5670 */ | 5684 */ |
5671 void API dw_window_function(HWND handle, void *function, void *data) | 5685 void API dw_window_function(HWND handle, void *function, void *data) |
5672 { | 5686 { |
5673 void (* windowfunc)(void *); | 5687 void **params = calloc(2, sizeof(void *)); |
5674 | 5688 NSValue *v = [NSValue valueWithPointer:params]; |
5675 windowfunc = function; | 5689 params[0] = function; |
5676 | 5690 params[1] = data; |
5677 if(windowfunc) | 5691 [DWObj performSelectorOnMainThread:@selector(doWindowFunc:) withObject:v waitUntilDone:YES]; |
5678 windowfunc(data); | 5692 free(params); |
5679 } | 5693 } |
5680 | 5694 |
5681 | 5695 |
5682 /* | 5696 /* |
5683 * Changes the appearance of the mouse pointer. | 5697 * Changes the appearance of the mouse pointer. |
5713 * Parameters: | 5727 * Parameters: |
5714 * handle: The window handle to make visible. | 5728 * handle: The window handle to make visible. |
5715 */ | 5729 */ |
5716 int API dw_window_show(HWND handle) | 5730 int API dw_window_show(HWND handle) |
5717 { | 5731 { |
5718 NSObject *object = handle; | 5732 NSObject *object = handle; |
5719 | 5733 |
5720 if([ object isKindOfClass:[ NSWindow class ] ]) | 5734 if([ object isKindOfClass:[ NSWindow class ] ]) |
5721 { | 5735 { |
5722 NSWindow *window = handle; | 5736 NSWindow *window = handle; |
5723 if([window isMiniaturized]) | 5737 NSRect rect = [window frame]; |
5724 { | 5738 if([window isMiniaturized]) |
5725 [window deminiaturize:nil]; | 5739 { |
5726 } | 5740 [window deminiaturize:nil]; |
5727 [window orderFront:nil]; | 5741 } |
5728 [[window contentView] windowResized:nil]; | 5742 /* If we haven't been sized by a call.. */ |
5743 if(rect.size.width < 1 || rect.size.height < 1) | |
5744 { | |
5745 /* Make a sane default size because MacOS won't automatically */ | |
5746 [window setContentSize:NSMakeSize(200,150)]; | |
5747 } | |
5748 [window makeKeyAndOrderFront:nil]; | |
5749 [[window contentView] windowResized:nil]; | |
5729 [[window contentView] windowDidBecomeMain:nil]; | 5750 [[window contentView] windowDidBecomeMain:nil]; |
5730 } | 5751 } |
5731 return 0; | 5752 return 0; |
5732 } | 5753 } |
5733 | 5754 |
5734 /* | 5755 /* |
5735 * Makes the window invisible. | 5756 * Makes the window invisible. |
5736 * Parameters: | 5757 * Parameters: |