예제 #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
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();
}
/*!	
 *	\brief			The constructor of CalendarControl.
 *	\param[in]	frame			The outer bounds of the control.
 *	\param[in]	name			Name of the control.
 *	\param[in]	labelInForCalendar		The label of the calendar part of control.
 *	\param[in]	calModuleName				ID of the calendar module used.
 *	\param[in]	initialTime					The initial time to be set, passed in seconds.
 *													If 0, current time is set.
 *	\param[in]	toSend						Message sent when the control's value is changed.
 *	\attention		It's assumed that calendar modules were already initialized prior
 *						to calling this function.
 */
CalendarControl::CalendarControl(BRect frame,
								 const char* name,
								 const BString& labelInForCalendar,
								 const BString& calModuleName,
								 time_t	initialTime,
								 BMessage* toSend )
	:
	BControl( frame, name, labelInForCalendar.String(), toSend,
			 B_FOLLOW_ALL_SIDES,
			 B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS ),
	fLabel(NULL),
	fDateLabel(NULL),
	fDateSelector( NULL ),
	fLastError( B_OK )
{
	// Firstly, set the calendar module
	this->fCalModule = utl_FindCalendarModule( calModuleName );
	if ( this->fCalModule == NULL ) {
		fLastError = B_BAD_VALUE;
		return;
	}
	
	// Load the preferences of this calendar module
	ParsePreferences();
	
	// Init the internal data to submitted time representation
	InitTimeRepresentation( initialTime );
	
	// Create the UI elements
	fLabel = new BStringView( BRect( 0, 0, 1, 1 ), 
									  "label", 
									  labelInForCalendar.String() );
	if ( !fLabel) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fLabel->ResizeToPreferred();
	
	fDateLabel = new BStringView( BRect( 0, 0, 1, 1 ), 
											"dateLabel", 
											NULL );
	if ( !fDateLabel ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	
	
	fCalendarModuleLabel = new BStringView( BRect( 0, 0, 1, 1 ),
														 "label for the calendar module selector",
														 "Calendar:" );
	if ( !fCalendarModuleLabel ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fCalendarModuleLabel->ResizeToPreferred();
	
	fCalendarsMenu = CreateMenuOfCalendarModules();
	if ( !fCalendarsMenu ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	
	fCalendarModuleSelector = new BMenuField( BRect( 0, 0, 1, 1 ),
															"calendar module selector",
															NULL,		// Label is created separately
															fCalendarsMenu );
	if ( !fCalendarModuleSelector ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fCalendarModuleSelector->ResizeToPreferred();
	
	// Create the menu
	CreateMenu();
	
	BRect stringViewFrame = fLabel->Frame();
	
	BPoint topLeftCorner = stringViewFrame.RightTop();
	BSize size( BUTTON_WIDTH, stringViewFrame.Height() + SPACING );
	
	
	fMenuBar = new BMenuBar( BRect(topLeftCorner, size),
								"menuBar",
								B_FOLLOW_RIGHT | B_FOLLOW_TOP,
								B_ITEMS_IN_ROW,
								false);
	if (! fMenuBar) {
		// Panic!
		fLastError = B_NO_MEMORY;
		return;
	}
	fMenuBar->SetBorder( B_BORDER_EACH_ITEM );
	fMenuBar->AddItem( fDateSelector );

	// Update the selected date label to currently selected moment of time
	UpdateText();
	
	// Initializing the layout
	BGridLayout* lay = new BGridLayout( );
	
	if (!lay) { 
		// Panic! 
		fLastError = B_NO_MEMORY;
		return; 
	}
	lay->SetInsets(0, 5, 0, 0);
	lay->SetSpacing( 10, 5 );
	lay->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_MIDDLE ) );
	this->SetLayout(lay);
	
	BLayoutItem* layoutItem;
	
	layoutItem = lay->AddView( fLabel, 0, 0 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) );
	layoutItem = lay->AddView( fDateLabel, 1, 0 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );
	layoutItem = lay->AddView( fMenuBar, 2, 0 );	
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_TOP ) );
	layoutItem->SetExplicitMaxSize( size );
	
	layoutItem = lay->AddView( fCalendarModuleLabel, 0, 1 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_MIDDLE ) );
	
	layoutItem = lay->AddView( fCalendarModuleSelector, 1, 1 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );

	lay->SetColumnWeight( 0, 0 );
	lay->SetColumnWeight( 1, 1000 );
	lay->SetColumnWeight( 2, 0 );
	
	lay->SetMaxColumnWidth( 2, BUTTON_WIDTH );
	
	this->InvalidateLayout();
	this->Relayout();
	this->Invalidate();
	
	fLastError = B_OK;
}
/*!	\brief		Add the interface for configuring colors.
 *	\param[in]	frame	The frame of the view.
 *	\param[in]	id		The ID of the interface to configure the colors for.
 */
BBox*		CalendarModulePreferencesView::BuildColorSelectors( BRect frame,
															    const BString& id )
{
	BBox* toReturn = NULL;
	BLayoutItem*	layoutItem = NULL;
	BString sb;
	BRect tempRect = frame;
//	tempRect.InsetBySelf( 10, 10 );
	BMessage* toSend = NULL;
	
	// Access the preferences
	CalendarModulePreferences* prefs = pref_GetPreferencesForCalendarModule( id );
	if ( !prefs ) {
		return NULL;
	}
	
	// Prepare the overall BBox
	toReturn = new BBox( frame, "Color selector" );
	if ( ! toReturn )
		return NULL;
		
	toReturn->SetLabel( "Set up colors" );
	
	// Set up the layout for this BBox
	BGroupLayout* groupLayout = new BGroupLayout( B_VERTICAL );
	if ( !groupLayout ) {
		delete toReturn;
		return NULL;
	}
	groupLayout->SetInsets( 10, 15, 10, 5 );
	groupLayout->SetSpacing( 2 );
	toReturn->SetLayout( groupLayout );
	
	// Label over the CategoryListView for the viewer
	BStringView* viewerString = new BStringView( BRect( 0, 0, 1, 1 ),
											   "Colors Changer Explanation",
											   "Double-click the color to edit it." );
	if ( !viewerString )
	{
		delete toReturn;
		return NULL;
	}
	viewerString->ResizeToPreferred();
	layoutItem = groupLayout->AddView( 0, viewerString, 0 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );

	toSend = new BMessage( kCategoryInvoked );
	if ( !toSend )
	{
		/* Panic! */
		exit( 1 );
	}
	toSend->AddString( "Calendar module", id );
	CategoryListView* menuColors = new CategoryListView( BRect( 0, 
																0,
																tempRect.Width() + B_V_SCROLL_BAR_WIDTH,
																tempRect.Height() + B_H_SCROLL_BAR_HEIGHT ),
														 "Colors list view" );
	if ( !menuColors ) {
//		menuString->RemoveSelf(); delete menuString;
//		viewerString->RemoveSelf(); delete viewerString;
		delete toReturn; return NULL;
	}
	menuColors->SetInvocationMessage( toSend );
	
	// Fill the CategoryListView for the menu colors
	sb.SetTo( "Color for displaying weekdays in the controls" );
	CategoryListItem* toAdd = new CategoryListItem( prefs->GetWeekdaysColor( false ),
													sb );
	if ( toAdd ) {
		menuColors->AddItem( toAdd );
	}
	
	sb.SetTo( "Color for displaying weekends in the controls" );
	toAdd = new CategoryListItem( prefs->GetWeekendsColor( false ),
		 					  	  sb );
	if ( toAdd ) {
		menuColors->AddItem( toAdd );
	}
	sb.SetTo( "Color for displaying weekdays in Viewer" );
	toAdd = new CategoryListItem( prefs->GetWeekdaysColor( true ),
								  sb );
	if ( toAdd ) {
		menuColors->AddItem( toAdd );
	}
	sb.SetTo( "Color for displaying weekends in Viewer" );
	toAdd = new CategoryListItem( prefs->GetWeekendsColor( true ),
		 					  	  sb );
	if ( toAdd ) {
		menuColors->AddItem( toAdd );
	}
	sb.SetTo( "Color for displaying service items in the controls" );
	toAdd = new CategoryListItem( prefs->GetServiceItemsColor( false ),
		 					  	  sb );
	if ( toAdd ) {
		menuColors->AddItem( toAdd );
	}
	sb.SetTo( "Color for displaying service items in the Viewer" );
	toAdd = new CategoryListItem( prefs->GetServiceItemsColor( true ),
		 					  	  sb );
	if ( toAdd ) {
		menuColors->AddItem( toAdd );
	}
	
	menuColors->ResizeToPreferred();	
//	BSize setSize( menuColors->Bounds().Width(), menuColors->Bounds().Height() );
	BSize setSize( frame.Width(), menuColors->Bounds().Height()+5 );
	
	layoutItem = groupLayout->AddView( 1, menuColors, 0 );
	layoutItem->SetExplicitMaxSize( setSize );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );
	groupLayout->InvalidateLayout();
		
	return toReturn;
}	// <-- end of function CalendarModulePreferecesView::BuildColorSelectors