00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #import "util-osx.h"
00017 #import "util-osx-cocoa.h"
00018 #import "Carbon/Carbon.h"
00019 #import <CoreFoundation/CFNumber.h>
00020 #include <stdio.h>
00021
00022
00023 int get_int_CF(CFDictionaryRef dict, CFStringRef key)
00024 {
00025 CFNumberRef ref = (CFNumberRef) CFDictionaryGetValue(dict, key);
00026 int val = 0;
00027
00028 if ( ! ref )
00029 puts("get_int_CF() - Failed to get number reference");
00030 else
00031 if ( ! CFNumberGetValue(ref, kCFNumberSInt32Type, &val) )
00032 puts("get_int_CF() - Failed to get 32bit int from number");
00033
00034 return val;
00035 }
00036
00037 float get_float_CF(CFDictionaryRef dict, CFStringRef key)
00038 {
00039 CFNumberRef ref = (CFNumberRef) CFDictionaryGetValue(dict, key);
00040 float val = 0.0;
00041
00042 if ( ! ref )
00043 puts("get_float_CF() - Failed to get number reference");
00044 else
00045 if ( ! CFNumberGetValue(ref, kCFNumberFloatType, &val) )
00046 puts("get_float_CF() - Failed to get float from number");
00047
00048 return val;
00049 }
00050
00051 CGDirectDisplayID GetOSXDisplay(WId win)
00052 {
00053 if (!win)
00054 return NULL;
00055
00056 #ifdef QT_MAC_USE_COCOA
00057 return GetOSXCocoaDisplay((void*)win);
00058 #else
00059 CGDirectDisplayID disp = NULL;
00060 HIViewRef hiview = (HIViewRef)win;
00061 WindowRef winref = HIViewGetWindow(hiview);
00062 Rect bounds;
00063 if (!GetWindowBounds(winref, kWindowStructureRgn, &bounds))
00064 {
00065 CGDisplayCount ct;
00066 CGPoint pt;
00067 pt.x = bounds.left;
00068 pt.y = bounds.top;
00069 if (kCGErrorSuccess != CGGetDisplaysWithPoint(pt, 1, &disp, &ct))
00070 disp = CGMainDisplayID();
00071 }
00072 return disp;
00073 #endif
00074 }