int32_t PTextViewGetSelection(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 *outArgs = static_cast<PArgs*>(out); if (backend->Window()) backend->Window()->Lock(); int32 outValue1; int32 outValue2; backend->GetSelection(&outValue1, &outValue2); if (backend->Window()) backend->Window()->Unlock(); outArgs->MakeEmpty(); outArgs->AddInt32("start", outValue1); outArgs->AddInt32("end", outValue2); return B_OK; }
bool PersonView::IsTextSelected() const { for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { BTextView* text = fControls.ItemAt(i)->TextView(); int32 start, end; text->GetSelection(&start, &end); if (start != end) return true; } return false; }
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(); }
void TPrefsWindow::MessageReceived(BMessage* msg) { bool revert = true; const char* family; const char* signature; const char* style; char label[256]; int32 new_size; int32 old_size; font_family new_family; font_family old_family; font_style new_style; font_style old_style; BMenuItem* item; BMessage message; switch (msg->what) { case P_OK: if (strcmp(fReplyPreamble->Text(), *fNewPreamble)) { free(*fNewPreamble); *fNewPreamble = (char *)malloc(strlen(fReplyPreamble->Text()) + 1); strcpy(*fNewPreamble, fReplyPreamble->Text()); } be_app->PostMessage(PREFS_CHANGED); Quit(); break; case P_CANCEL: revert = false; // supposed to fall through case P_REVERT: fFont.GetFamilyAndStyle(&old_family, &old_style); fNewFont->GetFamilyAndStyle(&new_family, &new_style); old_size = (int32)fFont.Size(); new_size = (int32)fNewFont->Size(); if (strcmp(old_family, new_family) || strcmp(old_style, new_style) || old_size != new_size) { fNewFont->SetFamilyAndStyle(old_family, old_style); if (revert) { sprintf(label, "%s %s", old_family, old_style); item = fFontMenu->FindItem(label); if (item != NULL) item->SetMarked(true); } fNewFont->SetSize(old_size); if (revert) { sprintf(label, "%" B_PRId32, old_size); item = fSizeMenu->FindItem(label); if (item != NULL) item->SetMarked(true); } message.what = M_FONT; be_app->PostMessage(&message); } *fNewWrap = fWrap; *fNewAttachAttributes = fAttachAttributes; if (strcmp(fSignature, *fNewSignature)) { free(*fNewSignature); *fNewSignature = (char*)malloc(strlen(fSignature) + 1); strcpy(*fNewSignature, fSignature); } *fNewEncoding = fEncoding; *fNewWarnUnencodable = fWarnUnencodable; *fNewSpellCheckStartOn = fSpellCheckStartOn; *fNewAutoMarkRead = fAutoMarkRead; *fNewButtonBar = fButtonBar; be_app->PostMessage(PREFS_CHANGED); if (revert) { for (int i = fAccountMenu->CountItems(); --i > 0;) { BMenuItem *item = fAccountMenu->ItemAt(i); BMessage* itemMessage = item->Message(); if (itemMessage != NULL && itemMessage->FindInt32("id") == *(int32 *)&fAccount) { item->SetMarked(true); break; } } strcpy(label,fReplyTo == ACCOUNT_USE_DEFAULT ? B_TRANSLATE("Use default account") : B_TRANSLATE("Account from mail")); if ((item = fReplyToMenu->FindItem(label)) != NULL) item->SetMarked(true); strcpy(label, fWrap ? B_TRANSLATE("On") : B_TRANSLATE("Off")); if ((item = fWrapMenu->FindItem(label)) != NULL) item->SetMarked(true); strcpy(label, fAttachAttributes ? B_TRANSLATE("Include file attributes in attachments") : B_TRANSLATE("No file attributes, just plain data")); if ((item = fAttachAttributesMenu->FindItem(label)) != NULL) item->SetMarked(true); strcpy(label, fColoredQuotes ? B_TRANSLATE("On") : B_TRANSLATE("Off")); if ((item = fColoredQuotesMenu->FindItem(label)) != NULL) item->SetMarked(true); if (strcmp(fReplyPreamble->Text(), *fNewPreamble)) fReplyPreamble->SetText(*fNewPreamble); item = fSignatureMenu->FindItem(fSignature); if (item) item->SetMarked(true); uint32 index = 0; while ((item = fEncodingMenu->ItemAt(index++)) != NULL) { BMessage* itemMessage = item->Message(); if (itemMessage == NULL) continue; int32 encoding; if (itemMessage->FindInt32("encoding", &encoding) == B_OK && (uint32)encoding == *fNewEncoding) { item->SetMarked(true); break; } } strcpy(label, fWarnUnencodable ? B_TRANSLATE("On") : B_TRANSLATE("Off")); if ((item = fWarnUnencodableMenu->FindItem(label)) != NULL) item->SetMarked(true); strcpy(label, fSpellCheckStartOn ? B_TRANSLATE("On") : B_TRANSLATE("Off")); if ((item = fSpellCheckStartOnMenu->FindItem(label)) != NULL) item->SetMarked(true); } else Quit(); break; case P_FONT: family = NULL; style = NULL; int32 family_menu_index; if (msg->FindString("font", &family) == B_OK) { msg->FindString("style", &style); fNewFont->SetFamilyAndStyle(family, style); message.what = M_FONT; be_app->PostMessage(&message); } /* grab this little tidbit so we can set the correct Family */ if (msg->FindInt32("parent_index", &family_menu_index) == B_OK) fFontMenu->ItemAt(family_menu_index)->SetMarked(true); 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); }