Ticket #11394: 0001-ToolBarView-rename-to-BToolbar-and-move-to-libshared.patch
File 0001-ToolBarView-rename-to-BToolbar-and-move-to-libshared.patch, 21.6 KB (added by , 10 years ago) |
---|
-
new file headers/private/shared/Toolbar.h
From 521d5e261da4a14acdbf7c50d28e068a386e7b6c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier <waddlesplash@gmail.com> Date: Thu, 30 Oct 2014 15:46:36 -0400 Subject: [PATCH] ToolBarView: rename to BToolbar and move to libshared. Also adjust ShowImage for this, it's the only thing that's using ToolBarView right now. --- headers/private/shared/Toolbar.h | 45 ++++++++ src/apps/showimage/Jamfile | 1 - src/apps/showimage/ShowImageWindow.cpp | 78 ++++++------- src/apps/showimage/ShowImageWindow.h | 4 +- src/apps/showimage/ToolBarView.cpp | 198 --------------------------------- src/apps/showimage/ToolBarView.h | 45 -------- src/kits/shared/Jamfile | 1 + src/kits/shared/Toolbar.cpp | 198 +++++++++++++++++++++++++++++++++ 8 files changed, 285 insertions(+), 285 deletions(-) create mode 100644 headers/private/shared/Toolbar.h delete mode 100644 src/apps/showimage/ToolBarView.cpp delete mode 100644 src/apps/showimage/ToolBarView.h create mode 100644 src/kits/shared/Toolbar.cpp diff --git a/headers/private/shared/Toolbar.h b/headers/private/shared/Toolbar.h new file mode 100644 index 0000000..251e9b4
- + 1 /* 2 * Copyright 2011 Stephan Aßmus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 #ifndef _TOOLBAR_H 6 #define _TOOLBAR_H 7 8 #include <GroupView.h> 9 10 11 class BButton; 12 13 14 class BToolbar : public BGroupView { 15 public: 16 BToolbar(BRect frame); 17 virtual ~BToolbar(); 18 19 virtual void Hide(); 20 21 void AddAction(uint32 command, BHandler* target, 22 const BBitmap* icon, 23 const char* toolTipText = NULL, 24 bool lockable = false); 25 void AddAction(BMessage* message, BHandler* target, 26 const BBitmap* icon, 27 const char* toolTipText = NULL, 28 bool lockable = false); 29 void AddSeparator(); 30 void AddGlue(); 31 32 void SetActionEnabled(uint32 command, bool enabled); 33 void SetActionPressed(uint32 command, bool pressed); 34 void SetActionVisible(uint32 command, bool visible); 35 36 private: 37 virtual void Pulse(); 38 virtual void FrameResized(float width, float height); 39 40 void _AddView(BView* view); 41 BButton* _FindButton(uint32 command) const; 42 void _HideToolTips() const; 43 }; 44 45 #endif // _TOOLBAR_H -
src/apps/showimage/Jamfile
diff --git a/src/apps/showimage/Jamfile b/src/apps/showimage/Jamfile index cac3886..f058075 100644
a b Application ShowImage : 20 20 ShowImageView.cpp 21 21 ShowImageWindow.cpp 22 22 ToolBarIcons.cpp 23 ToolBarView.cpp24 23 : libshared.a be tracker translation localestub 25 24 [ TargetLibstdc++ ] [ TargetLibsupc++ ] 26 25 : ShowImage.rdef -
src/apps/showimage/ShowImageWindow.cpp
diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index 6d715c8..0771943 100644
a b 44 44 #include <ScrollView.h> 45 45 #include <String.h> 46 46 #include <SupportDefs.h> 47 #include <Toolbar.h> 47 48 #include <TranslationDefs.h> 48 49 #include <TranslationUtils.h> 49 50 #include <TranslatorRoster.h> … … 55 56 #include "ShowImageStatusView.h" 56 57 #include "ShowImageView.h" 57 58 #include "ToolBarIcons.h" 58 #include "ToolBarView.h"59 59 60 60 61 61 // BMessage field names used in Save messages … … ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, 137 137 fBrowseMenu(NULL), 138 138 fGoToPageMenu(NULL), 139 139 fSlideShowDelayMenu(NULL), 140 fTool BarView(NULL),140 fToolbar(NULL), 141 141 fImageView(NULL), 142 142 fStatusView(NULL), 143 143 fProgressWindow(new ProgressWindow()), … … ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, 170 170 // Create the tool bar 171 171 BRect viewFrame = contentView->Bounds(); 172 172 viewFrame.right -= B_V_SCROLL_BAR_WIDTH; 173 fTool BarView = new ToolBarView(viewFrame);173 fToolbar = new BToolbar(viewFrame); 174 174 175 175 // Add the tool icons. 176 176 177 // fTool BarView->AddAction(MSG_FILE_OPEN, be_app,177 // fToolbar->AddAction(MSG_FILE_OPEN, be_app, 178 178 // tool_bar_icon(kIconDocumentOpen), B_TRANSLATE("Open" B_UTF8_ELLIPSIS)); 179 fTool BarView->AddAction(MSG_FILE_PREV, this,179 fToolbar->AddAction(MSG_FILE_PREV, this, 180 180 tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file"), false); 181 fTool BarView->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext),181 fToolbar->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext), 182 182 B_TRANSLATE("Next file"), false); 183 183 BMessage* fullScreenSlideShow = new BMessage(MSG_SLIDE_SHOW); 184 184 fullScreenSlideShow->AddBool("full screen", true); 185 fTool BarView->AddAction(fullScreenSlideShow, this,185 fToolbar->AddAction(fullScreenSlideShow, this, 186 186 tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide show"), 187 187 false); 188 fTool BarView->AddSeparator();189 fTool BarView->AddAction(MSG_SELECTION_MODE, this,188 fToolbar->AddSeparator(); 189 fToolbar->AddAction(MSG_SELECTION_MODE, this, 190 190 tool_bar_icon(kIconDrawRectangularSelection), 191 191 B_TRANSLATE("Selection mode"), false); 192 fTool BarView->AddSeparator();193 fTool BarView->AddAction(kMsgOriginalSize, this,192 fToolbar->AddSeparator(); 193 fToolbar->AddAction(kMsgOriginalSize, this, 194 194 tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"), true); 195 fTool BarView->AddAction(kMsgFitToWindow, this,195 fToolbar->AddAction(kMsgFitToWindow, this, 196 196 tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"), false); 197 fTool BarView->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn),197 fToolbar->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn), 198 198 B_TRANSLATE("Zoom in"), false); 199 fTool BarView->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut),199 fToolbar->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut), 200 200 B_TRANSLATE("Zoom out"), false); 201 fTool BarView->AddGlue();202 fTool BarView->AddAction(MSG_FULL_SCREEN, this,201 fToolbar->AddGlue(); 202 fToolbar->AddAction(MSG_FULL_SCREEN, this, 203 203 tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full screen"), 204 204 false); 205 fTool BarView->SetActionVisible(MSG_FULL_SCREEN, false);205 fToolbar->SetActionVisible(MSG_FULL_SCREEN, false); 206 206 207 fTool BarView->ResizeTo(viewFrame.Width(), fToolBarView->MinSize().height);207 fToolbar->ResizeTo(viewFrame.Width(), fToolbar->MinSize().height); 208 208 209 contentView->AddChild(fTool BarView);209 contentView->AddChild(fToolbar); 210 210 211 211 if (fShowToolBar) 212 viewFrame.top = fTool BarView->Frame().bottom + 1;212 viewFrame.top = fToolbar->Frame().bottom + 1; 213 213 else 214 fTool BarView->Hide();214 fToolbar->Hide(); 215 215 216 216 fToolBarVisible = fShowToolBar; 217 217 … … ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, 255 255 contentView->AddChild(fVerticalScrollBar); 256 256 257 257 // Update minimum window size 258 float toolBarMinWidth = fTool BarView->MinSize().width;258 float toolBarMinWidth = fToolbar->MinSize().width; 259 259 SetSizeLimits(std::max(menuBarMinWidth, toolBarMinWidth), 100000, 100, 260 260 100000); 261 261 … … ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu) 362 362 _AddItemMenu(menu, B_TRANSLATE("Show tool bar"), kMsgToggleToolBar, 363 363 'B', 0, this); 364 364 _MarkMenuItem(menu, kMsgToggleToolBar, 365 !fTool BarView->IsHidden(fToolBarView));365 !fToolbar->IsHidden(fToolbar)); 366 366 } 367 367 368 368 if (popupMenu) { … … ShowImageWindow::_ToggleMenuItem(uint32 what) 553 553 marked = !item->IsMarked(); 554 554 item->SetMarked(marked); 555 555 } 556 fTool BarView->SetActionPressed(what, marked);556 fToolbar->SetActionPressed(what, marked); 557 557 return marked; 558 558 } 559 559 … … ShowImageWindow::_EnableMenuItem(BMenu* menu, uint32 what, bool enable) 564 564 BMenuItem* item = menu->FindItem(what); 565 565 if (item && item->IsEnabled() != enable) 566 566 item->SetEnabled(enable); 567 fTool BarView->SetActionEnabled(what, enable);567 fToolbar->SetActionEnabled(what, enable); 568 568 } 569 569 570 570 … … ShowImageWindow::_MarkMenuItem(BMenu* menu, uint32 what, bool marked) 574 574 BMenuItem* item = menu->FindItem(what); 575 575 if (item && item->IsMarked() != marked) 576 576 item->SetMarked(marked); 577 fTool BarView->SetActionPressed(what, marked);577 fToolbar->SetActionPressed(what, marked); 578 578 } 579 579 580 580 … … ShowImageWindow::MessageReceived(BMessage* message) 893 893 if (item->IsMarked()) { 894 894 item->SetMarked(false); 895 895 _StopSlideShow(); 896 fTool BarView->SetActionPressed(MSG_SLIDE_SHOW, false);896 fToolbar->SetActionPressed(MSG_SLIDE_SHOW, false); 897 897 } else if (_ClosePrompt()) { 898 898 item->SetMarked(true); 899 899 if (!fFullScreen && fullScreen) 900 900 _ToggleFullScreen(); 901 901 _StartSlideShow(); 902 fTool BarView->SetActionPressed(MSG_SLIDE_SHOW, true);902 fToolbar->SetActionPressed(MSG_SLIDE_SHOW, true); 903 903 } 904 904 break; 905 905 } … … ShowImageWindow::MessageReceived(BMessage* message) 911 911 item->SetMarked(false); 912 912 913 913 _StopSlideShow(); 914 fTool BarView->SetActionPressed(MSG_SLIDE_SHOW, false);914 fToolbar->SetActionPressed(MSG_SLIDE_SHOW, false); 915 915 break; 916 916 } 917 917 … … ShowImageWindow::MessageReceived(BMessage* message) 1032 1032 { 1033 1033 float offset; 1034 1034 if (message->FindFloat("offset", &offset) == B_OK) { 1035 fTool BarView->MoveBy(0, offset);1035 fToolbar->MoveBy(0, offset); 1036 1036 fScrollView->ResizeBy(0, -offset); 1037 1037 fScrollView->MoveBy(0, offset); 1038 1038 fVerticalScrollBar->ResizeBy(0, -offset); … … ShowImageWindow::MessageReceived(BMessage* message) 1049 1049 if (message->FindFloat("offset", &offset) == B_OK 1050 1050 && message->FindBool("show", &show) == B_OK) { 1051 1051 // Compensate rounding errors with the final placement 1052 fTool BarView->MoveTo(fToolBarView->Frame().left, offset);1052 fToolbar->MoveTo(fToolbar->Frame().left, offset); 1053 1053 if (!show) 1054 fTool BarView->Hide();1055 BRect frame = fTool BarView->Parent()->Bounds();1056 frame.top = fTool BarView->Frame().bottom + 1;1054 fToolbar->Hide(); 1055 BRect frame = fToolbar->Parent()->Bounds(); 1056 frame.top = fToolbar->Frame().bottom + 1; 1057 1057 fScrollView->MoveTo(fScrollView->Frame().left, frame.top); 1058 1058 fScrollView->ResizeTo(fScrollView->Bounds().Width(), 1059 1059 frame.Height() - B_H_SCROLL_BAR_HEIGHT + 1); … … ShowImageWindow::_ToggleFullScreen() 1286 1286 SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE)); 1287 1287 } 1288 1288 1289 fTool BarView->SetActionVisible(MSG_FULL_SCREEN, fFullScreen);1289 fToolbar->SetActionVisible(MSG_FULL_SCREEN, fFullScreen); 1290 1290 _SetToolBarVisible(!fFullScreen && fShowToolBar); 1291 1291 1292 1292 MoveTo(frame.left, frame.top); … … ShowImageWindow::_SetToolBarVisible(bool visible, bool animate) 1518 1518 return; 1519 1519 1520 1520 fToolBarVisible = visible; 1521 float diff = fTool BarView->Bounds().Height() + 2;1521 float diff = fToolbar->Bounds().Height() + 2; 1522 1522 if (!visible) 1523 1523 diff = -diff; 1524 1524 else 1525 fTool BarView->Show();1525 fToolbar->Show(); 1526 1526 1527 1527 if (animate) { 1528 1528 // Slide the controls into view. We do this with messages in order … … ShowImageWindow::_SetToolBarVisible(bool visible, bool animate) 1543 1543 fScrollView->MoveBy(0, diff); 1544 1544 fVerticalScrollBar->ResizeBy(0, -diff); 1545 1545 fVerticalScrollBar->MoveBy(0, diff); 1546 fTool BarView->MoveBy(0, diff);1546 fToolbar->MoveBy(0, diff); 1547 1547 if (!visible) 1548 fTool BarView->Hide();1548 fToolbar->Hide(); 1549 1549 } 1550 1550 } 1551 1551 -
src/apps/showimage/ShowImageWindow.h
diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index 4834739..ec0a52c 100644
a b class BScrollView; 27 27 class ProgressWindow; 28 28 class ShowImageView; 29 29 class ShowImageStatusView; 30 class ToolBarView;30 class BToolbar; 31 31 32 32 33 33 // public message constants … … private: 114 114 BMenu* fGoToPageMenu; 115 115 BMenu* fSlideShowDelayMenu; 116 116 BMenu* fRatingMenu; 117 ToolBarView* fToolBarView;117 BToolbar* fToolbar; 118 118 bool fToolBarVisible; 119 119 BScrollView* fScrollView; 120 120 BScrollBar* fVerticalScrollBar; -
deleted file src/apps/showimage/ToolBarView.cpp
diff --git a/src/apps/showimage/ToolBarView.cpp b/src/apps/showimage/ToolBarView.cpp deleted file mode 100644 index ba237f3..0000000
+ - 1 /*2 * Copyright 2011 Stephan Aßmus <superstippi@gmx.de>3 * All rights reserved. Distributed under the terms of the MIT license.4 */5 #include "ToolBarView.h"6 7 #include <Button.h>8 #include <ControlLook.h>9 #include <Message.h>10 #include <SeparatorView.h>11 #include <SpaceLayoutItem.h>12 13 class LockableButton: public BButton {14 public:15 LockableButton(const char* name, const char* label,16 BMessage* message);17 18 void MouseDown(BPoint point);19 };20 21 22 LockableButton::LockableButton(const char* name, const char* label,23 BMessage* message)24 :25 BButton(name, label, message)26 {27 }28 29 30 void31 LockableButton::MouseDown(BPoint point)32 {33 if ((modifiers() & B_SHIFT_KEY) != 0 || Value() == B_CONTROL_ON)34 SetBehavior(B_TOGGLE_BEHAVIOR);35 else36 SetBehavior(B_BUTTON_BEHAVIOR);37 38 Message()->SetInt32("behavior", Behavior());39 BButton::MouseDown(point);40 }41 42 43 ToolBarView::ToolBarView(BRect frame)44 :45 BGroupView(B_HORIZONTAL)46 {47 float inset = ceilf(be_control_look->DefaultItemSpacing() / 2);48 GroupLayout()->SetInsets(inset, 0, inset, 0);49 GroupLayout()->SetSpacing(1);50 51 SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED);52 53 MoveTo(frame.LeftTop());54 ResizeTo(frame.Width(), frame.Height());55 SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);56 }57 58 59 ToolBarView::~ToolBarView()60 {61 }62 63 64 void65 ToolBarView::Hide()66 {67 BView::Hide();68 // TODO: This could be fixed in BView instead. Looking from the69 // BButtons, they are not hidden though, only their parent is...70 _HideToolTips();71 }72 73 74 void75 ToolBarView::AddAction(uint32 command, BHandler* target, const BBitmap* icon,76 const char* toolTipText, bool lockable)77 {78 AddAction(new BMessage(command), target, icon, toolTipText, lockable);79 }80 81 82 void83 ToolBarView::AddAction(BMessage* message, BHandler* target,84 const BBitmap* icon, const char* toolTipText, bool lockable)85 {86 87 BButton* button;88 if (lockable)89 button = new LockableButton(NULL, NULL, message);90 else91 button = new BButton(NULL, NULL, message);92 button->SetIcon(icon);93 button->SetFlat(true);94 if (toolTipText != NULL)95 button->SetToolTip(toolTipText);96 _AddView(button);97 button->SetTarget(target);98 }99 100 101 void102 ToolBarView::AddSeparator()103 {104 _AddView(new BSeparatorView(B_VERTICAL, B_PLAIN_BORDER));105 }106 107 108 void109 ToolBarView::AddGlue()110 {111 GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());112 }113 114 115 void116 ToolBarView::SetActionEnabled(uint32 command, bool enabled)117 {118 if (BButton* button = _FindButton(command))119 button->SetEnabled(enabled);120 }121 122 123 void124 ToolBarView::SetActionPressed(uint32 command, bool pressed)125 {126 if (BButton* button = _FindButton(command))127 button->SetValue(pressed);128 }129 130 131 void132 ToolBarView::SetActionVisible(uint32 command, bool visible)133 {134 BButton* button = _FindButton(command);135 if (button == NULL)136 return;137 for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) {138 if (item->View() != button)139 continue;140 item->SetVisible(visible);141 break;142 }143 }144 145 146 void147 ToolBarView::Pulse()148 {149 // TODO: Perhaps this could/should be addressed in BView instead.150 if (IsHidden())151 _HideToolTips();152 }153 154 155 void156 ToolBarView::FrameResized(float width, float height)157 {158 // TODO: There seems to be a bug in app_server which does not159 // correctly trigger invalidation of views which are shown, when160 // the resulting dirty area is somehow already part of an update region.161 Invalidate();162 }163 164 165 void166 ToolBarView::_AddView(BView* view)167 {168 GroupLayout()->AddView(view);169 }170 171 172 BButton*173 ToolBarView::_FindButton(uint32 command) const174 {175 for (int32 i = 0; BView* view = ChildAt(i); i++) {176 BButton* button = dynamic_cast<BButton*>(view);177 if (button == NULL)178 continue;179 BMessage* message = button->Message();180 if (message == NULL)181 continue;182 if (message->what == command) {183 return button;184 // Assumes there is only one button with this message...185 break;186 }187 }188 return NULL;189 }190 191 192 void193 ToolBarView::_HideToolTips() const194 {195 for (int32 i = 0; BView* view = ChildAt(i); i++)196 view->HideToolTip();197 }198 -
deleted file src/apps/showimage/ToolBarView.h
diff --git a/src/apps/showimage/ToolBarView.h b/src/apps/showimage/ToolBarView.h deleted file mode 100644 index 6273d33..0000000
+ - 1 /*2 * Copyright 2011 Stephan Aßmus <superstippi@gmx.de>3 * All rights reserved. Distributed under the terms of the MIT license.4 */5 #ifndef TOOL_BAR_VIEW_H6 #define TOOL_BAR_VIEW_H7 8 #include <GroupView.h>9 10 11 class BButton;12 13 14 class ToolBarView : public BGroupView {15 public:16 ToolBarView(BRect frame);17 virtual ~ToolBarView();18 19 virtual void Hide();20 21 void AddAction(uint32 command, BHandler* target,22 const BBitmap* icon,23 const char* toolTipText = NULL,24 bool lockable = false);25 void AddAction(BMessage* message, BHandler* target,26 const BBitmap* icon,27 const char* toolTipText = NULL,28 bool lockable = false);29 void AddSeparator();30 void AddGlue();31 32 void SetActionEnabled(uint32 command, bool enabled);33 void SetActionPressed(uint32 command, bool pressed);34 void SetActionVisible(uint32 command, bool visible);35 36 private:37 virtual void Pulse();38 virtual void FrameResized(float width, float height);39 40 void _AddView(BView* view);41 BButton* _FindButton(uint32 command) const;42 void _HideToolTips() const;43 };44 45 #endif // TOOL_BAR_VIEW_H -
src/kits/shared/Jamfile
diff --git a/src/kits/shared/Jamfile b/src/kits/shared/Jamfile index 3185802..039aeda 100644
a b for architectureObject in [ MultiArchSubDirSetup ] { 53 53 StringForSize.cpp 54 54 TextTable.cpp 55 55 Thread.cpp 56 Toolbar.cpp 56 57 Variant.cpp 57 58 ; 58 59 -
new file src/kits/shared/Toolbar.cpp
diff --git a/src/kits/shared/Toolbar.cpp b/src/kits/shared/Toolbar.cpp new file mode 100644 index 0000000..764f11d
- + 1 /* 2 * Copyright 2011 Stephan Aßmus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 #include "Toolbar.h" 6 7 #include <Button.h> 8 #include <ControlLook.h> 9 #include <Message.h> 10 #include <SeparatorView.h> 11 #include <SpaceLayoutItem.h> 12 13 class LockableButton: public BButton { 14 public: 15 LockableButton(const char* name, const char* label, 16 BMessage* message); 17 18 void MouseDown(BPoint point); 19 }; 20 21 22 LockableButton::LockableButton(const char* name, const char* label, 23 BMessage* message) 24 : 25 BButton(name, label, message) 26 { 27 } 28 29 30 void 31 LockableButton::MouseDown(BPoint point) 32 { 33 if ((modifiers() & B_SHIFT_KEY) != 0 || Value() == B_CONTROL_ON) 34 SetBehavior(B_TOGGLE_BEHAVIOR); 35 else 36 SetBehavior(B_BUTTON_BEHAVIOR); 37 38 Message()->SetInt32("behavior", Behavior()); 39 BButton::MouseDown(point); 40 } 41 42 43 BToolbar::BToolbar(BRect frame) 44 : 45 BGroupView(B_HORIZONTAL) 46 { 47 float inset = ceilf(be_control_look->DefaultItemSpacing() / 2); 48 GroupLayout()->SetInsets(inset, 0, inset, 0); 49 GroupLayout()->SetSpacing(1); 50 51 SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED); 52 53 MoveTo(frame.LeftTop()); 54 ResizeTo(frame.Width(), frame.Height()); 55 SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 56 } 57 58 59 BToolbar::~BToolbar() 60 { 61 } 62 63 64 void 65 BToolbar::Hide() 66 { 67 BView::Hide(); 68 // TODO: This could be fixed in BView instead. Looking from the 69 // BButtons, they are not hidden though, only their parent is... 70 _HideToolTips(); 71 } 72 73 74 void 75 BToolbar::AddAction(uint32 command, BHandler* target, const BBitmap* icon, 76 const char* toolTipText, bool lockable) 77 { 78 AddAction(new BMessage(command), target, icon, toolTipText, lockable); 79 } 80 81 82 void 83 BToolbar::AddAction(BMessage* message, BHandler* target, 84 const BBitmap* icon, const char* toolTipText, bool lockable) 85 { 86 87 BButton* button; 88 if (lockable) 89 button = new LockableButton(NULL, NULL, message); 90 else 91 button = new BButton(NULL, NULL, message); 92 button->SetIcon(icon); 93 button->SetFlat(true); 94 if (toolTipText != NULL) 95 button->SetToolTip(toolTipText); 96 _AddView(button); 97 button->SetTarget(target); 98 } 99 100 101 void 102 BToolbar::AddSeparator() 103 { 104 _AddView(new BSeparatorView(B_VERTICAL, B_PLAIN_BORDER)); 105 } 106 107 108 void 109 BToolbar::AddGlue() 110 { 111 GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); 112 } 113 114 115 void 116 BToolbar::SetActionEnabled(uint32 command, bool enabled) 117 { 118 if (BButton* button = _FindButton(command)) 119 button->SetEnabled(enabled); 120 } 121 122 123 void 124 BToolbar::SetActionPressed(uint32 command, bool pressed) 125 { 126 if (BButton* button = _FindButton(command)) 127 button->SetValue(pressed); 128 } 129 130 131 void 132 BToolbar::SetActionVisible(uint32 command, bool visible) 133 { 134 BButton* button = _FindButton(command); 135 if (button == NULL) 136 return; 137 for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) { 138 if (item->View() != button) 139 continue; 140 item->SetVisible(visible); 141 break; 142 } 143 } 144 145 146 void 147 BToolbar::Pulse() 148 { 149 // TODO: Perhaps this could/should be addressed in BView instead. 150 if (IsHidden()) 151 _HideToolTips(); 152 } 153 154 155 void 156 BToolbar::FrameResized(float width, float height) 157 { 158 // TODO: There seems to be a bug in app_server which does not 159 // correctly trigger invalidation of views which are shown, when 160 // the resulting dirty area is somehow already part of an update region. 161 Invalidate(); 162 } 163 164 165 void 166 BToolbar::_AddView(BView* view) 167 { 168 GroupLayout()->AddView(view); 169 } 170 171 172 BButton* 173 BToolbar::_FindButton(uint32 command) const 174 { 175 for (int32 i = 0; BView* view = ChildAt(i); i++) { 176 BButton* button = dynamic_cast<BButton*>(view); 177 if (button == NULL) 178 continue; 179 BMessage* message = button->Message(); 180 if (message == NULL) 181 continue; 182 if (message->what == command) { 183 return button; 184 // Assumes there is only one button with this message... 185 break; 186 } 187 } 188 return NULL; 189 } 190 191 192 void 193 BToolbar::_HideToolTips() const 194 { 195 for (int32 i = 0; BView* view = ChildAt(i); i++) 196 view->HideToolTip(); 197 } 198