Example #1
0
void
DTipWatcherView::ShowTip(BPoint pt, const char *text)
{
	if (!text)
		return;
	
	Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
	
	fTipView->SetText(text);
	
	// Figure the size of the tip. We do have a maximum width of 200 and a maximum height of 400, but
	// we only want to use the maximum size if it's necessary.
	fTipView->ResizeTo(200,400);
	fTipView->SetTextRect(BRect(2,2,198,398));
	
	int32 lineCount = fTipView->CountLines();
	float width = 200.0;
	
	if (lineCount == 1)
		width = fTipView->LineWidth() + 4;
	
	float height = fTipView->TextHeight(0,lineCount);
	height = (height < 400) ? height : 400;
	Window()->ResizeTo(width,height);
	
	fTipView->SetTextRect(BRect(2,2, width - 4, height - 4));
	
	BPoint winpt = PointForTip(pt);
	Window()->MoveTo(winpt.x,winpt.y);
	Window()->Show();
}
void
ConfigWindow::MakeHowToView()
{
	BResources *resources = BApplication::AppResources();
	if (resources)
	{
		size_t length;
		char *buffer = (char *)resources->FindResource('ICON',101,&length);
		if (buffer)
		{
			BBitmap *bitmap = new BBitmap(BRect(0,0,63,63),B_CMAP8);
			if (bitmap && bitmap->InitCheck() == B_OK)
			{
				// copy and enlarge a 32x32 8-bit bitmap
				char *bits = (char *)bitmap->Bits();
				for (int32 i = 0,j = -64;i < length;i++)
				{
					if ((i % 32) == 0)
						j += 64;

					char *b = bits + (i << 1) + j;
					b[0] = b[1] = b[64] = b[65] = buffer[i];
				}
				fConfigView->AddChild(new BitmapView(bitmap));
			}
			else
				delete bitmap;
		}
	}

	BRect rect = fConfigView->Bounds();
	BTextView *text = new BTextView(rect,NULL,rect,B_FOLLOW_NONE,B_WILL_DRAW);
	text->SetViewColor(fConfigView->Parent()->ViewColor());
	text->SetAlignment(B_ALIGN_CENTER);
	text->SetText(
		MDR_DIALECT_CHOICE ("\n\nCreate a new account using the \"Add\" button.\n\n"
		"Delete accounts (or only the inbound/outbound) by using the \"Remove\" button on the selected item.\n\n"
		"Select an item in the list to edit its configuration.",
		"\n\nアカウントの新規作成は\"追加\"ボタンを\n使います。"
		"\n\nアカウント自体またはアカウントの\n送受信設定を削除するには\n項目を選択して\"削除\"ボタンを使います。"
		"\n\nアカウント内容の変更は、\nマウスで項目をクリックしてください。"));
	rect = text->Bounds();
	text->ResizeTo(rect.Width(),text->TextHeight(0,42));
	text->SetTextRect(rect);

	text->MakeEditable(false);
	text->MakeSelectable(false);

	fConfigView->AddChild(text);
	
	static_cast<CenterContainer *>(fConfigView)->Layout();
}
Example #3
0
void ArpTextControl::FrameResized(float new_width, float new_height)
{
	ArpD(cdb << ADH << "ArpTextControl: FrameResized(" << new_width
			<< ", " << new_height << ")" << endl);
	BTextView* text = dynamic_cast<BTextView*>(ChildAt(0));
	if( !text ) ArpD(cdb << ADH << "!!! No BTextView !!!" << endl);
	if( text ) {
		ArpD(cdb << ADH << "BTextView: Initial Bounds=" << text->Bounds()
			<< ", TextRect=" << text->TextRect() << endl);
	}
	BTextControl::FrameResized(new_width, new_height);
	BRect textBounds(text->Bounds());
	BRect textRect(text->TextRect());
	textRect.right = textRect.left + text->LineWidth(0)-1;
	if( textRect.Width() < textBounds.Width() ) {
		textRect.right = textRect.left + textBounds.Width()-1;
	}
	text->SetTextRect(textRect);
	if( text ) {
		ArpD(cdb << ADH << "BTextView: Finish Bounds=" << text->Bounds()
			<< ", TextRect=" << text->TextRect() << endl);
	}
}
Example #4
0
void
ConfigWindow::_MakeHowToView()
{
	app_info info;
	if (be_app->GetAppInfo(&info) == B_OK) {
		BFile appFile(&info.ref, B_READ_ONLY);
		BAppFileInfo appFileInfo(&appFile);
		if (appFileInfo.InitCheck() == B_OK) {
			BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63),
				B_RGBA32);
			if (appFileInfo.GetIcon(bitmap, B_LARGE_ICON) == B_OK) {
				fConfigView->AddChild(new BitmapView(bitmap));
			} else
				delete bitmap;
		}
	}

	BRect rect = fConfigView->Bounds();
	BTextView *text = new BTextView(rect, NULL, rect, B_FOLLOW_NONE,
		B_WILL_DRAW);
	text->SetViewColor(fConfigView->Parent()->ViewColor());
	text->SetAlignment(B_ALIGN_CENTER);
	text->SetText(B_TRANSLATE(
		"\n\nCreate a new account with the Add button.\n\n"
		"Remove an account with the Remove button on the selected item.\n\n"
		"Select an item in the list to change its settings."));
	rect = text->Bounds();
	text->ResizeTo(rect.Width(), text->TextHeight(0, 42));
	text->SetTextRect(rect);

	text->MakeEditable(false);
	text->MakeSelectable(false);

	fConfigView->AddChild(text);

	fConfigView->Layout();
}
Example #5
0
void
ConfigWindow::MakeHowToView()
{
#ifndef HAIKU_TARGET_PLATFORM_HAIKU
    BResources *resources = BApplication::AppResources();
    if (resources) {
        size_t length;
        char *buffer = (char *)resources->FindResource(B_LARGE_ICON_TYPE, 101,
                       &length);
        if (buffer) {
            BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63),
                                                    B_CMAP8);
            if (bitmap && bitmap->InitCheck() == B_OK) {
                // copy and enlarge a 32x32 8-bit bitmap
                char *bits = (char *)bitmap->Bits();
                for (int32 i = 0, j = -64; i < (int32)length; i++) {
                    if ((i % 32) == 0)
                        j += 64;

                    char *b = bits + (i << 1) + j;
                    b[0] = b[1] = b[64] = b[65] = buffer[i];
                }
                fConfigView->AddChild(new BitmapView(bitmap));
            } else
                delete bitmap;
        }
    }
#else
    app_info info;
    if (be_app->GetAppInfo(&info) == B_OK) {
        BFile appFile(&info.ref, B_READ_ONLY);
        BAppFileInfo appFileInfo(&appFile);
        if (appFileInfo.InitCheck() == B_OK) {
            BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63),
                                                    B_RGBA32);
            if (appFileInfo.GetIcon(bitmap, B_LARGE_ICON) == B_OK) {
                fConfigView->AddChild(new BitmapView(bitmap));
            } else
                delete bitmap;
        }
    }
#endif // HAIKU_TARGET_PLATFORM_HAIKU

    BRect rect = fConfigView->Bounds();
    BTextView *text = new BTextView(rect, NULL, rect, B_FOLLOW_NONE,
                                    B_WILL_DRAW);
    text->SetViewColor(fConfigView->Parent()->ViewColor());
    text->SetAlignment(B_ALIGN_CENTER);
    text->SetText(B_TRANSLATE(
                      "\n\nCreate a new account with the Add button.\n\n"
                      "Remove an account with the Remove button on the selected item.\n\n"
                      "Select an item in the list to change its settings."));
    rect = text->Bounds();
    text->ResizeTo(rect.Width(), text->TextHeight(0, 42));
    text->SetTextRect(rect);

    text->MakeEditable(false);
    text->MakeSelectable(false);

    fConfigView->AddChild(text);

    static_cast<CenterContainer *>(fConfigView)->Layout();
}
Example #6
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 #7
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 #8
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();
	}
}