mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-09 21:52:12 +00:00
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
This commit is contained in:
parent
1c8c0ef617
commit
5b6158e6e4
@ -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 = "<group>"; };
|
||||
6ECABDF70A3FA2B700AD7F7B /* NSCustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCustomView.h; sourceTree = "<group>"; };
|
||||
6ECABDF80A3FA2B700AD7F7B /* NSCustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSCustomView.m; sourceTree = "<group>"; };
|
||||
98214B8D14EE566B006DB3BD /* NSStatusItem+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusItem+Private.h"; sourceTree = "<group>"; };
|
||||
9824ACB914EDE5A000245AEF /* NSStatusBar_(Private).h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusBar_(Private).h"; sourceTree = "<group>"; };
|
||||
A149E81710069B5B00616E2D /* NSCellUndoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCellUndoManager.h; sourceTree = "<group>"; };
|
||||
A149E81810069B5B00616E2D /* NSCellUndoManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSCellUndoManager.m; sourceTree = "<group>"; };
|
||||
A1CC7017100534AB00DB9974 /* NSCachingBinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCachingBinder.h; sourceTree = "<group>"; };
|
||||
@ -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;
|
||||
};
|
||||
|
@ -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 <Foundation/NSObject.h>
|
||||
#import <CoreFoundation/CFBase.h>
|
||||
#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
|
||||
|
@ -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 <AppKit/NSStatusBar.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <CoreGraphics/CGWindow.h>
|
||||
#import <CoreGraphics/CGGeometry.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#ifdef WIN32
|
||||
#import <windows.h>
|
||||
#import <AppKit/Win32Window.h>
|
||||
#endif
|
||||
#import <AppKit/NSStatusItem+Private.h>
|
||||
|
||||
@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
|
||||
|
@ -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 <Foundation/NSObject.h>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreFoundation/CFBase.h>
|
||||
#ifdef WIN32
|
||||
#import <windows.h>
|
||||
#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
|
||||
|
@ -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 <AppKit/NSStatusItem.h>
|
||||
#import <AppKit/NSStatusBar.h>
|
||||
#import <AppKit/NSRaise.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
#import <AppKit/NSStatusItem+Private.h>
|
||||
#import <AppKit/NSMenu.h>
|
||||
#import <AppKit/NSPopUpWindow.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
#ifdef WIN32
|
||||
#import <AppKit/NSStatusBar_(Private).h>
|
||||
#import <Foundation/NSPlatform_win32.h>
|
||||
#import <AppKit/Win32Window.h>
|
||||
#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<height;row++,rowBytes+=bytesPerRow,dibRowBytes+=width*4){
|
||||
for(column=0;column<width;column++){
|
||||
dibRowBytes[column*4]=rowBytes[column*4];
|
||||
dibRowBytes[column*4+1]=rowBytes[column*4+1];
|
||||
dibRowBytes[column*4+2]=rowBytes[column*4+2];
|
||||
dibRowBytes[column*4+3]=rowBytes[column*4+3];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// This works for versions lower than 2k, not really needed, but here.
|
||||
HDC colorDC=CreateCompatibleDC(displayDC);
|
||||
HDC maskDC=CreateCompatibleDC(displayDC);
|
||||
|
||||
colorBitmap=CreateCompatibleBitmap(displayDC,width,height);
|
||||
maskBitmap=CreateCompatibleBitmap(displayDC,width,height);
|
||||
|
||||
|
||||
HBITMAP oldColorBitmap=SelectObject(colorDC,colorBitmap);
|
||||
HBITMAP oldMaskBitmap=SelectObject(maskDC,maskBitmap);
|
||||
|
||||
int row,column;
|
||||
|
||||
for(row=0;row<height;row++,rowBytes+=bytesPerRow){
|
||||
for(column=0;column<width;column++){
|
||||
uint8_t b=rowBytes[column*4];
|
||||
uint8_t g=rowBytes[column*4+1];
|
||||
uint8_t r=rowBytes[column*4+2];
|
||||
uint8_t a=rowBytes[column*4+3];
|
||||
|
||||
if(a<255){
|
||||
SetPixel(colorDC,column,row,RGB(r,g,b));
|
||||
SetPixel(maskDC,column,row,RGB(255,255,255));
|
||||
}
|
||||
else {
|
||||
SetPixel(colorDC,column,row,RGB(r,g,b));
|
||||
SetPixel(maskDC,column,row,RGB(0,0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
SelectObject(colorDC,oldColorBitmap);
|
||||
SelectObject(maskDC,oldMaskBitmap);
|
||||
DeleteDC(colorDC);
|
||||
DeleteDC(maskDC);
|
||||
|
||||
}
|
||||
|
||||
ReleaseDC(NULL,displayDC);
|
||||
|
||||
CGContextRelease(context);
|
||||
|
||||
ICONINFO iconInfo;
|
||||
|
||||
iconInfo.fIcon=FALSE;
|
||||
iconInfo.hbmMask=maskBitmap;
|
||||
iconInfo.hbmColor=colorBitmap;
|
||||
|
||||
_trayIcon=CreateIconIndirect(&iconInfo);
|
||||
|
||||
DeleteObject(colorBitmap);
|
||||
DeleteObject(maskBitmap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#pragma mark Public Methods
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
#ifdef WIN32
|
||||
_trayIcon = NULL;
|
||||
_trayIconID = -1;
|
||||
_win32Menu = NULL;
|
||||
#endif
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSStatusBar *)statusBar{
|
||||
return [NSStatusBar systemStatusBar];
|
||||
}
|
||||
|
||||
- (SEL)action{
|
||||
return _action;
|
||||
}
|
||||
- (void)setAction:(SEL)action{
|
||||
_action = action;
|
||||
}
|
||||
- (SEL)doubleAction{
|
||||
return _doubleAction;
|
||||
}
|
||||
- (void)setDoubleAction:(SEL)action{
|
||||
_doubleAction = action;
|
||||
}
|
||||
- (id)target{
|
||||
return _target;
|
||||
}
|
||||
- (void)setTarget:(id)target{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
- (NSImage *)image{
|
||||
return _image;
|
||||
}
|
||||
|
||||
- (void)setImage:(NSImage *)image{
|
||||
[_image release];
|
||||
_image = nil;
|
||||
_image = [image copy];
|
||||
#ifdef WIN32
|
||||
if(_trayIconID <= -1){
|
||||
[self _createTrayIcon];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
- (NSImage *)alternateImage{
|
||||
return _alternateImage;
|
||||
}
|
||||
- (void)setAlternateImage:(NSImage *)image{
|
||||
#ifndef WIN32
|
||||
[_alternateImage release];
|
||||
_alternateImage = nil;
|
||||
_alternateImage = [image copy];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSString *)title{
|
||||
return _title;
|
||||
}
|
||||
- (void)setTitle:(NSString *)title{
|
||||
#ifndef WIN32
|
||||
[_title release];
|
||||
_title = nil;
|
||||
_title = [title copy];
|
||||
#endif
|
||||
}
|
||||
- (void)setToolTip:(NSString *)toolTip{
|
||||
|
||||
}
|
||||
- (NSAttributedString *)attributedTitle{
|
||||
return _atrTitle;
|
||||
}
|
||||
- (void)setAttributedTitle:(NSAttributedString *)title{
|
||||
#ifndef WIN32
|
||||
[_atrTitle release];
|
||||
_atrTitle = nil;
|
||||
_atrTitle = [title copy];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSView *)view{
|
||||
return _view;
|
||||
}
|
||||
- (void)setView:(NSView *)view{
|
||||
[_view release];
|
||||
_view = nil;
|
||||
_view = [view copy];
|
||||
//Start capture timer
|
||||
}
|
||||
|
||||
- (BOOL)highlightMode{
|
||||
return _highlightMode;
|
||||
}
|
||||
- (void)setHighlightMode:(BOOL)flag{
|
||||
_highlightMode = flag;
|
||||
}
|
||||
|
||||
- (BOOL)isEnabled{
|
||||
return _enabled;
|
||||
}
|
||||
- (void)setEnabled:(BOOL)flag{
|
||||
_enabled = flag;
|
||||
}
|
||||
|
||||
- (CGFloat)length{
|
||||
#ifdef WIN32
|
||||
int traySizeX = GetSystemMetrics(SM_CXSMICON);
|
||||
int traySizeY = GetSystemMetrics(SM_CYSMICON);
|
||||
//Make sure we return a value that will ensure icon will not be clipped with
|
||||
//non-standard tray icon sizes
|
||||
NSLog(@"X:%d Y:%d",traySizeX,traySizeY);
|
||||
if(traySizeX > 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
|
||||
|
@ -17,7 +17,7 @@ typedef enum {
|
||||
NSColor *_backgroundColor;
|
||||
NSColor *_textColor;
|
||||
BOOL _drawsBackground;
|
||||
BOOL _isBezeled;
|
||||
//BOOL _isBezeled;
|
||||
NSTextFieldBezelStyle _bezelStyle;
|
||||
id _placeholder;
|
||||
}
|
||||
|
@ -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 <windows.h>
|
||||
|
||||
@class O2Context_gdi,O2Surface,O2Surface_DIBSection;
|
||||
|
@ -9,6 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <AppKit/Win32Window.h>
|
||||
#import <AppKit/Win32Event.h>
|
||||
#import <AppKit/Win32Display.h>
|
||||
#import <AppKit/NSStatusBar_(Private).h>
|
||||
#import <Foundation/NSString_win32.h>
|
||||
#import <Onyx2D/O2Context.h>
|
||||
#import <Onyx2D/O2Surface.h>
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user