コード例 #1
0
/*------------------------------------------------------------------------------*\
	( )
		-	
\*------------------------------------------------------------------------------*/
void BmToolbar::UpdateLayout(bool recalcSizes) {
	if (LockLooper()) {
		// since we want the background tiles for the complete toolbar to appear
		// as one piece, we can't simply use the toolbar-background as view-bitmap
		// in all toolbar-buttons (horizontal wallpapering wouldn't work).
		// So, we render the complete wallpaper into a special bitmap, which is
		// then used by each toolbar-button when that creates its pictures.
		BRect rect = Bounds();
		BmBitmapHandle* toolbarBackground 
			= TheResources->IconByName("Toolbar_Background");
		if (toolbarBackground) {
			delete mBackgroundBitmap;
			BView* view = new BView( rect, NULL, B_FOLLOW_NONE, 0);
			mBackgroundBitmap = new BBitmap( rect, B_RGBA32, true);
			mBackgroundBitmap->AddChild( view);
			mBackgroundBitmap->Lock();
			
			float y=0.0;
			while(y < rect.Height()) {
				float x=0.0;
				while(x < rect.Width()) {
					view->DrawBitmap(toolbarBackground->bitmap, BPoint(x,y));
					x += toolbarBackground->bitmap->Bounds().Width();
				}
				y += toolbarBackground->bitmap->Bounds().Height();
			}
		
			view->Sync();
			mBackgroundBitmap->Unlock();
			mBackgroundBitmap->RemoveChild(view);
			delete view;
		}
	
		// now step through all toolbar-buttons and let them create
		// their pictures:
		BView* group = ChildAt(0);
		if (group) {
			int32 count = group->CountChildren();
			// Get maximum button size...
			float width=0, height=0;
			for( int32 c=0; c<count; ++c) {
				BmToolbarButton* tbb 
					= dynamic_cast<BmToolbarButton*>(group->ChildAt(c));
				if (tbb)
					BmToolbarButton::CalcMaxSize(
						width, height, tbb->Label().String(), tbb->NeedsLatch()
					);
			}
			//...and layout all buttons according to this size:
			for( int32 c=0; c<count; ++c) {
				BmToolbarButton* tbb 
					= dynamic_cast<BmToolbarButton*>(group->ChildAt(c));
				if (tbb)
					tbb->CreateAllPictures(width, height);
			}
			MWindow* win = dynamic_cast<MWindow*>( Window());
			if (win && recalcSizes)
				win->RecalcSize();
			for( int32 c=0; c<count; ++c)
				group->ChildAt(c)->Invalidate();
		}
		// FIXME: a little hackish, but we need to invalidate the whole window 
		// anyway, since icons in other views will have changed, too. 
		// Strangely enough, calling Invalidate() on the topmost child 
		// doesn't work...
		Window()->ChildAt(0)->Hide();
		Window()->ChildAt(0)->Show();
		UnlockLooper();
	}
}