Example #1
0
void
Spinner::_InitObject(void)
{
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	BRect r(Bounds());
	if (r.Height() < B_H_SCROLL_BAR_HEIGHT * 2)
		r.bottom = r.top + 1 + B_H_SCROLL_BAR_HEIGHT * 2;
	ResizeTo(r.Width(),r.Height());
	
	r.right -= B_V_SCROLL_BAR_WIDTH;
	
	font_height fh;
	BFont font;
	font.GetHeight(&fh);
	float textheight = fh.ascent + fh.descent + fh.leading;
	
	r.top = 0;
	r.bottom = textheight;
	
	fTextControl = new BTextControl(r,"textcontrol",Label(),"0",
									new BMessage(M_TEXT_CHANGED), B_FOLLOW_TOP | 
									B_FOLLOW_LEFT_RIGHT,
									B_WILL_DRAW | B_NAVIGABLE);
	AddChild(fTextControl);
	fTextControl->ResizeTo(r.Width(), MAX(textheight, fTextControl->TextView()->LineHeight(0) + 4.0));
	fTextControl->MoveTo(0,
		((B_H_SCROLL_BAR_HEIGHT * 2) - fTextControl->Bounds().Height()) / 2);
		
	fTextControl->SetDivider(StringWidth(Label()) + 5);
	
	BTextView *tview = fTextControl->TextView();
	tview->SetAlignment(B_ALIGN_LEFT);
	tview->SetWordWrap(false);
	
	BString string("QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,/qwertyuiop{}| "
		"asdfghjkl:\"zxcvbnm<>?!@#$%^&*()-_=+`~\r");
	
	for (int32 i = 0; i < string.CountChars(); i++) {
		char c = string.ByteAt(i);
		tview->DisallowChar(c);
	}
	
	r = Bounds();
	r.left = r.right - B_V_SCROLL_BAR_WIDTH;
	r.bottom = B_H_SCROLL_BAR_HEIGHT;
	
	fUpButton = new SpinnerArrowButton(r.LeftTop(),"up",ARROW_UP);
	AddChild(fUpButton);
	
	r.OffsetBy(0,r.Height() + 1);
	fDownButton = new SpinnerArrowButton(r.LeftTop(),"down",ARROW_DOWN);
	AddChild(fDownButton);
	
	
	fPrivateData = new SpinnerPrivateData;
	fFilter = new SpinnerMsgFilter;
}
Example #2
0
SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings)
	:
	BView(name, flags, new BGroupLayout(B_VERTICAL)),
	fSettings(settings)
{
	BPopUpMenu* menu = new BPopUpMenu("pick compression");

	uint32 currentCompression = 
		fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
	// create the menu items with the various compression methods
	add_menu_item(menu, SGI_COMP_NONE, B_TRANSLATE("None"), 
		currentCompression);
	//menu->AddSeparatorItem();
	add_menu_item(menu, SGI_COMP_RLE, B_TRANSLATE("RLE"), currentCompression);

	// DON'T turn this on, it's so slow that I didn't wait long enough
	// the one time I tested this. So I don't know if the code even works.
	// Supposedly, this would look for an already written scanline, and
	// modify the scanline tables so that the current row is not written
	// at all...

	//add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression);

	fCompressionMF = new BMenuField("compression", 
		B_TRANSLATE("Use compression:"), menu);

	BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);

	BStringView* titleView = new BStringView("title", 
		B_TRANSLATE("SGI image translator"));
	titleView->SetFont(be_bold_font);
	titleView->SetExplicitAlignment(labelAlignment);

	char detail[100];
	sprintf(detail, B_TRANSLATE("Version %d.%d.%d %s"),
		static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)),
		static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)),
		static_cast<int>(B_TRANSLATION_REVISION_VERSION(
			SGI_TRANSLATOR_VERSION)), __DATE__);
	BStringView* detailView = new BStringView("details", detail);
	detailView->SetExplicitAlignment(labelAlignment);

	BTextView* infoView = new BTextView("info");
	infoView->SetText(BString(B_TRANSLATE("written by:\n"))
			.Append(author)
			.Append(B_TRANSLATE("\n\nbased on GIMP SGI plugin v1.5:\n"))
			.Append(kSGICopyright).String());
	infoView->SetExplicitAlignment(labelAlignment);
	infoView->SetWordWrap(false);
	infoView->MakeEditable(false);
	infoView->MakeResizable(true);
	infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	float padding = 5.0f;
	BLayoutBuilder::Group<>(this, B_VERTICAL, padding)
		.SetInsets(padding)
		.Add(titleView)
		.Add(detailView)
		.AddGroup(B_HORIZONTAL)
			.Add(fCompressionMF)
			.AddGlue()
			.End()
		.Add(infoView)
		.AddGlue();

	BFont font;
	GetFont(&font);
	SetExplicitPreferredSize(BSize((font.Size() * 390) / 12,
		(font.Size() * 180) / 12));

	// TODO: remove this workaround for ticket #4217
	infoView->SetExplicitPreferredSize(
		BSize(infoView->LineWidth(4), infoView->TextHeight(0, 80)));
	infoView->SetExplicitMaxSize(infoView->ExplicitPreferredSize());
	infoView->SetExplicitMinSize(infoView->ExplicitPreferredSize());
}
Example #3
0
void
BTextWidget::StartEdit(BRect bounds, BPoseView *view, BPose *pose)
{
	if (!IsEditable())
		return;

	// don't allow editing of the trash directory name
	if (pose->TargetModel()->IsTrash())
		return;

	// don't allow editing of the "Disks" icon name
	if (pose->TargetModel()->IsRoot())
		return;

	BEntry entry(pose->TargetModel()->EntryRef());
	if (entry.InitCheck() == B_OK 
		&& !ConfirmChangeIfWellKnownDirectory(&entry, "rename"))
		return;

	// get bounds with full text length
	BRect rect(bounds);
	BRect textRect(bounds);
	rect.OffsetBy(-2, -1);
	rect.right += 1;

	BFont font;
	view->GetFont(&font);
	BTextView *textView = new BTextView(rect, "WidgetTextView", textRect, &font, 0,
		B_FOLLOW_ALL, B_WILL_DRAW);

	textView->SetWordWrap(false);
	DisallowMetaKeys(textView);
	fText->SetUpEditing(textView);

	textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter));

	rect.right = rect.left + textView->LineWidth() + 3;
	// center new width, if necessary
	if (view->ViewMode() == kIconMode
		|| (view->ViewMode() == kListMode && fAlignment == B_ALIGN_CENTER)) {
		rect.OffsetBy(bounds.Width() / 2 - rect.Width() / 2, 0);
	}

	rect.bottom = rect.top + textView->LineHeight() + 1;
	textRect = rect.OffsetToCopy(2, 1);
	textRect.right -= 3;
	textRect.bottom--;
	textView->SetTextRect(textRect);

	textRect = view->Bounds();
	bool hitBorder = false;
	if (rect.left < 1)
		rect.left = 1, hitBorder = true;
	if (rect.right > textRect.right)
		rect.right = textRect.right - 2, hitBorder = true;

	textView->MoveTo(rect.LeftTop());
	textView->ResizeTo(rect.Width(), rect.Height());

	BScrollView *scrollView = new BScrollView("BorderView", textView, 0, 0, false,
		false, B_PLAIN_BORDER);
	view->AddChild(scrollView);

	// configure text view
	switch (view->ViewMode()) {
		case kIconMode:
			textView->SetAlignment(B_ALIGN_CENTER);
			break;

		case kMiniIconMode:
			textView->SetAlignment(B_ALIGN_LEFT);
			break;

		case kListMode:
			textView->SetAlignment(fAlignment);
			break;
	}
	textView->MakeResizable(true, hitBorder ? NULL : scrollView);

	view->SetActivePose(pose);		// tell view about pose
	SetActive(true);				// for widget

	textView->SelectAll();
	textView->MakeFocus();

	// make this text widget invisible while we edit it
	SetVisible(false);

	ASSERT(view->Window());	// how can I not have a Window here???

	if (view->Window())
		// force immediate redraw so TextView appears instantly
		view->Window()->UpdateIfNeeded();
}
Example #4
0
	KeyRequestView()
		:
		BView("KeyRequestView", B_WILL_DRAW),
		fPassword(NULL)
	{
		SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

		BGroupLayout* rootLayout = new(std::nothrow) BGroupLayout(B_VERTICAL);
		if (rootLayout == NULL)
			return;

		SetLayout(rootLayout);

		BGridView* controls = new(std::nothrow) BGridView();
		if (controls == NULL)
			return;

		BGridLayout* layout = controls->GridLayout();

		float inset = ceilf(be_plain_font->Size() * 0.7);
		rootLayout->SetInsets(inset, inset, inset, inset);
		rootLayout->SetSpacing(inset);
		layout->SetSpacing(inset, inset);

		BStringView* label = new(std::nothrow) BStringView("keyringLabel",
			B_TRANSLATE("Keyring:"));
		if (label == NULL)
			return;

		int32 row = 0;
		layout->AddView(label, 0, row);

		fKeyringName = new(std::nothrow) BStringView("keyringName", "");
		if (fKeyringName == NULL)
			return;

		layout->AddView(fKeyringName, 1, row++);

		fPassword = new(std::nothrow) BTextControl(B_TRANSLATE("Password:"******"", NULL);
		if (fPassword == NULL)
			return;

		BLayoutItem* layoutItem = fPassword->CreateTextViewLayoutItem();
		layoutItem->SetExplicitMinSize(BSize(fPassword->StringWidth(
				"0123456789012345678901234567890123456789") + inset,
			B_SIZE_UNSET));

		layout->AddItem(fPassword->CreateLabelLayoutItem(), 0, row);
		layout->AddItem(layoutItem, 1, row++);

		BGroupView* buttons = new(std::nothrow) BGroupView(B_HORIZONTAL);
		if (buttons == NULL)
			return;

		fCancelButton = new(std::nothrow) BButton(B_TRANSLATE("Cancel"),
			new BMessage(kMessageCancel));
		buttons->GroupLayout()->AddView(fCancelButton);

		buttons->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());

		fUnlockButton = new(std::nothrow) BButton(B_TRANSLATE("Unlock"),
			new BMessage(kMessageUnlock));
		buttons->GroupLayout()->AddView(fUnlockButton);

		BTextView* message = new(std::nothrow) BTextView("message");
		message->SetText(B_TRANSLATE("An application wants to access the "
			"keyring below, but it is locked with a passphrase. Please enter "
			"the passphrase to unlock the keyring.\n"
			"If you unlock the keyring, it stays unlocked until the system is "
			"shut down or the keyring is manually locked again.\n"
			"If you cancel this dialog the keyring will remain locked."));
		message->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
		rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
		message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
		message->MakeEditable(false);
		message->MakeSelectable(false);
		message->SetWordWrap(true);

		rootLayout->AddView(message);
		rootLayout->AddView(controls);
		rootLayout->AddView(buttons);
	}
Example #5
0
status_t
PTextView::SetProperty(const char *name, PValue *value, const int32 &index)
{
	if (!name || !value)
		return B_ERROR;
	
	BString str(name);
	PProperty *prop = FindProperty(name,index);
	if (!prop)
		return B_NAME_NOT_FOUND;
	
	if (FlagsForProperty(prop) & PROPERTY_READ_ONLY)
		return B_READ_ONLY;
	
	BTextView *backend = (BTextView*)fView;
	
	BoolValue boolval;
	CharValue charval;
	ColorValue colorval;
	FloatValue floatval;
	IntValue intval;
	PointValue pointval;
	RectValue rectval;
	StringValue stringval;
	
	status_t status = prop->SetValue(value);
	if (status != B_OK)
		return status;

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

	else if (str.ICompare("Selectable") == 0)
	{
		prop->GetValue(&boolval);
		backend->MakeSelectable(*boolval.value);
	}
	else if (str.ICompare("CurrentLine") == 0)
	{
		prop->GetValue(&intval);
		backend->GoToLine(*intval.value);
	}
	else if (str.ICompare("TabWidth") == 0)
	{
		prop->GetValue(&floatval);
		backend->SetTabWidth(*floatval.value);
	}
	else if (str.ICompare("TextRect") == 0)
	{
		prop->GetValue(&rectval);
		backend->SetTextRect(*rectval.value);
	}
	else if (str.ICompare("MaxBytes") == 0)
	{
		prop->GetValue(&intval);
		backend->SetMaxBytes(*intval.value);
	}
	else if (str.ICompare("UseWordWrap") == 0)
	{
		prop->GetValue(&boolval);
		backend->SetWordWrap(*boolval.value);
	}
	else if (str.ICompare("HideTyping") == 0)
	{
		prop->GetValue(&boolval);
		backend->HideTyping(*boolval.value);
	}
	else if (str.ICompare("Editable") == 0)
	{
		prop->GetValue(&boolval);
		backend->MakeEditable(*boolval.value);
	}
	else if (str.ICompare("ColorSpace") == 0)
	{
		prop->GetValue(&intval);
		backend->SetColorSpace((color_space)*intval.value);
	}
	else if (str.ICompare("Text") == 0)
	{
		prop->GetValue(&stringval);
		backend->SetText(*stringval.value);
	}
	else if (str.ICompare("Resizable") == 0)
	{
		prop->GetValue(&boolval);
		backend->MakeResizable(*boolval.value);
	}
	else if (str.ICompare("Alignment") == 0)
	{
		prop->GetValue(&intval);
		backend->SetAlignment((alignment)*intval.value);
	}
	else if (str.ICompare("Undoable") == 0)
	{
		prop->GetValue(&boolval);
		backend->SetDoesUndo(*boolval.value);
	}
	else if (str.ICompare("AutoIndent") == 0)
	{
		prop->GetValue(&boolval);
		backend->SetAutoindent(*boolval.value);
	}
	else if (str.ICompare("Stylable") == 0)
	{
		prop->GetValue(&boolval);
		backend->SetStylable(*boolval.value);
	}
	else
	{
		if (backend->Window())
			backend->Window()->Unlock();

		return PView::SetProperty(name, value, index);
	}

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

	return prop->GetValue(value);
}
Example #6
0
void
BTextWidget::StartEdit(BRect bounds, BPoseView* view, BPose* pose)
{
	view->SetTextWidgetToCheck(NULL, this);
	if (!IsEditable() || IsActive())
		return;

	BEntry entry(pose->TargetModel()->EntryRef());
	if (entry.InitCheck() == B_OK
		&& !ConfirmChangeIfWellKnownDirectory(&entry,
			B_TRANSLATE_COMMENT("rename",
				"As in 'if you rename this folder...' (en) "
				"'Wird dieser Ordner umbenannt...' (de)"),
			B_TRANSLATE_COMMENT("rename",
				"As in 'to rename this folder...' (en) "
				"'Um diesen Ordner umzubenennen...' (de)"),
			B_TRANSLATE_COMMENT("Rename",
				"Button label, 'Rename' (en), 'Umbenennen' (de)")))
		return;

	// get bounds with full text length
	BRect rect(bounds);
	BRect textRect(bounds);
	rect.OffsetBy(-2, -1);
	rect.right += 1;

	BFont font;
	view->GetFont(&font);
	BTextView* textView = new BTextView(rect, "WidgetTextView", textRect,
		&font, 0, B_FOLLOW_ALL, B_WILL_DRAW);

	textView->SetWordWrap(false);
	DisallowMetaKeys(textView);
	fText->SetUpEditing(textView);

	textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter));

	rect.right = rect.left + textView->LineWidth() + 3;
	// center new width, if necessary
	if (view->ViewMode() == kIconMode
		|| (view->ViewMode() == kListMode && fAlignment == B_ALIGN_CENTER)) {
		rect.OffsetBy(bounds.Width() / 2 - rect.Width() / 2, 0);
	}

	rect.bottom = rect.top + textView->LineHeight() + 1;
	textRect = rect.OffsetToCopy(2, 1);
	textRect.right -= 3;
	textRect.bottom--;
	textView->SetTextRect(textRect);

	BPoint origin = view->LeftTop();
	textRect = view->Bounds();

	bool hitBorder = false;
	if (rect.left <= origin.x)
		rect.left = origin.x + 1, hitBorder = true;
	if (rect.right >= textRect.right)
		rect.right = textRect.right - 1, hitBorder = true;

	textView->MoveTo(rect.LeftTop());
	textView->ResizeTo(rect.Width(), rect.Height());

	BScrollView* scrollView = new BScrollView("BorderView", textView, 0, 0,
		false, false, B_PLAIN_BORDER);
	view->AddChild(scrollView);

	// configure text view
	switch (view->ViewMode()) {
		case kIconMode:
			textView->SetAlignment(B_ALIGN_CENTER);
			break;

		case kMiniIconMode:
			textView->SetAlignment(B_ALIGN_LEFT);
			break;

		case kListMode:
			textView->SetAlignment(fAlignment);
			break;
	}
	textView->MakeResizable(true, hitBorder ? NULL : scrollView);

	view->SetActivePose(pose);
		// tell view about pose
	SetActive(true);
		// for widget

	textView->SelectAll();
	textView->MakeFocus();

	// make this text widget invisible while we edit it
	SetVisible(false);

	ASSERT(view->Window() != NULL);
		// how can I not have a Window here???

	if (view->Window()) {
		// force immediate redraw so TextView appears instantly
		view->Window()->UpdateIfNeeded();
	}
}