ScreenSaverWindow::ScreenSaverWindow()
	:
	BWindow(BRect(50.0f, 50.0f, 50.0f + kWindowWidth, 50.0f + kWindowHeight),
		B_TRANSLATE_SYSTEM_NAME("ScreenSaver"), B_TITLED_WINDOW,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
	fSettings.Load();

	fMinWidth = floorf(be_control_look->DefaultItemSpacing()
		* (kWindowWidth / kDefaultItemSpacingAt12pt));

	font_height fontHeight;
	be_plain_font->GetHeight(&fontHeight);
	float textHeight = ceilf(fontHeight.ascent + fontHeight.descent);

	fMinHeight = ceilf(std::max(kWindowHeight, textHeight * 28));

	// Create the password editing window
	fPasswordWindow = new PasswordWindow(fSettings);
	fPasswordWindow->Run();

	// Create the tab view
	fTabView = new TabView();
	fTabView->SetBorder(B_NO_BORDER);

	// Create the controls inside the tabs
	fFadeView = new FadeView(B_TRANSLATE("General"), fSettings);
	fModulesView = new ModulesView(B_TRANSLATE("Screensavers"), fSettings);

	fTabView->AddTab(fFadeView);
	fTabView->AddTab(fModulesView);

	// Create the topmost background view
	BView* topView = new BView("topView", B_WILL_DRAW);
	topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	topView->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
		B_ALIGN_USE_FULL_HEIGHT));
	topView->SetExplicitMinSize(BSize(fMinWidth, fMinHeight));
	BLayoutBuilder::Group<>(topView, B_VERTICAL)
		.SetInsets(0, B_USE_DEFAULT_SPACING, 0, B_USE_WINDOW_SPACING)
		.Add(fTabView)
		.End();

	SetLayout(new BGroupLayout(B_VERTICAL));
	GetLayout()->AddView(topView);

	fTabView->Select(fSettings.WindowTab());

	if (fSettings.WindowFrame().left > 0 && fSettings.WindowFrame().top > 0)
		MoveTo(fSettings.WindowFrame().left, fSettings.WindowFrame().top);

	if (fSettings.WindowFrame().Width() > 0
		&& fSettings.WindowFrame().Height() > 0) {
		ResizeTo(fSettings.WindowFrame().Width(),
			fSettings.WindowFrame().Height());
	}

	CenterOnScreen();
}
Exemple #2
0
ScreenSaverWindow::ScreenSaverWindow()
	:
	BWindow(BRect(50, 50, 496, 375), B_TRANSLATE_SYSTEM_NAME("ScreenSaver"),
		B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
	fSettings.Load();

	float spacing = be_control_look->DefaultItemSpacing();

	fMinWidth = ceilf(std::max(446.0f, spacing * 44.6f));
	fMinHeight = ceilf(std::max(325.0f, spacing * 32.5f));

	// Create the password editing window
	fPasswordWindow = new PasswordWindow(fSettings);
	fPasswordWindow->Run();

	// Create the tab view
	fTabView = new BTabView("tab_view", B_WIDTH_FROM_LABEL);

	// Create the controls inside the tabs
	fFadeView = new FadeView(B_TRANSLATE("General"), fSettings);
	fModulesView = new ModulesView(B_TRANSLATE("Screensavers"), fSettings);

	fTabView->AddTab(fFadeView);
	fTabView->AddTab(fModulesView);

	// Create the topmost background view
	BView* topView = new BView("topView", B_WILL_DRAW);
	topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	topView->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
		B_ALIGN_USE_FULL_HEIGHT));
	topView->SetExplicitMinSize(BSize(fMinWidth, fMinHeight));
	BLayoutBuilder::Group<>(topView, B_VERTICAL)
		.SetInsets(-1, B_USE_SMALL_SPACING, -1, -1)
		.Add(fTabView)
		.End();

	SetLayout(new BGroupLayout(B_VERTICAL));
	GetLayout()->AddView(topView);

	fTabView->Select(fSettings.WindowTab());

	if (fSettings.WindowFrame().left > 0 && fSettings.WindowFrame().top > 0)
		MoveTo(fSettings.WindowFrame().left, fSettings.WindowFrame().top);

	if (fSettings.WindowFrame().Width() > 0
		&& fSettings.WindowFrame().Height() > 0) {
		ResizeTo(fSettings.WindowFrame().Width(),
			fSettings.WindowFrame().Height());
	}
}
ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
	const BMessenger& trackerMessenger)
	:
	BWindow(frame, "", B_DOCUMENT_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS),
	fNavigator(ref, trackerMessenger),
	fSavePanel(NULL),
	fBar(NULL),
	fBrowseMenu(NULL),
	fGoToPageMenu(NULL),
	fSlideShowDelayMenu(NULL),
	fToolBar(NULL),
	fImageView(NULL),
	fStatusView(NULL),
	fProgressWindow(new ProgressWindow()),
	fModified(false),
	fFullScreen(false),
	fShowCaption(true),
	fShowToolBar(true),
	fPrintSettings(NULL),
	fSlideShowRunner(NULL),
	fSlideShowDelay(kDefaultSlideShowDelay)
{
	_ApplySettings();

	SetLayout(new BGroupLayout(B_VERTICAL, 0));

	// create menu bar
	fBar = new BMenuBar("menu_bar");
	_AddMenus(fBar);
	float menuBarMinWidth = fBar->MinSize().width;
	AddChild(fBar);

	// Add a content view so the tool bar can be moved outside of the
	// visible portion without colliding with the menu bar.

	BView* contentView = new BView(BRect(), "content", B_FOLLOW_NONE, 0);
	contentView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	contentView->SetExplicitMinSize(BSize(250, 100));
	AddChild(contentView);

	// Create the tool bar
	BRect viewFrame = contentView->Bounds();
	viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
	fToolBar = new BToolBar(viewFrame);

	// Add the tool icons.

//	fToolBar->AddAction(MSG_FILE_OPEN, be_app,
//		tool_bar_icon(kIconDocumentOpen), B_TRANSLATE("Open" B_UTF8_ELLIPSIS));
	fToolBar->AddAction(MSG_FILE_PREV, this,
		tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file"), false);
	fToolBar->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext),
		B_TRANSLATE("Next file"), false);
	BMessage* fullScreenSlideShow = new BMessage(MSG_SLIDE_SHOW);
	fullScreenSlideShow->AddBool("full screen", true);
	fToolBar->AddAction(fullScreenSlideShow, this,
		tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide show"),
		false);
	fToolBar->AddSeparator();
	fToolBar->AddAction(MSG_SELECTION_MODE, this,
		tool_bar_icon(kIconDrawRectangularSelection),
		B_TRANSLATE("Selection mode"), false);
	fToolBar->AddSeparator();
	fToolBar->AddAction(kMsgOriginalSize, this,
		tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"), true);
	fToolBar->AddAction(kMsgFitToWindow, this,
		tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"), false);
	fToolBar->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn),
		B_TRANSLATE("Zoom in"), false);
	fToolBar->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut),
		B_TRANSLATE("Zoom out"), false);
	fToolBar->AddSeparator();
	fToolBar->AddAction(MSG_PAGE_PREV, this, tool_bar_icon(kIconPagePrevious),
		B_TRANSLATE("Previous page"), false);
	fToolBar->AddAction(MSG_PAGE_NEXT, this, tool_bar_icon(kIconPageNext),
		B_TRANSLATE("Next page"), false);
	fToolBar->AddGlue();
	fToolBar->AddAction(MSG_FULL_SCREEN, this,
		tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full screen"),
		false);
	fToolBar->SetActionVisible(MSG_FULL_SCREEN, false);

	fToolBar->ResizeTo(viewFrame.Width(), fToolBar->MinSize().height);

	contentView->AddChild(fToolBar);

	if (fShowToolBar)
		viewFrame.top = fToolBar->Frame().bottom + 1;
	else
		fToolBar->Hide();

	fToolBarVisible = fShowToolBar;

	viewFrame.bottom = contentView->Bounds().bottom;
	viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;

	// create the image view
	fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED
			| B_FRAME_EVENTS);
	// wrap a scroll view around the view
	fScrollView = new BScrollView("image_scroller", fImageView,
		B_FOLLOW_ALL, 0, true, true, B_PLAIN_BORDER);
	contentView->AddChild(fScrollView);

	fStatusView = new ShowImageStatusView(fScrollView);
	fScrollView->AddChild(fStatusView);

	// Update minimum window size
	float toolBarMinWidth = fToolBar->MinSize().width;
	SetSizeLimits(std::max(menuBarMinWidth, toolBarMinWidth), 100000, 100,
		100000);

	// finish creating the window
	if (_LoadImage() != B_OK) {
		_LoadError(ref);
		Quit();
		return;
	}

	// add View menu here so it can access ShowImageView methods
	BMenu* menu = new BMenu(B_TRANSLATE_CONTEXT("View", "Menus"));
	_BuildViewMenu(menu, false);
	fBar->AddItem(menu);

	fBar->AddItem(_BuildRatingMenu());

	SetPulseRate(100000);
		// every 1/10 second; ShowImageView needs it for marching ants

	_MarkMenuItem(menu, MSG_SELECTION_MODE,
		fImageView->IsSelectionModeEnabled());

	// Tell application object to query the clipboard
	// and tell this window if it contains interesting data or not
	be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED);

	// The window will be shown on screen automatically
	Run();
}