Esempio n. 1
0
LoginAlert::LoginAlert(nserror (*callback)(const char *username,
						const char *password,
						void *pw),
				void *callbackpw,
				nsurl *url, 
				const char *host, 
				const char *realm, 
				const char *text)
	: BAlert("Login", text, "Cancel", "Ok", NULL, 
		B_WIDTH_AS_USUAL, B_WARNING_ALERT)
{
	fCallback = callback;
	fCallbackPw = callbackpw;
	fUrl = url;
	fHost = host;
	fRealm = realm;

	SetFeel(B_MODAL_SUBSET_WINDOW_FEEL);
	/*
	// XXX: can't do that anymore
	nsbeos_scaffolding *s = nsbeos_get_scaffold(bw->window);
	if (s) {
		NSBrowserWindow *w = nsbeos_get_bwindow_for_scaffolding(s);
		if (w)
			AddToSubset(w);
	}*/

	// make space for controls
	ResizeBy(0, 2 * TC_H);
	MoveTo(AlertPosition(Frame().Width() + 1, 
		Frame().Height() + 1));


	BTextView *tv = TextView();
	BRect r(TC_MARGIN, tv->Bounds().bottom - 2 * TC_H, 
		tv->Bounds().right - TC_MARGIN, tv->Bounds().bottom - TC_H);

	fUserControl = new BTextControl(r, "user", "Username", "", 
		new BMessage(), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
	fUserControl->SetDivider(60);
	tv->AddChild(fUserControl);

	r.OffsetBySelf(0, TC_H);

	fPassControl = new BTextControl(r, "pass", "Password", "", 
		new BMessage(), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
	fPassControl->TextView()->HideTyping(true);
	fPassControl->SetDivider(60);
	tv->AddChild(fPassControl);
	
	SetShortcut(0, B_ESCAPE);
}
Esempio n. 2
0
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()));
}