BView* SeqPrefWin::NewEditView(BRect bounds, const BMessage& prefs) { BView* v = new BView(bounds, EDIT_STR, B_FOLLOW_ALL, 0); if (!v) return v; v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); const char* label = "Undo history:"; float top = INDENT; float fh = view_font_height(v); float ih = Prefs().Size(INT_CTRL_Y); float max = (fh > ih) ? fh : ih; BRect r(INDENT, top, INDENT + v->StringWidth(label), top + max); BStringView* sv = new BStringView(r, "undolevellabel", label); if (sv) v->AddChild(sv); r.left = r.right + LABEL_PAD; r.right = r.left + v->StringWidth("999") + 5; mUndoLevelCtrl = new ArpIntControl( r, UNDO_LEVEL_INT, NULL, new BMessage(CHANGE_UNDO_HISTORY_MSG) ); if (mUndoLevelCtrl) { mUndoLevelCtrl->SetLimits(0, UNDO_HISTORY_MAX); int32 level; if (prefs.FindInt32(UNDO_HISTORY_PREF, &level) != B_OK) level = AM_DEFAULT_UNDO_HISTORY; if (level < 0 || level > UNDO_HISTORY_MAX) level = AM_DEFAULT_UNDO_HISTORY; mUndoLevelCtrl->SetValue(level); v->AddChild(mUndoLevelCtrl); } return v; }
BView* SeqEditMultiFilterWindow::NewGeneralView(BRect frame) { BView* v = new BView(frame, GENERAL_STR, B_FOLLOW_ALL, 0); if (!v) return NULL; v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); float fh = arp_get_font_height(v); float spaceX = 5, spaceY = 5; float divider = v->StringWidth("Author:") + 10; BRect f(spaceX, 0, frame.Width() - spaceX, fh); /* The Name field. */ mNameCtrl = new BTextControl(f, "name_ctrl", "Name:", NULL, new BMessage(NAME_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); if (mNameCtrl) { f.top = mNameCtrl->Frame().bottom; mNameCtrl->SetDivider(divider); mNameCtrl->MakeFocus(true); v->AddChild(mNameCtrl); } /* The Key field. */ f.top += spaceY; f.bottom = f.top + fh; mKeyCtrl = new BTextControl(f, "key_ctrl", "Key:", NULL, new BMessage(KEY_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); if (mKeyCtrl) { f.top = mKeyCtrl->Frame().bottom; mKeyCtrl->SetDivider(divider); v->AddChild(mKeyCtrl); } /* The Author field. */ f.top += spaceY; f.bottom = f.top + fh; mAuthorCtrl = new BTextControl(f, "author_ctrl", "Author:", NULL, new BMessage(AUTHOR_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); if (mAuthorCtrl) { f.top = mAuthorCtrl->Frame().bottom; mAuthorCtrl->SetDivider(divider); v->AddChild(mAuthorCtrl); } /* The Email field. */ f.top += spaceY; f.bottom = f.top + fh; mEmailCtrl = new BTextControl(f, "email_ctrl", "Email:", NULL, new BMessage(EMAIL_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); if (mEmailCtrl) { f.top = mEmailCtrl->Frame().bottom; mEmailCtrl->SetDivider(divider); v->AddChild(mEmailCtrl); } return v; }
ColorPicker::ColorPicker(BLooper * target) : BWindow(BRect(50, 75, 100 + (CP_COL_WIDTH * 32), 120 + (CP_COL_WIDTH * 8)), str(STR_SET_COLORS), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE), _target(target), _whichColor(0) { const float margin = 5.0f; const float topRowHeight = 25.0f; _colControl = new BColorControl(BPoint(margin, margin+topRowHeight+margin), B_CELLS_32x8, CP_COL_WIDTH, "color_picker", new BMessage(CP_COL_UPDATE)); ResizeTo(_colControl->Frame().right+margin, _colControl->Frame().bottom+margin); BView * view = new BView(Bounds(), NULL, B_FOLLOW_ALL, 0); AddChild(view); view->SetViewColor(BeBackgroundGrey); const BRect & bounds = view->Bounds(); float revertWidth = view->StringWidth(str(STR_REVERT))+10.0f; BRect revertBounds(bounds.right-(revertWidth+margin), margin, bounds.right-margin, margin+topRowHeight); view->AddChild(_revert = new BButton(revertBounds, NULL, str(STR_REVERT), new BMessage(CP_BUTTON_REVERT))); float defaultWidth = view->StringWidth(str(STR_DEFAULT))+10.0f; BRect defaultBounds(revertBounds.left-(margin+defaultWidth), revertBounds.top, revertBounds.left-margin, revertBounds.bottom); view->AddChild(_default = new BButton(defaultBounds, NULL, str(STR_DEFAULT), new BMessage(CP_BUTTON_DEFAULT))); view->AddChild(_sampleView = new BView(BRect(margin, margin, margin+topRowHeight, margin+topRowHeight), NULL, B_FOLLOW_TOP|B_FOLLOW_LEFT, B_WILL_DRAW)); _colorMenu = new BMenu(""); _colorMenu->SetLabelFromMarked(true); for (int i=0; i<NUM_COLORS; i++) { BMessage * msg = new BMessage(CP_SELECTION_CHANGED); msg->AddInt32("which", i); BMenuItem * mi = new BMenuItem(str(STR_COLOR_BG+i), msg); _colorMenu->AddItem(mi); if (i==0) mi->SetMarked(true); } view->AddChild(new BMenuField(BRect(margin+topRowHeight+margin, margin, revertBounds.left-margin, revertBounds.bottom), NULL, NULL, _colorMenu)); view->AddChild(_colControl); BMessage initMsg(CP_INIT); PostMessage(&initMsg); }
void CounterView::FrameResized (float width, float height) { BRect BitmapRect (0, 0, width, height); char TempString [40]; m_BndRect = Bounds (); m_MovingDotSize = (int) (height / 20); if (m_MovingDotSize < 1) m_MovingDotSize = 1; m_MoveSpeed = m_MovingDotSize / 2.0; // Resize the offscreen bitmap and its view. if (m_BackingBitmap != NULL) { m_BackingBitmap->RemoveChild (&m_BackingView); delete m_BackingBitmap; m_BackingBitmap = NULL; } m_BackingView.ResizeTo (width, height); m_BackingBitmap = new BBitmap (BitmapRect, B_RGBA32, true /* Accepts subviews */); if (!m_BackingBitmap->IsValid ()) { delete m_BackingBitmap; m_BackingBitmap = NULL; } else { m_BackingBitmap->AddChild (&m_BackingView); m_BackingBitmap->Lock (); m_BackingView.SetDrawingMode (B_OP_ALPHA); m_BackingView.SetFontSize (height * 0.8); sprintf (TempString, "%d", m_CurrentCount); m_TextStartPoint.x = width / 2 - m_BackingView.StringWidth (TempString) / 2; m_TextStartPoint.y = height / 2 + height * 0.25; m_BackingBitmap->Unlock (); } }
BView* SeqEditMultiFilterWindow::NewPipelineView(BRect frame) { BView* v = new BView(frame, PIPELINE_STR, B_FOLLOW_ALL, 0); if (!v) return NULL; v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); float x = 5, y = 5; const char* addL = "Add"; const char* deleteL = "Delete"; float buttonW = v->StringWidth(deleteL) + 30, buttonH = 24; /* Lay out the views. */ BRect addF(x, 0, x + buttonW, buttonH); BRect deleteF(addF.right + x, addF.top, addF.right + x + buttonW, addF.bottom); float sbW = Prefs().Size(V_SCROLLBAR_X) + 3, sbH = Prefs().Size(H_SCROLLBAR_Y) + 3; BRect pipelineF(x, addF.bottom + y, frame.Width() - sbW, frame.Height() - sbH); /* Create and add the views. */ BButton* button = new BButton(addF, "add_btn", addL, new BMessage(ADD_PIPELINE_MSG), B_FOLLOW_LEFT | B_FOLLOW_TOP); if (button) v->AddChild(button); button = new BButton(deleteF, "del_btn", deleteL, new BMessage(DELETE_PIPELINE_MSG), B_FOLLOW_LEFT | B_FOLLOW_TOP); if (button) v->AddChild(button); mPipelineView = new SeqPipelineMatrixView( pipelineF, "pipeline_matrix", AmPipelineMatrixRef(mMultiFilter), NULLINPUTOUTPUT_PIPELINE, SEQ_SUPPRESS_BACKGROUND); if (mPipelineView) { mPipelineView->SetResizingMode(B_FOLLOW_ALL); mPipelineView->SetShowProperties(true); mPipelineView->ForceViewColor( tint_color(Prefs().Color(AM_AUX_WINDOW_BG_C), B_DARKEN_1_TINT) ); mPipelineScrollView = new BScrollView("pipeline_scroll", mPipelineView, B_FOLLOW_ALL, 0, true, true); if (mPipelineScrollView) { v->AddChild(mPipelineScrollView); mPipelineScrollView->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); } else v->AddChild(mPipelineView); } return v; }
ConfigWindow::ConfigWindow() : BWindow(BRect(100.0, 100.0, 580.0, 540.0), "E-mail", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE), fLastSelectedAccount(NULL), fSaveSettings(false) { // create controls BRect rect(Bounds()); BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(top); // determine font height font_height fontHeight; top->GetFontHeight(&fontHeight); int32 height = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 5; rect.InsetBy(5, 5); rect.bottom -= 11 + height; BTabView *tabView = new BTabView(rect, NULL); BView *view; rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new BView(rect, NULL, B_FOLLOW_ALL, 0)); tabView->TabAt(0)->SetLabel(B_TRANSLATE("Accounts")); view->SetViewColor(top->ViewColor()); // accounts listview rect = view->Bounds().InsetByCopy(8, 8); rect.right = 140 - B_V_SCROLL_BAR_WIDTH; rect.bottom -= height + 12; fAccountsListView = new AccountsListView(rect); view->AddChild(new BScrollView(NULL, fAccountsListView, B_FOLLOW_ALL, 0, false, true)); rect.right += B_V_SCROLL_BAR_WIDTH; rect.top = rect.bottom + 8; rect.bottom = rect.top + height; BRect sizeRect = rect; sizeRect.right = sizeRect.left + 30 + view->StringWidth( B_TRANSLATE("Add")); view->AddChild(new BButton(sizeRect, NULL, B_TRANSLATE("Add"), new BMessage(kMsgAddAccount), B_FOLLOW_BOTTOM)); sizeRect.left = sizeRect.right+3; sizeRect.right = sizeRect.left + 30 + view->StringWidth( B_TRANSLATE("Remove")); view->AddChild(fRemoveButton = new BButton( sizeRect, NULL, B_TRANSLATE("Remove"), new BMessage(kMsgRemoveAccount), B_FOLLOW_BOTTOM)); // accounts config view rect = view->Bounds(); rect.left = fAccountsListView->Frame().right + B_V_SCROLL_BAR_WIDTH + 16; rect.right -= 10; view->AddChild(fConfigView = new CenterContainer(rect)); MakeHowToView(); // general settings rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new CenterContainer(rect)); tabView->TabAt(1)->SetLabel(B_TRANSLATE("Settings")); rect = view->Bounds().InsetByCopy(8, 8); rect.right -= 1; rect.bottom = rect.top + height * 5 + 15; BBox *box = new BBox(rect); box->SetLabel(B_TRANSLATE("Mail checking")); view->AddChild(box); rect = box->Bounds().InsetByCopy(8, 8); rect.top += 7; rect.bottom = rect.top + height + 5; BRect tile = rect.OffsetByCopy(0, 1); int32 labelWidth = (int32)view->StringWidth(B_TRANSLATE("Check every")) + 6; tile.right = 80 + labelWidth; fIntervalControl = new BTextControl(tile, "time", B_TRANSLATE("Check every"), NULL, NULL); fIntervalControl->SetDivider(labelWidth); box->AddChild(fIntervalControl); BPopUpMenu *frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *frequencyStrings[] = { B_TRANSLATE("never"), B_TRANSLATE("minutes"), B_TRANSLATE("hours"), B_TRANSLATE("days") }; BMenuItem *item; for (int32 i = 0; i < 4; i++) { frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i], new BMessage(kMsgIntervalUnitChanged))); if (i == 1) item->SetMarked(true); } tile.left = tile.right + 5; tile.right = rect.right; tile.OffsetBy(0,-1); fIntervalUnitField = new BMenuField(tile, "frequency", B_EMPTY_STRING, frequencyPopUp); fIntervalUnitField->SetDivider(0.0); box->AddChild(fIntervalUnitField); rect.OffsetBy(0,height + 9); rect.bottom -= 2; fPPPActiveCheckBox = new BCheckBox(rect, "ppp active", B_TRANSLATE("Only when dial-up is connected"), NULL); box->AddChild(fPPPActiveCheckBox); rect.OffsetBy(0,height + 9); rect.bottom -= 2; fPPPActiveSendCheckBox = new BCheckBox(rect, "ppp activesend", B_TRANSLATE("Schedule outgoing mail when dial-up is disconnected"), NULL); box->AddChild(fPPPActiveSendCheckBox); // Miscellaneous settings box rect = box->Frame(); rect.bottom = rect.top + 3 * height + 30; box = new BBox(rect); box->SetLabel(B_TRANSLATE("Miscellaneous")); view->AddChild(box); BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *statusModes[] = { B_TRANSLATE("Never"), B_TRANSLATE("While sending"), B_TRANSLATE("While sending and receiving"), B_TRANSLATE("Always") }; BMessage *msg; for (int32 i = 0; i < 4; i++) { statusPopUp->AddItem(item = new BMenuItem(statusModes[i], msg = new BMessage(kMsgShowStatusWindowChanged))); msg->AddInt32("ShowStatusWindow", i); if (i == 0) item->SetMarked(true); } rect = box->Bounds().InsetByCopy(8,8); rect.top += 7; rect.bottom = rect.top + height + 5; labelWidth = (int32)view->StringWidth( B_TRANSLATE("Show connection status window:")) + 8; fStatusModeField = new BMenuField(rect, "show status", B_TRANSLATE("Show connection status window:"), statusPopUp); fStatusModeField->SetDivider(labelWidth); box->AddChild(fStatusModeField); rect = fStatusModeField->Frame();; rect.OffsetBy(0, rect.Height() + 10); BButton *button = new BButton(rect, B_EMPTY_STRING, B_TRANSLATE("Edit mailbox menu…"), msg = new BMessage(B_REFS_RECEIVED)); button->ResizeToPreferred(); box->AddChild(button); button->SetTarget(BMessenger("application/x-vnd.Be-TRAK")); BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/Menu Links"); BEntry entry(path.Path()); if (entry.InitCheck() == B_OK && entry.Exists()) { entry_ref ref; entry.GetRef(&ref); msg->AddRef("refs", &ref); } else button->SetEnabled(false); rect = button->Frame(); rect.OffsetBy(rect.Width() + 30,0); fAutoStartCheckBox = new BCheckBox(rect, "start daemon", B_TRANSLATE("Start mail services on startup"), NULL); fAutoStartCheckBox->ResizeToPreferred(); box->AddChild(fAutoStartCheckBox); // save/revert buttons top->AddChild(tabView); rect = tabView->Frame(); rect.top = rect.bottom + 5; rect.bottom = rect.top + height + 5; BButton *saveButton = new BButton(rect, "apply", B_TRANSLATE("Apply"), new BMessage(kMsgSaveSettings)); float w,h; saveButton->GetPreferredSize(&w, &h); saveButton->ResizeTo(w, h); saveButton->MoveTo(rect.right - w, rect.top); top->AddChild(saveButton); BButton *revertButton = new BButton(rect, "revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevertSettings)); revertButton->GetPreferredSize(&w, &h); revertButton->ResizeTo(w,h); revertButton->MoveTo(saveButton->Frame().left - 25 - w, rect.top); top->AddChild(revertButton); LoadSettings(); // this will also move our window to the stored position fAccountsListView->SetSelectionMessage(new BMessage(kMsgAccountSelected)); fAccountsListView->MakeFocus(true); }
// MouseMoved void ObjectView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) { // BRect dirty(where, where); // dirty.InsetBy(-10, -10); // Invalidate(dirty); if (dragMessage) { //printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y); //Window()->CurrentMessage()->PrintToStream(); } else { //printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f))\n", where.x, where.y); } if (fScrolling) { BCursor cursor(kGrabCursor); SetViewCursor(&cursor); BPoint offset = fLastMousePos - where; ScrollBy(offset.x, offset.y); fLastMousePos = where + offset; } else if (fInitiatingDrag) { BPoint offset = fLastMousePos - where; if (sqrtf(offset.x * offset.x + offset.y * offset.y) > 5.0) { BMessage newDragMessage('drag'); BBitmap* dragBitmap = new BBitmap(BRect(0, 0, 40, 40), B_RGBA32, true); if (dragBitmap->Lock()) { BView* helper = new BView(dragBitmap->Bounds(), "offscreen view", B_FOLLOW_ALL, B_WILL_DRAW); dragBitmap->AddChild(helper); helper->SetDrawingMode(B_OP_ALPHA); helper->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE); BRect r(helper->Bounds()); helper->SetHighColor(0, 0, 0, 128); helper->StrokeRect(r); helper->SetHighColor(200, 200, 200, 100); r.InsetBy(1, 1); helper->FillRect(r); helper->SetHighColor(0, 0, 0, 255); const char* text = B_TRANSLATE("Test"); float pos = (r.Width() - helper->StringWidth(text)) / 2; helper->DrawString(text, BPoint(pos, 25)); helper->Sync(); } DragMessage(&newDragMessage, dragBitmap, B_OP_ALPHA, B_ORIGIN, this); fInitiatingDrag = false; } } else { BCursor cursor(kMoveCursor); SetViewCursor(&cursor); if (fState && fState->IsTracking()) { BRect before = fState->Bounds(); fState->MouseMoved(where); BRect after = fState->Bounds(); BRect invalid(before | after); Invalidate(invalid); } } // SetViewCursor(); }
_OwqWindow(BMessenger target, const BMessage* prefs = 0) : BWindow( BRect(100, 100, 300, 300), "Open From Query", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE), mTarget(target), mFilePanel(0), mOnBox(0), mNameCtrl(0), mFileButton(0), mSkipBox(0), mRef(0) { BRect b = Bounds(); BView* v = new BView( b, "bg", B_FOLLOW_ALL, 0 ); float bottom = b.bottom; if (v) { v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); float cbH = check_box_height( v ); BRect f(5, 5, b.right - 5, 5 + cbH); mOnBox = new BCheckBox( f, "on_box", "On", new BMessage( OWQ_ON_MSG ) ); if( mOnBox ) { mOnBox->SetValue( B_CONTROL_ON ); v->AddChild( mOnBox ); } f.OffsetBy( 0, f.Height() + 10 ); f.bottom = f.top + text_control_height( v ); mNameCtrl = new BTextControl( f, "name_ctrl", "Name: ", "", new BMessage( OWQ_NAME_MSG ) ); if( mNameCtrl ) { mNameCtrl->SetDivider( v->StringWidth( "Name:" ) + 10 ); v->AddChild( mNameCtrl ); } f.OffsetBy( 0, f.Height() + 10 ); f.bottom = f.top + button_height( v ); mFileButton = new BButton( f, "file_ctrl", "Choose Query", new BMessage( OWQ_CHOOSE_FILE_MSG ) ); if( mFileButton ) v->AddChild( mFileButton ); /* I've turned off skip for now -- I think just having it on * is easier than explaining it. */ #if 0 f.OffsetBy( 0, f.Height() + 5 ); f.bottom = f.top + cbH; mSkipBox = new BCheckBox( f, "skip_box", "Skip top level", new BMessage( OWQ_SKIP_MSG ) ); if( mSkipBox ) v->AddChild( mSkipBox ); #endif f.top = f.bottom + 10; f.bottom = f.top + button_height( v ); float buttonW = 60; f.left = f.right - buttonW; BButton* button = new BButton( f, "ok_button", "OK", new BMessage( OK_MSG ) ); if( button ) { v->AddChild( button ); button->MakeDefault( true ); } f.OffsetBy( 0-(buttonW + 10), 0 ); button = new BButton( f, "cancel_button", "Cancel", new BMessage( CANCEL_MSG ) ); if( button ) v->AddChild( button ); bottom = f.bottom + 5; AddChild( v ); } ResizeTo( b.Width(), bottom ); if( prefs ) SetPrefs( prefs ); bool enable = false; if( mOnBox && mOnBox->Value() == B_CONTROL_ON ) enable = true; SetControlEnable(enable); }
BView* SeqPrefWin::NewTrackView(BRect bounds, const BMessage& prefs) { BView* v = new BView(bounds, TRACK_STR, B_FOLLOW_ALL, 0); if (!v) return v; v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); float fh = view_font_height(v); /* The Track windows follow playback position preference. */ const char* str = "Track windows follow playback position"; float w = v->StringWidth(str) + 25; BRect f(bounds.left + 5, bounds.top + 5, bounds.left + 5 + w, bounds.top + 5 + fh); mTrackWinFollowCtrl = new BCheckBox( f, TRACK_WIN_FOLLOW_STR, str, new BMessage(TRACK_WIN_FOLLOW_MSG) ); if (mTrackWinFollowCtrl) { bool b; if (prefs.FindBool(TRACK_WIN_FOLLOW_PREF, &b) != B_OK) b = false; mTrackWinFollowCtrl->SetValue( (b) ? B_CONTROL_ON : B_CONTROL_OFF ); v->AddChild(mTrackWinFollowCtrl); f.top = mTrackWinFollowCtrl->Frame().bottom + 5; } /* The Track windows play to end of song preference. */ str = "Track windows play to end of song"; w = v->StringWidth(str) + 25; f.bottom = f.top + Prefs().Size(INT_CTRL_Y); f.right = f.left + w; mTrackWinPlayToEndCtrl = new BCheckBox(f, TRACK_WIN_PLAY_TO_END_STR, str, new BMessage(TRACK_WIN_PLAY_TO_END_MSG) ); if (mTrackWinPlayToEndCtrl) { bool b; if (prefs.FindBool(TRACK_WIN_PLAY_TO_END_PREF, &b) != B_OK) b = false; mTrackWinPlayToEndCtrl->SetValue( (b) ? B_CONTROL_ON : B_CONTROL_OFF ); v->AddChild(mTrackWinPlayToEndCtrl); f.top = mTrackWinPlayToEndCtrl->Frame().bottom + 5; } /* The Initial track height preference. */ const char* label = "Initial track height:"; float divider = v->StringWidth(label) + 5; f.bottom = f.top + Prefs().Size(INT_CTRL_Y); f.right = f.left + divider + v->StringWidth("200") + 10; mTrackHeightCtrl = new ArpIntControl(f, "track_height_ctrl", label, new BMessage(TRACK_HEIGHT_MSG) ); if (mTrackHeightCtrl) { mTrackHeightCtrl->SetLimits(AM_DEFAULT_TRACK_HEIGHT, 199); int32 level; if (prefs.FindInt32(TRACK_HEIGHT_PREF, &level) != B_OK) level = AM_DEFAULT_TRACK_HEIGHT; if (level < AM_DEFAULT_TRACK_HEIGHT || level > 199) level = AM_DEFAULT_TRACK_HEIGHT; mTrackHeightCtrl->SetValue(level); mTrackHeightCtrl->SetFormatter(new _UpOneFormat() ); mTrackHeightCtrl->SetDivider(divider); v->AddChild(mTrackHeightCtrl); } /* The Track label height preference. */ label = "Track label height:"; f.top = f.bottom + 5; f.bottom = f.top + Prefs().Size(INT_CTRL_Y); mLabelHeightCtrl = new ArpIntControl(f, "label_height_ctrl", label, new BMessage(LABEL_HEIGHT_MSG) ); if (mLabelHeightCtrl) { mLabelHeightCtrl->SetLimits(6, 50); int32 level; if (prefs.FindInt32(PHRASE_LABEL_HEIGHT_PREF, &level) != B_OK) level = 8; if (level < 6 || level > 50) level = 8; mLabelHeightCtrl->SetValue(level); mLabelHeightCtrl->SetDivider(divider); v->AddChild(mLabelHeightCtrl); } return v; }
BView* SeqPrefWin::NewFileView(BRect bounds, const BMessage& prefs) const { BView* v = new BView( bounds, FILE_STR, B_FOLLOW_ALL, 0 ); if( !v ) return v; v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); float fh = view_font_height(v); float bfh = bold_font_height(); float openH = bfh + 5 + fh + 5 + fh + 5 + fh; /* The Remember Open Songs preference. */ float w = v->StringWidth("Remember open songs") + 25; BRect f(bounds.left + 5, bounds.top + 5, bounds.left + 5 + w, bounds.top + 5 + fh); BCheckBox* cb = new BCheckBox( f, REMEMBER_OPEN_STR, "Remember open songs", new BMessage(REMEMBER_OPEN_MSG) ); if( cb ) { bool b; if( prefs.FindBool(REMEBER_OPEN_SONGS_PREF, &b) != B_OK ) b = false; cb->SetValue( (b) ? B_CONTROL_ON : B_CONTROL_OFF ); v->AddChild( cb ); } /* The Skin preference. */ BMenu* menu = new BMenu("skin_menu"); BMessage skinMsg(CHANGE_SKIN_MSG); BMenuItem* item = new BMenuItem( "Default", new BMessage(CHANGE_SKIN_TO_DEFAULT_MSG) ); item->SetMarked(true); menu->AddItem(item); menu->AddSeparatorItem(); menu->SetLabelFromMarked(true); if( seq_make_skin_menu(menu, &skinMsg) == B_OK ) { const char* label = "Choose skin:"; f.Set(f.left, f.bottom + 8, bounds.right - 5, f.bottom + 8 + fh + 10); BMenuField* field = new BMenuField(f, "skin_field", label, menu); if (field) { field->SetDivider( v->StringWidth(label) + 10 ); v->AddChild(field); } else delete menu; } else delete menu; /* The Open New Songs preferences. */ f.Set(bounds.left + 5, f.bottom + 10, bounds.right - 5, f.bottom + 10 + openH + 10); BBox* box = new BBox( f, "open_new_songs", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); if( box ) { box->SetLabel( "Open New Songs" ); BRect boxB = box->Bounds(); BRect sf(boxB.left + 5, boxB.top + 5 + bfh, boxB.right - 5, boxB.top + 5 + bfh + fh); const char* choice; if( prefs.FindString(OPEN_NEW_SONG_PREF, &choice) != B_OK ) choice = 0; BRadioButton* button = new BRadioButton( sf, OPEN_BLANK_STR, "Blank", new BMessage(OPEN_BLANK_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); if( button ) { if( choice && strcmp(choice, "blank") == 0 ) button->SetValue( B_CONTROL_ON ); box->AddChild( button ); } sf.OffsetBy( 0, 5 + fh ); button = new BRadioButton( sf, OPEN_FOUR_STR, "With two channels of each device", new BMessage(OPEN_FOUR_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); if( button ) { if( choice && strcmp(choice, "channels") == 0 ) button->SetValue( B_CONTROL_ON ); box->AddChild( button ); } sf.OffsetBy( 0, 5 + fh ); button = new BRadioButton( sf, OPEN_FILE_STR, "From file: <click to select>", new BMessage(OPEN_FILE_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); if( button ) { if( choice && strcmp(choice, "file") == 0 ) button->SetValue( B_CONTROL_ON ); entry_ref ref; if( prefs.FindRef(OPEN_NEW_SONG_FILE_PREF, &ref) == B_OK ) button->SetLabel( label_for_open_new_from_file(&ref).String() ); box->AddChild( button ); } v->AddChild( box ); f.OffsetBy(0, f.bottom - f.top + 10 ); } /* The Open From Query preferences */ f.bottom = bounds.bottom - 27; box = new BBox( f, "open_from_query", B_FOLLOW_ALL); if( box ) { box->SetLabel("Open From Query"); BRect boxB = box->Bounds(); BRect tableF(boxB.left + 5, boxB.top + 5 + bfh, boxB.right - 5, boxB.bottom - 35); mOwqTable = new _OwqList( tableF, mPreferences ); if( mOwqTable ) { mOwqTable->SetLatchWidth( 0 ); box->AddChild( mOwqTable ); mOwqTable->AddColumn( new BStringColumn(ON_STR, 40, 20, 100, B_TRUNCATE_END), 0 ); mOwqTable->AddColumn( new BStringColumn(NAME_STR, 100, 20, 150, B_TRUNCATE_END), 1 ); mOwqTable->AddColumn( new BStringColumn(QUERY_STR, 180, 20, 450, B_TRUNCATE_MIDDLE), 2 ); // mOwqTable->AddColumn( new BStringColumn(SKIP_TOP_LEVEL_STR, 100, 20, 250, B_TRUNCATE_END), 3 ); mOwqTable->SetSortColumn(mOwqTable->ColumnAt(1), false, true); // mOwqTable->SetSortColumn(mOwqTable->ColumnAt(), true, true); mOwqTable->SetSelectionMode( B_SINGLE_SELECTION_LIST ); BRect bF(tableF.left, tableF.bottom + 5, tableF.left + 55, tableF.Height() - 10); BButton* add = new BButton( bF, "owq_add", "Add", new BMessage(OWQ_INVOKE_ADD), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM ); if( add ) box->AddChild( add ); bF.OffsetBy( bF.Width() + 5, 0 ); BButton* change = new BButton( bF, "owq_change", "Change", new BMessage(OWQ_CHANGE), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM ); if( change ) { change->SetEnabled( false ); box->AddChild( change ); } bF.OffsetBy( bF.Width() + 5, 0 ); BButton* remove = new BButton( bF, "owq_remove", "Remove", new BMessage(OWQ_REMOVE), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM ); if( remove ) { remove->SetEnabled( false ); box->AddChild( remove ); } mOwqTable->SetButtons( add, change, remove ); } v->AddChild( box ); } return v; }
float PBox::BuildGUI(BMessage viewTemplate, BMessage settings, BView *view) { BMessage curr; float yOffset = kEdgeOffset + kControlOffset; float xOffset = 0; const float kControlWidth = view->Bounds().Width() - (kEdgeOffset * 2); BMessage postAdded; for (int i=0; viewTemplate.FindMessage("setting",i,&curr) == B_OK; i++ ) { char temp[512]; // get text etc from template const char * name = curr.FindString("name"); const char * desc = curr.FindString("description"); const char * value = NULL; int32 type = -1; bool secret = false; bool freeText = true; bool multiLine = false; BView *control = NULL; BMenu *menu = NULL; BMessage* enabling = NULL; if ( name != NULL && strcmp(name,"app_sig") == 0 ) { // skip app-sig setting continue; } if (curr.FindInt32("type", &type) != B_OK) { printf("Error getting type for %s, skipping\n", name); continue; }; switch (type) { case B_STRING_TYPE: { if (curr.FindString("valid_value")) { // It's a "select one of these" setting freeText = false; menu = new BPopUpMenu(name); // menu->SetDivider(be_plain_font->StringWidth(name) + 10); for (int j = 0; curr.FindString("valid_value", j); j++) { menu->AddItem(new BMenuItem(curr.FindString("valid_value", j),NULL)); }; value = NULL; value = curr.FindString("default"); if (value && menu->FindItem(value)) menu->FindItem(value)->SetMarked(true); value = settings.FindString(name); if (value && menu->FindItem(value)) menu->FindItem(value)->SetMarked(true); } else { // It's a free-text setting if (curr.FindBool("multi_line", &multiLine) != B_OK) multiLine = false; value = settings.FindString(name); if (!value) value = curr.FindString("default"); if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; } } break; case B_INT32_TYPE: { if (curr.FindInt32("valid_value")) { // It's a "select one of these" setting freeText = false; menu = new BPopUpMenu(name); int32 v = 0; for ( int j = 0; curr.FindInt32("valid_value",j,&v) == B_OK; j++ ) { sprintf(temp,"%ld", v); menu->AddItem(new BMenuItem(temp, NULL)); }; if ( curr.FindInt32("default",&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; menu->FindItem(value)->SetMarked(true); } if ( settings.FindInt32(name,&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; menu->FindItem(value)->SetMarked(true); } } else { // It's a free-text (but number) setting int32 v = 0; if (settings.FindInt32(name,&v) == B_OK) { sprintf(temp,"%ld",v); value = temp; } else if ( curr.FindInt32("default",&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; } if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; } } break; case B_BOOL_TYPE: { bool active; if (settings.FindBool(name, &active) != B_OK) { if (curr.FindBool("default", &active) != B_OK) { active = false; }; }; for (int j = 0; curr.FindString("enable_control", j); j++) { if(!enabling) enabling = new BMessage('enab'); enabling->AddString("enable_control",curr.FindString("enable_control",j) ); if(!active) postAdded.AddString("disable",curr.FindString("enable_control", j)); }; control = new BCheckBox(BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), enabling); if (active) ((BCheckBox*)control)->SetValue(B_CONTROL_ON); } break; default: { continue; }; }; if (!value) value = ""; if (!control) { if (freeText) { if (multiLine == false) { control = new BTextControl( BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), value, NULL); if (secret) { ((BTextControl *)control)->TextView()->HideTyping(true); ((BTextControl *)control)->SetText(_T(value)); }; ((BTextControl *)control)->SetDivider(kDividerWidth); } else { BRect rect; BRect textRect; if (desc) //andrea: add description only if available. { BRect labelRect(0, 0, kDividerWidth, fFontHeight); BStringView *label = new BStringView(labelRect, "NA", _T(desc), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); view->AddChild(label); label->MoveTo(kEdgeOffset, yOffset); rect = BRect(0, 0, kControlWidth - kDividerWidth, fFontHeight * 4); rect.right -= B_V_SCROLL_BAR_WIDTH + kEdgeOffset + kControlOffset; xOffset = kEdgeOffset + kDividerWidth; } else { rect = BRect(0, 0, kControlWidth, fFontHeight * 4); rect.right -= B_V_SCROLL_BAR_WIDTH + kControlOffset; xOffset = 0; } textRect = rect; textRect.InsetBy(kEdgeOffset, kEdgeOffset); textRect.OffsetTo(1.0, 1.0); BTextView *textView = new BTextView(rect, name, textRect, B_FOLLOW_ALL_SIDES, B_WILL_DRAW); control = new BScrollView("NA", textView, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_NAVIGABLE, false, true); textView->SetText(_T(value)); }; } else { control = new BMenuField(BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), menu); float size=kDividerWidth; if(control->StringWidth(_T(desc)) > kDividerWidth) size=control->StringWidth(_T(desc)) + 20; ((BMenuField *)control)->SetDivider(size); }; }; view->AddChild(control); if(enabling) ((BCheckBox*)control)->SetTarget(this); float h, w = 0; control->GetPreferredSize(&w, &h); if (h < control->Bounds().Height()) h = control->Bounds().Height(); control->MoveTo(kEdgeOffset + xOffset, yOffset); yOffset += kControlOffset + h ; xOffset = 0; }; for (int j = 0; postAdded.FindString("disable", j); j++) { const char* name=postAdded.FindString("disable", j); BView* viewz=view->FindView(name); if(viewz) ((BControl*)viewz)->SetEnabled(false); } //if ( yOffset < view->Bounds().Height() ) // yOffset = view->Bounds().Height(); return yOffset;//view->ResizeTo( view->Bounds().Width(), yOffset }
// This function returns the number of pixels of the text that // were clipped if the text does not fit into the clipping rect. // If the text all fit, it returns 0. int BeOSCanvas::RenderText( int iFontHeight, Rect& oClipRect, string& oText, AlignEnum eAlign, Font* pFont, const Color& oColor, bool bBold, bool bItalic, bool bUnderline ) { Erase( oClipRect ); BView* v = m_pBufferBitmap->OffscreenView(); if ( !v ) return 0; BBitmap* bitmap = m_pBufferBitmap->GetBBitmap(); assert( bitmap ); BFont font; font_height fontHeight; BRect clipRect( float(oClipRect.x1), float(oClipRect.y1), float(oClipRect.x2-1), float(oClipRect.y2-1) ); BRegion clipRegion; clipRegion.Set( clipRect ); if ( !bitmap->Lock() ) { puts( "lock failed" ); return 0; } v->ConstrainClippingRegion( &clipRegion ); v->SetDrawingMode( B_OP_OVER ); if ( bBold ) { v->SetFont( be_bold_font ); } else { v->SetFont( be_plain_font ); } v->SetFontSize( (float)iFontHeight - 1 ); v->GetFont( &font ); font.GetHeight( &fontHeight ); float width = v->StringWidth(oText.c_str(), oText.size()); if(eAlign == eCenter) v->MovePenTo( float(oClipRect.x1) + (float(oClipRect.x2 - oClipRect.x1) - width)/2, float(oClipRect.y2-fontHeight.descent) ); else if (eAlign == eRight) v->MovePenTo( float(oClipRect.x2) - width, float(oClipRect.y2-fontHeight.descent) ); else v->MovePenTo( float(oClipRect.x1), float(oClipRect.y2-fontHeight.descent) ); v->DrawString( oText.c_str() ); v->Sync(); bitmap->Unlock(); Invalidate( oClipRect ); return (width < oClipRect.Width()) ? 0 : int(width - oClipRect.Width()); }
int BeOSCanvas::RenderOffsetText( int iFontHeight, Rect& oClipRect, string& oText, int iOffset, Font* pFont, const Color& oColor, bool bBold, bool bItalic, bool bUnderline ) { Erase( oClipRect ); BView* v = m_pBufferBitmap->OffscreenView(); if ( !v ) return 0; BBitmap* bitmap = m_pBufferBitmap->GetBBitmap(); BFont font; font_height fontHeight; BRect clipRect( float(oClipRect.x1), float(oClipRect.y1), float(oClipRect.x2-1), float(oClipRect.y2-1) ); BRegion clipRegion; clipRegion.Set( clipRect ); if ( !bitmap->Lock() ) { puts( "Lock Failed" ); return 0; } v->ConstrainClippingRegion( &clipRegion ); if ( bBold ) { v->SetFont( be_bold_font ); } else { v->SetFont( be_plain_font ); } v->SetFontSize( (float)iFontHeight - 1 ); v->GetFont( &font ); font.GetHeight( &fontHeight ); float width = v->StringWidth(oText.c_str(), oText.size()); width += iMarqueeSpacer; if ( iOffset > width ) { bitmap->Unlock(); return int( width ) - iOffset; } v->MovePenTo( float(oClipRect.x1 - iOffset), float(oClipRect.y2 - fontHeight.descent) ); v->DrawString( oText.c_str() ); int ret = int( width ) - iOffset - oClipRect.Width(); if ( ret < 0 ) { v->MovePenTo( float(oClipRect.x1 - iOffset + width), float(oClipRect.y2 - fontHeight.descent) ); v->DrawString( oText.c_str() ); } v->Sync(); bitmap->Unlock(); Invalidate( oClipRect ); return MAX( 0, ret ); }