0
#define INIT NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
0
#define RELEASE [pool release]
0
+#define COCOA_DO(statements) do {\
0
+ @try { statements; } \
0
+ @catch (NSException *e) { ; } \
0
@implementation ShoesEvents
0
@@ -643,8 +649,10 @@ void shoes_native_slot_lengthen(SHOES_SLOT_OS *slot, int height, int endy)
0
float s = slot->scrolly * 1., e = endy * 1., h = height * 1., d = (endy - height) * 1.;
0
- [slot->vscroll setFloatValue: (d > 0 ? s / d : 0) knobProportion: (h / e)];
0
- [slot->vscroll setHidden: endy <= height ? YES : NO];
0
+ [slot->vscroll setFloatValue: (d > 0 ? s / d : 0) knobProportion: (h / e)];
0
+ [slot->vscroll setHidden: endy <= height ? YES : NO];
0
@@ -698,23 +706,23 @@ shoes_native_app_resized(shoes_app *app)
0
shoes_native_app_title(shoes_app *app, char *msg)
0
-
[app->os.window setTitle: [NSString stringWithUTF8String: msg]];
0
+
COCOA_DO([app->os.window setTitle: [NSString stringWithUTF8String: msg]]);
0
shoes_native_app_open(shoes_app *app, char *path, int dialog)
0
unsigned int mask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
0
shoes_code code = SHOES_OK;
0
- mask |= NSResizableWindowMask;
0
- app->os.window = [[ShoesWindow alloc] initWithContentRect: NSMakeRect(0, 0, app->width, app->height)
0
- styleMask: mask backing: NSBackingStoreBuffered defer: NO];
0
- [app->os.window prepareWithApp: app->self];
0
- app->slot->view = [app->os.window contentView];
0
+ mask |= NSResizableWindowMask;
0
+ app->os.window = [[ShoesWindow alloc] initWithContentRect: NSMakeRect(0, 0, app->width, app->height)
0
+ styleMask: mask backing: NSBackingStoreBuffered defer: NO];
0
+ [app->os.window prepareWithApp: app->self];
0
+ app->slot->view = [app->os.window contentView];
0
@@ -723,7 +731,7 @@ quit:
0
shoes_native_app_show(shoes_app *app)
0
-
[app->os.window orderFront: nil];
0
+
COCOA_DO([app->os.window orderFront: nil]);
0
@@ -736,9 +744,7 @@ shoes_native_loop()
0
shoes_native_app_close(shoes_app *app)
0
- [app->os.window close];
0
+ COCOA_DO([app->os.window close]);
0
@@ -752,32 +758,32 @@ shoes_browser_open(char *url)
0
shoes_slot_init(VALUE c, SHOES_SLOT_OS *parent, int x, int y, int width, int height, int scrolls, int toplevel)
0
Data_Get_Struct(c, shoes_canvas, canvas);
0
- slot = shoes_slot_alloc(canvas, parent, toplevel);
0
- slot->controls = parent->controls;
0
- slot->view = [[ShoesView alloc] initWithFrame: NSMakeRect(x, y, width, height) andCanvas: c];
0
- [slot->view setAutoresizesSubviews: NO];
0
- [slot->view setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
0
- slot->vscroll = [[NSScroller alloc] initWithFrame:
0
- NSMakeRect(width - [NSScroller scrollerWidth], 0, [NSScroller scrollerWidth], height)];
0
- [slot->vscroll setEnabled: YES];
0
- [slot->vscroll setTarget: slot->view];
0
- [slot->vscroll setAction: @selector(scroll:)];
0
- [slot->view addSubview: slot->vscroll];
0
- [parent->view addSubview: slot->view positioned: NSWindowBelow relativeTo: parent->vscroll];
0
- [parent->view addSubview: slot->view];
0
+ slot = shoes_slot_alloc(canvas, parent, toplevel);
0
+ slot->controls = parent->controls;
0
+ slot->view = [[ShoesView alloc] initWithFrame: NSMakeRect(x, y, width, height) andCanvas: c];
0
+ [slot->view setAutoresizesSubviews: NO];
0
+ [slot->view setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
0
+ slot->vscroll = [[NSScroller alloc] initWithFrame:
0
+ NSMakeRect(width - [NSScroller scrollerWidth], 0, [NSScroller scrollerWidth], height)];
0
+ [slot->vscroll setEnabled: YES];
0
+ [slot->vscroll setTarget: slot->view];
0
+ [slot->vscroll setAction: @selector(scroll:)];
0
+ [slot->view addSubview: slot->vscroll];
0
+ [parent->view addSubview: slot->view positioned: NSWindowBelow relativeTo: parent->vscroll];
0
+ [parent->view addSubview: slot->view];
0
@@ -838,13 +844,13 @@ shoes_native_canvas_resize(shoes_canvas *canvas)
0
shoes_native_control_hide(SHOES_CONTROL_REF ref)
0
+
COCOA_DO([ref setHidden: YES]);
0
shoes_native_control_show(SHOES_CONTROL_REF ref)
0
+
COCOA_DO([ref setHidden: NO]);
0
@@ -884,15 +890,13 @@ shoes_native_control_repaint(SHOES_CONTROL_REF ref, shoes_place *p1,
0
shoes_native_control_focus(SHOES_CONTROL_REF ref)
0
-
[[ref window] makeFirstResponder: ref];
0
+
COCOA_DO([[ref window] makeFirstResponder: ref]);
0
shoes_native_control_remove(SHOES_CONTROL_REF ref, shoes_canvas *canvas)
0
- [ref removeFromSuperview];
0
+ COCOA_DO([ref removeFromSuperview]);
0
@@ -975,9 +979,7 @@ shoes_native_edit_line_get_text(SHOES_CONTROL_REF ref)
0
shoes_native_edit_line_set_text(SHOES_CONTROL_REF ref, char *msg)
0
- [ref setStringValue: [NSString stringWithUTF8String: msg]];
0
+ COCOA_DO([ref setStringValue: [NSString stringWithUTF8String: msg]]);
0
@@ -1006,9 +1008,7 @@ shoes_native_edit_box_get_text(SHOES_CONTROL_REF ref)
0
shoes_native_edit_box_set_text(SHOES_CONTROL_REF ref, char *msg)
0
- [[[(ShoesTextView *)ref textStorage] mutableString] setString: [NSString stringWithUTF8String: msg]];
0
+ COCOA_DO([[[(ShoesTextView *)ref textStorage] mutableString] setString: [NSString stringWithUTF8String: msg]]);
0
@@ -1026,18 +1026,18 @@ shoes_native_list_box(VALUE self, shoes_canvas *canvas, shoes_place *place, VALU
0
shoes_native_list_box_update(SHOES_CONTROL_REF ref, VALUE ary)
0
ShoesPopUpButton *pop = (ShoesPopUpButton *)ref;
0
- for (i = 0; i < RARRAY_LEN(ary); i++)
0
- VALUE msg_s = shoes_native_to_s(rb_ary_entry(ary, i));
0
- char *msg = RSTRING_PTR(msg_s);
0
- [[pop menu] insertItemWithTitle: [NSString stringWithUTF8String: msg] action: nil
0
- keyEquivalent: @"" atIndex: i];
0
+ for (i = 0; i < RARRAY_LEN(ary); i++)
0
+ VALUE msg_s = shoes_native_to_s(rb_ary_entry(ary, i));
0
+ char *msg = RSTRING_PTR(msg_s);
0
+ [[pop menu] insertItemWithTitle: [NSString stringWithUTF8String: msg] action: nil
0
+ keyEquivalent: @"" atIndex: i];
0
@@ -1054,7 +1054,7 @@ shoes_native_list_box_set_active(SHOES_CONTROL_REF ref, VALUE ary, VALUE item)
0
int idx = rb_ary_index_of(ary, item);
0
-
[(ShoesPopUpButton *)ref selectItemAtIndex: idx];
0
+
COCOA_DO([(ShoesPopUpButton *)ref selectItemAtIndex: idx]);
0
@@ -1078,7 +1078,7 @@ shoes_native_progress_get_fraction(SHOES_CONTROL_REF ref)
0
shoes_native_progress_set_fraction(SHOES_CONTROL_REF ref, double perc)
0
-
[(NSProgressIndicator *)ref setDoubleValue: perc * 100.];
0
+
COCOA_DO([(NSProgressIndicator *)ref setDoubleValue: perc * 100.]);
0
@@ -1099,7 +1099,7 @@ shoes_native_check_get(SHOES_CONTROL_REF ref)
0
shoes_native_check_set(SHOES_CONTROL_REF ref, int on)
0
-
[(ShoesButton *)ref setState: on ? NSOnState : NSOffState];
0
+
COCOA_DO([(ShoesButton *)ref setState: on ? NSOnState : NSOffState]);
0
@@ -1115,9 +1115,7 @@ shoes_native_radio(VALUE self, shoes_canvas *canvas, shoes_place *place, VALUE a
0
shoes_native_timer_remove(shoes_canvas *canvas, SHOES_TIMER_REF ref)
0
+ COCOA_DO([ref invalidate]);
0
@@ -1144,11 +1142,11 @@ shoes_native_clipboard_get(shoes_app *app)
0
shoes_native_clipboard_set(shoes_app *app, VALUE string)
0
- [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
0
- [[NSPasteboard generalPasteboard] setString: [NSString stringWithUTF8String: RSTRING_PTR(string)]
0
- forType: NSStringPboardType];
0
+ [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
0
+ [[NSPasteboard generalPasteboard] setString: [NSString stringWithUTF8String: RSTRING_PTR(string)]
0
+ forType: NSStringPboardType];
0
@@ -1179,55 +1177,53 @@ shoes_native_dialog_color(shoes_app *app)
0
shoes_dialog_alert(VALUE self, VALUE msg)
0
- msg = shoes_native_to_s(msg);
0
- NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes says:"
0
- defaultButton: @"OK" alternateButton: nil otherButton: nil
0
- informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(msg)]];
0
+ msg = shoes_native_to_s(msg);
0
+ NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes says:"
0
+ defaultButton: @"OK" alternateButton: nil otherButton: nil
0
+ informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(msg)]];
0
shoes_dialog_ask(int argc, VALUE *argv, VALUE self)
0
VALUE quiz, attr = Qnil, answer = Qnil;
0
rb_scan_args(argc, argv, "11", &quiz, &attr);
0
quiz = shoes_native_to_s(quiz);
0
- NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
- defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil
0
- informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(quiz)]];
0
- if (RTEST(ATTR(attr, secret)))
0
- input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
- input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
- [input setStringValue:@""];
0
- [alert setAccessoryView:input];
0
- if ([alert runModal] == NSOKButton)
0
- answer = rb_str_new2([[input stringValue] UTF8String]);
0
+ NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
+ defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil
0
+ informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(quiz)]];
0
+ if (RTEST(ATTR(attr, secret)))
0
+ input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
+ input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
+ [input setStringValue:@""];
0
+ [alert setAccessoryView:input];
0
+ if ([alert runModal] == NSOKButton)
0
+ answer = rb_str_new2([[input stringValue] UTF8String]);
0
shoes_dialog_confirm(VALUE self, VALUE quiz)
0
- quiz = shoes_native_to_s(quiz);
0
- msg = RSTRING_PTR(quiz);
0
- NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
- defaultButton: @"OK" alternateButton: @"Cancel" otherButton:nil
0
- informativeTextWithFormat: [NSString stringWithUTF8String: msg]];
0
- answer = ([alert runModal] == NSOKButton ? Qtrue : Qfalse);
0
+ quiz = shoes_native_to_s(quiz);
0
+ msg = RSTRING_PTR(quiz);
0
+ NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
+ defaultButton: @"OK" alternateButton: @"Cancel" otherButton:nil
0
+ informativeTextWithFormat: [NSString stringWithUTF8String: msg]];
0
+ answer = ([alert runModal] == NSOKButton ? Qtrue : Qfalse);
0
@@ -1252,17 +1248,20 @@ shoes_dialog_color(VALUE self, VALUE title)
0
shoes_dialog_chooser(VALUE self, NSString *title, BOOL directories)
0
- NSOpenPanel* openDlg = [NSOpenPanel openPanel];
0
- [openDlg setCanChooseFiles: !directories];
0
- [openDlg setCanChooseDirectories: directories];
0
- [openDlg setAllowsMultipleSelection: NO];
0
- if ( [openDlg runModalForDirectory: nil file: nil] == NSOKButton )
0
- NSArray* files = [openDlg filenames];
0
- char *filename = [[files objectAtIndex: 0] UTF8String];
0
- return rb_str_new2(filename);
0
+ NSOpenPanel* openDlg = [NSOpenPanel openPanel];
0
+ [openDlg setCanChooseFiles: !directories];
0
+ [openDlg setCanChooseDirectories: directories];
0
+ [openDlg setAllowsMultipleSelection: NO];
0
+ if ( [openDlg runModalForDirectory: nil file: nil] == NSOKButton )
0
+ NSArray* files = [openDlg filenames];
0
+ char *filename = [[files objectAtIndex: 0] UTF8String];
0
+ path = rb_str_new2(filename);
0
@@ -1274,12 +1273,15 @@ shoes_dialog_open(VALUE self)
0
shoes_dialog_save(VALUE self)
0
- NSSavePanel* saveDlg = [NSSavePanel savePanel];
0
- if ( [saveDlg runModalForDirectory:nil file:nil] == NSOKButton )
0
- char *filename = [[saveDlg filename] UTF8String];
0
- return rb_str_new2(filename);
0
+ NSSavePanel* saveDlg = [NSSavePanel savePanel];
0
+ if ( [saveDlg runModalForDirectory:nil file:nil] == NSOKButton )
0
+ char *filename = [[saveDlg filename] UTF8String];
0
+ path = rb_str_new2(filename);
Comments
No one has commented yet.