コード例 #1
0
void
ExpressionPromptWindow::_Init()
{
	fExpressionInput = new BTextControl("Expression:", NULL, NULL);
	BLayoutItem* labelItem = fExpressionInput->CreateLabelLayoutItem();
	BLayoutItem* inputItem = fExpressionInput->CreateTextViewLayoutItem();
	inputItem->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET));
	inputItem->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
	labelItem->View()->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.SetInsets(B_USE_DEFAULT_SPACING)
		.AddGroup(B_HORIZONTAL, 4.0f)
			.Add(labelItem)
			.Add(inputItem)
		.End()
		.AddGroup(B_HORIZONTAL, 4.0f)
			.AddGlue()
			.Add((fCancelButton = new BButton("Cancel",
					new BMessage(B_QUIT_REQUESTED))))
			.Add((fAddButton = new BButton("Add",
					new BMessage(MSG_ADD_NEW_EXPRESSION))))
		.End();

	fExpressionInput->SetTarget(this);
	fCancelButton->SetTarget(this);
	fAddButton->SetTarget(this);
	fAddButton->MakeDefault(true);
	fExpressionInput->TextView()->MakeFocus(true);
}
コード例 #2
0
void
BreakpointEditWindow::_Init()
{
	fConditionInput = new BTextControl(NULL, NULL, NULL);
	BLayoutItem* textLayoutItem = fConditionInput->CreateTextViewLayoutItem();
	textLayoutItem->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET));
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.SetInsets(B_USE_DEFAULT_SPACING)
		.Add((fAlwaysRadio = new BRadioButton("Break always",
				new BMessage(MSG_SET_BREAK_ALWAYS))))
		.AddGroup(B_HORIZONTAL)
			.Add((fConditionRadio = new BRadioButton("Break on condition: ",
				new BMessage(MSG_SET_BREAK_ON_CONDITION))))
			.Add(textLayoutItem)
		.End()
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add((fSaveButton = new BButton("Save",
				new BMessage(MSG_SAVE_BREAKPOINT_SETTINGS))))
			.Add((fCancelButton = new BButton("Cancel",
				new BMessage(B_CANCEL))))
		.End()
	.End();

	AutoLocker< ::Team> teamLocker(fTeam);
	if (fTargetBreakpoint->HasCondition()) {
		fConditionRadio->SetValue(B_CONTROL_ON);
		fConditionInput->SetText(fTargetBreakpoint->Condition());
	} else {
		fAlwaysRadio->SetValue(B_CONTROL_ON);
		fConditionInput->SetEnabled(false);
	}
}
コード例 #3
0
LaunchButton*
PadView::ButtonAt(int32 index) const
{
	BLayoutItem* item = fButtonLayout->ItemAt(index);
	if (item == NULL)
		return NULL;
	return dynamic_cast<LaunchButton*>(item->View());
}
コード例 #4
0
ファイル: TabManager.cpp プロジェクト: AmirAbrams/haiku
BView*
TabManager::ViewForTab(int32 tabIndex) const
{
	BLayoutItem* item = fCardLayout->ItemAt(tabIndex);
	if (item != NULL)
		return item->View();
	return NULL;
}
コード例 #5
0
ファイル: NamePanel.cpp プロジェクト: DonCN/haiku
NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
		BHandler* target, BMessage* message, const BSize& size)
	:
	Panel(BRect(B_ORIGIN, size), B_TRANSLATE("Name Panel"),
		B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE
			| B_AUTO_UPDATE_SIZE_LIMITS),
	fWindow(window),
	fTarget(target),
	fMessage(message)
{
	BButton* defaultButton = new BButton(B_TRANSLATE("OK"),
		new BMessage(MSG_PANEL_OK));
	BButton* cancelButton = new BButton(B_TRANSLATE("Cancel"),
		new BMessage(MSG_PANEL_CANCEL));
	fNameTC = new BTextControl(label, text, NULL);
	BLayoutItem* inputItem = fNameTC->CreateTextViewLayoutItem();
	inputItem->SetExplicitMinSize(
		BSize(fNameTC->StringWidth("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
			B_SIZE_UNSET));

	BLayoutBuilder::Group<>(this, B_VERTICAL, 10)
		.AddGlue()

		// controls
		.AddGroup(B_HORIZONTAL, 5)
			.AddStrut(5)

			// text control
			.Add(fNameTC->CreateLabelLayoutItem())
			.Add(inputItem)
			.AddStrut(5)
			.End()

		.AddGlue()

		// buttons
		.AddGroup(B_HORIZONTAL, 5)
			.AddGlue()
			.Add(cancelButton)
			.Add(defaultButton)
			.AddStrut(5)
			.End()

		.AddGlue();

	SetDefaultButton(defaultButton);
	fNameTC->MakeFocus(true);

	if (fWindow && fWindow->Lock()) {
		fSavedTargetWindowFeel = fWindow->Feel();
		if (fSavedTargetWindowFeel != B_NORMAL_WINDOW_FEEL)
			fWindow->SetFeel(B_NORMAL_WINDOW_FEEL);
		fWindow->Unlock();
	}	

	AddToSubset(fWindow);
}
コード例 #6
0
ファイル: TabManager.cpp プロジェクト: AmirAbrams/haiku
int32
TabManager::TabForView(const BView* containedView) const
{
	int32 count = fCardLayout->CountItems();
	for (int32 i = 0; i < count; i++) {
		BLayoutItem* item = fCardLayout->ItemAt(i);
		if (item->View() == containedView)
			return i;
	}
	return -1;
}
コード例 #7
0
ファイル: Layout.cpp プロジェクト: mariuz/haiku
int32
BLayout::IndexOfView(BView* child) const
{
	int itemCount = fItems.CountItems();
	for (int32 i = 0; i < itemCount; i++) {
		BLayoutItem* item = (BLayoutItem*)fItems.ItemAt(i);
		if (dynamic_cast<BViewLayoutItem*>(item) && item->View() == child)
			return i;
	}

	return -1;
}
コード例 #8
0
ファイル: TwoDimensionalLayout.cpp プロジェクト: mariuz/haiku
void
BTwoDimensionalLayout::LayoutView()
{
	_ValidateMinMax();

	// layout the horizontal/vertical elements
	BSize size = SubtractInsets(View()->Frame().Size());

#ifdef DEBUG_LAYOUT
printf("BTwoDimensionalLayout::LayoutView(%p): size: (%.1f, %.1f)\n",
View(), size.width, size.height);
#endif

	fLocalLayouter->Layout(size);

	// layout the items
	int itemCount = CountItems();
	for (int i = 0; i < itemCount; i++) {
		BLayoutItem* item = ItemAt(i);
		if (item->IsVisible()) {
			Dimensions itemDimensions;
			GetItemDimensions(item, &itemDimensions);
			BRect frame = fLocalLayouter->ItemFrame(itemDimensions);
			frame.left += fLeftInset;
			frame.top += fTopInset;
			frame.right += fLeftInset;
			frame.bottom += fTopInset;
{
#ifdef DEBUG_LAYOUT
printf("  frame for item %2d (view: %p): ", i, item->View());
frame.PrintToStream();
#endif
//BSize min(item->MinSize());
//BSize max(item->MaxSize());
//printf("    min: (%.1f, %.1f), max: (%.1f, %.1f)\n", min.width, min.height,
//	max.width, max.height);
//if (item->HasHeightForWidth()) {
//float minHeight, maxHeight, preferredHeight;
//item->GetHeightForWidth(frame.Width(), &minHeight, &maxHeight,
//	&preferredHeight);
//printf("    hfw: min: %.1f, max: %.1f, pref: %.1f\n", minHeight, maxHeight,
//	preferredHeight);
//}
}

			item->AlignInFrame(frame);
		}
//else
//printf("  item %2d not visible", i);
	}
}
コード例 #9
0
/*!	
 *	\brief			Default constructor
 *	\param[in]	frame	The rectangle enclosing the view
 *	\param[in]	name	Name of the view. Will be passed to BView's constructor.
 *
 */
CalendarModulePreferencesView::CalendarModulePreferencesView( BRect frame )
	:
	BView( BRect( frame.left, frame.top, frame.right, frame.bottom-10 ), 
		 "Calendar Module Preferences",
		 B_FOLLOW_LEFT | B_FOLLOW_TOP,
		 B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS )
{
	BRect tempFrame = this->Bounds();	// Got the boundaries
	
	this->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
	tempFrame.InsetBySelf( 5, 5 );
	tempFrame.bottom -= 10;
	
	/* Add the chooser for the calendar modules */
	BGroupLayout* groupLayout = new BGroupLayout( B_VERTICAL );
	if ( !groupLayout ) {
		/* Panic! */
		exit( 1 );
	}
	groupLayout->SetSpacing( 2 );
	this->SetLayout( groupLayout );
	
	// Create the menu with all supported calendar modules
	calendarModules = PopulateModulesMenu();
	if ( ! calendarModules ) {
		/* Panic! */
		exit ( 1 );
	}
	
	calendarModuleSelector = new BMenuField( BRect( 0, 0, this->Bounds().Width() - 10, 1 ),
											 "Calendar Modules selector",
											 "Calendar module:",
											 calendarModules,
											 B_FOLLOW_H_CENTER | B_FOLLOW_TOP );
	if ( !calendarModuleSelector ) {
		/* Panic! */
		exit ( 1 );
	}
	
	calendarModuleSelector->ResizeToPreferred();
	
	// Add the menu with all calendar modules to the layout
	BLayoutItem* layoutItem = groupLayout->AddView( 0, calendarModuleSelector, 1 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) );
	}
	
	// Relayout
	groupLayout->Relayout();
}	// <-- end of constructor for CalendarModulePreferencesView
コード例 #10
0
ファイル: MediaWindow.cpp プロジェクト: bhanug/haiku
void
MediaWindow::_ClearParamView()
{
	BLayoutItem* item = fContentLayout->VisibleItem();
	if (!item)
		return;

	BView* view = item->View();
	if (view != fVideoView && view != fAudioView && view != fMidiView) {
		fContentLayout->RemoveItem(item);
		delete item;
		delete view;
		delete fParamWeb;
		fParamWeb = NULL;
	}
}
コード例 #11
0
ファイル: DiskView.cpp プロジェクト: AmirAbrams/haiku
	int32 _FindInsertIndex(PartitionView* view, BGroupLayout* layout) const
	{
		int32 insertIndex = 0;
		int32 count = layout->CountItems();
		for (int32 i = 0; i < count; i++) {
			BLayoutItem* item = layout->ItemAt(i);
			if (!item)
				break;
			PartitionView* sibling
				= dynamic_cast<PartitionView*>(item->View());
			if (sibling && sibling->Offset() > view->Offset())
				break;
			insertIndex++;
		}
		return insertIndex;
	}
コード例 #12
0
ファイル: TabManager.cpp プロジェクト: AmirAbrams/haiku
BView*
TabManager::RemoveTab(int32 index)
{
	// It's important to remove the view first, since
	// removing the tab will preliminary mess with the selected tab
	// and then item count of card layout and tab container will not
	// match yet.
	BLayoutItem* item = fCardLayout->RemoveItem(index);
	if (item == NULL)
		return NULL;

	TabView* tab = fTabContainerView->RemoveTab(index);
	delete tab;

	BView* view = item->View();
	delete item;
	return view;
}
コード例 #13
0
ファイル: CardLayout.cpp プロジェクト: mariuz/haiku
// _ValidateMinMax
void
BCardLayout::_ValidateMinMax()
{
	if (fMinMaxValid)
		return;

	fMin.width = 0;
	fMin.height = 0;
	fMax.width = B_SIZE_UNLIMITED;
	fMax.height = B_SIZE_UNLIMITED;
	fPreferred.width = 0;
	fPreferred.height = 0;

	int32 itemCount = CountItems();
	for (int32 i = 0; i < itemCount; i++) {
		BLayoutItem* item = ItemAt(i);

		BSize min = item->MinSize();
		BSize max = item->MaxSize();
		BSize preferred = item->PreferredSize();

		fMin.width = max_c(fMin.width, min.width);
		fMin.height = max_c(fMin.height, min.height);

		fMax.width = min_c(fMax.width, max.width);
		fMax.height = min_c(fMax.height, max.height);

		fPreferred.width = max_c(fPreferred.width, preferred.width);
		fPreferred.height = max_c(fPreferred.height, preferred.height);
	}

	fMax.width = max_c(fMax.width, fMin.width);
	fMax.height = max_c(fMax.height, fMin.height);

	fPreferred.width = max_c(fPreferred.width, fMin.width);
	fPreferred.height = max_c(fPreferred.height, fMin.height);
	fPreferred.width = min_c(fPreferred.width, fMax.width);
	fPreferred.height = min_c(fPreferred.height, fMax.height);

	fMinMaxValid = true;

	if (BView* view = View())
		view->ResetLayoutInvalidation();
}
コード例 #14
0
void
TFilePanel::RestoreState()
{
	BNode defaultingNode;
	if (DefaultStateSourceNode(kDefaultFilePanelTemplate, &defaultingNode,
			false)) {
		AttributeStreamFileNode streamNodeSource(&defaultingNode);
		RestoreWindowState(&streamNodeSource);
		PoseView()->Init(&streamNodeSource);
	} else {
		RestoreWindowState(NULL);
		PoseView()->Init(NULL);
	}

	// Finish UI creation now that the PoseView is initialized
	BLayoutItem* item
		= fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView());
	BSize minSize = item->MinSize();
	BSize maxSize = item->MaxSize();
	item->SetExplicitMinSize(BSize(minSize.Width(), kTitleViewHeight));
	item->SetExplicitMaxSize(BSize(maxSize.Width(), kTitleViewHeight));

	BRect rect(fBorderedView->Frame());
	rect.right = rect.left + kCountViewWidth;
	rect.top = rect.bottom + 1;
	rect.bottom = rect.top + PoseView()->HScrollBar()->Bounds().Height() - 1;
	PoseView()->CountView()->MoveTo(rect.LeftTop());
	PoseView()->CountView()->ResizeTo(rect.Size());
	PoseView()->CountView()->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
	fBackView->AddChild(PoseView()->CountView(), fBorderedView);

	PoseView()->HScrollBar()->MoveBy(kCountViewWidth + 1, 0);
	PoseView()->HScrollBar()->ResizeBy(-kCountViewWidth - 1, 0);

	// The Be Book states that the BTitleView will have a name of "TitleView",
	// and so some apps will try to grab it by that name and move it around.
	// They don't need to, because resizing "PoseView" (really the BorderedView)
	// will resize the BTitleView as well. So just create a dummy view here
	// so that they don't get NULL when trying to find the view.
	BView* dummyTitleView = new BView(BRect(), "TitleView", B_FOLLOW_NONE, 0);
	fBackView->AddChild(dummyTitleView);
	dummyTitleView->Hide();
}
コード例 #15
0
ファイル: Layout.cpp プロジェクト: mariuz/haiku
bool
BLayout::RemoveView(BView* child)
{
	bool removed = false;

	// a view can have any number of layout items - we need to remove them all
	for (int32 i = fItems.CountItems(); i-- > 0;) {
		BLayoutItem* item = ItemAt(i);

		if (item->View() != child)
			continue;

		RemoveItem(i);
		removed = true;
		delete item;
	}

	return removed;
}
コード例 #16
0
ファイル: Layout.cpp プロジェクト: mariuz/haiku
BLayoutItem*
BLayout::RemoveItem(int32 index)
{
	if (index < 0 || index >= fItems.CountItems())
		return NULL;

	BLayoutItem* item = (BLayoutItem*)fItems.RemoveItem(index);

	// if the item refers to a BView, we make sure, it is removed from the
	// parent view
	BView* view = item->View();
	if (view && view->fParent == fView)
		view->_RemoveSelf();

	item->SetLayout(NULL);
	ItemRemoved(item);
	InvalidateLayout();

	return item;
}
コード例 #17
0
ファイル: CardLayout.cpp プロジェクト: mariuz/haiku
// GetHeightForWidth
void
BCardLayout::GetHeightForWidth(float width, float* min, float* max,
	float* preferred)
{
	_ValidateMinMax();

	// init with useful values
	float minHeight = fMin.height;
	float maxHeight = fMax.height;
	float preferredHeight = fPreferred.height;

	// apply the items' constraints
	int32 count = CountItems();
	for (int32 i = 0; i < count; i++) {
		BLayoutItem* item = ItemAt(i);
		if (item->HasHeightForWidth()) {
			float itemMinHeight;
			float itemMaxHeight;
			float itemPreferredHeight;
			item->GetHeightForWidth(width, &itemMinHeight, &itemMaxHeight,
				&itemPreferredHeight);
			minHeight = max_c(minHeight, itemMinHeight);
			maxHeight = min_c(maxHeight, itemMaxHeight);
			preferredHeight = min_c(preferredHeight, itemPreferredHeight);
		}
	}

	// adjust max and preferred, if necessary
	maxHeight = max_c(maxHeight, minHeight);
	preferredHeight = max_c(preferredHeight, minHeight);
	preferredHeight = min_c(preferredHeight, maxHeight);

	if (min)
		*min = minHeight;
	if (max)
		*max = maxHeight;
	if (preferred)
		*preferred = preferredHeight;
}
コード例 #18
0
ファイル: TwoDimensionalLayout.cpp プロジェクト: mariuz/haiku
bool
BTwoDimensionalLayout::LocalLayouter::AddHeightForWidthConstraints(
	VerticalCompoundLayouter* compoundLayouter, Layouter* layouter,
	BLayoutContext* context)
{
	if (context != fHorizontalLayoutContext)
		return false;

	if (fHeightForWidthConstraintsAdded)
		return false;

	LayoutInfo* hLayoutInfo = fHLayouter->GetLayoutInfo();

	// add the children's height for width constraints
	int32 itemCount = fHeightForWidthItems.CountItems();
	for (int32 i = 0; i < itemCount; i++) {
		BLayoutItem* item = (BLayoutItem*)fHeightForWidthItems.ItemAt(i);
		Dimensions itemDimensions;
		fLayout->GetItemDimensions(item, &itemDimensions);

		float minHeight, maxHeight, preferredHeight;
		item->GetHeightForWidth(
			hLayoutInfo->ElementRangeSize(itemDimensions.x,
				itemDimensions.width),
			&minHeight, &maxHeight, &preferredHeight);
		layouter->AddConstraints(
			itemDimensions.y,
			itemDimensions.height,
			minHeight,
			maxHeight,
			preferredHeight);
	}

	SetHeightForWidthConstraintsAdded(true);

	return true;
}
コード例 #19
0
ファイル: TwoDimensionalLayout.cpp プロジェクト: mariuz/haiku
void
BTwoDimensionalLayout::LocalLayouter::AddConstraints(
	CompoundLayouter* compoundLayouter, Layouter* layouter)
{
	enum orientation orientation = compoundLayouter->Orientation();
	int itemCount = fLayout->CountItems();
	if (itemCount > 0) {
		for (int i = 0; i < itemCount; i++) {
			BLayoutItem* item = fLayout->ItemAt(i);
			if (item->IsVisible()) {
				Dimensions itemDimensions;
				fLayout->GetItemDimensions(item, &itemDimensions);

				BSize min = item->MinSize();
				BSize max = item->MaxSize();
				BSize preferred = item->PreferredSize();

				if (orientation == B_HORIZONTAL) {
					layouter->AddConstraints(
						itemDimensions.x,
						itemDimensions.width,
						min.width,
						max.width,
						preferred.width);

					if (item->HasHeightForWidth())
						fHeightForWidthItems.AddItem(item);

				} else {
					layouter->AddConstraints(
						itemDimensions.y,
						itemDimensions.height,
						min.height,
						max.height,
						preferred.height);
				}
			}
		}

		// add column/row constraints
		ColumnRowConstraints constraints;
		int elementCount = CountElements(compoundLayouter);
		for (int element = 0; element < elementCount; element++) {
			fLayout->GetColumnRowConstraints(orientation, element,
				&constraints);
			layouter->SetWeight(element, constraints.weight);
			layouter->AddConstraints(element, 1, constraints.min,
				constraints.max, constraints.min);
		}
	}
}
コード例 #20
0
ファイル: LayoutContainer.cpp プロジェクト: D-os/BeFree
void
BLayoutContainer::SetUnitsPerPixel(float value, bool deep)
{
	if (value <= 0) return;

	fUnitsPerPixel = value;

	BLayoutItem *item;
	if (deep) {
		item = (BLayoutItem*)fItems.ItemAt(0);
		while (item != NULL) {
			cast_as(item, BLayoutContainer)->fUnitsPerPixel = value;

			if (cast_as(item, BLayoutContainer)->fItems.CountItems() > 0) {
				item = (BLayoutItem*)cast_as(item, BLayoutContainer)->fItems.ItemAt(0);
			} else if (item->fContainer == this) {
				item = item->NextSibling();
			} else {
				if (item->NextSibling() != NULL) {
					item = item->NextSibling();
					continue;
				}

				while (cast_as(item->fContainer, BLayoutItem)->NextSibling() == NULL) {
					item = cast_as(item->fContainer, BLayoutItem);
					if (item->fContainer == this) break;
				}
				item = cast_as(item->fContainer, BLayoutItem)->NextSibling();
			}
		}
	}

	BRect updateRect;
	for (item = (BLayoutItem*)fItems.ItemAt(0); item != NULL; item = item->NextSibling()) {
		if (item->fHidden || item->fFrame.IsValid() == false) continue;
		updateRect |= item->fFrame;
		item->UpdateVisibleRegion();
	}
	Invalidate(updateRect);
}
コード例 #21
0
/*!	\brief		Init user interface regardless of the parameter of constructor.
 */
void		EventEditorMainWindow::InitUI() 
{
	ClearUI();
	
	MainView = new BView( BWindow::Bounds(),
								  "Event Editor Main View",
								  B_FOLLOW_ALL,
								  B_WILL_DRAW | B_FRAME_EVENTS );
	if ( MainView != NULL )
	{
		MainView->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR ) );
		BWindow::AddChild( MainView );
	}
	else
	{
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	
	BGridLayout* layout = new BGridLayout( B_VERTICAL );
	if ( !layout ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	MainView->SetLayout( layout );
	layout->SetInsets( 0, 0, 0, 5 );
	layout->SetSpacing( 0, 2 );
	
	menuBar = CreateMenuBar();
	layout->AddView( menuBar, 0, 0 );
	
	BTabView* tabView = new BTabView( Bounds().InsetBySelf( 5, 30 ),
												 "Tab view" );
	if ( !tabView ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	BLayoutItem* layoutItem = layout->AddView( tabView, 0, 1 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) );
	}
	
	BRect individualTab = tabView->Bounds();
	individualTab.bottom -= ( tabView->TabHeight() + 20 + menuBar->Bounds().Height() );
	
	// Enable firing the activity in any case
	fData.SetEventActivityFired( false );
	
	// General view
	genView = new EventEditor_GeneralView( individualTab, &fData );
	if ( !genView || genView->InitCheck() != B_OK ) {		
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}	
	BTab* tab = new BTab();	
	tabView->AddTab( genView, tab );
	tab->SetLabel( "General" );
	
	// Reminder view
	remView = new EventEditor_ReminderView( individualTab, &fData );
	if ( !remView || remView->InitCheck() != B_OK ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}	
	tab = new BTab();	
	tabView->AddTab( remView, tab );
	tab->SetLabel( "Reminder" );
	
	// Event activity
	actView = new ActivityView( individualTab.InsetByCopy( 5, 5 ), "Event activity", fData.GetEventActivity() );
	if ( !actView || actView->InitCheck() != B_OK ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}	
	tab = new BTab();	
	tabView->AddTab( actView, tab );
	tab->SetLabel( "Activity" );
	
	// Note view
	noteView = new EventEditor_NoteView( individualTab.InsetByCopy( 5, 5 ), &fData );
	if ( !noteView || noteView->InitCheck() != B_OK ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	tab = new BTab();	
	tabView->AddTab( noteView, tab );
	tab->SetLabel( "Note" );
	
	menuBar->SetTargetForItems( this );
	
	// Save button
	saveAndClose = new BButton( BRect( 0, 0, 1, 1 ),
												  "Save",
												  "Save",
												  new BMessage( kFileSave ) );
	if ( !saveAndClose ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}										  
	BLayoutItem* layoutItem2 = layout->AddView( saveAndClose, 0, 2 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_BOTTOM ) );
	}
	saveAndClose->SetTarget( this );
	
	layout->SetMaxRowHeight( 1, 520 );
	layout->SetMinRowHeight( 2, 25 );
	
	// Refresh view
	InvalidateLayout();
	MainView->Invalidate();
}	// <-- end of UI initialization for MainWindow
コード例 #22
0
/*!	\function	ColorUpdateWindow::ColorUpdateWindow
 *	\brief		Constructor.
 *	\param[in]	corner	One of the corners of the window IN SCREEN COORDINATES!
 *	\param[in]	label	Label of the color. (Usually name of the category).
 *	\param[in]	enableEditingLabel	If "true", label can be edited. If "false", it's constant.
 *	\param[in]	title			Title of the window
 *	\param[in]	defaultColor	Original color. Defaults to black.
 *	\param[in]	targetLooper	The target which receives message with the results.
 *	\param[in]	currentScreen	Defines the screen the program runs in. Usually it's
 *								B_MAIN_SCREEN_ID.
 *	\param[in]	message			The template message to be used. If this parameter is NULL,
 *								a new message is constructed.
 */
ColorUpdateWindow::ColorUpdateWindow( BPoint corner,
								  	  BString& label,
								  	  rgb_color &defaultColor,
								  	  bool enableEditingLabel,
								  	  BString title,
								      BHandler *targetHandler,
								      screen_id currentScreen,
								   	  BMessage* message )
	:
	BWindow( BRect( 100, 100, 300, 500 ),
			 title.String(),
			 B_MODAL_WINDOW,
			 B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS | B_WILL_ACCEPT_FIRST_CLICK ),
	originalString( label ),
	originalColor( defaultColor),
	labelView( NULL ),
	okButton( NULL ),
	revertButton( NULL ),
	messageToSend( NULL ),
	target( targetHandler ),
	dirty( false )
{
	BSize layoutSize;
	BLayoutItem* item = NULL;
	float width, height, dontCare;
	BView* background = new BView( this->Bounds(),
								   "Background",
								   B_FOLLOW_LEFT | B_FOLLOW_TOP,
								   B_FRAME_EVENTS | B_WILL_DRAW );
	if ( !background )
	{
		/* Panic! */
		exit(1);
	}
	background->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );	
	
	this->enableEditingLabel = enableEditingLabel;
	
	/* There are three parts in the interface of the control.
	 * Upmost is the label, which, according to the user's settings,
	 * can be editable or not.
	 * Next is the color control.
	 * Last is the row of two buttons, Revert and Ok.
	 */

	// Debugging
	printf( "Color Selected = %u, Color Reverted = %u.\n",
			kColorSelected,
			kColorReverted );

	// Construct background view and layout
	BGridLayout* layout = new BGridLayout( B_VERTICAL );
	if ( !layout ) { /* Panic! */ exit(1); }
	layout->SetInsets( 5, 5, 5, 5 );
	
	background->SetLayout( layout );
	this->AddChild( background );

	// Constructing the name label, editable or not.
	if ( enableEditingLabel )
	{
		labelView = new BTextControl( BRect(0, 0, 1, 1),
									  "Label",
								   	  NULL,
								   	  label.String(),
								   	  NULL );
	} else {
		labelView = new BStringView( BRect (0, 0, 1, 1),
									 "Label",
									 label.String() );
	}
	if ( !labelView )
	{
		/* Panic! */
		exit(1);
	}
	labelView->ResizeToPreferred();
	item = layout->AddView( labelView, 0, 0, 3, 1 );
	if ( !item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_CENTER ) );
//	item->SetExplicitMinSize( BSize( width, height ) );
	
	// Construct color control
	BMessage* toSend = new BMessage( kColorChanged );
	if ( !toSend ) { /* Panic! */ exit(1); }
	colorControl = new BColorControl( BPoint( 0, 0 ),
								      B_CELLS_32x8,
								      4.0,
								      "Color Control",
								      toSend );
	if ( !colorControl )
	{
		/* Panic! */
		exit(1);
	}
	colorControl->GetPreferredSize( &width, &height );
	colorControl->ResizeTo( width, height );
	colorControl->SetTarget( this );
	item = layout->AddView( colorControl, 0, 1, 3, 1 );
	if ( !item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );

	// Construct last two buttons
	// Revert button
	toSend = new BMessage( kColorReverted );
	if ( !toSend ) { /* Panic! */ exit(1); }
	revertButton = new BButton( BRect( 0, 0, 1, 1),
								"Revert button",
								"Revert",
								toSend );
	if ( !revertButton ) { /* Panic! */ exit(1); }
	revertButton->ResizeToPreferred();
	
	// Ok button
	toSend = new BMessage( kColorSelected );
	if ( !toSend ) { /* Panic! */ exit(1); }
	okButton = new BButton( BRect( 0, 0, 1, 1),
						    "Ok button",
						    "Ok",
						    toSend,
						    B_FOLLOW_RIGHT | B_FOLLOW_TOP );
	if ( !okButton ) { /* Panic! */ exit(1); }
	okButton->ResizeToPreferred();
	
	// Attach the buttons to current layout
	item = layout->AddView( revertButton, 0, 2 );
	if ( ! item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_MIDDLE ) );
		// Note I'm skipping one cell - this is for showing current color!
	item = layout->AddView( okButton, 2, 2 );
	if ( ! item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_MIDDLE ) );
	
	// Make "Ok" button the default
	okButton->MakeDefault( true );
	
	// Now, find the correct place for this window. 
	// We have one of the corners from constructor, we need to position the window
	// in such manner that it will be fully visible and keep one of the corners in
	// the specified point.
	layout->Relayout( true );
	layoutSize = layout->PreferredSize();
	this->ResizeTo( layoutSize.width, layoutSize.height );
	background->ResizeTo( layoutSize.width, layoutSize.height );
	
	float windowWidth = layoutSize.width, windowHeight = layoutSize.height;
	BScreen* mainScreen = new BScreen( currentScreen ); // Get access to current screen
	display_mode currentDisplayMode;
	mainScreen->GetMode( &currentDisplayMode );		// Obtain the width and height of screen
	
	// The following booleans uniquely define where the window be located regarding
	// given corner.
	bool leftFromCorner = false, upFromCorner = false;
	
	// Check where the window should span regarding to the corner
	if ( corner.x + windowWidth >= currentDisplayMode.virtual_width )
	{
		if ( corner.x - windowWidth < 0 )
		{
			corner.x = 0;
			leftFromCorner = false;
		}
		else
		{
			leftFromCorner = true;
		}
	}
	
	if ( corner.y + windowHeight >= currentDisplayMode.virtual_height )
	{
		if ( corner.y - windowHeight < 0 )
		{
			corner.y = 0;
			upFromCorner = false;
		}
		else
		{
			upFromCorner = true;
		}	
	}
	
	// Calculate new top-left corner of the window
	if ( leftFromCorner ) 	{ corner.x -= windowWidth; }
	if ( upFromCorner )		{ corner.y -= windowHeight; }
	
	// Move the window to calculated position
	this->MoveTo( corner );
	
	// Show the window
	this->Show();
	colorControl->Invoke();
}	// <-- end of constructor for ColorUpdateWindow
コード例 #23
0
void
BSplitLayout::_InternalGetHeightForWidth(float width, bool realLayout,
        float* minHeight, float* maxHeight, float* preferredHeight)
{
    if ((realLayout && fHeightForWidthVerticalLayouterWidth != width)
            || (!realLayout && fCachedHeightForWidthWidth != width)) {
        // The general strategy is to clone the vertical layouter, which only
        // knows the general min/max constraints, do a horizontal layout for the
        // given width, and add the children's height for width constraints to
        // the cloned vertical layouter. If this method is invoked internally,
        // we keep the cloned vertical layouter, for it will be used for doing
        // the layout. Otherwise we just drop it after we've got the height for
        // width info.

        // clone the vertical layouter and get the horizontal layout info to be used
        LayoutInfo* horizontalLayoutInfo = NULL;
        Layouter* verticalLayouter = fVerticalLayouter->CloneLayouter();
        if (realLayout) {
            horizontalLayoutInfo = fHorizontalLayoutInfo;
            delete fHeightForWidthVerticalLayouter;
            fHeightForWidthVerticalLayouter = verticalLayouter;
            delete fVerticalLayoutInfo;
            fVerticalLayoutInfo = verticalLayouter->CreateLayoutInfo();
            fHeightForWidthVerticalLayouterWidth = width;
        } else {
            if (fHeightForWidthHorizontalLayoutInfo == NULL) {
                delete fHeightForWidthHorizontalLayoutInfo;
                fHeightForWidthHorizontalLayoutInfo
                    = fHorizontalLayouter->CreateLayoutInfo();
            }
            horizontalLayoutInfo = fHeightForWidthHorizontalLayoutInfo;
        }

        // do the horizontal layout (already done when doing this for the real
        // layout)
        if (!realLayout)
            fHorizontalLayouter->Layout(horizontalLayoutInfo, width);

        // add the children's height for width constraints
        int32 count = fHeightForWidthItems.CountItems();
        for (int32 i = 0; i < count; i++) {
            BLayoutItem* item = (BLayoutItem*)fHeightForWidthItems.ItemAt(i);
            int32 index = fVisibleItems.IndexOf(item);
            if (index >= 0) {
                float itemMinHeight, itemMaxHeight, itemPreferredHeight;
                item->GetHeightForWidth(
                    horizontalLayoutInfo->ElementSize(index),
                    &itemMinHeight, &itemMaxHeight, &itemPreferredHeight);
                verticalLayouter->AddConstraints(index, 1, itemMinHeight,
                                                 itemMaxHeight, itemPreferredHeight);
            }
        }

        // get the height for width info
        fCachedHeightForWidthWidth = width;
        fCachedMinHeightForWidth = verticalLayouter->MinSize();
        fCachedMaxHeightForWidth = verticalLayouter->MaxSize();
        fCachedPreferredHeightForWidth = verticalLayouter->PreferredSize();
    }

    if (minHeight)
        *minHeight = fCachedMinHeightForWidth;
    if (maxHeight)
        *maxHeight = fCachedMaxHeightForWidth;
    if (preferredHeight)
        *preferredHeight = fCachedPreferredHeightForWidth;
}
コード例 #24
0
ファイル: KeyRequestWindow.cpp プロジェクト: garodimb/haiku
	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);
	}
コード例 #25
0
ファイル: PackageView.cpp プロジェクト: looncraz/haiku
void
PackageView::_InitView()
{
	SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

	float fontHeight = be_plain_font->Size();
	rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);

	BTextView* packageDescriptionView = new DescriptionTextView(
		"package description", fontHeight * 13);
	packageDescriptionView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	packageDescriptionView->SetText(fInfo.GetDescription());
	packageDescriptionView->MakeEditable(false);
	packageDescriptionView->MakeSelectable(false);
	packageDescriptionView->SetFontAndColor(be_plain_font, B_FONT_ALL,
		&textColor);

	BScrollView* descriptionScrollView = new BScrollView(
		"package description scroll view", packageDescriptionView,
		0, false, true, B_NO_BORDER);

	// Install type menu field
	fInstallTypes = new BPopUpMenu(B_TRANSLATE("none"));
	BMenuField* installType = new BMenuField("install_type",
		B_TRANSLATE("Installation type:"), fInstallTypes);

	// Install type description text view
	fInstallTypeDescriptionView = new DescriptionTextView(
		"install type description", fontHeight * 4);
	fInstallTypeDescriptionView->MakeEditable(false);
	fInstallTypeDescriptionView->MakeSelectable(false);
	fInstallTypeDescriptionView->SetInsets(8, 0, 0, 0);
		// Left inset needs to match BMenuField text offset
	fInstallTypeDescriptionView->SetText(
		B_TRANSLATE("No installation type selected"));
	fInstallTypeDescriptionView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	BFont font(be_plain_font);
	font.SetSize(ceilf(font.Size() * 0.85));
	fInstallTypeDescriptionView->SetFontAndColor(&font, B_FONT_ALL,
		&textColor);

	BScrollView* installTypeScrollView = new BScrollView(
		"install type description scroll view", fInstallTypeDescriptionView,
		 0, false, true, B_NO_BORDER);

	// Destination menu field
	fDestination = new BPopUpMenu(B_TRANSLATE("none"));
	fDestField = new BMenuField("install_to", B_TRANSLATE("Install to:"),
		fDestination);

	fBeginButton = new BButton("begin_button", B_TRANSLATE("Begin"),
		new BMessage(P_MSG_INSTALL));

	BLayoutItem* typeLabelItem = installType->CreateLabelLayoutItem();
	BLayoutItem* typeMenuItem = installType->CreateMenuBarLayoutItem();

	BLayoutItem* destFieldLabelItem = fDestField->CreateLabelLayoutItem();
	BLayoutItem* destFieldMenuItem = fDestField->CreateMenuBarLayoutItem();

	float forcedMinWidth = be_plain_font->StringWidth("XXX") * 5;
	destFieldMenuItem->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	typeMenuItem->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));

	BAlignment labelAlignment(B_ALIGN_RIGHT, B_ALIGN_VERTICAL_UNSET);
	typeLabelItem->SetExplicitAlignment(labelAlignment);
	destFieldLabelItem->SetExplicitAlignment(labelAlignment);

	// Build the layout
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.Add(descriptionScrollView)
		.AddGrid(B_USE_SMALL_SPACING, B_USE_DEFAULT_SPACING)
			.Add(typeLabelItem, 0, 0)
			.Add(typeMenuItem, 1, 0)
			.Add(installTypeScrollView, 1, 1)
			.Add(destFieldLabelItem, 0, 2)
			.Add(destFieldMenuItem, 1, 2)
		.End()
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fBeginButton)
		.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
	;

	fBeginButton->MakeDefault(true);
}
コード例 #26
0
EthernetSettingsView::EthernetSettingsView()
    :
    BView("EthernetSettingsView", 0, NULL),
    fCurrentSettings(NULL)
{
    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

    fSocket = socket(AF_INET, SOCK_DGRAM, 0);
    _GatherInterfaces();

    // build the GUI
    BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL);
    SetLayout(rootLayout);

    BGridView* controlsGroup = new BGridView();
    BGridLayout* layout = controlsGroup->GridLayout();

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

    BPopUpMenu* deviceMenu = new BPopUpMenu(B_TRANSLATE("<no adapter>"));
    for (int32 i = 0; i < fInterfaces.CountItems(); i++) {
        BString& name = *fInterfaces.ItemAt(i);
        BString label = name;
        BMessage* info = new BMessage(kMsgInfo);
        info->AddString("interface", name.String());
        BMenuItem* item = new BMenuItem(label.String(), info);
        deviceMenu->AddItem(item);
    }

    BPopUpMenu* modeMenu = new BPopUpMenu("modes");
    modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
                                    new BMessage(kMsgStaticMode)));
    modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"),
                                    new BMessage(kMsgDHCPMode)));
    modeMenu->AddSeparatorItem();
    modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Disabled"),
                                    new BMessage(kMsgDisabledMode)));

    BPopUpMenu* networkMenu = new BPopUpMenu("networks");

    fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu);
    layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0);
    layout->AddItem(fDeviceMenuField->CreateMenuBarLayoutItem(), 1, 0);

    fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), networkMenu);
    layout->AddItem(fNetworkMenuField->CreateLabelLayoutItem(), 0, 1);
    layout->AddItem(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 1);

    fTypeMenuField = new BMenuField(B_TRANSLATE("Mode:"), modeMenu);
    layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 2);
    layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 2);

    fIPTextControl = new BTextControl(B_TRANSLATE("IP address:"), "", NULL);
    SetupTextControl(fIPTextControl);

    BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
    layoutItem->SetExplicitMinSize(BSize(
                                       fIPTextControl->StringWidth("XXX.XXX.XXX.XXX") + inset,
                                       B_SIZE_UNSET));

    layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 3);
    layout->AddItem(layoutItem, 1, 3);

    fNetMaskTextControl = new BTextControl(B_TRANSLATE("Netmask:"), "", NULL);
    SetupTextControl(fNetMaskTextControl);
    layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 4);
    layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 4);

    fGatewayTextControl = new BTextControl(B_TRANSLATE("Gateway:"), "", NULL);
    SetupTextControl(fGatewayTextControl);
    layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 5);
    layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 5);

    // TODO: Replace the DNS text controls by a BListView with add/remove
    // functionality and so on...
    fPrimaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #1:"), "",
            NULL);
    SetupTextControl(fPrimaryDNSTextControl);
    layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 6);
    layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6);

    fSecondaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #2:"), "",
            NULL);
    SetupTextControl(fSecondaryDNSTextControl);
    layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 7);
    layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7);

    fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL);
    SetupTextControl(fDomainTextControl);
    layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8);
    layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8);

    fErrorMessage = new BStringView("error", "");
    fErrorMessage->SetAlignment(B_ALIGN_LEFT);
    fErrorMessage->SetFont(be_bold_font);
    fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

    layout->AddView(fErrorMessage, 1, 9);

    // button group (TODO: move to window, but take care of
    // enabling/disabling)
    BGroupView* buttonGroup = new BGroupView(B_HORIZONTAL);

    fRevertButton = new BButton(B_TRANSLATE("Revert"),
                                new BMessage(kMsgRevert));
    fRevertButton->SetEnabled(false);
    buttonGroup->GroupLayout()->AddView(fRevertButton);

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

    fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply));
    fApplyButton->SetEnabled(false);
    buttonGroup->GroupLayout()->AddView(fApplyButton);

    rootLayout->AddView(controlsGroup);
    rootLayout->AddView(buttonGroup);
}
コード例 #27
0
bool
BSplitLayout::_SetSplitterValue(int32 index, int32 value)
{
    // if both items are collapsed, nothing can be dragged
    BLayoutItem* previousItem = ItemAt(index);
    BLayoutItem* nextItem = ItemAt(index + 1);
    ItemLayoutInfo* previousInfo = _ItemLayoutInfo(previousItem);
    ItemLayoutInfo* nextInfo = _ItemLayoutInfo(nextItem);
    ItemLayoutInfo* splitterInfo = _ItemLayoutInfo(_SplitterItemAt(index));
    bool previousVisible = previousInfo->isVisible;
    bool nextVisible = nextInfo->isVisible;
    if (!previousVisible && !nextVisible)
        return false;

    ValueRange range;
    _GetSplitterValueRange(index, range);

    value = max_c(min_c(value, range.sumValue), -(int32)fSpacing);

    int32 previousSize = value - (int32)fSpacing;
    int32 nextSize = range.sumValue - value - (int32)fSpacing;

    // Note: While this collapsed-check is mathmatically correct (i.e. we
    // collapse an item, if it would become smaller than half its minimum
    // size), we might want to change it, since for the user it looks like
    // collapsing happens earlier. The reason being that the only visual mark
    // the user has is the mouse cursor which indeed hasn't crossed the middle
    // of the item yet.
    bool previousCollapsed = (previousSize <= range.previousMin / 2)
                             && previousInfo->isCollapsible;
    bool nextCollapsed = (nextSize <= range.nextMin / 2)
                         && nextInfo->isCollapsible;
    if (previousCollapsed && nextCollapsed) {
        // we cannot collapse both items; we have to decide for one
        if (previousSize < nextSize) {
            // collapse previous
            nextCollapsed = false;
            nextSize = range.sumValue - (int32)fSpacing;
        } else {
            // collapse next
            previousCollapsed = false;
            previousSize = range.sumValue - (int32)fSpacing;
        }
    }

    if (previousCollapsed || nextCollapsed) {
        // one collapsed item -- check whether that violates the constraints
        // of the other one
        int32 availableSpace = range.sumValue - (int32)fSpacing;
        if (previousCollapsed) {
            if (availableSpace < range.nextMin
                    || availableSpace > range.nextMax) {
                // we cannot collapse the previous item
                previousCollapsed = false;
            }
        } else {
            if (availableSpace < range.previousMin
                    || availableSpace > range.previousMax) {
                // we cannot collapse the next item
                nextCollapsed = false;
            }
        }
    }

    if (!(previousCollapsed || nextCollapsed)) {
        // no collapsed item -- check whether there is a close solution
        previousSize = value - (int32)fSpacing;
        nextSize = range.sumValue - value - (int32)fSpacing;

        if (range.previousMin + range.nextMin + 2 * fSpacing > range.sumValue) {
            // we don't have enough space to uncollapse both items
            int32 availableSpace = range.sumValue - (int32)fSpacing;
            if (previousSize < nextSize && availableSpace >= range.nextMin
                    && availableSpace <= range.nextMax
                    && previousInfo->isCollapsible) {
                previousCollapsed = true;
            } else if (availableSpace >= range.previousMin
                       && availableSpace <= range.previousMax
                       && nextInfo->isCollapsible) {
                nextCollapsed = true;
            } else if (availableSpace >= range.nextMin
                       && availableSpace <= range.nextMax
                       && previousInfo->isCollapsible) {
                previousCollapsed = true;
            } else {
                if (previousSize < nextSize && previousInfo->isCollapsible) {
                    previousCollapsed = true;
                } else if (nextInfo->isCollapsible) {
                    nextCollapsed = true;
                } else {
                    // Neither item is collapsible although there's not enough
                    // space: Give them both their minimum size.
                    previousSize = range.previousMin;
                    nextSize = range.nextMin;
                }
            }

        } else {
            // there is enough space for both items
            // make sure the min constraints are satisfied
            if (previousSize < range.previousMin) {
                previousSize = range.previousMin;
                nextSize = range.sumValue - previousSize - 2 * (int32)fSpacing;
            } else if (nextSize < range.nextMin) {
                nextSize = range.nextMin;
                previousSize = range.sumValue - nextSize - 2 * (int32)fSpacing;
            }

            // if we can, also satisfy the max constraints
            if (range.previousMax + range.nextMax + 2 * (int32)fSpacing
                    >= range.sumValue) {
                if (previousSize > range.previousMax) {
                    previousSize = range.previousMax;
                    nextSize = range.sumValue - previousSize
                               - 2 * (int32)fSpacing;
                } else if (nextSize > range.nextMax) {
                    nextSize = range.nextMax;
                    previousSize = range.sumValue - nextSize
                                   - 2 * (int32)fSpacing;
                }
            }
        }
    }

    // compute the size for one collapsed item; for none collapsed item we
    // already have correct values
    if (previousCollapsed || nextCollapsed) {
        int32 availableSpace = range.sumValue - (int32)fSpacing;
        if (previousCollapsed) {
            previousSize = 0;
            nextSize = availableSpace;
        } else {
            previousSize = availableSpace;
            nextSize = 0;
        }
    }

    int32 newValue = previousSize + (previousCollapsed ? 0 : (int32)fSpacing);
    if (newValue == fDraggingCurrentValue) {
        // nothing changed
        return false;
    }

    // something changed: we need to recompute the layout
    int32 baseOffset = -fDraggingCurrentValue;
    // offset to the current splitter position
    int32 splitterOffset = baseOffset + newValue;
    int32 nextOffset = splitterOffset + (int32)fSplitterSize + (int32)fSpacing;

    BRect splitterFrame(splitterInfo->layoutFrame);
    if (fOrientation == B_HORIZONTAL) {
        // horizontal layout
        // previous item
        float left = splitterFrame.left + baseOffset;
        previousInfo->layoutFrame.Set(
            left,
            splitterFrame.top,
            left + previousSize - 1,
            splitterFrame.bottom);

        // next item
        left = splitterFrame.left + nextOffset;
        nextInfo->layoutFrame.Set(
            left,
            splitterFrame.top,
            left + nextSize - 1,
            splitterFrame.bottom);

        // splitter
        splitterInfo->layoutFrame.left += splitterOffset;
        splitterInfo->layoutFrame.right += splitterOffset;
    } else {
        // vertical layout
        // previous item
        float top = splitterFrame.top + baseOffset;
        previousInfo->layoutFrame.Set(
            splitterFrame.left,
            top,
            splitterFrame.right,
            top + previousSize - 1);

        // next item
        top = splitterFrame.top + nextOffset;
        nextInfo->layoutFrame.Set(
            splitterFrame.left,
            top,
            splitterFrame.right,
            top + nextSize - 1);

        // splitter
        splitterInfo->layoutFrame.top += splitterOffset;
        splitterInfo->layoutFrame.bottom += splitterOffset;
    }

    previousInfo->isVisible = !previousCollapsed;
    nextInfo->isVisible = !nextCollapsed;

    bool heightForWidth = (fOrientation == B_HORIZONTAL && HasHeightForWidth());

    // If the item visibility is to be changed, we need to update the splitter
    // values now, since the visibility change will cause an invalidation.
    if (previousVisible != previousInfo->isVisible
            || nextVisible != nextInfo->isVisible || heightForWidth) {
        _UpdateSplitterWeights();
    }

    // If we have height for width items, we need to invalidate the previous
    // and the next item. Actually we would only need to invalidate height for
    // width items, but since non height for width items might be aligned with
    // height for width items, we need to trigger a layout that creates a
    // context that spans all aligned items.
    // We invalidate already here, so that changing the items' size won't cause
    // an immediate relayout.
    if (heightForWidth) {
        previousItem->InvalidateLayout();
        nextItem->InvalidateLayout();
    }

    // do the layout
    _LayoutItem(previousItem, previousInfo);
    _LayoutItem(_SplitterItemAt(index), splitterInfo);
    _LayoutItem(nextItem, nextInfo);

    fDraggingCurrentValue = newValue;

    return true;
}
コード例 #28
0
/*!	\brief		Constructor for the ActivityWindow class.
 *		\param[in]	data			The data to be displayed.
 *		\param[in]	target		The process to be notified about user's choise.
 *		\param[in]	name			Name of the Event.
 *		\param[in]	category		Category of the Event.
 *		\param[in]	templateMessage		The message to be sent to the target.
 *										If \c NULL is passed, then a new message is constructed
 *										with \c kActivityWindowRepsonceMessage value in \c what.
 *		\param[in]	reminder		\c true if the window is constructed for a reminder, else
 *										\c false. Actually, it matters only for explanation to user.
 *										Default is \c false (it's not a reminder).
 *		\note			A note on memory management:
 *						\c data (the ActionData) belongs to the caller, but it's used only for
 *						initialization of this window. I. e., if the user makes changes to the
 *						data while an ActivityWindow is open, the changes won't be reflected.
 *						However, \c target and \c templateMessage belong to this object. User
 *						shouldn't free them or do anything else.
 */
ActivityWindow::ActivityWindow( ActivityData* data,
									 BMessenger* target,
									 BString		 name,
									 Category*	 category,
									 BMessage* templateMessage,
									 bool reminder )
	:
	BWindow( BRect( 0, 0, 400, 500 ),
				"Event occurred",
				B_FLOATING_WINDOW_LOOK,
				B_NORMAL_WINDOW_FEEL,
				B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS ),
	fTarget( target ),
	fData( data ),
	fTemplateMessage( templateMessage ),
	bIsReminder( reminder ),
	fLastError( B_OK ),
	fEventName( name ),
	fCategory( category ),
	fTitle( NULL ),
	fEventNameView( NULL ),
	fCategoryView( NULL ),
	fTextScroller( NULL ),
	fSnoozeTime( NULL ),
	fNoteText( NULL ),
	fSnooze( NULL ),
	fOk( NULL )
{
	BFont boldFont( be_bold_font );
	BFont plainFont( be_plain_font );
	BFont font;			// For various font-related activities
	font_height	fh;	// For setting the height of the Text View with notification text
	plainFont.GetHeight( &fh );
	int	numberOfColumnsInLayout = 2;
	
	// Sanity check
	if ( !data || !target ) {
		/* Panic! */
		fLastError = B_BAD_VALUE;
		return;
	}
	
	if ( ! fData->GetNotification( NULL ) &&
		  ! fData->GetSound( NULL ) &&
		  ! fData->GetProgram( NULL, NULL ) )
	{
		// Nothing to do! This is not an error!
		fLastError = B_NO_INIT;
		return;
	}
	BView*	background = new BView( Bounds(),
												"Background view",
												B_FOLLOW_ALL_SIDES,
												B_WILL_DRAW );
	if ( !background ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	this->AddChild( background );
	BGridLayout* gridLayout = new BGridLayout();
	if ( !gridLayout ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	background->SetLayout( gridLayout );
	background->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
	gridLayout->SetInsets( 5, 5, 5, 5 );
	
	/*-------------------------------------------------
	 * First line - explaining what's happening here
	 *------------------------------------------------*/
	BStringView* exp = new BStringView( BRect( 0, 0, 1, 1 ),
													"Explanation 1",
													( bIsReminder ? 
															"A Reminder has occured!" : 
															"An Event has occured!" ) );
	if ( ! exp ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;	
	}
	exp->SetFont( &boldFont );
	exp->ResizeToPreferred();
	BLayoutItem* layoutItem = gridLayout->AddView( exp, 0, 0, numberOfColumnsInLayout, 1 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) );
	}
	
	/*-----------------------------------------------------------------
	 * Second line - event's name on category's color as background
	 *----------------------------------------------------------------*/
	 
	// Create background
	// Note: the pulse is requested for this Window to receive Pulse notifications.
	fBackground = new BView( BRect( 0, 0, 1, 1 ),
									 "Background",
									 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_V_CENTER | B_PULSE_NEEDED,
									 B_WILL_DRAW );
	if ( !fBackground ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fBackground->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
	layoutItem = gridLayout->AddView( fBackground, 0, 1, numberOfColumnsInLayout, 1 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) );
	}
	
	BGroupLayout* bgLayout = new BGroupLayout( B_VERTICAL );
	if ( !bgLayout ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fBackground->SetLayout( bgLayout	);
	bgLayout->SetInsets( 15, 10, 15, 10 );
	fBackground->SetViewColor( fCategory.categoryColor );
	BString sb = "Category:\n";
	sb << fCategory.categoryName;
	fBackground->SetToolTip( sb.String() );
	
	// Create Event's name view
	fTitle = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Event name",
									  fEventName.String(),
									  B_FOLLOW_H_CENTER | B_FOLLOW_V_CENTER );
	if ( !fTitle ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
		// Use big bold font for Event's name
	fTitle->SetFont( be_bold_font );
	fTitle->GetFont( &font );
	font.SetSize( font.Size() + 2 );
	fTitle->SetFont( &font, B_FONT_SIZE );
	
		// Add the title and set its tooltip
	fTitle->ResizeToPreferred();
	fTitle->SetToolTip( sb.String() );
	bgLayout->AddView( fTitle );
	fTitle->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
	fTitle->SetToolTip( fEventName.String() );
	
	int	nextLineInLayout = 2;
	
	/*================================================================
	 * If the notification was set by the user, display it.
	 *================================================================*/

	BString 	tempString;
	BPath		path;
	float rectHeight = fh.leading + fh.ascent + fh.descent;
	float rectWidth = this->Bounds().Width() - 10;		// Layout insets
	BSize size( rectWidth, rectHeight );
	
	if ( fData->GetNotification( &tempString ) )
	{
		/*-----------------------------------------------------------------
	 	 * Line of explanation
	 	 *----------------------------------------------------------------*/
		exp = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Text view explanation",
									  "You set the following notification:" );
		if ( !exp ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		exp->ResizeToPreferred();
		layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );

		/*-----------------------------------------------------------------
	 	 * Text view with notification text
	 	 *----------------------------------------------------------------*/
		BRect tempRect( BPoint( 0, 0 ), size );
		tempRect.right -= B_V_SCROLL_BAR_WIDTH;
		fNoteText = new BTextView( tempRect,
											"Notification text container",
											tempRect.InsetByCopy( 1, 1 ),
											B_FOLLOW_ALL_SIDES,
											B_WILL_DRAW );
		if ( !fNoteText ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		fNoteText->MakeEditable( false );
		fNoteText->SetText( tempString.String() );
		
		/*-----------------------------------------------------------------
	 	 * Scroll view to scroll the notification text
	 	 *----------------------------------------------------------------*/
		fTextScroller = new BScrollView( "Notification text scroller",
													fNoteText,
													B_FOLLOW_ALL_SIDES,
													0,
													false,
													true );
		if ( !fTextScroller ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		layoutItem = gridLayout->AddView( fTextScroller, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
		if ( layoutItem ) {
//			layoutItem->SetExplicitMaxSize( size );
			layoutItem->SetExplicitMinSize( size );
			layoutItem->SetExplicitPreferredSize( size );
			layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) );
		}
	}	// <-- end of adding information about the notification
	
	/*================================================================
	 * If user wanted to play a sound file, notify him about it.
	 *================================================================*/
	if ( fData->GetSound( &path ) )
	{
		/*-----------------------------------------------------------------
	 	 * Line of explanation
	 	 *----------------------------------------------------------------*/
		exp = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Sound file explanation",
									  "You wanted to play the file:",
									  B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
		if ( !exp ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		exp->ResizeToPreferred();
		layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
		if ( layoutItem ) {
			layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
		}

		/*-----------------------------------------------------------------
	 	 * Display sound file name
	 	 *----------------------------------------------------------------*/
	 	 
	 	// What should we display - full path or just the leaf?
	 	if ( ( size.width - 10 ) > plainFont.StringWidth( path.Path() ) )
	 	{
	 		tempString.SetTo( path.Path() );
	 	}
	 	else
	 	{
	 		tempString.SetTo( path.Leaf() );
	 	}
		exp = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Sound file name",
									  tempString.String() );
		if ( !exp ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		exp->ResizeToPreferred();
		layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
		if ( layoutItem ) {
			layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
		}
		
	}	// <-- end of displaying information about the sound file
	
	/*================================================================
	 * If user wanted to run a program, notify him about it.
	 *================================================================*/
	if ( fData->GetProgram( &path, &tempString ) )
	{
		/*-----------------------------------------------------------------
	 	 * Line of explanation
	 	 *----------------------------------------------------------------*/
		exp = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Program explanation",
									  "You wanted to run a program:" );
		if ( !exp ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		exp->ResizeToPreferred();
		layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
		if ( layoutItem ) {
			layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
		}

		/*-----------------------------------------------------------------
	 	 * Display path to program file
	 	 *----------------------------------------------------------------*/
	 	 
	 	// What should we display - full path or just the leaf?
	 	exp = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Program file name",
									  ( ( size.width - 10 ) > plainFont.StringWidth( path.Path() ) ) ?
									  		path.Path() :
									  		path.Leaf() );
		if ( !exp ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		exp->ResizeToPreferred();
		layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
		if ( layoutItem ) {
			layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
		}
		
		/*-----------------------------------------------------------------
	 	 * Explanation about the program options
	 	 *----------------------------------------------------------------*/
	 	 
	 	if ( tempString.Length() > 0 ) {
		 	exp = new BStringView( BRect( 0, 0, 1, 1 ),
										  "Program file options explanation",
										  "With the following parameters:" );
			if ( !exp ) {
				/* Panic! */
				fLastError = B_NO_MEMORY;
				return;
			}
			exp->ResizeToPreferred();
			layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
			if ( layoutItem ) {
				layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
			}
			
			/*-----------------------------------------------------------------
		 	 * Display the program options
		 	 *----------------------------------------------------------------*/
		 	 
		 	// What should we display - full path or just the leaf?
		 	exp = new BStringView( BRect( 0, 0, 1, 1 ),
										  "Program file options",
										  tempString.String() );
			if ( !exp ) {
				/* Panic! */
				fLastError = B_NO_MEMORY;
				return;
			}
			exp->ResizeToPreferred();
			layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
			if ( layoutItem ) {
				layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
			}
	 	}	// <-- end of diplaying CLI options		
	}	// <-- end of displaying information about the program to run
	
	/*================================================================
	 * Now it's time to display the Snooze time selector
	 *================================================================*/
	TimePreferences* prefs = pref_GetTimePreferences();
	if ( prefs ) {
		prefs->GetDefaultSnoozeTime( ( int* )&fSnoozeHours, ( int* )&fSnoozeMins );
	} else {
		fSnoozeHours = 0;
		fSnoozeMins = 10;
	}
	
	BMessage* toSend = new BMessage( kSnoozeTimeControlMessage );
	if ( ! toSend ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fSnoozeTime = new GeneralHourMinControl( BRect( 0, 0, 1, 1 ),
														  "Snooze time selector",
														  "Snooze this Activtiy for:",
														  BString( "" ),	// No check box
														  toSend );
	if ( !fSnoozeTime ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fSnoozeTime->SetHoursLimit( 23 );	// Max reminder time delay is 23 hours 55 minutes
	fSnoozeTime->SetMinutesLimit( 55 );
	fSnoozeTime->SetCurrentTime( fSnoozeHours, fSnoozeMins );
	
	layoutItem = gridLayout->AddView( fSnoozeTime, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_MIDDLE ) );
	}
	

	/*================================================================
	 * Snooze button
	 *================================================================*/
	toSend = new BMessage( kSnoozeButtonPressed );
	if ( !toSend ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fSnooze = new BButton( BRect( 0, 0, 1, 1 ),
								  "Snooze button",
								  "Snooze",
								  toSend,
								  B_FOLLOW_LEFT | B_FOLLOW_TOP );
	if ( !fSnooze ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fSnooze->ResizeToPreferred();
	layoutItem = gridLayout->AddView( fSnooze, 0, nextLineInLayout );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) );
	}

	/*================================================================
	 * Ok button
	 *================================================================*/
	toSend = new BMessage( kDismissButtonPressed );
	if ( !toSend ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fOk = new BButton( BRect( 0, 0, 1, 1 ),
							  "Dismiss button",
							  "Dismiss",
							  toSend,
							  B_FOLLOW_RIGHT | B_FOLLOW_TOP );
	if ( !fOk ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fSnooze->ResizeToPreferred();
	layoutItem = gridLayout->AddView( fOk, 1, nextLineInLayout );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_TOP ) );
	}

	this->CenterOnScreen();	
}	// <-- end of constructor for ActivityWindow
コード例 #29
0
/*!	\brief		Constructor.
 *		\param[in]	frame		The rectangle of the View. Passed unmodified to
 *									constructor of BView.
 *		\param[in]	data		Data of the Event.
 *		\details		The user must check \c InitCheck() value. If it's not B_OK,
 *						the class did not initialize properly.
 */
EventEditor_ReminderView::EventEditor_ReminderView( BRect rect, EventData* data )
	:
	BView( rect,
			 "Reminder Activity",
			 B_FOLLOW_ALL,
			 B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED ),
	fData( data ),
	fLastError( B_OK ),
	fReminderEnabler( NULL ),
	fExplanation( NULL ),
	fExplanation2( NULL ),
	fHourMinControl( NULL ),
	fActivityView( NULL )
{	
	// Sanity check
	if ( !data ) {
		/* Panic! */
		fLastError = B_BAD_VALUE;
		return;
	}
	
	// Create the layout
	BGroupLayout* layout = new BGroupLayout( B_VERTICAL );
	if ( !layout ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	this->SetLayout( layout );
	layout->SetInsets( 5, 5, 5, 5 );
	
	// Get the preferences
	TimePreferences*	pref = pref_GetTimePreferences();	
	
	// Construct the checkbox
	BMessage* toSend = new BMessage( kReminderEnabled );
	if ( !toSend ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fReminderEnabler = new BCheckBox( BRect( 0, 0, 1, 1 ),
												 "Enable or disable the reminder",
												 "Remind me about this Event",
												 toSend );
	if( !fReminderEnabler ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fReminderEnabler->ResizeToPreferred();
	BLayoutItem* layoutItem = layout->AddView( fReminderEnabler );
	
	// Construct the explanation string
	fExplanation = new BStringView( BRect( 0, 0, 1, 1 ),
											  "Explanation",
											  "Reminder will not work if it's set up to start at" );
	fExplanation2 = new BStringView( BRect( 0, 0, 1, 1 ),
											  "Explanation2",
											  "the time of the Event itself. (Don't choose 00:00)!" );
	if ( !fExplanation || !fExplanation2 ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fExplanation->ResizeToPreferred();
	fExplanation2->ResizeToPreferred();
	fExplanation->SetFont( be_bold_font );
	fExplanation2->SetFont( be_bold_font );
	layoutItem = layout->AddView( fExplanation );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_BOTTOM ) );
	}
	layoutItem = layout->AddView( fExplanation2 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) );
	}
	
	// Construct the time control
	toSend = new BMessage( kReminderTimeUpdated );
	if ( !toSend ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	
	fHourMinControl = new GeneralHourMinControl( BRect ( 0, 0, 1, 1 ),
																"Reminder time",
																BString( "Reminder is set" ),
																BString( "before the Event" ),
																toSend );
	if ( !fHourMinControl ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fHourMinControl->ResizeToPreferred();
	fHourMinControl->SetHoursLimit( 71 );
	fHourMinControl->SetMinutesLimit( 55 );
	
	layoutItem = layout->AddView( fHourMinControl );
	
	// Activity control
	fActivityView = new ActivityView( BRect( 0, 0, 1, 1 ),
												 "Reminder activity",
												 fData->GetReminderActivity() );
	if ( !fActivityView ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fActivityView->ResizeToPreferred();
	layoutItem = layout->AddView( fActivityView );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) );
	}
	
	// Set up options
	bool beforeEvent = true;
	time_t fOffset = fData->GetReminderOffset( &beforeEvent );
	int seconds = ( int )( fOffset % 60 );
	fOffset /= 60;
	fMinutes = ( int )( fOffset % 60 );
	fHours = ( int )( fOffset / 60 );
	
	if ( fOffset == 0 && pref ) {		// First usage
		pref->GetDefaultReminderTime( ( int* )&fHours, ( int* )&fMinutes );
	}
	
	fHourMinControl->SetCurrentTime( fHours, fMinutes );
	fHourMinControl->SetCheckBoxValue( beforeEvent );
	
	// Initial enable / disable of the items	
	fReminderEnabler->SetValue( ( fOffset != 0 ) );
	fActivityView->SetEnabled( ( fOffset != 0 ) );
	fHourMinControl->SetEnabled( ( fOffset != 0 ) );

}	// <-- end of constructor
コード例 #30
0
ModifierKeysWindow::ModifierKeysWindow()
	:
	BWindow(BRect(0, 0, 360, 220), B_TRANSLATE("Modifier keys"),
		B_FLOATING_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
			| B_AUTO_UPDATE_SIZE_LIMITS)
{
	get_key_map(&fCurrentMap, &fCurrentBuffer);
	get_key_map(&fSavedMap, &fSavedBuffer);

	BStringView* keyRole = new BStringView("key role",
		B_TRANSLATE_COMMENT("Role", "As in the role of a modifier key"));
	keyRole->SetAlignment(B_ALIGN_RIGHT);
	keyRole->SetFont(be_bold_font);

	BStringView* keyLabel = new BStringView("key label",
		B_TRANSLATE_COMMENT("Key", "As in a computer keyboard key"));
	keyLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
	keyLabel->SetFont(be_bold_font);

	BMenuField* shiftMenuField = _CreateShiftMenuField();
	shiftMenuField->SetAlignment(B_ALIGN_RIGHT);

	BMenuField* controlMenuField = _CreateControlMenuField();
	controlMenuField->SetAlignment(B_ALIGN_RIGHT);

	BMenuField* optionMenuField = _CreateOptionMenuField();
	optionMenuField->SetAlignment(B_ALIGN_RIGHT);

	BMenuField* commandMenuField = _CreateCommandMenuField();
	commandMenuField->SetAlignment(B_ALIGN_RIGHT);

	fShiftConflictView = new ConflictView("shift warning view");
	fShiftConflictView->SetExplicitMaxSize(BSize(15, 15));

	fControlConflictView = new ConflictView("control warning view");
	fControlConflictView->SetExplicitMaxSize(BSize(15, 15));

	fOptionConflictView = new ConflictView("option warning view");
	fOptionConflictView->SetExplicitMaxSize(BSize(15, 15));

	fCommandConflictView = new ConflictView("command warning view");
	fCommandConflictView->SetExplicitMaxSize(BSize(15, 15));

	fCancelButton = new BButton("cancelButton", B_TRANSLATE("Cancel"),
		new BMessage(B_QUIT_REQUESTED));

	fRevertButton = new BButton("revertButton", B_TRANSLATE("Revert"),
		new BMessage(kMsgRevertModifiers));
	fRevertButton->SetEnabled(false);

	fOkButton = new BButton("okButton", B_TRANSLATE("Set modifier keys"),
		new BMessage(kMsgApplyModifiers));
	fOkButton->MakeDefault(true);

	// Build the layout
	SetLayout(new BGroupLayout(B_VERTICAL));

	float forcedMinWidth = be_plain_font->StringWidth("XXX") * 4;
	keyRole->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));

	BLayoutItem* shiftLabel = shiftMenuField->CreateLabelLayoutItem();
	shiftLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	BLayoutItem* controlLabel = controlMenuField->CreateLabelLayoutItem();
	controlLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	BLayoutItem* optionLabel = optionMenuField->CreateLabelLayoutItem();
	optionLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	BLayoutItem* commandLabel = commandMenuField->CreateLabelLayoutItem();
	commandLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));

	AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_SMALL_SPACING)
		.AddGroup(B_HORIZONTAL)
			.Add(keyRole)
			.Add(keyLabel)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(shiftLabel)
			.Add(shiftMenuField->CreateMenuBarLayoutItem())
			.Add(fShiftConflictView)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(controlLabel)
			.Add(controlMenuField->CreateMenuBarLayoutItem())
			.Add(fControlConflictView)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(optionLabel)
			.Add(optionMenuField->CreateMenuBarLayoutItem())
			.Add(fOptionConflictView)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(commandLabel)
			.Add(commandMenuField->CreateMenuBarLayoutItem())
			.Add(fCommandConflictView)
			.End()
		.AddGlue()
		.AddGroup(B_HORIZONTAL)
			.Add(fCancelButton)
			.AddGlue()
			.Add(fRevertButton)
			.Add(fOkButton)
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
	);

	_MarkMenuItems();
	_ValidateDuplicateKeys();

	PostMessage(kMsgHideShowIcons);
}