//calculate the view positions of all the MatrixLayoutItems //on the items list with offsets based upon matrixLeft //and matrixTop void LayoutMatrix :: Calc( const float paramMatrixLeft, const float paramMatrixTop, sem_id paramSemID) { int32 numItems = mpItemsList->CountItems(); if (!numItems) return; if (acquire_sem(paramSemID) != B_NO_ERROR) { warning(myPrefs->FailAqSem); return; } bool hasPopUpMenu = false; TextItem * scratchTextItem; for ( int i = 0; i < numItems; i++) { ((LayoutMatrixItem *)(mpItemsList->ItemAt(i)))->Calc(); } float widest = 0; float tallest = 0; int32 index = 0; for ( int i = 0; i < numItems; i++) { LayoutMatrixItem * lmi = (LayoutMatrixItem *)mpItemsList->ItemAt(index++); if (lmi->mfWidthPref > widest) { widest = lmi->mfWidthPref; } if (lmi->mfHeightPref > tallest) { tallest = lmi->mfHeightPref; } } if (mui32Flags & SAMESIZE) {//SAMESIZE makes all items the same size as the largest index = 0; //Resize all items to match largest: for ( uint32 i = 0; i < mui32Rows; i++) { for ( uint32 j = 0; j < mui32Columns; j++) { LayoutMatrixItem * lmi = (LayoutMatrixItem *)mpItemsList->ItemAt(index++); switch (lmi->mui32Kind) { case KIND_MYSPACER: { MySpacer * scratchMySpacer = (MySpacer *)lmi->mpItem; if (scratchMySpacer->mbSAMEFromWidest) { scratchMySpacer->ResizeTo(widest, tallest); } } break; case KIND_MYBUTTON: { BButton * scratchMyButton = (BButton *)lmi->mpItem; scratchMyButton->ResizeTo(widest, tallest); } break; case KIND_MYSLIDER: { BSlider * scratchMySlider = (BSlider *)lmi->mpItem; scratchMySlider->ResizeTo(widest, tallest); } break; case KIND_STRINGDRAWER: { BStringView * scratchMyStringView = (BStringView *)lmi->mpItem; scratchMyStringView->ResizeTo(widest, tallest); } break; case KIND_MYCHECKBOX: { BCheckBox * scratchMyCheckBox = (BCheckBox *)lmi->mpItem; scratchMyCheckBox->ResizeTo(widest, tallest); } break; case KIND_MYPICTUREBUTTON: { BPictureButton * scratchMyPictureButton = (BPictureButton *)lmi->mpItem; scratchMyPictureButton->ResizeTo(widest, tallest); } break; case KIND_MYCOLORCONTROL: { BColorControl * scratchMyColorControl = (BColorControl *)lmi->mpItem; scratchMyColorControl->ResizeTo(widest, tallest); } break; case KIND_MYSTATUSBAR: { BStatusBar * scratchMyStatusBar = (BStatusBar *)lmi->mpItem; scratchMyStatusBar->ResizeTo(widest, tallest); } break; case KIND_UINT32CONTROL: { UInt32Control * scratchUInt32Control = (UInt32Control *)lmi->mpItem; scratchUInt32Control->ResizeTo(widest, tallest); } break; case KIND_FLOATCONTROL: { FloatControl * scratchFloatControl = (FloatControl *)lmi->mpItem; scratchFloatControl->ResizeTo(widest, tallest); } break; case KIND_STRINGCONTROL: { StringControl * scratchStringControl = (StringControl *)lmi->mpItem; scratchStringControl->ResizeTo(widest, tallest); } break; } } } } index = 0; //move every item based upon size and padding: const float hpad = 2;//horizontal spacing between items const float vpad = 2;//vertical spacing between items float localLeft; float localTop = vpad + paramMatrixTop; float excessRight = 0, excessRightHold = 0; float excessBottom = 0, excessBottomHold = 0; for ( uint32 ii = 0; ii < mui32Rows; ii++) { localLeft = paramMatrixLeft + hpad; float columnRight = 0; excessBottom = 0; for ( uint32 jj = 0; jj < mui32Columns; jj++) { excessRight = 0; LayoutMatrixItem * lmi = (LayoutMatrixItem *)mpItemsList->ItemAt(index++); switch (lmi->mui32Kind) { case KIND_MYPOPUPMENU: { hasPopUpMenu = true; MyPopUpMenu * scratchPopUpMenu = (MyPopUpMenu *)lmi->mpItem; scratchPopUpMenu->mfLabelLeft = localLeft; excessRightHold = lmi->mfWidthPref + scratchPopUpMenu->mfLabelWidth; scratchPopUpMenu->SetLeft(localLeft); scratchPopUpMenu->mfLabelTop = localTop; if ((scratchPopUpMenu->mfHeight + 9) > scratchPopUpMenu->mfLabelHeight) { excessBottomHold = scratchPopUpMenu->mfHeight + 10; } else { excessBottomHold = scratchPopUpMenu->mfLabelHeight + 1; } } break; case KIND_MYTEXTVIEW: { BTextView * scratchTextView = (BTextView *)lmi->mpItem; scratchTextView->MoveTo(localLeft, localTop); excessRightHold = ((MyTextView *)scratchTextView)->mfWidth; excessBottomHold = ((MyTextView *)scratchTextView)->mfHeight; } break; case KIND_MYLISTVIEW: { BListView * scratchListView = (BListView *)lmi->mpItem; scratchListView->MoveTo(localLeft, localTop); ((BListView *)(lmi->mpItem))->GetPreferredSize(&excessRightHold, &excessBottomHold); } break; case KIND_MYBUTTON: { BButton * scratchMyButton = (BButton *)lmi->mpItem; scratchMyButton->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_MYSLIDER: { BSlider * scratchMySlider = (BSlider *)lmi->mpItem; scratchMySlider->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_MYSPACER: { MySpacer * scratchMySpacer = (MySpacer *)lmi->mpItem; if ( (mui32Flags & SAMESIZE) && scratchMySpacer->mbSAMEFromWidest) { excessRightHold = widest; excessBottomHold = tallest; } else { excessRightHold = scratchMySpacer->mfPreferredWidth; excessBottomHold = scratchMySpacer->mfPreferredHeight; } } break; case KIND_MYRADIOVIEW: { MyRadioView * scratchRadioView = (MyRadioView *)lmi->mpItem; scratchRadioView->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_STRINGDRAWER: { BStringView * scratchMyStringView = (BStringView *)lmi->mpItem; TextItem * scratchTextItem = ((MyStringDrawer *)lmi->mpItem)->GetTextItem(); scratchTextItem->mfLeft = localLeft; scratchTextItem->mfTop = localTop + lmi->mfHeightPref - ((MyStringDrawer *)lmi->mpItem)->mfDescender - vpad; scratchMyStringView->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_MYCHECKBOX: { BCheckBox * scratchMyCheckBox = (BCheckBox *)lmi->mpItem; scratchMyCheckBox->MoveTo(localLeft, localTop + 1); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref + 1; } break; case KIND_MYPICTUREBUTTON: { BPictureButton * scratchMyPictureButton = (BPictureButton *)lmi->mpItem; scratchMyPictureButton->MoveTo(localLeft, localTop); excessRightHold = scratchMyPictureButton->Bounds().Width() + 1; excessBottomHold = scratchMyPictureButton->Bounds().Height() + 1; } break; case KIND_MYCOLORCONTROL: { BColorControl * scratchMyColorControl = (BColorControl *)lmi->mpItem; scratchMyColorControl->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; ; } break; case KIND_MYSTATUSBAR: { MyStatusBar * scratchMyStatusBar = (MyStatusBar *)lmi->mpItem; scratchMyStatusBar->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_UINT32CONTROL: { UInt32Control * scratchUInt32Control = (UInt32Control *)lmi->mpItem; scratchUInt32Control->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_FLOATCONTROL: { FloatControl * scratchFloatControl = (FloatControl *)lmi->mpItem; scratchFloatControl->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_STRINGCONTROL: { StringControl * scratchStringControl = (StringControl *)lmi->mpItem; scratchStringControl->MoveTo(localLeft, localTop); excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; } break; case KIND_TEXT: scratchTextItem = (TextItem *)lmi->mpItem; scratchTextItem->mfLeft = localLeft; scratchTextItem->mfTop = localTop + lmi->mfHeightPref; excessRightHold = lmi->mfWidthPref; excessBottomHold = lmi->mfHeightPref; break; case KIND_COLORWELL: ((ColorWell *)lmi->mpItem)->mfLabelLeft = localLeft; ((ColorWell *)lmi->mpItem)->SetLeft(((ColorWell *)lmi->mpItem)->GetLeft() + localLeft); excessRightHold = lmi->mfWidthPref; ((ColorWell *)lmi->mpItem)->mfLabelTop = localTop; ((ColorWell *)lmi->mpItem)->SetTop(((ColorWell *)lmi->mpItem)->GetTop() + localTop); excessBottomHold = lmi->mfHeightPref; break; case KIND_INT8GADGET: case KIND_UINT8GADGET: case KIND_INT16GADGET: case KIND_UINT16GADGET: case KIND_INT32GADGET: case KIND_UINT32GADGET: case KIND_INT64GADGET: case KIND_UINT64GADGET: case KIND_FLOATGADGET: case KIND_HEXGADGET: case KIND_STRINGGADGET: ((GadgetBase *)lmi->mpItem)->mfLabelLeft = localLeft; ((GadgetBase *)lmi->mpItem)->SetLeft(((GadgetBase *)lmi->mpItem)->GetLeft() + localLeft); excessRightHold = lmi->mfWidthPref; ((GadgetBase *)lmi->mpItem)->mfLabelTop = localTop; ((GadgetBase *)lmi->mpItem)->SetTop(((GadgetBase *)lmi->mpItem)->GetTop() + localTop); excessBottomHold = lmi->mfHeightPref + 1; break; } if (mui32Flags & SAMESIZE) { excessRightHold = widest; excessBottomHold = tallest; } excessRightHold += hpad; if (excessRightHold > excessRight) { excessRight = excessRightHold; } localLeft += excessRight; if (mui32Columns - 1) { if (jj != (mui32Columns - 1)) { if (localLeft > columnRight) { columnRight = localLeft; } } else { columnRight = localLeft; } } else { if (localLeft > columnRight) { columnRight = localLeft; } } //mfRight is stored so that another MatrixLayout //can know where a previous one ended up if (excessBottomHold > excessBottom) { excessBottom = excessBottomHold; } } if (columnRight > mfRight) { mfRight = columnRight; } excessBottomHold += vpad; localTop += excessBottom; if (mui32Rows - 1) { if (ii != (mui32Rows - 1)) { if (localTop > mfBottom) { mfBottom = localTop; } } else { mfBottom = localTop; } } else { if (localTop > mfBottom) { mfBottom = localTop; } } //mfBottom is stored so that another MatrixLayout //can know where a previous one ended up } if (hasPopUpMenu) { mfRight += 30; } release_sem(paramSemID); }//end
void BTextWidget::StartEdit(BRect bounds, BPoseView *view, BPose *pose) { if (!IsEditable()) return; // don't allow editing of the trash directory name if (pose->TargetModel()->IsTrash()) return; // don't allow editing of the "Disks" icon name if (pose->TargetModel()->IsRoot()) return; BEntry entry(pose->TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK && !ConfirmChangeIfWellKnownDirectory(&entry, "rename")) return; // get bounds with full text length BRect rect(bounds); BRect textRect(bounds); rect.OffsetBy(-2, -1); rect.right += 1; BFont font; view->GetFont(&font); BTextView *textView = new BTextView(rect, "WidgetTextView", textRect, &font, 0, B_FOLLOW_ALL, B_WILL_DRAW); textView->SetWordWrap(false); DisallowMetaKeys(textView); fText->SetUpEditing(textView); textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter)); rect.right = rect.left + textView->LineWidth() + 3; // center new width, if necessary if (view->ViewMode() == kIconMode || (view->ViewMode() == kListMode && fAlignment == B_ALIGN_CENTER)) { rect.OffsetBy(bounds.Width() / 2 - rect.Width() / 2, 0); } rect.bottom = rect.top + textView->LineHeight() + 1; textRect = rect.OffsetToCopy(2, 1); textRect.right -= 3; textRect.bottom--; textView->SetTextRect(textRect); textRect = view->Bounds(); bool hitBorder = false; if (rect.left < 1) rect.left = 1, hitBorder = true; if (rect.right > textRect.right) rect.right = textRect.right - 2, hitBorder = true; textView->MoveTo(rect.LeftTop()); textView->ResizeTo(rect.Width(), rect.Height()); BScrollView *scrollView = new BScrollView("BorderView", textView, 0, 0, false, false, B_PLAIN_BORDER); view->AddChild(scrollView); // configure text view switch (view->ViewMode()) { case kIconMode: textView->SetAlignment(B_ALIGN_CENTER); break; case kMiniIconMode: textView->SetAlignment(B_ALIGN_LEFT); break; case kListMode: textView->SetAlignment(fAlignment); break; } textView->MakeResizable(true, hitBorder ? NULL : scrollView); view->SetActivePose(pose); // tell view about pose SetActive(true); // for widget textView->SelectAll(); textView->MakeFocus(); // make this text widget invisible while we edit it SetVisible(false); ASSERT(view->Window()); // how can I not have a Window here??? if (view->Window()) // force immediate redraw so TextView appears instantly view->Window()->UpdateIfNeeded(); }
void BTextWidget::StartEdit(BRect bounds, BPoseView* view, BPose* pose) { view->SetTextWidgetToCheck(NULL, this); if (!IsEditable() || IsActive()) return; BEntry entry(pose->TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK && !ConfirmChangeIfWellKnownDirectory(&entry, B_TRANSLATE_COMMENT("rename", "As in 'if you rename this folder...' (en) " "'Wird dieser Ordner umbenannt...' (de)"), B_TRANSLATE_COMMENT("rename", "As in 'to rename this folder...' (en) " "'Um diesen Ordner umzubenennen...' (de)"), B_TRANSLATE_COMMENT("Rename", "Button label, 'Rename' (en), 'Umbenennen' (de)"))) return; // get bounds with full text length BRect rect(bounds); BRect textRect(bounds); rect.OffsetBy(-2, -1); rect.right += 1; BFont font; view->GetFont(&font); BTextView* textView = new BTextView(rect, "WidgetTextView", textRect, &font, 0, B_FOLLOW_ALL, B_WILL_DRAW); textView->SetWordWrap(false); DisallowMetaKeys(textView); fText->SetUpEditing(textView); textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter)); rect.right = rect.left + textView->LineWidth() + 3; // center new width, if necessary if (view->ViewMode() == kIconMode || (view->ViewMode() == kListMode && fAlignment == B_ALIGN_CENTER)) { rect.OffsetBy(bounds.Width() / 2 - rect.Width() / 2, 0); } rect.bottom = rect.top + textView->LineHeight() + 1; textRect = rect.OffsetToCopy(2, 1); textRect.right -= 3; textRect.bottom--; textView->SetTextRect(textRect); BPoint origin = view->LeftTop(); textRect = view->Bounds(); bool hitBorder = false; if (rect.left <= origin.x) rect.left = origin.x + 1, hitBorder = true; if (rect.right >= textRect.right) rect.right = textRect.right - 1, hitBorder = true; textView->MoveTo(rect.LeftTop()); textView->ResizeTo(rect.Width(), rect.Height()); BScrollView* scrollView = new BScrollView("BorderView", textView, 0, 0, false, false, B_PLAIN_BORDER); view->AddChild(scrollView); // configure text view switch (view->ViewMode()) { case kIconMode: textView->SetAlignment(B_ALIGN_CENTER); break; case kMiniIconMode: textView->SetAlignment(B_ALIGN_LEFT); break; case kListMode: textView->SetAlignment(fAlignment); break; } textView->MakeResizable(true, hitBorder ? NULL : scrollView); view->SetActivePose(pose); // tell view about pose SetActive(true); // for widget textView->SelectAll(); textView->MakeFocus(); // make this text widget invisible while we edit it SetVisible(false); ASSERT(view->Window() != NULL); // how can I not have a Window here??? if (view->Window()) { // force immediate redraw so TextView appears instantly view->Window()->UpdateIfNeeded(); } }