/** SetNextHandler(BHandler* handler); NextHandler(); @case Handler1 and Handler2 belong to the same locked BLooper @param handler Valid BHandler pointer @results Returns Handler2 */ void TSetNextHandlerTest::SetNextHandler11() { BLooper Looper; BHandler Handler1; BHandler Handler2; Looper.AddHandler(&Handler1); Looper.AddHandler(&Handler2); Handler1.SetNextHandler(&Handler2); CPPUNIT_ASSERT(Handler1.NextHandler() == &Handler2); }
/** RemoveHandler(BHandler* handler) @case handler is valid, looper is unlocked @param handler Valid BHandler pointer, assigned to looper @results goes to debugger, but removes handler anyway */ void TRemoveHandlerTest::RemoveHandler3() { DEBUGGER_ESCAPE; BLooper Looper; BHandler Handler; Looper.AddHandler(&Handler); Looper.Unlock(); CPPUNIT_ASSERT(Looper.RemoveHandler(&Handler)); }
/** RemoveHandler(BHandler* handler) @case Valid looper and handler; handler has filters @param handler Valid BHandler pointer @results RemoveHandler() returns true handler->FilterList() returns NULL after removal */ void TRemoveHandlerTest::RemoveHandler5() { BLooper Looper; BHandler Handler; BMessageFilter* MessageFilter = new BMessageFilter('1234'); Handler.AddFilter(MessageFilter); Looper.AddHandler(&Handler); CPPUNIT_ASSERT(Looper.RemoveHandler(&Handler)); CPPUNIT_ASSERT(Handler.FilterList()); }
/** SetNextHandler(BHandler* handler); NextHandler(); @case Handler1 belongs to a locked BLooper, Handler2 does not @param handler Valid BHandler pointer @results NextHandler() returns BLooper debug message "The handler and its NextHandler must have the same looper" */ void TSetNextHandlerTest::SetNextHandler3() { DEBUGGER_ESCAPE; BHandler Handler1; BHandler Handler2; BLooper Looper; Looper.AddHandler(&Handler1); Handler1.SetNextHandler(&Handler2); CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper); }
/** SetNextHandler(BHandler* handler); NextHandler(); @case Handler2 belongs to a unlocked BLooper, Handler1 does not @param handler Valid BHandler pointer @results NextHandler() returns NULL debug message "handler must belong to looper before setting NextHandler" */ void TSetNextHandlerTest::SetNextHandler4() { DEBUGGER_ESCAPE; BHandler Handler1; BHandler Handler2; BLooper Looper; Looper.AddHandler(&Handler2); Looper.Unlock(); Handler1.SetNextHandler(&Handler2); CPPUNIT_ASSERT(Handler1.NextHandler() == NULL); }
/* bool IsTargetLocal() const @case 3 this is initialized to local target with specific handler @results should return true. */ void TargetTester::IsTargetLocalTest3() { // create looper and handler status_t result = B_OK; BLooper *looper = new BLooper; looper->Run(); LooperQuitter quitter(looper); BHandler *handler = new BHandler; HandlerDeleter deleter(handler); CHK(looper->Lock()); looper->AddHandler(handler); looper->Unlock(); // create the messenger and do the checks BMessenger messenger(handler, NULL, &result); CHK(messenger.IsTargetLocal() == true); }
/*! \brief Adds the handler to window's looper */ void CalendarModulePreferencesView::AttachedToWindow() { BLooper* looper = this->Looper(); if ( looper && looper->LockLooper() ) { looper->AddHandler( ( BHandler* )this ); looper->UnlockLooper(); } UpdateTargetting(); // Updates targets of all contents BView::AttachedToWindow(); // Fill the rest of the interface this->Looper()->PostMessage( calendarModules->FindMarked()->Message(), this ); } // <-- end of CalendarModulePreferencesView::AttachedToWindow()
/*! \brief Setting the view as preferred handler */ void CategoryPreferencesView::AttachedToWindow( void ) { BLooper* looper = this->Looper(); if ( looper && looper->LockLooper() ) { looper->AddHandler( ( BHandler* )this ); looper->UnlockLooper(); } addButton->SetTarget( this ); editButton->SetTarget( this ); listView->SetTarget( this ); for ( int i = 0; i < listMenu->CountItems(); ++i ) { ( listMenu->ItemAt( i ) )->SetTarget( this ); } BView::AttachedToWindow(); } // <-- end of function CategoryPreferencesView::AttachedToWindow
/*! \brief Sets up the view color and calls this view's children. */ void CalendarControl::AttachedToWindow() { // Get the view color of the father if ( Parent() ) { SetViewColor( Parent()->ViewColor() ); } // Attach to window both current view and all of its children BControl::AttachedToWindow(); // This view should respond to the messages - thus the Looper must know it BLooper* looper = ( BLooper* )Looper(); if ( looper && looper->LockLooper() ) { looper->AddHandler( ( BHandler* )this ); looper->UnlockLooper(); } UpdateTargets( fDateSelector ); this->InvalidateLayout(); this->Relayout(); this->Invalidate(); }
/*! \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