// AlignInFrame void BLayoutUtils::AlignInFrame(BView* view, BRect frame) { BSize maxSize = view->MaxSize(); BAlignment alignment = view->LayoutAlignment(); if (view->HasHeightForWidth()) { // The view has height for width, so we do the horizontal alignment // ourselves and restrict the height max constraint respectively. if (maxSize.width < frame.Width() && alignment.horizontal != B_ALIGN_USE_FULL_WIDTH) { frame.OffsetBy(floor((frame.Width() - maxSize.width) * alignment.RelativeHorizontal()), 0); frame.right = frame.left + maxSize.width; } alignment.horizontal = B_ALIGN_USE_FULL_WIDTH; float minHeight; float maxHeight; float preferredHeight; view->GetHeightForWidth(frame.Width(), &minHeight, &maxHeight, &preferredHeight); frame.bottom = frame.top + max_c(frame.Height(), minHeight); maxSize.height = minHeight; } frame = AlignInFrame(frame, maxSize, alignment); view->MoveTo(frame.LeftTop()); view->ResizeTo(frame.Size()); }
void PictureView::Draw(BRect updateRect) { BRect rect = Bounds(); // Draw the outer frame rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); if (IsFocus() && Window() && Window()->IsActive()) SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); else SetHighColor(tint_color(base, B_DARKEN_3_TINT)); StrokeRect(rect); if (fFocusChanging) { // focus frame is already redraw, stop here return; } BBitmap* picture = fPicture ? fPicture : fDefaultPicture; if (picture != NULL) { // scale to fit and center picture in frame BRect frame = rect.InsetByCopy(kPictureMargin, kPictureMargin); BRect srcRect = picture->Bounds(); BSize size = frame.Size(); if (srcRect.Width() > srcRect.Height()) size.height = srcRect.Height() * size.width / srcRect.Width(); else size.width = srcRect.Width() * size.height / srcRect.Height(); fPictureRect = BLayoutUtils::AlignInFrame(frame, size, BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); SetDrawingMode(B_OP_ALPHA); if (picture == fDefaultPicture) { SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); SetHighColor(0, 0, 0, 24); } DrawBitmapAsync(picture, srcRect, fPictureRect, B_FILTER_BITMAP_BILINEAR); SetDrawingMode(B_OP_OVER); } }
void MainWindow::MessageReceived(BMessage* message) { switch (message->what) { case MSG_LAUNCH: { BView* pointer; if (message->FindPointer("be:source", (void**)&pointer) < B_OK) break; LaunchButton* button = dynamic_cast<LaunchButton*>(pointer); if (button == NULL) break; BString errorMessage; bool launchedByRef = false; if (button->Ref()) { BEntry entry(button->Ref(), true); if (entry.IsDirectory()) { // open in Tracker BMessenger messenger("application/x-vnd.Be-TRAK"); if (messenger.IsValid()) { BMessage trackerMessage(B_REFS_RECEIVED); trackerMessage.AddRef("refs", button->Ref()); status_t ret = messenger.SendMessage(&trackerMessage); if (ret < B_OK) { errorMessage = B_TRANSLATE("Failed to send " "'open folder' command to Tracker.\n\nError: "); errorMessage << strerror(ret); } else launchedByRef = true; } else errorMessage = ("Failed to open folder - is Tracker " "running?"); } else { status_t ret = be_roster->Launch(button->Ref()); if (ret < B_OK && ret != B_ALREADY_RUNNING) { BString errStr(B_TRANSLATE("Failed to launch '%1'.\n" "\nError:")); BPath path(button->Ref()); if (path.InitCheck() >= B_OK) errStr.ReplaceFirst("%1", path.Path()); else errStr.ReplaceFirst("%1", button->Ref()->name); errorMessage << errStr.String() << " "; errorMessage << strerror(ret); } else launchedByRef = true; } } if (!launchedByRef && button->AppSignature()) { status_t ret = be_roster->Launch(button->AppSignature()); if (ret != B_OK && ret != B_ALREADY_RUNNING) { BString errStr(B_TRANSLATE("\n\nFailed to launch application " "with signature '%2'.\n\nError:")); errStr.ReplaceFirst("%2", button->AppSignature()); errorMessage << errStr.String() << " "; errorMessage << strerror(ret); } else { // clear error message on success (might have been // filled when trying to launch by ref) errorMessage = ""; } } else if (!launchedByRef) { errorMessage = B_TRANSLATE("Failed to launch 'something', " "error in Pad data."); } if (errorMessage.Length() > 0) { BAlert* alert = new BAlert("error", errorMessage.String(), B_TRANSLATE("Bummer"), NULL, NULL, B_WIDTH_FROM_WIDEST); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(NULL); } break; } case MSG_ADD_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { fPadView->AddButton(new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH)), button); } break; } case MSG_CLEAR_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) button->SetTo((entry_ref*)NULL); break; } case MSG_REMOVE_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { if (fPadView->RemoveButton(button)) delete button; } break; } case MSG_SET_DESCRIPTION: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { const char* name; if (message->FindString("name", &name) >= B_OK) { // message comes from a previous name panel button->SetDescription(name); BRect namePanelFrame; if (message->FindRect("frame", &namePanelFrame) == B_OK) { ((App*)be_app)->SetNamePanelSize( namePanelFrame.Size()); } } else { // message comes from pad view entry_ref* ref = button->Ref(); if (ref) { BString helper(B_TRANSLATE("Description for '%3'")); helper.ReplaceFirst("%3", ref->name); // Place the name panel besides the pad, but give it // the user configured size. BPoint origin = B_ORIGIN; BSize size = ((App*)be_app)->NamePanelSize(); NamePanel* panel = new NamePanel(helper.String(), button->Description(), this, this, new BMessage(*message), size); panel->Layout(true); size = panel->Frame().Size(); BScreen screen(this); BPoint mousePos; uint32 buttons; fPadView->GetMouse(&mousePos, &buttons, false); fPadView->ConvertToScreen(&mousePos); if (fPadView->Orientation() == B_HORIZONTAL) { // Place above or below the pad origin.x = mousePos.x - size.width / 2; if (screen.Frame().bottom - Frame().bottom > size.height + 20) { origin.y = Frame().bottom + 10; } else { origin.y = Frame().top - 10 - size.height; } } else { // Place left or right of the pad origin.y = mousePos.y - size.height / 2; if (screen.Frame().right - Frame().right > size.width + 20) { origin.x = Frame().right + 10; } else { origin.x = Frame().left - 10 - size.width; } } panel->MoveTo(origin); panel->Show(); } } } break; } case MSG_ADD_WINDOW: { BMessage settings('sett'); SaveSettings(&settings); message->AddMessage("window", &settings); be_app->PostMessage(message); break; } case MSG_SHOW_BORDER: SetLook(B_TITLED_WINDOW_LOOK); break; case MSG_HIDE_BORDER: SetLook(B_BORDERED_WINDOW_LOOK); break; case MSG_TOGGLE_AUTORAISE: ToggleAutoRaise(); break; case MSG_SHOW_ON_ALL_WORKSPACES: fShowOnAllWorkspaces = !fShowOnAllWorkspaces; if (fShowOnAllWorkspaces) SetWorkspaces(B_ALL_WORKSPACES); else SetWorkspaces(1L << current_workspace()); break; case B_SIMPLE_DATA: case B_REFS_RECEIVED: case B_PASTE: case B_MODIFIERS_CHANGED: break; default: BWindow::MessageReceived(message); break; } }
void TFilePanel::Init(const BMessage*) { BRect windRect(Bounds()); fBackView = new BView(Bounds(), "View", B_FOLLOW_ALL, 0); fBackView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); AddChild(fBackView); // add poseview menu bar fMenuBar = new BMenuBar(BRect(0, 0, windRect.Width(), 1), "MenuBar"); fMenuBar->SetBorder(B_BORDER_FRAME); fBackView->AddChild(fMenuBar); // add directory menu and menufield fDirMenu = new BDirMenu(0, this, kSwitchDirectory, "refs"); font_height ht; be_plain_font->GetHeight(&ht); float f_height = ht.ascent + ht.descent + ht.leading; BRect rect; rect.top = fMenuBar->Bounds().Height() + 8; rect.left = windRect.left + 8; rect.right = rect.left + 300; rect.bottom = rect.top + (f_height > 22 ? f_height : 22); fDirMenuField = new BMenuField(rect, "DirMenuField", "", fDirMenu); fDirMenuField->MenuBar()->SetFont(be_plain_font); fDirMenuField->SetDivider(0); fDirMenuField->MenuBar()->SetMaxContentWidth(rect.Width() - 26.0f); // Make room for the icon fDirMenuField->MenuBar()->RemoveItem((int32)0); fDirMenu->SetMenuBar(fDirMenuField->MenuBar()); // the above is a weird call from BDirMenu // ToDo: clean up BEntry entry(TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK) fDirMenu->Populate(&entry, 0, true, true, false, true); else fDirMenu->Populate(0, 0, true, true, false, true); fBackView->AddChild(fDirMenuField); // add file name text view if (fIsSavePanel) { BRect rect(windRect); rect.top = rect.bottom - 35; rect.left = 8; rect.right = rect.left + 170; rect.bottom = rect.top + 13; fTextControl = new BTextControl(rect, "text view", B_TRANSLATE("save text"), "", NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); DisallowMetaKeys(fTextControl->TextView()); DisallowFilenameKeys(fTextControl->TextView()); fBackView->AddChild(fTextControl); fTextControl->SetDivider(0.0f); fTextControl->TextView()->SetMaxBytes(B_FILE_NAME_LENGTH - 1); fButtonText.SetTo(B_TRANSLATE("Save")); } else fButtonText.SetTo(B_TRANSLATE("Open")); // Add PoseView fBorderedView->SetName("PoseView"); fBorderedView->SetResizingMode(B_FOLLOW_ALL); fBorderedView->EnableBorderHighlight(true); rect = windRect; rect.OffsetTo(10, fDirMenuField->Frame().bottom + 10); rect.bottom = windRect.bottom - 60; rect.right -= B_V_SCROLL_BAR_WIDTH + 20; fBorderedView->MoveTo(rect.LeftTop()); fBorderedView->ResizeTo(rect.Width(), rect.Height()); PoseView()->AddScrollBars(); PoseView()->SetDragEnabled(false); PoseView()->SetDropEnabled(false); PoseView()->SetSelectionHandler(this); PoseView()->SetSelectionChangedHook(true); PoseView()->DisableSaveLocation(); // horizontal rect = fBorderedView->Frame(); rect.top = rect.bottom; rect.bottom = rect.top + (float)B_H_SCROLL_BAR_HEIGHT; PoseView()->HScrollBar()->MoveTo(rect.LeftTop()); PoseView()->HScrollBar()->ResizeTo(rect.Size()); PoseView()->HScrollBar()->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM); fBackView->AddChild(PoseView()->HScrollBar()); // vertical rect = fBorderedView->Frame(); rect.left = rect.right; rect.right = rect.left + (float)B_V_SCROLL_BAR_WIDTH; PoseView()->VScrollBar()->MoveTo(rect.LeftTop()); PoseView()->VScrollBar()->ResizeTo(rect.Size()); PoseView()->VScrollBar()->SetResizingMode(B_FOLLOW_TOP_BOTTOM | B_FOLLOW_RIGHT); fBackView->AddChild(PoseView()->VScrollBar()); if (fIsSavePanel) fBackView->AddChild(fBorderedView, fTextControl); else fBackView->AddChild(fBorderedView); AddShortcut('W', B_COMMAND_KEY, new BMessage(kCancelButton)); AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome)); AddShortcut('A', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kShowSelectionWindow)); AddShortcut('A', B_COMMAND_KEY, new BMessage(B_SELECT_ALL), PoseView()); AddShortcut('S', B_COMMAND_KEY, new BMessage(kInvertSelection), PoseView()); AddShortcut('Y', B_COMMAND_KEY, new BMessage(kResizeToFit), PoseView()); AddShortcut(B_DOWN_ARROW, B_COMMAND_KEY, new BMessage(kOpenDir)); AddShortcut(B_DOWN_ARROW, B_COMMAND_KEY | B_OPTION_KEY, new BMessage(kOpenDir)); AddShortcut(B_UP_ARROW, B_COMMAND_KEY, new BMessage(kOpenParentDir)); AddShortcut(B_UP_ARROW, B_COMMAND_KEY | B_OPTION_KEY, new BMessage(kOpenParentDir)); // New code to make buttons font sensitive rect = windRect; rect.top = rect.bottom - 35; rect.bottom -= 10; rect.right -= 25; float default_width = be_plain_font->StringWidth(fButtonText.String()) + 20; rect.left = default_width > 75 ? rect.right - default_width : rect.right - 75; BButton* default_button = new BButton(rect, "default button", fButtonText.String(), new BMessage(kDefaultButton), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); fBackView->AddChild(default_button); rect.right = rect.left -= 10; float cancel_width = be_plain_font->StringWidth(B_TRANSLATE("Cancel")) + 20; rect.left = cancel_width > 75 ? rect.right - cancel_width : rect.right - 75; BButton* cancel_button = new BButton(rect, "cancel button", B_TRANSLATE("Cancel"), new BMessage(kCancelButton), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); fBackView->AddChild(cancel_button); if (!fIsSavePanel) default_button->SetEnabled(false); default_button->MakeDefault(true); RestoreState(); AddMenus(); AddContextMenus(); FavoritesMenu* favorites = new FavoritesMenu(B_TRANSLATE("Favorites"), new BMessage(kSwitchDirectory), new BMessage(B_REFS_RECEIVED), BMessenger(this), IsSavePanel(), fPoseView->RefFilter()); favorites->AddItem(new BMenuItem(B_TRANSLATE("Add current folder"), new BMessage(kAddCurrentDir))); favorites->AddItem(new BMenuItem( B_TRANSLATE("Edit favorites" B_UTF8_ELLIPSIS), new BMessage(kEditFavorites))); fMenuBar->AddItem(favorites); // configure menus BMenuItem* item = fMenuBar->FindItem(B_TRANSLATE("Window")); if (item) { fMenuBar->RemoveItem(item); delete item; } item = fMenuBar->FindItem(B_TRANSLATE("File")); if (item) { BMenu* menu = item->Submenu(); if (menu) { item = menu->FindItem(kOpenSelection); if (item && menu->RemoveItem(item)) delete item; item = menu->FindItem(kDuplicateSelection); if (item && menu->RemoveItem(item)) delete item; // remove add-ons menu, identifier menu, separator item = menu->FindItem(B_TRANSLATE("Add-ons")); if (item) { int32 index = menu->IndexOf(item); delete menu->RemoveItem(index); delete menu->RemoveItem(--index); delete menu->RemoveItem(--index); } // remove separator item = menu->FindItem(B_CUT); if (item) { item = menu->ItemAt(menu->IndexOf(item)-1); if (item && menu->RemoveItem(item)) delete item; } } } PoseView()->ScrollTo(B_ORIGIN); PoseView()->UpdateScrollRange(); PoseView()->ScrollTo(B_ORIGIN); if (fTextControl) { fTextControl->MakeFocus(); fTextControl->TextView()->SelectAll(); } else PoseView()->MakeFocus(); app_info info; BString title; if (be_app->GetAppInfo(&info) == B_OK) { if (!gLocalizedNamePreferred || BLocaleRoster::Default()->GetLocalizedFileName( title, info.ref, false) != B_OK) title = info.ref.name; title << ": "; } title << fButtonText; // Open or Save SetTitle(title.String()); SetSizeLimits(370, 10000, 200, 10000); }