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 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); }
// -------------------------------------------------- JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) : HWindow(BRect(0, 0, 320, 160), "Job Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE) { fSetupMsg = msg; fExitSem = create_sem(0, "JobSetup"); fResult = B_ERROR; if (printerName) { BString title; title << printerName << " Job Setup"; SetTitle(title.String()); fPrinterName = printerName; } // ---- Ok, build a default job setup user interface BRect r; BBox *panel; BBox *line; BButton *ok; BButton *cancel; BStringView *sv; float x, y, w, h; float indent; int32 copies; int32 firstPage; int32 lastPage; bool allPages; char buffer[80]; // PrinterDriver ensures that property exists fSetupMsg->FindInt32("copies", &copies); fSetupMsg->FindInt32("first_page", &firstPage); fSetupMsg->FindInt32("last_page", &lastPage); BMessage doc_info; if (B_OK != fSetupMsg->FindMessage("doc_info", &doc_info)) { // default fields doc_info.AddString("Author", ""); doc_info.AddString("Subject", ""); doc_info.AddString("Keywords", ""); fSetupMsg->AddMessage("doc_info", &doc_info); } AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys); allPages = firstPage == 1 && lastPage == MAX_INT32; r = Bounds(); // add a *dialog* background panel = new BBox(r, "top_panel", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); const int kMargin = 6; //const char *kCopiesLabel = "Copies:"; const char *kCopiesLabelExtraSpace = "Copies:##"; const char *kPagesRangeLabel = "Pages:"; const char *kAllPagesLabel = "All"; const char *kPagesRangeSelectionLabel = ""; const char *kFromLabel = "From:"; const char *kFromLabelExtraSpace = "From:##"; const char *kToLabel = "To:"; const char *kToLabelExtraSpace = "To:##"; r = panel->Bounds(); x = r.left + kMargin; y = r.top + kMargin; // add a "copies" input field /* Simon: temporarily removed this code sprintf(buffer, "%d", (int)copies); fCopies = new BTextControl(BRect(x, y, x+100, y+20), "copies", kCopiesLabel, buffer, new BMessage(NB_COPIES_MSG)); fCopies->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fCopies->ResizeToPreferred(); fCopies->GetPreferredSize(&w, &h); panel->AddChild(fCopies); y += h + kMargin; // "new line" */ // add a "pages" label sv = new BStringView(BRect(x, y, x+100, y+20), "pages_range", kPagesRangeLabel); panel->AddChild(sv); sv->ResizeToPreferred(); sv->GetPreferredSize(&w, &h); // align "copies" textcontrol field on the "allPages" radiobutton bellow... indent = be_plain_font->StringWidth(kCopiesLabelExtraSpace); w += kMargin; if ( w > indent ) indent = w; // fCopies->SetDivider(indent); x += indent; // add a "all" radiobutton fAll = new BRadioButton(BRect(x, y, x+100, y+20), "all_pages", kAllPagesLabel, new BMessage(ALL_PAGES_MGS)); fAll->ResizeToPreferred(); fAll->GetPreferredSize(&w, &h); fAll->SetValue(allPages); panel->AddChild(fAll); y += h + kMargin; // "new line" // add a range selection raddiobutton fRange = new BRadioButton(BRect(x, y, x+100, y+20), "pages_range_selection", kPagesRangeSelectionLabel, new BMessage(RANGE_SELECTION_MSG)); fRange->ResizeToPreferred(); fRange->GetPreferredSize(&w, &h); fRange->SetValue(!allPages); panel->AddChild(fRange); x += w + kMargin; // add a "from" field if (allPages) { buffer[0] = 0; } else { sprintf(buffer, "%d", (int)firstPage); } fFrom = new BTextControl(BRect(x, y, x+100, y+20), "from_field", kFromLabel, buffer, new BMessage(RANGE_FROM_MSG)); fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fFrom->SetDivider(be_plain_font->StringWidth(kFromLabelExtraSpace)); fFrom->ResizeToPreferred(); fFrom->GetPreferredSize(&w, &h); panel->AddChild(fFrom); x += w + kMargin; // add a "to" field if (allPages) { buffer[0] = 0; } else { sprintf(buffer, "%d", (int)lastPage); } fTo = new BTextControl(BRect(x, y, x+100, y+20), "to_field", kToLabel, buffer, new BMessage(RANGE_TO_MSG)); fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fTo->SetDivider(be_plain_font->StringWidth(kToLabelExtraSpace)); fTo->ResizeToPreferred(); fTo->GetPreferredSize(&w, &h); panel->AddChild(fTo); y += h + kMargin + kMargin; // "new line" x = r.left + kMargin; // add a separator line... line = new BBox(BRect(r.left, y - 1, r.right, y), NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); panel->AddChild(line); y += 2 + kMargin + kMargin; // "new line" // add a "OK" button, and make it default ok = new BButton(BRect(x, y, x+100, y+20), NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); ok->MakeDefault(true); ok->ResizeToPreferred(); ok->GetPreferredSize(&w, &h); x = r.right - w - kMargin; ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner panel->AddChild(ok); // add a "Cancel" button cancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); cancel->ResizeToPreferred(); cancel->GetPreferredSize(&w, &h); cancel->MoveTo(x - w - kMargin, y); // put cancel button left next the ok button panel->AddChild(cancel); // add a "DocInfo" button BButton *button = new BButton(r, NULL, "Doc Info", new BMessage(DOC_INFO_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(8, y); panel->AddChild(button); // Finally, add our panel to window AddChild(panel); // Auto resize window ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin); }