示例#1
0
文件: Alert.cpp 项目: tqh/haiku-efi
BAlert::BAlert(BMessage* data)
	:
	BWindow(data)
{
	fInvoker = NULL;
	fAlertSem = -1;
	fAlertValue = -1;

	fTextView = (BTextView*)FindView("_tv_");

	// TODO: window loses default button on dearchive!
	// TODO: ButtonAt() doesn't work afterwards (also affects shortcuts)

	TAlertView* view = (TAlertView*)FindView("_master_");
	if (view)
		view->SetBitmap(_CreateTypeIcon());

	// Get keys
	char key;
	for (int32 i = 0; i < 3; ++i) {
		if (data->FindInt8("_but_key", i, (int8*)&key) == B_OK)
			fKeys[i] = key;
	}

	AddCommonFilter(new(std::nothrow) _BAlertFilter_(this));
}
示例#2
0
文件: Alert.cpp 项目: mmanley/Antares
BAlert::BAlert(BMessage* data)
	: BWindow(data)
{
	fInvoker = NULL;
	fAlertSem = -1;
	fAlertValue = -1;

	fTextView = (BTextView*)FindView("_tv_");

	fButtons[0] = (BButton*)FindView("_b0_");
	fButtons[1] = (BButton*)FindView("_b1_");
	fButtons[2] = (BButton*)FindView("_b2_");

	if (fButtons[2])
		SetDefaultButton(fButtons[2]);
	else if (fButtons[1])
		SetDefaultButton(fButtons[1]);
	else if (fButtons[0])
		SetDefaultButton(fButtons[0]);

	TAlertView* view = (TAlertView*)FindView("_master_");
	if (view)
		view->SetBitmap(_InitIcon());

	// Get keys
	char key;
	for (int32 i = 0; i < 3; ++i) {
		if (data->FindInt8("_but_key", i, (int8*)&key) == B_OK)
			fKeys[i] = key;
	}

	int32 temp;
	// Get alert type
	if (data->FindInt32("_atype", &temp) == B_OK)
		fMsgType = (alert_type)temp;

	// Get button width
	if (data->FindInt32("_but_width", &temp) == B_OK)
		fButtonWidth = (button_width)temp;

	AddCommonFilter(new(std::nothrow) _BAlertFilter_(this));
}
示例#3
0
MediaAlert::MediaAlert(BRect _rect, const char* title, const char* text)
	: BWindow(_rect, title, B_MODAL_WINDOW, B_NOT_CLOSABLE | B_NOT_RESIZABLE)
{
	fTextView = NULL;

	// Set up the "_master_" view
	TAlertView* masterView = new TAlertView(Bounds());
	masterView->SetBitmap(InitIcon());
	AddChild(masterView);

	// Set up the text view
	BRect textViewRect(kTextIconOffset, kTextTopOffset,
		Bounds().right, Bounds().bottom);
	BRect rect = textViewRect;
	rect.OffsetTo(B_ORIGIN);
	rect.InsetBy(4, 2);

	fTextView = new BTextView(textViewRect, "_tv_", rect,
		B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
	fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	fTextView->SetText(text, strlen(text));
	fTextView->MakeEditable(false);
	fTextView->MakeSelectable(false);
	fTextView->SetWordWrap(true);
	fTextView->SetFontAndColor(be_bold_font);

	masterView->AddChild(fTextView);

	BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame();
	BPoint pt;
	pt.x = screenFrame.Width() / 2 - Bounds().Width() / 2;
	pt.y = screenFrame.Height() / 2 - Bounds().Height() / 2;

	if (screenFrame.Contains(pt))
		MoveTo(pt);
}
示例#4
0
文件: Alert.cpp 项目: mmanley/Antares
void
BAlert::_InitObject(const char* text, const char* button0, const char* button1,
	const char* button2, button_width buttonWidth, button_spacing spacing,
	alert_type type)
{
	fInvoker = NULL;
	fAlertSem = -1;
	fAlertValue = -1;
	fButtons[0] = fButtons[1] = fButtons[2] = NULL;
	fTextView = NULL;
	fKeys[0] = fKeys[1] = fKeys[2] = 0;
	fMsgType = type;
	fButtonWidth = buttonWidth;

	// Set up the "_master_" view
	TAlertView* view = new(std::nothrow) TAlertView(Bounds());
	if (view == NULL)
		return;

	AddChild(view);
	view->SetBitmap(_InitIcon());

	// Must have at least one button
	if (button0 == NULL) {
		debugger("BAlerts must have at least one button.");
		button0 = "";
	}

	// Set up the buttons

	int32 buttonCount = 1;
	view->AddChild(fButtons[0] = _CreateButton(0, button0));

	if (button1 != NULL) {
		view->AddChild(fButtons[1] = _CreateButton(1, button1));
		buttonCount++;
	}

	if (button2 != NULL) {
		view->AddChild(fButtons[2] = _CreateButton(2, button2));
		buttonCount++;
	}

	// Find the widest button only if the widest value needs to be known.

	if (fButtonWidth == B_WIDTH_FROM_WIDEST) {
		float maxWidth = 0;
		for (int i = 0; i < buttonCount; i++) {
			float width = fButtons[i]->Bounds().Width();
			if (width > maxWidth)
				maxWidth = width;
		}

		// resize buttons
		for (int i = 0; i < buttonCount; i++) {
			fButtons[i]->ResizeTo(maxWidth, fButtons[i]->Bounds().Height());
		}
	}

	float defaultButtonFrameWidth = -fButtons[buttonCount - 1]->Bounds().Width() / 2.0f;
	SetDefaultButton(fButtons[buttonCount - 1]);
	defaultButtonFrameWidth += fButtons[buttonCount - 1]->Bounds().Width() / 2.0f;

	// Layout buttons

	float fontFactor = be_plain_font->Size() / 11.0f;

	for (int i = buttonCount - 1; i >= 0; --i) {
		float x = -fButtons[i]->Bounds().Width();
		if (i + 1 == buttonCount)
			x += Bounds().right - kRightOffset + defaultButtonFrameWidth;
		else
			x += fButtons[i + 1]->Frame().left - kButtonSpacing;

		if (buttonCount > 1 && i == 0 && spacing == B_OFFSET_SPACING)
			x -= kButtonOffsetSpacing * fontFactor;

		fButtons[i]->MoveTo(x, fButtons[i]->Frame().top);
	}

	// Adjust the window's width, if necessary

	int32 iconLayoutScale = icon_layout_scale();
	float totalWidth = kRightOffset + fButtons[buttonCount - 1]->Frame().right
		- defaultButtonFrameWidth - fButtons[0]->Frame().left;
	if (view->Bitmap()) {
		totalWidth += (kIconStripeWidth + kWindowIconOffset) * iconLayoutScale;
	} else
		totalWidth += kWindowMinOffset;

	float width = (spacing == B_OFFSET_SPACING
		? kWindowOffsetMinWidth : kWindowMinWidth) * fontFactor;

	ResizeTo(max_c(totalWidth, width), Bounds().Height());

	// Set up the text view

	BRect textViewRect(kLeftOffset, kTopOffset,
		Bounds().right - kRightOffset,
		fButtons[0]->Frame().top - kTextButtonOffset);
	if (view->Bitmap())
		textViewRect.left = (kWindowIconOffset
			+ kIconStripeWidth) * iconLayoutScale - 2;

	fTextView = new(std::nothrow) BTextView(textViewRect, "_tv_",
		textViewRect.OffsetByCopy(B_ORIGIN),
		B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
	if (fTextView == NULL)
		return;

	fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
	fTextView->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
	fTextView->SetText(text, strlen(text));
	fTextView->MakeEditable(false);
	fTextView->MakeSelectable(false);
	fTextView->SetWordWrap(true);
	view->AddChild(fTextView);

	// Now resize the TextView vertically so that all the text is visible
	float textHeight = fTextView->TextHeight(0, fTextView->CountLines());
	textViewRect.OffsetTo(0, 0);
	textHeight -= textViewRect.Height();
	ResizeBy(0, textHeight);
	fTextView->ResizeBy(0, textHeight);
	textViewRect.bottom += textHeight;
	fTextView->SetTextRect(textViewRect);

	AddCommonFilter(new(std::nothrow) _BAlertFilter_(this));

	MoveTo(AlertPosition(Frame().Width(), Frame().Height()));
}