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); }
void AttachedToWindow() { if (Parent()) { SetViewColor(Parent()->ViewColor()); SetHighColor(Parent()->HighColor()); SetLowColor (Parent()->LowColor() ); } BRect rect; rect = Bounds(); rect.bottom = rect.top + B_H_SCROLL_BAR_HEIGHT - 1; mTotalCount_->ResizeTo(rect.Width(), rect.Height()); mTotalCount_->MoveTo(rect.left, rect.top); rect = Bounds(); rect.top = rect.top + B_H_SCROLL_BAR_HEIGHT; mMarkedCount_->ResizeTo(rect.Width(), rect.Height()); mMarkedCount_->MoveTo(rect.left, rect.top); }
void MonthWindowView::AttachedToWindow(void) { SetFont(be_plain_font); SetViewColor(VIEW_COLOR); // Calculate size of cell needed for number of day of month font_height h; be_plain_font->GetHeight(&h); h_cell=(int)(h.ascent+h.descent+h.leading+6); w_cell=StringWidth("4")*4; #ifdef __LANG_RUSSIAN BString s(""); s<<tday; s.Append(" "); switch(tmonth) { case 1: { s.Append("января "); break; } case 2: { s.Append("февраля "); break; } case 3: { s.Append("марта "); break; } case 4: { s.Append("апреля "); break; } case 5: { s.Append("мая "); break; } case 6: { s.Append("июня "); break; } case 7: { s.Append("июля "); break; } case 8: { s.Append("августа "); break; } case 9: { s.Append("сентября "); break; } case 10: { s.Append("октября "); break; } case 11: { s.Append("ноября "); break; } case 12: { s.Append("декабря "); break; } } s<<tyear; s.Append(" г."); #else // localized, english and french BString s(""); s<<tday; s.Append(" "); s.Append(monthNames[tmonth-1]); s.Append(" "); s<<tyear; #endif msng=new BMessenger(this); todayStringView=new MouseSenseStringView(new BMessage('TODA'), msng, BRect(10,10,100,100),"todayMStringViewAViX", s.String()); AddChild(todayStringView); todayStringView->ResizeToPreferred(); todayStringView->SetViewColor(VIEW_COLOR); monthStringView=new BStringView(BRect(10,10,100,100),"monthStringViewAViX", monthNames[8]); monthStringView->SetAlignment(B_ALIGN_CENTER); AddChild(monthStringView); monthStringView->ResizeToPreferred(); monthStringView->SetText(monthNames[cmonth-1]); monthStringView->SetViewColor(VIEW_COLOR); s.SetTo(""); if(cyear<10) s.Append("000"); else if(cyear<100) s.Append("00"); else if(cyear<1000) s.Append("0"); s<<cyear; yearStringView=new BStringView(BRect(10,10,100,100),"yearStringViewAViX", "0000"); AddChild(yearStringView); yearStringView->ResizeToPreferred(); yearStringView->SetText(s.String()); yearStringView->SetViewColor(VIEW_COLOR); ResizeTo(w_cell*7+1,h_cell*7+3+16+yearStringView->Bounds().bottom+todayStringView->Bounds().bottom); Window()->ResizeTo(Bounds().right, Bounds().bottom); yearMStringView[0]=new MouseSenseStringView(new BMessage('YEA0'),msng, BRect(10,10,100,100), "yearMStringViewAViX0", "<<"); AddChild(yearMStringView[0]); yearMStringView[0]->ResizeToPreferred(); yearMStringView[0]->SetViewColor(VIEW_COLOR); yearMStringView[1]=new MouseSenseStringView(new BMessage('YEA1'),msng, BRect(10,10,100,100), "yearMStringViewAViX1", ">>"); AddChild(yearMStringView[1]); yearMStringView[1]->ResizeToPreferred(); yearMStringView[1]->SetViewColor(VIEW_COLOR); monthMStringView[0]=new MouseSenseStringView(new BMessage('MON0'),msng, BRect(10,10,100,100), "monthMStringViewAViX0", "<<"); AddChild(monthMStringView[0]); monthMStringView[0]->ResizeToPreferred(); monthMStringView[0]->SetViewColor(VIEW_COLOR); monthMStringView[1]=new MouseSenseStringView(new BMessage('MON1'),msng, BRect(10,10,100,100), "monthMStringViewAViX1", ">>"); AddChild(monthMStringView[1]); monthMStringView[1]->ResizeToPreferred(); monthMStringView[1]->SetViewColor(VIEW_COLOR); todayStringView->MoveTo((Bounds().right-todayStringView->Bounds().right)/2, Bounds().bottom-todayStringView->Bounds().bottom-2); if(tyear<first_year || tyear>last_year) todayStringView->SetHighColor(NOACTIVE_COLOR); yearMStringView[1]->MoveTo(Bounds().right-yearMStringView[1]->Bounds().right,5); yearStringView->MoveTo(yearMStringView[1]->Frame().left-yearStringView->Bounds().right,5); yearMStringView[0]->MoveTo(yearStringView->Frame().left-yearMStringView[0]->Bounds().right,5); monthStringView->MoveTo((yearMStringView[0]->Frame().left-monthStringView->Bounds().right)/2,5); monthMStringView[0]->MoveTo(monthStringView->Frame().left-monthMStringView[0]->Bounds().right,5); monthMStringView[1]->MoveTo(monthStringView->Frame().right,5); which_focused=2; // days of month Bmp=new BBitmap(BRect(Frame()),B_RGB32,true); BmpView=new BView(Bmp->Bounds(),"BV",0,B_WILL_DRAW); Bmp->AddChild(BmpView); Bmp->Lock(); BmpView->SetHighColor(VIEW_COLOR); BmpView->FillRect(BmpView->Frame()); BmpView->SetHighColor(LINE_COLOR); BmpView->StrokeLine(BPoint(3,todayStringView->Frame().top-5), BPoint(Bounds().right-3,todayStringView->Frame().top-5)); BmpView->StrokeLine(BPoint(3,yearStringView->Frame().bottom+2), BPoint(Bounds().right-3,yearStringView->Frame().bottom+2)); BmpView->SetHighColor(0,0,0,0); float y=yearStringView->Frame().bottom+h_cell; float x=0; for(int i=0;i<7;i++) { BmpView->DrawString(weekdayNames[i],BPoint(x+(w_cell-StringWidth(weekdayNames[i]))/2,y)); x+=w_cell; } BmpView->Sync(); Bmp->Unlock(); DrawMonth(); }
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 }
//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 ImageView::_UpdateImage() { // ToDo: add scroller if necessary?! BAutolock locker(fEditor); // we need all the data... size_t viewSize = fEditor.ViewSize(); // that may need some more memory... if ((off_t)viewSize < fEditor.FileSize()) fEditor.SetViewSize(fEditor.FileSize()); const char *data; if (fEditor.GetViewBuffer((const uint8 **)&data) != B_OK) { fEditor.SetViewSize(viewSize); return; } if (fBitmap != NULL && (fEditor.Type() == B_MINI_ICON_TYPE || fEditor.Type() == B_LARGE_ICON_TYPE)) { // optimize icon update... fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8); fEditor.SetViewSize(viewSize); return; } #ifdef HAIKU_TARGET_PLATFORM_HAIKU if (fBitmap != NULL && fEditor.Type() == B_VECTOR_ICON_TYPE && fScaleSlider->Value() * 8 - 1 == fBitmap->Bounds().Width()) { if (BIconUtils::GetVectorIcon((const uint8 *)data, (size_t)fEditor.FileSize(), fBitmap) == B_OK) { fEditor.SetViewSize(viewSize); return; } } #endif delete fBitmap; fBitmap = NULL; switch (fEditor.Type()) { case B_MINI_ICON_TYPE: fBitmap = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8); if (fBitmap->InitCheck() == B_OK) fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8); break; case B_LARGE_ICON_TYPE: fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8); if (fBitmap->InitCheck() == B_OK) fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8); break; #ifdef HAIKU_TARGET_PLATFORM_HAIKU case B_VECTOR_ICON_TYPE: fBitmap = new BBitmap(BRect(0, 0, fScaleSlider->Value() * 8 - 1, fScaleSlider->Value() * 8 - 1), B_RGB32); if (fBitmap->InitCheck() != B_OK || BIconUtils::GetVectorIcon((const uint8 *)data, (size_t)fEditor.FileSize(), fBitmap) != B_OK) { delete fBitmap; fBitmap = NULL; } break; #endif case B_PNG_FORMAT: { BMemoryIO stream(data, fEditor.FileSize()); fBitmap = BTranslationUtils::GetBitmap(&stream); break; } case B_MESSAGE_TYPE: { BMessage message; // ToDo: this could be problematic if the data is not large // enough to contain the message... if (message.Unflatten(data) == B_OK) fBitmap = new BBitmap(&message); break; } } // Update the bitmap description. If no image can be displayed, // we will show our "unsupported" message if (fBitmap != NULL && fBitmap->InitCheck() != B_OK) { delete fBitmap; fBitmap = NULL; } if (fBitmap != NULL) { char buffer[256]; const char *type = B_TRANSLATE("Unknown type"); switch (fEditor.Type()) { case B_MINI_ICON_TYPE: case B_LARGE_ICON_TYPE: #ifdef HAIKU_TARGET_PLATFORM_HAIKU case B_VECTOR_ICON_TYPE: #endif type = B_TRANSLATE("Icon"); break; case B_PNG_FORMAT: type = B_TRANSLATE("PNG format"); break; case B_MESSAGE_TYPE: type = B_TRANSLATE("Flattened bitmap"); break; default: break; } const char *colorSpace; switch (fBitmap->ColorSpace()) { case B_GRAY1: case B_GRAY8: colorSpace = B_TRANSLATE("Grayscale"); break; case B_CMAP8: colorSpace = B_TRANSLATE("8 bit palette"); break; case B_RGB32: case B_RGBA32: case B_RGB32_BIG: case B_RGBA32_BIG: colorSpace = B_TRANSLATE("32 bit"); break; case B_RGB15: case B_RGBA15: case B_RGB15_BIG: case B_RGBA15_BIG: colorSpace = B_TRANSLATE("15 bit"); break; case B_RGB16: case B_RGB16_BIG: colorSpace = B_TRANSLATE("16 bit"); break; default: colorSpace = B_TRANSLATE("Unknown format"); break; } snprintf(buffer, sizeof(buffer), "%s, %g x %g, %s", type, fBitmap->Bounds().Width() + 1, fBitmap->Bounds().Height() + 1, colorSpace); fDescriptionView->SetText(buffer); } else fDescriptionView->SetText(B_TRANSLATE_COMMENT("Could not read image", "Image means here a picture file, not a disk image.")); // Update the view size to match the image and its description float width, height; fDescriptionView->GetPreferredSize(&width, &height); fDescriptionView->ResizeTo(width, height); BRect rect = fDescriptionView->Bounds(); if (fBitmap != NULL) { BRect bounds = fBitmap->Bounds(); rect.bottom += bounds.Height() + 5; if (fScaleSlider != NULL && rect.Width() < fScaleSlider->Bounds().Width()) rect.right = fScaleSlider->Bounds().right; if (bounds.Width() > rect.Width()) rect.right = bounds.right; // center description below the bitmap fDescriptionView->MoveTo((rect.Width() - fDescriptionView->Bounds().Width()) / 2, bounds.Height() + 5); if (fScaleSlider != NULL) { // center slider below description rect.bottom += fScaleSlider->Bounds().Height() + 5; fScaleSlider->MoveTo((rect.Width() - fScaleSlider->Bounds().Width()) / 2, fDescriptionView->Frame().bottom + 5); if (fScaleSlider->IsHidden()) fScaleSlider->Show(); } } else if (fScaleSlider != NULL && !fScaleSlider->IsHidden()) fScaleSlider->Hide(); ResizeTo(rect.Width(), rect.Height()); if (Parent()) { // center within parent view BRect parentBounds = Parent()->Bounds(); MoveTo((parentBounds.Width() - rect.Width()) / 2, (parentBounds.Height() - rect.Height()) / 2); } Invalidate(); // restore old view size fEditor.SetViewSize(viewSize); }
RecipeEditor::RecipeEditor(const BRect &frame, const BMessenger &msgr, const int32 &number, const char *category) : BWindow(frame,"Add Recipe",B_FLOATING_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS), fMessenger(msgr), fNumber(number), fCategory(category) { AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddShortcut('Q', B_COMMAND_KEY, new BMessage(M_QUIT_APP)); BView *back = new BView(Bounds(),"back",B_FOLLOW_ALL, B_WILL_DRAW); back->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(back); fCategories = new BMenu("Categories"); CppSQLite3Query query = DBQuery("select category from categories order by category;", "RecipeEditor:get categories"); while(!query.eof()) { BString cat(DeescapeIllegalCharacters(query.getStringField(0))); BMessage *menumsg = new BMessage(M_CATEGORY_CHANGED); menumsg->AddString("name",cat); fCategories->AddItem(new BMenuItem(cat.String(),menumsg)); query.nextRow(); } fCategories->SetRadioMode(true); fCategories->SetLabelFromMarked(true); if(fCategories->CountItems()>0) fCategories->ItemAt(0)->SetMarked(true); BRect r(10,10,10 + fCategories->MaxContentWidth(),11); BMenuField *field = new BMenuField(r,"field","Category",fCategories, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP); back->AddChild(field); field->ResizeToPreferred(); r = field->Frame(); if(category) { BMenuItem *marked = fCategories->FindItem(category); if(marked) marked->SetMarked(true); } else { BMenuItem *marked = fCategories->ItemAt(0L); if(marked) marked->SetMarked(true); } r.OffsetBy(0,r.Height() + 10); fNameBox = new AutoTextControl(r,"namebox","Name: ",NULL,NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW | B_PULSE_NEEDED | B_NAVIGABLE | B_NAVIGABLE_JUMP); fNameBox->SetEscapeCancel(true); fNameBox->SetDivider(be_plain_font->StringWidth("Name ") + 5); back->AddChild(fNameBox); fNameBox->ResizeToPreferred(); r = fNameBox->Frame(); r.right = Bounds().right - 10; fNameBox->ResizeTo(r.Width(), r.Height()); r.OffsetBy(0,r.Height() + 10); BStringView *label = new BStringView(r,"inglabel","Ingredients:"); back->AddChild(label); r.OffsetBy(0,r.Height() + 10); r.bottom = r.top + 100; r.right -= B_V_SCROLL_BAR_WIDTH; BRect textrect = r.OffsetToCopy(0,0); textrect.InsetBy(10,10); fIngredientBox = new BTextView(r, "ingredients", textrect, B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED | B_NAVIGABLE | B_NAVIGABLE_JUMP); fIngredientBox->SetDoesUndo(true); BScrollView *ingredscroll = new BScrollView("ingredients_scroller",fIngredientBox, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,0,false, true); back->AddChild(ingredscroll); r = ingredscroll->Frame(); label = new BStringView(BRect(10,10,11,11),"dirlabel","Directions:"); label->ResizeToPreferred(); label->MoveTo(10, r.bottom + 10); back->AddChild(label); r.OffsetBy(0,r.Height() + 20 + label->Frame().Height()); r.right -= B_V_SCROLL_BAR_WIDTH; textrect = r.OffsetToCopy(0,0); textrect.InsetBy(10,10); fDirectionsBox = new BTextView(r, "directions", textrect, B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED | B_NAVIGABLE | B_NAVIGABLE_JUMP); fDirectionsBox->SetDoesUndo(true); BScrollView *dirscroll = new BScrollView("directions_scroller",fDirectionsBox, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,0,false, true); back->AddChild(dirscroll); fOK = new BButton(BRect(10,10,11,11),"ok","Cancel", new BMessage(M_ADD_RECIPE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW); fOK->ResizeToPreferred(); fOK->SetLabel("OK"); fOK->MoveTo(Bounds().right - fOK->Bounds().Width() - 10, Bounds().bottom - fOK->Bounds().Height() - 10); r = fOK->Frame(); back->AddChild(fOK); r.OffsetBy(-r.Width() - 10, 0); fCancel = new BButton(r,"cancel","Cancel",new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW); back->AddChild(fCancel); field->MakeFocus(true); ResizeTo(Bounds().Width(), fDirectionsBox->Parent()->Frame().bottom + 20 + fOK->Bounds().Height()); dirscroll->SetResizingMode(B_FOLLOW_ALL); // This is the part that's different for editing a recipe as opposed to // just adding one to the database if(number >= 0 && category) { SetTitle("Edit Recipe"); BString name, ingredients, directions; if(GetRecipe(number,category,name,ingredients,directions)) { BMenuItem *item = fCategories->FindItem(category); if(item) item->SetMarked(true); fNameBox->SetText(name.String()); fIngredientBox->SetText(ingredients.String()); fDirectionsBox->SetText(directions.String()); fOK->SetMessage(new BMessage(M_EDIT_RECIPE)); } } AddShortcut(B_ENTER, B_COMMAND_KEY, new BMessage(fOK->Command())); }