1 /* 2 * Copyright (c) 2005-2006, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: 6 * DarkWyrm <darkwyrm@earthlink.net> 7 */ 8 #include "App.h" 9 #include "ResWindow.h" 10 #include <Entry.h> 11 12 int 13 main(void) 14 { 15 App app; 16 app.Run(); 17 return 0; 18 } 19 20 App::App(void) 21 : BApplication("application/x-vnd.Haiku-ResEdit"), 22 fWindowCount(0) 23 { 24 fOpenPanel = new BFilePanel(); 25 fSavePanel = new BFilePanel(B_SAVE_PANEL); 26 } 27 28 29 App::~App(void) 30 { 31 delete fOpenPanel; 32 delete fSavePanel; 33 } 34 35 36 void 37 App::ReadyToRun(void) 38 { 39 /* 40 if (fWindowCount < 1) { 41 ResWindow *win = new ResWindow(BRect(50,100,600,400)); 42 win->Show(); 43 } 44 */ 45 if (fWindowCount < 1) { 46 BEntry entry("/boot/develop/projects/ResEdit/CapitalBe.rsrc"); 47 entry_ref ref; 48 entry.GetRef(&ref); 49 ResWindow *win = new ResWindow(BRect(50,100,600,400),&ref); 50 win->Show(); 51 } 52 } 53 54 55 void 56 App::MessageReceived(BMessage *msg) 57 { 58 switch(msg->what) { 59 case M_REGISTER_WINDOW: { 60 fWindowCount++; 61 break; 62 } 63 case M_UNREGISTER_WINDOW: { 64 fWindowCount--; 65 if (fWindowCount == 0) 66 PostMessage(B_QUIT_REQUESTED); 67 break; 68 } 69 case M_SHOW_OPEN_PANEL: { 70 // Don't do anything if it's already open 71 if (fOpenPanel->IsShowing()) 72 break; 73 fOpenPanel->Show(); 74 break; 75 } 76 default: 77 BApplication::MessageReceived(msg); 78 } 79 } 80 81 82 void 83 App::RefsReceived(BMessage *msg) 84 { 85 entry_ref ref; 86 int32 i=0; 87 while (msg->FindRef("refs",i,&ref) == B_OK) { 88 ResWindow *win = new ResWindow(BRect(50,100,600,400),&ref); 89 win->Show(); 90 i++; 91 } 92 } 93 94 95 bool 96 App::QuitRequested(void) 97 { 98 for (int32 i = 0; i < CountWindows(); i++) { 99 BWindow *win = WindowAt(i); 100 if (fOpenPanel->Window() == win || fSavePanel->Window() == win) 101 continue; 102 103 if (!win->QuitRequested()) 104 return false; 105 } 106 107 return true; 108 } 109 110