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) 97*1de41298SMatthew Wilber : BWindow(BRect(5, 24, 250, 100), "", 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); 11213afa642SPhil Greenway 11313afa642SPhil Greenway BRect viewFrame = Bounds(); 1140916ab53SMatthew Wilber viewFrame.top = fBar->Bounds().bottom; 11513afa642SPhil Greenway viewFrame.right -= B_V_SCROLL_BAR_WIDTH; 11613afa642SPhil Greenway viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT; 11713afa642SPhil Greenway 11813afa642SPhil Greenway // create the image view 119d3046f7dSMichael Pfeiffer fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL, 1207eca0987SMichael Pfeiffer B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED); 12113afa642SPhil Greenway // wrap a scroll view around the view 122d3046f7dSMichael Pfeiffer BScrollView *pscrollView = new BScrollView("image_scroller", fImageView, 123cdb89ebbSMatthew Wilber B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER); 124cdb89ebbSMatthew Wilber AddChild(pscrollView); 1250916ab53SMatthew Wilber AddChild(fBar); 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; 1320916ab53SMatthew Wilber rect.right = viewFrame.right + 1; 1330916ab53SMatthew Wilber rect.bottom += 1; 134cdb89ebbSMatthew Wilber BScrollBar *phscroll; 135d3046f7dSMichael Pfeiffer phscroll = new BScrollBar(rect, "hscroll", fImageView, 0, 150, 136cdb89ebbSMatthew Wilber B_HORIZONTAL); 137cdb89ebbSMatthew Wilber AddChild(phscroll); 13813afa642SPhil Greenway 13913afa642SPhil Greenway rect.left = 0; 14007caaa8eSMatthew Wilber rect.right = kstatusWidth - 1; 141d3046f7dSMichael Pfeiffer fStatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM, 142cdb89ebbSMatthew Wilber B_WILL_DRAW); 143d3046f7dSMichael Pfeiffer fStatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 144d3046f7dSMichael Pfeiffer AddChild(fStatusView); 14513afa642SPhil Greenway 14613afa642SPhil Greenway rect = Bounds(); 1470916ab53SMatthew Wilber rect.top = viewFrame.top - 1; 14813afa642SPhil Greenway rect.left = viewFrame.right + 1; 1490916ab53SMatthew Wilber rect.bottom = viewFrame.bottom + 1; 1500916ab53SMatthew Wilber rect.right += 1; 151cdb89ebbSMatthew Wilber BScrollBar *pvscroll; 152d3046f7dSMichael Pfeiffer pvscroll = new BScrollBar(rect, "vscroll", fImageView, 0, 150, B_VERTICAL); 153cdb89ebbSMatthew Wilber AddChild(pvscroll); 15413afa642SPhil Greenway 15503839579SMatthew Wilber SetSizeLimits(250, 100000, 100, 100000); 15613afa642SPhil Greenway 15713afa642SPhil Greenway // finish creating window 158d3046f7dSMichael Pfeiffer fImageView->SetImage(pref); 1597eca0987SMichael Pfeiffer 160780d8a62SMichael Pfeiffer if (InitCheck() == B_OK) { 161d3046f7dSMichael Pfeiffer // add View menu here so it can access ShowImageView methods 162d3046f7dSMichael Pfeiffer BMenu* pmenu = new BMenu("View"); 163d3046f7dSMichael Pfeiffer BuildViewMenu(pmenu); 164d3046f7dSMichael Pfeiffer fBar->AddItem(pmenu); 165a8fc7138SMichael Pfeiffer MarkMenuItem(fBar, MSG_DITHER_IMAGE, fImageView->GetDither()); 166780d8a62SMichael Pfeiffer UpdateTitle(); 167780d8a62SMichael Pfeiffer 1687eca0987SMichael Pfeiffer SetPulseRate(100000); // every 1/10 second; ShowImageView needs it for marching ants 16903839579SMatthew Wilber 170d3046f7dSMichael Pfeiffer fImageView->FlushToLeftTop(); 171d3046f7dSMichael Pfeiffer WindowRedimension(fImageView->GetBitmap()); 172d3046f7dSMichael Pfeiffer fImageView->MakeFocus(true); // to receive KeyDown messages 17313afa642SPhil Greenway Show(); 174d10d5947SMichael Pfeiffer } else { 175e6a50d9cSMichael Pfeiffer BAlert* alert; 176e6a50d9cSMichael Pfeiffer alert = new BAlert("ShowImage", 177e6a50d9cSMichael Pfeiffer "Could not load image! Either the file or an image translator for it does not exist.", 178e6a50d9cSMichael Pfeiffer "OK", NULL, NULL, 179e6a50d9cSMichael Pfeiffer B_WIDTH_AS_USUAL, B_INFO_ALERT); 180e6a50d9cSMichael Pfeiffer alert->Go(); 181d10d5947SMichael Pfeiffer // exit if file could not be opened 182d10d5947SMichael Pfeiffer Quit(); 183d10d5947SMichael Pfeiffer } 184402c09e5SMatthew Wilber 185402c09e5SMatthew Wilber // Tell application object to query the clipboard 186402c09e5SMatthew Wilber // and tell this window if it contains interesting data or not 187402c09e5SMatthew Wilber be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED); 18813afa642SPhil Greenway } 18913afa642SPhil Greenway 19013afa642SPhil Greenway ShowImageWindow::~ShowImageWindow() 19113afa642SPhil Greenway { 19213afa642SPhil Greenway } 19313afa642SPhil Greenway 194cdb89ebbSMatthew Wilber status_t 195cdb89ebbSMatthew Wilber ShowImageWindow::InitCheck() 19613afa642SPhil Greenway { 197d3046f7dSMichael Pfeiffer if (!fImageView || fImageView->GetBitmap() == NULL) 19813afa642SPhil Greenway return B_ERROR; 199cdb89ebbSMatthew Wilber else 20013afa642SPhil Greenway return B_OK; 20113afa642SPhil Greenway } 202cdb89ebbSMatthew Wilber 203cdb89ebbSMatthew Wilber void 204cdb89ebbSMatthew Wilber ShowImageWindow::UpdateTitle() 20513afa642SPhil Greenway { 206e6a50d9cSMichael Pfeiffer BString path; 207d3046f7dSMichael Pfeiffer fImageView->GetPath(&path); 208e6a50d9cSMichael Pfeiffer SetTitle(path.String()); 20913afa642SPhil Greenway } 21013afa642SPhil Greenway 211cdb89ebbSMatthew Wilber void 212da87390fSMichael Pfeiffer ShowImageWindow::BuildViewMenu(BMenu *pmenu) 213da87390fSMichael Pfeiffer { 214da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Slide Show", MSG_SLIDE_SHOW, 0, 0, 'W', true); 215d3046f7dSMichael Pfeiffer MarkMenuItem(pmenu, MSG_SLIDE_SHOW, fImageView->SlideShowStarted()); 216da87390fSMichael Pfeiffer BMenu* pDelay = new BMenu("Slide Delay"); 217d3046f7dSMichael Pfeiffer if (fSlideShowDelay == NULL) { 218d3046f7dSMichael Pfeiffer fSlideShowDelay = pDelay; 219da87390fSMichael Pfeiffer } 220da87390fSMichael Pfeiffer pDelay->SetRadioMode(true); 221da87390fSMichael Pfeiffer // Note: ShowImage loades images in window thread so it becomes unresponsive if 222da87390fSMichael Pfeiffer // slide show delay is too short! (Especially if loading the image takes as long as 223da87390fSMichael Pfeiffer // or longer than the slide show delay). Should load in background thread! 224d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Three Seconds", 3); 225d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Four Second", 4); 226d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Five Seconds", 5); 227d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Six Seconds", 6); 228d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Seven Seconds", 7); 229d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Eight Seconds", 8); 230d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Nine Seconds", 9); 231d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Ten Seconds", 10); 232d3046f7dSMichael Pfeiffer AddDelayItem(pDelay, "Twenty Seconds", 20); 233da87390fSMichael Pfeiffer pmenu->AddItem(pDelay); 234da87390fSMichael Pfeiffer pmenu->AddSeparatorItem(); 235da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Original Size", MSG_ORIGINAL_SIZE, 0, 0, 'W', true); 236da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Zoom In", MSG_ZOOM_IN, '+', 0, 'W', true); 237da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Zoom Out", MSG_ZOOM_OUT, '-', 0, 'W', true); 238d3046f7dSMichael Pfeiffer pmenu->AddSeparatorItem(); 23981b9c776SMichael Pfeiffer AddItemMenu(pmenu, "Scale Bilinear", MSG_SCALE_BILINEAR, 0, 0, 'W', true); 240da87390fSMichael Pfeiffer pmenu->AddSeparatorItem(); 24119c76de4SMichael Pfeiffer AddItemMenu(pmenu, "Shrink to Window", MSG_SHRINK_TO_WINDOW, 0, 0, 'W', true); 24219c76de4SMichael Pfeiffer AddItemMenu(pmenu, "Zoom to Window", MSG_ZOOM_TO_WINDOW, 0, 0, 'W', true); 243d3046f7dSMichael Pfeiffer pmenu->AddSeparatorItem(); 24430060f17SMatthew Wilber AddItemMenu(pmenu, "Full Screen", MSG_FULL_SCREEN, 'F', 0, 'W', true); 24581b9c776SMichael Pfeiffer MarkMenuItem(pmenu, MSG_FULL_SCREEN, fFullScreen); 24630060f17SMatthew Wilber BMessage *pFullScreen = new BMessage(MSG_FULL_SCREEN); 24730060f17SMatthew Wilber AddShortcut(B_ENTER, 0, pFullScreen); 24830060f17SMatthew Wilber 249da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Show Caption in Full Screen Mode", MSG_SHOW_CAPTION, 0, 0, 'W', true); 250da87390fSMichael Pfeiffer MarkMenuItem(pmenu, MSG_SHOW_CAPTION, fShowCaption); 251da87390fSMichael Pfeiffer 25219c76de4SMichael Pfeiffer bool shrink, zoom, enabled; 253d3046f7dSMichael Pfeiffer MarkMenuItem(pmenu, MSG_SCALE_BILINEAR, fImageView->GetScaleBilinear()); 254d3046f7dSMichael Pfeiffer shrink = fImageView->GetShrinkToBounds(); 255d3046f7dSMichael Pfeiffer zoom = fImageView->GetZoomToBounds(); 25619c76de4SMichael Pfeiffer MarkMenuItem(pmenu, MSG_SHRINK_TO_WINDOW, shrink); 25719c76de4SMichael Pfeiffer MarkMenuItem(pmenu, MSG_ZOOM_TO_WINDOW, zoom); 25819c76de4SMichael Pfeiffer enabled = !(shrink || zoom); 25919c76de4SMichael Pfeiffer EnableMenuItem(pmenu, MSG_ORIGINAL_SIZE, enabled); 26019c76de4SMichael Pfeiffer EnableMenuItem(pmenu, MSG_ZOOM_IN, enabled); 26119c76de4SMichael Pfeiffer EnableMenuItem(pmenu, MSG_ZOOM_OUT, enabled); 262da87390fSMichael Pfeiffer } 263da87390fSMichael Pfeiffer 264da87390fSMichael Pfeiffer void 265cdb89ebbSMatthew Wilber ShowImageWindow::LoadMenus(BMenuBar *pbar) 26613afa642SPhil Greenway { 267cdb89ebbSMatthew Wilber BMenu *pmenu = new BMenu("File"); 268a8fc7138SMichael Pfeiffer fOpenMenu = new RecentDocumentsMenu("Open"); 269d3046f7dSMichael Pfeiffer pmenu->AddItem(fOpenMenu); 270d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetTrigger('O'); 271d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetMessage(new BMessage(MSG_FILE_OPEN)); 272d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetTarget(be_app); 273d3046f7dSMichael Pfeiffer fOpenMenu->Superitem()->SetShortcut('O', 0); 274cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 275780d8a62SMichael Pfeiffer BMenu *pmenuSaveAs = new BMenu("Save As" B_UTF8_ELLIPSIS, B_ITEMS_IN_COLUMN); 276cdb89ebbSMatthew Wilber BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP); 277fc0a275bSMatthew Wilber // Fill Save As submenu with all types that can be converted 278fc0a275bSMatthew Wilber // to from the Be bitmap image format 279cdb89ebbSMatthew Wilber pmenu->AddItem(pmenuSaveAs); 280cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Close", MSG_CLOSE, 'W', 0, 'W', true); 281cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 282780d8a62SMichael Pfeiffer AddItemMenu(pmenu, "Page Setup" B_UTF8_ELLIPSIS, MSG_PAGE_SETUP, 0, 0, 'W', true); 283780d8a62SMichael Pfeiffer AddItemMenu(pmenu, "Print" B_UTF8_ELLIPSIS, MSG_PREPARE_PRINT, 0, 0, 'W', true); 284780d8a62SMichael Pfeiffer pmenu->AddSeparatorItem(); 285780d8a62SMichael Pfeiffer AddItemMenu(pmenu, "About ShowImage" B_UTF8_ELLIPSIS, B_ABOUT_REQUESTED, 0, 0, 'A', true); 286cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 287cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true); 288cdb89ebbSMatthew Wilber pbar->AddItem(pmenu); 28913afa642SPhil Greenway 290cdb89ebbSMatthew Wilber pmenu = new BMenu("Edit"); 291cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Undo", B_UNDO, 'Z', 0, 'W', false); 292cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 293cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Cut", B_CUT, 'X', 0, 'W', false); 2948ad30bcfSMatthew Wilber AddItemMenu(pmenu, "Copy", B_COPY, 'C', 0, 'W', false); 295cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Paste", B_PASTE, 'V', 0, 'W', false); 296da87390fSMichael Pfeiffer AddItemMenu(pmenu, "Clear", MSG_CLEAR_SELECT, 0, 0, 'W', false); 297cdb89ebbSMatthew Wilber pmenu->AddSeparatorItem(); 298d10d5947SMichael Pfeiffer AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', true); 299cdb89ebbSMatthew Wilber pbar->AddItem(pmenu); 30013afa642SPhil Greenway 301d3046f7dSMichael Pfeiffer pmenu = fBrowseMenu = new BMenu("Browse"); 3022cb9af89SMatthew Wilber AddItemMenu(pmenu, "First Page", MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, 'W', true); 3032cb9af89SMatthew Wilber AddItemMenu(pmenu, "Last Page", MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, 'W', true); 3042cb9af89SMatthew Wilber AddItemMenu(pmenu, "Next Page", MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, 'W', true); 3052cb9af89SMatthew Wilber AddItemMenu(pmenu, "Previous Page", MSG_PAGE_PREV, B_LEFT_ARROW, 0, 'W', true); 306d3046f7dSMichael Pfeiffer fGoToPageMenu = new BMenu("Go To Page"); 3075e427b6aSMichael Pfeiffer fGoToPageMenu->SetRadioMode(true); 308d3046f7dSMichael Pfeiffer pmenu->AddItem(fGoToPageMenu); 309e6a50d9cSMichael Pfeiffer pmenu->AddSeparatorItem(); 310e6a50d9cSMichael Pfeiffer AddItemMenu(pmenu, "Next File", MSG_FILE_NEXT, B_DOWN_ARROW, 0, 'W', true); 311e6a50d9cSMichael Pfeiffer AddItemMenu(pmenu, "Previous File", MSG_FILE_PREV, B_UP_ARROW, 0, 'W', true); 31203839579SMatthew Wilber pbar->AddItem(pmenu); 31303839579SMatthew Wilber 314cdb89ebbSMatthew Wilber pmenu = new BMenu("Image"); 315cdb89ebbSMatthew Wilber AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true); 316ad13f387SMichael Pfeiffer pmenu->AddSeparatorItem(); 317bf461dbeSMatthew Wilber AddItemMenu(pmenu, "Rotate +90", MSG_ROTATE_90, ']', 0, 'W', true); 318bf461dbeSMatthew Wilber AddItemMenu(pmenu, "Rotate -90", MSG_ROTATE_270, '[', 0, 'W', true); 319ad13f387SMichael Pfeiffer pmenu->AddSeparatorItem(); 320ad13f387SMichael Pfeiffer AddItemMenu(pmenu, "Mirror Vertical", MSG_MIRROR_VERTICAL, 0, 0, 'W', true); 321ad13f387SMichael Pfeiffer AddItemMenu(pmenu, "Mirror Horizontal", MSG_MIRROR_HORIZONTAL, 0, 0, 'W', true); 322ad13f387SMichael Pfeiffer pmenu->AddSeparatorItem(); 323ad13f387SMichael Pfeiffer AddItemMenu(pmenu, "Invert", MSG_INVERT, 0, 0, 'W', true); 324ad13f387SMichael Pfeiffer pbar->AddItem(pmenu); 32513afa642SPhil Greenway } 32613afa642SPhil Greenway 327cdb89ebbSMatthew Wilber BMenuItem * 328cdb89ebbSMatthew Wilber ShowImageWindow::AddItemMenu(BMenu *pmenu, char *caption, long unsigned int msg, 329cdb89ebbSMatthew Wilber char shortcut, uint32 modifier, char target, bool benabled) 330cdb89ebbSMatthew Wilber { 331cdb89ebbSMatthew Wilber BMenuItem* pitem; 3322cb9af89SMatthew Wilber pitem = new BMenuItem(caption, new BMessage(msg), shortcut, modifier); 33313afa642SPhil Greenway 33413afa642SPhil Greenway if (target == 'A') 335cdb89ebbSMatthew Wilber pitem->SetTarget(be_app); 336da87390fSMichael Pfeiffer else 337da87390fSMichael Pfeiffer pitem->SetTarget(this); 338cdb89ebbSMatthew Wilber pitem->SetEnabled(benabled); 339cdb89ebbSMatthew Wilber pmenu->AddItem(pitem); 34013afa642SPhil Greenway 341cdb89ebbSMatthew Wilber return pitem; 34213afa642SPhil Greenway } 34313afa642SPhil Greenway 344ad13f387SMichael Pfeiffer BMenuItem* 345d3046f7dSMichael Pfeiffer ShowImageWindow::AddDelayItem(BMenu *pmenu, char *caption, float value) 346ad13f387SMichael Pfeiffer { 347ad13f387SMichael Pfeiffer BMenuItem* pitem; 348ad13f387SMichael Pfeiffer BMessage* pmsg; 349e6a50d9cSMichael Pfeiffer pmsg = new BMessage(MSG_SLIDE_SHOW_DELAY); 350ad13f387SMichael Pfeiffer pmsg->AddFloat("value", value); 351ad13f387SMichael Pfeiffer 352ad13f387SMichael Pfeiffer pitem = new BMenuItem(caption, pmsg, 0); 353da87390fSMichael Pfeiffer pitem->SetTarget(this); 354ad13f387SMichael Pfeiffer 355d3046f7dSMichael Pfeiffer bool marked = fImageView->GetSlideShowDelay() == value; 356ad13f387SMichael Pfeiffer if (marked) pitem->SetMarked(true); 357ad13f387SMichael Pfeiffer pmenu->AddItem(pitem); 358ad13f387SMichael Pfeiffer 359ad13f387SMichael Pfeiffer return pitem; 360ad13f387SMichael Pfeiffer } 361ad13f387SMichael Pfeiffer 362cdb89ebbSMatthew Wilber void 363cdb89ebbSMatthew Wilber ShowImageWindow::WindowRedimension(BBitmap *pbitmap) 36413afa642SPhil Greenway { 365d10d5947SMichael Pfeiffer BScreen screen; 366d10d5947SMichael Pfeiffer BRect r(pbitmap->Bounds()); 367d10d5947SMichael Pfeiffer float width, height; 368d10d5947SMichael Pfeiffer float maxWidth, maxHeight; 369a8fc7138SMichael Pfeiffer float minW, maxW, minH, maxH; 370d10d5947SMichael Pfeiffer const float windowBorderWidth = 5; 371d10d5947SMichael Pfeiffer const float windowBorderHeight = 5; 37213afa642SPhil Greenway 373d10d5947SMichael Pfeiffer if (screen.Frame().right == 0.0) { 374d10d5947SMichael Pfeiffer return; // invalid screen object 375d10d5947SMichael Pfeiffer } 376cdb89ebbSMatthew Wilber 377d10d5947SMichael Pfeiffer width = r.Width() + B_V_SCROLL_BAR_WIDTH; 378d3046f7dSMichael Pfeiffer height = r.Height() + 1 + fBar->Frame().Height() + B_H_SCROLL_BAR_HEIGHT; 379cdb89ebbSMatthew Wilber 380d10d5947SMichael Pfeiffer // dimensions so that window does not reach outside of screen 381d10d5947SMichael Pfeiffer maxWidth = screen.Frame().Width() + 1 - windowBorderWidth - Frame().left; 382d10d5947SMichael Pfeiffer maxHeight = screen.Frame().Height() + 1 - windowBorderHeight - Frame().top; 383cdb89ebbSMatthew Wilber 384a8fc7138SMichael Pfeiffer // We have to check size limits manually, otherwise 385a8fc7138SMichael Pfeiffer // menu bar will be too short for small images. 386a8fc7138SMichael Pfeiffer GetSizeLimits(&minW, &maxW, &minH, &maxH); 387a8fc7138SMichael Pfeiffer if (maxWidth > maxW) maxWidth = maxW; 388a8fc7138SMichael Pfeiffer if (maxHeight > maxH) maxHeight = maxH; 389a8fc7138SMichael Pfeiffer if (width < minW) width = minW; 390a8fc7138SMichael Pfeiffer if (height < minH) height = minH; 391a8fc7138SMichael Pfeiffer 392d10d5947SMichael Pfeiffer if (width > maxWidth) width = maxWidth; 393d10d5947SMichael Pfeiffer if (height > maxHeight) height = maxHeight; 394d10d5947SMichael Pfeiffer 395d10d5947SMichael Pfeiffer ResizeTo(width, height); 39613afa642SPhil Greenway } 39713afa642SPhil Greenway 398cdb89ebbSMatthew Wilber void 399cdb89ebbSMatthew Wilber ShowImageWindow::FrameResized(float width, float height) 40013afa642SPhil Greenway { 40113afa642SPhil Greenway } 40213afa642SPhil Greenway 4037eca0987SMichael Pfeiffer bool 4047eca0987SMichael Pfeiffer ShowImageWindow::ToggleMenuItem(uint32 what) 4057eca0987SMichael Pfeiffer { 4067eca0987SMichael Pfeiffer BMenuItem *item; 4077eca0987SMichael Pfeiffer bool marked = false; 408d3046f7dSMichael Pfeiffer item = fBar->FindItem(what); 4097eca0987SMichael Pfeiffer if (item != NULL) { 4107eca0987SMichael Pfeiffer marked = !item->IsMarked(); 4117eca0987SMichael Pfeiffer item->SetMarked(marked); 4127eca0987SMichael Pfeiffer } 4137eca0987SMichael Pfeiffer return marked; 4147eca0987SMichael Pfeiffer } 4157eca0987SMichael Pfeiffer 416cdb89ebbSMatthew Wilber void 417da87390fSMichael Pfeiffer ShowImageWindow::EnableMenuItem(BMenu *menu, uint32 what, bool enable) 418e6a50d9cSMichael Pfeiffer { 419e6a50d9cSMichael Pfeiffer BMenuItem* item; 420da87390fSMichael Pfeiffer item = menu->FindItem(what); 421e6a50d9cSMichael Pfeiffer if (item && item->IsEnabled() != enable) { 422e6a50d9cSMichael Pfeiffer item->SetEnabled(enable); 423e6a50d9cSMichael Pfeiffer } 424e6a50d9cSMichael Pfeiffer } 425e6a50d9cSMichael Pfeiffer 426e6a50d9cSMichael Pfeiffer void 427da87390fSMichael Pfeiffer ShowImageWindow::MarkMenuItem(BMenu *menu, uint32 what, bool marked) 428e6a50d9cSMichael Pfeiffer { 429e6a50d9cSMichael Pfeiffer BMenuItem* item; 430da87390fSMichael Pfeiffer item = menu->FindItem(what); 431e6a50d9cSMichael Pfeiffer if (item && item->IsMarked() != marked) { 432e6a50d9cSMichael Pfeiffer item->SetMarked(marked); 433e6a50d9cSMichael Pfeiffer } 434e6a50d9cSMichael Pfeiffer } 435e6a50d9cSMichael Pfeiffer 436da87390fSMichael Pfeiffer void 437da87390fSMichael Pfeiffer ShowImageWindow::MarkSlideShowDelay(float value) 438da87390fSMichael Pfeiffer { 439d3046f7dSMichael Pfeiffer const int32 n = fSlideShowDelay->CountItems(); 440da87390fSMichael Pfeiffer float v; 441da87390fSMichael Pfeiffer for (int32 i = 0; i < n; i ++) { 442d3046f7dSMichael Pfeiffer BMenuItem* item = fSlideShowDelay->ItemAt(i); 443da87390fSMichael Pfeiffer if (item) { 444da87390fSMichael Pfeiffer if (item->Message()->FindFloat("value", &v) == B_OK && v == value) { 445da87390fSMichael Pfeiffer if (!item->IsMarked()) { 446da87390fSMichael Pfeiffer item->SetMarked(true); 447da87390fSMichael Pfeiffer } 448da87390fSMichael Pfeiffer return; 449da87390fSMichael Pfeiffer } 450da87390fSMichael Pfeiffer } 451da87390fSMichael Pfeiffer } 452da87390fSMichael Pfeiffer } 453e6a50d9cSMichael Pfeiffer 45419c76de4SMichael Pfeiffer 45519c76de4SMichael Pfeiffer void 45619c76de4SMichael Pfeiffer ShowImageWindow::ResizeToWindow(bool shrink, uint32 what) 45719c76de4SMichael Pfeiffer { 45819c76de4SMichael Pfeiffer bool enabled; 45919c76de4SMichael Pfeiffer enabled = ToggleMenuItem(what); 46019c76de4SMichael Pfeiffer if (shrink) { 461d3046f7dSMichael Pfeiffer fImageView->SetShrinkToBounds(enabled); 46219c76de4SMichael Pfeiffer } else { 463d3046f7dSMichael Pfeiffer fImageView->SetZoomToBounds(enabled); 46419c76de4SMichael Pfeiffer } 465d3046f7dSMichael Pfeiffer enabled = !(fImageView->GetShrinkToBounds() || fImageView->GetZoomToBounds()); 466d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_ORIGINAL_SIZE, enabled); 467d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_ZOOM_IN, enabled); 468d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_ZOOM_OUT, enabled); 46919c76de4SMichael Pfeiffer } 47019c76de4SMichael Pfeiffer 471e6a50d9cSMichael Pfeiffer void 472cdb89ebbSMatthew Wilber ShowImageWindow::MessageReceived(BMessage *pmsg) 47313afa642SPhil Greenway { 474d3046f7dSMichael Pfeiffer ShowImageSettings* settings; 475cdb89ebbSMatthew Wilber switch (pmsg->what) { 476ee7b4f39SMatthew Wilber case MSG_MODIFIED: 477ee7b4f39SMatthew Wilber // If image has been modified due to a Cut or Paste 478ee7b4f39SMatthew Wilber fModified = true; 479ee7b4f39SMatthew Wilber break; 480ee7b4f39SMatthew Wilber 481fc0a275bSMatthew Wilber case MSG_OUTPUT_TYPE: 482fc0a275bSMatthew Wilber // User clicked Save As then choose an output format 483d3046f7dSMichael Pfeiffer if (!fSavePanel) 484cdb89ebbSMatthew Wilber // If user doesn't already have a save panel open 485cdb89ebbSMatthew Wilber SaveAs(pmsg); 48613afa642SPhil Greenway break; 487fc0a275bSMatthew Wilber 488fc0a275bSMatthew Wilber case MSG_SAVE_PANEL: 489fc0a275bSMatthew Wilber // User specified where to save the output image 490cdb89ebbSMatthew Wilber SaveToFile(pmsg); 491fc0a275bSMatthew Wilber break; 492fc0a275bSMatthew Wilber 49307caaa8eSMatthew Wilber case MSG_CLOSE: 494cdb89ebbSMatthew Wilber if (CanQuit()) 49507caaa8eSMatthew Wilber Quit(); 49607caaa8eSMatthew Wilber break; 49707caaa8eSMatthew Wilber 498cdb89ebbSMatthew Wilber case B_CANCEL: 499d3046f7dSMichael Pfeiffer delete fSavePanel; 500d3046f7dSMichael Pfeiffer fSavePanel = NULL; 501cdb89ebbSMatthew Wilber break; 502cdb89ebbSMatthew Wilber 50303839579SMatthew Wilber case MSG_UPDATE_STATUS: 50403839579SMatthew Wilber { 5056c305411SMatthew Wilber int32 pages, curPage; 506d3046f7dSMichael Pfeiffer pages = fImageView->PageCount(); 507d3046f7dSMichael Pfeiffer curPage = fImageView->CurrentPage(); 5086c305411SMatthew Wilber 5096c305411SMatthew Wilber bool benable = (pages > 1) ? true : false; 510d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_FIRST, benable); 511d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_LAST, benable); 512d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_NEXT, benable); 513d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_PAGE_PREV, benable); 5141d592070SMatthew Wilber 515d3046f7dSMichael Pfeiffer if (fGoToPageMenu->CountItems() != pages) { 5166c305411SMatthew Wilber // Only rebuild the submenu if the number of 5176c305411SMatthew Wilber // pages is different 5186c305411SMatthew Wilber 519d3046f7dSMichael Pfeiffer while (fGoToPageMenu->CountItems() > 0) 5206c305411SMatthew Wilber // Remove all page numbers 521d3046f7dSMichael Pfeiffer delete fGoToPageMenu->RemoveItem(0L); 5226c305411SMatthew Wilber 523780d8a62SMichael Pfeiffer for (int32 i = 1; i <= pages; i++) { 5246c305411SMatthew Wilber // Fill Go To page submenu with an entry for each page 5256c305411SMatthew Wilber BMessage *pgomsg; 526780d8a62SMichael Pfeiffer char shortcut = 0; 5276c305411SMatthew Wilber pgomsg = new BMessage(MSG_GOTO_PAGE); 5286c305411SMatthew Wilber pgomsg->AddInt32("page", i); 5296c305411SMatthew Wilber BString strCaption; 5306c305411SMatthew Wilber strCaption << i; 5316c305411SMatthew Wilber BMenuItem *pitem; 532780d8a62SMichael Pfeiffer if (i < 10) { 533780d8a62SMichael Pfeiffer shortcut = '0' + i; 534780d8a62SMichael Pfeiffer } else if (i == 10) { 535780d8a62SMichael Pfeiffer shortcut = '0'; 536780d8a62SMichael Pfeiffer } 537780d8a62SMichael Pfeiffer pitem = new BMenuItem(strCaption.String(), pgomsg, shortcut); 5386c305411SMatthew Wilber if (curPage == i) 5396c305411SMatthew Wilber pitem->SetMarked(true); 540d3046f7dSMichael Pfeiffer fGoToPageMenu->AddItem(pitem); 5416c305411SMatthew Wilber } 5426c305411SMatthew Wilber } else { 5436c305411SMatthew Wilber // Make sure the correct page is marked 5446c305411SMatthew Wilber BMenuItem *pcurItem; 545d3046f7dSMichael Pfeiffer pcurItem = fGoToPageMenu->ItemAt(curPage - 1); 5466c305411SMatthew Wilber if (!pcurItem->IsMarked()) { 5476c305411SMatthew Wilber pcurItem->SetMarked(true); 5486c305411SMatthew Wilber } 5496c305411SMatthew Wilber } 5506c305411SMatthew Wilber 55116b663b7SMatthew Wilber // Disable the Invert menu item if the bitmap color space 55216b663b7SMatthew Wilber // is B_CMAP8. (B_CMAP8 is currently unsupported by the 55316b663b7SMatthew Wilber // invert algorithm) 55416b663b7SMatthew Wilber color_space colors = B_NO_COLOR_SPACE; 55516b663b7SMatthew Wilber pmsg->FindInt32("colors", reinterpret_cast<int32 *>(&colors)); 55616b663b7SMatthew Wilber EnableMenuItem(fBar, MSG_INVERT, (colors != B_CMAP8)); 55716b663b7SMatthew Wilber 55803839579SMatthew Wilber BString str; 55903839579SMatthew Wilber if (pmsg->FindString("status", &str) == B_OK) 560d3046f7dSMichael Pfeiffer fStatusView->SetText(str); 5617eca0987SMichael Pfeiffer 5627eca0987SMichael Pfeiffer UpdateTitle(); 56303839579SMatthew Wilber break; 56403839579SMatthew Wilber } 56503839579SMatthew Wilber 5668ad30bcfSMatthew Wilber case MSG_SELECTION: 5678ad30bcfSMatthew Wilber { 5688ad30bcfSMatthew Wilber // The view sends this message when a selection is 5698ad30bcfSMatthew Wilber // made or the selection is cleared so that the window 5708ad30bcfSMatthew Wilber // can update the state of the appropriate menu items 5718ad30bcfSMatthew Wilber bool benable; 5728ad30bcfSMatthew Wilber if (pmsg->FindBool("has_selection", &benable) == B_OK) { 573d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, B_CUT, benable); 574d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, B_COPY, benable); 575d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, MSG_CLEAR_SELECT, benable); 5768ad30bcfSMatthew Wilber } 5778ad30bcfSMatthew Wilber break; 5788ad30bcfSMatthew Wilber } 5798ad30bcfSMatthew Wilber 5807598450eSMatthew Wilber case MSG_UNDO_STATE: 5817598450eSMatthew Wilber { 5827598450eSMatthew Wilber bool benable; 5837598450eSMatthew Wilber if (pmsg->FindBool("can_undo", &benable) == B_OK) 5847598450eSMatthew Wilber EnableMenuItem(fBar, B_UNDO, benable); 5857598450eSMatthew Wilber break; 5867598450eSMatthew Wilber } 5877598450eSMatthew Wilber 588402c09e5SMatthew Wilber case MSG_CLIPBOARD_CHANGED: 589402c09e5SMatthew Wilber { 590402c09e5SMatthew Wilber // The app sends this message after it examines 591402c09e5SMatthew Wilber // the clipboard in response to a B_CLIPBOARD_CHANGED 592402c09e5SMatthew Wilber // message 593402c09e5SMatthew Wilber bool bdata; 594402c09e5SMatthew Wilber if (pmsg->FindBool("data_available", &bdata) == B_OK) 595d3046f7dSMichael Pfeiffer EnableMenuItem(fBar, B_PASTE, bdata); 596402c09e5SMatthew Wilber break; 597402c09e5SMatthew Wilber } 598402c09e5SMatthew Wilber 59913afa642SPhil Greenway case B_UNDO: 6007598450eSMatthew Wilber fImageView->Undo(); 60113afa642SPhil Greenway break; 60213afa642SPhil Greenway case B_CUT: 603d3046f7dSMichael Pfeiffer fImageView->Cut(); 60413afa642SPhil Greenway break; 60513afa642SPhil Greenway case B_COPY: 606d3046f7dSMichael Pfeiffer fImageView->CopySelectionToClipboard(); 60713afa642SPhil Greenway break; 60813afa642SPhil Greenway case B_PASTE: 609d3046f7dSMichael Pfeiffer fImageView->Paste(); 61013afa642SPhil Greenway break; 61113afa642SPhil Greenway case MSG_CLEAR_SELECT: 612d3046f7dSMichael Pfeiffer fImageView->ClearSelection(); 61313afa642SPhil Greenway break; 61413afa642SPhil Greenway case MSG_SELECT_ALL: 615d3046f7dSMichael Pfeiffer fImageView->SelectAll(); 61613afa642SPhil Greenway break; 61713afa642SPhil Greenway 61803839579SMatthew Wilber case MSG_PAGE_FIRST: 619ee7b4f39SMatthew Wilber if (ClosePrompt()) 620d3046f7dSMichael Pfeiffer fImageView->FirstPage(); 62103839579SMatthew Wilber break; 62203839579SMatthew Wilber 62303839579SMatthew Wilber case MSG_PAGE_LAST: 624ee7b4f39SMatthew Wilber if (ClosePrompt()) 625d3046f7dSMichael Pfeiffer fImageView->LastPage(); 62603839579SMatthew Wilber break; 62703839579SMatthew Wilber 62803839579SMatthew Wilber case MSG_PAGE_NEXT: 629ee7b4f39SMatthew Wilber if (ClosePrompt()) 630d3046f7dSMichael Pfeiffer fImageView->NextPage(); 63103839579SMatthew Wilber break; 63203839579SMatthew Wilber 63303839579SMatthew Wilber case MSG_PAGE_PREV: 634ee7b4f39SMatthew Wilber if (ClosePrompt()) 635d3046f7dSMichael Pfeiffer fImageView->PrevPage(); 63603839579SMatthew Wilber break; 63703839579SMatthew Wilber 6386c305411SMatthew Wilber case MSG_GOTO_PAGE: 6396c305411SMatthew Wilber { 640ee7b4f39SMatthew Wilber if (!ClosePrompt()) 641ee7b4f39SMatthew Wilber break; 642ee7b4f39SMatthew Wilber 6436c305411SMatthew Wilber int32 curPage, newPage, pages; 6446c305411SMatthew Wilber if (pmsg->FindInt32("page", &newPage) == B_OK) { 645d3046f7dSMichael Pfeiffer curPage = fImageView->CurrentPage(); 646d3046f7dSMichael Pfeiffer pages = fImageView->PageCount(); 6476c305411SMatthew Wilber 6486c305411SMatthew Wilber if (newPage > 0 && newPage <= pages) { 6496c305411SMatthew Wilber BMenuItem *pcurItem, *pnewItem; 650d3046f7dSMichael Pfeiffer pcurItem = fGoToPageMenu->ItemAt(curPage - 1); 651d3046f7dSMichael Pfeiffer pnewItem = fGoToPageMenu->ItemAt(newPage - 1); 6526c305411SMatthew Wilber if (!pcurItem || !pnewItem) 6536c305411SMatthew Wilber break; 6546c305411SMatthew Wilber pcurItem->SetMarked(false); 6556c305411SMatthew Wilber pnewItem->SetMarked(true); 656d3046f7dSMichael Pfeiffer fImageView->GoToPage(newPage); 6576c305411SMatthew Wilber } 6586c305411SMatthew Wilber } 6596c305411SMatthew Wilber } 6606c305411SMatthew Wilber break; 6616c305411SMatthew Wilber 662cdb89ebbSMatthew Wilber case MSG_DITHER_IMAGE: 663a8fc7138SMichael Pfeiffer fImageView->SetDither(ToggleMenuItem(pmsg->what)); 6647eca0987SMichael Pfeiffer break; 6657eca0987SMichael Pfeiffer 66619c76de4SMichael Pfeiffer case MSG_SHRINK_TO_WINDOW: 66719c76de4SMichael Pfeiffer ResizeToWindow(true, pmsg->what); 66819c76de4SMichael Pfeiffer break; 66919c76de4SMichael Pfeiffer case MSG_ZOOM_TO_WINDOW: 67019c76de4SMichael Pfeiffer ResizeToWindow(false, pmsg->what); 6717eca0987SMichael Pfeiffer break; 6727eca0987SMichael Pfeiffer 6737eca0987SMichael Pfeiffer case MSG_FILE_PREV: 674ee7b4f39SMatthew Wilber if (ClosePrompt()) 675d3046f7dSMichael Pfeiffer fImageView->PrevFile(); 6767eca0987SMichael Pfeiffer break; 6777eca0987SMichael Pfeiffer 6787eca0987SMichael Pfeiffer case MSG_FILE_NEXT: 679ee7b4f39SMatthew Wilber if (ClosePrompt()) 680d3046f7dSMichael Pfeiffer fImageView->NextFile(); 68113afa642SPhil Greenway break; 68213afa642SPhil Greenway 683bf461dbeSMatthew Wilber case MSG_ROTATE_90: 684d3046f7dSMichael Pfeiffer fImageView->Rotate(90); 685ad13f387SMichael Pfeiffer break; 686bf461dbeSMatthew Wilber case MSG_ROTATE_270: 687d3046f7dSMichael Pfeiffer fImageView->Rotate(270); 688ad13f387SMichael Pfeiffer break; 689ad13f387SMichael Pfeiffer case MSG_MIRROR_VERTICAL: 690d3046f7dSMichael Pfeiffer fImageView->Mirror(true); 691ad13f387SMichael Pfeiffer break; 692ad13f387SMichael Pfeiffer case MSG_MIRROR_HORIZONTAL: 693d3046f7dSMichael Pfeiffer fImageView->Mirror(false); 694ad13f387SMichael Pfeiffer break; 695ad13f387SMichael Pfeiffer case MSG_INVERT: 696d3046f7dSMichael Pfeiffer fImageView->Invert(); 697ad13f387SMichael Pfeiffer break; 698e6a50d9cSMichael Pfeiffer case MSG_SLIDE_SHOW: 699ee7b4f39SMatthew Wilber { 700ee7b4f39SMatthew Wilber BMenuItem *item; 701ee7b4f39SMatthew Wilber item = fBar->FindItem(pmsg->what); 702ee7b4f39SMatthew Wilber if (!item) 703ee7b4f39SMatthew Wilber break; 704ee7b4f39SMatthew Wilber if (item->IsMarked()) { 705ee7b4f39SMatthew Wilber item->SetMarked(false); 706d3046f7dSMichael Pfeiffer fImageView->StopSlideShow(); 707ee7b4f39SMatthew Wilber } else if (ClosePrompt()) { 708ee7b4f39SMatthew Wilber item->SetMarked(true); 709ee7b4f39SMatthew Wilber fImageView->StartSlideShow(); 710ad13f387SMichael Pfeiffer } 711ee7b4f39SMatthew Wilber } 712ee7b4f39SMatthew Wilber break; 713ee7b4f39SMatthew Wilber 714e6a50d9cSMichael Pfeiffer case MSG_SLIDE_SHOW_DELAY: 715ad13f387SMichael Pfeiffer { 716ad13f387SMichael Pfeiffer float value; 717ad13f387SMichael Pfeiffer if (pmsg->FindFloat("value", &value) == B_OK) { 718d3046f7dSMichael Pfeiffer fImageView->SetSlideShowDelay(value); 719da87390fSMichael Pfeiffer // in case message is sent from popup menu 720da87390fSMichael Pfeiffer MarkSlideShowDelay(value); 721ad13f387SMichael Pfeiffer } 722ad13f387SMichael Pfeiffer } 723ad13f387SMichael Pfeiffer break; 724ad13f387SMichael Pfeiffer 725ad13f387SMichael Pfeiffer case MSG_FULL_SCREEN: 726ad13f387SMichael Pfeiffer ToggleFullScreen(); 727ad13f387SMichael Pfeiffer break; 728e6a50d9cSMichael Pfeiffer case MSG_SHOW_CAPTION: 729e6a50d9cSMichael Pfeiffer fShowCaption = ToggleMenuItem(pmsg->what); 730d3046f7dSMichael Pfeiffer settings = my_app->Settings(); 731d3046f7dSMichael Pfeiffer if (settings->Lock()) { 732d3046f7dSMichael Pfeiffer settings->SetBool("ShowCaption", fShowCaption); 733d3046f7dSMichael Pfeiffer settings->Unlock(); 734d3046f7dSMichael Pfeiffer } 735e6a50d9cSMichael Pfeiffer if (fFullScreen) { 736d3046f7dSMichael Pfeiffer fImageView->SetShowCaption(fShowCaption); 737e6a50d9cSMichael Pfeiffer } 738e6a50d9cSMichael Pfeiffer break; 739ad13f387SMichael Pfeiffer 740780d8a62SMichael Pfeiffer case MSG_PAGE_SETUP: 741780d8a62SMichael Pfeiffer PageSetup(); 742780d8a62SMichael Pfeiffer break; 743780d8a62SMichael Pfeiffer case MSG_PREPARE_PRINT: 744780d8a62SMichael Pfeiffer PrepareForPrint(); 745780d8a62SMichael Pfeiffer break; 746780d8a62SMichael Pfeiffer case MSG_PRINT: 747780d8a62SMichael Pfeiffer Print(pmsg); 748780d8a62SMichael Pfeiffer break; 749780d8a62SMichael Pfeiffer 750780d8a62SMichael Pfeiffer case MSG_ZOOM_IN: 751d3046f7dSMichael Pfeiffer fImageView->ZoomIn(); 752780d8a62SMichael Pfeiffer break; 753780d8a62SMichael Pfeiffer case MSG_ZOOM_OUT: 754d3046f7dSMichael Pfeiffer fImageView->ZoomOut(); 755780d8a62SMichael Pfeiffer break; 756780d8a62SMichael Pfeiffer case MSG_ORIGINAL_SIZE: 757d3046f7dSMichael Pfeiffer fImageView->SetZoom(1.0); 758780d8a62SMichael Pfeiffer break; 75981b9c776SMichael Pfeiffer case MSG_SCALE_BILINEAR: 760d3046f7dSMichael Pfeiffer fImageView->SetScaleBilinear(ToggleMenuItem(pmsg->what)); 76181b9c776SMichael Pfeiffer break; 762780d8a62SMichael Pfeiffer 76313afa642SPhil Greenway default: 764cdb89ebbSMatthew Wilber BWindow::MessageReceived(pmsg); 76513afa642SPhil Greenway break; 76613afa642SPhil Greenway } 76713afa642SPhil Greenway } 768fc0a275bSMatthew Wilber 769fc0a275bSMatthew Wilber void 770fc0a275bSMatthew Wilber ShowImageWindow::SaveAs(BMessage *pmsg) 771fc0a275bSMatthew Wilber { 772cdb89ebbSMatthew Wilber // Read the translator and output type the user chose 773cdb89ebbSMatthew Wilber translator_id outTranslator; 774cdb89ebbSMatthew Wilber uint32 outType; 775cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TRANSLATOR_FLD, 776cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outTranslator)) != B_OK) 777fc0a275bSMatthew Wilber return; 778cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TYPE_FLD, 779cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outType)) != B_OK) 780fc0a275bSMatthew Wilber return; 781fc0a275bSMatthew Wilber 782cdb89ebbSMatthew Wilber // Add the chosen translator and output type to the 783cdb89ebbSMatthew Wilber // message that the save panel will send back 784cdb89ebbSMatthew Wilber BMessage *ppanelMsg = new BMessage(MSG_SAVE_PANEL); 785cdb89ebbSMatthew Wilber ppanelMsg->AddInt32(TRANSLATOR_FLD, outTranslator); 786cdb89ebbSMatthew Wilber ppanelMsg->AddInt32(TYPE_FLD, outType); 787cdb89ebbSMatthew Wilber 788cdb89ebbSMatthew Wilber // Create save panel and show it 789d3046f7dSMichael Pfeiffer fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0, 790cdb89ebbSMatthew Wilber false, ppanelMsg); 791d3046f7dSMichael Pfeiffer if (!fSavePanel) 792fc0a275bSMatthew Wilber return; 793d3046f7dSMichael Pfeiffer fSavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE); 794d3046f7dSMichael Pfeiffer fSavePanel->Show(); 795fc0a275bSMatthew Wilber } 796fc0a275bSMatthew Wilber 797fc0a275bSMatthew Wilber void 798fc0a275bSMatthew Wilber ShowImageWindow::SaveToFile(BMessage *pmsg) 799fc0a275bSMatthew Wilber { 800cdb89ebbSMatthew Wilber // Read in where the file should be saved 801fc0a275bSMatthew Wilber entry_ref dirref; 802fc0a275bSMatthew Wilber if (pmsg->FindRef("directory", &dirref) != B_OK) 803fc0a275bSMatthew Wilber return; 804fc0a275bSMatthew Wilber const char *filename; 805fc0a275bSMatthew Wilber if (pmsg->FindString("name", &filename) != B_OK) 806fc0a275bSMatthew Wilber return; 807fc0a275bSMatthew Wilber 808cdb89ebbSMatthew Wilber // Read in the translator and type to be used 809cdb89ebbSMatthew Wilber // to save the output image 810cdb89ebbSMatthew Wilber translator_id outTranslator; 811cdb89ebbSMatthew Wilber uint32 outType; 812cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TRANSLATOR_FLD, 813cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outTranslator)) != B_OK) 814cdb89ebbSMatthew Wilber return; 815cdb89ebbSMatthew Wilber if (pmsg->FindInt32(TYPE_FLD, 816cdb89ebbSMatthew Wilber reinterpret_cast<int32 *>(&outType)) != B_OK) 817cdb89ebbSMatthew Wilber return; 818cdb89ebbSMatthew Wilber 819cdb89ebbSMatthew Wilber // Create the output file 820fc0a275bSMatthew Wilber BDirectory dir(&dirref); 821fc0a275bSMatthew Wilber BFile file(&dir, filename, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 822fc0a275bSMatthew Wilber if (file.InitCheck() != B_OK) 823fc0a275bSMatthew Wilber return; 824fc0a275bSMatthew Wilber 825cdb89ebbSMatthew Wilber // Translate the image and write it out to the output file 826d3046f7dSMichael Pfeiffer BBitmapStream stream(fImageView->GetBitmap()); 827fc0a275bSMatthew Wilber BTranslatorRoster *proster = BTranslatorRoster::Default(); 828cdb89ebbSMatthew Wilber if (proster->Translate(outTranslator, &stream, NULL, 829cdb89ebbSMatthew Wilber &file, outType) != B_OK) { 830fc0a275bSMatthew Wilber BAlert *palert = new BAlert(NULL, "Error writing image file.", "Ok"); 831fc0a275bSMatthew Wilber palert->Go(); 832ee7b4f39SMatthew Wilber } else 833ee7b4f39SMatthew Wilber fModified = false; 834fc0a275bSMatthew Wilber 835fc0a275bSMatthew Wilber BBitmap *pout = NULL; 836fc0a275bSMatthew Wilber stream.DetachBitmap(&pout); 837fc0a275bSMatthew Wilber // bitmap used by stream still belongs to the view, 838fc0a275bSMatthew Wilber // detach so it doesn't get deleted 839fc0a275bSMatthew Wilber } 840fc0a275bSMatthew Wilber 841cdb89ebbSMatthew Wilber bool 842ee7b4f39SMatthew Wilber ShowImageWindow::ClosePrompt() 843ee7b4f39SMatthew Wilber { 844ee7b4f39SMatthew Wilber if (!fModified) 845ee7b4f39SMatthew Wilber return true; 846ee7b4f39SMatthew Wilber else { 847ee7b4f39SMatthew Wilber int32 page, count; 848ee7b4f39SMatthew Wilber count = fImageView->PageCount(); 849ee7b4f39SMatthew Wilber page = fImageView->CurrentPage(); 850ee7b4f39SMatthew Wilber BString prompt, name; 851ee7b4f39SMatthew Wilber fImageView->GetName(&name); 852ee7b4f39SMatthew Wilber prompt << "The document '" << name << "'"; 853ee7b4f39SMatthew Wilber if (count > 1) 854ee7b4f39SMatthew Wilber prompt << " (page " << page << ")"; 855ee7b4f39SMatthew Wilber prompt << " has been changed. " 856ee7b4f39SMatthew Wilber << "Do you want to close the document?"; 857ee7b4f39SMatthew Wilber BAlert *pAlert = new BAlert("Close document", prompt.String(), 858ee7b4f39SMatthew Wilber "Cancel", "Close"); 859ee7b4f39SMatthew Wilber if (pAlert->Go() == 0) 860ee7b4f39SMatthew Wilber // Cancel 861ee7b4f39SMatthew Wilber return false; 862187f0b8aSMatthew Wilber else { 863ee7b4f39SMatthew Wilber // Close 864187f0b8aSMatthew Wilber fModified = false; 865ee7b4f39SMatthew Wilber return true; 866ee7b4f39SMatthew Wilber } 867ee7b4f39SMatthew Wilber } 868187f0b8aSMatthew Wilber } 869ee7b4f39SMatthew Wilber 870ee7b4f39SMatthew Wilber bool 871cdb89ebbSMatthew Wilber ShowImageWindow::CanQuit() 872cdb89ebbSMatthew Wilber { 873d3046f7dSMichael Pfeiffer if (fSavePanel) 874cdb89ebbSMatthew Wilber // Don't allow this window to be closed if a save panel is open 875cdb89ebbSMatthew Wilber return false; 876cdb89ebbSMatthew Wilber else 877ee7b4f39SMatthew Wilber return ClosePrompt(); 878cdb89ebbSMatthew Wilber } 879cdb89ebbSMatthew Wilber 880ad13f387SMichael Pfeiffer void 881ad13f387SMichael Pfeiffer ShowImageWindow::ToggleFullScreen() 882ad13f387SMichael Pfeiffer { 883ad13f387SMichael Pfeiffer BRect frame; 884ad13f387SMichael Pfeiffer fFullScreen = !fFullScreen; 885ad13f387SMichael Pfeiffer if (fFullScreen) { 886ad13f387SMichael Pfeiffer BScreen screen; 887ad13f387SMichael Pfeiffer fWindowFrame = Frame(); 888ad13f387SMichael Pfeiffer frame = screen.Frame(); 889d3046f7dSMichael Pfeiffer frame.top -= fBar->Bounds().Height()+1; 890ad13f387SMichael Pfeiffer frame.right += B_V_SCROLL_BAR_WIDTH; 891ad13f387SMichael Pfeiffer frame.bottom += B_H_SCROLL_BAR_HEIGHT; 892ad13f387SMichael Pfeiffer frame.InsetBy(-1, -1); // PEN_SIZE in ShowImageView 893ad13f387SMichael Pfeiffer 894ad13f387SMichael Pfeiffer SetFlags(Flags() | B_NOT_RESIZABLE | B_NOT_MOVABLE); 895d3046f7dSMichael Pfeiffer fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE); 896ad13f387SMichael Pfeiffer } else { 897ad13f387SMichael Pfeiffer frame = fWindowFrame; 898ad13f387SMichael Pfeiffer 899ad13f387SMichael Pfeiffer SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE)); 900d3046f7dSMichael Pfeiffer fImageView->SetAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); 901ad13f387SMichael Pfeiffer } 902d3046f7dSMichael Pfeiffer fImageView->SetBorder(!fFullScreen); 903d3046f7dSMichael Pfeiffer fImageView->SetShowCaption(fFullScreen && fShowCaption); 904ad13f387SMichael Pfeiffer MoveTo(frame.left, frame.top); 905ad13f387SMichael Pfeiffer ResizeTo(frame.Width(), frame.Height()); 906ad13f387SMichael Pfeiffer } 907ad13f387SMichael Pfeiffer 908d3046f7dSMichael Pfeiffer void 909d3046f7dSMichael Pfeiffer ShowImageWindow::LoadSettings() 910d3046f7dSMichael Pfeiffer { 911d3046f7dSMichael Pfeiffer ShowImageSettings* settings; 912d3046f7dSMichael Pfeiffer settings = my_app->Settings(); 913d3046f7dSMichael Pfeiffer int32 op; 914d3046f7dSMichael Pfeiffer float f; 915d3046f7dSMichael Pfeiffer if (settings->Lock()) { 916d3046f7dSMichael Pfeiffer fShowCaption = settings->GetBool("ShowCaption", fShowCaption); 917d3046f7dSMichael Pfeiffer fPrintOptions.SetBounds(BRect(0, 0, 1023, 767)); 918d3046f7dSMichael Pfeiffer 919d3046f7dSMichael Pfeiffer op = settings->GetInt32("PO:Option", fPrintOptions.Option()); 920d3046f7dSMichael Pfeiffer fPrintOptions.SetOption((enum PrintOptions::Option)op); 921d3046f7dSMichael Pfeiffer 922d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:ZoomFactor", fPrintOptions.ZoomFactor()); 923d3046f7dSMichael Pfeiffer fPrintOptions.SetZoomFactor(f); 924d3046f7dSMichael Pfeiffer 925d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:DPI", fPrintOptions.DPI()); 926d3046f7dSMichael Pfeiffer fPrintOptions.SetDPI(f); 927d3046f7dSMichael Pfeiffer 928d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:Width", fPrintOptions.Width()); 929d3046f7dSMichael Pfeiffer fPrintOptions.SetWidth(f); 930d3046f7dSMichael Pfeiffer 931d3046f7dSMichael Pfeiffer f = settings->GetFloat("PO:Height", fPrintOptions.Height()); 932d3046f7dSMichael Pfeiffer fPrintOptions.SetHeight(f); 933d3046f7dSMichael Pfeiffer 934d3046f7dSMichael Pfeiffer settings->Unlock(); 935d3046f7dSMichael Pfeiffer } 936d3046f7dSMichael Pfeiffer } 937d3046f7dSMichael Pfeiffer 938d3046f7dSMichael Pfeiffer void 939d3046f7dSMichael Pfeiffer ShowImageWindow::SavePrintOptions() 940d3046f7dSMichael Pfeiffer { 941d3046f7dSMichael Pfeiffer ShowImageSettings* settings; 942d3046f7dSMichael Pfeiffer settings = my_app->Settings(); 943d3046f7dSMichael Pfeiffer if (settings->Lock()) { 944d3046f7dSMichael Pfeiffer settings->SetInt32("PO:Option", fPrintOptions.Option()); 945d3046f7dSMichael Pfeiffer settings->SetFloat("PO:ZoomFactor", fPrintOptions.ZoomFactor()); 946d3046f7dSMichael Pfeiffer settings->SetFloat("PO:DPI", fPrintOptions.DPI()); 947d3046f7dSMichael Pfeiffer settings->SetFloat("PO:Width", fPrintOptions.Width()); 948d3046f7dSMichael Pfeiffer settings->SetFloat("PO:Height", fPrintOptions.Height()); 949d3046f7dSMichael Pfeiffer settings->Unlock(); 950d3046f7dSMichael Pfeiffer } 951d3046f7dSMichael Pfeiffer } 952d3046f7dSMichael Pfeiffer 953cdb89ebbSMatthew Wilber bool 954780d8a62SMichael Pfeiffer ShowImageWindow::PageSetup() 955780d8a62SMichael Pfeiffer { 956780d8a62SMichael Pfeiffer status_t st; 957780d8a62SMichael Pfeiffer BString name; 958d3046f7dSMichael Pfeiffer fImageView->GetName(&name); 959780d8a62SMichael Pfeiffer BPrintJob printJob(name.String()); 960780d8a62SMichael Pfeiffer if (fPrintSettings != NULL) { 961780d8a62SMichael Pfeiffer printJob.SetSettings(new BMessage(*fPrintSettings)); 962780d8a62SMichael Pfeiffer } 963780d8a62SMichael Pfeiffer st = printJob.ConfigPage(); 964780d8a62SMichael Pfeiffer if (st == B_OK) { 965780d8a62SMichael Pfeiffer delete fPrintSettings; 966780d8a62SMichael Pfeiffer fPrintSettings = printJob.Settings(); 967780d8a62SMichael Pfeiffer } 968780d8a62SMichael Pfeiffer return st == B_OK; 969780d8a62SMichael Pfeiffer } 970780d8a62SMichael Pfeiffer 971780d8a62SMichael Pfeiffer void 972780d8a62SMichael Pfeiffer ShowImageWindow::PrepareForPrint() 973780d8a62SMichael Pfeiffer { 974780d8a62SMichael Pfeiffer if (fPrintSettings == NULL && !PageSetup()) { 975780d8a62SMichael Pfeiffer return; 976780d8a62SMichael Pfeiffer } 977780d8a62SMichael Pfeiffer 978d3046f7dSMichael Pfeiffer fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds()); 979d3046f7dSMichael Pfeiffer fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width()+1); 980780d8a62SMichael Pfeiffer 981780d8a62SMichael Pfeiffer new PrintOptionsWindow(BPoint(Frame().left+30, Frame().top+50), &fPrintOptions, this); 982780d8a62SMichael Pfeiffer } 983780d8a62SMichael Pfeiffer 984780d8a62SMichael Pfeiffer void 985780d8a62SMichael Pfeiffer ShowImageWindow::Print(BMessage *msg) 986780d8a62SMichael Pfeiffer { 987780d8a62SMichael Pfeiffer status_t st; 988780d8a62SMichael Pfeiffer if (msg->FindInt32("status", &st) != B_OK || st != B_OK) { 989780d8a62SMichael Pfeiffer return; 990780d8a62SMichael Pfeiffer } 991780d8a62SMichael Pfeiffer 992d3046f7dSMichael Pfeiffer SavePrintOptions(); 993d3046f7dSMichael Pfeiffer 994780d8a62SMichael Pfeiffer BString name; 995d3046f7dSMichael Pfeiffer fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds()); 996d3046f7dSMichael Pfeiffer fImageView->GetName(&name); 997780d8a62SMichael Pfeiffer BPrintJob printJob(name.String()); 998780d8a62SMichael Pfeiffer printJob.SetSettings(new BMessage(*fPrintSettings)); 999780d8a62SMichael Pfeiffer if (printJob.ConfigJob() == B_OK) { 1000780d8a62SMichael Pfeiffer int32 firstPage; 1001780d8a62SMichael Pfeiffer int32 lastPage; 1002780d8a62SMichael Pfeiffer BRect printableRect = printJob.PrintableRect(); 1003780d8a62SMichael Pfeiffer float width, imageWidth, imageHeight, w1, w2; 1004780d8a62SMichael Pfeiffer BBitmap* bitmap; 1005780d8a62SMichael Pfeiffer 1006780d8a62SMichael Pfeiffer // first/lastPage is unused for now 1007780d8a62SMichael Pfeiffer firstPage = printJob.FirstPage(); 1008780d8a62SMichael Pfeiffer lastPage = printJob.LastPage(); 1009780d8a62SMichael Pfeiffer if (firstPage < 1) { 1010780d8a62SMichael Pfeiffer firstPage = 1; 1011780d8a62SMichael Pfeiffer } 1012780d8a62SMichael Pfeiffer if (lastPage < firstPage) { 1013780d8a62SMichael Pfeiffer lastPage = firstPage; 1014780d8a62SMichael Pfeiffer } 1015780d8a62SMichael Pfeiffer 1016d3046f7dSMichael Pfeiffer bitmap = fImageView->GetBitmap(); 1017780d8a62SMichael Pfeiffer imageWidth = bitmap->Bounds().Width() + 1.0; 1018780d8a62SMichael Pfeiffer imageHeight = bitmap->Bounds().Height() + 1.0; 1019780d8a62SMichael Pfeiffer 1020780d8a62SMichael Pfeiffer switch (fPrintOptions.Option()) { 1021780d8a62SMichael Pfeiffer case PrintOptions::kFitToPage: 1022780d8a62SMichael Pfeiffer w1 = printableRect.Width()+1; 1023780d8a62SMichael Pfeiffer w2 = imageWidth * (printableRect.Height() + 1) / imageHeight; 1024780d8a62SMichael Pfeiffer if (w2 < w1) { 1025780d8a62SMichael Pfeiffer width = w2; 1026780d8a62SMichael Pfeiffer } else { 1027780d8a62SMichael Pfeiffer width = w1; 1028780d8a62SMichael Pfeiffer } 1029780d8a62SMichael Pfeiffer break; 1030780d8a62SMichael Pfeiffer case PrintOptions::kZoomFactor: 1031780d8a62SMichael Pfeiffer width = imageWidth * fPrintOptions.ZoomFactor(); 1032780d8a62SMichael Pfeiffer break; 1033780d8a62SMichael Pfeiffer case PrintOptions::kDPI: 1034780d8a62SMichael Pfeiffer width = imageWidth * 72.0 / fPrintOptions.DPI(); 1035780d8a62SMichael Pfeiffer break; 1036780d8a62SMichael Pfeiffer case PrintOptions::kWidth: 1037780d8a62SMichael Pfeiffer case PrintOptions::kHeight: 1038780d8a62SMichael Pfeiffer width = fPrintOptions.Width(); 1039780d8a62SMichael Pfeiffer break; 1040780d8a62SMichael Pfeiffer default: 1041780d8a62SMichael Pfeiffer // keep compiler silent; should not reach here 1042780d8a62SMichael Pfeiffer width = imageWidth; 1043780d8a62SMichael Pfeiffer } 1044780d8a62SMichael Pfeiffer 1045780d8a62SMichael Pfeiffer // XXX: eventually print large images on several pages 1046780d8a62SMichael Pfeiffer printJob.BeginJob(); 1047d3046f7dSMichael Pfeiffer fImageView->SetScale(width / imageWidth); 1048d3046f7dSMichael Pfeiffer printJob.DrawView(fImageView, bitmap->Bounds(), BPoint(printableRect.left, printableRect.top)); 1049d3046f7dSMichael Pfeiffer fImageView->SetScale(1.0); 1050780d8a62SMichael Pfeiffer printJob.SpoolPage(); 1051780d8a62SMichael Pfeiffer printJob.CommitJob(); 1052780d8a62SMichael Pfeiffer } 1053780d8a62SMichael Pfeiffer } 1054780d8a62SMichael Pfeiffer 1055780d8a62SMichael Pfeiffer bool 1056cdb89ebbSMatthew Wilber ShowImageWindow::QuitRequested() 1057cdb89ebbSMatthew Wilber { 1058cdb89ebbSMatthew Wilber return CanQuit(); 1059cdb89ebbSMatthew Wilber } 1060cdb89ebbSMatthew Wilber 106107caaa8eSMatthew Wilber void 106207caaa8eSMatthew Wilber ShowImageWindow::Quit() 106307caaa8eSMatthew Wilber { 106407caaa8eSMatthew Wilber // tell the app to forget about this window 106507caaa8eSMatthew Wilber be_app->PostMessage(MSG_WINDOW_QUIT); 106607caaa8eSMatthew Wilber BWindow::Quit(); 106707caaa8eSMatthew Wilber } 1068fc0a275bSMatthew Wilber 1069