/*! * \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
/*! \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
/*! \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( ¤tDisplayMode ); // 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
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); }
/*! \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
/*! \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
MediaConverterWindow::MediaConverterWindow(BRect frame) : BWindow(frame, B_TRANSLATE_SYSTEM_NAME("MediaConverter"), B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fVideoQuality(75), fAudioQuality(75), fSaveFilePanel(NULL), fOpenFilePanel(NULL), fOutputDirSpecified(false), fEnabled(true), fConverting(false), fCancelling(false) { BPath outputDir; if (find_directory(B_USER_DIRECTORY, &outputDir) != B_OK) outputDir.SetTo("/boot/home"); fOutputDir.SetTo(outputDir.Path()); fMenuBar = new BMenuBar("menubar"); _CreateMenu(); float padding = be_control_look->DefaultItemSpacing(); fListView = new MediaFileListView(); fListView->SetExplicitMinSize(BSize(padding * kMinSourceWidth, B_SIZE_UNSET)); BScrollView* scroller = new BScrollView(NULL, fListView, 0, false, true); // file list view box fSourcesBox = new BBox(B_FANCY_BORDER, scroller); fSourcesBox->SetLayout(new BGroupLayout(B_HORIZONTAL, 0)); // fSourcesBox's layout adjusted in _UpdateLabels // info box fInfoView = new MediaFileInfoView(); fInfoView->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET)); fInfoBox = new BBox(B_FANCY_BORDER, fInfoView); // output menu fields fFormatMenu = new BMenuField(NULL, B_TRANSLATE("File format:"), new BPopUpMenu("")); fAudioMenu = new BMenuField(NULL, B_TRANSLATE("Audio encoding:"), new BPopUpMenu("")); fVideoMenu = new BMenuField(NULL, B_TRANSLATE("Video encoding:"), new BPopUpMenu("")); // output folder fDestButton = new BButton(B_TRANSLATE("Output folder"), new BMessage(OUTPUT_FOLDER_MESSAGE)); BAlignment labelAlignment(be_control_look->DefaultLabelAlignment()); fOutputFolder = new BStringView(NULL, outputDir.Path()); fOutputFolder->SetExplicitAlignment(labelAlignment); // start/end duration fStartDurationTC = new BTextControl(NULL, "0", NULL); BLayoutItem* startDuration = fStartDurationTC->CreateTextViewLayoutItem(); startDuration->SetExplicitSize(BSize(padding * kDurationWidth, B_SIZE_UNSET)); startDuration->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); fEndDurationTC = new BTextControl(NULL, "0", NULL); BLayoutItem* endDuration = fEndDurationTC->CreateTextViewLayoutItem(); endDuration->SetExplicitSize(BSize(padding * kDurationWidth, B_SIZE_UNSET)); endDuration->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); // video quality fVideoQualitySlider = new BSlider("VSlider", "" , new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL); fVideoQualitySlider->SetModificationMessage( new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE)); fVideoQualitySlider->SetValue(fVideoQuality); fVideoQualitySlider->SetEnabled(false); fVideoQualitySlider->SetExplicitSize(BSize(padding * kQualitySliderWidth, B_SIZE_UNSET)); // audio quality fAudioQualitySlider = new BSlider("ASlider", "" , new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL); fAudioQualitySlider->SetModificationMessage( new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE)); fAudioQualitySlider->SetValue(fAudioQuality); fAudioQualitySlider->SetEnabled(false); fAudioQualitySlider->SetExplicitSize(BSize(padding * kQualitySliderWidth, B_SIZE_UNSET)); // output format box BView* outputGrid = BLayoutBuilder::Grid<>() .Add(fFormatMenu->CreateLabelLayoutItem(), 0, 0) .Add(fFormatMenu->CreateMenuBarLayoutItem(), 1, 0) .Add(fAudioMenu->CreateLabelLayoutItem(), 0, 1) .Add(fAudioMenu->CreateMenuBarLayoutItem(), 1, 1) .Add(fVideoMenu->CreateLabelLayoutItem(), 0, 2) .Add(fVideoMenu->CreateMenuBarLayoutItem(), 1, 2) .Add(fDestButton, 0, 3) .Add(fOutputFolder, 1, 3) .Add(fStartDurationTC->CreateLabelLayoutItem(), 0, 4) .Add(startDuration, 1, 4) .Add(fEndDurationTC->CreateLabelLayoutItem(), 0, 5) .Add(endDuration, 1, 5) .Add(fVideoQualitySlider, 0, 6, 2, 1) .Add(fAudioQualitySlider, 0, 7, 2, 1) .View(); outputGrid->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT)); fOutputBox = new OutputBox(B_FANCY_BORDER, outputGrid); fOutputBox->SetLayout(new BGroupLayout(B_HORIZONTAL, 0)); // fOutputBox's layout adjusted in _UpdateLabels // buttons fPreviewButton = new BButton(B_TRANSLATE("Preview"), new BMessage(PREVIEW_MESSAGE)); fPreviewButton->SetEnabled(false); fConvertButton = new BButton(B_TRANSLATE("Convert"), new BMessage(CONVERT_BUTTON_MESSAGE)); // Status views fStatus = new BStringView(NULL, NULL); fStatus->SetExplicitAlignment(labelAlignment); fFileStatus = new BStringView(NULL, NULL); fFileStatus->SetExplicitAlignment(labelAlignment); SetStatusMessage(""); _UpdateLabels(); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .SetInsets(0, 0, 0, 0) .Add(fMenuBar) .AddSplit(B_HORIZONTAL, padding / 2) .SetInsets(padding, padding, padding, padding) .Add(fSourcesBox, 0.4) .AddGroup(B_VERTICAL, padding, 0.6) .Add(fInfoBox) .Add(fOutputBox) .End() .End() .AddGrid(padding, padding) .SetInsets(padding, 0, padding, padding) .Add(fStatus, 0, 0) .Add(fFileStatus, 0, 1) .Add(BSpaceLayoutItem::CreateGlue(), 1, 0) .Add(fPreviewButton, 2, 0) .Add(fConvertButton, 3, 0) .End(); }
/*! \brief Constructor of CategoryPreferencesView * \details It's a descendant of BView. * \param[in] frame The frame rectangle of the view. */ CategoryPreferencesView::CategoryPreferencesView( BRect frame ) : BView( frame, "Category Preferences", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE ) { BLayoutItem* layoutItem = NULL; BMessage* toSend = NULL; menuField = NULL; this->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); /*! \note Layout of the view * The view has a grid layout. It's arranged in the following way: * 1) Left column - list of Categories (CategoryList) that * contains all categories currently available. * 2) Right column - three buttons, from top to bottom: * 2a) Edit currently selected category - guess what it's doing * 2b) Add a new category * 2c) Merge a current directory into another one + menu with * all categories. The category selected in the list is disabled. * \note Restrictions: * a) The list of categories is scrolled. * b) If no category is selected, then * i) "Edit" button is disabled * ii) "Merge to" field is disabled * */ BGridLayout* gridLayout = new BGridLayout(); if ( !gridLayout ) { /* Panic! */ exit( 1 ); } // Margins from the sides of the view and spacing between the elements gridLayout->SetInsets( 5, 5, 5, 5 ); gridLayout->SetHorizontalSpacing( 10 ); gridLayout->SetVerticalSpacing( 10 ); this->SetLayout( gridLayout ); gridLayout->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) ); gridLayout->SetExplicitMinSize( BSize( (this->Bounds()).Width(), (this->Bounds()).Height() ) ); BRect rect = gridLayout->Frame(); printf ( "The frame is %d pixels wide and %d pixels high.\n", (int )rect.Width(), (int )rect.Height() ); /* Creating the CategoryListView with its scroller */ BRect r( this->Bounds() ); r.InsetBySelf( 5, 10 ); // Margins near the border of the view r.right = (int)(r.right / 2) - B_V_SCROLL_BAR_WIDTH; r.bottom -= 0; listView = new CategoryListView( r, "List View" ); if ( ! listView ) { /* Panic! */ exit( 1 ); } BLooper* looper = this->Looper(); if ( looper && looper->LockLooper() ) { looper->AddHandler( ( BHandler* )this ); looper->UnlockLooper(); } scroller = new BScrollView( "Scroller", listView, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, // Flags true, true ); if ( !scroller ) { /* Panic! */ exit( 1 ); } layoutItem = gridLayout->AddView( scroller, 0, 0, 1, 3 ); if ( !layoutItem ) { /* Panic! */ exit( 1 ); } layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_USE_FULL_HEIGHT ) ); toSend = new BMessage( kCategoryInvoked ); if ( !toSend ) { /* Panic! */ exit( 1 ); } listView->SetInvocationMessage( toSend ); toSend = new BMessage( kCategorySelected ); if ( !toSend ) { /* Panic! */ exit( 1 ); } listView->SetSelectionMessage( toSend ); r = listView->Bounds(); r.bottom += B_H_SCROLL_BAR_HEIGHT + 3; r.right -= ( B_V_SCROLL_BAR_WIDTH + 10 ); layoutItem->SetExplicitMinSize( BSize( ( B_V_SCROLL_BAR_WIDTH * 2 ), r.Height() ) ); gridLayout->SetMaxColumnWidth( 0, r.Width()-70 ); gridLayout->SetMaxColumnWidth( 1, r.Width()-66 ); // Add categories to the list PopulateCategoriesView(); /* Creating the buttons */ // Add new category button toSend = new BMessage( kAddNewCategory ); addButton = new BButton( BRect( 0, 0, 1, 1), "Add category", "Add category", toSend, B_FOLLOW_H_CENTER | B_FOLLOW_V_CENTER ); if ( !toSend || !addButton ) { /* Panic! */ exit( 1 ); } addButton->ResizeToPreferred(); addButton->SetTarget( this ); layoutItem = gridLayout->AddView( addButton, 1, 0, 1, 1 ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER ) ); // Edit old category button toSend = new BMessage( kCategoryInvoked ); editButton = new BButton( BRect( 0, 0, 1, 1), "Edit category", "Edit category", toSend, B_FOLLOW_H_CENTER | B_FOLLOW_V_CENTER ); if ( !toSend || !editButton ) { /* Panic! */ exit( 1 ); } editButton->ResizeToPreferred(); editButton->SetTarget( this ); layoutItem = gridLayout->AddView( editButton, 1, 1, 1, 1 ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER ) ); // Edit category button is disabled by default; // it's enabled when user chooses a category in the list. editButton->SetEnabled( false ); /* Creating the menu of merging a category */ // Create a label BGroupLayout* groupLayout = new BGroupLayout( B_VERTICAL ); if ( !groupLayout ) { /* Panic! */ exit( 1 ); } gridLayout->AddItem( groupLayout, 1, 2, 1, 1 ); groupLayout->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); mergeToLabel = new BStringView( BRect( 0, 0, 1, 1 ), "Merge to label", "Merge selected category into:" ); if ( !mergeToLabel ) { /* Panic! */ exit( 1 ); } mergeToLabel->ResizeToPreferred(); layoutItem = groupLayout->AddView( mergeToLabel ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); // Create the menu BMessage templateMessage( kMergeIntoCategory ); listMenu = new CategoryMenu( "Select category to merge to:", true, &templateMessage ); if ( !listMenu ) { /* Panic! */ exit( 1 ); } menuField = new BMenuField( mergeToLabel->Bounds(), "Merge to field", NULL, listMenu ); if ( !menuField ) { /* Panic! */ exit( 1 ); } menuField->SetDivider( 0 ); // Just like the "Edit" button above, the menu is initially disabled. menuField->SetEnabled( false ); layoutItem = groupLayout->AddView( menuField ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) ); for ( int index = 0; index < gridLayout->CountColumns(); ++index ) { gridLayout->SetColumnWeight( index, 1 ); } for ( int index = 0; index < gridLayout->CountRows(); ++index ) { gridLayout->SetRowWeight( index, 1 ); } gridLayout->InvalidateLayout(); } // <-- end of constructor of CategoryPreferencesView
/*! * \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
/*! \brief Builds the interface for a selected calendar module. * \param[in] id Name of the calendar module to build the interface for. * \details If the interface for a module already exists, this function * deletes it without affecting the already set preferences. */ void CalendarModulePreferencesView::BuildInterfaceForModule( const BString& id ) { BGroupLayout* layout = ( BGroupLayout* )( BView::GetLayout() ); BLayoutItem* layoutItem = NULL; BBox* tempBBox = NULL; if ( !this->Window() || this->Window()->Lock() ) { // First, clean up old interface items if they existed this->ClearOldInterface(); // Prepare the frame for the BBox for weekends selection BRect r = this->Bounds(); r.InsetBySelf( 5, 5 ); r.right -= 10; r.bottom -= 10; if ( calendarModuleSelector ) r.top += ( calendarModuleSelector->Bounds().Height() + 10 ); // Build weekend selection tempBBox = CreateWeekendSelectionBox( r, id ); if ( tempBBox ) { // After the call, the BBox is resized to minimal required size. layoutItem = layout->AddView( 1, tempBBox, 0 ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) ); } else { utl_Deb = new DebuggerPrintout( "Error - Weekend selection box is NULL." ); } // Start day chooser BMenuField* startDayChooser = CreateWeekStartDayChooser( r, id ); if ( startDayChooser ) { layoutItem = layout->AddView( 2, startDayChooser, 0 ); if ( layoutItem ) layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); } // Day-month-year order BMenuField* dmyChooser = CreateDayMonthYearOrderChooser( r, id ); if ( dmyChooser ) { layoutItem = layout->AddView( 3, dmyChooser, 0 ); if ( layoutItem ) layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); } // Colors selection tempBBox = BuildColorSelectors( r, id ); if ( tempBBox ) { layoutItem = layout->AddView( 4, tempBBox, 0 ); } /* At the end, all children are targetted at current window */ UpdateTargetting(); if ( this->Window() ) { this->Window()->Unlock(); } } // <-- end of lock-only section } // <-- end of function CalendarModulePreferencesView::BuildInterfaceForModule
/*! * \brief Create box for selection of the weekend days * \note Additionally, select the color for weekends and weekdays * \param[in] frame Enclosing rectangle. * \param[in] id Reference to name of the selected Calendar module. * \returns Pointer to all-set-up BBox. Or NULL in case of error. */ BBox* CalendarModulePreferencesView::CreateWeekendSelectionBox( BRect frame, const BString &id ) { /*! \par Notes on implementation: * It's not all that straightforward - to create this selection box. * The problem is that number of days in week is dependent on the * Calendar Module, therefore the frame rectangle must be divided * properly. We should take into account the possibility that there's * not enough place for all days in the submitted frame. * * \par * The solution will be as follows: * Let number of days in week be N. I create two columns and * several rows (the number depends on N). Days in week will be * proceeded in the order <em>as Calendar Module supplies them</em>. * The days occupy both columns, and are located in rows * [0, (ceiling of (N/2)) ). Days returned from CalendarModule are * placed as follows: days from 0 to (ceiling of (N/2)-1) in the left * column, days from (ceiling of (N/2)-1) to (N-1) in right column. * * \par * There will be an empty cell in the right column, if number * of days in week is odd, (which is usually the case). */ frame.InsetBySelf( 5, 0 ); BMessage* toSend = NULL; BCheckBox* dayCheckBox = NULL; BString tempString; BLayoutItem* layoutItem = NULL; CalendarModulePreferences* prefs = NULL; CalendarModule* calModule = NULL; int height = 0; //!< this is used to resize the BBox to proper size calModule = utl_FindCalendarModule( id ); if ( calModule == NULL ) { /* Error */ utl_Deb = new DebuggerPrintout( "Did not succeed to find the calendar module." ); return NULL; } // Get the data on days of week uint32 daysInWeek = ( uint32 )( calModule->GetDaysInWeek() ); map<uint32, DoubleNames> weekdayNames = calModule->GetWeekdayNames(); /* Obtain the current Calendar Module preferences */ prefs = pref_GetPreferencesForCalendarModule( id ); if ( !prefs ) { utl_Deb = new DebuggerPrintout( "Did not succeed to find the preferences for the calendar module." ); return NULL; } // At this point, "pref" points to current preferences of this calendar module. BList* weekends = prefs->GetWeekends(); // Get info on currently selected weekends // Prepare the item to be returned BBox* enclosingBox = new BBox( frame, "Weekend selector" ); if ( !enclosingBox ) { /* Panic! */ exit(1); } enclosingBox->SetLabel( "Select the non-working days (weekends)" ); // Prepare the layout to be used BGridLayout* layout = new BGridLayout(); if ( !layout) { /* Panic! */ exit(1); } enclosingBox->SetLayout( layout ); layout->SetInsets( 10, 15, 10, 5 ); layout->SetVerticalSpacing( 1 ); /* indexX is 0 for left column or 1 for right column. * indexY is 0 for topmost row, 1 for second from top row, etc. * Max value for indexY = (ceiling of (N/2)). */ int indexX = 0, indexY = 0; for (uint32 day = prefs->GetFirstDayOfWeek(), i = 0; i < ( uint32 )daysInWeek; ++i ) { /* Creating the message to be sent */ toSend = new BMessage( kCalendarModuleWeekendDaySelected ); if ( !toSend ) { /* Panic! */ exit(1); } toSend->AddInt32( "Weekday const", day ); toSend->AddString( "Calendar module", id ); /* Set the name of the checkbox. * This is used to identify if the checkbox was checked or unchecked. */ tempString.SetTo( "Weekday" ); tempString << day; /* Creating the checkbox */ dayCheckBox = new BCheckBox( BRect(0, 0, 1, 1), tempString.String(), weekdayNames[ day ].longName.String(), toSend ); if (!dayCheckBox) { // Panic! exit(1); } dayCheckBox->ResizeToPreferred(); // Check if the checkbox should be checked if ( weekends->HasItem( ( void* )day ) ) { dayCheckBox->SetValue( 1 ); } else { dayCheckBox->SetValue( 0 ); } /* Adding the item to the BBox */ layoutItem = layout->AddView( dayCheckBox, indexX, indexY ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); // layoutItem->SetExplicitMaxSize( BSize( (int )dayCheckBox->Bounds().Width(), (int )dayCheckBox->Bounds().Height() ) ); layout->SetMaxRowHeight( indexY, (int )dayCheckBox->Bounds().Height() + 10 ); layout->SetRowWeight( indexY, 0 ); } /* Advancing to the next cell in grid */ // If arrived to the last item in the first column, advancing to second // The +1 is needed because i starts from 0, but days are starting from 1 if ( ( i + 1 ) == ( unsigned int )( ( daysInWeek + 1 ) / 2 ) ) { indexX = 1; indexY = 0; } else // Staying in the same column, but advancing down { ++indexY; } /* Advancing to the next day */ ( day == daysInWeek ) ? day = kSunday : ++day; } // <-- end of "for (all days in week)" // Resizing the BBox to the correct size. // Note: dayCheckBox is surely not NULL; if it were, we would exit earlier. height =(int )( ( dayCheckBox->Bounds().Height() + 5 ) * ( int )( ( daysInWeek + 1 ) / 2 ) - 5 ); // Formula: ( ^height of one checkbox^ + ^separator^ ) * ( ^number of days in column^ ) - ^one unneeded extra separator^ enclosingBox->ResizeTo( enclosingBox->Bounds().Width() - 10, ( int )height ); // layout->SetExplicitMaxSize( BSize( enclosingBox->Bounds().Width() - 5, ( int )height + 25 ) ); return enclosingBox; }