void TSignatureView::AttachedToWindow() { BRect rect = Bounds(); float name_text_length = StringWidth(kNameText); float sig_text_length = StringWidth(kSigText); float divide_length; if (name_text_length > sig_text_length) divide_length = name_text_length; else divide_length = sig_text_length; rect.InsetBy(8,0); rect.top+= 8; fName = new TNameControl(rect, kNameText, new BMessage(NAME_FIELD)); AddChild(fName); fName->SetDivider(divide_length + 10); fName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); rect.OffsetBy(0,fName->Bounds().Height()+5); rect.bottom = rect.top + kSigHeight; rect.left = fName->TextView()->Frame().left; BRect text = rect; text.OffsetTo(10,0); fTextView = new TSigTextView(rect, text); BScrollView *scroller = new BScrollView("SigScroller", fTextView, B_FOLLOW_ALL, 0, false, true); AddChild(scroller); scroller->ResizeBy(-1 * scroller->ScrollBar(B_VERTICAL)->Frame().Width() - 9, 0); scroller->MoveBy(7,0); /* back up a bit to make room for the label */ rect = scroller->Frame(); BStringView *stringView = new BStringView(rect, "SigLabel", kSigText); AddChild(stringView); float tWidth, tHeight; stringView->GetPreferredSize(&tWidth, &tHeight); /* the 5 is for the spacer in the TextView */ rect.OffsetBy(-1 *(tWidth) - 5, 0); rect.right = rect.left + tWidth; rect.bottom = rect.top + tHeight; stringView->MoveTo(rect.LeftTop()); stringView->ResizeTo(rect.Width(), rect.Height()); /* Resize the View to the correct height */ scroller->SetResizingMode(B_FOLLOW_NONE); ResizeTo(Frame().Width(), scroller->Frame().bottom + 8); scroller->SetResizingMode(B_FOLLOW_ALL); }
ShortcutsWindow::ShortcutsWindow() : BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Shortcuts"), B_TITLED_WINDOW, 0L), fSavePanel(NULL), fOpenPanel(NULL), fSelectPanel(NULL), fKeySetModified(false), fLastOpenWasAppend(false) { ShortcutsSpec::InitializeMetaMaps(); float spacing = be_control_look->DefaultItemSpacing(); BView* top = new BView(Bounds(), NULL, B_FOLLOW_ALL_SIDES, 0); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(top); BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "Menu Bar"); BMenu* fileMenu = new BMenu(B_TRANSLATE("File")); fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Open KeySet" B_UTF8_ELLIPSIS), new BMessage(OPEN_KEYSET), 'O')); fileMenu->AddItem(new BMenuItem( B_TRANSLATE("Append KeySet" B_UTF8_ELLIPSIS), new BMessage(APPEND_KEYSET), 'A')); fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Revert to saved"), new BMessage(REVERT_KEYSET), 'A')); fileMenu->AddItem(new BSeparatorItem); fileMenu->AddItem(new BMenuItem( B_TRANSLATE("Save KeySet as" B_UTF8_ELLIPSIS), new BMessage(SAVE_KEYSET_AS), 'S')); fileMenu->AddItem(new BSeparatorItem); fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q')); menuBar->AddItem(fileMenu); top->AddChild(menuBar); BRect tableBounds = Bounds(); tableBounds.top = menuBar->Bounds().bottom + 1; tableBounds.right -= B_V_SCROLL_BAR_WIDTH; tableBounds.bottom -= B_H_SCROLL_BAR_HEIGHT; BScrollView* containerView; fColumnListView = new ColumnListView(tableBounds, &containerView, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE, B_SINGLE_SELECTION_LIST, true, true, true, B_NO_BORDER); fColumnListView->SetEditMessage(new BMessage(HOTKEY_ITEM_MODIFIED), BMessenger(this)); float minListWidth = 0; // A running total is kept as the columns are created. float cellWidth = be_plain_font->StringWidth("Either") + 20; // ShortcutsSpec does not seem to translate the string "Either". for (int i = 0; i < ShortcutsSpec::NUM_META_COLUMNS; i++) { const char* name = ShortcutsSpec::GetColumnName(i); float headerWidth = be_plain_font->StringWidth(name) + 20; float width = max_c(headerWidth, cellWidth); minListWidth += width + 1; fColumnListView->AddColumn( new CLVColumn(name, CreateMetaPopUp(i), width, CLV_SORT_KEYABLE)); } float keyCellWidth = be_plain_font->StringWidth("Caps Lock") + 20; fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Key"), CreateKeysPopUp(), keyCellWidth, CLV_SORT_KEYABLE)); minListWidth += keyCellWidth + 1; BPopUpMenu* popup = new BPopUpMenu(NULL, false); popup->AddItem(new BMenuItem( B_TRANSLATE("(Choose application with file requester)"), NULL)); popup->AddItem(new BMenuItem( B_TRANSLATE("*InsertString \"Your Text Here\""), NULL)); popup->AddItem(new BMenuItem( B_TRANSLATE("*MoveMouse +20 +0"), NULL)); popup->AddItem(new BMenuItem(B_TRANSLATE("*MoveMouseTo 50% 50%"), NULL)); popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseButton 1"), NULL)); popup->AddItem(new BMenuItem( B_TRANSLATE("*LaunchHandler text/html"), NULL)); popup->AddItem(new BMenuItem( B_TRANSLATE("*Multi \"*MoveMouseTo 100% 0\" \"*MouseButton 1\""), NULL)); popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseDown"), NULL)); popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseUp"), NULL)); popup->AddItem(new BMenuItem( B_TRANSLATE("*SendMessage application/x-vnd.Be-TRAK 'Tfnd'"), NULL)); popup->AddItem(new BMenuItem(B_TRANSLATE("*Beep"), NULL)); fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Application"), popup, 323.0, CLV_SORT_KEYABLE)); minListWidth += 323.0 + 1; minListWidth += B_V_SCROLL_BAR_WIDTH; fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare); top->AddChild(containerView); fColumnListView->SetSelectionMessage(new BMessage(HOTKEY_ITEM_SELECTED)); fColumnListView->SetTarget(this); fAddButton = new BButton(BRect(0, 0, 0, 0), "add", B_TRANSLATE("Add new shortcut"), new BMessage(ADD_HOTKEY_ITEM), B_FOLLOW_BOTTOM); fAddButton->ResizeToPreferred(); fAddButton->MoveBy(spacing, Bounds().bottom - fAddButton->Bounds().bottom - spacing); top->AddChild(fAddButton); fRemoveButton = new BButton(BRect(0, 0, 0, 0), "remove", B_TRANSLATE("Remove selected shortcut"), new BMessage(REMOVE_HOTKEY_ITEM), B_FOLLOW_BOTTOM); fRemoveButton->ResizeToPreferred(); fRemoveButton->MoveBy(fAddButton->Frame().right + spacing, Bounds().bottom - fRemoveButton->Bounds().bottom - spacing); top->AddChild(fRemoveButton); fRemoveButton->SetEnabled(false); fSaveButton = new BButton(BRect(0, 0, 0, 0), "save", B_TRANSLATE("Save & apply"), new BMessage(SAVE_KEYSET), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT); fSaveButton->ResizeToPreferred(); fSaveButton->MoveBy(Bounds().right - fSaveButton->Bounds().right - spacing, Bounds().bottom - fSaveButton->Bounds().bottom - spacing); top->AddChild(fSaveButton); fSaveButton->SetEnabled(false); containerView->ResizeBy(0, -(fAddButton->Bounds().bottom + 2 * spacing + 2)); float minButtonBarWidth = fRemoveButton->Frame().right + fSaveButton->Bounds().right + 2 * spacing; float minWidth = max_c(minListWidth, minButtonBarWidth); float menuBarHeight = menuBar->Bounds().bottom; float buttonBarHeight = Bounds().bottom - containerView->Frame().bottom; float minHeight = menuBarHeight + 200 + buttonBarHeight; SetSizeLimits(minWidth, MAX_WIDTH, minHeight, MAX_HEIGHT); // SetSizeLimits() will resize the window to the minimum size. CenterOnScreen(); entry_ref windowSettingsRef; if (_GetWindowSettingsFile(&windowSettingsRef)) { // The window settings file is not accepted via B_REFS_RECEIVED; this // is a behind-the-scenes file that the user will never see or // interact with. BFile windowSettingsFile(&windowSettingsRef, B_READ_ONLY); BMessage loadMsg; if (loadMsg.Unflatten(&windowSettingsFile) == B_OK) _LoadWindowSettings(loadMsg); } entry_ref keySetRef; if (_GetSettingsFile(&keySetRef)) { BMessage msg(B_REFS_RECEIVED); msg.AddRef("refs", &keySetRef); msg.AddString("startupRef", "please"); PostMessage(&msg); // Tell ourselves to load this file if it exists. } Show(); }