From 5b6158e6e4bf2630b6b2be413b9bd2935c3cd2bb Mon Sep 17 00:00:00 2001 From: Rhys Cox Date: Fri, 17 Feb 2012 19:45:27 +0000 Subject: [PATCH] Added basic implementation of NSStatusBar and NSStatusItem, Private headers added to allow for additional callbacks, changes made to Win32Window to facilitate tray event callbacks. Currently unsupported features are: drawing status bar background, view-based menu items, view an text-based status items --- AppKit/AppKit.xcodeproj/project.pbxproj | 24 ++ AppKit/NSStatusBar.h | 15 +- AppKit/NSStatusBar.m | 110 ++++- AppKit/NSStatusItem.h | 70 ++- AppKit/NSStatusItem.m | 403 ++++++++++++++++++ AppKit/NSTextFieldCell.h | 2 +- AppKit/Win32.subproj/Win32Window.h | 1 + AppKit/Win32.subproj/Win32Window.m | 9 + .../CoreFoundation.xcodeproj/project.pbxproj | 3 + .../CoreServices.xcodeproj/project.pbxproj | 3 + .../Foundation.xcodeproj/project.pbxproj | 8 +- 11 files changed, 638 insertions(+), 10 deletions(-) diff --git a/AppKit/AppKit.xcodeproj/project.pbxproj b/AppKit/AppKit.xcodeproj/project.pbxproj index a881b579..8f3389cf 100644 --- a/AppKit/AppKit.xcodeproj/project.pbxproj +++ b/AppKit/AppKit.xcodeproj/project.pbxproj @@ -64,6 +64,16 @@ 631382B6145F734100765AA7 /* NSColorWheel.png in Resources */ = {isa = PBXBuildFile; fileRef = 631382B3145F734100765AA7 /* NSColorWheel.png */; }; 631382B7145F734100765AA7 /* NSColorWheel.png in Resources */ = {isa = PBXBuildFile; fileRef = 631382B3145F734100765AA7 /* NSColorWheel.png */; }; 631382B8145F734100765AA7 /* NSColorWheel.png in Resources */ = {isa = PBXBuildFile; fileRef = 631382B3145F734100765AA7 /* NSColorWheel.png */; }; + 98214B8F14EE566B006DB3BD /* NSStatusItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 98214B9014EE566B006DB3BD /* NSStatusItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 98214B9114EE566B006DB3BD /* NSStatusItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 98214B9214EE566B006DB3BD /* NSStatusItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 98214B9314EE566B006DB3BD /* NSStatusItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 9824ACBB14EDE5A100245AEF /* NSStatusBar_(Private).h in Headers */ = {isa = PBXBuildFile; fileRef = 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */; settings = {ATTRIBUTES = (Private, ); }; }; + 9824ACBD14EDE63D00245AEF /* NSStatusBar_(Private).h in Headers */ = {isa = PBXBuildFile; fileRef = 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */; settings = {ATTRIBUTES = (Private, ); }; }; + 9824ACBE14EDE64100245AEF /* NSStatusBar_(Private).h in Headers */ = {isa = PBXBuildFile; fileRef = 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */; settings = {ATTRIBUTES = (Private, ); }; }; + 9824ACBF14EDE64200245AEF /* NSStatusBar_(Private).h in Headers */ = {isa = PBXBuildFile; fileRef = 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */; settings = {ATTRIBUTES = (Private, ); }; }; + 9824ACC014EDE64200245AEF /* NSStatusBar_(Private).h in Headers */ = {isa = PBXBuildFile; fileRef = 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */; settings = {ATTRIBUTES = (Private, ); }; }; A1CC7019100534AB00DB9974 /* NSCachingBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC7017100534AB00DB9974 /* NSCachingBinder.h */; }; A1CC701A100534AB00DB9974 /* NSCachingBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC7018100534AB00DB9974 /* NSCachingBinder.m */; }; A1CC701B100534AB00DB9974 /* NSCachingBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC7017100534AB00DB9974 /* NSCachingBinder.h */; }; @@ -4884,6 +4894,8 @@ 6EC4ADE50A37294300E8D6CA /* NSButtonImageSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSButtonImageSource.m; sourceTree = ""; }; 6ECABDF70A3FA2B700AD7F7B /* NSCustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCustomView.h; sourceTree = ""; }; 6ECABDF80A3FA2B700AD7F7B /* NSCustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSCustomView.m; sourceTree = ""; }; + 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusItem+Private.h"; sourceTree = ""; }; + 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusBar_(Private).h"; sourceTree = ""; }; A149E81710069B5B00616E2D /* NSCellUndoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCellUndoManager.h; sourceTree = ""; }; A149E81810069B5B00616E2D /* NSCellUndoManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSCellUndoManager.m; sourceTree = ""; }; A1CC7017100534AB00DB9974 /* NSCachingBinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCachingBinder.h; sourceTree = ""; }; @@ -5727,8 +5739,10 @@ FE2A112E0B45C55D006C03DE /* NSSpellChecker.m */, 6E2B54980976075200DA0954 /* NSSplitView.h */, 6E2B53BD0976075200DA0954 /* NSSplitView.m */, + 9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */, FE2A113D0B45C58D006C03DE /* NSStatusBar.h */, FE2A113E0B45C58D006C03DE /* NSStatusBar.m */, + 98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */, FE2A11450B45C59A006C03DE /* NSStatusItem.h */, FE2A11460B45C59A006C03DE /* NSStatusItem.m */, 6E2B54A20976075200DA0954 /* NSStepper.h */, @@ -7214,6 +7228,8 @@ FEB3F1ED14049CC400059C8F /* NSSpellCheckerTagData.h in Headers */, 63138206145F3A5F00765AA7 /* NSColorPickerWheel.h in Headers */, 6313829E145F6ED300765AA7 /* NSColorPickerWheelView.h in Headers */, + 9824ACBD14EDE63D00245AEF /* NSStatusBar_(Private).h in Headers */, + 98214B9014EE566B006DB3BD /* NSStatusItem+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -7622,6 +7638,8 @@ FEB3F1E914049CC400059C8F /* NSSpellCheckerTagData.h in Headers */, 63138208145F3A5F00765AA7 /* NSColorPickerWheel.h in Headers */, 631382A0145F6ED300765AA7 /* NSColorPickerWheelView.h in Headers */, + 9824ACBE14EDE64100245AEF /* NSStatusBar_(Private).h in Headers */, + 98214B9114EE566B006DB3BD /* NSStatusItem+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -8027,6 +8045,8 @@ FEB3F1EB14049CC400059C8F /* NSSpellCheckerTagData.h in Headers */, 63138202145F3A5F00765AA7 /* NSColorPickerWheel.h in Headers */, 6313829A145F6ED300765AA7 /* NSColorPickerWheelView.h in Headers */, + 9824ACBB14EDE5A100245AEF /* NSStatusBar_(Private).h in Headers */, + 98214B8F14EE566B006DB3BD /* NSStatusItem+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -8437,6 +8457,8 @@ FEB3F1EF14049CC400059C8F /* NSSpellCheckerTagData.h in Headers */, 63138204145F3A5F00765AA7 /* NSColorPickerWheel.h in Headers */, 6313829C145F6ED300765AA7 /* NSColorPickerWheelView.h in Headers */, + 9824ACC014EDE64200245AEF /* NSStatusBar_(Private).h in Headers */, + 98214B9314EE566B006DB3BD /* NSStatusItem+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -8764,6 +8786,8 @@ FEB3F1F114049CC400059C8F /* NSSpellCheckerTagData.h in Headers */, 6313820A145F3A5F00765AA7 /* NSColorPickerWheel.h in Headers */, 631382A2145F6ED300765AA7 /* NSColorPickerWheelView.h in Headers */, + 9824ACBF14EDE64200245AEF /* NSStatusBar_(Private).h in Headers */, + 98214B9214EE566B006DB3BD /* NSStatusItem+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AppKit/NSStatusBar.h b/AppKit/NSStatusBar.h index a7eb8ee8..397172ce 100644 --- a/AppKit/NSStatusBar.h +++ b/AppKit/NSStatusBar.h @@ -7,9 +7,22 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import +#import +#define NSVariableStatusItemLength (-1) +#define NSSquareStatusItemLength (-2) -@interface NSStatusBar : NSObject { +@class NSStatusItem, Win32Window; +@interface NSStatusBar : NSObject{ + NSMutableArray *_statusItems; +#ifdef WIN32 + Win32Window *_fakeWindow; +#endif } ++ (NSStatusBar *)systemStatusBar; +- (BOOL)isVertical; +- (void)removeStatusItem:(NSStatusItem *)item; +- (NSStatusItem *)statusItemWithLength:(CGFloat)length; +- (CGFloat)thickness; @end diff --git a/AppKit/NSStatusBar.m b/AppKit/NSStatusBar.m index f7baadda..51b35f08 100644 --- a/AppKit/NSStatusBar.m +++ b/AppKit/NSStatusBar.m @@ -5,8 +5,116 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#import +#import +#import +#import +#import +#ifdef WIN32 +#import +#import +#endif +#import @implementation NSStatusBar +static NSStatusBar *_statusBar=nil; + ++ (NSStatusBar *)systemStatusBar{ + if(_statusBar==nil){ + _statusBar = [[NSStatusBar alloc] init]; + } + return _statusBar; +} + +- (id)init { + self = [super init]; + if (self) { + _statusItems = [[NSMutableArray alloc] init]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationClose) name:@"NSApplicationWillTerminateNotification" object:nil]; + } + return self; +} + +- (BOOL)isVertical{ +#ifdef WIN32 + HWND hTaskbar = FindWindow( "Shell_TrayWnd", NULL ); + + APPBARDATA abd; + RECT taskBarRect = {0}; + abd.rc = taskBarRect; + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hTaskbar; + + SHAppBarMessage(ABM_GETTASKBARPOS, &abd); + + UINT uEdge = abd.uEdge; + + if(uEdge == ABE_LEFT || uEdge == ABE_RIGHT){ + //Vertical + return YES; + }else { + //Horizontal + return NO; + } +#endif + return NO; +} +- (void)removeStatusItem:(NSStatusItem *)item{ + +} +- (NSStatusItem *)statusItemWithLength:(CGFloat)length{ + NSStatusItem *item = [[NSStatusItem alloc] init]; + [item setLength:length]; + [_statusItems addObject:item]; + return [item autorelease]; +} +- (CGFloat)thickness{ +#ifdef WIN32 + HWND hWnd = FindWindow("Shell_TrayWnd",""); + if(hWnd != NULL){ + RECT rect; + GetWindowRect(hWnd, &rect); + if([self isVertical]){ + return rect.right - rect.left; + }else { + return rect.bottom - rect.top; + } + }else { + //Fall back to Windows XP's default taskbar height + return 30; + } +#endif + return 42; +} + +#ifdef WIN32 +- (void)_trayNotificationForID:(int)aTrayID event:(int)anEvent{ + for(int i = 0; i < _statusItems.count; i++){ + NSStatusItem *item = [_statusItems objectAtIndex:i]; + if([item trayIconID] == aTrayID){ + [item _processWin32Event:anEvent]; + } + } +} + +- (Win32Window *)fakeWindow{ + if(!_fakeWindow){ + _fakeWindow = [[Win32Window alloc] initWithFrame:CGRectMake(0, 0, 1, 1) styleMask: (unsigned)NSBorderlessWindowMask isPanel:NO backingType:CGSBackingStoreRetained]; + } + [_fakeWindow makeTransparent]; + [_fakeWindow showWindowWithoutActivation]; + return _fakeWindow; +} + +#endif + +- (void)handleApplicationClose{ +#ifdef WIN32 + for(int i = 0; i < _statusItems.count; i++){ + NSStatusItem *item = [_statusItems objectAtIndex:i]; + [item _removeTrayIcon]; + } +#endif +} + @end diff --git a/AppKit/NSStatusItem.h b/AppKit/NSStatusItem.h index 0f9fb36d..e2675935 100644 --- a/AppKit/NSStatusItem.h +++ b/AppKit/NSStatusItem.h @@ -6,10 +6,74 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#import - +#import +#import +#ifdef WIN32 +#import +#endif +@class NSStatusBar, NSImage, NSAttributedString, NSMenu, NSView, NSWindow; @interface NSStatusItem : NSObject { - + SEL _action; + SEL _doubleAction; + id _target; + //Image-Based Item Vars + NSImage *_image; + NSImage *_alternateImage; + //Text-Based Item Vars + NSString *_title; + NSAttributedString *_atrTitle; + //View-Based Item Vars + NSView *_view; + //Other Vars + BOOL _highlightMode; + BOOL _enabled; + CGFloat _length; + NSMenu *_menu; + NSInteger _actionMask; +#ifdef WIN32 + int _trayIconID; + HICON _trayIcon; + HMENU _win32Menu; +#endif } +- (NSStatusBar *)statusBar; + +- (SEL)action; +- (void)setAction:(SEL)action; +- (SEL)doubleAction; +- (void)setDoubleAction:(SEL)action; +- (id)target; +- (void)setTarget:(id)target; + +- (NSImage *)image; +- (void)setImage:(NSImage *)image; +- (NSImage *)alternateImage; +- (void)setAlternateImage:(NSImage *)image; + +- (NSString *)title; +- (void)setTitle:(NSString *)title; +- (void)setToolTip:(NSString *)toolTip; +- (NSAttributedString *)attributedTitle; +- (void)setAttributedTitle:(NSAttributedString *)title; + +- (NSView *)view; +- (void)setView:(NSView *)view; + +- (BOOL)highlightMode; +- (void)setHighlightMode:(BOOL)flag; + +- (BOOL)isEnabled; +- (void)setEnabled:(BOOL)flag; + +- (CGFloat)length; +- (void)setLength:(CGFloat)len; + +- (NSMenu *)menu; +- (void)setMenu:(NSMenu *)menu; + +- (void)popUpStatusItemMenu:(NSMenu *)menu; +- (NSInteger)sendActionOn:(NSInteger)mask; + +- (void)drawStatusBarBackgroundInRect:(NSRect)rect withHighlight:(BOOL)highlight; @end diff --git a/AppKit/NSStatusItem.m b/AppKit/NSStatusItem.m index ff0e7ba8..3fd065c5 100644 --- a/AppKit/NSStatusItem.m +++ b/AppKit/NSStatusItem.m @@ -7,7 +7,410 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import +#import +#import +#import +#import +#import +#import +#import +#import +#ifdef WIN32 +#import +#import +#import +#endif @implementation NSStatusItem +#pragma mark Private Methods + +#ifdef WIN32 + +- (void)_createTrayIcon{ + ZeroMemory(&niData, sizeof(NOTIFYICONDATA_V2_SIZE)); + niData.cbSize = NOTIFYICONDATA_V2_SIZE; + srand(time(NULL)); + _trayIconID = rand(); + niData.uID = _trayIconID; + niData.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP; + if(_trayIcon == NULL){ + [self _setHICONFromImage:[self image]]; + } + niData.hIcon = _trayIcon; + Win32Window *window = [[NSStatusBar systemStatusBar] fakeWindow]; + niData.hWnd = [window windowHandle]; + niData.uCallbackMessage = 9001; + Shell_NotifyIcon(NIM_ADD,&niData); +} + +- (void)_removeTrayIcon{ + //If tray icon has been created, destroy it + if(_trayIconID > -1){ + Shell_NotifyIcon(NIM_DELETE,&niData); + } +} + +- (int)trayIconID{ + return _trayIconID; +} + +- (void)_processWin32Event:(int)event{ + switch (event) { + case WM_RBUTTONUP: + NSLog(@"Clicked Contextual"); + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processCommandEvent:) name:@"WIN32_WM_COMMAND" object:nil]; + [self _showContextMenu]; + break; + case WM_LBUTTONUP: + NSLog(@"Clicked"); + break; + default: + break; + } +} + +- (void)processCommandEvent:(NSNotification *)notification{ + NSValue *obj = [notification object]; + NSLog(@"Got command event with data: %d:%d",[obj pointValue].x,[obj pointValue].y); + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)_w32loadMenuItem:(NSMenuItem *)item withIdentifier:(int)i intoMenu:(HMENU)menu{ + if([item hasSubmenu]){ + //Configure Submenu based item + NSString *title = [item title]; + HMENU submenu = CreatePopupMenu(); + if(submenu){ + NSMenu *sub = [item submenu]; + if(sub){ + for(int pos = 0; pos < [sub itemArray].count; pos++){ + [self _w32loadMenuItem:[[sub itemArray] objectAtIndex:pos] withIdentifier:(i*10)+pos intoMenu:submenu]; + } + }; + NSString *title = [item title]; + MENUITEMINFO item = {0}; + item.cbSize = sizeof(MENUITEMINFO); + item.fMask = MIIM_TYPE|MIIM_ID|MIIM_DATA|MIIM_SUBMENU; + item.fType = MFT_STRING; + char *string = [title cStringUsingEncoding:NSUTF8StringEncoding]; + item.dwTypeData = string; + item.cch = lstrlen(string); + item.hSubMenu = submenu; + InsertMenuItem(menu, i, FALSE, &item); + } + }else { + NSString *title = [item title]; + MENUITEMINFO item = {0}; + item.cbSize = sizeof(MENUITEMINFO); + item.fMask = MIIM_TYPE|MIIM_ID|MIIM_DATA; + item.fType = MFT_STRING; + char *string = [title cStringUsingEncoding:NSUTF8StringEncoding]; + item.dwTypeData = string; + item.cch = lstrlen(string); + InsertMenuItem(menu, i, FALSE, &item); + } +} + +- (void)_setHICONFromImage:(NSImage *)image{ + //Taken from NSCursor.m + + /// move to the platform files + size_t width=[self length]; + size_t height=width; + + CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB(); + CGContextRef context=CGBitmapContextCreate(NULL,width,height,8,0,colorSpace,kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Little); + CGColorSpaceRelease(colorSpace); + + NSAutoreleasePool *pool=[NSAutoreleasePool new]; + NSGraphicsContext *graphicsContext=[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]; + + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:graphicsContext]; + + [image drawInRect:NSMakeRect(0,0,width,height) fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; + + [NSGraphicsContext restoreGraphicsState]; + + [pool release]; + + uint8_t *rowBytes=CGBitmapContextGetData(context); + size_t bytesPerRow=CGBitmapContextGetBytesPerRow(context); + + HDC displayDC=GetDC(NULL); + HBITMAP colorBitmap; + HBITMAP maskBitmap; + + if(NSPlatformGreaterThanOrEqualToWindows2000()){ + // Cursor with alpha channel, no mask. Win2k and above + BITMAPV5HEADER bi; + void *lpBits; + uint8_t *dibRowBytes; + + ZeroMemory(&bi,sizeof(BITMAPV5HEADER)); + bi.bV5Size=sizeof(BITMAPV5HEADER); + bi.bV5Width=width; + bi.bV5Height=-height; + bi.bV5Planes=1; + bi.bV5BitCount=32; + bi.bV5Compression=BI_BITFIELDS; + bi.bV5RedMask=0x00FF0000; + bi.bV5GreenMask=0x0000FF00; + bi.bV5BlueMask=0x000000FF; + bi.bV5AlphaMask=0xFF000000; + + colorBitmap=CreateDIBSection(displayDC,(BITMAPINFO *)&bi,DIB_RGB_COLORS,&lpBits,NULL,0); + dibRowBytes=lpBits; + + maskBitmap=CreateBitmap(width,height,1,1,NULL); + int row,column; + + for(row=0;row traySizeY){ + return traySizeY; + }else { + return traySizeX; + } +#endif + return _length; +} +- (void)setLength:(CGFloat)len{ +#ifndef WIN32 + _length = len; +#endif +} + +- (NSMenu *)menu{ + return _menu; +} +- (void)setMenu:(NSMenu *)menu{ + [_menu release]; + _menu = nil; + _menu = [menu copy]; +#ifdef WIN32 + //Preprocess Menu into HMENU ready for Win32 Events + if(_win32Menu == NULL){ + _win32Menu = CreatePopupMenu(); + } + if(_win32Menu) { + for(int i = 0; i < [_menu itemArray].count; i++){ + [self _w32loadMenuItem:[[_menu itemArray] objectAtIndex:i] withIdentifier:i intoMenu:_win32Menu]; + } + NSLog(@"Done"); + } +#endif +} + +- (void)popUpStatusItemMenu:(NSMenu *)menu{ +} + +- (void)_showContextMenu{ +#ifdef WIN32 + if(_win32Menu){ + POINT pt; + GetCursorPos(&pt); + Win32Window *window = [[NSStatusBar systemStatusBar] fakeWindow]; + SetForegroundWindow([window windowHandle]); + TrackPopupMenu(_win32Menu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, [window windowHandle], NULL); + }else { + NSLog(@"win32Menu is null!"); + } +#endif +} + +- (NSInteger)sendActionOn:(NSInteger)mask{ + int previousMask = _actionMask; + _actionMask = mask; + return previousMask; +} + +- (void)drawStatusBarBackgroundInRect:(NSRect)rect withHighlight:(BOOL)highlight{ + NSUnimplementedMethod(); +} + @end diff --git a/AppKit/NSTextFieldCell.h b/AppKit/NSTextFieldCell.h index c7d266c8..9c1504c3 100755 --- a/AppKit/NSTextFieldCell.h +++ b/AppKit/NSTextFieldCell.h @@ -17,7 +17,7 @@ typedef enum { NSColor *_backgroundColor; NSColor *_textColor; BOOL _drawsBackground; - BOOL _isBezeled; + //BOOL _isBezeled; NSTextFieldBezelStyle _bezelStyle; id _placeholder; } diff --git a/AppKit/Win32.subproj/Win32Window.h b/AppKit/Win32.subproj/Win32Window.h index c32f71e5..8e67de29 100755 --- a/AppKit/Win32.subproj/Win32Window.h +++ b/AppKit/Win32.subproj/Win32Window.h @@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #undef WINVER #define WINVER 0x501 // XP drop shadow constants +#define WM_NSTRAYACTIVATE 9001 #import @class O2Context_gdi,O2Surface,O2Surface_DIBSection; diff --git a/AppKit/Win32.subproj/Win32Window.m b/AppKit/Win32.subproj/Win32Window.m index b50646d2..bbd83721 100755 --- a/AppKit/Win32.subproj/Win32Window.m +++ b/AppKit/Win32.subproj/Win32Window.m @@ -9,6 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #import #import #import +#import #import #import #import @@ -1461,6 +1462,11 @@ static int reportGLErrorIfNeeded(const char *function,int line){ // This can avoid OpenGL flickering case WM_ERASEBKGND: return 1; + + case WM_COMMAND: + [[NSNotificationCenter defaultCenter] postNotificationName:@"WIN32_WM_COMMAND" object:[NSValue valueWithPoint:CGPointMake(lParam, wParam)]]; + return 1; + break; #if 0 // doesn't seem to work @@ -1469,6 +1475,9 @@ static int reportGLErrorIfNeeded(const char *function,int line){ [_delegate platformWindow:self needsDisplayInRect:NSZeroRect]; break; #endif + case WM_NSTRAYACTIVATE: + [[NSStatusBar systemStatusBar] _trayNotificationForID:wParam event:lParam]; + return 1; default: break; diff --git a/CoreFoundation/CoreFoundation.xcodeproj/project.pbxproj b/CoreFoundation/CoreFoundation.xcodeproj/project.pbxproj index fbcf8591..fec021d6 100644 --- a/CoreFoundation/CoreFoundation.xcodeproj/project.pbxproj +++ b/CoreFoundation/CoreFoundation.xcodeproj/project.pbxproj @@ -974,6 +974,9 @@ /* Begin PBXProject section */ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "CoreFoundation" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; diff --git a/CoreServices/CoreServices.xcodeproj/project.pbxproj b/CoreServices/CoreServices.xcodeproj/project.pbxproj index 22ec93de..7f15e21d 100644 --- a/CoreServices/CoreServices.xcodeproj/project.pbxproj +++ b/CoreServices/CoreServices.xcodeproj/project.pbxproj @@ -386,6 +386,9 @@ /* Begin PBXProject section */ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "CoreServices" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; diff --git a/Foundation/Foundation.xcodeproj/project.pbxproj b/Foundation/Foundation.xcodeproj/project.pbxproj index 71db4b1d..49067a02 100644 --- a/Foundation/Foundation.xcodeproj/project.pbxproj +++ b/Foundation/Foundation.xcodeproj/project.pbxproj @@ -16391,7 +16391,7 @@ baseConfigurationReference = FE70869F143117F100B99A95 /* windows-i386-framework.xcconfig */; buildSettings = { COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEBUG_INFORMATION_FORMAT = stabs; GCC_ENABLE_CPP_EXCEPTIONS = NO; GCC_ENABLE_CPP_RTTI = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -16512,7 +16512,7 @@ GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = NO; - GCC_VERSION = 4.2; + GCC_VERSION = com.apple.compilers.llvmgcc42; INFOPLIST_FILE = Info.plist; INSTALL_PATH = /Developer/Cocotron/1.0/Darwin/i386/Frameworks; OTHER_CFLAGS = ( @@ -16580,7 +16580,7 @@ baseConfigurationReference = FE70869F143117F100B99A95 /* windows-i386-framework.xcconfig */; buildSettings = { COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEBUG_INFORMATION_FORMAT = stabs; GCC_ENABLE_CPP_EXCEPTIONS = NO; GCC_ENABLE_CPP_RTTI = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -16780,7 +16780,7 @@ GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_PRECOMPILE_PREFIX_HEADER = NO; GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; - GCC_VERSION = 4.2; + GCC_VERSION = com.apple.compilers.llvmgcc42; INFOPLIST_FILE = Info.plist; INSTALL_PATH = /Developer/Cocotron/1.0/Darwin/i386/Frameworks; OTHER_CFLAGS = (