Example #1
0
int32_t
PTextViewSelect(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);

	int32 start;
	if (inArgs->FindInt32("start", &start) != B_OK)
		return B_ERROR;

	int32 end;
	if (inArgs->FindInt32("end", &end) != B_OK)
		return B_ERROR;

	if (backend->Window())
		backend->Window()->Lock();


	backend->Select(start, end);

	if (backend->Window())
		backend->Window()->Unlock();

	return B_OK;
}
Example #2
0
void ShowAboutWindow(void)
{
	char str[512];
	sprintf(str,
		"Basilisk II\nVersion %d.%d\n\n"
		"Copyright " B_UTF8_COPYRIGHT " 1997-2008 Christian Bauer et al.\n"
		"E-mail: [email protected]\n"
		"http://www.uni-mainz.de/~bauec002/B2Main.html\n\n"
		"Basilisk II comes with ABSOLUTELY NO\n"
		"WARRANTY. This is free software, and\n"
		"you are welcome to redistribute it\n"
		"under the terms of the GNU General\n"
		"Public License.\n",
		VERSION_MAJOR, VERSION_MINOR
	);
	BAlert *about = new BAlert("", str, GetString(STR_OK_BUTTON), NULL, NULL, B_WIDTH_FROM_LABEL);
	BTextView *theText = about->TextView();
	if (theText) {
		theText->SetStylable(true);
		theText->Select(0, 11);
		BFont ourFont;
		theText->SetFontAndColor(be_bold_font);
		theText->GetFontAndColor(2, &ourFont, NULL);
		ourFont.SetSize(24);
		theText->SetFontAndColor(&ourFont);
	}
	about->Go();
}
Example #3
0
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();
}
Example #4
0
/***********************************************************
 * 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);
				}
			}
		}
	}
}
void
PersonView::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case M_SAVE:
			Save();
			break;

		case M_REVERT:
			if (fPictureView)
				fPictureView->Revert();

			if (fAddrView)
				fAddrView->Reload();

			for (int32 i = fControls.CountItems() - 1; i >= 0; i--)
				fControls.ItemAt(i)->Reload();
			break;

		case M_SELECT:
			for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
				BTextView* text = fControls.ItemAt(i)->TextView();
				if (text->IsFocus()) {
					text->Select(0, text->TextLength());
					break;
				}
			}
			break;

		case M_GROUP_MENU:
		{
			/*const char* name = NULL;
			if (msg->FindString("group", &name) == B_OK)
				SetAttribute(fCategoryAttribute, name, false);*/
			break;
		}

	}
}
void
PersonView::MessageReceived(BMessage* msg)
{
	msg->PrintToStream();
	switch (msg->what) {
		case M_SAVE:
			Save();
			break;

		case M_REVERT:
			if (fPictureView)
				fPictureView->Revert();

			if (fAddressWindow)
				fAddressWindow->Reload();

			for (int32 i = fControls.CountItems() - 1; i >= 0; i--)
				fControls.ItemAt(i)->Reload();
			break;

		case M_SELECT:
			for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
				BTextView* text = fControls.ItemAt(i)->TextView();
				if (text->IsFocus()) {
					text->Select(0, text->TextLength());
					break;
				}
			}
			break;

		case M_GROUP_MENU:
		{
			/*const char* name = NULL;
			if (msg->FindString("group", &name) == B_OK)
				SetAttribute(fCategoryAttribute, name, false);*/
			break;
		}

		case M_SHOW_LOCATIONS:
		{
			if (fAddressWindow == NULL) {
				fAddressWindow = new AddressWindow(fContact);
			}
			fAddressWindow->Show();
			fAddressWindow->Activate(true);
			break;
		}

		case M_ADD_FIELD:
		{
			field_type type;
			if (msg->FindInt32("field_type", (int32*)&type) == B_OK) {
				BContactField* contactField 
					= BContactField::InstantiateChildClass(type);
				fContact->AddField(contactField);
				AddNewField(contactField);
				fSaved = false;
			}
			break;
		}

		case M_REMOVE_FIELD:
		{
			ContactFieldTextControl* control;
			if (msg->FindPointer("fieldtextcontrol",
				(void**)&control) == B_OK) {
				_RemoveField(control);
				fSaved = false;
			}
			break;
		}
	}
}
Example #7
0
void
TTextControl::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
		case B_SIMPLE_DATA: {
			if (fIncoming && !fResending)
				return;

			int32 buttons = -1;
			BPoint point;
			if (msg->FindInt32("buttons", &buttons) != B_OK)
				buttons = B_PRIMARY_MOUSE_BUTTON;

			if (buttons != B_PRIMARY_MOUSE_BUTTON
				&& msg->FindPoint("_drop_point_", &point) != B_OK)
				return;

			BMessage message(REFS_RECEIVED);
			bool enclosure = false;
			BString addressList;
				// Batch up the addresses to be added, since we can only
				// insert a few times before deadlocking since inserting
				// sends a notification message to the window BLooper,
				// which is busy doing this insert.  BeOS message queues
				// are annoyingly limited in their design.

			entry_ref ref;
			for (int32 index = 0;msg->FindRef("refs", index, &ref) == B_OK; index++) {
				BFile file(&ref, B_READ_ONLY);
				if (file.InitCheck() == B_NO_ERROR) {
					BNodeInfo info(&file);
					char type[B_FILE_NAME_LENGTH];
					info.GetType(type);

					if (fCommand != SUBJECT_FIELD
						&& !strcmp(type,"application/x-person")) {
						// add person's E-mail address to the To: field

						BString attr = "";
						if (buttons == B_PRIMARY_MOUSE_BUTTON) {
							if (msg->FindString("attr", &attr) < B_OK)
								attr = "META:email"; // If not META:email3 etc.
						} else {
							BNode node(&ref);
							node.RewindAttrs();

							char buffer[B_ATTR_NAME_LENGTH];

							delete fRefDropMenu;
							fRefDropMenu = new BPopUpMenu("RecipientMenu");

							while (node.GetNextAttrName(buffer) == B_OK) {
								if (strstr(buffer, "email") <= 0)
									continue;

								attr = buffer;

								BString address;
								node.ReadAttrString(buffer, &address);
								if (address.Length() <= 0)
									continue;

								BMessage *itemMsg = new BMessage(kMsgAddressChosen);
								itemMsg->AddString("address", address.String());
								itemMsg->AddRef("ref", &ref);

								BMenuItem *item = new BMenuItem(address.String(),
									itemMsg);
								fRefDropMenu->AddItem(item);
							}

							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);
	}
}