Changeset 436
- Timestamp:
- 02/29/2008 01:37:22 (6 months ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
lib/shoes.rb (modified) (3 diffs)
-
shoes/app.c (modified) (10 diffs)
-
shoes/app.h (modified) (1 diff)
-
shoes/world.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/shoes.rb
r426 r436 103 103 104 104 @mounts = [] 105 @main_app = nil106 105 107 106 OPTS = OptionParser.new do |opts| … … 110 109 opts.on("-m", "--manual", 111 110 "Open the built-in manual.") do 112 @main_app = Shoes::Help111 Shoes.app(&Shoes::Help) 113 112 end 114 113 115 114 opts.on("-s", "--shy DIRECTORY", 116 115 "Compress a directory into a Shoes YAML (SHY) archive.") do |s| 117 @main_app = ShyMake.call(s)116 Shoes.app(&ShyMake.call(s)) 118 117 end 119 118 … … 152 151 end 153 152 case uri.path when "/" 154 [ @main_app]153 [nil] 155 154 when SHOES_URL_RE 156 155 [proc { eval(URI("http://#$1:53045#$2").read) }] -
trunk/shoes/app.c
r433 r436 1315 1315 { 1316 1316 VALUE attr, block; 1317 GLOBAL_APP(app); 1317 VALUE app = shoes_app_new(); 1318 shoes_app *app_t; 1319 Data_Get_Struct(app, shoes_app, app_t); 1320 1321 if (NIL_P(shoes_world->app)) 1322 shoes_world->app = app; 1318 1323 1319 1324 rb_scan_args(argc, argv, "01&", &attr, &block); 1320 rb_iv_set( self, "@main_app", block);1321 1322 app ->title = ATTR(attr, title);1323 app ->resizable = (ATTR(attr, resizable) != Qfalse);1324 shoes_app_resize(app , ATTR2(int, attr, width, SHOES_APP_WIDTH), ATTR2(int, attr, height, SHOES_APP_HEIGHT));1325 shoes_canvas_init(app ->canvas, app->slot, attr, app->width, app->height);1325 rb_iv_set(app, "@main_app", block); 1326 1327 app_t->title = ATTR(attr, title); 1328 app_t->resizable = (ATTR(attr, resizable) != Qfalse); 1329 shoes_app_resize(app_t, ATTR2(int, attr, width, SHOES_APP_WIDTH), ATTR2(int, attr, height, SHOES_APP_HEIGHT)); 1330 shoes_canvas_init(app_t->canvas, app_t->slot, attr, app_t->width, app_t->height); 1326 1331 return self; 1327 1332 } … … 1354 1359 1355 1360 shoes_code 1356 shoes_app_start(VALUE appobj, char *uri) 1357 { 1361 shoes_app_start(VALUE appobj, VALUE allapps, char *uri) 1362 { 1363 int i; 1358 1364 shoes_code code; 1359 1365 shoes_app *app; 1366 1367 for (i = 0; i < RARRAY_LEN(allapps); i++) 1368 { 1369 VALUE appobj2 = rb_ary_entry(allapps, i); 1370 Data_Get_Struct(appobj2, shoes_app, app); 1371 1372 code = shoes_app_open(app, uri, appobj2 == appobj); 1373 if (code != SHOES_OK) 1374 return code; 1375 } 1376 1360 1377 Data_Get_Struct(appobj, shoes_app, app); 1361 1362 code = shoes_app_open(app); 1378 code = shoes_app_loop(app); 1363 1379 if (code != SHOES_OK) 1364 1380 return code; 1365 1381 1366 code = shoes_app_loop(app, uri); 1367 if (code != SHOES_OK) 1368 return code; 1369 1370 return shoes_app_close(app); 1382 for (i = 0; i < RARRAY_LEN(allapps); i++) 1383 { 1384 Data_Get_Struct(rb_ary_entry(allapps, i), shoes_app, app); 1385 1386 code = shoes_app_close(app); 1387 if (code != SHOES_OK) 1388 return code; 1389 } 1390 1391 return SHOES_OK; 1371 1392 } 1372 1393 1373 1394 shoes_code 1374 shoes_app_open(shoes_app *app )1395 shoes_app_open(shoes_app *app, char *path, unsigned char is_main) 1375 1396 { 1376 1397 shoes_code code = SHOES_OK; … … 1390 1411 g_signal_connect(G_OBJECT(gk->window), "motion-notify-event", 1391 1412 G_CALLBACK(shoes_app_gtk_motion), app); 1392 g_signal_connect(G_OBJECT(gk->window), "delete-event",1393 G_CALLBACK(gtk_main_quit), NULL);1394 1413 g_signal_connect(G_OBJECT(gk->window), "key-press-event", 1395 1414 G_CALLBACK(shoes_app_gtk_keypress), app); 1415 if (is_main) 1416 { 1417 g_signal_connect(G_OBJECT(gk->window), "delete-event", 1418 G_CALLBACK(gtk_main_quit), NULL); 1419 } 1396 1420 app->slot.canvas = gk->window; 1397 1421 #endif … … 1434 1458 InitCursor(); 1435 1459 1436 err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 1437 NewAEEventHandlerUPP(shoes_app_quartz_quit), 0, false); 1438 if (err != noErr) 1439 { 1440 QUIT("Out of memory.", 0); 1460 if (is_main) 1461 { 1462 err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 1463 NewAEEventHandlerUPP(shoes_app_quartz_quit), 0, false); 1464 if (err != noErr) 1465 { 1466 QUIT("Out of memory.", 0); 1467 } 1441 1468 } 1442 1469 … … 1545 1572 shoes_app_title(app, app->title); 1546 1573 1547 quit:1548 return code;1549 }1550 1551 shoes_code1552 shoes_app_loop(shoes_app *app, char *path)1553 {1554 shoes_code code = SHOES_OK;1555 1574 #ifndef SHOES_GTK 1556 1575 app->slot.controls = rb_ary_new(); … … 1561 1580 if (code != SHOES_OK) 1562 1581 return code; 1563 INFO("RUNNING LOOP.\n", 0); 1582 1583 #ifdef SHOES_WIN32 1584 ShowWindow(app->slot.window, SW_SHOWNORMAL); 1585 #endif 1586 1587 #ifdef SHOES_GTK 1588 gtk_widget_show_all(app->os.window); 1589 #endif 1564 1590 1565 1591 #ifdef SHOES_QUARTZ 1566 1592 ShowWindow(app->os.window); 1593 #endif 1594 1595 quit: 1596 return code; 1597 } 1598 1599 shoes_code 1600 shoes_app_loop(shoes_app *app) 1601 { 1602 shoes_code code = SHOES_OK; 1603 INFO("RUNNING LOOP.\n", 0); 1604 1605 #ifdef SHOES_QUARTZ 1567 1606 TextEncoding utf8Encoding, unicodeEncoding; 1568 1607 utf8Encoding = CreateTextEncoding(kTextEncodingUnicodeDefault, … … 1581 1620 { 1582 1621 OSStatus err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent); 1583 if (err == noErr) { SendEventToEventTarget (theEvent, theTarget); 1622 if (err == noErr) 1623 { 1624 SendEventToEventTarget (theEvent, theTarget); 1584 1625 ReleaseEvent(theEvent); 1585 1626 } … … 1592 1633 1593 1634 #ifdef SHOES_GTK 1594 gtk_widget_show_all(app->os.window);1595 1635 g_main_set_poll_func(shoes_app_g_poll); 1596 1636 gtk_main(); … … 1599 1639 #ifdef SHOES_WIN32 1600 1640 MSG msgs; 1601 ShowWindow(app->slot.window, SW_SHOWNORMAL);1602 1641 while (WM_QUIT != msgs.message) 1603 1642 { … … 1721 1760 if (NIL_P(rb_ary_entry(meth, 0))) 1722 1761 { 1723 VALUE script = shoes_dialog_open(app->canvas); 1724 if (NIL_P(script)) 1725 return SHOES_QUIT; 1726 rb_funcall(cShoes, rb_intern("load"), 1, script); 1727 meth = rb_funcall(cShoes, s_run, 1, app->location); 1762 VALUE app_block = rb_iv_get(app->self, "@main_app"); 1763 if (!NIL_P(app_block)) 1764 rb_ary_store(meth, 0, app_block); 1765 else 1766 { 1767 VALUE script = shoes_dialog_open(app->canvas); 1768 if (NIL_P(script)) 1769 return SHOES_QUIT; 1770 rb_funcall(cShoes, rb_intern("load"), 1, script); 1771 meth = rb_funcall(cShoes, s_run, 1, app->location); 1772 } 1728 1773 } 1729 1774 -
trunk/shoes/app.h
r348 r436 47 47 VALUE shoes_app_alloc(VALUE); 48 48 VALUE shoes_app_new(void); 49 shoes_code shoes_app_start(VALUE, char *);50 shoes_code shoes_app_open(shoes_app * );51 shoes_code shoes_app_loop(shoes_app * , char *);49 shoes_code shoes_app_start(VALUE, VALUE, char *); 50 shoes_code shoes_app_open(shoes_app *, char *, unsigned char); 51 shoes_code shoes_app_loop(shoes_app *); 52 52 shoes_code shoes_app_visit(shoes_app *, char *); 53 53 shoes_code shoes_app_paint(shoes_app *); -
trunk/shoes/world.c
r400 r436 68 68 shoes_load(char *path, char *uri) 69 69 { 70 VALUE appobj = shoes_app_new();70 shoes_code code = SHOES_QUIT; 71 71 72 72 if (path) … … 81 81 } 82 82 83 return shoes_app_start(appobj, uri); 83 if (!NIL_P(shoes_world->app)) 84 return shoes_app_start(shoes_world->app, shoes_world->apps, uri); 85 86 return SHOES_QUIT; 84 87 } 85 88
