2 * Copyright 2011 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
8 #include <ControlLook.h>
10 #include <SeparatorView.h>
11 #include <SpaceLayoutItem.h>
18 // Button to adopt backgrond color of toolbar
19 class ToolBarButton
: public BButton
{
21 ToolBarButton(const char* name
, const char* label
,
24 void AttachedToWindow();
28 ToolBarButton::ToolBarButton(const char* name
, const char* label
,
31 BButton(name
, label
, message
)
36 ToolBarButton::AttachedToWindow()
38 BButton::AttachedToWindow();
39 SetLowUIColor(B_PANEL_BACKGROUND_COLOR
);
40 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
41 // have to remove the darkening caused by BButton's drawing
48 class LockableButton
: public ToolBarButton
{
50 LockableButton(const char* name
, const char* label
,
53 void MouseDown(BPoint point
);
57 LockableButton::LockableButton(const char* name
, const char* label
,
60 ToolBarButton(name
, label
, message
)
66 LockableButton::MouseDown(BPoint point
)
68 if ((modifiers() & B_SHIFT_KEY
) != 0 || Value() == B_CONTROL_ON
)
69 SetBehavior(B_TOGGLE_BEHAVIOR
);
71 SetBehavior(B_BUTTON_BEHAVIOR
);
73 Message()->SetInt32("behavior", Behavior());
74 ToolBarButton::MouseDown(point
);
81 BToolBar::BToolBar(BRect frame
, orientation ont
)
88 MoveTo(frame
.LeftTop());
89 ResizeTo(frame
.Width(), frame
.Height());
90 SetResizingMode(B_FOLLOW_LEFT_RIGHT
| B_FOLLOW_TOP
);
94 BToolBar::BToolBar(orientation ont
)
103 BToolBar::~BToolBar()
112 // TODO: This could be fixed in BView instead. Looking from the
113 // BButtons, they are not hidden though, only their parent is...
119 BToolBar::AddAction(uint32 command
, BHandler
* target
, const BBitmap
* icon
,
120 const char* toolTipText
, const char* text
, bool lockable
)
122 AddAction(new BMessage(command
), target
, icon
, toolTipText
, text
, lockable
);
127 BToolBar::AddAction(BMessage
* message
, BHandler
* target
,
128 const BBitmap
* icon
, const char* toolTipText
, const char* text
,
131 ToolBarButton
* button
;
133 button
= new LockableButton(NULL
, NULL
, message
);
135 button
= new ToolBarButton(NULL
, NULL
, message
);
136 button
->SetIcon(icon
);
137 button
->SetFlat(true);
138 if (toolTipText
!= NULL
)
139 button
->SetToolTip(toolTipText
);
141 button
->SetLabel(text
);
143 button
->SetTarget(target
);
148 BToolBar::AddSeparator()
150 orientation ont
= (fOrientation
== B_HORIZONTAL
) ?
151 B_VERTICAL
: B_HORIZONTAL
;
152 AddView(new BSeparatorView(ont
, B_PLAIN_BORDER
));
159 GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
164 BToolBar::AddView(BView
* view
)
166 GroupLayout()->AddView(view
);
171 BToolBar::SetActionEnabled(uint32 command
, bool enabled
)
173 if (BButton
* button
= FindButton(command
))
174 button
->SetEnabled(enabled
);
179 BToolBar::SetActionPressed(uint32 command
, bool pressed
)
181 if (BButton
* button
= FindButton(command
))
182 button
->SetValue(pressed
);
187 BToolBar::SetActionVisible(uint32 command
, bool visible
)
189 BButton
* button
= FindButton(command
);
192 for (int32 i
= 0; BLayoutItem
* item
= GroupLayout()->ItemAt(i
); i
++) {
193 if (item
->View() != button
)
195 item
->SetVisible(visible
);
202 BToolBar::FindButton(uint32 command
) const
204 for (int32 i
= 0; BView
* view
= ChildAt(i
); i
++) {
205 BButton
* button
= dynamic_cast<BButton
*>(view
);
208 BMessage
* message
= button
->Message();
211 if (message
->what
== command
) {
213 // Assumes there is only one button with this message...
221 // #pragma mark - Private methods
226 // TODO: Perhaps this could/should be addressed in BView instead.
233 BToolBar::FrameResized(float width
, float height
)
235 // TODO: There seems to be a bug in app_server which does not
236 // correctly trigger invalidation of views which are shown, when
237 // the resulting dirty area is somehow already part of an update region.
245 float inset
= ceilf(be_control_look
->DefaultItemSpacing() / 2);
246 GroupLayout()->SetInsets(inset
, 0, inset
, 0);
247 GroupLayout()->SetSpacing(1);
249 SetFlags(Flags() | B_FRAME_EVENTS
| B_PULSE_NEEDED
);
254 BToolBar::_HideToolTips() const
256 for (int32 i
= 0; BView
* view
= ChildAt(i
); i
++)
261 } // namespace BPrivate