From 11b238836413c4577462d754a9c1e216c03133f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 8 Apr 2011 14:59:54 +0000 Subject: [PATCH] * Added AddGlue() method. If this is not used, the tool bar will stretch the icons across the available space. However, it's possible to still add items afterwards, which makes those items right-aligned. * Added SetActionVisible() to show or hide icons. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41200 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ToolBarView.cpp | 27 +++++++++++++++++++++++---- src/apps/showimage/ToolBarView.h | 2 ++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/apps/showimage/ToolBarView.cpp b/src/apps/showimage/ToolBarView.cpp index cbf6fb3264..afe272f18c 100644 --- a/src/apps/showimage/ToolBarView.cpp +++ b/src/apps/showimage/ToolBarView.cpp @@ -19,8 +19,6 @@ ToolBarView::ToolBarView(BRect frame) GroupLayout()->SetInsets(inset, 2, inset, 3); GroupLayout()->SetSpacing(inset); - GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); - SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED); MoveTo(frame.LeftTop()); @@ -71,6 +69,13 @@ ToolBarView::AddSeparator() } +void +ToolBarView::AddGlue() +{ + GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); +} + + void ToolBarView::SetActionEnabled(uint32 command, bool enabled) { @@ -87,6 +92,21 @@ ToolBarView::SetActionPressed(uint32 command, bool pressed) } +void +ToolBarView::SetActionVisible(uint32 command, bool visible) +{ + BIconButton* button = _FindIconButton(command); + if (button == NULL) + return; + for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) { + if (item->View() != button) + continue; + item->SetVisible(visible); + break; + } +} + + void ToolBarView::Pulse() { @@ -109,8 +129,7 @@ ToolBarView::FrameResized(float width, float height) void ToolBarView::_AddView(BView* view) { - // Add before the space layout item at the end - GroupLayout()->AddView(GroupLayout()->CountItems() - 1, view); + GroupLayout()->AddView(view); } diff --git a/src/apps/showimage/ToolBarView.h b/src/apps/showimage/ToolBarView.h index 02857c24a9..b89d295071 100644 --- a/src/apps/showimage/ToolBarView.h +++ b/src/apps/showimage/ToolBarView.h @@ -29,9 +29,11 @@ public: const BBitmap* icon, const char* toolTipText = NULL); void AddSeparator(); + void AddGlue(); void SetActionEnabled(uint32 command, bool enabled); void SetActionPressed(uint32 command, bool pressed); + void SetActionVisible(uint32 command, bool visible); private: virtual void Pulse();