comparison mac/dw.m @ 751:eba6ab48c952

Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 17 Mar 2011 03:31:01 +0000
parents 9e147366147b
children cf447811d322
comparison
equal deleted inserted replaced
750:e6a9f1c7b0d7 751:eba6ab48c952
344 HMTX DWRunMutex; 344 HMTX DWRunMutex;
345 HMTX DWThreadMutex; 345 HMTX DWThreadMutex;
346 HMTX DWThreadMutex2; 346 HMTX DWThreadMutex2;
347 DWTID DWThread = (DWTID)-1; 347 DWTID DWThread = (DWTID)-1;
348 DWTID _dw_mutex_locked = (DWTID)-1; 348 DWTID _dw_mutex_locked = (DWTID)-1;
349 long DWOSMajor, DWOSMinor, DWOSBuild;
349 350
350 /* Used for doing bitblts from the main thread */ 351 /* Used for doing bitblts from the main thread */
351 typedef struct _bitbltinfo 352 typedef struct _bitbltinfo
352 { 353 {
353 id src; 354 id src;
1831 } 1832 }
1832 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) 1833 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20)
1833 { 1834 {
1834 DWSplitBar *split = (DWSplitBar *)handle; 1835 DWSplitBar *split = (DWSplitBar *)handle;
1835 float percent = [split percent]; 1836 float percent = [split percent];
1836 1837
1837 if(percent > 0) 1838 if(percent > 0)
1838 { 1839 {
1839 dw_splitbar_set(handle, percent); 1840 dw_splitbar_set(handle, percent);
1840 [split setPercent:0]; 1841 [split setPercent:0];
1841 } 1842 }
1874 } 1875 }
1875 } 1876 }
1876 1877
1877 NSMenu *_generate_main_menu() 1878 NSMenu *_generate_main_menu()
1878 { 1879 {
1879 NSString *applicationName = nil; 1880 NSString *applicationName = nil;
1880 1881
1881 /* This only works on 10.6 so we have a backup method */ 1882 /* This only works on 10.6 so we have a backup method */
1882 #ifdef BUILDING_FOR_SNOW_LEOPARD 1883 #ifdef BUILDING_FOR_SNOW_LEOPARD
1883 applicationName = [[NSRunningApplication currentApplication] localizedName]; 1884 applicationName = [[NSRunningApplication currentApplication] localizedName];
1884 #endif 1885 #endif
1885 if(applicationName == nil) 1886 if(applicationName == nil)
1886 { 1887 {
1887 applicationName = [[NSProcessInfo processInfo] processName]; 1888 applicationName = [[NSProcessInfo processInfo] processName];
1888 } 1889 }
1889 1890
1890 /* Create the main menu */ 1891 /* Create the main menu */
1891 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; 1892 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease];
1892 1893
1893 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""]; 1894 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""];
2229 */ 2230 */
2230 void dw_clipboard_set_text( char *str, int len) 2231 void dw_clipboard_set_text( char *str, int len)
2231 { 2232 {
2232 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; 2233 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2233 2234
2234 #ifdef BUILDING_FOR_SNOW_LEOPARD 2235 /* Only in Snow Leopard */
2235 [pasteboard clearContents]; 2236 if(DWOSMinor > 5)
2236 #endif 2237 {
2238 [pasteboard clearContents];
2239 }
2237 2240
2238 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; 2241 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType];
2239 } 2242 }
2240 2243
2241 2244
3635 * text: The text to be display by the static text widget. 3638 * text: The text to be display by the static text widget.
3636 * id: An ID to be used with dw_window_from_id() or 0L. 3639 * id: An ID to be used with dw_window_from_id() or 0L.
3637 */ 3640 */
3638 HWND API dw_status_text_new(char *text, ULONG cid) 3641 HWND API dw_status_text_new(char *text, ULONG cid)
3639 { 3642 {
3640 NSTextField *textfield = dw_text_new(text, cid); 3643 NSTextField *textfield = dw_text_new(text, cid);
3641 [textfield setBordered:YES]; 3644 [textfield setBordered:YES];
3642 [textfield setBezeled:YES]; 3645 if(DWOSMinor > 5)
3643 [textfield setBezelStyle:NSTextFieldSquareBezel]; 3646 {
3644 [textfield setBackgroundColor:[NSColor colorWithDeviceRed:1 green:1 blue:1 alpha: 0]]; 3647 [textfield setBezeled:YES];
3648 [textfield setBezelStyle:NSTextFieldSquareBezel];
3649 }
3650 [textfield setBackgroundColor:[NSColor clearColor]];
3645 [textfield setDrawsBackground:NO]; 3651 [textfield setDrawsBackground:NO];
3646 return textfield; 3652 return textfield;
3647 } 3653 }
3648 3654
3649 /* 3655 /*
3650 * Create a new static text window (widget) to be packed. 3656 * Create a new static text window (widget) to be packed.
3651 * Parameters: 3657 * Parameters:
5722 5728
5723 DWView *view = [[DWView alloc] init]; 5729 DWView *view = [[DWView alloc] init];
5724 5730
5725 [window setContentView:view]; 5731 [window setContentView:view];
5726 [window setDelegate:view]; 5732 [window setDelegate:view];
5727 #ifdef BUILDING_FOR_SNOW_LEOPARD
5728 [window setAllowsConcurrentViewDrawing:NO];
5729 #endif
5730 [view release]; 5733 [view release];
5731 5734
5732 /* If it isn't a toplevel window... */ 5735 /* If it isn't a toplevel window... */
5733 if(hwndOwner) 5736 if(hwndOwner)
5734 { 5737 {
5896 */ 5899 */
5897 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) 5900 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask)
5898 { 5901 {
5899 id object = handle; 5902 id object = handle;
5900 5903
5901 if([object isMemberOfClass:[NSWindow class]]) 5904 if(DWOSMinor > 5 && [object isMemberOfClass:[NSWindow class]])
5902 { 5905 {
5903 #ifdef BUILDING_FOR_SNOW_LEOPARD 5906 NSWindow *window = object;
5904 NSWindow *window = object; 5907 int currentstyle = (int)[window styleMask];
5905 int currentstyle = (int)[window styleMask]; 5908 int tmp;
5906 int tmp;
5907 5909
5908 tmp = currentstyle | (int)mask; 5910 tmp = currentstyle | (int)mask;
5909 tmp ^= mask; 5911 tmp ^= mask;
5910 tmp |= style; 5912 tmp |= style;
5911 5913
5912 [window setStyleMask:tmp]; 5914 [window setStyleMask:tmp];
5913 #endif 5915 }
5914 }
5915 else if([object isKindOfClass:[NSTextField class]]) 5916 else if([object isKindOfClass:[NSTextField class]])
5916 { 5917 {
5917 NSTextField *tf = object; 5918 NSTextField *tf = object;
5918 5919
5919 /* TODO: See if we need to switch to a bitmask */ 5920 /* TODO: See if we need to switch to a bitmask */
6462 * env: Pointer to a DWEnv struct. 6463 * env: Pointer to a DWEnv struct.
6463 */ 6464 */
6464 void dw_environment_query(DWEnv *env) 6465 void dw_environment_query(DWEnv *env)
6465 { 6466 {
6466 struct utsname name; 6467 struct utsname name;
6467 char tempbuf[100];
6468 int len, z;
6469 6468
6470 uname(&name); 6469 uname(&name);
6471 strcpy(env->osName, "MacOS"); 6470 strcpy(env->osName, "MacOS");
6472 strcpy(tempbuf, name.release);
6473
6474 env->MajorBuild = env->MinorBuild = 0;
6475
6476 len = (int)strlen(tempbuf);
6477 6471
6478 strcpy(env->buildDate, __DATE__); 6472 strcpy(env->buildDate, __DATE__);
6479 strcpy(env->buildTime, __TIME__); 6473 strcpy(env->buildTime, __TIME__);
6480 env->DWMajorVersion = DW_MAJOR_VERSION; 6474 env->DWMajorVersion = DW_MAJOR_VERSION;
6481 env->DWMinorVersion = DW_MINOR_VERSION; 6475 env->DWMinorVersion = DW_MINOR_VERSION;
6482 env->DWSubVersion = DW_SUB_VERSION; 6476 env->DWSubVersion = DW_SUB_VERSION;
6483 6477
6484 for(z=1;z<len;z++) 6478 env->MajorVersion = DWOSMajor;
6485 { 6479 env->MinorVersion = DWOSMinor;
6486 if(tempbuf[z] == '.') 6480 env->MajorBuild = DWOSBuild;
6487 {
6488 int ver = atoi(tempbuf);
6489 tempbuf[z] = '\0';
6490 if(ver > 4)
6491 {
6492 env->MajorVersion = 10;
6493 env->MinorVersion = ver - 4;
6494 env->MajorBuild = atoi(&tempbuf[z+1]);
6495 }
6496 else
6497 {
6498 env->MajorVersion = ver;
6499 env->MinorVersion = atoi(&tempbuf[z+1]);
6500 }
6501
6502 return;
6503 }
6504 }
6505 env->MajorVersion = atoi(tempbuf);
6506 env->MinorVersion = 0;
6507 } 6481 }
6508 6482
6509 /* 6483 /*
6510 * Emits a beep. 6484 * Emits a beep.
6511 * Parameters: 6485 * Parameters:
7571 * newthread: True if this is the only thread. 7545 * newthread: True if this is the only thread.
7572 * False if there is already a message loop running. 7546 * False if there is already a message loop running.
7573 */ 7547 */
7574 int API dw_init(int newthread, int argc, char *argv[]) 7548 int API dw_init(int newthread, int argc, char *argv[])
7575 { 7549 {
7550 /* Get the operating system version */
7551 Gestalt(gestaltSystemVersionMajor, &DWOSMajor);
7552 Gestalt(gestaltSystemVersionMinor, &DWOSMinor);
7553 Gestalt(gestaltSystemVersionBugFix, &DWOSBuild);
7576 /* Create the application object */ 7554 /* Create the application object */
7577 DWApp = [NSApplication sharedApplication]; 7555 DWApp = [NSApplication sharedApplication];
7578 /* Create object for handling timers */ 7556 /* Create object for handling timers */
7579 DWHandler = [[DWTimerHandler alloc] init]; 7557 DWHandler = [[DWTimerHandler alloc] init];
7580 /* If we aren't using garbage collection we need autorelease pools */ 7558 /* If we aren't using garbage collection we need autorelease pools */