本文整理汇总了C++中BTextView::Insert方法的典型用法代码示例。如果您正苦于以下问题:C++ BTextView::Insert方法的具体用法?C++ BTextView::Insert怎么用?C++ BTextView::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTextView
的用法示例。
在下文中一共展示了BTextView::Insert方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BTextView
/***********************************************************
* 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);
}
示例2: text
void
BAboutWindow::AddText(const char* header, const char** contents)
{
BTextView* infoView = fAboutView->InfoView();
int32 textLength = infoView->TextLength();
BString text("");
if (textLength > 0) {
text << "\n\n";
textLength += 2;
}
const char* indent = "";
if (header != NULL) {
indent = " ";
text << header;
}
if (contents != NULL) {
text << "\n";
for (int32 i = 0; contents[i]; i++)
text << indent << contents[i] << "\n";
}
infoView->Insert(text.String());
if (contents != NULL && header != NULL) {
infoView->SetFontAndColor(textLength, textLength + strlen(header),
be_bold_font);
}
}
示例3:
int32_t
PTextViewInsert(void *pobject, void *in, void *out, void *extraData)
{
if (!pobject || !in || !out)
return B_ERROR;
PView *parent = static_cast<PView*>(pobject);
if (!parent)
return B_BAD_TYPE;
BTextView *backend = (BTextView*)parent->GetView();
PArgs *inArgs = static_cast<PArgs*>(in);
BString text;
if (inArgs->FindString("text", &text) != B_OK)
return B_ERROR;
int32 length;
if (inArgs->FindInt32("length", &length) != B_OK)
return B_ERROR;
if (backend->Window())
backend->Window()->Lock();
backend->Insert(text.String(), length);
if (backend->Window())
backend->Window()->Unlock();
return B_OK;
}
示例4: frame
void
Leaves::StartConfig(BView* view)
{
BRect bounds = view->Bounds();
bounds.InsetBy(10, 10);
BRect frame(0, 0, bounds.Width(), 20);
fDropRateSlider = new BSlider(frame, "drop rate",
B_TRANSLATE("Drop rate:"), new BMessage(MSG_SET_DROP_RATE),
kMinimumDropRate, kMaximumDropRate, B_BLOCK_THUMB,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
fDropRateSlider->SetValue(fDropRate);
fDropRateSlider->ResizeToPreferred();
bounds.bottom -= fDropRateSlider->Bounds().Height() * 1.5;
fDropRateSlider->MoveTo(bounds.LeftBottom());
view->AddChild(fDropRateSlider);
fLeafSizeSlider = new BSlider(frame, "leaf size",
B_TRANSLATE("Leaf size:"), new BMessage(MSG_SET_LEAF_SIZE),
kMinimumLeafSize, kMaximumLeafSize, B_BLOCK_THUMB,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
fLeafSizeSlider->SetValue(fLeafSize);
fLeafSizeSlider->ResizeToPreferred();
bounds.bottom -= fLeafSizeSlider->Bounds().Height() * 1.5;
fLeafSizeSlider->MoveTo(bounds.LeftBottom());
view->AddChild(fLeafSizeSlider);
fSizeVariationSlider = new BSlider(frame, "variation",
B_TRANSLATE("Size variation:"), new BMessage(MSG_SET_SIZE_VARIATION),
0, kMaximumSizeVariation, B_BLOCK_THUMB,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
fSizeVariationSlider->SetValue(fSizeVariation);
fSizeVariationSlider->ResizeToPreferred();
bounds.bottom -= fSizeVariationSlider->Bounds().Height() * 1.5;
fSizeVariationSlider->MoveTo(bounds.LeftBottom());
view->AddChild(fSizeVariationSlider);
BTextView* textView = new BTextView(bounds, B_EMPTY_STRING,
bounds.OffsetToCopy(0., 0.), B_FOLLOW_ALL, B_WILL_DRAW);
textView->SetViewColor(view->ViewColor());
BString name = B_TRANSLATE("Leaves");
BString text = name;
text << "\n\n";
text << B_TRANSLATE("by Deyan Genovski, Geoffry Song");
text << "\n\n";
textView->Insert(text.String());
textView->SetStylable(true);
textView->SetFontAndColor(0, name.Length(), be_bold_font);
textView->MakeEditable(false);
view->AddChild(textView);
BWindow* window = view->Window();
if (window) window->AddHandler(this);
fDropRateSlider->SetTarget(this);
fLeafSizeSlider->SetTarget(this);
fSizeVariationSlider->SetTarget(this);
}
示例5: if
void
PersonView::SetAttribute(const char* attribute, const char* value,
bool update)
{
if (!LockLooper())
return;
AttributeTextControl* control = NULL;
for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
if (fControls.ItemAt(i)->Attribute() == attribute) {
control = fControls.ItemAt(i);
break;
}
}
if (control == NULL)
return;
if (update) {
control->SetText(value);
control->Update();
} else {
BTextView* text = control->TextView();
int32 start, end;
text->GetSelection(&start, &end);
if (start != end) {
text->Delete();
text->Insert(value);
} else if ((end = text->TextLength())) {
text->Select(end, end);
text->Insert(",");
text->Insert(value);
text->Select(text->TextLength(), text->TextLength());
} else
control->SetText(value);
}
UnlockLooper();
}
示例6: file
/***********************************************************
* ChangeAccount
***********************************************************/
void
HAddressView::ChangeAccount(const char* name)
{
BPath path;
::find_directory(B_USER_SETTINGS_DIRECTORY,&path);
path.Append(APP_NAME);
path.Append("Accounts");
path.Append(name);
BFile file(path.Path(),B_READ_ONLY);
if(file.InitCheck() == B_OK)
{
BMessage msg;
msg.Unflatten(&file);
BString name,from,address;
if(msg.FindString("real_name",&name) != B_OK)
name = "";
if(msg.FindString("address",&address) != B_OK)
{
address = "";
(new BAlert("",_("Cound not find your email address!\nPlease check your account"),_("OK")))->Go();
return;
}
if(name.Length() > 0)
from << "\"" <<name << "\" <";
from += address;
if(name.Length() > 0)
from << ">";
fFrom->SetText(from.String());
// Insert signature.
BTextView *view = cast_as(Window()->FindView("HMailView"),BTextView);
if(view)
{
const char* sig_path;
if(msg.FindString("signature",&sig_path) == B_OK)
{
BFile sigfile(sig_path,B_READ_ONLY);
if(sigfile.InitCheck() == B_OK)
{
BString str;
str << "\n" << sigfile;
view->Insert(view->TextLength(),str.String(),str.Length());
view->Select(0,0);
}
}
}
}
}
示例7: frame
// StartConfig
void
IFSSaver::StartConfig(BView *view)
{
BRect bounds = view->Bounds();
bounds.InsetBy(10.0, 10.0);
BRect frame(0.0, 0.0, bounds.Width(), 20.0);
// the additive check box
fAdditiveCB = new BCheckBox(frame, "additive setting",
B_TRANSLATE("Render dots additive"),
new BMessage(MSG_TOGGLE_ADDITIVE),
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fAdditiveCB->SetValue(fAdditive);
fAdditiveCB->ResizeToPreferred();
bounds.bottom -= fAdditiveCB->Bounds().Height() * 2.0;
fAdditiveCB->MoveTo(bounds.LeftBottom());
view->AddChild(fAdditiveCB);
// the additive check box
fSpeedS = new BSlider(frame, "speed setting",
B_TRANSLATE("Morphing speed:"),
new BMessage(MSG_SET_SPEED),
1, 12, B_BLOCK_THUMB,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
fSpeedS->SetValue(fSpeed);
fSpeedS->SetHashMarks(B_HASH_MARKS_BOTTOM);
fSpeedS->SetHashMarkCount(12);
fSpeedS->ResizeToPreferred();
bounds.bottom -= fSpeedS->Bounds().Height() + 15.0;
fSpeedS->MoveTo(bounds.LeftBottom());
view->AddChild(fSpeedS);
// the info text view
BRect textRect = bounds;
textRect.OffsetTo(0.0, 0.0);
BTextView* textView = new BTextView(bounds, B_EMPTY_STRING, textRect,
B_FOLLOW_ALL, B_WILL_DRAW);
textView->SetViewColor(view->ViewColor());
textView->Insert(B_TRANSLATE("Iterated Function System\n\n"
""B_UTF8_COPYRIGHT" 1997 Massimino Pascal\n\n"
"xscreensaver port by Stephan Aßmus\n"
"<[email protected]>"));
textView->SetStylable(true);
textView->SetFontAndColor(0, 24, be_bold_font);
// textView->SetFontAndColor(25, 255, be_plain_font);
textView->MakeEditable(false);
view->AddChild(textView);
// make sure we receive messages from the views we added
if (BWindow* window = view->Window())
window->AddHandler(this);
fAdditiveCB->SetTarget(this);
fSpeedS->SetTarget(this);
}
示例8: strcmp
//.........这里部分代码省略.........
break;
case P_SIZE:
old_size = (int32) fNewFont->Size();
msg->FindInt32("size", &new_size);
if (old_size != new_size) {
fNewFont->SetSize(new_size);
message.what = M_FONT;
be_app->PostMessage(&message);
}
break;
case P_WRAP:
msg->FindBool("wrap", fNewWrap);
break;
case P_ATTACH_ATTRIBUTES:
msg->FindBool("attachAttributes", fNewAttachAttributes);
break;
case P_COLORED_QUOTES:
msg->FindBool("cquotes", fNewColoredQuotes);
break;
case P_ACCOUNT:
msg->FindInt32("id",(int32*)fNewAccount);
break;
case P_REPLYTO:
msg->FindInt32("replyTo", fNewReplyTo);
break;
case P_REPLY_PREAMBLE:
{
int32 index = -1;
if (msg->FindInt32("index", &index) < B_OK)
break;
BMenuItem *item = fReplyPreambleMenu->ItemAt(index);
if (item == NULL) {
msg->PrintToStream();
break;
}
BTextView *text = fReplyPreamble->TextView();
int32 selectionStart;
int32 selectionEnd;
text->GetSelection(&selectionStart, &selectionEnd);
if (selectionStart != selectionEnd)
text->Delete(selectionStart, selectionEnd);
text->Insert(item->Label(), 2);
}
case P_SIG:
free(*fNewSignature);
if (msg->FindString("signature", &signature) == B_NO_ERROR) {
*fNewSignature = (char*)malloc(strlen(signature) + 1);
strcpy(*fNewSignature, signature);
} else {
*fNewSignature = (char*)malloc(
strlen(B_TRANSLATE("None")) + 1);
strcpy(*fNewSignature, B_TRANSLATE("None"));
}
break;
case P_ENC:
msg->FindInt32("encoding", (int32*)fNewEncoding);
break;
case P_WARN_UNENCODABLE:
msg->FindBool("warnUnencodable", fNewWarnUnencodable);
break;
case P_SPELL_CHECK_START_ON:
msg->FindBool("spellCheckStartOn", fNewSpellCheckStartOn);
break;
case P_MARK_READ:
msg->FindBool("autoMarkRead", fNewAutoMarkRead);
be_app->PostMessage(PREFS_CHANGED);
break;
case P_BUTTON_BAR:
msg->FindInt8("bar", (int8*)fNewButtonBar);
be_app->PostMessage(PREFS_CHANGED);
break;
default:
BWindow::MessageReceived(msg);
}
fFont.GetFamilyAndStyle(&old_family, &old_style);
fNewFont->GetFamilyAndStyle(&new_family, &new_style);
old_size = (int32) fFont.Size();
new_size = (int32) fNewFont->Size();
bool changed = old_size != new_size
|| fWrap != *fNewWrap
|| fAttachAttributes != *fNewAttachAttributes
|| fColoredQuotes != *fNewColoredQuotes
|| fAccount != *fNewAccount
|| fReplyTo != *fNewReplyTo
|| strcmp(old_family, new_family)
|| strcmp(old_style, new_style)
|| strcmp(fReplyPreamble->Text(), *fNewPreamble)
|| strcmp(fSignature, *fNewSignature)
|| fEncoding != *fNewEncoding
|| fWarnUnencodable != *fNewWarnUnencodable
|| fSpellCheckStartOn != *fNewSpellCheckStartOn
|| fAutoMarkRead != *fNewAutoMarkRead
|| fButtonBar != *fNewButtonBar;
fRevert->SetEnabled(changed);
}
示例9: sizeof
void
MessageView::SetTo(BMessage& message)
{
// TODO: when we have a real column list/tree view, redo this using
// it with nice editors as well.
fTextView->SetText("");
char text[512];
snprintf(text, sizeof(text), B_TRANSLATE_COMMENT("what: '%.4s'\n\n",
"'What' is a message specifier that defines the type of the message."),
(char*)&message.what);
fTextView->Insert(text);
type_code type;
int32 count;
#ifdef HAIKU_TARGET_PLATFORM_DANO
const
#endif
char* name;
for (int32 i = 0; message.GetInfo(B_ANY_TYPE, i, &name, &type, &count)
== B_OK; i++) {
snprintf(text, sizeof(text), "%s\t", _TypeToString(type).String());
fTextView->Insert(text);
text_run_array array;
array.count = 1;
array.runs[0].offset = 0;
array.runs[0].font.SetFace(B_BOLD_FACE);
array.runs[0].color = (rgb_color){0, 0, 0, 255};
fTextView->Insert(name, &array);
array.runs[0].font = be_plain_font;
fTextView->Insert("\n", &array);
for (int32 j = 0; j < count; j++) {
const char* data;
ssize_t size;
if (message.FindData(name, type, j, (const void**)&data, &size)
!= B_OK)
continue;
text[0] = '\0';
switch (type) {
case B_INT64_TYPE:
snprintf(text, sizeof(text), "%" B_PRId64, *(int64*)data);
break;
case B_UINT64_TYPE:
snprintf(text, sizeof(text), "%" B_PRIu64, *(uint64*)data);
break;
case B_INT32_TYPE:
snprintf(text, sizeof(text), "%" B_PRId32, *(int32*)data);
break;
case B_UINT32_TYPE:
snprintf(text, sizeof(text), "%" B_PRIu32, *(uint32*)data);
break;
case B_BOOL_TYPE:
if (*(uint8*)data)
strcpy(text, "true");
else
strcpy(text, "false");
break;
case B_STRING_TYPE:
case B_MIME_STRING_TYPE:
{
snprintf(text, sizeof(text), "%s", data);
break;
}
}
if (text[0]) {
fTextView->Insert("\t\t");
if (count > 1) {
char index[16];
snprintf(index, sizeof(index), "%" B_PRId32 ".\t", j);
fTextView->Insert(index);
}
fTextView->Insert(text);
fTextView->Insert("\n");
}
}
}
}
示例10: message
//.........这里部分代码省略.........
if (fRefDropMenu->CountItems() > 1) {
fRefDropMenu->SetTargetForItems(this);
fRefDropMenu->Go(point, true, true, true);
return;
} else {
delete fRefDropMenu;
fRefDropMenu = NULL;
}
}
BString email;
file.ReadAttrString(attr.String(), &email);
// we got something...
if (email.Length() > 0) {
// see if we can get a username as well
BString name;
file.ReadAttrString("META:name", &name);
BString address;
if (name.Length() == 0) {
// if we have no Name, just use the email address
address = email;
} else {
// otherwise, pretty-format it
address << "\"" << name << "\" <" << email << ">";
}
if (addressList.Length() > 0)
addressList << ", ";
addressList << address;
}
} else {
enclosure = true;
message.AddRef("refs", &ref);
}
}
}
if (addressList.Length() > 0) {
BTextView *textView = TextView();
int end = textView->TextLength();
if (end != 0) {
textView->Select(end, end);
textView->Insert(", ");
}
textView->Insert(addressList.String());
}
if (enclosure)
Window()->PostMessage(&message, Window());
break;
}
case M_SELECT:
{
BTextView *textView = (BTextView *)ChildAt(0);
if (textView != NULL)
textView->Select(0, textView->TextLength());
break;
}
case kMsgAddressChosen: {
BString display;
BString address;
entry_ref ref;
if (msg->FindString("address", &address) != B_OK
|| msg->FindRef("ref", &ref) != B_OK)
return;
if (address.Length() > 0) {
BString name;
BNode node(&ref);
display = address;
node.ReadAttrString("META:name", &name);
if (name.Length() > 0) {
display = "";
display << "\"" << name << "\" <" << address << ">";
}
BTextView *textView = TextView();
int end = textView->TextLength();
if (end != 0) {
textView->Select(end, end);
textView->Insert(", ");
}
textView->Insert(display.String());
}
break;
}
default:
// BTextControl::MessageReceived(msg);
BComboBox::MessageReceived(msg);
}
}
示例11: IconLabel
AudioView::AudioView(BRect size)
:
BView(size, "AudioView", B_FOLLOW_NONE, B_WILL_DRAW)
{
BRect r, r2;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
IconLabel* advLabel = new IconLabel(BRect(0, 0, 19 + be_bold_font->StringWidth(" Audio Options (see help before change options)"), 19),
" Audio Options (see help before change options)", "audiocd_16.png");
advLabel->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
advLabel->SetDrawingMode(B_OP_ALPHA);
r = Bounds();
r.InsetBy(5.0, 5.0);
r.bottom = 80;
BBox* advOptionsBox = new BBox(r, "fAdvOptionsBox", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER);
advOptionsBox->SetLabel(advLabel);
AddChild(advOptionsBox);
r = advOptionsBox->Bounds();
r.InsetBy(5.0, 5.0);
r.top += 10;
r.right = 120;
r.bottom = 25;
fPadCheckBox = new BCheckBox(r, "pad", "Padding", new BMessage(AUDIO_PAD));
if (!strncmp(PAD, "-pad", 4))
fPadCheckBox->SetValue(B_CONTROL_ON);
advOptionsBox->AddChild(fPadCheckBox);
r.bottom += 15;
r.top += 15;
r.right = 120;
fNoFixCheckBox = new BCheckBox(r, "nofix", "No fixate", new BMessage(AUDIO_NOFIX));
if (!strncmp(NOFIX, "-nofix", 6))
fNoFixCheckBox->SetValue(B_CONTROL_ON);
advOptionsBox->AddChild(fNoFixCheckBox);
r.bottom += 15;
r.top += 15;
fPreEmpCheckBox = new BCheckBox(r, "preemp", "Preemp", new BMessage(AUDIO_PREEMP));
if (!strncmp(PREEMP, "-preemp", 7))
fPreEmpCheckBox->SetValue(B_CONTROL_ON);
advOptionsBox->AddChild(fPreEmpCheckBox);
r = advOptionsBox->Bounds();
r.InsetBy(5.0, 5.0);
r.top += 10;
r.left = 125;
r.bottom = 25;
fSwabCheckBox = new BCheckBox(r, "swab", "Swab", new BMessage(AUDIO_SWAB));
if (!strncmp(SWAB, "-swab", 5))
fSwabCheckBox->SetValue(B_CONTROL_ON);
advOptionsBox->AddChild(fSwabCheckBox);
// Info box
r = Bounds();
r.InsetBy(5.0, 5.0);
r.top = 85;
BBox* infoBox = new BBox(r, "Info", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER);
infoBox->SetLabel("Audio Info");
AddChild(infoBox);
r = infoBox->Bounds();
r.InsetBy(5.0, 5.0);
r.top += 10;
r.right -= B_V_SCROLL_BAR_WIDTH;
r2 = r;
r2.InsetBy(2.0, 2.0);
BTextView* infoTextView = new BTextView(r, "infoTextView", r2, B_FOLLOW_NONE, B_WILL_DRAW);
infoTextView->MakeEditable(false);
infoTextView->SetStylable(true);
BScrollView* infoScrollView = new BScrollView("infoScrollView", infoTextView, B_FOLLOW_NONE, 0, false, true, B_FANCY_BORDER);
infoBox->AddChild(infoScrollView);
infoTextView->SetFontAndColor(be_fixed_font, B_FONT_ALL, &darkblue);
infoTextView->Insert("Here will be some AudioInfo in the future like what codecs there are on the system.");
}