mirror of
https://github.com/fltk/fltk.git
synced 2026-05-29 04:26:27 +08:00
New patches appliet for Cocoa port. Fixed(?) STR 2232 workaround for X11 keyrepeat bbbbuuuuuuggggg.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6966 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -43,8 +43,9 @@ public:
|
|||||||
fl_sys_menu_bar = this;
|
fl_sys_menu_bar = this;
|
||||||
}
|
}
|
||||||
void menu(const Fl_Menu_Item *m);
|
void menu(const Fl_Menu_Item *m);
|
||||||
int add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0);
|
int add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0);
|
||||||
void remove(int n);
|
void remove(int n);
|
||||||
|
void replace(int rank, const char *name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
#ifndef MAC_OS_X_VERSION_MAX_ALLOWED
|
#ifndef MAC_OS_X_VERSION_MAX_ALLOWED
|
||||||
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
|
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
|
||||||
#endif
|
#endif
|
||||||
|
#endif //__APPLE_COCOA__
|
||||||
|
|
||||||
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
|
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
|
||||||
#if defined(__LP64__) && __LP64__
|
#if defined(__LP64__) && __LP64__
|
||||||
@@ -61,9 +62,8 @@ typedef double CGFloat;
|
|||||||
#else
|
#else
|
||||||
typedef float CGFloat;
|
typedef float CGFloat;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif //CGFLOAT_DEFINED
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Now make some fixes to the headers...
|
// Now make some fixes to the headers...
|
||||||
#undef check // Dunno where this comes from...
|
#undef check // Dunno where this comes from...
|
||||||
|
|||||||
+33
-19
@@ -65,7 +65,6 @@
|
|||||||
|
|
||||||
#ifdef __APPLE_COCOA__
|
#ifdef __APPLE_COCOA__
|
||||||
extern void *MACMenuOrItemOperation(const char *operation, ...);
|
extern void *MACMenuOrItemOperation(const char *operation, ...);
|
||||||
extern void *MACmainMenu(void);
|
|
||||||
#define MenuHandle void *
|
#define MenuHandle void *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -149,7 +148,7 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
|
|||||||
|
|
||||||
#ifdef __APPLE_COCOA__
|
#ifdef __APPLE_COCOA__
|
||||||
void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt);
|
void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt);
|
||||||
MACMenuOrItemOperation("setKeyEquivalent", menuItem, key );
|
MACMenuOrItemOperation("setKeyEquivalent", menuItem, m->shortcut_ & 0xff );
|
||||||
MACMenuOrItemOperation("setKeyEquivalentModifierMask", menuItem, m->shortcut_ );
|
MACMenuOrItemOperation("setKeyEquivalentModifierMask", menuItem, m->shortcut_ );
|
||||||
#else
|
#else
|
||||||
long macMod = kMenuNoCommandModifier;
|
long macMod = kMenuNoCommandModifier;
|
||||||
@@ -223,20 +222,21 @@ static void createSubMenu( void * mh, pFl_Menu_Item &mm )
|
|||||||
menuItem = MACMenuOrItemOperation("itemAtIndex", mh, cnt);
|
menuItem = MACMenuOrItemOperation("itemAtIndex", mh, cnt);
|
||||||
MACMenuOrItemOperation("setSubmenu", menuItem, submenu);
|
MACMenuOrItemOperation("setSubmenu", menuItem, submenu);
|
||||||
if ( mm->flags & FL_MENU_INACTIVE ) {
|
if ( mm->flags & FL_MENU_INACTIVE ) {
|
||||||
MACMenuOrItemOperation("setEnabled", menuItem, 0);
|
MACMenuOrItemOperation("setEnabled", menuItem, 0);
|
||||||
}
|
}
|
||||||
mm++;
|
mm++;
|
||||||
|
|
||||||
while ( mm->text )
|
while ( mm->text )
|
||||||
{
|
{
|
||||||
MACMenuOrItemOperation("addNewItem", submenu, mm, &miCnt);
|
int flRank = mm - fl_sys_menu_bar->Fl_Menu_::menu();
|
||||||
|
MACMenuOrItemOperation("addNewItem", submenu, flRank, &miCnt);
|
||||||
setMenuFlags( submenu, miCnt, mm );
|
setMenuFlags( submenu, miCnt, mm );
|
||||||
setMenuShortcut( submenu, miCnt, mm );
|
setMenuShortcut( submenu, miCnt, mm );
|
||||||
if ( mm->flags & FL_MENU_INACTIVE ) {
|
if ( mm->flags & FL_MENU_INACTIVE ) {
|
||||||
void *item = MACMenuOrItemOperation("itemAtIndex", submenu, miCnt);
|
void *item = MACMenuOrItemOperation("itemAtIndex", submenu, miCnt);
|
||||||
MACMenuOrItemOperation("setEnabled", item, 0);
|
MACMenuOrItemOperation("setEnabled", item, 0);
|
||||||
}
|
}
|
||||||
flags = mm->flags;
|
flags = mm->flags;
|
||||||
if ( mm->flags & FL_SUBMENU )
|
if ( mm->flags & FL_SUBMENU )
|
||||||
{
|
{
|
||||||
createSubMenu( submenu, mm );
|
createSubMenu( submenu, mm );
|
||||||
@@ -247,8 +247,8 @@ static void createSubMenu( void * mh, pFl_Menu_Item &mm )
|
|||||||
createSubMenu( submenu, smm );
|
createSubMenu( submenu, smm );
|
||||||
}
|
}
|
||||||
if ( flags & FL_MENU_DIVIDER ) {
|
if ( flags & FL_MENU_DIVIDER ) {
|
||||||
MACMenuOrItemOperation("addSeparatorItem", submenu);
|
MACMenuOrItemOperation("addSeparatorItem", submenu);
|
||||||
}
|
}
|
||||||
mm++;
|
mm++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,9 +259,9 @@ static void convertToMenuBar(const Fl_Menu_Item *mm)
|
|||||||
//ALL PREVIOUS SYSTEM MENUS, EXCEPT APPLICATION MENU, ARE REPLACED BY THE NEW DATA
|
//ALL PREVIOUS SYSTEM MENUS, EXCEPT APPLICATION MENU, ARE REPLACED BY THE NEW DATA
|
||||||
{
|
{
|
||||||
int count;//first, delete all existing system menus
|
int count;//first, delete all existing system menus
|
||||||
MACMenuOrItemOperation("numberOfItems", MACmainMenu(), &count);
|
MACMenuOrItemOperation("numberOfItems", fl_system_menu, &count);
|
||||||
for(int i = count - 1; i > 0; i--) {
|
for(int i = count - 1; i > 0; i--) {
|
||||||
MACMenuOrItemOperation("removeItem", MACmainMenu(), i);
|
MACMenuOrItemOperation("removeItem", fl_system_menu, i);
|
||||||
}
|
}
|
||||||
//now convert FLTK stuff into MacOS menus
|
//now convert FLTK stuff into MacOS menus
|
||||||
for (;;)
|
for (;;)
|
||||||
@@ -269,13 +269,14 @@ static void convertToMenuBar(const Fl_Menu_Item *mm)
|
|||||||
if ( !mm || !mm->text )
|
if ( !mm || !mm->text )
|
||||||
break;
|
break;
|
||||||
char visible = mm->visible() ? 1 : 0;
|
char visible = mm->visible() ? 1 : 0;
|
||||||
MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm, NULL);
|
int flRank = mm - fl_sys_menu_bar->Fl_Menu_::menu();
|
||||||
|
MACMenuOrItemOperation("addNewItem", fl_system_menu, flRank, NULL);
|
||||||
|
|
||||||
if ( mm->flags & FL_SUBMENU )
|
if ( mm->flags & FL_SUBMENU )
|
||||||
createSubMenu( MACmainMenu(), mm );
|
createSubMenu( fl_system_menu, mm );
|
||||||
else if ( mm->flags & FL_SUBMENU_POINTER ) {
|
else if ( mm->flags & FL_SUBMENU_POINTER ) {
|
||||||
const Fl_Menu_Item *smm = (Fl_Menu_Item*)mm->user_data_;
|
const Fl_Menu_Item *smm = (Fl_Menu_Item*)mm->user_data_;
|
||||||
createSubMenu( MACmainMenu(), smm );
|
createSubMenu( fl_system_menu, smm );
|
||||||
}
|
}
|
||||||
if ( visible ) {
|
if ( visible ) {
|
||||||
// InsertMenu( mh, 0 );
|
// InsertMenu( mh, 0 );
|
||||||
@@ -315,14 +316,27 @@ int Fl_Sys_Menu_Bar::add(const char* label, int shortcut, Fl_Callback *cb, void
|
|||||||
/**
|
/**
|
||||||
* remove an item from the system menu bar
|
* remove an item from the system menu bar
|
||||||
*
|
*
|
||||||
* @param n the rank of the item to remove
|
* @param rank the rank of the item to remove
|
||||||
*/
|
*/
|
||||||
void Fl_Sys_Menu_Bar::remove(int n)
|
void Fl_Sys_Menu_Bar::remove(int rank)
|
||||||
{
|
{
|
||||||
Fl_Menu_::remove(n);
|
Fl_Menu_::remove(rank);
|
||||||
convertToMenuBar(Fl_Menu_::menu());
|
convertToMenuBar(Fl_Menu_::menu());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rename an item from the system menu bar
|
||||||
|
*
|
||||||
|
* @param rank the rank of the item to rename
|
||||||
|
* @param name the new item name as a UTF8 string
|
||||||
|
*/
|
||||||
|
void Fl_Sys_Menu_Bar::replace(int rank, const char *name)
|
||||||
|
{
|
||||||
|
MACMenuOrItemOperation("renameItem", rank, name);
|
||||||
|
fl_sys_menu_bar->Fl_Menu_::replace(rank, name);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
|
static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
|
||||||
|
|||||||
+141
-111
@@ -54,6 +54,7 @@ extern "C" {
|
|||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
#include <FL/Fl_Tooltip.H>
|
#include <FL/Fl_Tooltip.H>
|
||||||
#include <FL/Fl_Sys_Menu_Bar.H>
|
#include <FL/Fl_Sys_Menu_Bar.H>
|
||||||
|
#include <FL/Fl_Input_.H>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "flstring.h"
|
#include "flstring.h"
|
||||||
@@ -1268,14 +1269,9 @@ extern "C" {
|
|||||||
- (void)windowDidMiniaturize:(NSNotification *)notif;
|
- (void)windowDidMiniaturize:(NSNotification *)notif;
|
||||||
- (void)windowWillClose:(NSNotification *)notif;
|
- (void)windowWillClose:(NSNotification *)notif;
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@implementation FLDelegate
|
@implementation FLDelegate
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
||||||
{
|
|
||||||
fl_system_menu = [NSApp mainMenu];
|
|
||||||
}
|
|
||||||
- (void)windowDidMove:(NSNotification *)notif
|
- (void)windowDidMove:(NSNotification *)notif
|
||||||
{
|
{
|
||||||
FLWindow *nsw = (FLWindow*)[notif object];
|
FLWindow *nsw = (FLWindow*)[notif object];
|
||||||
@@ -1882,14 +1878,14 @@ void Fl_X::make(Fl_Window* w)
|
|||||||
}
|
}
|
||||||
else // create a desktop window
|
else // create a desktop window
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *localPool;
|
NSAutoreleasePool *localPool;
|
||||||
localPool = [[NSAutoreleasePool alloc] init];
|
localPool = [[NSAutoreleasePool alloc] init];
|
||||||
Fl_Group::current(0);
|
Fl_Group::current(0);
|
||||||
fl_open_display();
|
fl_open_display();
|
||||||
NSInteger winlevel = NSNormalWindowLevel;
|
NSInteger winlevel = NSNormalWindowLevel;
|
||||||
NSUInteger winstyle;
|
NSUInteger winstyle;
|
||||||
if(w->border()) winstyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
if(w->border()) winstyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
||||||
else winstyle = NSBorderlessWindowMask;
|
else winstyle = NSBorderlessWindowMask;
|
||||||
int xp = w->x();
|
int xp = w->x();
|
||||||
int yp = w->y();
|
int yp = w->y();
|
||||||
int wp = w->w();
|
int wp = w->w();
|
||||||
@@ -2809,11 +2805,11 @@ static void createAppleMenu(void)
|
|||||||
[menuItem setSubmenu:appleMenu];
|
[menuItem setSubmenu:appleMenu];
|
||||||
mainmenu = [[NSMenu alloc] initWithTitle:@""];
|
mainmenu = [[NSMenu alloc] initWithTitle:@""];
|
||||||
[mainmenu addItem:menuItem];
|
[mainmenu addItem:menuItem];
|
||||||
if(MACsystemVersion < 0x1060) {
|
if(MACsystemVersion < 0x1060) {
|
||||||
// [NSApp setAppleMenu:appleMenu];
|
// [NSApp setAppleMenu:appleMenu];
|
||||||
// to avoid compiler warning raised by use of undocumented setAppleMenu :
|
// to avoid compiler warning raised by use of undocumented setAppleMenu :
|
||||||
[NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu];
|
[NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu];
|
||||||
}
|
}
|
||||||
[NSApp setServicesMenu:services];
|
[NSApp setServicesMenu:services];
|
||||||
[NSApp setMainMenu:mainmenu];
|
[NSApp setMainMenu:mainmenu];
|
||||||
CFRelease(nsappname);
|
CFRelease(nsappname);
|
||||||
@@ -2821,23 +2817,19 @@ static void createAppleMenu(void)
|
|||||||
[mainmenu release];
|
[mainmenu release];
|
||||||
[appleMenu release];
|
[appleMenu release];
|
||||||
[menuItem release];
|
[menuItem release];
|
||||||
|
fl_system_menu = [NSApp mainMenu];
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface FLMenuItem : NSMenuItem {
|
@interface FLMenuItem : NSMenuItem {
|
||||||
const Fl_Menu_Item *item;
|
|
||||||
}
|
}
|
||||||
- (void) setFlMenuItem:(const Fl_Menu_Item*)flItem;
|
|
||||||
- (void) doCallback:(id)unused;
|
- (void) doCallback:(id)unused;
|
||||||
- (void) directCallback:(id)unused;
|
- (void) directCallback:(id)unused;
|
||||||
- (Fl_Menu_Item*)getFlMenuItem;
|
|
||||||
@end
|
@end
|
||||||
@implementation FLMenuItem
|
@implementation FLMenuItem
|
||||||
- (void) setFlMenuItem:(const Fl_Menu_Item*)flItem
|
|
||||||
{
|
|
||||||
item = flItem;
|
|
||||||
}
|
|
||||||
- (void) doCallback:(id)unused
|
- (void) doCallback:(id)unused
|
||||||
{
|
{
|
||||||
|
int flRank = [self tag];
|
||||||
|
const Fl_Menu_Item *item = fl_sys_menu_bar->Fl_Menu_::menu() + flRank;
|
||||||
if(item) {
|
if(item) {
|
||||||
fl_sys_menu_bar->picked(item);
|
fl_sys_menu_bar->picked(item);
|
||||||
if ( item->flags & FL_MENU_TOGGLE ) {// update the menu toggle symbol
|
if ( item->flags & FL_MENU_TOGGLE ) {// update the menu toggle symbol
|
||||||
@@ -2847,62 +2839,45 @@ static void createAppleMenu(void)
|
|||||||
}
|
}
|
||||||
- (void) directCallback:(id)unused
|
- (void) directCallback:(id)unused
|
||||||
{
|
{
|
||||||
|
Fl_Menu_Item *item = (Fl_Menu_Item *)[(NSData*)[self representedObject] bytes];
|
||||||
if( item && item->callback() ) item->do_callback(NULL);
|
if( item && item->callback() ) item->do_callback(NULL);
|
||||||
}
|
}
|
||||||
- (const Fl_Menu_Item*)getFlMenuItem
|
|
||||||
{
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
void *MACmainMenu(void)
|
|
||||||
{
|
|
||||||
return (void *)[NSApp mainMenu];
|
|
||||||
}
|
|
||||||
|
|
||||||
void *MACcreateMenu(const char *name)
|
void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0)
|
||||||
// to create a new top-level menu in the apple menu bar
|
|
||||||
// returns the created menu (NSMenu*)
|
|
||||||
{
|
|
||||||
fl_open_display();
|
|
||||||
NSMenu *mymenu;
|
|
||||||
NSMenuItem *menuItem;
|
|
||||||
CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
|
|
||||||
mymenu = [[NSMenu alloc] initWithTitle:(NSString*)cfname];
|
|
||||||
CFRelease(cfname);
|
|
||||||
// Put menu into the menubar
|
|
||||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
|
||||||
[menuItem setSubmenu:mymenu];
|
|
||||||
[[NSApp mainMenu] addItem:menuItem];
|
|
||||||
[menuItem release];
|
|
||||||
[mymenu setAutoenablesItems:NO];
|
|
||||||
[mymenu release];
|
|
||||||
return (void *)mymenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fl_mac_set_about( const Fl_Menu_Item *flItem )
|
|
||||||
/**
|
/**
|
||||||
* Mac OS: attaches an Fl_Menu_Item to the "About myprog" item of the system application menu.
|
* Mac OS: attaches a callback to the "About myprog" item of the system application menu.
|
||||||
* \note Only the shortcut_, callback_ and user_data_ fields of the Fl_Menu_Item* \p flItem are used.
|
|
||||||
*
|
*
|
||||||
* \author Manolo Gouy
|
* \author Manolo Gouy
|
||||||
*
|
*
|
||||||
* \param[in] flItem is a const Fl_Menu_Item*
|
* \param[in] cb a callback that will be called by "About myprog" menu item
|
||||||
|
* \param[in] user_data a pointer transmitted as 2nd argument to the callback
|
||||||
|
* \param[in] shortcut optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a')
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
NSAutoreleasePool *localPool;
|
||||||
|
localPool = [[NSAutoreleasePool alloc] init];
|
||||||
fl_open_display();
|
fl_open_display();
|
||||||
|
Fl_Menu_Item aboutItem;
|
||||||
|
memset(&aboutItem, 0, sizeof(Fl_Menu_Item));
|
||||||
|
aboutItem.callback(cb);
|
||||||
|
aboutItem.user_data(user_data);
|
||||||
|
aboutItem.shortcut(shortcut);
|
||||||
CFStringRef cfname = CFStringCreateCopy(NULL, (CFStringRef)[[appleMenu itemAtIndex:0] title]);
|
CFStringRef cfname = CFStringCreateCopy(NULL, (CFStringRef)[[appleMenu itemAtIndex:0] title]);
|
||||||
[appleMenu removeItemAtIndex:0];
|
[appleMenu removeItemAtIndex:0];
|
||||||
FLMenuItem *item = [[FLMenuItem alloc] autorelease];
|
FLMenuItem *item = [[FLMenuItem alloc] autorelease];
|
||||||
[item initWithTitle:(NSString*)cfname action:@selector(directCallback:) keyEquivalent:@""];
|
[item initWithTitle:(NSString*)cfname action:@selector(directCallback:) keyEquivalent:@""];
|
||||||
if(flItem->shortcut()) {
|
if(aboutItem.shortcut()) {
|
||||||
MACMenuOrItemOperation("setKeyEquivalent", item, flItem->shortcut() & 0xff);
|
MACMenuOrItemOperation("setKeyEquivalent", item, aboutItem.shortcut() & 0xff);
|
||||||
MACMenuOrItemOperation("setKeyEquivalentModifierMask", item, flItem->shortcut() );
|
MACMenuOrItemOperation("setKeyEquivalentModifierMask", item, aboutItem.shortcut() );
|
||||||
}
|
}
|
||||||
[item setFlMenuItem:flItem];
|
NSData *pointer = [NSData dataWithBytes:&aboutItem length:sizeof(Fl_Menu_Item)];
|
||||||
|
[item setRepresentedObject:pointer];
|
||||||
[appleMenu insertItem:item atIndex:0];
|
[appleMenu insertItem:item atIndex:0];
|
||||||
CFRelease(cfname);
|
CFRelease(cfname);
|
||||||
[item setTarget:item];
|
[item setTarget:item];
|
||||||
|
[localPool release];
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *remove_ampersand(const char *s)
|
static char *remove_ampersand(const char *s)
|
||||||
@@ -2929,6 +2904,8 @@ void *MACMenuOrItemOperation(const char *operation, ...)
|
|||||||
/* these operations apply to menus, submenus, or menu items
|
/* these operations apply to menus, submenus, or menu items
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
NSAutoreleasePool *localPool;
|
||||||
|
localPool = [[NSAutoreleasePool alloc] init];
|
||||||
NSMenu *menu;
|
NSMenu *menu;
|
||||||
NSMenuItem *item;
|
NSMenuItem *item;
|
||||||
int value;
|
int value;
|
||||||
@@ -2945,7 +2922,8 @@ void *MACMenuOrItemOperation(const char *operation, ...)
|
|||||||
else if(strcmp(operation, "setKeyEquivalent") == 0) {//arguments: NSMenuItem*, int
|
else if(strcmp(operation, "setKeyEquivalent") == 0) {//arguments: NSMenuItem*, int
|
||||||
item = va_arg(ap, NSMenuItem*);
|
item = va_arg(ap, NSMenuItem*);
|
||||||
value = va_arg(ap, int);
|
value = va_arg(ap, int);
|
||||||
NSString *equiv = [[NSString alloc] initWithBytes:&value length:1 encoding:NSASCIIStringEncoding];
|
char key = value;
|
||||||
|
NSString *equiv = [[NSString alloc] initWithBytes:&key length:1 encoding:NSASCIIStringEncoding];
|
||||||
[item setKeyEquivalent:equiv];
|
[item setKeyEquivalent:equiv];
|
||||||
[equiv release];
|
[equiv release];
|
||||||
}
|
}
|
||||||
@@ -2973,7 +2951,6 @@ void *MACMenuOrItemOperation(const char *operation, ...)
|
|||||||
CFRelease(title);
|
CFRelease(title);
|
||||||
[menu setAutoenablesItems:NO];
|
[menu setAutoenablesItems:NO];
|
||||||
retval = (void *)menu;
|
retval = (void *)menu;
|
||||||
[menu autorelease];
|
|
||||||
}
|
}
|
||||||
else if(strcmp(operation, "numberOfItems") == 0) {//arguments: NSMenu *menu, int *pcount
|
else if(strcmp(operation, "numberOfItems") == 0) {//arguments: NSMenu *menu, int *pcount
|
||||||
//upon return, *pcount is set to menu's item count
|
//upon return, *pcount is set to menu's item count
|
||||||
@@ -2986,6 +2963,7 @@ void *MACMenuOrItemOperation(const char *operation, ...)
|
|||||||
item = va_arg(ap, NSMenuItem*);
|
item = va_arg(ap, NSMenuItem*);
|
||||||
menu = va_arg(ap, NSMenu*);
|
menu = va_arg(ap, NSMenu*);
|
||||||
[item setSubmenu:menu];
|
[item setSubmenu:menu];
|
||||||
|
[menu release];
|
||||||
}
|
}
|
||||||
else if(strcmp(operation, "setEnabled") == 0) {//arguments: NSMenuItem*, int
|
else if(strcmp(operation, "setEnabled") == 0) {//arguments: NSMenuItem*, int
|
||||||
item = va_arg(ap, NSMenuItem*);
|
item = va_arg(ap, NSMenuItem*);
|
||||||
@@ -3009,32 +2987,49 @@ void *MACMenuOrItemOperation(const char *operation, ...)
|
|||||||
value = va_arg(ap, int);
|
value = va_arg(ap, int);
|
||||||
[menu removeItem:[menu itemAtIndex:value]];
|
[menu removeItem:[menu itemAtIndex:value]];
|
||||||
}
|
}
|
||||||
else if(strcmp(operation, "getFlMenuItem") == 0) {//arguments: NSMenu*, int. Returns the item's Fl_Menu_Item*
|
else if(strcmp(operation, "addNewItem") == 0) {//arguments: NSMenu *menu, int flrank, int *prank
|
||||||
menu = va_arg(ap, NSMenu*);
|
|
||||||
value = va_arg(ap, int);
|
|
||||||
retval = [(FLMenuItem *)[menu itemAtIndex:value] getFlMenuItem];
|
|
||||||
}
|
|
||||||
else if(strcmp(operation, "addNewItem") == 0) {
|
|
||||||
//arguments: NSMenu *menu, const Fl_Menu_Item* flItem, int *prank
|
|
||||||
//creates a new menu item at the end of 'menu'
|
//creates a new menu item at the end of 'menu'
|
||||||
//attaches the Fl_Menu_Item *flItem to it
|
//attaches the item of rank flrank (counted in Fl_Menu_) of fl_sys_menu_bar to it
|
||||||
//upon return, puts the rank of the new item in *prank unless prank is NULL
|
//upon return, puts the rank (counted in NSMenu) of the new item in *prank unless prank is NULL
|
||||||
menu = va_arg(ap, NSMenu*);
|
menu = va_arg(ap, NSMenu*);
|
||||||
const Fl_Menu_Item *flItem = va_arg(ap, const Fl_Menu_Item*);
|
int flRank = va_arg(ap, int);
|
||||||
char *name = remove_ampersand(flItem->label());
|
char *name = remove_ampersand( (fl_sys_menu_bar->Fl_Menu_::menu() + flRank)->label());
|
||||||
int *prank = va_arg(ap, int*);
|
int *prank = va_arg(ap, int*);
|
||||||
CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
|
CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
|
||||||
free(name);
|
free(name);
|
||||||
FLMenuItem *item = [FLMenuItem alloc];
|
FLMenuItem *item = [FLMenuItem alloc];
|
||||||
[item initWithTitle:(NSString*)cfname action:@selector(doCallback:) keyEquivalent:@""];
|
[item initWithTitle:(NSString*)cfname action:@selector(doCallback:) keyEquivalent:@""];
|
||||||
[item setFlMenuItem:flItem];
|
[item setTag:flRank];
|
||||||
[menu addItem:item];
|
[menu addItem:item];
|
||||||
CFRelease(cfname);
|
CFRelease(cfname);
|
||||||
[item setTarget:item];
|
[item setTarget:item];
|
||||||
if(prank != NULL) *prank = [menu indexOfItem:item];
|
if(prank != NULL) *prank = [menu indexOfItem:item];
|
||||||
[item release];
|
[item release];
|
||||||
|
}
|
||||||
|
else if(strcmp(operation, "renameItem") == 0) {//arguments: int rank, const char *newname
|
||||||
|
//renames the system menu item numbered rank in fl_sys_menu_bar->menu()
|
||||||
|
int rank = va_arg(ap, int);
|
||||||
|
char *newname = remove_ampersand( va_arg(ap, const char *) );
|
||||||
|
int countmenus = [(NSMenu*)fl_system_menu numberOfItems];
|
||||||
|
bool found = NO;
|
||||||
|
NSMenuItem *macitem;
|
||||||
|
for(int i = 1; (!found) && i < countmenus; i++) {
|
||||||
|
NSMenuItem *item = [(NSMenu*)fl_system_menu itemAtIndex:i];
|
||||||
|
NSMenu *submenu = [item submenu];
|
||||||
|
if(submenu == nil) continue;
|
||||||
|
int countitems = [submenu numberOfItems];
|
||||||
|
for(int j = 0; j < countitems; j++) {
|
||||||
|
macitem = [submenu itemAtIndex:j];
|
||||||
|
if([macitem tag] == rank) { found = YES; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(found) {
|
||||||
|
[macitem setTitle:[[[NSString alloc] initWithUTF8String:newname] autorelease]];
|
||||||
|
}
|
||||||
|
free(newname);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
[localPool release];
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3043,6 +3038,69 @@ void MACsetkeywindow(void *nsw)
|
|||||||
[(NSWindow*)nsw makeKeyAndOrderFront:nil];
|
[(NSWindow*)nsw makeKeyAndOrderFront:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NSImage *imageFromText(const char *text, int *pwidth, int *pheight)
|
||||||
|
{
|
||||||
|
const char *p, *q;
|
||||||
|
int width = 0, height, w2, ltext = strlen(text);
|
||||||
|
fl_font(FL_HELVETICA, 10);
|
||||||
|
p = text;
|
||||||
|
int nl = 0;
|
||||||
|
while((q=strchr(p, '\n')) != NULL) {
|
||||||
|
nl++;
|
||||||
|
w2 = fl_width(p, q - p);
|
||||||
|
if(w2 > width) width = w2;
|
||||||
|
p = q + 1;
|
||||||
|
}
|
||||||
|
if(text[ ltext - 1] != '\n') {
|
||||||
|
nl++;
|
||||||
|
w2 = fl_width(p);
|
||||||
|
if(w2 > width) width = w2;
|
||||||
|
}
|
||||||
|
height = nl * fl_height() + 3;
|
||||||
|
width += 6;
|
||||||
|
Fl_Offscreen off = fl_create_offscreen_with_alpha(width, height);
|
||||||
|
fl_begin_offscreen(off);
|
||||||
|
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
|
||||||
|
fl_rectf(0,0,width,height);
|
||||||
|
fl_color(FL_BLACK);
|
||||||
|
p = text;
|
||||||
|
int y = fl_height();
|
||||||
|
while(TRUE) {
|
||||||
|
q = strchr(p, '\n');
|
||||||
|
if(q) fl_draw(p, q - p, 3, y);
|
||||||
|
else {
|
||||||
|
fl_draw(p, 3, y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
y += fl_height();
|
||||||
|
p = q + 1;
|
||||||
|
}
|
||||||
|
fl_end_offscreen();
|
||||||
|
NSImage* image = CGBitmapContextToNSImage( (CGContextRef)off );
|
||||||
|
fl_delete_offscreen( off );
|
||||||
|
*pwidth = width;
|
||||||
|
*pheight = height;
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NSImage *defaultDragImage(int *pwidth, int *pheight)
|
||||||
|
{
|
||||||
|
const int width = 16, height = 16;
|
||||||
|
Fl_Offscreen off = fl_create_offscreen_with_alpha(width, height);
|
||||||
|
fl_begin_offscreen(off);
|
||||||
|
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
|
||||||
|
fl_rectf(0,0,width,height);
|
||||||
|
CGContextSetRGBStrokeColor( (CGContextRef)off, 0,0,0,0.6);
|
||||||
|
fl_rect(0,0,width,height);
|
||||||
|
fl_rect(2,2,width-4,height-4);
|
||||||
|
fl_end_offscreen();
|
||||||
|
NSImage* image = CGBitmapContextToNSImage( (CGContextRef)off );
|
||||||
|
fl_delete_offscreen( off );
|
||||||
|
*pwidth = width;
|
||||||
|
*pheight = height;
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
int MACpreparedrag(void)
|
int MACpreparedrag(void)
|
||||||
{
|
{
|
||||||
CFDataRef text = CFDataCreate(kCFAllocatorDefault, (UInt8*)fl_selection_buffer[0], fl_selection_length[0]);
|
CFDataRef text = CFDataCreate(kCFAllocatorDefault, (UInt8*)fl_selection_buffer[0], fl_selection_length[0]);
|
||||||
@@ -3055,49 +3113,21 @@ int MACpreparedrag(void)
|
|||||||
CFRelease(text);
|
CFRelease(text);
|
||||||
Fl_Widget *w = Fl::pushed();
|
Fl_Widget *w = Fl::pushed();
|
||||||
Fl_Window *win = w->window();
|
Fl_Window *win = w->window();
|
||||||
while(win->window()) win = win->window();
|
if(win == NULL) { win = (Fl_Window*)w; }
|
||||||
|
else { while(win->window()) win = win->window(); }
|
||||||
NSView *myview = [(NSWindow*)Fl_X::i(win)->xid contentView];
|
NSView *myview = [(NSWindow*)Fl_X::i(win)->xid contentView];
|
||||||
NSEvent *theEvent = [NSApp currentEvent];
|
NSEvent *theEvent = [NSApp currentEvent];
|
||||||
|
|
||||||
char *p, *q;
|
int width, height;
|
||||||
int width = 0, height, w2;
|
NSImage *image;
|
||||||
fl_font(FL_HELVETICA, 10);
|
if( dynamic_cast<Fl_Input_*>(w) != NULL) {
|
||||||
fl_selection_buffer[0][ fl_selection_length[0] ] = 0;
|
fl_selection_buffer[0][ fl_selection_length[0] ] = 0;
|
||||||
p = fl_selection_buffer[0];
|
image = imageFromText(fl_selection_buffer[0], &width, &height);
|
||||||
int nl = 0;
|
}
|
||||||
while((q=strchr(p, '\n')) != NULL) {
|
else {
|
||||||
nl++;
|
image = defaultDragImage(&width, &height);
|
||||||
w2 = fl_width(p, q - p);
|
}
|
||||||
if(w2 > width) width = w2;
|
|
||||||
p = q + 1;
|
|
||||||
}
|
|
||||||
if(fl_selection_buffer[0][ fl_selection_length[0] - 1] != '\n') {
|
|
||||||
nl++;
|
|
||||||
w2 = fl_width(p);
|
|
||||||
if(w2 > width) width = w2;
|
|
||||||
}
|
|
||||||
height = nl * fl_height() + 3;
|
|
||||||
width += 6;
|
|
||||||
Fl_Offscreen off = fl_create_offscreen_with_alpha(width, height);
|
|
||||||
fl_begin_offscreen(off);
|
|
||||||
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
|
|
||||||
fl_rectf(0,0,width,height);
|
|
||||||
fl_color(FL_BLACK);
|
|
||||||
p = fl_selection_buffer[0];
|
|
||||||
int y = fl_height();
|
|
||||||
while(TRUE) {
|
|
||||||
q = strchr(p, '\n');
|
|
||||||
if(q) fl_draw(p, q - p, 3, y);
|
|
||||||
else {
|
|
||||||
fl_draw(p, 3, y);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
y += fl_height();
|
|
||||||
p = q + 1;
|
|
||||||
}
|
|
||||||
fl_end_offscreen();
|
|
||||||
NSImage* image = CGBitmapContextToNSImage( (CGContextRef)off );
|
|
||||||
fl_delete_offscreen( off );
|
|
||||||
static NSSize offset={0,0};
|
static NSSize offset={0,0};
|
||||||
NSPoint pt = [theEvent locationInWindow];
|
NSPoint pt = [theEvent locationInWindow];
|
||||||
pt.x -= width/2;
|
pt.x -= width/2;
|
||||||
|
|||||||
+28
-13
@@ -780,15 +780,6 @@ static inline void checkdouble() {
|
|||||||
|
|
||||||
static Fl_Window* resize_bug_fix;
|
static Fl_Window* resize_bug_fix;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
static Bool fake_keyup_test(Display*, XEvent* event, char* previous) {
|
|
||||||
return
|
|
||||||
event->type == KeyPress &&
|
|
||||||
event->xkey.keycode == ((XKeyEvent*)previous)->keycode &&
|
|
||||||
event->xkey.time == ((XKeyEvent*)previous)->time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static char unknown[] = "<unknown>";
|
static char unknown[] = "<unknown>";
|
||||||
@@ -1173,11 +1164,35 @@ int fl_handle(const XEvent& thisevent)
|
|||||||
// down, probably due to some back compatibility problem. Fortunately
|
// down, probably due to some back compatibility problem. Fortunately
|
||||||
// we can detect this because the repeating KeyPress event is in
|
// we can detect this because the repeating KeyPress event is in
|
||||||
// the queue, get it and execute it instead:
|
// the queue, get it and execute it instead:
|
||||||
XEvent temp;
|
|
||||||
if (XCheckIfEvent(fl_display,&temp,fake_keyup_test,(char*)(&xevent))){
|
// Bool XkbSetDetectableAutorepeat ( display, detectable, supported_rtrn )
|
||||||
xevent = temp;
|
// Display * display ;
|
||||||
goto KEYPRESS;
|
// Bool detectable ;
|
||||||
|
// Bool * supported_rtrn ;
|
||||||
|
// ...would be the easy way to corrct this isuue. Unfortunatly, this call is also
|
||||||
|
// broken on many Unix distros including Ubuntu and Solaris (as of Dec 2009)
|
||||||
|
|
||||||
|
// Bogus KeyUp events are generated by repeated KeyDown events. One
|
||||||
|
// neccessary condition is an identical key event pending right after
|
||||||
|
// the bogus KeyUp.
|
||||||
|
// The new code introduced Dec 2009 differs in that it only check the very
|
||||||
|
// next event in the queue, not the entire queue of events.
|
||||||
|
// This function wrongly detects a repeat key if a software keyboard
|
||||||
|
// sends a burst of events containing two consecutive equal keys. However,
|
||||||
|
// in every non-gaming situation, this is no problem because both KeyPress
|
||||||
|
// events will cause the expected behavior.
|
||||||
|
XEvent peekevent;
|
||||||
|
if (XPending(fl_display)) {
|
||||||
|
XPeekEvent(fl_display, &peekevent);
|
||||||
|
if ( (peekevent.type == KeyPress) // must be a KeyPress event
|
||||||
|
&& (peekevent.xkey.keycode == xevent.xkey.keycode) // must be the same key
|
||||||
|
&& (peekevent.xkey.time == xevent.xkey.time) // must be sent at the exact same time
|
||||||
|
) {
|
||||||
|
XNextEvent(fl_display, &xevent);
|
||||||
|
goto KEYPRESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event = FL_KEYUP;
|
event = FL_KEYUP;
|
||||||
fl_key_vector[keycode/8] &= ~(1 << (keycode%8));
|
fl_key_vector[keycode/8] &= ~(1 << (keycode%8));
|
||||||
// keyup events just get the unshifted keysym:
|
// keyup events just get the unshifted keysym:
|
||||||
|
|||||||
+3
-2
@@ -476,7 +476,7 @@ include makedepend
|
|||||||
# These dependencies aren't part of the makedepend file since
|
# These dependencies aren't part of the makedepend file since
|
||||||
# they are part of the WIN32 and MacOS code base...
|
# they are part of the WIN32 and MacOS code base...
|
||||||
Fl_get_key.o: Fl_get_key_mac.cxx Fl_get_key_win32.cxx
|
Fl_get_key.o: Fl_get_key_mac.cxx Fl_get_key_win32.cxx
|
||||||
Fl.o: Fl_mac.cxx Fl_win32.cxx
|
Fl.o: Fl_mac.cxx Fl_win32.cxx Fl_cocoa.mm
|
||||||
fl_color.o: fl_color_mac.cxx fl_color_win32.cxx
|
fl_color.o: fl_color_mac.cxx fl_color_win32.cxx
|
||||||
fl_dnd.o: fl_dnd_mac.cxx fl_dnd_win32.cxx fl_dnd_x.cxx
|
fl_dnd.o: fl_dnd_mac.cxx fl_dnd_win32.cxx fl_dnd_x.cxx
|
||||||
fl_draw_image.o: fl_draw_image_mac.cxx fl_draw_image_win32.cxx
|
fl_draw_image.o: fl_draw_image_mac.cxx fl_draw_image_win32.cxx
|
||||||
@@ -492,7 +492,7 @@ Fl_Bitmap.o: ../FL/mac.H ../FL/win32.H
|
|||||||
fl_color.o: ../FL/mac.H ../FL/win32.H
|
fl_color.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_cursor.o: ../FL/mac.H ../FL/win32.H
|
fl_cursor.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_dnd.o: ../FL/mac.H ../FL/win32.H
|
fl_dnd.o: ../FL/mac.H ../FL/win32.H
|
||||||
Fl.o: ../FL/mac.H ../FL/win32.H Fl_win32.cxx Fl_mac.cxx
|
Fl.o: ../FL/mac.H ../FL/win32.H Fl_win32.cxx Fl_mac.cxx Fl_cocoa.mm
|
||||||
Fl_Double_Window.o: ../FL/mac.H ../FL/win32.H
|
Fl_Double_Window.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_draw_image.o: ../FL/mac.H ../FL/win32.H
|
fl_draw_image.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_draw_image_mac.o: ../FL/mac.H ../FL/win32.H
|
fl_draw_image_mac.o: ../FL/mac.H ../FL/win32.H
|
||||||
@@ -511,6 +511,7 @@ Fl_grab.o: ../FL/mac.H ../FL/win32.H
|
|||||||
Fl_Image.o: ../FL/mac.H ../FL/win32.H
|
Fl_Image.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_line_style.o: ../FL/mac.H ../FL/win32.H
|
fl_line_style.o: ../FL/mac.H ../FL/win32.H
|
||||||
Fl_mac.o: ../FL/mac.H ../FL/win32.H
|
Fl_mac.o: ../FL/mac.H ../FL/win32.H
|
||||||
|
Fl_cocoa.o: ../FL/mac.H ../FL/win32.H
|
||||||
Fl_Menu_Window.o: ../FL/mac.H ../FL/win32.H
|
Fl_Menu_Window.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_overlay.o: ../FL/mac.H ../FL/win32.H
|
fl_overlay.o: ../FL/mac.H ../FL/win32.H
|
||||||
fl_overlay_visual.o: ../FL/mac.H ../FL/win32.H
|
fl_overlay_visual.o: ../FL/mac.H ../FL/win32.H
|
||||||
|
|||||||
+36
-62
@@ -428,7 +428,7 @@ CGColorRef flcolortocgcolor(Fl_Color i)
|
|||||||
g = c>>16;
|
g = c>>16;
|
||||||
b = c>> 8;
|
b = c>> 8;
|
||||||
}
|
}
|
||||||
CGFloat components[4] = {r/255.0f, g/255.0f, b/255.0f, 1.};
|
CGFloat components[4] = {r/255.0f, g/255.0f, b/255.0f, 1.};
|
||||||
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||||
return CGColorCreate(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), components);
|
return CGColorCreate(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), components);
|
||||||
#else
|
#else
|
||||||
@@ -444,35 +444,35 @@ void fl_draw(const char *str, int n, float x, float y) {
|
|||||||
// convert to UTF-16 first
|
// convert to UTF-16 first
|
||||||
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
|
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
|
||||||
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
if(CTFontCreateWithName != NULL) {
|
if(CTFontCreateWithName != NULL) {
|
||||||
CFStringRef keys[2];
|
CFStringRef keys[2];
|
||||||
CFTypeRef values[2];
|
CFTypeRef values[2];
|
||||||
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)uniStr, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
|
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)uniStr, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
|
||||||
CGColorRef color = flcolortocgcolor(fl_color());
|
CGColorRef color = flcolortocgcolor(fl_color());
|
||||||
keys[0] = kCTFontAttributeName;
|
keys[0] = kCTFontAttributeName;
|
||||||
keys[1] = kCTForegroundColorAttributeName;
|
keys[1] = kCTForegroundColorAttributeName;
|
||||||
values[0] = fl_fontsize->fontref;
|
values[0] = fl_fontsize->fontref;
|
||||||
values[1] = color;
|
values[1] = color;
|
||||||
CFDictionaryRef attributes = CFDictionaryCreate(kCFAllocatorDefault,
|
CFDictionaryRef attributes = CFDictionaryCreate(kCFAllocatorDefault,
|
||||||
(const void**)&keys,
|
(const void**)&keys,
|
||||||
(const void**)&values,
|
(const void**)&values,
|
||||||
2,
|
2,
|
||||||
&kCFTypeDictionaryKeyCallBacks,
|
&kCFTypeDictionaryKeyCallBacks,
|
||||||
&kCFTypeDictionaryValueCallBacks);
|
&kCFTypeDictionaryValueCallBacks);
|
||||||
CFAttributedStringRef mastr = CFAttributedStringCreate(kCFAllocatorDefault, str16, attributes);
|
CFAttributedStringRef mastr = CFAttributedStringCreate(kCFAllocatorDefault, str16, attributes);
|
||||||
CFRelease(str16);
|
CFRelease(str16);
|
||||||
CFRelease(attributes);
|
CFRelease(attributes);
|
||||||
CFRelease(color);
|
CFRelease(color);
|
||||||
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
|
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
|
||||||
CFRelease(mastr);
|
CFRelease(mastr);
|
||||||
CGContextSetTextMatrix(fl_gc, font_mx);
|
CGContextSetTextMatrix(fl_gc, font_mx);
|
||||||
CGContextSetTextPosition(fl_gc, x, y);
|
CGContextSetTextPosition(fl_gc, x, y);
|
||||||
CGContextSetShouldAntialias(fl_gc, true);
|
CGContextSetShouldAntialias(fl_gc, true);
|
||||||
CTLineDraw(ctline, fl_gc);
|
CTLineDraw(ctline, fl_gc);
|
||||||
CGContextSetShouldAntialias(fl_gc, false);
|
CGContextSetShouldAntialias(fl_gc, false);
|
||||||
CFRelease(ctline);
|
CFRelease(ctline);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#endif
|
#endif
|
||||||
#if ! __LP64__
|
#if ! __LP64__
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
@@ -499,19 +499,15 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fl_draw(int angle, const char *str, int n, int x, int y) {
|
void fl_draw(int angle, const char *str, int n, int x, int y) {
|
||||||
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
#if defined(__APPLE_COCOA__)
|
||||||
if(CTFontCreateWithName != NULL) {
|
|
||||||
CGContextSaveGState(fl_gc);
|
CGContextSaveGState(fl_gc);
|
||||||
CGContextTranslateCTM(fl_gc, x, y);
|
CGContextTranslateCTM(fl_gc, x, y);
|
||||||
CGContextRotateCTM(fl_gc, - angle*(M_PI/180) );
|
CGContextRotateCTM(fl_gc, - angle*(M_PI/180) );
|
||||||
fl_draw(str, n, (float)0., (float)0.);
|
fl_draw(str, n, (float)0., (float)0.);
|
||||||
CGContextRestoreGState(fl_gc);
|
CGContextRestoreGState(fl_gc);
|
||||||
}
|
#else
|
||||||
else {
|
OSStatus err;
|
||||||
#endif
|
// convert to UTF-16 first
|
||||||
#if ! __LP64__
|
|
||||||
OSStatus err;
|
|
||||||
// convert to UTF-16 first
|
|
||||||
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
|
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
|
||||||
|
|
||||||
// avoid a crash if no font has been selected by user yet !
|
// avoid a crash if no font has been selected by user yet !
|
||||||
@@ -526,31 +522,18 @@ else {
|
|||||||
ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr);
|
ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr);
|
||||||
|
|
||||||
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
|
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
|
||||||
#if defined(__APPLE_COCOA__)
|
|
||||||
CGContextSetShouldAntialias(fl_gc, true);
|
|
||||||
#endif
|
|
||||||
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y));
|
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y));
|
||||||
#if defined(__APPLE_COCOA__)
|
|
||||||
CGContextSetShouldAntialias(fl_gc, false);
|
|
||||||
#endif
|
|
||||||
//restore layout baseline
|
//restore layout baseline
|
||||||
ang = IntToFixed(0);
|
ang = IntToFixed(0);
|
||||||
ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr);
|
ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr);
|
||||||
#endif
|
#endif
|
||||||
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fl_rtl_draw(const char* c, int n, int x, int y) {
|
void fl_rtl_draw(const char* c, int n, int x, int y) {
|
||||||
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
#if defined(__APPLE_COCOA__)
|
||||||
if(CTFontCreateWithName != NULL) {
|
|
||||||
fl_draw(c, n, x - fl_width(c, n), y); //to check;
|
fl_draw(c, n, x - fl_width(c, n), y); //to check;
|
||||||
}
|
#else
|
||||||
else {
|
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text...
|
||||||
#endif
|
|
||||||
#if ! __LP64__
|
|
||||||
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text...
|
|
||||||
double offs = fl_width(c, n);
|
double offs = fl_width(c, n);
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
// convert to UTF-16 first
|
// convert to UTF-16 first
|
||||||
@@ -565,16 +548,7 @@ else {
|
|||||||
ATSUSetLayoutControls (layout, 2, iTag, iSize, aAttr );
|
ATSUSetLayoutControls (layout, 2, iTag, iSize, aAttr );
|
||||||
|
|
||||||
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
|
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
|
||||||
#if defined(__APPLE_COCOA__)
|
|
||||||
CGContextSetShouldAntialias(fl_gc, true);
|
|
||||||
#endif
|
|
||||||
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y));
|
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y));
|
||||||
#if defined(__APPLE_COCOA__)
|
|
||||||
CGContextSetShouldAntialias(fl_gc, false);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user