Browse Source

Fumbeling about at the Cocoa implementation.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6960 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Matthias Melcher 16 years ago
parent
commit
0f0a4672c9
  1. 28
      FL/mac.H
  2. 75
      src/Fl_cocoa.mm

28
FL/mac.H

@ -36,10 +36,34 @@ @@ -36,10 +36,34 @@
// Standard MacOS Carbon API includes...
#include <Carbon/Carbon.h>
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) && !__LP64__
#include <config.h>
#ifdef __APPLE_COCOA__
#ifndef MAC_OS_X_VERSION_10_3
#define MAC_OS_X_VERSION_10_3 1030
#endif
#ifndef MAC_OS_X_VERSION_10_4
#define MAC_OS_X_VERSION_10_4 1040
#endif
#ifndef MAC_OS_X_VERSION_10_5
#define MAC_OS_X_VERSION_10_5 1050
#endif
#ifndef MAC_OS_X_VERSION_10_6
#define MAC_OS_X_VERSION_10_6 1060
#endif
#ifndef MAC_OS_X_VERSION_MAX_ALLOWED
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
#endif
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
#if defined(__LP64__) && __LP64__
typedef double CGFloat;
#else
typedef float CGFloat;
#endif
#include <config.h>
#endif
#endif
// Now make some fixes to the headers...
#undef check // Dunno where this comes from...

75
src/Fl_cocoa.mm

@ -61,16 +61,15 @@ extern "C" { @@ -61,16 +61,15 @@ extern "C" {
#include <stdarg.h>
#import <Cocoa/Cocoa.h>
#include <AvailabilityMacros.h>
#if defined(__LP64__) && __LP64__
typedef double CGFloat;
#else
typedef float CGFloat;
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
#ifndef NSINTEGER_DEFINED //appears with 10.5 in NSObjCRuntime.h
#if defined(__LP64__) && __LP64__
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
#endif
@ -1255,7 +1254,11 @@ extern "C" { @@ -1255,7 +1254,11 @@ extern "C" {
UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
}
@interface FLDelegate : NSObject {
@interface FLDelegate : NSObject
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSWindowDelegate, NSApplicationDelegate>
#endif
{
}
- (void)windowDidMove:(NSNotification *)notif;
- (void)windowDidResize:(NSNotification *)notif;
@ -2746,6 +2749,23 @@ int MACscreen_init(XRectangle screens[]) @@ -2746,6 +2749,23 @@ int MACscreen_init(XRectangle screens[])
return num_screens;
}
@interface FLaboutItemTarget : NSObject
{
}
- (void)showPanel;
@end
@implementation FLaboutItemTarget
- (void)showPanel
{
NSDictionary *options;
options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@" FLTK %d.%d Cocoa", FL_MAJOR_VERSION,
FL_MINOR_VERSION ], @"Copyright",
nil];
[NSApp orderFrontStandardAboutPanelWithOptions:options];
}
@end
static NSMenu *appleMenu;
static void createAppleMenu(void)
{
@ -2763,7 +2783,9 @@ static void createAppleMenu(void) @@ -2763,7 +2783,9 @@ static void createAppleMenu(void)
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:(NSString*)nsappname];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItemWithTitle:title action:@selector(showPanel) keyEquivalent:@""];
FLaboutItemTarget *about = [[FLaboutItemTarget alloc] init];
[[appleMenu itemAtIndex:0] setTarget:about];
[appleMenu addItem:[NSMenuItem separatorItem]];
// Services Menu
services = [[[NSMenu alloc] init] autorelease];
@ -2818,7 +2840,7 @@ static void createAppleMenu(void) @@ -2818,7 +2840,7 @@ static void createAppleMenu(void)
}
- (void) doCallback:(id)obj
{
cb((Fl_Widget*)obj, data);
if (cb) cb((Fl_Widget*)obj, data);
}
- (void*)getItemData
{
@ -2865,6 +2887,26 @@ void MACsetAboutMenu( Fl_Callback *cb, void *data ) @@ -2865,6 +2887,26 @@ void MACsetAboutMenu( Fl_Callback *cb, void *data )
[item setTarget:item];
}
static char *remove_ampersand(const char *s)
{
char *ret = strdup(s);
const char *p = s;
char *q = ret;
while(*p != 0) {
if (p[0]=='&') {
if (p[1]=='&') {
*q++ = '&'; p+=2;
} else {
p++;
}
} else {
*q++ = *p++;
}
}
*q = 0;
return ret;
}
void *MACMenuOrItemOperation(const char *operation, ...)
/* these operations apply to menus, submenus, or menu items
*/
@ -2906,8 +2948,9 @@ void *MACMenuOrItemOperation(const char *operation, ...) @@ -2906,8 +2948,9 @@ void *MACMenuOrItemOperation(const char *operation, ...)
}
else if(strcmp(operation, "initWithTitle") == 0) {//arguments: const char*title. Returns the newly created menu
//creates a new (sub)menu
pter = va_arg(ap, void *);
CFStringRef title = CFStringCreateWithCString(NULL, (const char *)pter, kCFStringEncodingUTF8);
char *ts = remove_ampersand(va_arg(ap, char *));
CFStringRef title = CFStringCreateWithCString(NULL, ts, kCFStringEncodingUTF8);
free(ts);
NSMenu *menu = [[NSMenu alloc] initWithTitle:(NSString*)title];
CFRelease(title);
[menu setAutoenablesItems:NO];
@ -2937,8 +2980,9 @@ void *MACMenuOrItemOperation(const char *operation, ...) @@ -2937,8 +2980,9 @@ void *MACMenuOrItemOperation(const char *operation, ...)
}
else if(strcmp(operation, "setTitle") == 0) {//arguments: NSMenuItem*, const char *
item = va_arg(ap, NSMenuItem*);
pter = va_arg(ap, void *);
CFStringRef title = CFStringCreateWithCString(NULL, (const char *)pter, kCFStringEncodingUTF8);
char *ts = remove_ampersand(va_arg(ap, char *));
CFStringRef title = CFStringCreateWithCString(NULL, ts, kCFStringEncodingUTF8);
free(ts);
[item setTitle:(NSString*)title];
CFRelease(title);
}
@ -2959,11 +3003,12 @@ void *MACMenuOrItemOperation(const char *operation, ...) @@ -2959,11 +3003,12 @@ void *MACMenuOrItemOperation(const char *operation, ...)
//attaches callback 'cb' and data pointer 'data' to it
//upon return, puts the rank of the new item in *prank unless prank is NULL
menu = va_arg(ap, NSMenu*);
const char *name = va_arg(ap, const char*);
char *name = remove_ampersand(va_arg(ap, const char*));
Fl_Callback *cb = va_arg(ap, Fl_Callback*);
pter = va_arg(ap, void *);
int *prank = va_arg(ap, int*);
CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
free(name);
FLMenuItem *item = [FLMenuItem alloc];
[item initWithTitle:(NSString*)cfname action:@selector(doCallback:) keyEquivalent:@""];
[item putData:cb pter:pter];

Loading…
Cancel
Save