xref: /haiku/src/apps/showimage/ShowImageWindow.cpp (revision 69eee339bad0aed4b9c4a99226a2cc0f64fb8513)
1efa8b4f3SAxel Dörfler /*
2efa8b4f3SAxel Dörfler  * Copyright 2003-2006, Haiku, Inc. All Rights Reserved.
3efa8b4f3SAxel Dörfler  * Distributed under the terms of the MIT License.
4efa8b4f3SAxel Dörfler  *
5efa8b4f3SAxel Dörfler  * Authors:
6efa8b4f3SAxel Dörfler  *		Fernando Francisco de Oliveira
7efa8b4f3SAxel Dörfler  *		Michael Wilber
8efa8b4f3SAxel Dörfler  *		Michael Pfeiffer
9efa8b4f3SAxel Dörfler  */
1013afa642SPhil Greenway 
11efa8b4f3SAxel Dörfler 
12a60adbf9SAxel Dörfler #include "BackgroundImage.h"
13efa8b4f3SAxel Dörfler #include "EntryMenuItem.h"
14efa8b4f3SAxel Dörfler #include "ShowImageApp.h"
15efa8b4f3SAxel Dörfler #include "ShowImageConstants.h"
16efa8b4f3SAxel Dörfler #include "ShowImageStatusView.h"
17efa8b4f3SAxel Dörfler #include "ShowImageView.h"
18efa8b4f3SAxel Dörfler #include "ShowImageWindow.h"
19efa8b4f3SAxel Dörfler 
20efa8b4f3SAxel Dörfler #include <Alert.h>
2113afa642SPhil Greenway #include <Application.h>
2213afa642SPhil Greenway #include <Bitmap.h>
23fc0a275bSMatthew Wilber #include <BitmapStream.h>
24efa8b4f3SAxel Dörfler #include <Clipboard.h>
2513afa642SPhil Greenway #include <Entry.h>
26fc0a275bSMatthew Wilber #include <File.h>
2713afa642SPhil Greenway #include <Menu.h>
2813afa642SPhil Greenway #include <MenuBar.h>
2913afa642SPhil Greenway #include <MenuItem.h>
3013afa642SPhil Greenway #include <Path.h>
31efa8b4f3SAxel Dörfler #include <PrintJob.h>
32efa8b4f3SAxel Dörfler #include <Roster.h>
33efa8b4f3SAxel Dörfler #include <Screen.h>
3413afa642SPhil Greenway #include <ScrollView.h>
35efa8b4f3SAxel Dörfler #include <SupportDefs.h>
3613afa642SPhil Greenway #include <TranslationUtils.h>
3713afa642SPhil Greenway #include <TranslatorRoster.h>
3813afa642SPhil Greenway 
39efa8b4f3SAxel Dörfler #include <new>
40efa8b4f3SAxel Dörfler #include <stdio.h>
4113afa642SPhil Greenway 
42a8fc7138SMichael Pfeiffer 
43758b1d0eSIngo Weinhold RecentDocumentsMenu::RecentDocumentsMenu(const char *title, menu_layout layout)
44a8fc7138SMichael Pfeiffer 	: BMenu(title, layout)
45a8fc7138SMichael Pfeiffer {
46a8fc7138SMichael Pfeiffer }
47a8fc7138SMichael Pfeiffer 
48efa8b4f3SAxel Dörfler 
49a8fc7138SMichael Pfeiffer bool
50a60adbf9SAxel Dörfler RecentDocumentsMenu::AddDynamicItem(add_state addState)
51a8fc7138SMichael Pfeiffer {
52a60adbf9SAxel Dörfler 	if (addState != B_INITIAL_ADD)
53efa8b4f3SAxel Dörfler 		return false;
54a8fc7138SMichael Pfeiffer 
55a8fc7138SMichael Pfeiffer 	BMenuItem *item;
56a8fc7138SMichael Pfeiffer 	BMessage list, *msg;
57a8fc7138SMichael Pfeiffer 	entry_ref ref;
58a8fc7138SMichael Pfeiffer 	char name[B_FILE_NAME_LENGTH];
59a8fc7138SMichael Pfeiffer 
60a8fc7138SMichael Pfeiffer 	while ((item = RemoveItem((int32)0)) != NULL) {
61a8fc7138SMichael Pfeiffer 		delete item;
62a8fc7138SMichael Pfeiffer 	}
63a8fc7138SMichael Pfeiffer 
64efa8b4f3SAxel Dörfler 	be_roster->GetRecentDocuments(&list, 20, NULL, kApplicationSignature);
65a8fc7138SMichael Pfeiffer 	for (int i = 0; list.FindRef("refs", i, &ref) == B_OK; i++) {
66a8fc7138SMichael Pfeiffer 		BEntry entry(&ref);
67a8fc7138SMichael Pfeiffer 		if (entry.Exists() && entry.GetName(name) == B_OK) {
68a8fc7138SMichael Pfeiffer 			msg = new BMessage(B_REFS_RECEIVED);
69a8fc7138SMichael Pfeiffer 			msg->AddRef("refs", &ref);
70a8fc7138SMichael Pfeiffer 			item =  new EntryMenuItem(&ref, name, msg, 0, 0);
71a8fc7138SMichael Pfeiffer 			AddItem(item);
72a8fc7138SMichael Pfeiffer 			item->SetTarget(be_app, NULL);
73a8fc7138SMichael Pfeiffer 		}
74a8fc7138SMichael Pfeiffer 	}
75a8fc7138SMichael Pfeiffer 
76a8fc7138SMichael Pfeiffer 	return false;
77a8fc7138SMichael Pfeiffer }
78a8fc7138SMichael Pfeiffer 
79a8fc7138SMichael Pfeiffer 
80efa8b4f3SAxel Dörfler //	#pragma mark -
81a8fc7138SMichael Pfeiffer 
82efa8b4f3SAxel Dörfler 
83efa8b4f3SAxel Dörfler ShowImageWindow::ShowImageWindow(const entry_ref *ref,
84efa8b4f3SAxel Dörfler 		const BMessenger& trackerMessenger)
851de41298SMatthew Wilber 	: BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0)
8613afa642SPhil Greenway {
87d3046f7dSMichael Pfeiffer 	fSavePanel = NULL;
88ee7b4f39SMatthew Wilber 	fModified = false;
89ad13f387SMichael Pfeiffer 	fFullScreen = false;
90d3046f7dSMichael Pfeiffer 	fShowCaption = true;
91780d8a62SMichael Pfeiffer 	fPrintSettings = NULL;
92d3046f7dSMichael Pfeiffer 	fImageView = NULL;
93d3046f7dSMichael Pfeiffer 	fSlideShowDelay = NULL;
94d3046f7dSMichael Pfeiffer 
95d3046f7dSMichael Pfeiffer 	LoadSettings();
96fc0a275bSMatthew Wilber 
9713afa642SPhil Greenway 	// create menu bar
98e9dcd874SAxel Dörfler 	fBar = new BMenuBar(BRect(0, 0, Bounds().right, 1), "menu_bar");
99efa8b4f3SAxel Dörfler 	AddMenus(fBar);
100e9dcd874SAxel Dörfler 	AddChild(fBar);
10113afa642SPhil Greenway 
10213afa642SPhil Greenway 	BRect viewFrame = Bounds();
103e9dcd874SAxel Dörfler 	viewFrame.top = fBar->Bounds().Height() + 1;
10413afa642SPhil Greenway 	viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
10513afa642SPhil Greenway 	viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
10613afa642SPhil Greenway 
10713afa642SPhil Greenway 	// create the image view
108d3046f7dSMichael Pfeiffer 	fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
1097eca0987SMichael Pfeiffer 		B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED);
11013afa642SPhil Greenway 	// wrap a scroll view around the view
111efa8b4f3SAxel Dörfler 	BScrollView *scrollView = new BScrollView("image_scroller", fImageView,
112cdb89ebbSMatthew Wilber 		B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
113efa8b4f3SAxel Dörfler 	AddChild(scrollView);
11413afa642SPhil Greenway 
11507caaa8eSMatthew Wilber 	const int32 kstatusWidth = 190;
116cdb89ebbSMatthew Wilber 	BRect rect;
11713afa642SPhil Greenway 	rect = Bounds();
11813afa642SPhil Greenway 	rect.top	= viewFrame.bottom + 1;
11907caaa8eSMatthew Wilber 	rect.left 	= viewFrame.left + kstatusWidth;
1200916ab53SMatthew Wilber 	rect.right	= viewFrame.right + 1;
1210916ab53SMatthew Wilber 	rect.bottom += 1;
122efa8b4f3SAxel Dörfler 	BScrollBar *horizontalScrollBar = new BScrollBar(rect, "hscroll",
123efa8b4f3SAxel Dörfler 		fImageView, 0, 150, B_HORIZONTAL);
124efa8b4f3SAxel Dörfler 	AddChild(horizontalScrollBar);
12513afa642SPhil Greenway 
12613afa642SPhil Greenway 	rect.left = 0;
12707caaa8eSMatthew Wilber 	rect.right = kstatusWidth - 1;
1280cd4ecd8SStephan Aßmus 	rect.bottom -= 1;
129d3046f7dSMichael Pfeiffer 	fStatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
130cdb89ebbSMatthew Wilber 		B_WILL_DRAW);
131d3046f7dSMichael Pfeiffer 	AddChild(fStatusView);
13213afa642SPhil Greenway 
13313afa642SPhil Greenway 	rect = Bounds();
1340916ab53SMatthew Wilber 	rect.top    = viewFrame.top - 1;
13513afa642SPhil Greenway 	rect.left 	= viewFrame.right + 1;
1360916ab53SMatthew Wilber 	rect.bottom	= viewFrame.bottom + 1;
1370916ab53SMatthew Wilber 	rect.right	+= 1;
138efa8b4f3SAxel Dörfler 	BScrollBar *verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,
139efa8b4f3SAxel Dörfler 		0, 150, B_VERTICAL);
140efa8b4f3SAxel Dörfler 	AddChild(verticalScrollBar);
14113afa642SPhil Greenway 
14203839579SMatthew Wilber 	SetSizeLimits(250, 100000, 100, 100000);
14313afa642SPhil Greenway 
144134d6076SMichael Pfeiffer 	// finish creating the window
145efa8b4f3SAxel Dörfler 	fImageView->SetImage(ref);
146134d6076SMichael Pfeiffer 	fImageView->SetTrackerMessenger(trackerMessenger);
1477eca0987SMichael Pfeiffer 
148780d8a62SMichael Pfeiffer 	if (InitCheck() == B_OK) {
149d3046f7dSMichael Pfeiffer 		// add View menu here so it can access ShowImageView methods
150efa8b4f3SAxel Dörfler 		BMenu* menu = new BMenu("View");
151efa8b4f3SAxel Dörfler 		BuildViewMenu(menu);
152efa8b4f3SAxel Dörfler 		fBar->AddItem(menu);
153a8fc7138SMichael Pfeiffer 		MarkMenuItem(fBar, MSG_DITHER_IMAGE, fImageView->GetDither());
154780d8a62SMichael Pfeiffer 		UpdateTitle();
155780d8a62SMichael Pfeiffer 
156efa8b4f3SAxel Dörfler 		SetPulseRate(100000);
157efa8b4f3SAxel Dörfler 			// every 1/10 second; ShowImageView needs it for marching ants
15803839579SMatthew Wilber 
159d3046f7dSMichael Pfeiffer 		fImageView->FlushToLeftTop();
160d3046f7dSMichael Pfeiffer 		WindowRedimension(fImageView->GetBitmap());
161d3046f7dSMichael Pfeiffer 		fImageView->MakeFocus(true); // to receive KeyDown messages
16213afa642SPhil Greenway 		Show();
163d10d5947SMichael Pfeiffer 	} else {
164e6a50d9cSMichael Pfeiffer 		BAlert* alert;
165e6a50d9cSMichael Pfeiffer 		alert = new BAlert("ShowImage",
166e6a50d9cSMichael Pfeiffer 			"Could not load image! Either the file or an image translator for it does not exist.",
167e6a50d9cSMichael Pfeiffer 			"OK", NULL, NULL,
168e6a50d9cSMichael Pfeiffer 			B_WIDTH_AS_USUAL, B_INFO_ALERT);
169e6a50d9cSMichael Pfeiffer 		alert->Go();
170efa8b4f3SAxel Dörfler 
171d10d5947SMichael Pfeiffer 		// exit if file could not be opened
172efa8b4f3SAxel Dörfler 		PostMessage(B_QUIT_REQUESTED);
173efa8b4f3SAxel Dörfler 		return;
174d10d5947SMichael Pfeiffer 	}
175402c09e5SMatthew Wilber 
176402c09e5SMatthew Wilber 	// Tell application object to query the clipboard
177402c09e5SMatthew Wilber 	// and tell this window if it contains interesting data or not
178402c09e5SMatthew Wilber 	be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED);
17913afa642SPhil Greenway }
18013afa642SPhil Greenway 
181efa8b4f3SAxel Dörfler 
18213afa642SPhil Greenway ShowImageWindow::~ShowImageWindow()
18313afa642SPhil Greenway {
18413afa642SPhil Greenway }
18513afa642SPhil Greenway 
186efa8b4f3SAxel Dörfler 
187cdb89ebbSMatthew Wilber status_t
188cdb89ebbSMatthew Wilber ShowImageWindow::InitCheck()
18913afa642SPhil Greenway {
190d3046f7dSMichael Pfeiffer 	if (!fImageView || fImageView->GetBitmap() == NULL)
19113afa642SPhil Greenway 		return B_ERROR;
192efa8b4f3SAxel Dörfler 
19313afa642SPhil Greenway 	return B_OK;
19413afa642SPhil Greenway }
195cdb89ebbSMatthew Wilber 
196efa8b4f3SAxel Dörfler 
197cdb89ebbSMatthew Wilber void
198cdb89ebbSMatthew Wilber ShowImageWindow::UpdateTitle()
19913afa642SPhil Greenway {
200e6a50d9cSMichael Pfeiffer 	BString path;
201d3046f7dSMichael Pfeiffer 	fImageView->GetPath(&path);
202e6a50d9cSMichael Pfeiffer 	SetTitle(path.String());
20313afa642SPhil Greenway }
20413afa642SPhil Greenway 
205efa8b4f3SAxel Dörfler 
206cdb89ebbSMatthew Wilber void
207efa8b4f3SAxel Dörfler ShowImageWindow::BuildViewMenu(BMenu *menu)
208da87390fSMichael Pfeiffer {
209efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Slide Show", MSG_SLIDE_SHOW, 0, 0, 'W', true);
210efa8b4f3SAxel Dörfler 	MarkMenuItem(menu, MSG_SLIDE_SHOW, fImageView->SlideShowStarted());
211efa8b4f3SAxel Dörfler 	BMenu* delayMenu = new BMenu("Slide Delay");
212efa8b4f3SAxel Dörfler 	if (fSlideShowDelay == NULL)
213efa8b4f3SAxel Dörfler 		fSlideShowDelay = delayMenu;
214efa8b4f3SAxel Dörfler 
215efa8b4f3SAxel Dörfler 	delayMenu->SetRadioMode(true);
216efa8b4f3SAxel Dörfler 	// Note: ShowImage loads images in window thread so it becomes unresponsive if
217da87390fSMichael Pfeiffer 	// slide show delay is too short! (Especially if loading the image takes as long as
218da87390fSMichael Pfeiffer 	// or longer than the slide show delay). Should load in background thread!
219efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Three Seconds", 3);
220efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Four Second", 4);
221efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Five Seconds", 5);
222efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Six Seconds", 6);
223efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Seven Seconds", 7);
224efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Eight Seconds", 8);
225efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Nine Seconds", 9);
226efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Ten Seconds", 10);
227efa8b4f3SAxel Dörfler 	AddDelayItem(delayMenu, "Twenty Seconds", 20);
228efa8b4f3SAxel Dörfler 	menu->AddItem(delayMenu);
22930060f17SMatthew Wilber 
230efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
231efa8b4f3SAxel Dörfler 
232efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Original Size", MSG_ORIGINAL_SIZE, 0, 0, 'W', true);
233efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Zoom In", MSG_ZOOM_IN, '+', 0, 'W', true);
234efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Zoom Out", MSG_ZOOM_OUT, '-', 0, 'W', true);
235efa8b4f3SAxel Dörfler 
236efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
237efa8b4f3SAxel Dörfler 
238efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Scale Bilinear", MSG_SCALE_BILINEAR, 0, 0, 'W', true);
239efa8b4f3SAxel Dörfler 
240efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
241efa8b4f3SAxel Dörfler 
242efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Shrink to Window", MSG_SHRINK_TO_WINDOW, 0, 0, 'W', true);
243efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Zoom to Window", MSG_ZOOM_TO_WINDOW, 0, 0, 'W', true);
244efa8b4f3SAxel Dörfler 
245efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
246efa8b4f3SAxel Dörfler 
247efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Full Screen", MSG_FULL_SCREEN, 'F', 0, 'W', true);
248efa8b4f3SAxel Dörfler 	MarkMenuItem(menu, MSG_FULL_SCREEN, fFullScreen);
249efa8b4f3SAxel Dörfler 
250efa8b4f3SAxel Dörfler 	AddShortcut(B_ENTER, 0, new BMessage(MSG_FULL_SCREEN));
251efa8b4f3SAxel Dörfler 
252efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Show Caption in Full Screen Mode", MSG_SHOW_CAPTION, 0, 0, 'W', true);
253efa8b4f3SAxel Dörfler 	MarkMenuItem(menu, MSG_SHOW_CAPTION, fShowCaption);
254efa8b4f3SAxel Dörfler 
255efa8b4f3SAxel Dörfler 	MarkMenuItem(menu, MSG_SCALE_BILINEAR, fImageView->GetScaleBilinear());
256da87390fSMichael Pfeiffer 
25719c76de4SMichael Pfeiffer 	bool shrink, zoom, enabled;
258efa8b4f3SAxel Dörfler 
259d3046f7dSMichael Pfeiffer 	shrink = fImageView->GetShrinkToBounds();
260d3046f7dSMichael Pfeiffer 	zoom = fImageView->GetZoomToBounds();
261efa8b4f3SAxel Dörfler 	MarkMenuItem(menu, MSG_SHRINK_TO_WINDOW, shrink);
262efa8b4f3SAxel Dörfler 	MarkMenuItem(menu, MSG_ZOOM_TO_WINDOW, zoom);
263efa8b4f3SAxel Dörfler 
26419c76de4SMichael Pfeiffer  	enabled = !(shrink || zoom);
265efa8b4f3SAxel Dörfler 	EnableMenuItem(menu, MSG_ORIGINAL_SIZE, enabled);
266efa8b4f3SAxel Dörfler 	EnableMenuItem(menu, MSG_ZOOM_IN, enabled);
267efa8b4f3SAxel Dörfler 	EnableMenuItem(menu, MSG_ZOOM_OUT, enabled);
268a60adbf9SAxel Dörfler 
269a60adbf9SAxel Dörfler 	menu->AddSeparatorItem();
270a60adbf9SAxel Dörfler 
271a60adbf9SAxel Dörfler 	AddItemMenu(menu, "As Desktop Background", MSG_DESKTOP_BACKGROUND, 0, 0, 'W',
272a60adbf9SAxel Dörfler 		true);
273da87390fSMichael Pfeiffer }
274da87390fSMichael Pfeiffer 
275efa8b4f3SAxel Dörfler 
276da87390fSMichael Pfeiffer void
277efa8b4f3SAxel Dörfler ShowImageWindow::AddMenus(BMenuBar *bar)
27813afa642SPhil Greenway {
279efa8b4f3SAxel Dörfler 	BMenu *menu = new BMenu("File");
280a8fc7138SMichael Pfeiffer 	fOpenMenu = new RecentDocumentsMenu("Open");
281efa8b4f3SAxel Dörfler 	menu->AddItem(fOpenMenu);
282d3046f7dSMichael Pfeiffer 	fOpenMenu->Superitem()->SetTrigger('O');
283d3046f7dSMichael Pfeiffer 	fOpenMenu->Superitem()->SetMessage(new BMessage(MSG_FILE_OPEN));
284d3046f7dSMichael Pfeiffer 	fOpenMenu->Superitem()->SetTarget(be_app);
285d3046f7dSMichael Pfeiffer 	fOpenMenu->Superitem()->SetShortcut('O', 0);
286efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
287780d8a62SMichael Pfeiffer 	BMenu *pmenuSaveAs = new BMenu("Save As" B_UTF8_ELLIPSIS, B_ITEMS_IN_COLUMN);
288cdb89ebbSMatthew Wilber 	BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP);
289fc0a275bSMatthew Wilber 		// Fill Save As submenu with all types that can be converted
290fc0a275bSMatthew Wilber 		// to from the Be bitmap image format
291efa8b4f3SAxel Dörfler 	menu->AddItem(pmenuSaveAs);
292efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Close", B_QUIT_REQUESTED, 'W', 0, 'W', true);
293efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
294efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Page Setup" B_UTF8_ELLIPSIS, MSG_PAGE_SETUP, 0, 0, 'W', true);
295efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Print" B_UTF8_ELLIPSIS, MSG_PREPARE_PRINT, 0, 0, 'W', true);
296efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
297efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "About ShowImage" B_UTF8_ELLIPSIS, B_ABOUT_REQUESTED, 0, 0, 'A', true);
298efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
299efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true);
300efa8b4f3SAxel Dörfler 	bar->AddItem(menu);
30113afa642SPhil Greenway 
302efa8b4f3SAxel Dörfler 	menu = new BMenu("Edit");
303efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Undo", B_UNDO, 'Z', 0, 'W', false);
304efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
305efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Cut", B_CUT, 'X', 0, 'W', false);
306efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Copy", B_COPY, 'C', 0, 'W', false);
307efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Paste", B_PASTE, 'V', 0, 'W', false);
308efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Clear", MSG_CLEAR_SELECT, 0, 0, 'W', false);
309efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
310efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', true);
311efa8b4f3SAxel Dörfler 	bar->AddItem(menu);
31213afa642SPhil Greenway 
313efa8b4f3SAxel Dörfler 	menu = fBrowseMenu = new BMenu("Browse");
314efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "First Page", MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, 'W', true);
315efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Last Page", MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, 'W', true);
316efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Previous Page", MSG_PAGE_PREV, B_LEFT_ARROW, 0, 'W', true);
317efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Next Page", MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, 'W', true);
318d3046f7dSMichael Pfeiffer 	fGoToPageMenu = new BMenu("Go To Page");
3195e427b6aSMichael Pfeiffer 	fGoToPageMenu->SetRadioMode(true);
320efa8b4f3SAxel Dörfler 	menu->AddItem(fGoToPageMenu);
321efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
322efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Previous File", MSG_FILE_PREV, B_UP_ARROW, 0, 'W', true);
323efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Next File", MSG_FILE_NEXT, B_DOWN_ARROW, 0, 'W', true);
324efa8b4f3SAxel Dörfler 	bar->AddItem(menu);
32503839579SMatthew Wilber 
326efa8b4f3SAxel Dörfler 	menu = new BMenu("Image");
327efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
328efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
329efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Rotate -90°", MSG_ROTATE_270, '[', 0, 'W', true);
330efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Rotate +90°", MSG_ROTATE_90, ']', 0, 'W', true);
331efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
332*69eee339SRyan Leavengood 	AddItemMenu(menu, "Flip Left To Right", MSG_FLIP_LEFT_TO_RIGHT, 0, 0, 'W', true);
333*69eee339SRyan Leavengood 	AddItemMenu(menu, "Flip Top To Bottom", MSG_FLIP_TOP_TO_BOTTOM, 0, 0, 'W', true);
334efa8b4f3SAxel Dörfler 	menu->AddSeparatorItem();
335efa8b4f3SAxel Dörfler 	AddItemMenu(menu, "Invert", MSG_INVERT, 0, 0, 'W', true);
336efa8b4f3SAxel Dörfler 	bar->AddItem(menu);
33713afa642SPhil Greenway }
33813afa642SPhil Greenway 
339efa8b4f3SAxel Dörfler 
340cdb89ebbSMatthew Wilber BMenuItem *
341a60adbf9SAxel Dörfler ShowImageWindow::AddItemMenu(BMenu *menu, char *caption, uint32 command,
342efa8b4f3SAxel Dörfler 	char shortcut, uint32 modifier, char target, bool enabled)
343cdb89ebbSMatthew Wilber {
344a60adbf9SAxel Dörfler 	BMenuItem* item = new BMenuItem(caption, new BMessage(command), shortcut, modifier);
34513afa642SPhil Greenway 
34613afa642SPhil Greenway 	if (target == 'A')
347efa8b4f3SAxel Dörfler 		item->SetTarget(be_app);
348da87390fSMichael Pfeiffer 	else
349efa8b4f3SAxel Dörfler 		item->SetTarget(this);
35013afa642SPhil Greenway 
351efa8b4f3SAxel Dörfler 	item->SetEnabled(enabled);
352efa8b4f3SAxel Dörfler 	menu->AddItem(item);
353efa8b4f3SAxel Dörfler 
354efa8b4f3SAxel Dörfler 	return item;
35513afa642SPhil Greenway }
35613afa642SPhil Greenway 
357efa8b4f3SAxel Dörfler 
358ad13f387SMichael Pfeiffer BMenuItem*
359efa8b4f3SAxel Dörfler ShowImageWindow::AddDelayItem(BMenu *menu, char *caption, float value)
360ad13f387SMichael Pfeiffer {
361efa8b4f3SAxel Dörfler 	BMessage* message = new BMessage(MSG_SLIDE_SHOW_DELAY);
362efa8b4f3SAxel Dörfler 	message->AddFloat("value", value);
363ad13f387SMichael Pfeiffer 
364efa8b4f3SAxel Dörfler 	BMenuItem* item = new BMenuItem(caption, message, 0);
365efa8b4f3SAxel Dörfler 	item->SetTarget(this);
366ad13f387SMichael Pfeiffer 
367d3046f7dSMichael Pfeiffer 	bool marked = fImageView->GetSlideShowDelay() == value;
368efa8b4f3SAxel Dörfler 	if (marked)
369efa8b4f3SAxel Dörfler 		item->SetMarked(true);
370ad13f387SMichael Pfeiffer 
371efa8b4f3SAxel Dörfler 	menu->AddItem(item);
372efa8b4f3SAxel Dörfler 	return item;
373ad13f387SMichael Pfeiffer }
374ad13f387SMichael Pfeiffer 
375efa8b4f3SAxel Dörfler 
376cdb89ebbSMatthew Wilber void
377cdb89ebbSMatthew Wilber ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
37813afa642SPhil Greenway {
379d10d5947SMichael Pfeiffer 	BScreen screen;
38071a34702SAxel Dörfler 	if (!screen.IsValid())
381efa8b4f3SAxel Dörfler 		return;
382efa8b4f3SAxel Dörfler 
383d10d5947SMichael Pfeiffer 	BRect r(pbitmap->Bounds());
384d10d5947SMichael Pfeiffer 	const float windowBorderWidth = 5;
385d10d5947SMichael Pfeiffer 	const float windowBorderHeight = 5;
38613afa642SPhil Greenway 
387fc5ca95dSStephan Aßmus 	float width = r.Width() + 2 * PEN_SIZE + B_V_SCROLL_BAR_WIDTH;
388fc5ca95dSStephan Aßmus 	float height = r.Height() + 2 * PEN_SIZE + 1 + fBar->Frame().Height() + B_H_SCROLL_BAR_HEIGHT;
389cdb89ebbSMatthew Wilber 
390d10d5947SMichael Pfeiffer 	// dimensions so that window does not reach outside of screen
391fc5ca95dSStephan Aßmus 	float maxWidth = screen.Frame().Width() + 1 - windowBorderWidth - Frame().left;
392fc5ca95dSStephan Aßmus 	float maxHeight = screen.Frame().Height() + 1 - windowBorderHeight - Frame().top;
393cdb89ebbSMatthew Wilber 
394a8fc7138SMichael Pfeiffer 	// We have to check size limits manually, otherwise
395a8fc7138SMichael Pfeiffer 	// menu bar will be too short for small images.
396efa8b4f3SAxel Dörfler 
397fc5ca95dSStephan Aßmus 	float minW, maxW, minH, maxH;
398a8fc7138SMichael Pfeiffer 	GetSizeLimits(&minW, &maxW, &minH, &maxH);
399efa8b4f3SAxel Dörfler 	if (maxWidth > maxW)
400efa8b4f3SAxel Dörfler 		maxWidth = maxW;
401efa8b4f3SAxel Dörfler 	if (maxHeight > maxH)
402efa8b4f3SAxel Dörfler 		maxHeight = maxH;
403efa8b4f3SAxel Dörfler 	if (width < minW)
404efa8b4f3SAxel Dörfler 		width = minW;
405efa8b4f3SAxel Dörfler 	if (height < minH)
406efa8b4f3SAxel Dörfler 		height = minH;
407a8fc7138SMichael Pfeiffer 
408efa8b4f3SAxel Dörfler 	if (width > maxWidth)
409efa8b4f3SAxel Dörfler 		width = maxWidth;
410efa8b4f3SAxel Dörfler 	if (height > maxHeight)
411efa8b4f3SAxel Dörfler 		height = maxHeight;
412d10d5947SMichael Pfeiffer 
413d10d5947SMichael Pfeiffer 	ResizeTo(width, height);
41413afa642SPhil Greenway }
41513afa642SPhil Greenway 
416efa8b4f3SAxel Dörfler 
417cdb89ebbSMatthew Wilber void
418cdb89ebbSMatthew Wilber ShowImageWindow::FrameResized(float width, float height)
41913afa642SPhil Greenway {
42013afa642SPhil Greenway }
42113afa642SPhil Greenway 
422efa8b4f3SAxel Dörfler 
4237eca0987SMichael Pfeiffer bool
4247eca0987SMichael Pfeiffer ShowImageWindow::ToggleMenuItem(uint32 what)
4257eca0987SMichael Pfeiffer {
4267eca0987SMichael Pfeiffer 	BMenuItem *item;
4277eca0987SMichael Pfeiffer 	bool marked = false;
428d3046f7dSMichael Pfeiffer 	item = fBar->FindItem(what);
4297eca0987SMichael Pfeiffer 	if (item != NULL) {
4307eca0987SMichael Pfeiffer 		marked = !item->IsMarked();
4317eca0987SMichael Pfeiffer 		item->SetMarked(marked);
4327eca0987SMichael Pfeiffer 	}
4337eca0987SMichael Pfeiffer 	return marked;
4347eca0987SMichael Pfeiffer }
4357eca0987SMichael Pfeiffer 
436efa8b4f3SAxel Dörfler 
437cdb89ebbSMatthew Wilber void
438da87390fSMichael Pfeiffer ShowImageWindow::EnableMenuItem(BMenu *menu, uint32 what, bool enable)
439e6a50d9cSMichael Pfeiffer {
440e6a50d9cSMichael Pfeiffer 	BMenuItem* item;
441da87390fSMichael Pfeiffer 	item = menu->FindItem(what);
442e6a50d9cSMichael Pfeiffer 	if (item && item->IsEnabled() != enable) {
443e6a50d9cSMichael Pfeiffer 		item->SetEnabled(enable);
444e6a50d9cSMichael Pfeiffer 	}
445e6a50d9cSMichael Pfeiffer }
446e6a50d9cSMichael Pfeiffer 
447efa8b4f3SAxel Dörfler 
448e6a50d9cSMichael Pfeiffer void
449da87390fSMichael Pfeiffer ShowImageWindow::MarkMenuItem(BMenu *menu, uint32 what, bool marked)
450e6a50d9cSMichael Pfeiffer {
451e6a50d9cSMichael Pfeiffer 	BMenuItem* item;
452da87390fSMichael Pfeiffer 	item = menu->FindItem(what);
453e6a50d9cSMichael Pfeiffer 	if (item && item->IsMarked() != marked) {
454e6a50d9cSMichael Pfeiffer 		item->SetMarked(marked);
455e6a50d9cSMichael Pfeiffer 	}
456e6a50d9cSMichael Pfeiffer }
457e6a50d9cSMichael Pfeiffer 
458efa8b4f3SAxel Dörfler 
459da87390fSMichael Pfeiffer void
460da87390fSMichael Pfeiffer ShowImageWindow::MarkSlideShowDelay(float value)
461da87390fSMichael Pfeiffer {
462d3046f7dSMichael Pfeiffer 	const int32 n = fSlideShowDelay->CountItems();
463da87390fSMichael Pfeiffer 	float v;
464da87390fSMichael Pfeiffer 	for (int32 i = 0; i < n; i ++) {
465d3046f7dSMichael Pfeiffer 		BMenuItem* item = fSlideShowDelay->ItemAt(i);
466da87390fSMichael Pfeiffer 		if (item) {
467da87390fSMichael Pfeiffer 			if (item->Message()->FindFloat("value", &v) == B_OK && v == value) {
468da87390fSMichael Pfeiffer 				if (!item->IsMarked()) {
469da87390fSMichael Pfeiffer 					item->SetMarked(true);
470da87390fSMichael Pfeiffer 				}
471da87390fSMichael Pfeiffer 				return;
472da87390fSMichael Pfeiffer 			}
473da87390fSMichael Pfeiffer 		}
474da87390fSMichael Pfeiffer 	}
475da87390fSMichael Pfeiffer }
476e6a50d9cSMichael Pfeiffer 
47719c76de4SMichael Pfeiffer 
47819c76de4SMichael Pfeiffer void
47919c76de4SMichael Pfeiffer ShowImageWindow::ResizeToWindow(bool shrink, uint32 what)
48019c76de4SMichael Pfeiffer {
48119c76de4SMichael Pfeiffer 	bool enabled;
48219c76de4SMichael Pfeiffer 	enabled = ToggleMenuItem(what);
48319c76de4SMichael Pfeiffer 	if (shrink) {
484d3046f7dSMichael Pfeiffer 		fImageView->SetShrinkToBounds(enabled);
48519c76de4SMichael Pfeiffer 	} else {
486d3046f7dSMichael Pfeiffer 		fImageView->SetZoomToBounds(enabled);
48719c76de4SMichael Pfeiffer 	}
488d3046f7dSMichael Pfeiffer 	enabled = !(fImageView->GetShrinkToBounds() || fImageView->GetZoomToBounds());
489d3046f7dSMichael Pfeiffer 	EnableMenuItem(fBar, MSG_ORIGINAL_SIZE, enabled);
490d3046f7dSMichael Pfeiffer 	EnableMenuItem(fBar, MSG_ZOOM_IN, enabled);
491d3046f7dSMichael Pfeiffer 	EnableMenuItem(fBar, MSG_ZOOM_OUT, enabled);
49219c76de4SMichael Pfeiffer }
49319c76de4SMichael Pfeiffer 
494efa8b4f3SAxel Dörfler 
495e6a50d9cSMichael Pfeiffer void
496efa8b4f3SAxel Dörfler ShowImageWindow::MessageReceived(BMessage *message)
49713afa642SPhil Greenway {
498efa8b4f3SAxel Dörfler 	switch (message->what) {
499ee7b4f39SMatthew Wilber 		case MSG_MODIFIED:
500ee7b4f39SMatthew Wilber 			// If image has been modified due to a Cut or Paste
501ee7b4f39SMatthew Wilber 			fModified = true;
502ee7b4f39SMatthew Wilber 			break;
503ee7b4f39SMatthew Wilber 
504fc0a275bSMatthew Wilber 		case MSG_OUTPUT_TYPE:
505fc0a275bSMatthew Wilber 			// User clicked Save As then choose an output format
506d3046f7dSMichael Pfeiffer 			if (!fSavePanel)
507cdb89ebbSMatthew Wilber 				// If user doesn't already have a save panel open
508efa8b4f3SAxel Dörfler 				SaveAs(message);
50913afa642SPhil Greenway 			break;
510fc0a275bSMatthew Wilber 
511fc0a275bSMatthew Wilber 		case MSG_SAVE_PANEL:
512fc0a275bSMatthew Wilber 			// User specified where to save the output image
513efa8b4f3SAxel Dörfler 			SaveToFile(message);
51407caaa8eSMatthew Wilber 			break;
51507caaa8eSMatthew Wilber 
516cdb89ebbSMatthew Wilber 		case B_CANCEL:
517d3046f7dSMichael Pfeiffer 			delete fSavePanel;
518d3046f7dSMichael Pfeiffer 			fSavePanel = NULL;
519cdb89ebbSMatthew Wilber 			break;
520cdb89ebbSMatthew Wilber 
52103839579SMatthew Wilber 		case MSG_UPDATE_STATUS:
52203839579SMatthew Wilber 		{
5236c305411SMatthew Wilber 			int32 pages, curPage;
524d3046f7dSMichael Pfeiffer 			pages = fImageView->PageCount();
525d3046f7dSMichael Pfeiffer 			curPage = fImageView->CurrentPage();
5266c305411SMatthew Wilber 
5276c305411SMatthew Wilber 			bool benable = (pages > 1) ? true : false;
528d3046f7dSMichael Pfeiffer 			EnableMenuItem(fBar, MSG_PAGE_FIRST, benable);
529d3046f7dSMichael Pfeiffer 			EnableMenuItem(fBar, MSG_PAGE_LAST, benable);
530d3046f7dSMichael Pfeiffer 			EnableMenuItem(fBar, MSG_PAGE_NEXT, benable);
531d3046f7dSMichael Pfeiffer 			EnableMenuItem(fBar, MSG_PAGE_PREV, benable);
5321d592070SMatthew Wilber 
533134d6076SMichael Pfeiffer 			EnableMenuItem(fBar, MSG_FILE_NEXT, fImageView->HasNextFile());
534134d6076SMichael Pfeiffer 			EnableMenuItem(fBar, MSG_FILE_PREV, fImageView->HasPrevFile());
535134d6076SMichael Pfeiffer 
536d3046f7dSMichael Pfeiffer 			if (fGoToPageMenu->CountItems() != pages) {
5376c305411SMatthew Wilber 				// Only rebuild the submenu if the number of
5386c305411SMatthew Wilber 				// pages is different
5396c305411SMatthew Wilber 
540d3046f7dSMichael Pfeiffer 				while (fGoToPageMenu->CountItems() > 0)
5416c305411SMatthew Wilber 					// Remove all page numbers
542d3046f7dSMichael Pfeiffer 					delete fGoToPageMenu->RemoveItem(0L);
5436c305411SMatthew Wilber 
544780d8a62SMichael Pfeiffer 				for (int32 i = 1; i <= pages; i++) {
5456c305411SMatthew Wilber 					// Fill Go To page submenu with an entry for each page
5466c305411SMatthew Wilber 					BMessage *pgomsg;
547780d8a62SMichael Pfeiffer 					char shortcut = 0;
5486c305411SMatthew Wilber 					pgomsg = new BMessage(MSG_GOTO_PAGE);
5496c305411SMatthew Wilber 					pgomsg->AddInt32("page", i);
5506c305411SMatthew Wilber 					BString strCaption;
5516c305411SMatthew Wilber 					strCaption << i;
552efa8b4f3SAxel Dörfler 					BMenuItem *item;
553780d8a62SMichael Pfeiffer 					if (i < 10) {
554780d8a62SMichael Pfeiffer 						shortcut = '0' + i;
555780d8a62SMichael Pfeiffer 					} else if (i == 10) {
556780d8a62SMichael Pfeiffer 						shortcut = '0';
557780d8a62SMichael Pfeiffer 					}
558efa8b4f3SAxel Dörfler 					item = new BMenuItem(strCaption.String(), pgomsg, shortcut);
5596c305411SMatthew Wilber 					if (curPage == i)
560efa8b4f3SAxel Dörfler 						item->SetMarked(true);
561efa8b4f3SAxel Dörfler 					fGoToPageMenu->AddItem(item);
5626c305411SMatthew Wilber 				}
5636c305411SMatthew Wilber 			} else {
5646c305411SMatthew Wilber 				// Make sure the correct page is marked
5656c305411SMatthew Wilber 				BMenuItem *pcurItem;
566d3046f7dSMichael Pfeiffer 				pcurItem = fGoToPageMenu->ItemAt(curPage - 1);
5676c305411SMatthew Wilber 				if (!pcurItem->IsMarked()) {
5686c305411SMatthew Wilber 					pcurItem->SetMarked(true);
5696c305411SMatthew Wilber 				}
5706c305411SMatthew Wilber 			}
5716c305411SMatthew Wilber 
57216b663b7SMatthew Wilber 			// Disable the Invert menu item if the bitmap color space
57316b663b7SMatthew Wilber 			// is B_CMAP8. (B_CMAP8 is currently unsupported by the
57416b663b7SMatthew Wilber 			// invert algorithm)
57516b663b7SMatthew Wilber 			color_space colors = B_NO_COLOR_SPACE;
576efa8b4f3SAxel Dörfler 			message->FindInt32("colors", reinterpret_cast<int32 *>(&colors));
57716b663b7SMatthew Wilber 			EnableMenuItem(fBar, MSG_INVERT, (colors != B_CMAP8));
57816b663b7SMatthew Wilber 
5790cd4ecd8SStephan Aßmus 			BString status;
5800cd4ecd8SStephan Aßmus 			int32 width, height;
581efa8b4f3SAxel Dörfler 			if (message->FindInt32("width", &width) >= B_OK
582efa8b4f3SAxel Dörfler 				&& message->FindInt32("height", &height) >= B_OK) {
5830cd4ecd8SStephan Aßmus 				status << width << "x" << height << ", ";
5840cd4ecd8SStephan Aßmus 			}
5850cd4ecd8SStephan Aßmus 
58603839579SMatthew Wilber 			BString str;
587efa8b4f3SAxel Dörfler 			if (message->FindString("status", &str) == B_OK) {
5880cd4ecd8SStephan Aßmus 				status << str;
5895eb50e46SMichael Pfeiffer 			}
5900cd4ecd8SStephan Aßmus 
5910cd4ecd8SStephan Aßmus 			fStatusView->SetText(status);
5927eca0987SMichael Pfeiffer 
5937eca0987SMichael Pfeiffer 			UpdateTitle();
59403839579SMatthew Wilber 			break;
59503839579SMatthew Wilber 		}
59603839579SMatthew Wilber 
5978ad30bcfSMatthew Wilber 		case MSG_SELECTION:
5988ad30bcfSMatthew Wilber 		{
5998ad30bcfSMatthew Wilber 			// The view sends this message when a selection is
6008ad30bcfSMatthew Wilber 			// made or the selection is cleared so that the window
6018ad30bcfSMatthew Wilber 			// can update the state of the appropriate menu items
6028ad30bcfSMatthew Wilber 			bool benable;
603efa8b4f3SAxel Dörfler 			if (message->FindBool("has_selection", &benable) == B_OK) {
604d3046f7dSMichael Pfeiffer 				EnableMenuItem(fBar, B_CUT, benable);
605d3046f7dSMichael Pfeiffer 				EnableMenuItem(fBar, B_COPY, benable);
606d3046f7dSMichael Pfeiffer 				EnableMenuItem(fBar, MSG_CLEAR_SELECT, benable);
6078ad30bcfSMatthew Wilber 			}
6088ad30bcfSMatthew Wilber 			break;
6098ad30bcfSMatthew Wilber 		}
6108ad30bcfSMatthew Wilber 
6117598450eSMatthew Wilber 		case MSG_UNDO_STATE:
6127598450eSMatthew Wilber 		{
6137598450eSMatthew Wilber 			bool benable;
614efa8b4f3SAxel Dörfler 			if (message->FindBool("can_undo", &benable) == B_OK)
6157598450eSMatthew Wilber 				EnableMenuItem(fBar, B_UNDO, benable);
6167598450eSMatthew Wilber 			break;
6177598450eSMatthew Wilber 		}
6187598450eSMatthew Wilber 
619402c09e5SMatthew Wilber 		case MSG_CLIPBOARD_CHANGED:
620402c09e5SMatthew Wilber 		{
621402c09e5SMatthew Wilber 			// The app sends this message after it examines
622402c09e5SMatthew Wilber 			// the clipboard in response to a B_CLIPBOARD_CHANGED
623402c09e5SMatthew Wilber 			// message
624402c09e5SMatthew Wilber 			bool bdata;
625efa8b4f3SAxel Dörfler 			if (message->FindBool("data_available", &bdata) == B_OK)
626d3046f7dSMichael Pfeiffer 				EnableMenuItem(fBar, B_PASTE, bdata);
627402c09e5SMatthew Wilber 			break;
628402c09e5SMatthew Wilber 		}
629402c09e5SMatthew Wilber 
63013afa642SPhil Greenway 		case B_UNDO:
6317598450eSMatthew Wilber 			fImageView->Undo();
63213afa642SPhil Greenway 			break;
63313afa642SPhil Greenway 		case B_CUT:
634d3046f7dSMichael Pfeiffer 			fImageView->Cut();
63513afa642SPhil Greenway 			break;
63613afa642SPhil Greenway 		case B_COPY:
637d3046f7dSMichael Pfeiffer 			fImageView->CopySelectionToClipboard();
63813afa642SPhil Greenway 			break;
63913afa642SPhil Greenway 		case B_PASTE:
640d3046f7dSMichael Pfeiffer 			fImageView->Paste();
64113afa642SPhil Greenway 			break;
64213afa642SPhil Greenway 		case MSG_CLEAR_SELECT:
643d3046f7dSMichael Pfeiffer 			fImageView->ClearSelection();
64413afa642SPhil Greenway 			break;
64513afa642SPhil Greenway 		case MSG_SELECT_ALL:
646d3046f7dSMichael Pfeiffer 			fImageView->SelectAll();
64713afa642SPhil Greenway 			break;
64813afa642SPhil Greenway 
64903839579SMatthew Wilber 		case MSG_PAGE_FIRST:
650ee7b4f39SMatthew Wilber 			if (ClosePrompt())
651d3046f7dSMichael Pfeiffer 				fImageView->FirstPage();
65203839579SMatthew Wilber 			break;
65303839579SMatthew Wilber 
65403839579SMatthew Wilber 		case MSG_PAGE_LAST:
655ee7b4f39SMatthew Wilber 			if (ClosePrompt())
656d3046f7dSMichael Pfeiffer 				fImageView->LastPage();
65703839579SMatthew Wilber 			break;
65803839579SMatthew Wilber 
65903839579SMatthew Wilber 		case MSG_PAGE_NEXT:
660ee7b4f39SMatthew Wilber 			if (ClosePrompt())
661d3046f7dSMichael Pfeiffer 				fImageView->NextPage();
66203839579SMatthew Wilber 			break;
66303839579SMatthew Wilber 
66403839579SMatthew Wilber 		case MSG_PAGE_PREV:
665ee7b4f39SMatthew Wilber 			if (ClosePrompt())
666d3046f7dSMichael Pfeiffer 				fImageView->PrevPage();
66703839579SMatthew Wilber 			break;
66803839579SMatthew Wilber 
6696c305411SMatthew Wilber 		case MSG_GOTO_PAGE:
6706c305411SMatthew Wilber 		{
671ee7b4f39SMatthew Wilber 			if (!ClosePrompt())
672ee7b4f39SMatthew Wilber 				break;
673ee7b4f39SMatthew Wilber 
6746c305411SMatthew Wilber 			int32 curPage, newPage, pages;
675efa8b4f3SAxel Dörfler 			if (message->FindInt32("page", &newPage) == B_OK) {
676d3046f7dSMichael Pfeiffer 				curPage = fImageView->CurrentPage();
677d3046f7dSMichael Pfeiffer 				pages = fImageView->PageCount();
6786c305411SMatthew Wilber 
6796c305411SMatthew Wilber 				if (newPage > 0 && newPage <= pages) {
6806c305411SMatthew Wilber 					BMenuItem *pcurItem, *pnewItem;
681d3046f7dSMichael Pfeiffer 					pcurItem = fGoToPageMenu->ItemAt(curPage - 1);
682d3046f7dSMichael Pfeiffer 					pnewItem = fGoToPageMenu->ItemAt(newPage - 1);
6836c305411SMatthew Wilber 					if (!pcurItem || !pnewItem)
6846c305411SMatthew Wilber 						break;
6856c305411SMatthew Wilber 					pcurItem->SetMarked(false);
6866c305411SMatthew Wilber 					pnewItem->SetMarked(true);
687d3046f7dSMichael Pfeiffer 					fImageView->GoToPage(newPage);
6886c305411SMatthew Wilber 				}
6896c305411SMatthew Wilber 			}
6906c305411SMatthew Wilber 			break;
691efa8b4f3SAxel Dörfler 		}
6926c305411SMatthew Wilber 
693cdb89ebbSMatthew Wilber 		case MSG_DITHER_IMAGE:
694efa8b4f3SAxel Dörfler 			fImageView->SetDither(ToggleMenuItem(message->what));
6957eca0987SMichael Pfeiffer 			break;
6967eca0987SMichael Pfeiffer 
69719c76de4SMichael Pfeiffer 		case MSG_SHRINK_TO_WINDOW:
698efa8b4f3SAxel Dörfler 			ResizeToWindow(true, message->what);
69919c76de4SMichael Pfeiffer 			break;
70019c76de4SMichael Pfeiffer 		case MSG_ZOOM_TO_WINDOW:
701efa8b4f3SAxel Dörfler 			ResizeToWindow(false, message->what);
7027eca0987SMichael Pfeiffer 			break;
7037eca0987SMichael Pfeiffer 
7047eca0987SMichael Pfeiffer 		case MSG_FILE_PREV:
705ee7b4f39SMatthew Wilber 			if (ClosePrompt())
706d3046f7dSMichael Pfeiffer 				fImageView->PrevFile();
7077eca0987SMichael Pfeiffer 			break;
7087eca0987SMichael Pfeiffer 
7097eca0987SMichael Pfeiffer 		case MSG_FILE_NEXT:
710ee7b4f39SMatthew Wilber 			if (ClosePrompt())
711d3046f7dSMichael Pfeiffer 				fImageView->NextFile();
71213afa642SPhil Greenway 			break;
71313afa642SPhil Greenway 
714bf461dbeSMatthew Wilber 		case MSG_ROTATE_90:
715d3046f7dSMichael Pfeiffer 			fImageView->Rotate(90);
716ad13f387SMichael Pfeiffer 			break;
717bf461dbeSMatthew Wilber 		case MSG_ROTATE_270:
718d3046f7dSMichael Pfeiffer 			fImageView->Rotate(270);
719ad13f387SMichael Pfeiffer 			break;
720*69eee339SRyan Leavengood 		case MSG_FLIP_LEFT_TO_RIGHT:
72161ddc257SRyan Leavengood 			fImageView->Flip(true);
722ad13f387SMichael Pfeiffer 			break;
723*69eee339SRyan Leavengood 		case MSG_FLIP_TOP_TO_BOTTOM:
72461ddc257SRyan Leavengood 			fImageView->Flip(false);
725ad13f387SMichael Pfeiffer 			break;
726ad13f387SMichael Pfeiffer 		case MSG_INVERT:
727d3046f7dSMichael Pfeiffer 			fImageView->Invert();
728ad13f387SMichael Pfeiffer 			break;
729e6a50d9cSMichael Pfeiffer 		case MSG_SLIDE_SHOW:
730ee7b4f39SMatthew Wilber 		{
731ee7b4f39SMatthew Wilber 			BMenuItem *item;
732efa8b4f3SAxel Dörfler 			item = fBar->FindItem(message->what);
733ee7b4f39SMatthew Wilber 			if (!item)
734ee7b4f39SMatthew Wilber 				break;
735ee7b4f39SMatthew Wilber 			if (item->IsMarked()) {
736ee7b4f39SMatthew Wilber 				item->SetMarked(false);
737d3046f7dSMichael Pfeiffer 				fImageView->StopSlideShow();
738ee7b4f39SMatthew Wilber 			} else if (ClosePrompt()) {
739ee7b4f39SMatthew Wilber 				item->SetMarked(true);
740ee7b4f39SMatthew Wilber 				fImageView->StartSlideShow();
741ad13f387SMichael Pfeiffer 			}
742ee7b4f39SMatthew Wilber 			break;
743efa8b4f3SAxel Dörfler 		}
744ee7b4f39SMatthew Wilber 
745e6a50d9cSMichael Pfeiffer 		case MSG_SLIDE_SHOW_DELAY:
746ad13f387SMichael Pfeiffer 		{
747ad13f387SMichael Pfeiffer 			float value;
748efa8b4f3SAxel Dörfler 			if (message->FindFloat("value", &value) == B_OK) {
749d3046f7dSMichael Pfeiffer 				fImageView->SetSlideShowDelay(value);
750da87390fSMichael Pfeiffer 				// in case message is sent from popup menu
751da87390fSMichael Pfeiffer 				MarkSlideShowDelay(value);
752ad13f387SMichael Pfeiffer 			}
753ad13f387SMichael Pfeiffer 			break;
754efa8b4f3SAxel Dörfler 		}
755ad13f387SMichael Pfeiffer 
756ad13f387SMichael Pfeiffer 		case MSG_FULL_SCREEN:
757ad13f387SMichael Pfeiffer 			ToggleFullScreen();
758ad13f387SMichael Pfeiffer 			break;
759fc5ca95dSStephan Aßmus 		case MSG_EXIT_FULL_SCREEN:
760fc5ca95dSStephan Aßmus 			if (fFullScreen)
761fc5ca95dSStephan Aßmus 				ToggleFullScreen();
762fc5ca95dSStephan Aßmus 			break;
763e6a50d9cSMichael Pfeiffer 		case MSG_SHOW_CAPTION:
764efa8b4f3SAxel Dörfler 		{
765efa8b4f3SAxel Dörfler 			fShowCaption = ToggleMenuItem(message->what);
766efa8b4f3SAxel Dörfler 			ShowImageSettings* settings = my_app->Settings();
767efa8b4f3SAxel Dörfler 
768d3046f7dSMichael Pfeiffer 			if (settings->Lock()) {
769d3046f7dSMichael Pfeiffer 				settings->SetBool("ShowCaption", fShowCaption);
770d3046f7dSMichael Pfeiffer 				settings->Unlock();
771d3046f7dSMichael Pfeiffer 			}
772efa8b4f3SAxel Dörfler 			if (fFullScreen)
773d3046f7dSMichael Pfeiffer 				fImageView->SetShowCaption(fShowCaption);
774e6a50d9cSMichael Pfeiffer 			break;
775efa8b4f3SAxel Dörfler 		}
776ad13f387SMichael Pfeiffer 
777780d8a62SMichael Pfeiffer 		case MSG_PAGE_SETUP:
778780d8a62SMichael Pfeiffer 			PageSetup();
779780d8a62SMichael Pfeiffer 			break;
780780d8a62SMichael Pfeiffer 		case MSG_PREPARE_PRINT:
781780d8a62SMichael Pfeiffer 			PrepareForPrint();
782780d8a62SMichael Pfeiffer 			break;
783780d8a62SMichael Pfeiffer 		case MSG_PRINT:
784efa8b4f3SAxel Dörfler 			Print(message);
785780d8a62SMichael Pfeiffer 			break;
786780d8a62SMichael Pfeiffer 
787780d8a62SMichael Pfeiffer 		case MSG_ZOOM_IN:
788d3046f7dSMichael Pfeiffer 			fImageView->ZoomIn();
789780d8a62SMichael Pfeiffer 			break;
790780d8a62SMichael Pfeiffer 		case MSG_ZOOM_OUT:
791d3046f7dSMichael Pfeiffer 			fImageView->ZoomOut();
792780d8a62SMichael Pfeiffer 			break;
793780d8a62SMichael Pfeiffer 		case MSG_ORIGINAL_SIZE:
794d3046f7dSMichael Pfeiffer 			fImageView->SetZoom(1.0);
795780d8a62SMichael Pfeiffer 			break;
79681b9c776SMichael Pfeiffer 		case MSG_SCALE_BILINEAR:
797efa8b4f3SAxel Dörfler 			fImageView->SetScaleBilinear(ToggleMenuItem(message->what));
79881b9c776SMichael Pfeiffer 			break;
799780d8a62SMichael Pfeiffer 
800a60adbf9SAxel Dörfler 		case MSG_DESKTOP_BACKGROUND:
801a60adbf9SAxel Dörfler 		{
802a60adbf9SAxel Dörfler 			BPath path;
803a60adbf9SAxel Dörfler 			if (path.SetTo(fImageView->Image()) == B_OK) {
8045921f4e2SAxel Dörfler 				BackgroundImage::SetDesktopImage(B_CURRENT_WORKSPACE,
8055921f4e2SAxel Dörfler 					path.Path(), BackgroundImage::kScaledToFit,
8065921f4e2SAxel Dörfler 					BPoint(0, 0), false);
807a60adbf9SAxel Dörfler 			}
808a60adbf9SAxel Dörfler 			break;
809a60adbf9SAxel Dörfler 		}
810a60adbf9SAxel Dörfler 
81113afa642SPhil Greenway 		default:
812efa8b4f3SAxel Dörfler 			BWindow::MessageReceived(message);
81313afa642SPhil Greenway 			break;
81413afa642SPhil Greenway 	}
81513afa642SPhil Greenway }
816fc0a275bSMatthew Wilber 
817efa8b4f3SAxel Dörfler 
818fc0a275bSMatthew Wilber void
819efa8b4f3SAxel Dörfler ShowImageWindow::SaveAs(BMessage *message)
820fc0a275bSMatthew Wilber {
821cdb89ebbSMatthew Wilber 	// Read the translator and output type the user chose
822cdb89ebbSMatthew Wilber 	translator_id outTranslator;
823cdb89ebbSMatthew Wilber 	uint32 outType;
824efa8b4f3SAxel Dörfler 	if (message->FindInt32(TRANSLATOR_FLD,
825efa8b4f3SAxel Dörfler 			reinterpret_cast<int32 *>(&outTranslator)) != B_OK
826efa8b4f3SAxel Dörfler 		|| message->FindInt32(TYPE_FLD,
827cdb89ebbSMatthew Wilber 			reinterpret_cast<int32 *>(&outType)) != B_OK)
828fc0a275bSMatthew Wilber 		return;
829fc0a275bSMatthew Wilber 
830cdb89ebbSMatthew Wilber 	// Add the chosen translator and output type to the
831cdb89ebbSMatthew Wilber 	// message that the save panel will send back
832a60adbf9SAxel Dörfler 	BMessage *panelMsg = new BMessage(MSG_SAVE_PANEL);
833a60adbf9SAxel Dörfler 	panelMsg->AddInt32(TRANSLATOR_FLD, outTranslator);
834a60adbf9SAxel Dörfler 	panelMsg->AddInt32(TYPE_FLD, outType);
835cdb89ebbSMatthew Wilber 
836cdb89ebbSMatthew Wilber 	// Create save panel and show it
837efa8b4f3SAxel Dörfler 	fSavePanel = new (std::nothrow) BFilePanel(B_SAVE_PANEL,
838a60adbf9SAxel Dörfler 		new BMessenger(this), NULL, 0, false, panelMsg);
839d3046f7dSMichael Pfeiffer 	if (!fSavePanel)
840fc0a275bSMatthew Wilber 		return;
841a60adbf9SAxel Dörfler 
842d3046f7dSMichael Pfeiffer 	fSavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
843d3046f7dSMichael Pfeiffer 	fSavePanel->Show();
844fc0a275bSMatthew Wilber }
845fc0a275bSMatthew Wilber 
846efa8b4f3SAxel Dörfler 
847fc0a275bSMatthew Wilber void
848efa8b4f3SAxel Dörfler ShowImageWindow::SaveToFile(BMessage *message)
849fc0a275bSMatthew Wilber {
850cdb89ebbSMatthew Wilber 	// Read in where the file should be saved
851efa8b4f3SAxel Dörfler 	entry_ref dirRef;
852efa8b4f3SAxel Dörfler 	if (message->FindRef("directory", &dirRef) != B_OK)
853fc0a275bSMatthew Wilber 		return;
854efa8b4f3SAxel Dörfler 
855fc0a275bSMatthew Wilber 	const char *filename;
856efa8b4f3SAxel Dörfler 	if (message->FindString("name", &filename) != B_OK)
857fc0a275bSMatthew Wilber 		return;
858fc0a275bSMatthew Wilber 
859cdb89ebbSMatthew Wilber 	// Read in the translator and type to be used
860cdb89ebbSMatthew Wilber 	// to save the output image
861cdb89ebbSMatthew Wilber 	translator_id outTranslator;
862cdb89ebbSMatthew Wilber 	uint32 outType;
863efa8b4f3SAxel Dörfler 	if (message->FindInt32(TRANSLATOR_FLD,
864efa8b4f3SAxel Dörfler 			reinterpret_cast<int32 *>(&outTranslator)) != B_OK
865efa8b4f3SAxel Dörfler 		|| message->FindInt32(TYPE_FLD,
866cdb89ebbSMatthew Wilber 			reinterpret_cast<int32 *>(&outType)) != B_OK)
867cdb89ebbSMatthew Wilber 		return;
868cdb89ebbSMatthew Wilber 
869a7e78e3bSMatthew Wilber 	// Find the translator_format information needed to
870a7e78e3bSMatthew Wilber 	// write a MIME attribute for the image file
871a7e78e3bSMatthew Wilber 	BTranslatorRoster *roster = BTranslatorRoster::Default();
872efa8b4f3SAxel Dörfler 	const translation_format *outFormat = NULL;
873efa8b4f3SAxel Dörfler 	int32 outCount = 0;
874efa8b4f3SAxel Dörfler 	if (roster->GetOutputFormats(outTranslator, &outFormat, &outCount) != B_OK
875efa8b4f3SAxel Dörfler 		|| outCount < 1)
876a7e78e3bSMatthew Wilber 		return;
877efa8b4f3SAxel Dörfler 
878a7e78e3bSMatthew Wilber 	int32 i;
879efa8b4f3SAxel Dörfler 	for (i = 0; i < outCount; i++) {
880efa8b4f3SAxel Dörfler 		if (outFormat[i].group == B_TRANSLATOR_BITMAP && outFormat[i].type == outType)
881a7e78e3bSMatthew Wilber 			break;
882a7e78e3bSMatthew Wilber 	}
883efa8b4f3SAxel Dörfler 	if (i == outCount)
884fc0a275bSMatthew Wilber 		return;
885fc0a275bSMatthew Wilber 
886a7e78e3bSMatthew Wilber 	// Write out the image file
887efa8b4f3SAxel Dörfler 	BDirectory dir(&dirRef);
888efa8b4f3SAxel Dörfler 	fImageView->SaveToFile(&dir, filename, NULL, &outFormat[i]);
889fc0a275bSMatthew Wilber }
890fc0a275bSMatthew Wilber 
891efa8b4f3SAxel Dörfler 
892cdb89ebbSMatthew Wilber bool
893ee7b4f39SMatthew Wilber ShowImageWindow::ClosePrompt()
894ee7b4f39SMatthew Wilber {
895ee7b4f39SMatthew Wilber 	if (!fModified)
896ee7b4f39SMatthew Wilber 		return true;
897efa8b4f3SAxel Dörfler 
898ee7b4f39SMatthew Wilber 	int32 page, count;
899ee7b4f39SMatthew Wilber 	count = fImageView->PageCount();
900ee7b4f39SMatthew Wilber 	page = fImageView->CurrentPage();
901ee7b4f39SMatthew Wilber 	BString prompt, name;
902ee7b4f39SMatthew Wilber 	fImageView->GetName(&name);
903ee7b4f39SMatthew Wilber 	prompt << "The document '" << name << "'";
904ee7b4f39SMatthew Wilber 	if (count > 1)
905ee7b4f39SMatthew Wilber 		prompt << " (page " << page << ")";
906efa8b4f3SAxel Dörfler 
907ee7b4f39SMatthew Wilber 	prompt << " has been changed. "
908ee7b4f39SMatthew Wilber 	       << "Do you want to close the document?";
909ee7b4f39SMatthew Wilber 	BAlert *pAlert = new BAlert("Close document", prompt.String(),
910ee7b4f39SMatthew Wilber 		"Cancel", "Close");
911efa8b4f3SAxel Dörfler 	if (pAlert->Go() == 0) {
912ee7b4f39SMatthew Wilber 		// Cancel
913ee7b4f39SMatthew Wilber 		return false;
914efa8b4f3SAxel Dörfler 	} else {
915ee7b4f39SMatthew Wilber 		// Close
916187f0b8aSMatthew Wilber 		fModified = false;
917ee7b4f39SMatthew Wilber 		return true;
918ee7b4f39SMatthew Wilber 	}
919ee7b4f39SMatthew Wilber }
920ee7b4f39SMatthew Wilber 
921cdb89ebbSMatthew Wilber 
922ad13f387SMichael Pfeiffer void
923ad13f387SMichael Pfeiffer ShowImageWindow::ToggleFullScreen()
924ad13f387SMichael Pfeiffer {
925ad13f387SMichael Pfeiffer 	BRect frame;
926ad13f387SMichael Pfeiffer 	fFullScreen = !fFullScreen;
927ad13f387SMichael Pfeiffer 	if (fFullScreen) {
928ad13f387SMichael Pfeiffer 		BScreen screen;
929ad13f387SMichael Pfeiffer 		fWindowFrame = Frame();
930ad13f387SMichael Pfeiffer 		frame = screen.Frame();
931d3046f7dSMichael Pfeiffer 		frame.top -= fBar->Bounds().Height()+1;
932ad13f387SMichael Pfeiffer 		frame.right += B_V_SCROLL_BAR_WIDTH;
933ad13f387SMichael Pfeiffer 		frame.bottom += B_H_SCROLL_BAR_HEIGHT;
934ad13f387SMichael Pfeiffer 		frame.InsetBy(-1, -1); // PEN_SIZE in ShowImageView
935ad13f387SMichael Pfeiffer 
936ad13f387SMichael Pfeiffer 		SetFlags(Flags() | B_NOT_RESIZABLE | B_NOT_MOVABLE);
937d3046f7dSMichael Pfeiffer 		fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE);
938ad13f387SMichael Pfeiffer 	} else {
939ad13f387SMichael Pfeiffer 		frame = fWindowFrame;
940ad13f387SMichael Pfeiffer 
941ad13f387SMichael Pfeiffer 		SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE));
942fc5ca95dSStephan Aßmus // NOTE: I changed this to not use left/top alignment at all, because
943fc5ca95dSStephan Aßmus // I have no idea why it would be useful. The layouting is much more
944fc5ca95dSStephan Aßmus // predictable now. -Stephan
945fc5ca95dSStephan Aßmus //		fImageView->SetAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
946fc5ca95dSStephan Aßmus 		fImageView->SetAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE);
947ad13f387SMichael Pfeiffer 	}
948efa8b4f3SAxel Dörfler 
949d3046f7dSMichael Pfeiffer 	fImageView->SetBorder(!fFullScreen);
950d3046f7dSMichael Pfeiffer 	fImageView->SetShowCaption(fFullScreen && fShowCaption);
951ad13f387SMichael Pfeiffer 	MoveTo(frame.left, frame.top);
952ad13f387SMichael Pfeiffer 	ResizeTo(frame.Width(), frame.Height());
953ad13f387SMichael Pfeiffer }
954ad13f387SMichael Pfeiffer 
955efa8b4f3SAxel Dörfler 
956d3046f7dSMichael Pfeiffer void
957d3046f7dSMichael Pfeiffer ShowImageWindow::LoadSettings()
958d3046f7dSMichael Pfeiffer {
959efa8b4f3SAxel Dörfler 	ShowImageSettings* settings = my_app->Settings();
960efa8b4f3SAxel Dörfler 
961d3046f7dSMichael Pfeiffer 	if (settings->Lock()) {
962d3046f7dSMichael Pfeiffer 		fShowCaption = settings->GetBool("ShowCaption", fShowCaption);
963d3046f7dSMichael Pfeiffer 		fPrintOptions.SetBounds(BRect(0, 0, 1023, 767));
964d3046f7dSMichael Pfeiffer 
965efa8b4f3SAxel Dörfler 		int32 op = settings->GetInt32("PO:Option", fPrintOptions.Option());
966d3046f7dSMichael Pfeiffer 		fPrintOptions.SetOption((enum PrintOptions::Option)op);
967d3046f7dSMichael Pfeiffer 
968efa8b4f3SAxel Dörfler 		float f = settings->GetFloat("PO:ZoomFactor", fPrintOptions.ZoomFactor());
969d3046f7dSMichael Pfeiffer 		fPrintOptions.SetZoomFactor(f);
970d3046f7dSMichael Pfeiffer 
971d3046f7dSMichael Pfeiffer 		f = settings->GetFloat("PO:DPI", fPrintOptions.DPI());
972d3046f7dSMichael Pfeiffer 		fPrintOptions.SetDPI(f);
973d3046f7dSMichael Pfeiffer 
974d3046f7dSMichael Pfeiffer 		f = settings->GetFloat("PO:Width", fPrintOptions.Width());
975d3046f7dSMichael Pfeiffer 		fPrintOptions.SetWidth(f);
976d3046f7dSMichael Pfeiffer 
977d3046f7dSMichael Pfeiffer 		f = settings->GetFloat("PO:Height", fPrintOptions.Height());
978d3046f7dSMichael Pfeiffer 		fPrintOptions.SetHeight(f);
979d3046f7dSMichael Pfeiffer 
980d3046f7dSMichael Pfeiffer 		settings->Unlock();
981d3046f7dSMichael Pfeiffer 	}
982d3046f7dSMichael Pfeiffer }
983d3046f7dSMichael Pfeiffer 
984efa8b4f3SAxel Dörfler 
985d3046f7dSMichael Pfeiffer void
986d3046f7dSMichael Pfeiffer ShowImageWindow::SavePrintOptions()
987d3046f7dSMichael Pfeiffer {
988efa8b4f3SAxel Dörfler 	ShowImageSettings* settings = my_app->Settings();
989efa8b4f3SAxel Dörfler 
990d3046f7dSMichael Pfeiffer 	if (settings->Lock()) {
991d3046f7dSMichael Pfeiffer 		settings->SetInt32("PO:Option", fPrintOptions.Option());
992d3046f7dSMichael Pfeiffer 		settings->SetFloat("PO:ZoomFactor", fPrintOptions.ZoomFactor());
993d3046f7dSMichael Pfeiffer 		settings->SetFloat("PO:DPI", fPrintOptions.DPI());
994d3046f7dSMichael Pfeiffer 		settings->SetFloat("PO:Width", fPrintOptions.Width());
995d3046f7dSMichael Pfeiffer 		settings->SetFloat("PO:Height", fPrintOptions.Height());
996d3046f7dSMichael Pfeiffer 		settings->Unlock();
997d3046f7dSMichael Pfeiffer 	}
998d3046f7dSMichael Pfeiffer }
999d3046f7dSMichael Pfeiffer 
1000efa8b4f3SAxel Dörfler 
1001cdb89ebbSMatthew Wilber bool
1002780d8a62SMichael Pfeiffer ShowImageWindow::PageSetup()
1003780d8a62SMichael Pfeiffer {
1004780d8a62SMichael Pfeiffer 	status_t st;
1005780d8a62SMichael Pfeiffer 	BString name;
1006d3046f7dSMichael Pfeiffer 	fImageView->GetName(&name);
1007780d8a62SMichael Pfeiffer 	BPrintJob printJob(name.String());
1008efa8b4f3SAxel Dörfler 	if (fPrintSettings != NULL)
1009780d8a62SMichael Pfeiffer 		printJob.SetSettings(new BMessage(*fPrintSettings));
1010efa8b4f3SAxel Dörfler 
1011780d8a62SMichael Pfeiffer 	st = printJob.ConfigPage();
1012780d8a62SMichael Pfeiffer 	if (st == B_OK) {
1013780d8a62SMichael Pfeiffer 		delete fPrintSettings;
1014780d8a62SMichael Pfeiffer 		fPrintSettings = printJob.Settings();
1015780d8a62SMichael Pfeiffer 	}
1016efa8b4f3SAxel Dörfler 
1017780d8a62SMichael Pfeiffer 	return st == B_OK;
1018780d8a62SMichael Pfeiffer }
1019780d8a62SMichael Pfeiffer 
1020efa8b4f3SAxel Dörfler 
1021780d8a62SMichael Pfeiffer void
1022780d8a62SMichael Pfeiffer ShowImageWindow::PrepareForPrint()
1023780d8a62SMichael Pfeiffer {
1024efa8b4f3SAxel Dörfler 	if (fPrintSettings == NULL && !PageSetup())
1025780d8a62SMichael Pfeiffer 		return;
1026780d8a62SMichael Pfeiffer 
1027d3046f7dSMichael Pfeiffer 	fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds());
1028d3046f7dSMichael Pfeiffer 	fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width()+1);
1029780d8a62SMichael Pfeiffer 
1030efa8b4f3SAxel Dörfler 	new PrintOptionsWindow(BPoint(Frame().left+30, Frame().top+50),
1031efa8b4f3SAxel Dörfler 		&fPrintOptions, this);
1032780d8a62SMichael Pfeiffer }
1033780d8a62SMichael Pfeiffer 
1034efa8b4f3SAxel Dörfler 
1035780d8a62SMichael Pfeiffer void
1036780d8a62SMichael Pfeiffer ShowImageWindow::Print(BMessage *msg)
1037780d8a62SMichael Pfeiffer {
1038780d8a62SMichael Pfeiffer 	status_t st;
1039efa8b4f3SAxel Dörfler 	if (msg->FindInt32("status", &st) != B_OK || st != B_OK)
1040780d8a62SMichael Pfeiffer 		return;
1041780d8a62SMichael Pfeiffer 
1042d3046f7dSMichael Pfeiffer 	SavePrintOptions();
1043d3046f7dSMichael Pfeiffer 
1044780d8a62SMichael Pfeiffer 	BString name;
1045d3046f7dSMichael Pfeiffer 	fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds());
1046d3046f7dSMichael Pfeiffer 	fImageView->GetName(&name);
1047780d8a62SMichael Pfeiffer 	BPrintJob printJob(name.String());
1048780d8a62SMichael Pfeiffer 	printJob.SetSettings(new BMessage(*fPrintSettings));
1049780d8a62SMichael Pfeiffer 	if (printJob.ConfigJob() == B_OK) {
1050780d8a62SMichael Pfeiffer 		int32 firstPage;
1051780d8a62SMichael Pfeiffer 		int32 lastPage;
1052780d8a62SMichael Pfeiffer 		BRect printableRect = printJob.PrintableRect();
1053780d8a62SMichael Pfeiffer 		float width, imageWidth, imageHeight, w1, w2;
1054780d8a62SMichael Pfeiffer 		BBitmap* bitmap;
1055780d8a62SMichael Pfeiffer 
1056780d8a62SMichael Pfeiffer 		// first/lastPage is unused for now
1057780d8a62SMichael Pfeiffer 		firstPage = printJob.FirstPage();
1058780d8a62SMichael Pfeiffer 		lastPage = printJob.LastPage();
1059efa8b4f3SAxel Dörfler 		if (firstPage < 1)
1060780d8a62SMichael Pfeiffer 			firstPage = 1;
1061efa8b4f3SAxel Dörfler 		if (lastPage < firstPage)
1062780d8a62SMichael Pfeiffer 			lastPage = firstPage;
1063780d8a62SMichael Pfeiffer 
1064d3046f7dSMichael Pfeiffer 		bitmap = fImageView->GetBitmap();
1065780d8a62SMichael Pfeiffer 		imageWidth = bitmap->Bounds().Width() + 1.0;
1066780d8a62SMichael Pfeiffer 		imageHeight = bitmap->Bounds().Height() + 1.0;
1067780d8a62SMichael Pfeiffer 
1068780d8a62SMichael Pfeiffer 		switch (fPrintOptions.Option()) {
1069780d8a62SMichael Pfeiffer 			case PrintOptions::kFitToPage:
1070780d8a62SMichael Pfeiffer 				w1 = printableRect.Width()+1;
1071780d8a62SMichael Pfeiffer 				w2 = imageWidth * (printableRect.Height() + 1) / imageHeight;
1072efa8b4f3SAxel Dörfler 				if (w2 < w1)
1073780d8a62SMichael Pfeiffer 					width = w2;
1074efa8b4f3SAxel Dörfler 				else
1075780d8a62SMichael Pfeiffer 					width = w1;
1076780d8a62SMichael Pfeiffer 				break;
1077780d8a62SMichael Pfeiffer 			case PrintOptions::kZoomFactor:
1078780d8a62SMichael Pfeiffer 				width = imageWidth * fPrintOptions.ZoomFactor();
1079780d8a62SMichael Pfeiffer 				break;
1080780d8a62SMichael Pfeiffer 			case PrintOptions::kDPI:
1081780d8a62SMichael Pfeiffer 				width = imageWidth * 72.0 / fPrintOptions.DPI();
1082780d8a62SMichael Pfeiffer 				break;
1083780d8a62SMichael Pfeiffer 			case PrintOptions::kWidth:
1084780d8a62SMichael Pfeiffer 			case PrintOptions::kHeight:
1085780d8a62SMichael Pfeiffer 				width = fPrintOptions.Width();
1086780d8a62SMichael Pfeiffer 				break;
1087efa8b4f3SAxel Dörfler 
1088780d8a62SMichael Pfeiffer 			default:
1089780d8a62SMichael Pfeiffer 				// keep compiler silent; should not reach here
1090780d8a62SMichael Pfeiffer 				width = imageWidth;
1091780d8a62SMichael Pfeiffer 		}
1092780d8a62SMichael Pfeiffer 
1093efa8b4f3SAxel Dörfler 		// TODO: eventually print large images on several pages
1094780d8a62SMichael Pfeiffer 		printJob.BeginJob();
1095d3046f7dSMichael Pfeiffer 		fImageView->SetScale(width / imageWidth);
10965eb50e46SMichael Pfeiffer 		// coordinates are relative to printable rectangle
10975eb50e46SMichael Pfeiffer 		BRect bounds(bitmap->Bounds());
10985eb50e46SMichael Pfeiffer 		printJob.DrawView(fImageView, bounds, BPoint(0, 0));
1099d3046f7dSMichael Pfeiffer 		fImageView->SetScale(1.0);
1100780d8a62SMichael Pfeiffer 		printJob.SpoolPage();
1101780d8a62SMichael Pfeiffer 		printJob.CommitJob();
1102780d8a62SMichael Pfeiffer 	}
1103780d8a62SMichael Pfeiffer }
1104780d8a62SMichael Pfeiffer 
1105efa8b4f3SAxel Dörfler 
1106780d8a62SMichael Pfeiffer bool
1107cdb89ebbSMatthew Wilber ShowImageWindow::QuitRequested()
1108cdb89ebbSMatthew Wilber {
1109efa8b4f3SAxel Dörfler 	if (fSavePanel) {
1110efa8b4f3SAxel Dörfler 		// Don't allow this window to be closed if a save panel is open
1111efa8b4f3SAxel Dörfler 		return false;
1112cdb89ebbSMatthew Wilber 	}
1113cdb89ebbSMatthew Wilber 
1114efa8b4f3SAxel Dörfler 	bool quit = ClosePrompt();
1115efa8b4f3SAxel Dörfler 
1116efa8b4f3SAxel Dörfler 	if (quit) {
111707caaa8eSMatthew Wilber 		// tell the app to forget about this window
111807caaa8eSMatthew Wilber 		be_app->PostMessage(MSG_WINDOW_QUIT);
111907caaa8eSMatthew Wilber 	}
1120fc0a275bSMatthew Wilber 
1121efa8b4f3SAxel Dörfler 	return quit;
1122efa8b4f3SAxel Dörfler }
1123efa8b4f3SAxel Dörfler 
1124efa8b4f3SAxel Dörfler 
1125fc5ca95dSStephan Aßmus void
1126fc5ca95dSStephan Aßmus ShowImageWindow::Zoom(BPoint origin, float width, float height)
1127fc5ca95dSStephan Aßmus {
1128fc5ca95dSStephan Aßmus 	// just go into fullscreen
1129fc5ca95dSStephan Aßmus 	ToggleFullScreen();
1130fc5ca95dSStephan Aßmus }
1131fc5ca95dSStephan Aßmus 
1132