void StringEditor::CommitChanges() { if (fPreviousText != fTextView->Text()) { fEditor.Replace(0, (const uint8 *)fTextView->Text(), fTextView->TextLength() + 1); } }
void AddWindow::MessageReceived(BMessage *mess){ if(mess->what == 'can'){ BMessenger(this).SendMessage(B_QUIT_REQUESTED); } else if(mess->what == 'sav'){ BTextView *textView = (BTextView*)FindView("rss_url"); if (textView){ BMessage msg(DOWNLOAD_CHANNEL); msg.AddString("url",textView->Text()); BMessenger(main_window).SendMessage(&msg); BMessenger(this).SendMessage(B_QUIT_REQUESTED); } } else if(mess->what== 'past'){ BString url; mess->FindString("url",&url); BTextView *textView = (BTextView*)FindView("rss_url"); if (textView){ textView->SetText(url.String()); } } else BWindow::MessageReceived(mess); }
void HWindow::AboutRequested() { const char* aboutText = AboutText(); if (aboutText == NULL) return; BAlert *about = new BAlert("About", aboutText, "Cool"); BTextView *v = about->TextView(); if (v) { rgb_color red = {255, 0, 51, 255}; rgb_color blue = {0, 102, 255, 255}; v->SetStylable(true); char *text = (char*)v->Text(); char *s = text; // set all Be in blue and red while ((s = strstr(s, "Be")) != NULL) { int32 i = s - text; v->SetFontAndColor(i, i+1, NULL, 0, &blue); v->SetFontAndColor(i+1, i+2, NULL, 0, &red); s += 2; } // first text line s = strchr(text, '\n'); BFont font; v->GetFontAndColor(0, &font); font.SetSize(12); // font.SetFace(B_OUTLINED_FACE); v->SetFontAndColor(0, s-text+1, &font, B_FONT_SIZE); }; about->SetFlags(about->Flags() | B_CLOSE_ON_ESCAPE); about->Go(); }
/*********************************************************** * HardWrap ***********************************************************/ void HWrapTextView::GetHardWrapedText(BString &out) { MakeEditable(false); BTextView *offview = new BTextView(Bounds(),NULL,TextRect(),B_FOLLOW_ALL); offview->SetText(Text()); BFont font; uint32 propa; GetFontAndColor(&font,&propa); out = ""; offview->SetFontAndColor(&font,B_FONT_ALL); BString line; int32 length = offview->TextLength(); float view_width = offview->TextRect().Width(); char c=0; bool inserted; for(int32 i=0;i < length;i++) { c = offview->ByteAt(i); if(c == '\n') { line = ""; continue; } line += c; if(font.StringWidth(line.String())>=view_width) { // Back 1 charactor. i--; line.Truncate(line.Length()-1); // Insert line break. inserted = false; int32 len = line.Length(); for(int32 k = 0;k<len;k++) { if(offview->CanEndLine(i-k)) { offview->Insert(i-k,"\n",1); inserted=true; i = i-k; break; } } // If could not find proper position, add line break to end. if(!inserted) offview->Insert(i,"\n",1); line = ""; } } out = offview->Text(); delete offview; MakeEditable(true); }
void BepdfApplication::AboutRequested() { BString version; BString str("BePDF\n"); str += B_TRANSLATE("Version"); str += " "; str += GetVersion(version); str += "\n"; str += bePDFCopyright; str += "\n"; str += B_TRANSLATE_COMMENT("Language 'English', translated by the BePDF authors.", "Replace 'English' with the language you're translating to, and 'the BePDF authors' with your name or your translation group's name."); str += "\n\n"; str += BString().SetToFormat(B_TRANSLATE_COMMENT("BePDF is based on XPDF %s, %s.", "XPDF version, copyright"), xpdfVersion, xpdfCopyright); str += GPLCopyright; BAlert *about = new BAlert("About", str.String(), "OK"); BTextView *v = about->TextView(); if (v) { rgb_color red = {255, 0, 51, 255}; rgb_color blue = {0, 102, 255, 255}; v->SetStylable(true); char *text = (char*)v->Text(); char *s = text; // set all Be in BePDF in blue and red while ((s = strstr(s, "BePDF")) != NULL) { int32 i = s - text; v->SetFontAndColor(i, i+1, NULL, 0, &blue); v->SetFontAndColor(i+1, i+2, NULL, 0, &red); s += 2; } // first text line s = strchr(text, '\n'); BFont font; v->GetFontAndColor(0, &font); font.SetSize(16); v->SetFontAndColor(0, s-text+1, &font, B_FONT_SIZE); }; about->Go(); }
filter_result SpinnerMsgFilter::Filter(BMessage *msg, BHandler **target) { int32 c; msg->FindInt32("raw_char",&c); switch (c) { case B_ENTER: { BTextView *text = dynamic_cast<BTextView*>(*target); if (text && text->IsFocus()) { BView *view = text->Parent(); while (view) { Spinner *spin = dynamic_cast<Spinner*>(view); if (spin) { BString string(text->Text()); int32 newvalue = 0; sscanf(string.String(),"%ld",&newvalue); if (newvalue != spin->Value()) { spin->SetValue(newvalue); spin->Invoke(); } return B_SKIP_MESSAGE; } view = view->Parent(); } } return B_DISPATCH_MESSAGE; } case B_TAB: { // Cause Tab characters to perform keybaord navigation BHandler *h = *target; BView *v = NULL; h = h->NextHandler(); while (h) { v = dynamic_cast<BView*>(h); if (v) { *target = v->Window(); return B_DISPATCH_MESSAGE; } h = h->NextHandler(); } return B_SKIP_MESSAGE; } case B_UP_ARROW: case B_DOWN_ARROW: { BTextView *text = dynamic_cast<BTextView*>(*target); if (text && text->IsFocus()) { // We have a text view. See if it currently has the focus and belongs // to a Spinner control. If so, change the value of the spinner // TextViews are complicated beasts which are actually multiple views. // Travel up the hierarchy to see if any of the target's ancestors are // a Spinner. BView *view = text->Parent(); while (view) { Spinner *spin = dynamic_cast<Spinner*>(view); if (spin) { int32 step = spin->GetSteps(); if (c == B_DOWN_ARROW) step = 0 - step; spin->SetValue(spin->Value() + step); spin->Invoke(); return B_SKIP_MESSAGE; } view = view->Parent(); } } return B_DISPATCH_MESSAGE; } default: return B_DISPATCH_MESSAGE; } // shut the stupid compiler up return B_SKIP_MESSAGE; }
void PBox::GetData(BMessage* data){ BView * panel = fPrefView; BMessage cur; for (int i = 0; fTemplate.FindMessage("setting", i, &cur) == B_OK; i++) { const char *name = cur.FindString("name"); int32 type = -1; cur.FindInt32("type", &type); if ( dynamic_cast<BTextControl*>(panel->FindView(name))) { // Free text BTextControl * ctrl = (BTextControl*)panel->FindView(name); switch (type) { case B_STRING_TYPE: { data->AddString(name, ctrl->Text() ); } break; case B_INT32_TYPE: { data->AddInt32(name, atoi(ctrl->Text()) ); } break; default: { return; }; }; } else if (dynamic_cast<BMenuField*>(panel->FindView(name))) { // Provided option BMenuField * ctrl = (BMenuField*)panel->FindView(name); BMenuItem * item = ctrl->Menu()->FindMarked(); if (!item) return; switch (type) { case B_STRING_TYPE: { data->AddString(name, item->Label() ); BString index(name); index << "_index"; data->AddInt32(index.String(), ctrl->Menu()->IndexOf(item)); //index } break; case B_INT32_TYPE: { data->AddInt32(name, atoi(item->Label()) ); BString index(name); index << "_index"; data->AddInt32(index.String(), ctrl->Menu()->IndexOf(item)); //index } break; default: { return; }; } } else if (dynamic_cast<BCheckBox*>(panel->FindView(name))) { // Boolean setting BCheckBox * box = (BCheckBox*)panel->FindView(name); if ( box->Value() == B_CONTROL_ON ) { data->AddBool(name,true); } else { data->AddBool(name,false); } } else if (dynamic_cast<BTextView *>(panel->FindView(name))) { BTextView *view = (BTextView *)panel->FindView(name); data->AddString(name, view->Text()); }; }; }
status_t PTextView::GetProperty(const char *name, PValue *value, const int32 &index) const { if (!name || !value) return B_ERROR; BString str(name); PProperty *prop = FindProperty(name,index); if (!prop) return B_NAME_NOT_FOUND; BTextView *backend = (BTextView*)fView; if (backend->Window()) backend->Window()->Lock(); if (str.ICompare("LineCount") == 0) ((IntProperty*)prop)->SetValue(backend->CountLines()); else if (str.ICompare("Selectable") == 0) ((BoolProperty*)prop)->SetValue(backend->IsSelectable()); else if (str.ICompare("CurrentLine") == 0) ((IntProperty*)prop)->SetValue(backend->CurrentLine()); else if (str.ICompare("TabWidth") == 0) ((FloatProperty*)prop)->SetValue(backend->TabWidth()); else if (str.ICompare("TextRect") == 0) ((RectProperty*)prop)->SetValue(backend->TextRect()); else if (str.ICompare("MaxBytes") == 0) ((IntProperty*)prop)->SetValue(backend->MaxBytes()); else if (str.ICompare("UseWordWrap") == 0) ((BoolProperty*)prop)->SetValue(backend->DoesWordWrap()); else if (str.ICompare("HideTyping") == 0) ((BoolProperty*)prop)->SetValue(backend->IsTypingHidden()); else if (str.ICompare("Editable") == 0) ((BoolProperty*)prop)->SetValue(backend->IsEditable()); else if (str.ICompare("ColorSpace") == 0) ((IntProperty*)prop)->SetValue(backend->ColorSpace()); else if (str.ICompare("TextLength") == 0) ((IntProperty*)prop)->SetValue(backend->TextLength()); else if (str.ICompare("Text") == 0) ((StringProperty*)prop)->SetValue(backend->Text()); else if (str.ICompare("Resizable") == 0) ((BoolProperty*)prop)->SetValue(backend->IsResizable()); else if (str.ICompare("Alignment") == 0) ((EnumProperty*)prop)->SetValue(backend->Alignment()); else if (str.ICompare("Undoable") == 0) ((BoolProperty*)prop)->SetValue(backend->DoesUndo()); else if (str.ICompare("AutoIndent") == 0) ((BoolProperty*)prop)->SetValue(backend->DoesAutoindent()); else if (str.ICompare("Stylable") == 0) ((BoolProperty*)prop)->SetValue(backend->IsStylable()); else { if (backend->Window()) backend->Window()->Unlock(); return PView::GetProperty(name, value, index); } if (backend->Window()) backend->Window()->Unlock(); return prop->GetValue(value); }
void AlertTestWindow::Test() { BAlert *pAlert = new BAlert( "alert1", k60X, k20X, "OK", "Cancel", B_WIDTH_AS_USUAL, // widthStyle B_OFFSET_SPACING, B_EMPTY_ALERT // alert_type ); if (fAlertType == 'H') { BView *master = pAlert->ChildAt(0); master->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); } BPoint pt; BString strLabel; BButton *pBtns[3] = { NULL }; pBtns[0] = pAlert->ButtonAt(0); pBtns[1] = pAlert->ButtonAt(1); pBtns[2] = pAlert->ButtonAt(2); BTextView *pTextView = pAlert->TextView(); // Window info printf("wi.width = %.1ff;\n" "wi.height = %.1ff;\n" "ati.SetWinInfo(wi);\n", pAlert->Bounds().Width(), pAlert->Bounds().Height()); // TextView info printf("\n"); which_label(pTextView->Text(), strLabel); pt = pTextView->ConvertToParent(BPoint(0, 0)); printf("ti.label = %s;\n" "ti.width = %.1ff;\n" "ti.height = %.1ff;\n" "ti.topleft.Set(%.1ff, %.1ff);\n" "ati.SetTextViewInfo(ti);\n", strLabel.String(), pTextView->Bounds().Width(), pTextView->Bounds().Height(), pt.x, pt.y); // Button info printf("\n"); int32 i = 0; while (i < 3 && pBtns[i] != NULL) { BButton *pb = pBtns[i]; which_label(pb->Label(), strLabel); pt = pb->ConvertToParent(BPoint(0, 0)); printf("bi.label = %s;\n" "bi.width = %.1ff;\n" "bi.height = %.1ff;\n" "bi.topleft.Set(%.1ff, %.1ff);\n" "ati.SetButtonInfo(%d, bi);\n", strLabel.String(), pb->Bounds().Width(), pb->Bounds().Height(), pt.x, pt.y, (int)i); i++; } int32 result = pAlert->Go(); printf("%c<Clicked: %d\n", fAlertType, static_cast<int>(result)); pAlert = NULL; }