コード例 #1
0
ファイル: ProgressWindow.cpp プロジェクト: mmanley/Antares
ProgressWindow::ProgressWindow(BWindow* referenceWindow, bool center)
	:
	BWindow(BRect(0, 0, 250, 100), "Progress monitor",
		B_MODAL_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL,
		B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS),
	fRunner(NULL)
{
	BRect rect = Bounds();

	BView *view = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(view);

	rect = view->Bounds().InsetByCopy(5, 5);
	fStatusBar = new BStatusBar(rect, "status", NULL, NULL);
	float width, height;
	fStatusBar->GetPreferredSize(&width, &height);
	fStatusBar->ResizeTo(rect.Width(), height);
	fStatusBar->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
	view->AddChild(fStatusBar);

	BScreen screen(referenceWindow);
	if (!center) {
		ResizeTo(Bounds().Width(), height + 9);
		// TODO: frame width!
		MoveTo(screen.Frame().left + 5,
			screen.Frame().bottom - Bounds().Height() - 5);
	} else
		CenterIn(screen.Frame());

	Run();
}
コード例 #2
0
FolderConfigWindow::FolderConfigWindow(BRect parent, const BMessage& settings)
	:
	BWindow(BRect(0, 0, 300, 300), B_TRANSLATE("IMAP Folders"),
		B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
		B_NO_WORKSPACE_ACTIVATION | B_NOT_ZOOMABLE | B_AVOID_FRONT),
	fSettings(settings)
{
	BView* rootView = new BView(Bounds(), "root", B_FOLLOW_ALL, B_WILL_DRAW);
	AddChild(rootView);
	rootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	float spacing = be_control_look->DefaultItemSpacing();
	BALMLayout* layout = new BALMLayout(spacing);
	rootView->SetLayout(layout);
	layout->SetInset(spacing);

	fFolderListView = new EditListView(B_TRANSLATE("IMAP Folders"));
	fFolderListView->SetExplicitPreferredSize(BSize(B_SIZE_UNLIMITED,
		B_SIZE_UNLIMITED));
	fApplyButton = new BButton("Apply", B_TRANSLATE("Apply"),
		new BMessage(kMsgApplyButton));

	fQuotaView = new BStringView("quota view",
		B_TRANSLATE("Failed to fetch available storage."));
	fQuotaView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_CENTER));

	layout->AddView(fFolderListView, layout->Left(), layout->Top(),
		layout->Right(), layout->Bottom());

	GroupItem item = GroupItem(fQuotaView) / GroupItem(fFolderListView)
		/ (GroupItem(BSpaceLayoutItem::CreateGlue())
			| GroupItem(fApplyButton));
	layout->BuildLayout(item);

	PostMessage(kMsgInit);

	BSize min = layout->MinSize();
	BSize max = layout->MaxSize();
	SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());

	CenterIn(parent);
}
コード例 #3
0
PromotionWindow::PromotionWindow(ChessBoardView* target)
	:
    BWindow(target->Frame(), "Please Choose", B_TITLED_WINDOW_LOOK,
                B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS
                    | B_NOT_CLOSABLE
                    | B_AUTO_UPDATE_SIZE_LIMITS | B_OUTLINE_RESIZE
                    | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE ),
    fTarget(target)
{
    BRect frame = BRect(0, 0, fTarget->fIR.Width()*8, fTarget->fIR.Width()*8);

    frame.OffsetBySelf(fTarget->Window()->Frame().LeftTop());
    frame.OffsetBySelf(fTarget->Frame().LeftTop());
    frame.OffsetBySelf(fTarget->fBoard2dOffset);

    ImageButton* (button)[4];
    BString nameW[4] = {"wQ", "wR", "wB", "wN"};
    BString nameB[4] = {"bQ", "bR", "bB", "bN"};

    int     valW[4] = {Q_W, R_W, B_W, N_W};
    int     valB[4] = {Q_B, R_B, B_B, N_B};

    for (int i = 0; i < 4; ++i) {
        if (fTarget->IsWhiteTurn() == false)
            button[i] = new ImageButton(nameW[i], new BMessage(valW[i]), 0.1);
        else
            button[i] = new ImageButton(nameB[i], new BMessage(valB[i]), 0.1);

        button[i]->SetExplicitMinSize(BSize(frame.Width()/5, frame.Width()/5));
        button[i]->SetExplicitMaxSize(BSize(frame.Width()/5, frame.Width()/5));
    }
    //if (isWhite) name = ;

	BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0)
		.Add(button[0]).Add(button[1]).Add(button[2]).Add(button[3])
	;

    CenterIn(frame);
    Show();
}
コード例 #4
0
ファイル: RatePackageWindow.cpp プロジェクト: mylegacy/haiku
RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)
	:
	BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"),
		B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
	fRatingText()
{
	AddToSubset(parent);
	CenterIn(parent->Frame());

	TextDocumentView* textView = new TextDocumentView();
	ScrollView* textScrollView = new ScrollView(
		"rating scroll view", textView);

	MarkupParser parser;
	fRatingText = parser.CreateDocumentFromMarkup(
		"Here is where you ''could'' type your awesome rating comment, "
		"if only this were already implemented.");

	textView->SetInsets(10.0f);
	textView->SetTextDocument(fRatingText);
	textView->SetTextEditor(TextEditorRef(new TextEditor(), true));

	fSendButton = new BButton("send", B_TRANSLATE("Send"),
		new BMessage(MSG_SEND));

	// Build layout
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.Add(textScrollView)
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fSendButton)
		.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
	;
}
コード例 #5
0
ファイル: CreateParamsPanel.cpp プロジェクト: mmanley/Antares
int32
CreateParamsPanel::Go(off_t& offset, off_t& size, BString& name,
	BString& type, BString& parameters)
{
	// run the window thread, to get an initial layout of the controls
	Hide();
	Show();
	if (!Lock())
		return GO_CANCELED;

	// center the panel above the parent window
	CenterIn(fWindow->Frame());

	Show();
	Unlock();

	// block this thread now, but keep the window repainting
	while (true) {
		status_t err = acquire_sem_etc(fExitSemaphore, 1,
			B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000);
		if (err != B_TIMED_OUT && err != B_INTERRUPTED)
			break;
		fWindow->UpdateIfNeeded();
	}

	if (!Lock())
		return GO_CANCELED;

	if (fReturnValue == GO_SUCCESS) {
		// Return the value back as bytes.
		size = (off_t)fSizeSlider->Size() * kMegaByte;
		offset = (off_t)fSizeSlider->Offset() * kMegaByte;

		// get name
		name.SetTo(fNameTextControl->Text());

		// get type
		if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
			const char* _type;
			BMessage* message = item->Message();
			if (!message || message->FindString("type", &_type) < B_OK)
				_type = kPartitionTypeBFS;
			type << _type;
		}

		// get editors parameters
		if (fEditor != NULL) {
			if (fEditor->FinishedEditing()) {
				status_t status = fEditor->GetParameters(&parameters);
				if (status != B_OK)
					fReturnValue = status;
			}
		}
	}

	int32 value = fReturnValue;

	Quit();
		// NOTE: this object is toast now!

	return value;
}
コード例 #6
0
bool AuthenticationPanel::getAuthentication(const BString& text,
    const BString& previousUser, const BString& previousPass,
	bool previousRememberCredentials, bool badPassword,
	BString& user, BString&  pass, bool* rememberCredentials)
{
	// Configure panel and layout controls.
	rgb_color infoColor = ui_color(B_PANEL_TEXT_COLOR);
	BRect textBounds(0, 0, 250, 200);
	BTextView* textView = new BTextView(textBounds, "text", textBounds,
	    be_plain_font, &infoColor, B_FOLLOW_NONE, B_WILL_DRAW | B_SUPPORTS_LAYOUT);
	textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	textView->SetText(text.String());
	textView->MakeEditable(false);
	textView->MakeSelectable(false);

    m_usernameTextControl->SetText(previousUser.String());
	m_passwordTextControl->TextView()->HideTyping(true);
	// Ignore the previous password, if it didn't work.
	if (!badPassword)
	    m_passwordTextControl->SetText(previousPass.String());
	m_hidePasswordCheckBox->SetValue(B_CONTROL_ON);
	m_rememberCredentialsCheckBox->SetValue(previousRememberCredentials);

	// create layout
	SetLayout(new BGroupLayout(B_VERTICAL, 0.0));
	float spacing = be_control_look->DefaultItemSpacing();
	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0.0)
	    .Add(BGridLayoutBuilder(0, spacing)
	        .Add(textView, 0, 0, 2)
	        .Add(m_usernameTextControl->CreateLabelLayoutItem(), 0, 1)
	        .Add(m_usernameTextControl->CreateTextViewLayoutItem(), 1, 1)
	        .Add(m_passwordTextControl->CreateLabelLayoutItem(), 0, 2)
	        .Add(m_passwordTextControl->CreateTextViewLayoutItem(), 1, 2)
	        .Add(BSpaceLayoutItem::CreateGlue(), 0, 3)
	        .Add(m_hidePasswordCheckBox, 1, 3)
	        .Add(m_rememberCredentialsCheckBox, 0, 4, 2)
	        .SetInsets(spacing, spacing, spacing, spacing)
	    )
	    .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
	    .Add(BGroupLayoutBuilder(B_HORIZONTAL, spacing)
	        .AddGlue()
	        .Add(m_cancelButton)
	        .Add(m_okButton)
	        .SetInsets(spacing, spacing, spacing, spacing)
	    )
	);

	float textHeight = textView->LineHeight(0) * textView->CountLines();
	textView->SetExplicitMinSize(BSize(B_SIZE_UNSET, textHeight));

	SetDefaultButton(m_okButton);
	if (badPassword && previousUser.Length())
	    m_passwordTextControl->MakeFocus(true);
	else
	    m_usernameTextControl->MakeFocus(true);

    if (m_parentWindowFrame.IsValid())
        CenterIn(m_parentWindowFrame);
    else
        CenterOnScreen();

	// Start AuthenticationPanel window thread
	Show();

	// Let the window jitter, if the previous password was invalid
	if (badPassword)
		PostMessage(kMsgJitter);

	// Block calling thread
	// Get the originating window, if it exists, to let it redraw itself.
	BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
	if (window) {
		status_t err;
		for (;;) {
			do {
				err = acquire_sem_etc(m_exitSemaphore, 1, B_RELATIVE_TIMEOUT, 10000);
				// We've (probably) had our time slice taken away from us
			} while (err == B_INTERRUPTED);

			if (err != B_TIMED_OUT) {
				// Semaphore was finally released or nuked.
				break;
			}
			window->UpdateIfNeeded();
		}
	} else {
		// No window to update, so just hang out until we're done.
		while (acquire_sem(m_exitSemaphore) == B_INTERRUPTED) {
		}
	}

	// AuthenticationPanel wants to quit.
	Lock();

	user = m_usernameTextControl->Text();
	pass = m_passwordTextControl->Text();
	if (rememberCredentials)
        *rememberCredentials = m_rememberCredentialsCheckBox->Value() == B_CONTROL_ON;

    bool canceled = m_cancelled;
	Quit();
	// AuthenticationPanel object is TOAST here.
	return !canceled;
}
コード例 #7
0
RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame,
	Model& model)
	:
	BWindow(frame, B_TRANSLATE("Rate package"),
		B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
	fModel(model),
	fRatingText(),
	fTextEditor(new TextEditor(), true),
	fRating(-1.0f),
	fCommentLanguage(fModel.PreferredLanguage()),
	fWorkerThread(-1)
{
	AddToSubset(parent);

	BStringView* ratingLabel = new BStringView("rating label",
		B_TRANSLATE("Your rating:"));

	fSetRatingView = new SetRatingView();

	fTextView = new TextDocumentView();
	ScrollView* textScrollView = new ScrollView(
		"rating scroll view", fTextView);

	// Get a TextDocument with default paragraph and character style
	MarkupParser parser;
	fRatingText = parser.CreateDocumentFromMarkup("");

	fTextView->SetInsets(10.0f);
	fTextView->SetTextDocument(fRatingText);
	fTextView->SetTextEditor(fTextEditor);

	// Construct stability rating popup
	BPopUpMenu* stabilityMenu = new BPopUpMenu(B_TRANSLATE("Stability"));
	fStabilityField = new BMenuField("stability",
		B_TRANSLATE("Stability:"), stabilityMenu);

	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Not specified"), "unspecified"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Stable"), "stable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Mostly stable"), "mostlystable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Unstable but usable"), "unstablebutusable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Very unstable"), "veryunstable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Does not start"), "nostart"));

	add_stabilities_to_menu(fStabilityCodes, stabilityMenu);
	stabilityMenu->SetTargetForItems(this);

	fStability = fStabilityCodes.ItemAt(0).Name();
	stabilityMenu->ItemAt(0)->SetMarked(true);

	// Construct languages popup
	BPopUpMenu* languagesMenu = new BPopUpMenu(B_TRANSLATE("Language"));
	fCommentLanguageField = new BMenuField("language",
		B_TRANSLATE("Comment language:"), languagesMenu);

	add_languages_to_menu(fModel.SupportedLanguages(), languagesMenu);
	languagesMenu->SetTargetForItems(this);

	BMenuItem* defaultItem = languagesMenu->ItemAt(
		fModel.SupportedLanguages().IndexOf(fCommentLanguage));
	if (defaultItem != NULL)
		defaultItem->SetMarked(true);

	fRatingActiveCheckBox = new BCheckBox("rating active",
		B_TRANSLATE("Other users can see this rating"),
		new BMessage(MSG_RATING_ACTIVE_CHANGED));
	// Hide the check mark by default, it will be made visible when
	// the user already made a rating and it is loaded
	fRatingActiveCheckBox->Hide();

	// Construct buttons
	fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
		new BMessage(B_QUIT_REQUESTED));

	fSendButton = new BButton("send", B_TRANSLATE("Send"),
		new BMessage(MSG_SEND));

	// Build layout
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.AddGrid()
			.Add(ratingLabel, 0, 0)
			.Add(fSetRatingView, 1, 0)
			.AddMenuField(fStabilityField, 0, 1)
			.AddMenuField(fCommentLanguageField, 0, 2)
		.End()
		.Add(textScrollView)
		.AddGroup(B_HORIZONTAL)
			.Add(fRatingActiveCheckBox)
			.AddGlue()
			.Add(fCancelButton)
			.Add(fSendButton)
		.End()
		.SetInsets(B_USE_WINDOW_INSETS)
	;

	// NOTE: Do not make Send the default button. The user might want
	// to type line-breaks instead of sending when hitting RETURN.

	CenterIn(parent->Frame());
}