1cdb89ebbSMatthew Wilber /*****************************************************************************/ 2cdb89ebbSMatthew Wilber // ShowImageWindow 3ad13f387SMichael Pfeiffer // Written by Fernando Francisco de Oliveira, Michael Wilber, Michael Pfeiffer 4cdb89ebbSMatthew Wilber // 5cdb89ebbSMatthew Wilber // ShowImageWindow.cpp 6cdb89ebbSMatthew Wilber // 7cdb89ebbSMatthew Wilber // 8cdb89ebbSMatthew Wilber // Copyright (c) 2003 OpenBeOS Project 9cdb89ebbSMatthew Wilber // 10cdb89ebbSMatthew Wilber // Permission is hereby granted, free of charge, to any person obtaining a 11cdb89ebbSMatthew Wilber // copy of this software and associated documentation files (the "Software"), 12cdb89ebbSMatthew Wilber // to deal in the Software without restriction, including without limitation 13cdb89ebbSMatthew Wilber // the rights to use, copy, modify, merge, publish, distribute, sublicense, 14cdb89ebbSMatthew Wilber // and/or sell copies of the Software, and to permit persons to whom the 15cdb89ebbSMatthew Wilber // Software is furnished to do so, subject to the following conditions: 16cdb89ebbSMatthew Wilber // 17cdb89ebbSMatthew Wilber // The above copyright notice and this permission notice shall be included 18cdb89ebbSMatthew Wilber // in all copies or substantial portions of the Software. 19cdb89ebbSMatthew Wilber // 20cdb89ebbSMatthew Wilber // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21cdb89ebbSMatthew Wilber // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22cdb89ebbSMatthew Wilber // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23cdb89ebbSMatthew Wilber // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24cdb89ebbSMatthew Wilber // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25cdb89ebbSMatthew Wilber // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26cdb89ebbSMatthew Wilber // DEALINGS IN THE SOFTWARE. 27cdb89ebbSMatthew Wilber /*****************************************************************************/ 2813afa642SPhil Greenway 2907caaa8eSMatthew Wilber #include <stdio.h> 3013afa642SPhil Greenway #include <Application.h> 3113afa642SPhil Greenway #include <Bitmap.h> 32fc0a275bSMatthew Wilber #include <BitmapStream.h> 3313afa642SPhil Greenway #include <Entry.h> 34fc0a275bSMatthew Wilber #include <File.h> 3513afa642SPhil Greenway #include <Menu.h> 3613afa642SPhil Greenway #include <MenuBar.h> 3713afa642SPhil Greenway #include <MenuItem.h> 3813afa642SPhil Greenway #include <Path.h> 3913afa642SPhil Greenway #include <ScrollView.h> 4013afa642SPhil Greenway #include <TranslationUtils.h> 4113afa642SPhil Greenway #include <TranslatorRoster.h> 4213afa642SPhil Greenway #include <Alert.h> 4307caaa8eSMatthew Wilber #include <SupportDefs.h> 44ad13f387SMichael Pfeiffer #include <Screen.h> 45d10d5947SMichael Pfeiffer #include <Roster.h> 46780d8a62SMichael Pfeiffer #include <PrintJob.h> 47c60a8d8cSPhilippe Houdoin #include <Clipboard.h> 4813afa642SPhil Greenway 49d3046f7dSMichael Pfeiffer #include "ShowImageApp.h" 5013afa642SPhil Greenway #include "ShowImageConstants.h" 5113afa642SPhil Greenway #include "ShowImageWindow.h" 5213afa642SPhil Greenway #include "ShowImageView.h" 5313afa642SPhil Greenway #include "ShowImageStatusView.h" 547c0bc4a2SMichael Pfeiffer #include "EntryMenuItem.h" 5513afa642SPhil Greenway 56a8fc7138SMichael Pfeiffer 57a8fc7138SMichael Pfeiffer // Implementation of RecentDocumentsMenu 58a8fc7138SMichael Pfeiffer 59a8fc7138SMichael Pfeiffer RecentDocumentsMenu::RecentDocumentsMenu(const char *title, menu_layout layout = B_ITEMS_IN_COLUMN) 60a8fc7138SMichael Pfeiffer : BMenu(title, layout) 61a8fc7138SMichael Pfeiffer { 62a8fc7138SMichael Pfeiffer } 63a8fc7138SMichael Pfeiffer 64a8fc7138SMichael Pfeiffer bool 65a8fc7138SMichael Pfeiffer RecentDocumentsMenu::AddDynamicItem(add_state s) 66a8fc7138SMichael Pfeiffer { 67a8fc7138SMichael Pfeiffer if (s != B_INITIAL_ADD) return false; 68a8fc7138SMichael Pfeiffer 69a8fc7138SMichael Pfeiffer BMenuItem *item; 70a8fc7138SMichael Pfeiffer BMessage list, *msg; 71a8fc7138SMichael Pfeiffer entry_ref ref; 72a8fc7138SMichael Pfeiffer char name[B_FILE_NAME_LENGTH]; 73a8fc7138SMichael Pfeiffer 74a8fc7138SMichael Pfeiffer while ((item = RemoveItem((int32)0)) != NULL) { 75a8fc7138SMichael Pfeiffer delete item; 76a8fc7138SMichael Pfeiffer } 77a8fc7138SMichael Pfeiffer 78a8fc7138SMichael Pfeiffer be_roster->GetRecentDocuments(&list, 20, NULL, APP_SIG); 79a8fc7138SMichael Pfeiffer for (int i = 0; list.FindRef("refs", i, &ref) == B_OK; i++) { 80a8fc7138SMichael Pfeiffer BEntry entry(&ref); 81a8fc7138SMichael Pfeiffer if (entry.Exists() && entry.GetName(name) == B_OK) { 82a8fc7138SMichael Pfeiffer msg = new BMessage(B_REFS_RECEIVED); 83a8fc7138SMichael Pfeiffer msg->AddRef("refs", &ref); 84a8fc7138SMichael Pfeiffer item = new EntryMenuItem(&ref, name, msg, 0, 0); 85a8fc7138SMichael Pfeiffer AddItem(item); 86a8fc7138SMichael Pfeiffer item->SetTarget(be_app, NULL); 87a8fc7138SMichael Pfeiffer } 88a8fc7138SMichael Pfeiffer } 89a8fc7138SMichael Pfeiffer 90a8fc7138SMichael Pfeiffer return false; 91a8fc7138SMichael Pfeiffer } 92a8fc7138SMichael Pfeiffer 93a8fc7138SMichael Pfeiffer 94a8fc7138SMichael Pfeiffer // Implementation of ShowImageWindow 95a8fc7138SMichael Pfeiffer 9603839579SMatthew Wilber ShowImageWindow::ShowImageWindow(const entry_ref *pref) 9716cb4890SMatthew Wilber : BWindow(BRect(5, 24, 350, 250), "", B_DOCUMENT_WINDOW, 0) 9813afa642SPhil Greenway { 99d3046f7dSMichael Pfeiffer fSavePanel = NULL; 100ee7b4f39SMatthew Wilber fModified = false; 101ad13f387SMichael Pfeiffer fFullScreen = false; 102d3046f7dSMichael Pfeiffer fShowCaption = true; 103780d8a62SMichael Pfeiffer fPrintSettings = NULL; 104d3046f7dSMichael Pfeiffer fImageView = NULL; 105d3046f7dSMichael Pfeiffer fSlideShowDelay = NULL; 106d3046f7dSMichael Pfeiffer 107d3046f7dSMichael Pfeiffer LoadSettings(); 108fc0a275bSMatthew Wilber 10913afa642SPhil Greenway // create menu bar 110d3046f7dSMichael Pfeiffer fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar"); 111d3046f7dSMichael Pfeiffer LoadMenus(fBar); 112d3046f7dSMichael Pfeiffer AddChild(fBar); 11313afa642SPhil Greenway 11413afa642SPhil Greenway BRect viewFrame = Bounds(); 115d3046f7dSMichael Pfeiffer viewFrame.top = fBar->Bounds().bottom + 1; 11613afa642SPhil Greenway viewFrame.right -= B_V_SCROLL_BAR_WIDTH; 11713afa642SPhil Greenway viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT; 11813afa642SPhil Greenway 11913afa642SPhil Greenway // create the image view 120d3046f7dSMichael Pfeiffer fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL, 1217eca0987SMichael Pfeiffer B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED); 12213afa642SPhil Greenway // wrap a scroll view around the view 123d3046f7dSMichael Pfeiffer BScrollView *pscrollView = new BScrollView("image_scroller", fImageView, 124cdb89ebbSMatthew Wilber B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER); 125cdb89ebbSMatthew Wilber AddChild(pscrollView); 12613afa642SPhil Greenway 12707caaa8eSMatthew Wilber const int32 kstatusWidth = 190; 128cdb89ebbSMatthew Wilber BRect rect; 12913afa642SPhil Greenway rect = Bounds(); 13013afa642SPhil Greenway rect.top = viewFrame.bottom + 1; 13107caaa8eSMatthew Wilber rect.left = viewFrame.left + kstatusWidth; 13213afa642SPhil Greenway rect.right = viewFrame.right; 133cdb89ebbSMatthew Wilber BScrollBar *phscroll; 134d3046f7dSMichael Pfeiffer phscroll = new BScrollBar(rect, "hscroll", fImageView, 0, 150, 135cdb89ebbSMatthew Wilber B_HORIZONTAL); 136cdb89ebbSMatthew Wilber AddChild(phscroll); 13713afa642SPhil Greenway 13813afa642SPhil Greenway rect.left = 0; 13907caaa8eSMatthew Wilber rect.right = kstatusWidth - 1; 140d3046f7dSMichael Pfeiffer fStatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM, 141cdb89ebbSMatthew Wilber B_WILL_DRAW); 142d3046f7dSMichael Pfeiffer fStatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 143d3046f7dSMichael Pfeiffer AddChild(fStatusView); 14413afa642SPhil Greenway 14513afa642SPhil Greenway rect = Bounds(); 14613afa642SPhil Greenway rect.top = viewFrame.top; 14713afa642SPhil Greenway rect.left = viewFrame.right + 1; 14813afa642SPhil Greenway rect.bottom = viewFrame.bottom; 149cdb89ebbSMatthew Wilber BScrollBar *pvscroll; 150d3046f7dSMichael Pfeiffer pvscroll = new BScrollBar(rect, "vscroll", fImageView, 0, 150, B_VERTICAL); 151cdb89ebbSMatthew Wilber AddChild(pvscroll); 15213afa642SPhil Greenway 15303839579SMatthew Wilber SetSizeLimits(250, 100000, 100, 100000); 15413afa642SPhil Greenway 15513afa642SPhil Greenway // finish creating window 156d3046f7dSMichael Pfeiffer fImageView->SetImage(pref); 1577eca0987SMichael Pfeiffer 158780d8a62SMichael Pfeiffer if (InitCheck() == B_OK) { 159d3046f7dSMichael Pfeiffer // add View menu here so it can access ShowImageView methods 160d3046f7dSMichael Pfeiffer BMenu* pmenu = new BMenu("View"); 161d3046f7dSMichael Pfeiffer BuildViewMenu(pmenu); 162d3046f7dSMichael Pfeiffer fBar->AddItem(pmenu); 163a8fc7138SMichael Pfeiffer MarkMenuItem(fBar, MSG_DITHER_IMAGE, fImageView->GetDither()); 164780d8a62SMichael Pfeiffer UpdateTitle(); 165780d8a62SMichael Pfeiffer 1667eca0987SMichael Pfeiffer SetPulseRate(100000); // every 1/10 second; ShowImageView needs it for marching ants 16703839579SMatthew Wilber 168d3046f7dSMichael Pfeiffer fImageView->FlushToLeftTop(); 169d3046f7dSMichael Pfeiffer WindowRedimension(fImageView->GetBitmap()); 170d3046f7dSMichael Pfeiffer fImageView->MakeFocus(true); // to receive KeyDown messages 17113afa642SPhil Greenway Show(); 172d10d5947SMichael Pfeiffer } else { 173e6a50d9cSMichael Pfeiffer BAlert* alert; 174e6a50d9cSMichael Pfeiffer alert = new BAlert("ShowImage", 175e6a50d9cSMichael Pfeiffer "Could not load image! Either the file or an image translator for it does not exist.", 176e6a50d9cSMichael Pfeiffer "OK", NULL, NULL, 177e6a50d9cSMichael Pfeiffer B_WIDTH_AS_USUAL, B_INFO_ALERT); 178e6a50d9cSMichael Pfeiffer alert->Go(); 179d10d5947SMichael Pfeiffer // exit if file could not be opened 180d10d5947SMichael Pfeiffer Quit(); 181d10d5947SMichael Pfeiffer } 182402c09e5SMatthew Wilber 183402c09e5SMatthew Wilber // Tell application object to query the clipboard 184402c09e5SMatthew Wilber // and tell this window if it contains interesting data or not 185402c09e5SMatthew Wilber be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED); 18613afa642SPhil Greenway } 18713afa642SPhil Greenway 18813afa642SPhil Greenway ShowImageWindow::~ShowImageWindow() 18913afa642SPhil Greenway { 19013afa642SPhil Greenway } 19113afa642SPhil Greenway 192cdb89ebbSMatthew Wilber status_t 193cdb89ebbSMatthew Wilber ShowImageWindow::InitCheck() 19413afa642SPhil Greenway { 195d3046f7dSMichael Pfeiffer if (!fImageView || fImageView->GetBitmap() == NULL) 19613afa642SPhil Greenway return B_ERROR; 197cdb89ebbSMatthew Wilber else 19813afa642SPhil Greenway return B_OK; 19913afa642SPhil Greenway } 200cdb89ebbSMatthew Wilber 201cdb89ebbSMatthew Wilber void 202cdb89ebbSMatthew Wilber ShowImageWindow::UpdateTitle() 20313afa642SPhil Greenway { 204e6a50d9cSMichael Pfeiffer BString path; 205d3046f7dSMichael Pfeiffer fImageView->GetPath(&path); 206e6a50d9cSMichael Pfeiffer SetTitle(path.String()); 20713afa642SPhil Greenway } 20813afa642SPhil Greenway 209cdb89ebbSMatthew Wilber void 210da87390fSMichael Pfeiffer ShowImageWindow::BuildViewMenu(BMenu *pmenu) 211da87390fSMichael Pfeiffer { 212da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Slide Show", MSG_SLIDE_SHOW, 0, 0, 'W', true); 213d3046f7dSMichael Pfeiffer MarkMenuItem(pmenu, MSG_SLIDE_SHOW, fImageView->SlideShowStarted()); 214da87390fSMichael Pfeiffer BMenu* pDelay = new BMenu("Slide Delay"); 215d3046f7dSMichael Pfeiffer if (fSlideShowDelay == NULL) { 216d3046f7dSMichael Pfeiffer fSlideShowDelay = pDelay; 217da87390fSMichael Pfeiffer } 218da87390fSMichael Pfeiffer pDelay->SetRadioMode(true); 219da87390fSMichael Pfeiffer // Note: ShowImage loades images in window thread so it becomes unresponsive if 220da87390fSMichael Pfeiffer // slide show delay is too short! (Especially if loading the image takes as long as 221da87390fSMichael Pfeiffer // or longer than the slide show delay). Should load in background thread! 222d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Three Seconds", 3); 223d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Four Second", 4); 224d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Five Seconds", 5); 225d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Six Seconds", 6); 226d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Seven Seconds", 7); 227d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Eight Seconds", 8); 228d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Nine Seconds", 9); 229d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Ten Seconds", 10); 230d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Twenty Seconds", 20); 231da87390fSMichael Pfeiffer pmenu->AddItem(pDelay); 232da87390fSMichael Pfeiffer pmenu->AddSeparatorItem(); 233da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Original Size", MSG_ORIGINAL_SIZE, 0, 0, 'W', true); 234da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Zoom In", MSG_ZOOM_IN, '+', 0, 'W', true); 235da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Zoom Out", MSG_ZOOM_OUT, '-', 0, 'W', true); 236d3046f7dSMichael Pfeiffer pmenu->AddSeparatorItem(); 23781b9c776SMichael Pfeiffer AddItemMenu(pmenu, "Scale Bilinear", MSG_SCALE_BILINEAR, 0, 0, 'W', true); 238da87390fSMichael Pfeiffer pmenu->AddSeparatorItem(); 23919c76de4SMichael Pfeiffer AddItemMenu(pmenu, "Shrink to Window", MSG_SHRINK_TO_WINDOW, 0, 0, 'W', true); 24019c76de4SMichael Pfeiffer AddItemMenu(pmenu, "Zoom to Window", MSG_ZOOM_TO_WINDOW, 0, 0, 'W', true); 241d3046f7dSMichael Pfeiffer pmenu->AddSeparatorItem(); 24230060f17SMatthew Wilber AddItemMenu(pmenu, "Full Screen", MSG_FULL_SCREEN, 'F', 0, 'W', true); 24381b9c776SMichael Pfeiffer MarkMenuItem(pmenu, MSG_FULL_SCREEN, fFullScreen); 24430060f17SMatthew Wilber BMessage *pFullScreen = new BMessage(MSG_FULL_SCREEN); 24530060f17SMatthew Wilber AddShortcut(B_ENTER, 0, pFullScreen); 24630060f17SMatthew Wilber 247da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Show Caption in Full Screen Mode", MSG_SHOW_CAPTION, 0, 0, 'W', true); 248da87390fSMichael Pfeiffer MarkMenuItem(pmenu, MSG_SHOW_CAPTION, fShowCaption); 249da87390fSMichael Pfeiffer 25019c76de4SMichael Pfeiffer bool shrink, zoom, enabled; 251d3046f7dSMichael Pfeiffer MarkMenuItem(pmenu, MSG_SCALE_BILINEAR, fImageView->GetScaleBilinear()); 252d3046f7dSMichael Pfeiffer shrink = fImageView->GetShrinkToBounds(); 253d3046f7dSMichael Pfeiffer zoom = fImageView->GetZoomToBounds(); 25419c76de4SMichael Pfeiffer MarkMenuItem(pmenu, MSG_SHRINK_TO_WINDOW, shrink); 25519c76de4SMichael Pfeiffer MarkMenuItem(pmenu, MSG_ZOOM_TO_WINDOW, zoom); 25619c76de4SMichael Pfeiffer enabled = !(shrink || zoom); 25719c76de4SMichael Pfeiffer EnableMenuItem(pmenu, MSG_ORIGINAL_SIZE, enabled); 25819c76de4SMichael Pfeiffer EnableMenuItem(pmenu, MSG_ZOOM_IN, enabled); 25919c76de4SMichael Pfeiffer EnableMenuItem(pmenu, MSG_ZOOM_OUT, enabled); 260da87390fSMichael Pfeiffer } 261da87390fSMichael Pfeiffer 262da87390fSMichael Pfeiffer void 263cdb89ebbSMatthew Wilber ShowImageWindow::LoadMenus(BMenuBar *pbar) 26413afa642SPhil Greenway { 265cdb89ebbSMatthew Wilber BMenu *pmenu = new BMenu("File"); 266a8fc7138SMichael Pfeiffer fOpenMenu = new RecentDocumentsMenu("Open"); 267d3046f7dSMichael Pfeiffer pmenu->AddItem(fOpenMenu); 268d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetTrigger('O'); 269d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetMessage(new BMessage(MSG_FILE_OPEN)); 270d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetTarget(be_app); 271d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetShortcut('O', 0); 272cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 273780d8a62SMichael Pfeiffer BMenu *pmenuSaveAs = new BMenu("Save As" B_UTF8_ELLIPSIS, B_ITEMS_IN_COLUMN); 274cdb89ebbSMatthew Wilber BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP); 275fc0a275bSMatthew Wilber // Fill Save As submenu with all types that can be converted 276fc0a275bSMatthew Wilber // to from the Be bitmap image format 277cdb89ebbSMatthew Wilber pmenu->AddItem(pmenuSaveAs); 278cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Close", MSG_CLOSE, 'W', 0, 'W', true); 279cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 280780d8a62SMichael Pfeiffer AddItemMenu(pmenu, "Page Setup" B_UTF8_ELLIPSIS, MSG_PAGE_SETUP, 0, 0, 'W', true); 281780d8a62SMichael Pfeiffer AddItemMenu(pmenu, "Print" B_UTF8_ELLIPSIS, MSG_PREPARE_PRINT, 0, 0, 'W', true); 282780d8a62SMichael Pfeiffer pmenu->AddSeparatorItem(); 283780d8a62SMichael Pfeiffer AddItemMenu(pmenu, "About ShowImage" B_UTF8_ELLIPSIS, B_ABOUT_REQUESTED, 0, 0, 'A', true); 284cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 285cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true); 286cdb89ebbSMatthew Wilber pbar->AddItem(pmenu); 28713afa642SPhil Greenway 288cdb89ebbSMatthew Wilber pmenu = new BMenu("Edit"); 289cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Undo", B_UNDO, 'Z', 0, 'W', false); 290cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 291cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Cut", B_CUT, 'X', 0, 'W', false); 2928ad30bcfSMatthew Wilber AddItemMenu(pmenu, "Copy", B_COPY, 'C', 0, 'W', false); 293cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Paste", B_PASTE, 'V', 0, 'W', false); 294da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Clear", MSG_CLEAR_SELECT, 0, 0, 'W', false); 295cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 296d10d5947SMichael Pfeiffer AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', true); 297cdb89ebbSMatthew Wilber pbar->AddItem(pmenu); 29813afa642SPhil Greenway 299d3046f7dSMichael Pfeiffer pmenu = fBrowseMenu = new BMenu("Browse"); 3002cb9af89SMatthew Wilber AddItemMenu(pmenu, "First Page", MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, 'W', true); 3012cb9af89SMatthew Wilber AddItemMenu(pmenu, "Last Page", MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, 'W', true); 3022cb9af89SMatthew Wilber AddItemMenu(pmenu, "Next Page", MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, 'W', true); 3032cb9af89SMatthew Wilber AddItemMenu(pmenu, "Previous Page", MSG_PAGE_PREV, B_LEFT_ARROW, 0, 'W', true); 304d3046f7dSMichael Pfeiffer fGoToPageMenu = new BMenu("Go To Page"); 3055e427b6aSMichael Pfeiffer fGoToPageMenu->SetRadioMode(true); 306d3046f7dSMichael Pfeiffer pmenu->AddItem(fGoToPageMenu); 307e6a50d9cSMichael Pfeiffer pmenu->AddSeparatorItem(); 308e6a50d9cSMichael Pfeiffer AddItemMenu(pmenu, "Next File", MSG_FILE_NEXT, B_DOWN_ARROW, 0, 'W', true); 309e6a50d9cSMichael Pfeiffer AddItemMenu(pmenu, "Previous File", MSG_FILE_PREV, B_UP_ARROW, 0, 'W', true); 31003839579SMatthew Wilber pbar->AddItem(pmenu); 31103839579SMatthew Wilber 312cdb89ebbSMatthew Wilber pmenu = new BMenu("Image"); 313cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true); 314ad13f387SMichael Pfeiffer pmenu->AddSeparatorItem(); 315bf461dbeSMatthew Wilber AddItemMenu(pmenu, "Rotate +90", MSG_ROTATE_90, ']', 0, 'W', true); 316bf461dbeSMatthew Wilber AddItemMenu(pmenu, "Rotate -90", MSG_ROTATE_270, '[', 0, 'W', true); 317ad13f387SMichael Pfeiffer pmenu->AddSeparatorItem(); 318ad13f387SMichael Pfeiffer AddItemMenu(pmenu, "Mirror Vertical", MSG_MIRROR_VERTICAL, 0, 0, 'W', true); 319ad13f387SMichael Pfeiffer AddItemMenu(pmenu, "Mirror Horizontal", MSG_MIRROR_HORIZONTAL, 0, 0, 'W', true); 320ad13f387SMichael Pfeiffer pmenu->AddSeparatorItem(); 321ad13f387SMichael Pfeiffer AddItemMenu(pmenu, "Invert", MSG_INVERT, 0, 0, 'W', true); 322ad13f387SMichael Pfeiffer pbar->AddItem(pmenu); 32313afa642SPhil Greenway } 32413afa642SPhil Greenway 325cdb89ebbSMatthew Wilber BMenuItem * 326cdb89ebbSMatthew Wilber ShowImageWindow::AddItemMenu(BMenu *pmenu, char *caption, long unsigned int msg, 327cdb89ebbSMatthew Wilber char shortcut, uint32 modifier, char target, bool benabled) 328cdb89ebbSMatthew Wilber { 329cdb89ebbSMatthew Wilber BMenuItem* pitem; 3302cb9af89SMatthew Wilber pitem = new BMenuItem(caption, new BMessage(msg), shortcut, modifier); 33113afa642SPhil Greenway 33213afa642SPhil Greenway if (target == 'A') 333cdb89ebbSMatthew Wilber pitem->SetTarget(be_app); 334da87390fSMichael Pfeiffer else 335da87390fSMichael Pfeiffer pitem->SetTarget(this); 336cdb89ebbSMatthew Wilber pitem->SetEnabled(benabled); 337cdb89ebbSMatthew Wilber pmenu->AddItem(pitem); 33813afa642SPhil Greenway 339cdb89ebbSMatthew Wilber return pitem; 34013afa642SPhil Greenway } 34113afa642SPhil Greenway 342ad13f387SMichael Pfeiffer BMenuItem* 343d3046f7dSMichael Pfeiffer ShowImageWindow::AddDelayItem(BMenu *pmenu, char *caption, float value) 344ad13f387SMichael Pfeiffer { 345ad13f387SMichael Pfeiffer BMenuItem* pitem; 346ad13f387SMichael Pfeiffer BMessage* pmsg; 347e6a50d9cSMichael Pfeiffer pmsg = new BMessage(MSG_SLIDE_SHOW_DELAY); 348ad13f387SMichael Pfeiffer pmsg->AddFloat("value", value); 349ad13f387SMichael Pfeiffer 350ad13f387SMichael Pfeiffer pitem = new BMenuItem(caption, pmsg, 0); 351da87390fSMichael Pfeiffer pitem->SetTarget(this); 352ad13f387SMichael Pfeiffer 353d3046f7dSMichael Pfeiffer bool marked = fImageView->GetSlideShowDelay() == value; 354ad13f387SMichael Pfeiffer if (marked) pitem->SetMarked(true); 355ad13f387SMichael Pfeiffer pmenu->AddItem(pitem); 356ad13f387SMichael Pfeiffer 357ad13f387SMichael Pfeiffer return pitem; 358ad13f387SMichael Pfeiffer } 359ad13f387SMichael Pfeiffer 360cdb89ebbSMatthew Wilber void 361cdb89ebbSMatthew Wilber ShowImageWindow::WindowRedimension(BBitmap *pbitmap) 36213afa642SPhil Greenway { 363d10d5947SMichael Pfeiffer BScreen screen; 364d10d5947SMichael Pfeiffer BRect r(pbitmap->Bounds()); 365d10d5947SMichael Pfeiffer float width, height; 366d10d5947SMichael Pfeiffer float maxWidth, maxHeight; 367a8fc7138SMichael Pfeiffer float minW, maxW, minH, maxH; 368d10d5947SMichael Pfeiffer const float windowBorderWidth = 5; 369d10d5947SMichael Pfeiffer const float windowBorderHeight = 5; 37013afa642SPhil Greenway 371d10d5947SMichael Pfeiffer if (screen.Frame().right == 0.0) { 372d10d5947SMichael Pfeiffer return; // invalid screen object 373d10d5947SMichael Pfeiffer } 374cdb89ebbSMatthew Wilber 375d10d5947SMichael Pfeiffer width = r.Width() + B_V_SCROLL_BAR_WIDTH; 376d3046f7dSMichael Pfeiffer height = r.Height() + 1 + fBar->Frame().Height() + B_H_SCROLL_BAR_HEIGHT; 377cdb89ebbSMatthew Wilber 378d10d5947SMichael Pfeiffer // dimensions so that window does not reach outside of screen 379d10d5947SMichael Pfeiffer maxWidth = screen.Frame().Width() + 1 - windowBorderWidth - Frame().left; 380d10d5947SMichael Pfeiffer maxHeight = screen.Frame().Height() + 1 - windowBorderHeight - Frame().top; 381cdb89ebbSMatthew Wilber 382a8fc7138SMichael Pfeiffer // We have to check size limits manually, otherwise 383a8fc7138SMichael Pfeiffer // menu bar will be too short for small images. 384a8fc7138SMichael Pfeiffer GetSizeLimits(&minW, &maxW, &minH, &maxH); 385a8fc7138SMichael Pfeiffer if (maxWidth > maxW) maxWidth = maxW; 386a8fc7138SMichael Pfeiffer if (maxHeight > maxH) maxHeight = maxH; 387a8fc7138SMichael Pfeiffer if (width < minW) width = minW; 388a8fc7138SMichael Pfeiffer if (height < minH) height = minH; 389a8fc7138SMichael Pfeiffer 390d10d5947SMichael Pfeiffer if (width > maxWidth) width = maxWidth; 391d10d5947SMichael Pfeiffer if (height > maxHeight) height = maxHeight; 392d10d5947SMichael Pfeiffer 393d10d5947SMichael Pfeiffer ResizeTo(width, height); 39413afa642SPhil Greenway } 39513afa642SPhil Greenway 396cdb89ebbSMatthew Wilber void 397cdb89ebbSMatthew Wilber ShowImageWindow::FrameResized(float width, float height) 39813afa642SPhil Greenway { 39913afa642SPhil Greenway } 40013afa642SPhil Greenway 4017eca0987SMichael Pfeiffer bool 4027eca0987SMichael Pfeiffer ShowImageWindow::ToggleMenuItem(uint32 what) 4037eca0987SMichael Pfeiffer { 4047eca0987SMichael Pfeiffer BMenuItem *item; 4057eca0987SMichael Pfeiffer bool marked = false; 406d3046f7dSMichael Pfeiffer item = fBar->FindItem(what); 4077eca0987SMichael Pfeiffer if (item != NULL) { 4087eca0987SMichael Pfeiffer marked = !item->IsMarked(); 4097eca0987SMichael Pfeiffer item->SetMarked(marked); 4107eca0987SMichael Pfeiffer } 4117eca0987SMichael Pfeiffer return marked; 4127eca0987SMichael Pfeiffer } 4137eca0987SMichael Pfeiffer 414cdb89ebbSMatthew Wilber void 415da87390fSMichael Pfeiffer ShowImageWindow::EnableMenuItem(BMenu *menu, uint32 what, bool enable) 416e6a50d9cSMichael Pfeiffer { 417e6a50d9cSMichael Pfeiffer BMenuItem* item; 418da87390fSMichael Pfeiffer item = menu->FindItem(what); 419e6a50d9cSMichael Pfeiffer if (item && item->IsEnabled() != enable) { 420e6a50d9cSMichael Pfeiffer item->SetEnabled(enable); 421e6a50d9cSMichael Pfeiffer } 422e6a50d9cSMichael Pfeiffer } 423e6a50d9cSMichael Pfeiffer 424e6a50d9cSMichael Pfeiffer void 425da87390fSMichael Pfeiffer ShowImageWindow::MarkMenuItem(BMenu *menu, uint32 what, bool marked) 426e6a50d9cSMichael Pfeiffer { 427e6a50d9cSMichael Pfeiffer BMenuItem* item; 428da87390fSMichael Pfeiffer item = menu->FindItem(what); 429e6a50d9cSMichael Pfeiffer if (item && item->IsMarked() != marked) { 430e6a50d9cSMichael Pfeiffer item->SetMarked(marked); 431e6a50d9cSMichael Pfeiffer } 432e6a50d9cSMichael Pfeiffer } 433e6a50d9cSMichael Pfeiffer 434da87390fSMichael Pfeiffer void 435da87390fSMichael Pfeiffer ShowImageWindow::MarkSlideShowDelay(float value) 436da87390fSMichael Pfeiffer { 437d3046f7dSMichael Pfeiffer const int32 n = fSlideShowDelay->CountItems(); 438da87390fSMichael Pfeiffer float v; 439da87390fSMichael Pfeiffer for (int32 i = 0; i < n; i ++) { 440d3046f7dSMichael Pfeiffer BMenuItem* item = fSlideShowDelay->ItemAt(i); 441da87390fSMichael Pfeiffer if (item) { 442da87390fSMichael Pfeiffer if (item->Message()->FindFloat("value", &v) == B_OK && v == value) { 443da87390fSMichael Pfeiffer if (!item->IsMarked()) { 444da87390fSMichael Pfeiffer item->SetMarked(true); 445da87390fSMichael Pfeiffer } 446da87390fSMichael Pfeiffer return; 447da87390fSMichael Pfeiffer } 448da87390fSMichael Pfeiffer } 449da87390fSMichael Pfeiffer } 450da87390fSMichael Pfeiffer } 451e6a50d9cSMichael Pfeiffer 45219c76de4SMichael Pfeiffer 45319c76de4SMichael Pfeiffer void 45419c76de4SMichael Pfeiffer ShowImageWindow::ResizeToWindow(bool shrink, uint32 what) 45519c76de4SMichael Pfeiffer { 45619c76de4SMichael Pfeiffer bool enabled; 45719c76de4SMichael Pfeiffer enabled = ToggleMenuItem(what); 45819c76de4SMichael Pfeiffer if (shrink) { 459d3046f7dSMichael Pfeiffer fImageView->SetShrinkToBounds(enabled); 46019c76de4SMichael Pfeiffer } else { 461d3046f7dSMichael Pfeiffer fImageView->SetZoomToBounds(enabled); 46219c76de4SMichael Pfeiffer } 463d3046f7dSMichael Pfeiffer enabled = !(fImageView->GetShrinkToBounds() || fImageView->GetZoomToBounds()); 464d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_ORIGINAL_SIZE, enabled); 465d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_ZOOM_IN, enabled); 466d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_ZOOM_OUT, enabled); 46719c76de4SMichael Pfeiffer } 46819c76de4SMichael Pfeiffer 469e6a50d9cSMichael Pfeiffer void 470cdb89ebbSMatthew Wilber ShowImageWindow::MessageReceived(BMessage *pmsg) 47113afa642SPhil Greenway { 472d3046f7dSMichael Pfeiffer ShowImageSettings* settings; 473cdb89ebbSMatthew Wilber switch (pmsg->what) { 474ee7b4f39SMatthew Wilber case MSG_MODIFIED: 475ee7b4f39SMatthew Wilber // If image has been modified due to a Cut or Paste 476ee7b4f39SMatthew Wilber fModified = true; 477ee7b4f39SMatthew Wilber break; 478ee7b4f39SMatthew Wilber 479fc0a275bSMatthew Wilber case MSG_OUTPUT_TYPE: 480fc0a275bSMatthew Wilber // User clicked Save As then choose an output format 481d3046f7dSMichael Pfeiffer if (!fSavePanel) 482cdb89ebbSMatthew Wilber // If user doesn't already have a save panel open 483cdb89ebbSMatthew Wilber SaveAs(pmsg); 48413afa642SPhil Greenway break; 485fc0a275bSMatthew Wilber 486fc0a275bSMatthew Wilber case MSG_SAVE_PANEL: 487fc0a275bSMatthew Wilber // User specified where to save the output image 488cdb89ebbSMatthew Wilber SaveToFile(pmsg); 489fc0a275bSMatthew Wilber break; 490fc0a275bSMatthew Wilber 49107caaa8eSMatthew Wilber case MSG_CLOSE: 492cdb89ebbSMatthew Wilber if (CanQuit()) 49307caaa8eSMatthew Wilber Quit(); 49407caaa8eSMatthew Wilber break; 49507caaa8eSMatthew Wilber 496cdb89ebbSMatthew Wilber case B_CANCEL: 497d3046f7dSMichael Pfeiffer delete fSavePanel; 498d3046f7dSMichael Pfeiffer fSavePanel = NULL; 499cdb89ebbSMatthew Wilber break; 500cdb89ebbSMatthew Wilber 50103839579SMatthew Wilber case MSG_UPDATE_STATUS: 50203839579SMatthew Wilber { 5036c305411SMatthew Wilber int32 pages, curPage; 504d3046f7dSMichael Pfeiffer pages = fImageView->PageCount(); 505d3046f7dSMichael Pfeiffer curPage = fImageView->CurrentPage(); 5066c305411SMatthew Wilber 5076c305411SMatthew Wilber bool benable = (pages > 1) ? true : false; 508d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_FIRST, benable); 509d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_LAST, benable); 510d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_NEXT, benable); 511d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_PREV, benable); 5121d592070SMatthew Wilber 513d3046f7dSMichael Pfeiffer if (fGoToPageMenu->CountItems() != pages) { 5146c305411SMatthew Wilber // Only rebuild the submenu if the number of 5156c305411SMatthew Wilber // pages is different 5166c305411SMatthew Wilber 517d3046f7dSMichael Pfeiffer while (fGoToPageMenu->CountItems() > 0) 5186c305411SMatthew Wilber // Remove all page numbers 519d3046f7dSMichael Pfeiffer delete fGoToPageMenu->RemoveItem(0L); 5206c305411SMatthew Wilber 521780d8a62SMichael Pfeiffer for (int32 i = 1; i <= pages; i++) { 5226c305411SMatthew Wilber // Fill Go To page submenu with an entry for each page 5236c305411SMatthew Wilber BMessage *pgomsg; 524780d8a62SMichael Pfeiffer char shortcut = 0; 5256c305411SMatthew Wilber pgomsg = new BMessage(MSG_GOTO_PAGE); 5266c305411SMatthew Wilber pgomsg->AddInt32("page", i); 5276c305411SMatthew Wilber BString strCaption; 5286c305411SMatthew Wilber strCaption << i; 5296c305411SMatthew Wilber BMenuItem *pitem; 530780d8a62SMichael Pfeiffer if (i < 10) { 531780d8a62SMichael Pfeiffer shortcut = '0' + i; 532780d8a62SMichael Pfeiffer } else if (i == 10) { 533780d8a62SMichael Pfeiffer shortcut = '0'; 534780d8a62SMichael Pfeiffer } 535780d8a62SMichael Pfeiffer pitem = new BMenuItem(strCaption.String(), pgomsg, shortcut); 5366c305411SMatthew Wilber if (curPage == i) 5376c305411SMatthew Wilber pitem->SetMarked(true); 538d3046f7dSMichael Pfeiffer fGoToPageMenu->AddItem(pitem); 5396c305411SMatthew Wilber } 5406c305411SMatthew Wilber } else { 5416c305411SMatthew Wilber // Make sure the correct page is marked 5426c305411SMatthew Wilber BMenuItem *pcurItem; 543d3046f7dSMichael Pfeiffer pcurItem = fGoToPageMenu->ItemAt(curPage - 1); 5446c305411SMatthew Wilber if (!pcurItem->IsMarked()) { 5456c305411SMatthew Wilber pcurItem->SetMarked(true); 5466c305411SMatthew Wilber } 5476c305411SMatthew Wilber } 5486c305411SMatthew Wilber 54903839579SMatthew Wilber BString str; 55003839579SMatthew Wilber if (pmsg->FindString("status", &str) == B_OK) 551d3046f7dSMichael Pfeiffer fStatusView->SetText(str); 5527eca0987SMichael Pfeiffer 5537eca0987SMichael Pfeiffer UpdateTitle(); 55403839579SMatthew Wilber break; 55503839579SMatthew Wilber } 55603839579SMatthew Wilber 5578ad30bcfSMatthew Wilber case MSG_SELECTION: 5588ad30bcfSMatthew Wilber { 5598ad30bcfSMatthew Wilber // The view sends this message when a selection is 5608ad30bcfSMatthew Wilber // made or the selection is cleared so that the window 5618ad30bcfSMatthew Wilber // can update the state of the appropriate menu items 5628ad30bcfSMatthew Wilber bool benable; 5638ad30bcfSMatthew Wilber if (pmsg->FindBool("has_selection", &benable) == B_OK) { 564d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, B_CUT, benable); 565d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, B_COPY, benable); 566d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_CLEAR_SELECT, benable); 5678ad30bcfSMatthew Wilber } 5688ad30bcfSMatthew Wilber break; 5698ad30bcfSMatthew Wilber } 5708ad30bcfSMatthew Wilber 571*7598450eSMatthew Wilber case MSG_UNDO_STATE: 572*7598450eSMatthew Wilber { 573*7598450eSMatthew Wilber bool benable; 574*7598450eSMatthew Wilber if (pmsg->FindBool("can_undo", &benable) == B_OK) 575*7598450eSMatthew Wilber EnableMenuItem(fBar, B_UNDO, benable); 576*7598450eSMatthew Wilber break; 577*7598450eSMatthew Wilber } 578*7598450eSMatthew Wilber 579402c09e5SMatthew Wilber case MSG_CLIPBOARD_CHANGED: 580402c09e5SMatthew Wilber { 581402c09e5SMatthew Wilber // The app sends this message after it examines 582402c09e5SMatthew Wilber // the clipboard in response to a B_CLIPBOARD_CHANGED 583402c09e5SMatthew Wilber // message 584402c09e5SMatthew Wilber bool bdata; 585402c09e5SMatthew Wilber if (pmsg->FindBool("data_available", &bdata) == B_OK) 586d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, B_PASTE, bdata); 587402c09e5SMatthew Wilber break; 588402c09e5SMatthew Wilber } 589402c09e5SMatthew Wilber 59013afa642SPhil Greenway case B_UNDO: 591*7598450eSMatthew Wilber fImageView->Undo(); 59213afa642SPhil Greenway break; 59313afa642SPhil Greenway case B_CUT: 594d3046f7dSMichael Pfeiffer fImageView->Cut(); 59513afa642SPhil Greenway break; 59613afa642SPhil Greenway case B_COPY: 597d3046f7dSMichael Pfeiffer fImageView->CopySelectionToClipboard(); 59813afa642SPhil Greenway break; 59913afa642SPhil Greenway case B_PASTE: 600d3046f7dSMichael Pfeiffer fImageView->Paste(); 60113afa642SPhil Greenway break; 60213afa642SPhil Greenway case MSG_CLEAR_SELECT: 603d3046f7dSMichael Pfeiffer fImageView->ClearSelection(); 60413afa642SPhil Greenway break; 60513afa642SPhil Greenway case MSG_SELECT_ALL: 606d3046f7dSMichael Pfeiffer fImageView->SelectAll(); 60713afa642SPhil Greenway break; 60813afa642SPhil Greenway 60903839579SMatthew Wilber case MSG_PAGE_FIRST: 610ee7b4f39SMatthew Wilber if (ClosePrompt()) 611d3046f7dSMichael Pfeiffer fImageView->FirstPage(); 61203839579SMatthew Wilber break; 61303839579SMatthew Wilber 61403839579SMatthew Wilber case MSG_PAGE_LAST: 615ee7b4f39SMatthew Wilber if (ClosePrompt()) 616d3046f7dSMichael Pfeiffer fImageView->LastPage(); 61703839579SMatthew Wilber break; 61803839579SMatthew Wilber 61903839579SMatthew Wilber case MSG_PAGE_NEXT: 620ee7b4f39SMatthew Wilber if (ClosePrompt()) 621d3046f7dSMichael Pfeiffer fImageView->NextPage(); 62203839579SMatthew Wilber break; 62303839579SMatthew Wilber 62403839579SMatthew Wilber case MSG_PAGE_PREV: 625ee7b4f39SMatthew Wilber if (ClosePrompt()) 626d3046f7dSMichael Pfeiffer fImageView->PrevPage(); 62703839579SMatthew Wilber break; 62803839579SMatthew Wilber 6296c305411SMatthew Wilber case MSG_GOTO_PAGE: 6306c305411SMatthew Wilber { 631ee7b4f39SMatthew Wilber if (!ClosePrompt()) 632ee7b4f39SMatthew Wilber break; 633ee7b4f39SMatthew Wilber 6346c305411SMatthew Wilber int32 curPage, newPage, pages; 6356c305411SMatthew Wilber if (pmsg->FindInt32("page", &newPage) == B_OK) { 636d3046f7dSMichael Pfeiffer curPage = fImageView->CurrentPage(); 637d3046f7dSMichael Pfeiffer pages = fImageView->PageCount(); 6386c305411SMatthew Wilber 6396c305411SMatthew Wilber if (newPage > 0 && newPage <= pages) { 6406c305411SMatthew Wilber BMenuItem *pcurItem, *pnewItem; 641d3046f7dSMichael Pfeiffer pcurItem = fGoToPageMenu->ItemAt(curPage - 1); 642d3046f7dSMichael Pfeiffer pnewItem = fGoToPageMenu->ItemAt(newPage - 1); 6436c305411SMatthew Wilber if (!pcurItem || !pnewItem) 6446c305411SMatthew Wilber break; 6456c305411SMatthew Wilber pcurItem->SetMarked(false); 6466c305411SMatthew Wilber pnewItem->SetMarked(true); 647d3046f7dSMichael Pfeiffer fImageView->GoToPage(newPage); 6486c305411SMatthew Wilber } 6496c305411SMatthew Wilber } 6506c305411SMatthew Wilber } 6516c305411SMatthew Wilber break; 6526c305411SMatthew Wilber 653cdb89ebbSMatthew Wilber case MSG_DITHER_IMAGE: 654a8fc7138SMichael Pfeiffer fImageView->SetDither(ToggleMenuItem(pmsg->what)); 6557eca0987SMichael Pfeiffer break; 6567eca0987SMichael Pfeiffer 65719c76de4SMichael Pfeiffer case MSG_SHRINK_TO_WINDOW: 65819c76de4SMichael Pfeiffer ResizeToWindow(true, pmsg->what); 65919c76de4SMichael Pfeiffer break; 66019c76de4SMichael Pfeiffer case MSG_ZOOM_TO_WINDOW: 66119c76de4SMichael Pfeiffer ResizeToWindow(false, pmsg->what); 6627eca0987SMichael Pfeiffer break; 6637eca0987SMichael Pfeiffer 6647eca0987SMichael Pfeiffer case MSG_FILE_PREV: 665ee7b4f39SMatthew Wilber if (ClosePrompt()) 666d3046f7dSMichael Pfeiffer fImageView->PrevFile(); 6677eca0987SMichael Pfeiffer break; 6687eca0987SMichael Pfeiffer 6697eca0987SMichael Pfeiffer case MSG_FILE_NEXT: 670ee7b4f39SMatthew Wilber if (ClosePrompt()) 671d3046f7dSMichael Pfeiffer fImageView->NextFile(); 67213afa642SPhil Greenway break; 67313afa642SPhil Greenway 674bf461dbeSMatthew Wilber case MSG_ROTATE_90: 675d3046f7dSMichael Pfeiffer fImageView->Rotate(90); 676ad13f387SMichael Pfeiffer break; 677bf461dbeSMatthew Wilber case MSG_ROTATE_270: 678d3046f7dSMichael Pfeiffer fImageView->Rotate(270); 679ad13f387SMichael Pfeiffer break; 680ad13f387SMichael Pfeiffer case MSG_MIRROR_VERTICAL: 681d3046f7dSMichael Pfeiffer fImageView->Mirror(true); 682ad13f387SMichael Pfeiffer break; 683ad13f387SMichael Pfeiffer case MSG_MIRROR_HORIZONTAL: 684d3046f7dSMichael Pfeiffer fImageView->Mirror(false); 685ad13f387SMichael Pfeiffer break; 686ad13f387SMichael Pfeiffer case MSG_INVERT: 687d3046f7dSMichael Pfeiffer fImageView->Invert(); 688ad13f387SMichael Pfeiffer break; 689e6a50d9cSMichael Pfeiffer case MSG_SLIDE_SHOW: 690ee7b4f39SMatthew Wilber { 691ee7b4f39SMatthew Wilber BMenuItem *item; 692ee7b4f39SMatthew Wilber item = fBar->FindItem(pmsg->what); 693ee7b4f39SMatthew Wilber if (!item) 694ee7b4f39SMatthew Wilber break; 695ee7b4f39SMatthew Wilber if (item->IsMarked()) { 696ee7b4f39SMatthew Wilber item->SetMarked(false); 697d3046f7dSMichael Pfeiffer fImageView->StopSlideShow(); 698ee7b4f39SMatthew Wilber } else if (ClosePrompt()) { 699ee7b4f39SMatthew Wilber item->SetMarked(true); 700ee7b4f39SMatthew Wilber fImageView->StartSlideShow(); 701ad13f387SMichael Pfeiffer } 702ee7b4f39SMatthew Wilber } 703ee7b4f39SMatthew Wilber break; 704ee7b4f39SMatthew Wilber 705e6a50d9cSMichael Pfeiffer case MSG_SLIDE_SHOW_DELAY: 706ad13f387SMichael Pfeiffer { 707ad13f387SMichael Pfeiffer float value; 708ad13f387SMichael Pfeiffer if (pmsg->FindFloat("value", &value) == B_OK) { 709d3046f7dSMichael Pfeiffer fImageView->SetSlideShowDelay(value); 710da87390fSMichael Pfeiffer // in case message is sent from popup menu 711da87390fSMichael Pfeiffer MarkSlideShowDelay(value); 712ad13f387SMichael Pfeiffer } 713ad13f387SMichael Pfeiffer } 714ad13f387SMichael Pfeiffer break; 715ad13f387SMichael Pfeiffer 716ad13f387SMichael Pfeiffer case MSG_FULL_SCREEN: 717ad13f387SMichael Pfeiffer ToggleFullScreen(); 718ad13f387SMichael Pfeiffer break; 719e6a50d9cSMichael Pfeiffer case MSG_SHOW_CAPTION: 720e6a50d9cSMichael Pfeiffer fShowCaption = ToggleMenuItem(pmsg->what); 721d3046f7dSMichael Pfeiffer settings = my_app->Settings(); 722d3046f7dSMichael Pfeiffer if (settings->Lock()) { 723d3046f7dSMichael Pfeiffer settings->SetBool("ShowCaption", fShowCaption); 724d3046f7dSMichael Pfeiffer settings->Unlock(); 725d3046f7dSMichael Pfeiffer } 726e6a50d9cSMichael Pfeiffer if (fFullScreen) { 727d3046f7dSMichael Pfeiffer fImageView->SetShowCaption(fShowCaption); 728e6a50d9cSMichael Pfeiffer } 729e6a50d9cSMichael Pfeiffer break; 730ad13f387SMichael Pfeiffer 731780d8a62SMichael Pfeiffer case MSG_PAGE_SETUP: 732780d8a62SMichael Pfeiffer PageSetup(); 733780d8a62SMichael Pfeiffer break; 734780d8a62SMichael Pfeiffer case MSG_PREPARE_PRINT: 735780d8a62SMichael Pfeiffer PrepareForPrint(); 736780d8a62SMichael Pfeiffer break; 737780d8a62SMichael Pfeiffer case MSG_PRINT: 738780d8a62SMichael Pfeiffer Print(pmsg); 739780d8a62SMichael Pfeiffer break; 740780d8a62SMichael Pfeiffer 741780d8a62SMichael Pfeiffer case MSG_ZOOM_IN: 742d3046f7dSMichael Pfeiffer fImageView->ZoomIn(); 743780d8a62SMichael Pfeiffer break; 744780d8a62SMichael Pfeiffer case MSG_ZOOM_OUT: 745d3046f7dSMichael Pfeiffer fImageView->ZoomOut(); 746780d8a62SMichael Pfeiffer break; 747780d8a62SMichael Pfeiffer case MSG_ORIGINAL_SIZE: 748d3046f7dSMichael Pfeiffer fImageView->SetZoom(1.0); 749780d8a62SMichael Pfeiffer break; 75081b9c776SMichael Pfeiffer case MSG_SCALE_BILINEAR: 751d3046f7dSMichael Pfeiffer fImageView->SetScaleBilinear(ToggleMenuItem(pmsg->what)); 75281b9c776SMichael Pfeiffer break; 753780d8a62SMichael Pfeiffer 75413afa642SPhil Greenway default: 755cdb89ebbSMatthew Wilber BWindow::MessageReceived(pmsg); 75613afa642SPhil Greenway break; 75713afa642SPhil Greenway } 75813afa642SPhil Greenway } 759fc0a275bSMatthew Wilber 760fc0a275bSMatthew Wilber void 761fc0a275bSMatthew Wilber ShowImageWindow::SaveAs(BMessage *pmsg) 762fc0a275bSMatthew Wilber { 763cdb89ebbSMatthew Wilber // Read the translator and output type the user chose 764cdb89ebbSMatthew Wilber translator_id outTranslator; 765cdb89ebbSMatthew Wilber uint32 outType; 766cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TRANSLATOR_FLD, 767cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outTranslator)) != B_OK) 768fc0a275bSMatthew Wilber return; 769cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TYPE_FLD, 770cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outType)) != B_OK) 771fc0a275bSMatthew Wilber return; 772fc0a275bSMatthew Wilber 773cdb89ebbSMatthew Wilber // Add the chosen translator and output type to the 774cdb89ebbSMatthew Wilber // message that the save panel will send back 775cdb89ebbSMatthew Wilber BMessage *ppanelMsg = new BMessage(MSG_SAVE_PANEL); 776cdb89ebbSMatthew Wilber ppanelMsg->AddInt32(TRANSLATOR_FLD, outTranslator); 777cdb89ebbSMatthew Wilber ppanelMsg->AddInt32(TYPE_FLD, outType); 778cdb89ebbSMatthew Wilber 779cdb89ebbSMatthew Wilber // Create save panel and show it 780d3046f7dSMichael Pfeiffer fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0, 781cdb89ebbSMatthew Wilber false, ppanelMsg); 782d3046f7dSMichael Pfeiffer if (!fSavePanel) 783fc0a275bSMatthew Wilber return; 784d3046f7dSMichael Pfeiffer fSavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE); 785d3046f7dSMichael Pfeiffer fSavePanel->Show(); 786fc0a275bSMatthew Wilber } 787fc0a275bSMatthew Wilber 788fc0a275bSMatthew Wilber void 789fc0a275bSMatthew Wilber ShowImageWindow::SaveToFile(BMessage *pmsg) 790fc0a275bSMatthew Wilber { 791cdb89ebbSMatthew Wilber // Read in where the file should be saved 792fc0a275bSMatthew Wilber entry_ref dirref; 793fc0a275bSMatthew Wilber if (pmsg->FindRef("directory", &dirref) != B_OK) 794fc0a275bSMatthew Wilber return; 795fc0a275bSMatthew Wilber const char *filename; 796fc0a275bSMatthew Wilber if (pmsg->FindString("name", &filename) != B_OK) 797fc0a275bSMatthew Wilber return; 798fc0a275bSMatthew Wilber 799cdb89ebbSMatthew Wilber // Read in the translator and type to be used 800cdb89ebbSMatthew Wilber // to save the output image 801cdb89ebbSMatthew Wilber translator_id outTranslator; 802cdb89ebbSMatthew Wilber uint32 outType; 803cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TRANSLATOR_FLD, 804cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outTranslator)) != B_OK) 805cdb89ebbSMatthew Wilber return; 806cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TYPE_FLD, 807cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outType)) != B_OK) 808cdb89ebbSMatthew Wilber return; 809cdb89ebbSMatthew Wilber 810cdb89ebbSMatthew Wilber // Create the output file 811fc0a275bSMatthew Wilber BDirectory dir(&dirref); 812fc0a275bSMatthew Wilber BFile file(&dir, filename, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 813fc0a275bSMatthew Wilber if (file.InitCheck() != B_OK) 814fc0a275bSMatthew Wilber return; 815fc0a275bSMatthew Wilber 816cdb89ebbSMatthew Wilber // Translate the image and write it out to the output file 817d3046f7dSMichael Pfeiffer BBitmapStream stream(fImageView->GetBitmap()); 818fc0a275bSMatthew Wilber BTranslatorRoster *proster = BTranslatorRoster::Default(); 819cdb89ebbSMatthew Wilber if (proster->Translate(outTranslator, &stream, NULL, 820cdb89ebbSMatthew Wilber &file, outType) != B_OK) { 821fc0a275bSMatthew Wilber BAlert *palert = new BAlert(NULL, "Error writing image file.", "Ok"); 822fc0a275bSMatthew Wilber palert->Go(); 823ee7b4f39SMatthew Wilber } else 824ee7b4f39SMatthew Wilber fModified = false; 825fc0a275bSMatthew Wilber 826fc0a275bSMatthew Wilber BBitmap *pout = NULL; 827fc0a275bSMatthew Wilber stream.DetachBitmap(&pout); 828fc0a275bSMatthew Wilber // bitmap used by stream still belongs to the view, 829fc0a275bSMatthew Wilber // detach so it doesn't get deleted 830fc0a275bSMatthew Wilber } 831fc0a275bSMatthew Wilber 832cdb89ebbSMatthew Wilber bool 833ee7b4f39SMatthew Wilber ShowImageWindow::ClosePrompt() 834ee7b4f39SMatthew Wilber { 835ee7b4f39SMatthew Wilber if (!fModified) 836ee7b4f39SMatthew Wilber return true; 837ee7b4f39SMatthew Wilber else { 838ee7b4f39SMatthew Wilber int32 page, count; 839ee7b4f39SMatthew Wilber count = fImageView->PageCount(); 840ee7b4f39SMatthew Wilber page = fImageView->CurrentPage(); 841ee7b4f39SMatthew Wilber BString prompt, name; 842ee7b4f39SMatthew Wilber fImageView->GetName(&name); 843ee7b4f39SMatthew Wilber prompt << "The document '" << name << "'"; 844ee7b4f39SMatthew Wilber if (count > 1) 845ee7b4f39SMatthew Wilber prompt << " (page " << page << ")"; 846ee7b4f39SMatthew Wilber prompt << " has been changed. " 847ee7b4f39SMatthew Wilber << "Do you want to close the document?"; 848ee7b4f39SMatthew Wilber BAlert *pAlert = new BAlert("Close document", prompt.String(), 849ee7b4f39SMatthew Wilber "Cancel", "Close"); 850ee7b4f39SMatthew Wilber if (pAlert->Go() == 0) 851ee7b4f39SMatthew Wilber // Cancel 852ee7b4f39SMatthew Wilber return false; 853187f0b8aSMatthew Wilber else { 854ee7b4f39SMatthew Wilber // Close 855187f0b8aSMatthew Wilber fModified = false; 856ee7b4f39SMatthew Wilber return true; 857ee7b4f39SMatthew Wilber } 858ee7b4f39SMatthew Wilber } 859187f0b8aSMatthew Wilber } 860ee7b4f39SMatthew Wilber 861ee7b4f39SMatthew Wilber bool 862cdb89ebbSMatthew Wilber ShowImageWindow::CanQuit() 863cdb89ebbSMatthew Wilber { 864d3046f7dSMichael Pfeiffer if (fSavePanel) 865cdb89ebbSMatthew Wilber // Don't allow this window to be closed if a save panel is open 866cdb89ebbSMatthew Wilber return false; 867cdb89ebbSMatthew Wilber else 868ee7b4f39SMatthew Wilber return ClosePrompt(); 869cdb89ebbSMatthew Wilber } 870cdb89ebbSMatthew Wilber 871ad13f387SMichael Pfeiffer void 872ad13f387SMichael Pfeiffer ShowImageWindow::ToggleFullScreen() 873ad13f387SMichael Pfeiffer { 874ad13f387SMichael Pfeiffer BRect frame; 875ad13f387SMichael Pfeiffer fFullScreen = !fFullScreen; 876ad13f387SMichael Pfeiffer if (fFullScreen) { 877ad13f387SMichael Pfeiffer BScreen screen; 878ad13f387SMichael Pfeiffer fWindowFrame = Frame(); 879ad13f387SMichael Pfeiffer frame = screen.Frame(); 880d3046f7dSMichael Pfeiffer frame.top -= fBar->Bounds().Height()+1; 881ad13f387SMichael Pfeiffer frame.right += B_V_SCROLL_BAR_WIDTH; 882ad13f387SMichael Pfeiffer frame.bottom += B_H_SCROLL_BAR_HEIGHT; 883ad13f387SMichael Pfeiffer frame.InsetBy(-1, -1); // PEN_SIZE in ShowImageView 884ad13f387SMichael Pfeiffer 885ad13f387SMichael Pfeiffer SetFlags(Flags() | B_NOT_RESIZABLE | B_NOT_MOVABLE); 886d3046f7dSMichael Pfeiffer fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE); 887ad13f387SMichael Pfeiffer } else { 888ad13f387SMichael Pfeiffer frame = fWindowFrame; 889ad13f387SMichael Pfeiffer 890ad13f387SMichael Pfeiffer SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE)); 891d3046f7dSMichael Pfeiffer fImageView->SetAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); 892ad13f387SMichael Pfeiffer } 893d3046f7dSMichael Pfeiffer fImageView->SetBorder(!fFullScreen); 894d3046f7dSMichael Pfeiffer fImageView->SetShowCaption(fFullScreen && fShowCaption); 895ad13f387SMichael Pfeiffer MoveTo(frame.left, frame.top); 896ad13f387SMichael Pfeiffer ResizeTo(frame.Width(), frame.Height()); 897ad13f387SMichael Pfeiffer } 898ad13f387SMichael Pfeiffer 899d3046f7dSMichael Pfeiffer void 900d3046f7dSMichael Pfeiffer ShowImageWindow::LoadSettings() 901d3046f7dSMichael Pfeiffer { 902d3046f7dSMichael Pfeiffer ShowImageSettings* settings; 903d3046f7dSMichael Pfeiffer settings = my_app->Settings(); 904d3046f7dSMichael Pfeiffer int32 op; 905d3046f7dSMichael Pfeiffer float f; 906d3046f7dSMichael Pfeiffer if (settings->Lock()) { 907d3046f7dSMichael Pfeiffer fShowCaption = settings->GetBool("ShowCaption", fShowCaption); 908d3046f7dSMichael Pfeiffer fPrintOptions.SetBounds(BRect(0, 0, 1023, 767)); 909d3046f7dSMichael Pfeiffer 910d3046f7dSMichael Pfeiffer op = settings->GetInt32("PO:Option", fPrintOptions.Option()); 911d3046f7dSMichael Pfeiffer fPrintOptions.SetOption((enum PrintOptions::Option)op); 912d3046f7dSMichael Pfeiffer 913d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:ZoomFactor", fPrintOptions.ZoomFactor()); 914d3046f7dSMichael Pfeiffer fPrintOptions.SetZoomFactor(f); 915d3046f7dSMichael Pfeiffer 916d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:DPI", fPrintOptions.DPI()); 917d3046f7dSMichael Pfeiffer fPrintOptions.SetDPI(f); 918d3046f7dSMichael Pfeiffer 919d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:Width", fPrintOptions.Width()); 920d3046f7dSMichael Pfeiffer fPrintOptions.SetWidth(f); 921d3046f7dSMichael Pfeiffer 922d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:Height", fPrintOptions.Height()); 923d3046f7dSMichael Pfeiffer fPrintOptions.SetHeight(f); 924d3046f7dSMichael Pfeiffer 925d3046f7dSMichael Pfeiffer settings->Unlock(); 926d3046f7dSMichael Pfeiffer } 927d3046f7dSMichael Pfeiffer } 928d3046f7dSMichael Pfeiffer 929d3046f7dSMichael Pfeiffer void 930d3046f7dSMichael Pfeiffer ShowImageWindow::SavePrintOptions() 931d3046f7dSMichael Pfeiffer { 932d3046f7dSMichael Pfeiffer ShowImageSettings* settings; 933d3046f7dSMichael Pfeiffer settings = my_app->Settings(); 934d3046f7dSMichael Pfeiffer if (settings->Lock()) { 935d3046f7dSMichael Pfeiffer settings->SetInt32("PO:Option", fPrintOptions.Option()); 936d3046f7dSMichael Pfeiffer settings->SetFloat("PO:ZoomFactor", fPrintOptions.ZoomFactor()); 937d3046f7dSMichael Pfeiffer settings->SetFloat("PO:DPI", fPrintOptions.DPI()); 938d3046f7dSMichael Pfeiffer settings->SetFloat("PO:Width", fPrintOptions.Width()); 939d3046f7dSMichael Pfeiffer settings->SetFloat("PO:Height", fPrintOptions.Height()); 940d3046f7dSMichael Pfeiffer settings->Unlock(); 941d3046f7dSMichael Pfeiffer } 942d3046f7dSMichael Pfeiffer } 943d3046f7dSMichael Pfeiffer 944cdb89ebbSMatthew Wilber bool 945780d8a62SMichael Pfeiffer ShowImageWindow::PageSetup() 946780d8a62SMichael Pfeiffer { 947780d8a62SMichael Pfeiffer status_t st; 948780d8a62SMichael Pfeiffer BString name; 949d3046f7dSMichael Pfeiffer fImageView->GetName(&name); 950780d8a62SMichael Pfeiffer BPrintJob printJob(name.String()); 951780d8a62SMichael Pfeiffer if (fPrintSettings != NULL) { 952780d8a62SMichael Pfeiffer printJob.SetSettings(new BMessage(*fPrintSettings)); 953780d8a62SMichael Pfeiffer } 954780d8a62SMichael Pfeiffer st = printJob.ConfigPage(); 955780d8a62SMichael Pfeiffer if (st == B_OK) { 956780d8a62SMichael Pfeiffer delete fPrintSettings; 957780d8a62SMichael Pfeiffer fPrintSettings = printJob.Settings(); 958780d8a62SMichael Pfeiffer } 959780d8a62SMichael Pfeiffer return st == B_OK; 960780d8a62SMichael Pfeiffer } 961780d8a62SMichael Pfeiffer 962780d8a62SMichael Pfeiffer void 963780d8a62SMichael Pfeiffer ShowImageWindow::PrepareForPrint() 964780d8a62SMichael Pfeiffer { 965780d8a62SMichael Pfeiffer if (fPrintSettings == NULL && !PageSetup()) { 966780d8a62SMichael Pfeiffer return; 967780d8a62SMichael Pfeiffer } 968780d8a62SMichael Pfeiffer 969d3046f7dSMichael Pfeiffer fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds()); 970d3046f7dSMichael Pfeiffer fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width()+1); 971780d8a62SMichael Pfeiffer 972780d8a62SMichael Pfeiffer new PrintOptionsWindow(BPoint(Frame().left+30, Frame().top+50), &fPrintOptions, this); 973780d8a62SMichael Pfeiffer } 974780d8a62SMichael Pfeiffer 975780d8a62SMichael Pfeiffer void 976780d8a62SMichael Pfeiffer ShowImageWindow::Print(BMessage *msg) 977780d8a62SMichael Pfeiffer { 978780d8a62SMichael Pfeiffer status_t st; 979780d8a62SMichael Pfeiffer if (msg->FindInt32("status", &st) != B_OK || st != B_OK) { 980780d8a62SMichael Pfeiffer return; 981780d8a62SMichael Pfeiffer } 982780d8a62SMichael Pfeiffer 983d3046f7dSMichael Pfeiffer SavePrintOptions(); 984d3046f7dSMichael Pfeiffer 985780d8a62SMichael Pfeiffer BString name; 986d3046f7dSMichael Pfeiffer fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds()); 987d3046f7dSMichael Pfeiffer fImageView->GetName(&name); 988780d8a62SMichael Pfeiffer BPrintJob printJob(name.String()); 989780d8a62SMichael Pfeiffer printJob.SetSettings(new BMessage(*fPrintSettings)); 990780d8a62SMichael Pfeiffer if (printJob.ConfigJob() == B_OK) { 991780d8a62SMichael Pfeiffer int32 firstPage; 992780d8a62SMichael Pfeiffer int32 lastPage; 993780d8a62SMichael Pfeiffer BRect printableRect = printJob.PrintableRect(); 994780d8a62SMichael Pfeiffer float width, imageWidth, imageHeight, w1, w2; 995780d8a62SMichael Pfeiffer BBitmap* bitmap; 996780d8a62SMichael Pfeiffer 997780d8a62SMichael Pfeiffer // first/lastPage is unused for now 998780d8a62SMichael Pfeiffer firstPage = printJob.FirstPage(); 999780d8a62SMichael Pfeiffer lastPage = printJob.LastPage(); 1000780d8a62SMichael Pfeiffer if (firstPage < 1) { 1001780d8a62SMichael Pfeiffer firstPage = 1; 1002780d8a62SMichael Pfeiffer } 1003780d8a62SMichael Pfeiffer if (lastPage < firstPage) { 1004780d8a62SMichael Pfeiffer lastPage = firstPage; 1005780d8a62SMichael Pfeiffer } 1006780d8a62SMichael Pfeiffer 1007d3046f7dSMichael Pfeiffer bitmap = fImageView->GetBitmap(); 1008780d8a62SMichael Pfeiffer imageWidth = bitmap->Bounds().Width() + 1.0; 1009780d8a62SMichael Pfeiffer imageHeight = bitmap->Bounds().Height() + 1.0; 1010780d8a62SMichael Pfeiffer 1011780d8a62SMichael Pfeiffer switch (fPrintOptions.Option()) { 1012780d8a62SMichael Pfeiffer case PrintOptions::kFitToPage: 1013780d8a62SMichael Pfeiffer w1 = printableRect.Width()+1; 1014780d8a62SMichael Pfeiffer w2 = imageWidth * (printableRect.Height() + 1) / imageHeight; 1015780d8a62SMichael Pfeiffer if (w2 < w1) { 1016780d8a62SMichael Pfeiffer width = w2; 1017780d8a62SMichael Pfeiffer } else { 1018780d8a62SMichael Pfeiffer width = w1; 1019780d8a62SMichael Pfeiffer } 1020780d8a62SMichael Pfeiffer break; 1021780d8a62SMichael Pfeiffer case PrintOptions::kZoomFactor: 1022780d8a62SMichael Pfeiffer width = imageWidth * fPrintOptions.ZoomFactor(); 1023780d8a62SMichael Pfeiffer break; 1024780d8a62SMichael Pfeiffer case PrintOptions::kDPI: 1025780d8a62SMichael Pfeiffer width = imageWidth * 72.0 / fPrintOptions.DPI(); 1026780d8a62SMichael Pfeiffer break; 1027780d8a62SMichael Pfeiffer case PrintOptions::kWidth: 1028780d8a62SMichael Pfeiffer case PrintOptions::kHeight: 1029780d8a62SMichael Pfeiffer width = fPrintOptions.Width(); 1030780d8a62SMichael Pfeiffer break; 1031780d8a62SMichael Pfeiffer default: 1032780d8a62SMichael Pfeiffer // keep compiler silent; should not reach here 1033780d8a62SMichael Pfeiffer width = imageWidth; 1034780d8a62SMichael Pfeiffer } 1035780d8a62SMichael Pfeiffer 1036780d8a62SMichael Pfeiffer // XXX: eventually print large images on several pages 1037780d8a62SMichael Pfeiffer printJob.BeginJob(); 1038d3046f7dSMichael Pfeiffer fImageView->SetScale(width / imageWidth); 1039d3046f7dSMichael Pfeiffer printJob.DrawView(fImageView, bitmap->Bounds(), BPoint(printableRect.left, printableRect.top)); 1040d3046f7dSMichael Pfeiffer fImageView->SetScale(1.0); 1041780d8a62SMichael Pfeiffer printJob.SpoolPage(); 1042780d8a62SMichael Pfeiffer printJob.CommitJob(); 1043780d8a62SMichael Pfeiffer } 1044780d8a62SMichael Pfeiffer } 1045780d8a62SMichael Pfeiffer 1046780d8a62SMichael Pfeiffer bool 1047cdb89ebbSMatthew Wilber ShowImageWindow::QuitRequested() 1048cdb89ebbSMatthew Wilber { 1049cdb89ebbSMatthew Wilber return CanQuit(); 1050cdb89ebbSMatthew Wilber } 1051cdb89ebbSMatthew Wilber 105207caaa8eSMatthew Wilber void 105307caaa8eSMatthew Wilber ShowImageWindow::Quit() 105407caaa8eSMatthew Wilber { 105507caaa8eSMatthew Wilber // tell the app to forget about this window 105607caaa8eSMatthew Wilber be_app->PostMessage(MSG_WINDOW_QUIT); 105707caaa8eSMatthew Wilber BWindow::Quit(); 105807caaa8eSMatthew Wilber } 1059fc0a275bSMatthew Wilber 1060