Changeset 436

Show
Ignore:
Timestamp:
02/29/2008 01:37:22 (6 months ago)
Author:
why
Message:
  • shoes/app.c: initial work to get multiple Shoes.app blocks to work at once. this breaks alot of stuff, sorry!
Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/shoes.rb

    r426 r436  
    103103 
    104104  @mounts = [] 
    105   @main_app = nil 
    106105 
    107106  OPTS = OptionParser.new do |opts| 
     
    110109    opts.on("-m", "--manual", 
    111110            "Open the built-in manual.") do 
    112       @main_app = Shoes::Help 
     111      Shoes.app(&Shoes::Help) 
    113112    end 
    114113 
    115114    opts.on("-s", "--shy DIRECTORY", 
    116115            "Compress a directory into a Shoes YAML (SHY) archive.") do |s| 
    117       @main_app = ShyMake.call(s) 
     116      Shoes.app(&ShyMake.call(s)) 
    118117    end 
    119118 
     
    152151    end 
    153152    case uri.path when "/" 
    154       [@main_app] 
     153      [nil] 
    155154    when SHOES_URL_RE 
    156155      [proc { eval(URI("http://#$1:53045#$2").read) }] 
  • trunk/shoes/app.c

    r433 r436  
    13151315{ 
    13161316  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; 
    13181323 
    13191324  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); 
    13261331  return self; 
    13271332} 
     
    13541359 
    13551360shoes_code 
    1356 shoes_app_start(VALUE appobj, char *uri) 
    1357 { 
     1361shoes_app_start(VALUE appobj, VALUE allapps, char *uri) 
     1362{ 
     1363  int i; 
    13581364  shoes_code code; 
    13591365  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 
    13601377  Data_Get_Struct(appobj, shoes_app, app); 
    1361  
    1362   code = shoes_app_open(app); 
     1378  code = shoes_app_loop(app); 
    13631379  if (code != SHOES_OK) 
    13641380    return code; 
    13651381 
    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; 
    13711392} 
    13721393 
    13731394shoes_code 
    1374 shoes_app_open(shoes_app *app) 
     1395shoes_app_open(shoes_app *app, char *path, unsigned char is_main) 
    13751396{ 
    13761397  shoes_code code = SHOES_OK; 
     
    13901411  g_signal_connect(G_OBJECT(gk->window), "motion-notify-event",  
    13911412                   G_CALLBACK(shoes_app_gtk_motion), app); 
    1392   g_signal_connect(G_OBJECT(gk->window), "delete-event", 
    1393                    G_CALLBACK(gtk_main_quit), NULL); 
    13941413  g_signal_connect(G_OBJECT(gk->window), "key-press-event", 
    13951414                   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  } 
    13961420  app->slot.canvas = gk->window; 
    13971421#endif 
     
    14341458  InitCursor(); 
    14351459 
    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    } 
    14411468  } 
    14421469 
     
    15451572  shoes_app_title(app, app->title); 
    15461573 
    1547 quit: 
    1548   return code; 
    1549 } 
    1550  
    1551 shoes_code 
    1552 shoes_app_loop(shoes_app *app, char *path) 
    1553 { 
    1554   shoes_code code = SHOES_OK; 
    15551574#ifndef SHOES_GTK 
    15561575  app->slot.controls = rb_ary_new(); 
     
    15611580  if (code != SHOES_OK) 
    15621581    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 
    15641590 
    15651591#ifdef SHOES_QUARTZ 
    15661592  ShowWindow(app->os.window); 
     1593#endif 
     1594 
     1595quit: 
     1596  return code; 
     1597} 
     1598 
     1599shoes_code 
     1600shoes_app_loop(shoes_app *app) 
     1601{ 
     1602  shoes_code code = SHOES_OK; 
     1603  INFO("RUNNING LOOP.\n", 0); 
     1604 
     1605#ifdef SHOES_QUARTZ 
    15671606  TextEncoding utf8Encoding, unicodeEncoding; 
    15681607  utf8Encoding = CreateTextEncoding(kTextEncodingUnicodeDefault, 
     
    15811620  { 
    15821621    OSStatus err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent); 
    1583     if (err == noErr)                                                                                                                 {                                                                                                                                   SendEventToEventTarget (theEvent, theTarget); 
     1622    if (err == noErr) 
     1623    { 
     1624      SendEventToEventTarget (theEvent, theTarget); 
    15841625      ReleaseEvent(theEvent); 
    15851626    } 
     
    15921633 
    15931634#ifdef SHOES_GTK 
    1594   gtk_widget_show_all(app->os.window); 
    15951635  g_main_set_poll_func(shoes_app_g_poll); 
    15961636  gtk_main(); 
     
    15991639#ifdef SHOES_WIN32 
    16001640  MSG msgs; 
    1601   ShowWindow(app->slot.window, SW_SHOWNORMAL); 
    16021641  while (WM_QUIT != msgs.message) 
    16031642  { 
     
    17211760  if (NIL_P(rb_ary_entry(meth, 0))) 
    17221761  { 
    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    } 
    17281773  } 
    17291774 
  • trunk/shoes/app.h

    r348 r436  
    4747VALUE shoes_app_alloc(VALUE); 
    4848VALUE 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 *); 
     49shoes_code shoes_app_start(VALUE, VALUE, char *); 
     50shoes_code shoes_app_open(shoes_app *, char *, unsigned char); 
     51shoes_code shoes_app_loop(shoes_app *); 
    5252shoes_code shoes_app_visit(shoes_app *, char *); 
    5353shoes_code shoes_app_paint(shoes_app *); 
  • trunk/shoes/world.c

    r400 r436  
    6868shoes_load(char *path, char *uri) 
    6969{ 
    70   VALUE appobj = shoes_app_new(); 
     70  shoes_code code = SHOES_QUIT; 
    7171 
    7272  if (path) 
     
    8181  } 
    8282 
    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; 
    8487} 
    8588