// ContainerWindow.cpp // Generated by Interface Elements (Window v2.3) on Feb 14 2004 // This is a user written class and will not be overwritten. #include "ContainerWindow.h" #include #include extern const char *PREFS_BACKSTORE_PATH; ContainerWindow :: ContainerWindow(BPositionIO *stream) : IEWindow("ContainerWindow") { Lock(); CreateViewBitmap(); fArchiveStream = stream; fShelf = new BShelf(fArchiveStream, fContainerView); // Attach fShelf to fContainerView fShelf -> SetDisplaysZombies(true); fArchiveStream -> Seek(0, SEEK_SET); fRemoveButton = (BButton *)FindView("RemoveButton" ); fTestButton = (BButton *)FindView("TestButton" ); GetPrefs(); Unlock(); Show(); } ContainerWindow :: ~ContainerWindow(void) { SetPrefs(); if (fPrefs != NULL) delete fPrefs; // now prefs are saved } bool ContainerWindow :: QuitRequested() { // long c = be_app->CountWindows(); // if (c == 1) be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED); delete fShelf; // by deleting the Shelf we'll save the state fShelf = NULL; return true; } // Handling of user interface and other events void ContainerWindow::MessageReceived(BMessage *message) { switch(message->what) { case IE_CONTAINERWINDOW_MAINMENU_FILE_NEW: // "New" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_FILE_OPEN___: // "Open…" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE: // "Save" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE_AS___: // "Save As…" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_FILE_ABOUT___: // "About…" is selected from menu… PostMessage(B_ABOUT_REQUESTED); break; case IE_CONTAINERWINDOW_MAINMENU_FILE_QUIT: // "Quit" is selected from menu… PostMessage(B_QUIT_REQUESTED); break; case IE_CONTAINERWINDOW_MAINMENU_EDIT_UNDO: // "Undo" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_EDIT_CUT: // "Cut" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_EDIT_COPY: // "Copy" is selected from menu… break; case IE_CONTAINERWINDOW_MAINMENU_EDIT_PASTE: // "Paste" is selected from menu… break; case IE_CONTAINERWINDOW_TESTBUTTON: // 'TestButton' is pressed... { BMessage msg = BMessage(TEST_REPLICANT); msg.AddBool("Test",true); be_app ->PostMessage(&msg,be_app); // Send Info to App QuitRequested(); } break; case IE_CONTAINERWINDOW_REMOVEBUTTON: // 'RemoveButton' is pressed... { BMessage msg = BMessage(CLEAR_FILE); msg.AddBool("Remove",true); be_app ->PostMessage(&msg,be_app); // Send Info to App QuitRequested(); } break; case B_ABOUT_REQUESTED: { BAlert *alert = new BAlert("", "XContainer (H.Reh, dr.hartmut.reh@gmx.de) " "\n" "\n" "Based upon Container Demo from Be Inc." "\n" "The GUI was created with InterfaceElements (Attila Mezei)" "\n" "Please read the ***Be Sample Code License*** " "\n" ,"OK"); alert -> Go(NULL); } break; default: BWindow::MessageReceived(message); break; } } // Update the menu items before they appear on screen void ContainerWindow::MenusBeginning() { // Complete the SetEnabled argument or do anything with the source below... KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_NEW) ->SetEnabled(false); // "New" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_OPEN___) ->SetEnabled(false); // "Open…" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE) ->SetEnabled(false); // "Save" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE_AS___) ->SetEnabled(false); // "Save As…" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_ABOUT___) ->SetEnabled(true); // "About…" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_QUIT) ->SetEnabled(true); // "Quit" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_UNDO) ->SetEnabled(false); // "Undo" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_CUT) ->SetEnabled(false); // "Cut" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_COPY) ->SetEnabled(false); // "Copy" KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_PASTE) ->SetEnabled(false); // "Paste" } void ContainerWindow :: CreateViewBitmap() { // create background bitmap BBitmap *bitmap = NULL; fContainerView = NULL; bitmap = BTranslationUtils :: GetBitmap('JPEG',"DropZone.jpeg"); // load bitmap from resource fContainerView = (BView *)FindView("ContainerView"); if ( (bitmap != NULL) && (fContainerView != NULL) ) fContainerView -> SetViewBitmap(bitmap); delete bitmap; } void ContainerWindow :: GetPrefs() { status_t err; BRect windFrame; fPrefs = new TPreferences ("XContainer/preferences"); // name of prefs-file if (fPrefs -> InitCheck() != B_OK) // if no prefs-> create new { windFrame = Frame(); // get window frame fPrefs -> SetRect ("WindowFrame", windFrame ); } err = (fPrefs -> FindRect ("WindowFrame", &windFrame) ); if (err == B_OK) { ResizeTo(windFrame.Width(), windFrame.Height() ); // window position and size MoveTo(windFrame.left, windFrame.top); } } void ContainerWindow :: SetPrefs() { fPrefs -> SetRect ("WindowFrame", Frame() ); } void ContainerWindow :: EnableRemoveButton(bool enable) { fRemoveButton -> SetEnabled(enable); } void ContainerWindow :: EnableTestButton(bool enable) { fTestButton -> SetEnabled(enable); }