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 waddlesplash, 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
     11class BButton;
     12
     13
     14class BToolbar : public BGroupView {
     15public:
     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
     36private:
     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 :  
    2020    ShowImageView.cpp
    2121    ShowImageWindow.cpp
    2222    ToolBarIcons.cpp
    23     ToolBarView.cpp
    2423    : libshared.a be tracker translation localestub
    2524        [ TargetLibstdc++ ] [ TargetLibsupc++ ]
    2625    : 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  
    4444#include <ScrollView.h>
    4545#include <String.h>
    4646#include <SupportDefs.h>
     47#include <Toolbar.h>
    4748#include <TranslationDefs.h>
    4849#include <TranslationUtils.h>
    4950#include <TranslatorRoster.h>
     
    5556#include "ShowImageStatusView.h"
    5657#include "ShowImageView.h"
    5758#include "ToolBarIcons.h"
    58 #include "ToolBarView.h"
    5959
    6060
    6161// BMessage field names used in Save messages
    ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,  
    137137    fBrowseMenu(NULL),
    138138    fGoToPageMenu(NULL),
    139139    fSlideShowDelayMenu(NULL),
    140     fToolBarView(NULL),
     140    fToolbar(NULL),
    141141    fImageView(NULL),
    142142    fStatusView(NULL),
    143143    fProgressWindow(new ProgressWindow()),
    ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,  
    170170    // Create the tool bar
    171171    BRect viewFrame = contentView->Bounds();
    172172    viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
    173     fToolBarView = new ToolBarView(viewFrame);
     173    fToolbar = new BToolbar(viewFrame);
    174174
    175175    // Add the tool icons.
    176176
    177 //  fToolBarView->AddAction(MSG_FILE_OPEN, be_app,
     177//  fToolbar->AddAction(MSG_FILE_OPEN, be_app,
    178178//      tool_bar_icon(kIconDocumentOpen), B_TRANSLATE("Open" B_UTF8_ELLIPSIS));
    179     fToolBarView->AddAction(MSG_FILE_PREV, this,
     179    fToolbar->AddAction(MSG_FILE_PREV, this,
    180180        tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file"), false);
    181     fToolBarView->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext),
     181    fToolbar->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext),
    182182        B_TRANSLATE("Next file"), false);
    183183    BMessage* fullScreenSlideShow = new BMessage(MSG_SLIDE_SHOW);
    184184    fullScreenSlideShow->AddBool("full screen", true);
    185     fToolBarView->AddAction(fullScreenSlideShow, this,
     185    fToolbar->AddAction(fullScreenSlideShow, this,
    186186        tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide show"),
    187187        false);
    188     fToolBarView->AddSeparator();
    189     fToolBarView->AddAction(MSG_SELECTION_MODE, this,
     188    fToolbar->AddSeparator();
     189    fToolbar->AddAction(MSG_SELECTION_MODE, this,
    190190        tool_bar_icon(kIconDrawRectangularSelection),
    191191        B_TRANSLATE("Selection mode"), false);
    192     fToolBarView->AddSeparator();
    193     fToolBarView->AddAction(kMsgOriginalSize, this,
     192    fToolbar->AddSeparator();
     193    fToolbar->AddAction(kMsgOriginalSize, this,
    194194        tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"), true);
    195     fToolBarView->AddAction(kMsgFitToWindow, this,
     195    fToolbar->AddAction(kMsgFitToWindow, this,
    196196        tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"), false);
    197     fToolBarView->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn),
     197    fToolbar->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn),
    198198        B_TRANSLATE("Zoom in"), false);
    199     fToolBarView->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut),
     199    fToolbar->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut),
    200200        B_TRANSLATE("Zoom out"), false);
    201     fToolBarView->AddGlue();
    202     fToolBarView->AddAction(MSG_FULL_SCREEN, this,
     201    fToolbar->AddGlue();
     202    fToolbar->AddAction(MSG_FULL_SCREEN, this,
    203203        tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full screen"),
    204204        false);
    205     fToolBarView->SetActionVisible(MSG_FULL_SCREEN, false);
     205    fToolbar->SetActionVisible(MSG_FULL_SCREEN, false);
    206206
    207     fToolBarView->ResizeTo(viewFrame.Width(), fToolBarView->MinSize().height);
     207    fToolbar->ResizeTo(viewFrame.Width(), fToolbar->MinSize().height);
    208208
    209     contentView->AddChild(fToolBarView);
     209    contentView->AddChild(fToolbar);
    210210
    211211    if (fShowToolBar)
    212         viewFrame.top = fToolBarView->Frame().bottom + 1;
     212        viewFrame.top = fToolbar->Frame().bottom + 1;
    213213    else
    214         fToolBarView->Hide();
     214        fToolbar->Hide();
    215215
    216216    fToolBarVisible = fShowToolBar;
    217217
    ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,  
    255255    contentView->AddChild(fVerticalScrollBar);
    256256
    257257    // Update minimum window size
    258     float toolBarMinWidth = fToolBarView->MinSize().width;
     258    float toolBarMinWidth = fToolbar->MinSize().width;
    259259    SetSizeLimits(std::max(menuBarMinWidth, toolBarMinWidth), 100000, 100,
    260260        100000);
    261261
    ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)  
    362362        _AddItemMenu(menu, B_TRANSLATE("Show tool bar"), kMsgToggleToolBar,
    363363            'B', 0, this);
    364364        _MarkMenuItem(menu, kMsgToggleToolBar,
    365             !fToolBarView->IsHidden(fToolBarView));
     365            !fToolbar->IsHidden(fToolbar));
    366366    }
    367367
    368368    if (popupMenu) {
    ShowImageWindow::_ToggleMenuItem(uint32 what)  
    553553        marked = !item->IsMarked();
    554554        item->SetMarked(marked);
    555555    }
    556     fToolBarView->SetActionPressed(what, marked);
     556    fToolbar->SetActionPressed(what, marked);
    557557    return marked;
    558558}
    559559
    ShowImageWindow::_EnableMenuItem(BMenu* menu, uint32 what, bool enable)  
    564564    BMenuItem* item = menu->FindItem(what);
    565565    if (item && item->IsEnabled() != enable)
    566566        item->SetEnabled(enable);
    567     fToolBarView->SetActionEnabled(what, enable);
     567    fToolbar->SetActionEnabled(what, enable);
    568568}
    569569
    570570
    ShowImageWindow::_MarkMenuItem(BMenu* menu, uint32 what, bool marked)  
    574574    BMenuItem* item = menu->FindItem(what);
    575575    if (item && item->IsMarked() != marked)
    576576        item->SetMarked(marked);
    577     fToolBarView->SetActionPressed(what, marked);
     577    fToolbar->SetActionPressed(what, marked);
    578578}
    579579
    580580
    ShowImageWindow::MessageReceived(BMessage* message)  
    893893            if (item->IsMarked()) {
    894894                item->SetMarked(false);
    895895                _StopSlideShow();
    896                 fToolBarView->SetActionPressed(MSG_SLIDE_SHOW, false);
     896                fToolbar->SetActionPressed(MSG_SLIDE_SHOW, false);
    897897            } else if (_ClosePrompt()) {
    898898                item->SetMarked(true);
    899899                if (!fFullScreen && fullScreen)
    900900                    _ToggleFullScreen();
    901901                _StartSlideShow();
    902                 fToolBarView->SetActionPressed(MSG_SLIDE_SHOW, true);
     902                fToolbar->SetActionPressed(MSG_SLIDE_SHOW, true);
    903903            }
    904904            break;
    905905        }
    ShowImageWindow::MessageReceived(BMessage* message)  
    911911                item->SetMarked(false);
    912912
    913913            _StopSlideShow();
    914             fToolBarView->SetActionPressed(MSG_SLIDE_SHOW, false);
     914            fToolbar->SetActionPressed(MSG_SLIDE_SHOW, false);
    915915            break;
    916916        }
    917917
    ShowImageWindow::MessageReceived(BMessage* message)  
    10321032        {
    10331033            float offset;
    10341034            if (message->FindFloat("offset", &offset) == B_OK) {
    1035                 fToolBarView->MoveBy(0, offset);
     1035                fToolbar->MoveBy(0, offset);
    10361036                fScrollView->ResizeBy(0, -offset);
    10371037                fScrollView->MoveBy(0, offset);
    10381038                fVerticalScrollBar->ResizeBy(0, -offset);
    ShowImageWindow::MessageReceived(BMessage* message)  
    10491049            if (message->FindFloat("offset", &offset) == B_OK
    10501050                && message->FindBool("show", &show) == B_OK) {
    10511051                // Compensate rounding errors with the final placement
    1052                 fToolBarView->MoveTo(fToolBarView->Frame().left, offset);
     1052                fToolbar->MoveTo(fToolbar->Frame().left, offset);
    10531053                if (!show)
    1054                     fToolBarView->Hide();
    1055                 BRect frame = fToolBarView->Parent()->Bounds();
    1056                 frame.top = fToolBarView->Frame().bottom + 1;
     1054                    fToolbar->Hide();
     1055                BRect frame = fToolbar->Parent()->Bounds();
     1056                frame.top = fToolbar->Frame().bottom + 1;
    10571057                fScrollView->MoveTo(fScrollView->Frame().left, frame.top);
    10581058                fScrollView->ResizeTo(fScrollView->Bounds().Width(),
    10591059                    frame.Height() - B_H_SCROLL_BAR_HEIGHT + 1);
    ShowImageWindow::_ToggleFullScreen()  
    12861286        SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE));
    12871287    }
    12881288
    1289     fToolBarView->SetActionVisible(MSG_FULL_SCREEN, fFullScreen);
     1289    fToolbar->SetActionVisible(MSG_FULL_SCREEN, fFullScreen);
    12901290    _SetToolBarVisible(!fFullScreen && fShowToolBar);
    12911291
    12921292    MoveTo(frame.left, frame.top);
    ShowImageWindow::_SetToolBarVisible(bool visible, bool animate)  
    15181518        return;
    15191519
    15201520    fToolBarVisible = visible;
    1521     float diff = fToolBarView->Bounds().Height() + 2;
     1521    float diff = fToolbar->Bounds().Height() + 2;
    15221522    if (!visible)
    15231523        diff = -diff;
    15241524    else
    1525         fToolBarView->Show();
     1525        fToolbar->Show();
    15261526
    15271527    if (animate) {
    15281528        // Slide the controls into view. We do this with messages in order
    ShowImageWindow::_SetToolBarVisible(bool visible, bool animate)  
    15431543        fScrollView->MoveBy(0, diff);
    15441544        fVerticalScrollBar->ResizeBy(0, -diff);
    15451545        fVerticalScrollBar->MoveBy(0, diff);
    1546         fToolBarView->MoveBy(0, diff);
     1546        fToolbar->MoveBy(0, diff);
    15471547        if (!visible)
    1548             fToolBarView->Hide();
     1548            fToolbar->Hide();
    15491549    }
    15501550}
    15511551
  • 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;  
    2727class ProgressWindow;
    2828class ShowImageView;
    2929class ShowImageStatusView;
    30 class ToolBarView;
     30class BToolbar;
    3131
    3232
    3333// public message constants
    private:  
    114114            BMenu*              fGoToPageMenu;
    115115            BMenu*              fSlideShowDelayMenu;
    116116            BMenu*              fRatingMenu;
    117             ToolBarView*        fToolBarView;
     117            BToolbar*           fToolbar;
    118118            bool                fToolBarVisible;
    119119            BScrollView*        fScrollView;
    120120            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 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 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 void
    65 ToolBarView::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 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 void
    83 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     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 ToolBarView::AddSeparator()
    103 {
    104     _AddView(new BSeparatorView(B_VERTICAL, B_PLAIN_BORDER));
    105 }
    106 
    107 
    108 void
    109 ToolBarView::AddGlue()
    110 {
    111     GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
    112 }
    113 
    114 
    115 void
    116 ToolBarView::SetActionEnabled(uint32 command, bool enabled)
    117 {
    118     if (BButton* button = _FindButton(command))
    119         button->SetEnabled(enabled);
    120 }
    121 
    122 
    123 void
    124 ToolBarView::SetActionPressed(uint32 command, bool pressed)
    125 {
    126     if (BButton* button = _FindButton(command))
    127         button->SetValue(pressed);
    128 }
    129 
    130 
    131 void
    132 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 void
    147 ToolBarView::Pulse()
    148 {
    149     // TODO: Perhaps this could/should be addressed in BView instead.
    150     if (IsHidden())
    151         _HideToolTips();
    152 }
    153 
    154 
    155 void
    156 ToolBarView::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 ToolBarView::_AddView(BView* view)
    167 {
    168     GroupLayout()->AddView(view);
    169 }
    170 
    171 
    172 BButton*
    173 ToolBarView::_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 ToolBarView::_HideToolTips() const
    194 {
    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_H
    6 #define TOOL_BAR_VIEW_H
    7 
    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 ] {  
    5353            StringForSize.cpp
    5454            TextTable.cpp
    5555            Thread.cpp
     56            Toolbar.cpp
    5657            Variant.cpp
    5758            ;
    5859
  • 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
     13class LockableButton: public BButton {
     14public:
     15            LockableButton(const char* name, const char* label,
     16                BMessage* message);
     17
     18    void    MouseDown(BPoint point);
     19};
     20
     21
     22LockableButton::LockableButton(const char* name, const char* label,
     23    BMessage* message)
     24    :
     25    BButton(name, label, message)
     26{
     27}
     28
     29
     30void
     31LockableButton::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
     43BToolbar::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
     59BToolbar::~BToolbar()
     60{
     61}
     62
     63
     64void
     65BToolbar::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
     74void
     75BToolbar::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
     82void
     83BToolbar::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
     101void
     102BToolbar::AddSeparator()
     103{
     104    _AddView(new BSeparatorView(B_VERTICAL, B_PLAIN_BORDER));
     105}
     106
     107
     108void
     109BToolbar::AddGlue()
     110{
     111    GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
     112}
     113
     114
     115void
     116BToolbar::SetActionEnabled(uint32 command, bool enabled)
     117{
     118    if (BButton* button = _FindButton(command))
     119        button->SetEnabled(enabled);
     120}
     121
     122
     123void
     124BToolbar::SetActionPressed(uint32 command, bool pressed)
     125{
     126    if (BButton* button = _FindButton(command))
     127        button->SetValue(pressed);
     128}
     129
     130
     131void
     132BToolbar::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
     146void
     147BToolbar::Pulse()
     148{
     149    // TODO: Perhaps this could/should be addressed in BView instead.
     150    if (IsHidden())
     151        _HideToolTips();
     152}
     153
     154
     155void
     156BToolbar::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
     165void
     166BToolbar::_AddView(BView* view)
     167{
     168    GroupLayout()->AddView(view);
     169}
     170
     171
     172BButton*
     173BToolbar::_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
     192void
     193BToolbar::_HideToolTips() const
     194{
     195    for (int32 i = 0; BView* view = ChildAt(i); i++)
     196        view->HideToolTip();
     197}
     198