Commit 15034960 authored by Adrian Robert's avatar Adrian Robert
Browse files

clear warnings and clean up NS port

parent 27ec92c9
2008-08-01 Adrian Robert <Adrian.B.Robert@gmail.com>
Warning clearing and clean-up in NS port.
* keyboard.h (xmalloc_widget_value, digest_single_submenu): Add
prototypes.
* nsgui.h (FACE_DEFAULT): Remove, unused.
(XGCValues): Change colors to unsigned long.
* nsterm.h (EmacsApp): Add declaration of all methods implemented in
nsterm.m.
(EmacsMenu -addItemWithWidgetValue:): Change to use NSMenuItem class.
(ns_list_fonts): Remove, unused.
(ns_font_to_xlfd, ns_fontname_to_xlfd): Drop prototypes.
* nsfns.m (interpret_services_menu): Use NSMenuItem class.
* nsfont.m (nsfont_open): Fix cast error in glyphs,metrics alloc.
(nsfont_draw): Compare face colors to 0, not nil.
* nsmenu.m (struct widget_value): Drop unneeded declaration.
(EmacsMenu -addItemWithWidgetValue:, -fillWithWidgetValue:)
(-addSubmenuWithTitle:): Use NSMenuItem class.
(ns_popup_menu): Use NO, not NULL, for enabled setting.
* nsterm.m (ns_draw_glyph_string): Don't compare font to ~0.
(ns_clip_to_row): Make gc arg a BOOL.
(ns_draw_fringe_bitmap, ns_draw_window_cursor): Use YES, NO in
ns_clip_to_row() call.
(ns_draw_glyph_string): Drop face comparison to ~0 (no longer
used). Cast FRAME_FONT assignments.
(ns_read_socket): Cast call to EmacsApp-fulfillService:withArg:.
(ns_string_to_lispmod): Change arg to const char.
(ns_term_init): Use NSMenuItem class.
(EmacsApp -openFile:): Move to different section of file.
(EmacsApp -application:openFiles:): Don't return a value, call
-replyToOpenOrPrint:.
(EmacsView -keyDown:): Fix up cast.
(EmacsView -converstationIdentifier): Use NSInteger instead of long.
(EmacsView -menuDown:): Cast tag in call to
find_and_call_menu_selection().
(ns_list_fonts): Remove, unused.
(ns_font_to_xlfd): Make static. Cast result of UTF8String.
(ns_fontname_to_xlfd): Make static.
* w32menu.c (xmalloc_widget_value, digest_single_submenu): Remove
prototypes (now in keyboard.h).
(next_menubar_widget_id): Remove, unused.
* xmenu.c (xmalloc_widget_value, digest_single_submenu): Remove
prototypes (now in keyboard.h).
* xfaces.c (ns_list_fonts, w32_list_fonts): Remove, unused.
2008-08-01 Dan Nicolaescu <dann@ics.uci.edu> 2008-08-01 Dan Nicolaescu <dann@ics.uci.edu>
* systty.h: Fix previous change that removed BSD_TERMIOS. Add * systty.h: Fix previous change that removed BSD_TERMIOS. Add
......
...@@ -367,6 +367,11 @@ typedef struct _widget_value ...@@ -367,6 +367,11 @@ typedef struct _widget_value
} widget_value; } widget_value;
#endif #endif
#if defined (HAVE_NS) || defined (HAVE_NTGUI) || defined (USE_X_TOOLKIT) || defined (USE_GTK)
extern widget_value *xmalloc_widget_value P_ ((void));
extern widget_value *digest_single_submenu P_ ((int, int, int));
#endif
/* Macros for dealing with lispy events. */ /* Macros for dealing with lispy events. */
......
...@@ -280,7 +280,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side ...@@ -280,7 +280,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
{ {
int i, count; int i, count;
id<NSMenuItem> item; NSMenuItem *item;
const char *name; const char *name;
Lisp_Object nameStr; Lisp_Object nameStr;
unsigned short key; unsigned short key;
......
...@@ -597,9 +597,9 @@ avoid creating multiple struct font objects (with metrics cache, etc.) ...@@ -597,9 +597,9 @@ avoid creating multiple struct font objects (with metrics cache, etc.)
} }
#endif #endif
font_info->glyphs = (unsigned short *) font_info->glyphs = (unsigned short **)
xmalloc (0x100 * sizeof (unsigned short *)); xmalloc (0x100 * sizeof (unsigned short *));
font_info->metrics = (struct font_metrics *) font_info->metrics = (struct font_metrics **)
xmalloc (0x100 * sizeof (struct font_metrics *)); xmalloc (0x100 * sizeof (struct font_metrics *));
if (!font_info->glyphs || !font_info->metrics) if (!font_info->glyphs || !font_info->metrics)
return Qnil; return Qnil;
...@@ -984,7 +984,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */ ...@@ -984,7 +984,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
/* set up for character rendering */ /* set up for character rendering */
r.origin.y += font->voffset + (s->height - font->height)/2; r.origin.y += font->voffset + (s->height - font->height)/2;
col = (NS_FACE_FOREGROUND (face) != nil col = (NS_FACE_FOREGROUND (face) != 0
? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f) ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f)
: FRAME_FOREGROUND_COLOR (s->f)); : FRAME_FOREGROUND_COLOR (s->f));
/* FIXME: find another way to pass this */ /* FIXME: find another way to pass this */
...@@ -1077,7 +1077,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */ ...@@ -1077,7 +1077,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
if (face->underline_p) if (face->underline_p)
{ {
if (face->underline_color != nil) if (face->underline_color != 0)
[ns_lookup_indexed_color (face->underline_color, s->f) set]; [ns_lookup_indexed_color (face->underline_color, s->f) set];
else else
[col set]; [col set];
...@@ -1087,7 +1087,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */ ...@@ -1087,7 +1087,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
CGContextAddLineToPoint (gcontext, r.origin.x + r.size.width, CGContextAddLineToPoint (gcontext, r.origin.x + r.size.width,
r.origin.y + font->underpos); r.origin.y + font->underpos);
CGContextStrokePath (gcontext); CGContextStrokePath (gcontext);
if (face->underline_color != nil) if (face->underline_color != 0)
[col set]; [col set];
} }
else else
......
...@@ -75,20 +75,16 @@ typedef unichar XChar2b; ...@@ -75,20 +75,16 @@ typedef unichar XChar2b;
#define XCHAR2B_BYTE2(chp) \ #define XCHAR2B_BYTE2(chp) \
((*chp) & 0x00ff) ((*chp) & 0x00ff)
#define FACE_DEFAULT (~0)
/* XXX: xfaces requires these structures, but the question is are we /* XXX: xfaces requires these structures, but the question is are we
forced to use them? */ forced to use them? */
typedef struct _XGCValues typedef struct _XGCValues
{ {
unsigned long foreground;
unsigned long background;
#ifdef __OBJC__ #ifdef __OBJC__
NSColor *foreground;
NSColor *background;
struct ns_font *font; struct ns_font *font;
#else #else
void *foreground;
void *background;
void *font; void *font;
#endif #endif
} XGCValues; } XGCValues;
......
...@@ -53,8 +53,6 @@ ...@@ -53,8 +53,6 @@
#include "nsmenu_common.c" #include "nsmenu_common.c"
#endif #endif
extern struct widget_value;
extern Lisp_Object Qundefined, Qmenu_enable, Qmenu_bar_update_hook; extern Lisp_Object Qundefined, Qmenu_enable, Qmenu_bar_update_hook;
extern Lisp_Object QCtoggle, QCradio; extern Lisp_Object QCtoggle, QCradio;
...@@ -594,9 +592,9 @@ -(NSString *)parseKeyEquiv: (char *)key ...@@ -594,9 +592,9 @@ -(NSString *)parseKeyEquiv: (char *)key
return [NSString stringWithFormat: @"%c", tpos[2]]; return [NSString stringWithFormat: @"%c", tpos[2]];
} }
- (id <NSMenuItem>)addItemWithWidgetValue: (void *)wvptr - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr
{ {
id <NSMenuItem> item; NSMenuItem *item;
widget_value *wv = (widget_value *)wvptr; widget_value *wv = (widget_value *)wvptr;
if (name_is_separator (wv->name)) if (name_is_separator (wv->name))
...@@ -663,7 +661,7 @@ - (void)fillWithWidgetValue: (void *)wvptr ...@@ -663,7 +661,7 @@ - (void)fillWithWidgetValue: (void *)wvptr
/* add new contents */ /* add new contents */
for (; wv != NULL; wv = wv->next) for (; wv != NULL; wv = wv->next)
{ {
id <NSMenuItem> item = [self addItemWithWidgetValue: wv]; NSMenuItem *item = [self addItemWithWidgetValue: wv];
if (wv->contents) if (wv->contents)
{ {
...@@ -691,8 +689,7 @@ - (void)fillWithWidgetValue: (void *)wvptr ...@@ -691,8 +689,7 @@ - (void)fillWithWidgetValue: (void *)wvptr
- (EmacsMenu *)addSubmenuWithTitle: (char *)title forFrame: (struct frame *)f - (EmacsMenu *)addSubmenuWithTitle: (char *)title forFrame: (struct frame *)f
{ {
NSString *titleStr = [NSString stringWithUTF8String: title]; NSString *titleStr = [NSString stringWithUTF8String: title];
id <NSMenuItem> item NSMenuItem *item = [self addItemWithTitle: titleStr
= [self addItemWithTitle: titleStr
action: nil /*@selector (menuDown:) */ action: nil /*@selector (menuDown:) */
keyEquivalent: @""]; keyEquivalent: @""];
EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: titleStr frame: f]; EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: titleStr frame: f];
...@@ -1107,7 +1104,7 @@ key equivalents (see below) because the keydefs in ns-win.el have ...@@ -1107,7 +1104,7 @@ key equivalents (see below) because the keydefs in ns-win.el have
#endif #endif
wv_title->name = (char *) SDATA (title); wv_title->name = (char *) SDATA (title);
wv_title->enabled = NULL; wv_title->enabled = NO;
wv_title->button_type = BUTTON_TYPE_NONE; wv_title->button_type = BUTTON_TYPE_NONE;
wv_title->help = Qnil; wv_title->help = Qnil;
wv_title->next = wv_sep; wv_title->next = wv_sep;
......
...@@ -36,8 +36,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -36,8 +36,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
@interface EmacsApp : NSApplication @interface EmacsApp : NSApplication
{ {
} }
- (void)logNotification: (NSNotification *)notification;
- (void)sendEvent: (NSEvent *)theEvent; - (void)sendEvent: (NSEvent *)theEvent;
- (void)showPreferencesWindow: (id)sender; - (void)showPreferencesWindow: (id)sender;
- (BOOL) openFile: (NSString *)fileName;
- (void)fd_handler: (NSTimer *) fdEntry;
- (void)cursor_blink_handler: (NSTimer *)cursorEntry;
- (void)timeout_handler: (NSTimer *)timedEntry;
- (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
@end @end
...@@ -104,7 +110,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -104,7 +110,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
- (void)setFrame: (struct frame *)f; - (void)setFrame: (struct frame *)f;
- (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */ - (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
- (NSString *)parseKeyEquiv: (char *)key; - (NSString *)parseKeyEquiv: (char *)key;
- (id <NSMenuItem>)addItemWithWidgetValue: (void *)wvptr; - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
- (void)fillWithWidgetValue: (void *)wvptr; - (void)fillWithWidgetValue: (void *)wvptr;
- (EmacsMenu *)addSubmenuWithTitle: (char *)title forFrame: (struct frame *)f; - (EmacsMenu *)addSubmenuWithTitle: (char *)title forFrame: (struct frame *)f;
- (void) clear; - (void) clear;
...@@ -727,10 +733,6 @@ extern Lisp_Object ns_list_fonts (FRAME_PTR f, Lisp_Object pattern, ...@@ -727,10 +733,6 @@ extern Lisp_Object ns_list_fonts (FRAME_PTR f, Lisp_Object pattern,
int size, int maxnames); int size, int maxnames);
extern void ns_clear_frame (struct frame *f); extern void ns_clear_frame (struct frame *f);
#ifdef __OBJC__
extern const char *ns_font_to_xlfd (NSFont *font);
#endif
extern const char *ns_fontname_to_xlfd (const char *name);
extern const char *ns_xlfd_to_fontname (const char *xlfd); extern const char *ns_xlfd_to_fontname (const char *xlfd);
extern void check_ns (void); extern void check_ns (void);
......
...@@ -785,7 +785,7 @@ Free a pool and temporary objects it refers to (callable from C) ...@@ -785,7 +785,7 @@ Free a pool and temporary objects it refers to (callable from C)
static void static void
ns_clip_to_row (struct window *w, struct glyph_row *row, int area, GC gc) ns_clip_to_row (struct window *w, struct glyph_row *row, int area, BOOL gc)
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
23: Internal (but parallels other terms): Focus drawing on given row 23: Internal (but parallels other terms): Focus drawing on given row
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
...@@ -2212,7 +2212,7 @@ Free a pool and temporary objects it refers to (callable from C) ...@@ -2212,7 +2212,7 @@ Free a pool and temporary objects it refers to (callable from C)
int oldVH = row->visible_height; int oldVH = row->visible_height;
row->visible_height = p->h; row->visible_height = p->h;
row->y -= rowY - p->y; row->y -= rowY - p->y;
ns_clip_to_row (w, row, -1, NULL); ns_clip_to_row (w, row, -1, NO);
row->y = oldY; row->y = oldY;
row->visible_height = oldVH; row->visible_height = oldVH;
} }
...@@ -2329,7 +2329,7 @@ External call (RIF): draw cursor ...@@ -2329,7 +2329,7 @@ External call (RIF): draw cursor
/* TODO: only needed in rare cases with last-resort font in HELLO.. /* TODO: only needed in rare cases with last-resort font in HELLO..
should we do this more efficiently? */ should we do this more efficiently? */
ns_clip_to_row (w, glyph_row, -1, NULL); ns_clip_to_row (w, glyph_row, -1, NO);
/* ns_focus (f, &r, 1); */ /* ns_focus (f, &r, 1); */
if (FRAME_LAST_INACTIVE (f)) if (FRAME_LAST_INACTIVE (f))
...@@ -2943,8 +2943,8 @@ overwriting cursor (usually when cursor on a tab) */ ...@@ -2943,8 +2943,8 @@ overwriting cursor (usually when cursor on a tab) */
(s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND : (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
NS_DUMPGLYPH_NORMAL)); NS_DUMPGLYPH_NORMAL));
ns_tmp_font = (struct nsfont_info *)s->face->font; ns_tmp_font = (struct nsfont_info *)s->face->font;
if (ns_tmp_font == ~0 || ns_tmp_font == NULL) if (ns_tmp_font == NULL)
ns_tmp_font = FRAME_FONT (s->f); ns_tmp_font = (struct nsfont_info *)FRAME_FONT (s->f);
ns_tmp_font->font.driver->draw ns_tmp_font->font.driver->draw
(s, 0, s->nchars, s->x, s->y, (s, 0, s->nchars, s->x, s->y,
...@@ -3078,7 +3078,8 @@ overwriting cursor (usually when cursor on a tab) */ ...@@ -3078,7 +3078,8 @@ overwriting cursor (usually when cursor on a tab) */
} }
/* Deal with pending service requests. */ /* Deal with pending service requests. */
else if (ns_pending_service_names && [ns_pending_service_names count] != 0 else if (ns_pending_service_names && [ns_pending_service_names count] != 0
&& [NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0] && [(EmacsApp *)
NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0]
withArg: [ns_pending_service_args objectAtIndex: 0]]) withArg: [ns_pending_service_args objectAtIndex: 0]])
{ {
[ns_pending_service_names removeObjectAtIndex: 0]; [ns_pending_service_names removeObjectAtIndex: 0];
...@@ -3437,7 +3438,7 @@ overwriting cursor (usually when cursor on a tab) */ ...@@ -3437,7 +3438,7 @@ overwriting cursor (usually when cursor on a tab) */
========================================================================== */ ========================================================================== */
static Lisp_Object ns_string_to_lispmod (char *s) static Lisp_Object ns_string_to_lispmod (const char *s)
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Convert modifier name to lisp symbol Convert modifier name to lisp symbol
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
...@@ -3876,7 +3877,7 @@ Needs to be here because ns_initialize_display_info () uses AppKit classes. ...@@ -3876,7 +3877,7 @@ Needs to be here because ns_initialize_display_info () uses AppKit classes.
#ifdef NS_IMPL_COCOA #ifdef NS_IMPL_COCOA
{ {
NSMenu *appMenu; NSMenu *appMenu;
id<NSMenuItem> item; NSMenuItem *item;
/* set up the application menu */ /* set up the application menu */
svcsMenu = [[EmacsMenu alloc] initWithTitle: @"Services"]; svcsMenu = [[EmacsMenu alloc] initWithTitle: @"Services"];
[svcsMenu setAutoenablesItems: NO]; [svcsMenu setAutoenablesItems: NO];
...@@ -4029,6 +4030,26 @@ - (void)showPreferencesWindow: (id)sender ...@@ -4029,6 +4030,26 @@ - (void)showPreferencesWindow: (id)sender
} }
/* Open a file (used by below, after going into queue read by ns_read_socket) */
- (BOOL) openFile: (NSString *)fileName
{
struct frame *emacsframe = SELECTED_FRAME ();
NSEvent *theEvent = [NSApp currentEvent];
if (!emacs_event)
return NO;
emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
emacs_event->code = KEY_NS_OPEN_FILE_LINE;
ns_input_file = append2 (ns_input_file, build_string ([fileName UTF8String]));
ns_input_line = Qnil; /* can be start or cons start,end */
emacs_event->modifiers =0;
EV_TRAILER (theEvent);
return YES;
}
/* ************************************************************************** /* **************************************************************************
EmacsApp delegate implementation EmacsApp delegate implementation
...@@ -4080,26 +4101,6 @@ - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender ...@@ -4080,26 +4101,6 @@ - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender
} }
/* Open a file (used by below, after going into queue read by ns_read_socket) */
-(BOOL) openFile: (NSString *)fileName
{
struct frame *emacsframe = SELECTED_FRAME ();
NSEvent *theEvent = [NSApp currentEvent];
if (!emacs_event)
return NO;
emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
emacs_event->code = KEY_NS_OPEN_FILE_LINE;
ns_input_file = append2 (ns_input_file, build_string ([fileName UTF8String]));
ns_input_line = Qnil; /* can be start or cons start,end */
emacs_event->modifiers =0;
EV_TRAILER (theEvent);
return YES;
}
/* Notification from the Workspace to open a file */ /* Notification from the Workspace to open a file */
- (BOOL)application: sender openFile: (NSString *)file - (BOOL)application: sender openFile: (NSString *)file
{ {
...@@ -4131,7 +4132,7 @@ - (void)application: sender openFiles: (NSArray *)fileList ...@@ -4131,7 +4132,7 @@ - (void)application: sender openFiles: (NSArray *)fileList
NSString *file; NSString *file;
while ((file = [files nextObject]) != nil) while ((file = [files nextObject]) != nil)
[ns_pending_files addObject: file]; [ns_pending_files addObject: file];
return YES; [self replyToOpenOrPrint: NSApplicationDelegateReplySuccess];
} }
/* TODO: these may help w/IO switching btwn terminal and NSApp */ /* TODO: these may help w/IO switching btwn terminal and NSApp */
...@@ -4359,7 +4360,7 @@ - (void)keyDown: (NSEvent *)theEvent ...@@ -4359,7 +4360,7 @@ - (void)keyDown: (NSEvent *)theEvent
NSView most recently updated (I guess), which is not the correct one. NSView most recently updated (I guess), which is not the correct one.
UPDATE: After multi-TTY merge this happens even w/o NO_SOCK_SIGIO */ UPDATE: After multi-TTY merge this happens even w/o NO_SOCK_SIGIO */
if ([[theEvent window] isKindOfClass: [EmacsWindow class]]) if ([[theEvent window] isKindOfClass: [EmacsWindow class]])
[[(EmacsView *)[theEvent window] delegate] keyDown: theEvent]; [(EmacsView *)[[theEvent window] delegate] keyDown: theEvent];
return; return;
} }
...@@ -4638,9 +4639,9 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange ...@@ -4638,9 +4639,9 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange
return rect; return rect;
} }
- (long)conversationIdentifier - (NSInteger)conversationIdentifier
{ {
return (long)self; return (NSInteger)self;
} }
/* TODO: below here not yet implemented correctly, but may not be needed */ /* TODO: below here not yet implemented correctly, but may not be needed */
...@@ -5239,7 +5240,8 @@ - (void)mouseExited: (NSEvent *)theEvent ...@@ -5239,7 +5240,8 @@ - (void)mouseExited: (NSEvent *)theEvent
context_menu_value = [sender tag]; context_menu_value = [sender tag];
else else
find_and_call_menu_selection (emacsframe, emacsframe->menu_bar_items_used, find_and_call_menu_selection (emacsframe, emacsframe->menu_bar_items_used,
emacsframe->menu_bar_vector, [sender tag]); emacsframe->menu_bar_vector,
(void *)[sender tag]);
ns_send_appdefined (-1); ns_send_appdefined (-1);
return self; return self;
} }
...@@ -6156,6 +6158,7 @@ - (IBAction)setDefaultFont: (id)sender ...@@ -6156,6 +6158,7 @@ - (IBAction)setDefaultFont: (id)sender
/* ========================================================================== /* ==========================================================================
Font-related functions; these used to be in nsfaces.m Font-related functions; these used to be in nsfaces.m
The XLFD functions (115 lines) are an abomination that should be removed.
========================================================================== */ ========================================================================== */
...@@ -6204,141 +6207,9 @@ - (IBAction)setDefaultFont: (id)sender ...@@ -6204,141 +6207,9 @@ - (IBAction)setDefaultFont: (id)sender
} }
Lisp_Object
ns_list_fonts (FRAME_PTR f, Lisp_Object pattern, int size, int maxnames)
/* --------------------------------------------------------------------------
This is used by the xfaces system. It is expected to speak XLFD.
-------------------------------------------------------------------------- */
{
Lisp_Object list = Qnil,
rpattern,
key,
tem,
args[2];
struct re_pattern_buffer *bufp;
id fm = [NSFontManager sharedFontManager];
NSEnumerator *fenum, *senum;
NSArray *membInfo;
NSString *fontname;
const char *xlfdName;
char *pattFam;
char *patt;
NSString *famName;
NSTRACE (ns_list_fonts);
CHECK_STRING (pattern);
patt = SDATA (pattern);
#if 0
/* temporary: for font_backend, we use fontsets, and when these are defined,
the old XLFD-based system is used; eventually this will be replaced by
backend code, but for now we allow specs that are just family names */
/* if pattern is not XLFD, panic now */
if (patt[0] != '-')
error ("ns_list_fonts: X font name (XLFD) expected.");
/* if unicode encoding not requested, also die */
if (!strstr (patt, "iso10646") && patt[strlen (patt)-3] != '*')
return Qnil;
#endif /* 0 */
key = f ? Fcons (pattern, make_number (maxnames)) : Qnil;
tem = f ? XCDR (FRAME_NS_DISPLAY_INFO (f)->name_list_element) : Qnil;
/* See if we cached the result for this particular query.
The cache is an alist of the form:
((((PATTERN . MAXNAMES) FONTNAME) ...) ...)
*/
if (f && !NILP (list = Fassoc (key, tem)))
{
list = Fcdr_safe (list);
/* We have a cached list. Don't have to get the list again. */
if (!NILP (list))
return list;
}
if (patt[0] != '-')
pattFam = patt;
else
pattFam = ns_xlfd_to_fontname (patt);
/* XXX: '*' at beginning matches literally.. */
if (pattFam[0] == '*')
pattFam[0] = '.';
/* must start w/family name, but can have other stuff afterwards
(usually bold and italic specifiers) */
args[0] = build_string ("^");
args[1] = build_string (pattFam);
rpattern = Fconcat (2, args);
bufp = compile_pattern (rpattern, 0, Vascii_canon_table, 0, 0);
list = Qnil;
fenum = [[fm availableFontFamilies] objectEnumerator];
while ( (famName = [fenum nextObject]) )
{
NSMutableString *tmp = [famName mutableCopy];
const char *fname;
NSRange r;
/* remove spaces, to look like postscript name */
while ((r = [tmp rangeOfString: @" "]).location != NSNotFound)
[tmp deleteCharactersInRange: r];
fname = [tmp UTF8String];
int len = strlen (fname);
BOOL foundItal;
const char *synthItalFont;
if (re_search (bufp, fname, len, 0, len, 0) >= 0)
{
/* Found a family. Add all variants. If we have no italic variant,
add a synthItal. */
senum =[[fm availableMembersOfFontFamily: famName] objectEnumerator];
foundItal = NO;
synthItalFont = NULL;
while (membInfo = [senum nextObject])
{
xlfdName
= ns_fontname_to_xlfd ([[membInfo objectAtIndex: 0]
UTF8String]);
list = Fcons (build_string (xlfdName), list);
if (!synthItalFont)
{
NSString *synthName
= [[membInfo objectAtIndex: 0]
stringByAppendingString: @"-synthItal"];
synthItalFont = [synthName UTF8String];
}
else if ([[membInfo objectAtIndex: 3] intValue]
& NSItalicFontMask)
foundItal = YES;
}
if (foundItal == NO)
{
xlfdName = ns_fontname_to_xlfd (synthItalFont);
list = Fcons (build_string (xlfdName), list);
}
}
[