Converted struct mapTable to uiprivMap first, since that typedef will be a dependency of later stuff. ALso I didn't realize whoever wrote that new menu code also completely rewrote map.m... Cleaned up style inconsistencies I found in both. Anyway I plan on getting rid of that menu code anyway, and I could just have something else for target-action instead of this depending on whatever happens with ARC...
This commit is contained in:
parent
5a113e1e0b
commit
b8316c61dd
|
@ -1,7 +1,7 @@
|
|||
|
||||
// menu.m
|
||||
@interface menuManager : NSObject {
|
||||
struct mapTable *items;
|
||||
uiprivMap *items;
|
||||
BOOL hasQuit;
|
||||
BOOL hasPreferences;
|
||||
BOOL hasAbout;
|
||||
|
@ -68,15 +68,6 @@ extern void singleChildConstraintsEstablish(struct singleChildConstraints *c, NS
|
|||
extern void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv);
|
||||
extern void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined);
|
||||
|
||||
// map.m
|
||||
extern struct mapTable *newMap(void);
|
||||
extern void mapDestroy(struct mapTable *m);
|
||||
extern void *mapGet(struct mapTable *m, void *key);
|
||||
extern void mapSet(struct mapTable *m, void *key, void *value);
|
||||
extern void mapDelete(struct mapTable *m, void *key);
|
||||
extern void mapWalk(struct mapTable *m, void (*f)(void *key, void *value));
|
||||
extern void mapReset(struct mapTable *m);
|
||||
|
||||
// area.m
|
||||
extern int sendAreaEvents(NSEvent *);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ struct uiButton {
|
|||
};
|
||||
|
||||
@interface buttonDelegateClass : NSObject {
|
||||
struct mapTable *buttons;
|
||||
uiprivMap *buttons;
|
||||
}
|
||||
- (IBAction)onClicked:(id)sender;
|
||||
- (void)registerButton:(uiButton *)b;
|
||||
|
@ -22,13 +22,13 @@ struct uiButton {
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->buttons = newMap();
|
||||
self->buttons = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->buttons);
|
||||
uiprivMapDestroy(self->buttons);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,13 @@ struct uiButton {
|
|||
{
|
||||
uiButton *b;
|
||||
|
||||
b = (uiButton *) mapGet(self->buttons, sender);
|
||||
b = (uiButton *) uiprivMapGet(self->buttons, sender);
|
||||
(*(b->onClicked))(b, b->onClickedData);
|
||||
}
|
||||
|
||||
- (void)registerButton:(uiButton *)b
|
||||
{
|
||||
mapSet(self->buttons, b->button, b);
|
||||
uiprivMapSet(self->buttons, b->button, b);
|
||||
[b->button setTarget:self];
|
||||
[b->button setAction:@selector(onClicked:)];
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ struct uiButton {
|
|||
- (void)unregisterButton:(uiButton *)b
|
||||
{
|
||||
[b->button setTarget:nil];
|
||||
mapDelete(self->buttons, b->button);
|
||||
uiprivMapDelete(self->buttons, b->button);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -9,7 +9,7 @@ struct uiCheckbox {
|
|||
};
|
||||
|
||||
@interface checkboxDelegateClass : NSObject {
|
||||
struct mapTable *buttons;
|
||||
uiprivMap *buttons;
|
||||
}
|
||||
- (IBAction)onToggled:(id)sender;
|
||||
- (void)registerCheckbox:(uiCheckbox *)c;
|
||||
|
@ -22,13 +22,13 @@ struct uiCheckbox {
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->buttons = newMap();
|
||||
self->buttons = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->buttons);
|
||||
uiprivMapDestroy(self->buttons);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,13 @@ struct uiCheckbox {
|
|||
{
|
||||
uiCheckbox *c;
|
||||
|
||||
c = (uiCheckbox *) mapGet(self->buttons, sender);
|
||||
c = (uiCheckbox *) uiprivMapGet(self->buttons, sender);
|
||||
(*(c->onToggled))(c, c->onToggledData);
|
||||
}
|
||||
|
||||
- (void)registerCheckbox:(uiCheckbox *)c
|
||||
{
|
||||
mapSet(self->buttons, c->button, c);
|
||||
uiprivMapSet(self->buttons, c->button, c);
|
||||
[c->button setTarget:self];
|
||||
[c->button setAction:@selector(onToggled:)];
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ struct uiCheckbox {
|
|||
- (void)unregisterCheckbox:(uiCheckbox *)c
|
||||
{
|
||||
[c->button setTarget:nil];
|
||||
mapDelete(self->buttons, c->button);
|
||||
uiprivMapDelete(self->buttons, c->button);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,7 +14,7 @@ struct uiCombobox {
|
|||
};
|
||||
|
||||
@interface comboboxDelegateClass : NSObject {
|
||||
struct mapTable *comboboxes;
|
||||
uiprivMap *comboboxes;
|
||||
}
|
||||
- (IBAction)onSelected:(id)sender;
|
||||
- (void)registerCombobox:(uiCombobox *)c;
|
||||
|
@ -27,13 +27,13 @@ struct uiCombobox {
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->comboboxes = newMap();
|
||||
self->comboboxes = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->comboboxes);
|
||||
uiprivMapDestroy(self->comboboxes);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,13 @@ struct uiCombobox {
|
|||
{
|
||||
uiCombobox *c;
|
||||
|
||||
c = uiCombobox(mapGet(self->comboboxes, sender));
|
||||
c = uiCombobox(uiprivMapGet(self->comboboxes, sender));
|
||||
(*(c->onSelected))(c, c->onSelectedData);
|
||||
}
|
||||
|
||||
- (void)registerCombobox:(uiCombobox *)c
|
||||
{
|
||||
mapSet(self->comboboxes, c->pb, c);
|
||||
uiprivMapSet(self->comboboxes, c->pb, c);
|
||||
[c->pb setTarget:self];
|
||||
[c->pb setAction:@selector(onSelected:)];
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ struct uiCombobox {
|
|||
- (void)unregisterCombobox:(uiCombobox *)c
|
||||
{
|
||||
[c->pb setTarget:nil];
|
||||
mapDelete(self->comboboxes, c->pb);
|
||||
uiprivMapDelete(self->comboboxes, c->pb);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -34,7 +34,7 @@ struct uiEditableCombobox {
|
|||
};
|
||||
|
||||
@interface editableComboboxDelegateClass : NSObject<NSComboBoxDelegate> {
|
||||
struct mapTable *comboboxes;
|
||||
uiprivMap *comboboxes;
|
||||
}
|
||||
- (void)controlTextDidChange:(NSNotification *)note;
|
||||
- (void)comboBoxSelectionDidChange:(NSNotification *)note;
|
||||
|
@ -48,13 +48,13 @@ struct uiEditableCombobox {
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->comboboxes = newMap();
|
||||
self->comboboxes = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->comboboxes);
|
||||
uiprivMapDestroy(self->comboboxes);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,8 @@ struct uiEditableCombobox {
|
|||
{
|
||||
uiEditableCombobox *c;
|
||||
|
||||
c = uiEditableCombobox(mapGet(self->comboboxes, [note object]));
|
||||
// TODO normalize the cast styles in these calls
|
||||
c = uiEditableCombobox(uiprivMapGet(self->comboboxes, [note object]));
|
||||
(*(c->onChanged))(c, c->onChangedData);
|
||||
}
|
||||
|
||||
|
@ -79,14 +80,14 @@ struct uiEditableCombobox {
|
|||
|
||||
- (void)registerCombobox:(uiEditableCombobox *)c
|
||||
{
|
||||
mapSet(self->comboboxes, c->cb, c);
|
||||
uiprivMapSet(self->comboboxes, c->cb, c);
|
||||
[c->cb setDelegate:self];
|
||||
}
|
||||
|
||||
- (void)unregisterCombobox:(uiEditableCombobox *)c
|
||||
{
|
||||
[c->cb setDelegate:nil];
|
||||
mapDelete(self->comboboxes, c->cb);
|
||||
uiprivMapDelete(self->comboboxes, c->cb);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -67,7 +67,7 @@ static BOOL isSearchField(NSTextField *tf)
|
|||
}
|
||||
|
||||
@interface entryDelegateClass : NSObject<NSTextFieldDelegate> {
|
||||
struct mapTable *entries;
|
||||
uiprivMap *entries;
|
||||
}
|
||||
- (void)controlTextDidChange:(NSNotification *)note;
|
||||
- (IBAction)onSearch:(id)sender;
|
||||
|
@ -81,13 +81,13 @@ static BOOL isSearchField(NSTextField *tf)
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->entries = newMap();
|
||||
self->entries = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->entries);
|
||||
uiprivMapDestroy(self->entries);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -100,13 +100,13 @@ static BOOL isSearchField(NSTextField *tf)
|
|||
{
|
||||
uiEntry *e;
|
||||
|
||||
e = (uiEntry *) mapGet(self->entries, sender);
|
||||
e = (uiEntry *) uiprivMapGet(self->entries, sender);
|
||||
(*(e->onChanged))(e, e->onChangedData);
|
||||
}
|
||||
|
||||
- (void)registerEntry:(uiEntry *)e
|
||||
{
|
||||
mapSet(self->entries, e->textfield, e);
|
||||
uiprivMapSet(self->entries, e->textfield, e);
|
||||
if (isSearchField(e->textfield)) {
|
||||
[e->textfield setTarget:self];
|
||||
[e->textfield setAction:@selector(onSearch:)];
|
||||
|
@ -120,7 +120,7 @@ static BOOL isSearchField(NSTextField *tf)
|
|||
[e->textfield setTarget:nil];
|
||||
else
|
||||
[e->textfield setDelegate:nil];
|
||||
mapDelete(self->entries, e->textfield);
|
||||
uiprivMapDelete(self->entries, e->textfield);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
32
darwin/map.m
32
darwin/map.m
|
@ -4,22 +4,22 @@
|
|||
// unfortunately NSMutableDictionary copies its keys, meaning we can't use it for pointers
|
||||
// hence, this file
|
||||
// we could expose a NSMapTable directly, but let's treat all pointers as opaque and hide the implementation, just to be safe and prevent even more rewrites later
|
||||
struct mapTable {
|
||||
struct uiprivMap {
|
||||
NSMapTable *m;
|
||||
};
|
||||
|
||||
struct mapTable *newMap(void)
|
||||
uiprivMap *uiprivNewMap(void)
|
||||
{
|
||||
struct mapTable *m;
|
||||
uiprivMap *m;
|
||||
|
||||
m = uiprivNew(struct mapTable);
|
||||
m = uiprivNew(uiprivMap);
|
||||
m->m = [[NSMapTable alloc] initWithKeyOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
|
||||
valueOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
|
||||
capacity:0];
|
||||
return m;
|
||||
}
|
||||
|
||||
void mapDestroy(struct mapTable *m)
|
||||
void uiprivMapDestroy(uiprivMap *m)
|
||||
{
|
||||
if ([m->m count] != 0)
|
||||
uiprivImplBug("attempt to destroy map with items inside");
|
||||
|
@ -27,33 +27,35 @@ void mapDestroy(struct mapTable *m)
|
|||
uiprivFree(m);
|
||||
}
|
||||
|
||||
void *mapGet(struct mapTable *m, void *key)
|
||||
void *uiprivMapGet(uiprivMap *m, void *key)
|
||||
{
|
||||
return NSMapGet(m->m, key);
|
||||
}
|
||||
|
||||
void mapSet(struct mapTable *m, void *key, void *value)
|
||||
void uiprivMapSet(uiprivMap *m, void *key, void *value)
|
||||
{
|
||||
NSMapInsert(m->m, key, value);
|
||||
}
|
||||
|
||||
void mapDelete(struct mapTable *m, void *key)
|
||||
void uiprivMapDelete(uiprivMap *m, void *key)
|
||||
{
|
||||
NSMapRemove(m->m, key);
|
||||
}
|
||||
|
||||
void mapWalk(struct mapTable *m, void (*f)(void *key, void *value))
|
||||
void uiprivMapWalk(uiprivMap *m, void (*f)(void *key, void *value))
|
||||
{
|
||||
NSMapEnumerator e = NSEnumerateMapTable(m->m);
|
||||
void *k = NULL;
|
||||
void *v = NULL;
|
||||
while (NSNextMapEnumeratorPair(&e, &k, &v)) {
|
||||
NSMapEnumerator e;
|
||||
void *k, *v;
|
||||
|
||||
e = NSEnumerateMapTable(m->m);
|
||||
k = NULL;
|
||||
v = NULL;
|
||||
while (NSNextMapEnumeratorPair(&e, &k, &v))
|
||||
f(k, v);
|
||||
}
|
||||
NSEndMapTableEnumeration(&e);
|
||||
}
|
||||
|
||||
void mapReset(struct mapTable *m)
|
||||
void uiprivMapReset(uiprivMap *m)
|
||||
{
|
||||
NSResetMapTable(m->m);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ static void mapItemReleaser(void *key, void *value)
|
|||
{
|
||||
uiMenuItem *item;
|
||||
|
||||
item = (uiMenuItem *)value;
|
||||
item = (uiMenuItem *) value;
|
||||
[item->item release];
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ static void mapItemReleaser(void *key, void *value)
|
|||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self->items = newMap();
|
||||
self->items = uiprivNewMap();
|
||||
self->hasQuit = NO;
|
||||
self->hasPreferences = NO;
|
||||
self->hasAbout = NO;
|
||||
|
@ -51,9 +51,9 @@ static void mapItemReleaser(void *key, void *value)
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapWalk(self->items, mapItemReleaser);
|
||||
mapReset(self->items);
|
||||
mapDestroy(self->items);
|
||||
uiprivMapWalk(self->items, mapItemReleaser);
|
||||
uiprivMapReset(self->items);
|
||||
uiprivMapDestroy(self->items);
|
||||
uninitMenus();
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ static void mapItemReleaser(void *key, void *value)
|
|||
{
|
||||
uiMenuItem *item;
|
||||
|
||||
item = (uiMenuItem *) mapGet(self->items, sender);
|
||||
item = (uiMenuItem *) uiprivMapGet(self->items, sender);
|
||||
if (item->type == typeCheckbox)
|
||||
uiMenuItemSetChecked(item, !uiMenuItemChecked(item));
|
||||
// use the key window as the source of the menu event; it's the active window
|
||||
|
@ -94,7 +94,7 @@ static void mapItemReleaser(void *key, void *value)
|
|||
self->hasAbout = YES;
|
||||
break;
|
||||
}
|
||||
mapSet(self->items, item, smi);
|
||||
uiprivMapSet(self->items, item, smi);
|
||||
}
|
||||
|
||||
// on OS X there are two ways to handle menu items being enabled or disabled: automatically and manually
|
||||
|
@ -112,7 +112,7 @@ static void mapItemReleaser(void *key, void *value)
|
|||
if (item == self.aboutItem && !self->hasAbout)
|
||||
return NO;
|
||||
// then poll the item's enabled/disabled state
|
||||
smi = (uiMenuItem *) mapGet(self->items, item);
|
||||
smi = (uiMenuItem *) uiprivMapGet(self->items, item);
|
||||
return !smi->disabled;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ struct uiSlider {
|
|||
};
|
||||
|
||||
@interface sliderDelegateClass : NSObject {
|
||||
struct mapTable *sliders;
|
||||
uiprivMap *sliders;
|
||||
}
|
||||
- (IBAction)onChanged:(id)sender;
|
||||
- (void)registerSlider:(uiSlider *)b;
|
||||
|
@ -42,13 +42,13 @@ struct uiSlider {
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->sliders = newMap();
|
||||
self->sliders = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->sliders);
|
||||
uiprivMapDestroy(self->sliders);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -56,13 +56,13 @@ struct uiSlider {
|
|||
{
|
||||
uiSlider *s;
|
||||
|
||||
s = (uiSlider *) mapGet(self->sliders, sender);
|
||||
s = (uiSlider *) uiprivMapGet(self->sliders, sender);
|
||||
(*(s->onChanged))(s, s->onChangedData);
|
||||
}
|
||||
|
||||
- (void)registerSlider:(uiSlider *)s
|
||||
{
|
||||
mapSet(self->sliders, s->slider, s);
|
||||
uiprivMapSet(self->sliders, s->slider, s);
|
||||
[s->slider setTarget:self];
|
||||
[s->slider setAction:@selector(onChanged:)];
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ struct uiSlider {
|
|||
- (void)unregisterSlider:(uiSlider *)s
|
||||
{
|
||||
[s->slider setTarget:nil];
|
||||
mapDelete(self->sliders, s->slider);
|
||||
uiprivMapDelete(self->sliders, s->slider);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -22,4 +22,14 @@
|
|||
|
||||
/*TODO remove this*/typedef struct uiImage uiImage;
|
||||
|
||||
// map.m
|
||||
typedef struct uiprivMap uiprivMap;
|
||||
extern uiprivMap *uiprivNewMap(void);
|
||||
extern void uiprivMapDestroy(uiprivMap *m);
|
||||
extern void *uiprivMapGet(uiprivMap *m, void *key);
|
||||
extern void uiprivMapSet(uiprivMap *m, void *key, void *value);
|
||||
extern void uiprivMapDelete(uiprivMap *m, void *key);
|
||||
extern void uiprivMapWalk(uiprivMap *m, void (*f)(void *key, void *value));
|
||||
extern void uiprivMapReset(uiprivMap *m);
|
||||
|
||||
#import "OLD_uipriv_darwin.h"
|
||||
|
|
|
@ -33,7 +33,7 @@ struct uiWindow {
|
|||
@end
|
||||
|
||||
@interface windowDelegateClass : NSObject<NSWindowDelegate> {
|
||||
struct mapTable *windows;
|
||||
uiprivMap *windows;
|
||||
}
|
||||
- (BOOL)windowShouldClose:(id)sender;
|
||||
- (void)windowDidResize:(NSNotification *)note;
|
||||
|
@ -50,13 +50,13 @@ struct uiWindow {
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->windows = newMap();
|
||||
self->windows = uiprivNewMap();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mapDestroy(self->windows);
|
||||
uiprivMapDestroy(self->windows);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -100,21 +100,21 @@ struct uiWindow {
|
|||
|
||||
- (void)registerWindow:(uiWindow *)w
|
||||
{
|
||||
mapSet(self->windows, w->window, w);
|
||||
uiprivMapSet(self->windows, w->window, w);
|
||||
[w->window setDelegate:self];
|
||||
}
|
||||
|
||||
- (void)unregisterWindow:(uiWindow *)w
|
||||
{
|
||||
[w->window setDelegate:nil];
|
||||
mapDelete(self->windows, w->window);
|
||||
uiprivMapDelete(self->windows, w->window);
|
||||
}
|
||||
|
||||
- (uiWindow *)lookupWindow:(NSWindow *)w
|
||||
{
|
||||
uiWindow *v;
|
||||
|
||||
v = uiWindow(mapGet(self->windows, w));
|
||||
v = uiWindow(uiprivMapGet(self->windows, w));
|
||||
// this CAN (and IS ALLOWED TO) return NULL, just in case we're called with some OS X-provided window as the key window
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue