Ticket #4996: HVIFNavigator.patch

File HVIFNavigator.patch, 38.3 KB (added by michaelvoliveira, 13 years ago)

patch code borrowed from aldeck tracker_layout branch.

  • src/apps/tracker/Tracker.rdef

    diff -Naur tracker_layout-haiku/src/apps/tracker/Tracker.rdef tracker_layout-aldeck/src/apps/tracker/Tracker.rdef
    old new  
    1111    internal   = 0,
    1212    short_info = "Tracker",
    1313    long_info  = "Tracker 5.2.1 ©1991-2001 Be, Inc.,\n"
    14         "©2006-2009 Haiku, Inc."
     14        "©2006-2011 Haiku, Inc."
    1515};
    1616
    1717resource app_flags B_EXCLUSIVE_LAUNCH;
     
    6868    $"040A0D0112000A0E0113000A0F0114000A100115000A11011600"
    6969};
    7070
     71resource(201, "kActionBack") #'VICN' array {
     72    $"6E636966040500020006023B739F3B784BBD5E1B3D59924AC607487DCF0093E2"
     73    $"06FF25A0000200060237610B3A79B3BE3F6A3B117A4AE42248E57700D4FA9DFF"
     74    $"1A6A0104014A010A072B3E3A2F3A364E364E463A463A4D030A00010010011784"
     75    $"00040A020100000A0101001001157C0004"
     76};
     77 
     78resource(202, "kActionForward") #'VICN' array {
     79    $"6E636966040500020006023B739F3B784BBD5E1B3D59924AC607487DCF0095E2"
     80    $"06FF26A0000200060238B4E439E705BDE7313CB5034A8A3C48635C00D4FA9DFF"
     81    $"1A6A0104014A010A074D3E3E4D3E462AC2232ABBC33E363E2F030A0001001001"
     82    $"178400040A020100000A0101001001157C0004"
     83};
     84 
     85resource(203, "kActionUp") #'VICN' array {
     86    $"6E636966040500020006023B739F3B784BBD5E1B3D59924AE607487DCF00FFBF"
     87    $"44FFFF9806020006023A3F27371338BB135B3E3F414A364447949400FFD789FF"
     88    $"E0860604014A010A07BF592D4DBE2746BE2746C48738C48738BE2731BE27030A"
     89    $"0001001001178400040A020100000A0101001001157C0004"
     90};
  • src/kits/tracker/IconButton.cpp

    diff -Naur tracker_layout-haiku/src/kits/tracker/IconButton.cpp tracker_layout-aldeck/src/kits/tracker/IconButton.cpp
    old new  
     1/*
     2 * Copyright 2006-2010, Haiku.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Stephan Aßmus <superstippi@gmx.de>
     7 */
     8
     9// NOTE: this file is a duplicate of the version in Icon-O-Matic/generic
     10// it should be placed into a common folder for generic useful stuff
     11
     12#include "IconButton.h"
     13
     14#include <new>
     15#include <stdio.h>
     16
     17#include <Application.h>
     18#include <Bitmap.h>
     19#include <Control.h>
     20#include <ControlLook.h>
     21#include <Entry.h>
     22#include <Looper.h>
     23#include <Message.h>
     24#include <Mime.h>
     25#include <Path.h>
     26#include <Region.h>
     27#include <Resources.h>
     28#include <Roster.h>
     29#include <TranslationUtils.h>
     30#include <Window.h>
     31#include "IconUtils.h"
     32
     33using std::nothrow;
     34
     35// constructor
     36IconButton::IconButton(const char* name, uint32 id, uint32 size,
     37    const char* label, BMessage* message, BHandler* target)
     38    :
     39    BView(name, B_WILL_DRAW),
     40    BInvoker(message, target),
     41    fButtonState(STATE_ENABLED),
     42    fID(id),
     43    fSize(size),
     44    fNormalBitmap(NULL),
     45    fDisabledBitmap(NULL),
     46    fClickedBitmap(NULL),
     47    fDisabledClickedBitmap(NULL),
     48    fLabel(label),
     49    fTargetCache(target)
     50{
     51    SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     52}
     53
     54// destructor
     55IconButton::~IconButton()
     56{
     57    _DeleteBitmaps();
     58}
     59
     60// MessageReceived
     61void
     62IconButton::MessageReceived(BMessage* message)
     63{
     64    switch (message->what) {
     65        default:
     66            BView::MessageReceived(message);
     67            break;
     68    }
     69}
     70
     71// AttachedToWindow
     72void
     73IconButton::AttachedToWindow()
     74{
     75    rgb_color background = B_TRANSPARENT_COLOR;
     76    if (BView* parent = Parent()) {
     77        background = parent->ViewColor();
     78        if (background == B_TRANSPARENT_COLOR)
     79            background = parent->LowColor();
     80    }
     81    if (background == B_TRANSPARENT_COLOR)
     82        background = ui_color(B_PANEL_BACKGROUND_COLOR);
     83    SetLowColor(background);
     84
     85    SetTarget(fTargetCache);
     86    if (!Target())
     87        SetTarget(Window());
     88}
     89
     90// Draw
     91void
     92IconButton::Draw(BRect area)
     93{
     94    rgb_color background = LowColor();
     95
     96    BRect r(Bounds());
     97
     98    uint32 flags = 0;
     99    BBitmap* bitmap = fNormalBitmap;
     100    if (!IsEnabled()) {
     101        flags |= BControlLook::B_DISABLED;
     102        bitmap = fDisabledBitmap;
     103    }
     104    if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
     105        flags |= BControlLook::B_ACTIVATED;
     106
     107    if (DrawBorder()) {
     108        be_control_look->DrawButtonFrame(this, r, area, background,
     109            background, flags);
     110        be_control_look->DrawButtonBackground(this, r, area, background,
     111            flags);
     112    }
     113
     114    if (bitmap && bitmap->IsValid()) {
     115        float x = r.left + floorf((r.Width()
     116            - bitmap->Bounds().Width()) / 2.0 + 0.5);
     117        float y = r.top + floorf((r.Height()
     118            - bitmap->Bounds().Height()) / 2.0 + 0.5);
     119        BPoint point(x, y);
     120        if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
     121            point += BPoint(1.0, 1.0);
     122        if (bitmap->ColorSpace() == B_RGBA32
     123            || bitmap->ColorSpace() == B_RGBA32_BIG) {
     124            SetDrawingMode(B_OP_ALPHA);
     125            SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
     126        }
     127        DrawBitmap(bitmap, point);
     128    }
     129}
     130
     131// MouseDown
     132void
     133IconButton::MouseDown(BPoint where)
     134{
     135    if (!IsValid())
     136        return;
     137
     138    if (_HasFlags(STATE_ENABLED)/* && !_HasFlags(STATE_FORCE_PRESSED)*/) {
     139        if (Bounds().Contains(where)) {
     140            SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
     141            _AddFlags(STATE_PRESSED | STATE_TRACKING);
     142        } else {
     143            _ClearFlags(STATE_PRESSED | STATE_TRACKING);
     144        }
     145    }
     146}
     147
     148// MouseUp
     149void
     150IconButton::MouseUp(BPoint where)
     151{
     152    if (!IsValid())
     153        return;
     154
     155//  if (!_HasFlags(STATE_FORCE_PRESSED)) {
     156        if (_HasFlags(STATE_ENABLED) && _HasFlags(STATE_PRESSED) && Bounds().Contains(where))
     157            Invoke();
     158        else if (Bounds().Contains(where))
     159            _AddFlags(STATE_INSIDE);
     160        _ClearFlags(STATE_PRESSED | STATE_TRACKING);
     161//  }
     162}
     163
     164// MouseMoved
     165void
     166IconButton::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
     167{
     168    if (!IsValid())
     169        return;
     170
     171    uint32 buttons = 0;
     172    Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
     173    // catch a mouse up event that we might have missed
     174    if (!buttons && _HasFlags(STATE_PRESSED)) {
     175        MouseUp(where);
     176        return;
     177    }
     178    if (buttons && !_HasFlags(STATE_TRACKING))
     179        return;
     180    if ((transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW)
     181        && _HasFlags(STATE_ENABLED))
     182        _AddFlags(STATE_INSIDE);
     183    else
     184        _ClearFlags(STATE_INSIDE);
     185    if (_HasFlags(STATE_TRACKING)) {
     186        if (Bounds().Contains(where))
     187            _AddFlags(STATE_PRESSED);
     188        else
     189            _ClearFlags(STATE_PRESSED);
     190    }
     191}
     192
     193#define MIN_SPACE 15.0
     194
     195// GetPreferredSize
     196void
     197IconButton::GetPreferredSize(float* width, float* height)
     198{
     199    float minWidth = 0.0;
     200    float minHeight = 0.0;
     201    if (IsValid()) {
     202        minWidth += fNormalBitmap->Bounds().IntegerWidth() + 1.0;
     203        minHeight += fNormalBitmap->Bounds().IntegerHeight() + 1.0;
     204    }
     205    if (minWidth < MIN_SPACE)
     206        minWidth = MIN_SPACE;
     207    if (minHeight < MIN_SPACE)
     208        minHeight = MIN_SPACE;
     209
     210    float hPadding = max_c(6.0, ceilf(minHeight / 4.0));
     211    float vPadding = max_c(6.0, ceilf(minWidth / 4.0));
     212
     213    if (fLabel.CountChars() > 0) {
     214        font_height fh;
     215        GetFontHeight(&fh);
     216        minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
     217        minWidth += StringWidth(fLabel.String()) + vPadding;
     218    }
     219
     220    if (width)
     221        *width = minWidth + hPadding;
     222    if (height)
     223        *height = minHeight + vPadding;
     224}
     225
     226// MinSize
     227BSize
     228IconButton::MinSize()
     229{
     230    BSize size;
     231    GetPreferredSize(&size.width, &size.height);
     232    return size;
     233}
     234
     235// MaxSize
     236BSize
     237IconButton::MaxSize()
     238{
     239    return MinSize();
     240}
     241
     242// Invoke
     243status_t
     244IconButton::Invoke(BMessage* message)
     245{
     246    if (!message)
     247        message = Message();
     248    if (message) {
     249        BMessage clone(*message);
     250        clone.AddInt64("be:when", system_time());
     251        clone.AddPointer("be:source", (BView*)this);
     252        clone.AddInt32("be:value", Value());
     253        clone.AddInt32("id", ID());
     254        return BInvoker::Invoke(&clone);
     255    }
     256    return BInvoker::Invoke(message);
     257}
     258
     259// SetPressed
     260void
     261IconButton::SetPressed(bool pressed)
     262{
     263    if (pressed)
     264        _AddFlags(STATE_FORCE_PRESSED);
     265    else
     266        _ClearFlags(STATE_FORCE_PRESSED);
     267}
     268
     269// IsPressed
     270bool
     271IconButton::IsPressed() const
     272{
     273    return _HasFlags(STATE_FORCE_PRESSED);
     274}
     275
     276status_t
     277IconButton::SetIcon(int32 resourceID)
     278{
     279    app_info info;
     280    status_t status = be_app->GetAppInfo(&info);
     281    if (status != B_OK)
     282        return status;
     283
     284    BResources resources(&info.ref);
     285    status = resources.InitCheck();
     286    if (status != B_OK)
     287        return status;
     288
     289    size_t size;
     290    const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, resourceID,
     291        &size);
     292    if (data != NULL) {
     293        BBitmap bitmap(BRect(0, 0, fSize - 1, fSize - 1), B_BITMAP_NO_SERVER_LINK, B_RGBA32);
     294        status = bitmap.InitCheck();
     295        if (status != B_OK)
     296            return status;
     297        status = BIconUtils::GetVectorIcon(reinterpret_cast<const uint8*>(data),
     298            size, &bitmap);
     299        if (status != B_OK)
     300            return status;
     301        return SetIcon(&bitmap);
     302    }
     303//  const void* data = resources.LoadResource(B_BITMAP_TYPE, resourceID, &size);
     304    return B_ERROR;
     305}
     306
     307// SetIcon
     308status_t
     309IconButton::SetIcon(const char* pathToBitmap)
     310{
     311    if (pathToBitmap == NULL)
     312        return B_BAD_VALUE;
     313
     314    status_t status = B_BAD_VALUE;
     315    BBitmap* fileBitmap = NULL;
     316    // try to load bitmap from either relative or absolute path
     317    BEntry entry(pathToBitmap, true);
     318    if (!entry.Exists()) {
     319        app_info info;
     320        status = be_app->GetAppInfo(&info);
     321        if (status == B_OK) {
     322            BEntry app_entry(&info.ref, true);
     323            BPath path;
     324            app_entry.GetPath(&path);
     325            status = path.InitCheck();
     326            if (status == B_OK) {
     327                status = path.GetParent(&path);
     328                if (status == B_OK) {
     329                    status = path.Append(pathToBitmap, true);
     330                    if (status == B_OK)
     331                        fileBitmap = BTranslationUtils::GetBitmap(path.Path());
     332                    else
     333                        printf("IconButton::SetIcon() - path.Append() failed: %s\n", strerror(status));
     334                } else
     335                    printf("IconButton::SetIcon() - path.GetParent() failed: %s\n", strerror(status));
     336            } else
     337                printf("IconButton::SetIcon() - path.InitCheck() failed: %s\n", strerror(status));
     338        } else
     339            printf("IconButton::SetIcon() - be_app->GetAppInfo() failed: %s\n", strerror(status));
     340    } else
     341        fileBitmap = BTranslationUtils::GetBitmap(pathToBitmap);
     342    if (fileBitmap) {
     343        status = _MakeBitmaps(fileBitmap);
     344        delete fileBitmap;
     345    } else
     346        status = B_ERROR;
     347    return status;
     348}
     349
     350// SetIcon
     351status_t
     352IconButton::SetIcon(const BBitmap* bitmap)
     353{
     354    if (bitmap && bitmap->ColorSpace() == B_CMAP8) {
     355        status_t status = bitmap->InitCheck();
     356        if (status >= B_OK) {
     357            if (BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap)) {
     358                status = _MakeBitmaps(rgb32Bitmap);
     359                delete rgb32Bitmap;
     360            } else
     361                status = B_NO_MEMORY;
     362        }
     363        return status;
     364    } else
     365        return _MakeBitmaps(bitmap);
     366}
     367
     368// SetIcon
     369status_t
     370IconButton::SetIcon(const BMimeType* fileType, bool small)
     371{
     372    status_t status = fileType ? fileType->InitCheck() : B_BAD_VALUE;
     373    if (status >= B_OK) {
     374        BBitmap* mimeBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, 15.0, 15.0), B_CMAP8);
     375        if (mimeBitmap && mimeBitmap->IsValid()) {
     376            status = fileType->GetIcon(mimeBitmap, small ? B_MINI_ICON : B_LARGE_ICON);
     377            if (status >= B_OK) {
     378                if (BBitmap* bitmap = _ConvertToRGB32(mimeBitmap)) {
     379                    status = _MakeBitmaps(bitmap);
     380                    delete bitmap;
     381                } else
     382                    printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
     383            } else
     384                printf("IconButton::SetIcon() - fileType->GetIcon() failed: %s\n", strerror(status));
     385        } else
     386            printf("IconButton::SetIcon() - B_CMAP8 bitmap is not valid\n");
     387        delete mimeBitmap;
     388    } else
     389        printf("IconButton::SetIcon() - fileType is not valid: %s\n", strerror(status));
     390    return status;
     391}
     392
     393// SetIcon
     394status_t
     395IconButton::SetIcon(const unsigned char* bitsFromQuickRes,
     396    uint32 width, uint32 height, color_space format, bool convertToBW)
     397{
     398    status_t status = B_BAD_VALUE;
     399    if (bitsFromQuickRes && width > 0 && height > 0) {
     400        BBitmap* quickResBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, width - 1.0, height - 1.0), format);
     401        status = quickResBitmap ? quickResBitmap->InitCheck() : B_ERROR;
     402        if (status >= B_OK) {
     403            // It doesn't look right to copy BitsLength() bytes, but bitmaps
     404            // exported from QuickRes still contain their padding, so it is alright.
     405            memcpy(quickResBitmap->Bits(), bitsFromQuickRes, quickResBitmap->BitsLength());
     406            if (format != B_RGB32 && format != B_RGBA32 && format != B_RGB32_BIG && format != B_RGBA32_BIG) {
     407                // colorspace needs conversion
     408                BBitmap* bitmap = new(nothrow) BBitmap(quickResBitmap->Bounds(), B_RGB32, true);
     409                if (bitmap && bitmap->IsValid()) {
     410                    BView* helper = new BView(bitmap->Bounds(), "helper",
     411                                              B_FOLLOW_NONE, B_WILL_DRAW);
     412                    if (bitmap->Lock()) {
     413                        bitmap->AddChild(helper);
     414                        helper->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     415                        helper->FillRect(helper->Bounds());
     416                        helper->SetDrawingMode(B_OP_OVER);
     417                        helper->DrawBitmap(quickResBitmap, BPoint(0.0, 0.0));
     418                        helper->Sync();
     419                        bitmap->Unlock();
     420                    }
     421                    status = _MakeBitmaps(bitmap);
     422                } else
     423                    printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
     424                delete bitmap;
     425            } else {
     426                // native colorspace (32 bits)
     427                if (convertToBW) {
     428                    // convert to gray scale icon
     429                    uint8* bits = (uint8*)quickResBitmap->Bits();
     430                    uint32 bpr = quickResBitmap->BytesPerRow();
     431                    for (uint32 y = 0; y < height; y++) {
     432                        uint8* handle = bits;
     433                        uint8 gray;
     434                        for (uint32 x = 0; x < width; x++) {
     435                            gray = uint8((116 * handle[0] + 600 * handle[1] + 308 * handle[2]) / 1024);
     436                            handle[0] = gray;
     437                            handle[1] = gray;
     438                            handle[2] = gray;
     439                            handle += 4;
     440                        }
     441                        bits += bpr;
     442                    }
     443                }
     444                status = _MakeBitmaps(quickResBitmap);
     445            }
     446        } else
     447            printf("IconButton::SetIcon() - error allocating bitmap: %s\n", strerror(status));
     448        delete quickResBitmap;
     449    }
     450    return status;
     451}
     452
     453// ClearIcon
     454void
     455IconButton::ClearIcon()
     456{
     457    _DeleteBitmaps();
     458    _Update();
     459}
     460
     461void
     462IconButton::TrimIcon(bool keepAspect)
     463{
     464    if (fNormalBitmap == NULL)
     465        return;
     466
     467    uint8* bits = (uint8*)fNormalBitmap->Bits();
     468    uint32 bpr = fNormalBitmap->BytesPerRow();
     469    uint32 width = fNormalBitmap->Bounds().IntegerWidth() + 1;
     470    uint32 height = fNormalBitmap->Bounds().IntegerHeight() + 1;
     471    BRect trimmed(LONG_MAX, LONG_MAX, LONG_MIN, LONG_MIN);
     472    for (uint32 y = 0; y < height; y++) {
     473        uint8* b = bits + 3;
     474        bool rowHasAlpha = false;
     475        for (uint32 x = 0; x < width; x++) {
     476            if (*b) {
     477                rowHasAlpha = true;
     478                if (x < trimmed.left)
     479                    trimmed.left = x;
     480                if (x > trimmed.right)
     481                    trimmed.right = x;
     482            }
     483            b += 4;
     484        }
     485        if (rowHasAlpha) {
     486            if (y < trimmed.top)
     487                trimmed.top = y;
     488            if (y > trimmed.bottom)
     489                trimmed.bottom = y;
     490        }
     491        bits += bpr;
     492    }
     493    if (!trimmed.IsValid())
     494        return;
     495    if (keepAspect) {
     496        float minInset = trimmed.left;
     497        minInset = min_c(minInset, trimmed.top);
     498        minInset = min_c(minInset, fNormalBitmap->Bounds().right - trimmed.right);
     499        minInset = min_c(minInset, fNormalBitmap->Bounds().bottom - trimmed.bottom);
     500        trimmed = fNormalBitmap->Bounds().InsetByCopy(minInset, minInset);
     501    }
     502    trimmed = trimmed & fNormalBitmap->Bounds();
     503    BBitmap trimmedBitmap(trimmed.OffsetToCopy(B_ORIGIN),
     504        B_BITMAP_NO_SERVER_LINK, B_RGBA32);
     505    bits = (uint8*)fNormalBitmap->Bits();
     506    bits += 4 * (int32)trimmed.left + bpr * (int32)trimmed.top;
     507    uint8* dst = (uint8*)trimmedBitmap.Bits();
     508    uint32 trimmedWidth = trimmedBitmap.Bounds().IntegerWidth() + 1;
     509    uint32 trimmedHeight = trimmedBitmap.Bounds().IntegerHeight() + 1;
     510    uint32 trimmedBPR = trimmedBitmap.BytesPerRow();
     511    for (uint32 y = 0; y < trimmedHeight; y++) {
     512        memcpy(dst, bits, trimmedWidth * 4);
     513        dst += trimmedBPR;
     514        bits += bpr;
     515    }
     516    SetIcon(&trimmedBitmap);
     517}
     518
     519// Bitmap
     520BBitmap*
     521IconButton::Bitmap() const
     522{
     523    BBitmap* bitmap = NULL;
     524    if (fNormalBitmap && fNormalBitmap->IsValid()) {
     525        bitmap = new(nothrow) BBitmap(fNormalBitmap);
     526        if (bitmap->IsValid()) {
     527            // TODO: remove this functionality when we use real transparent bitmaps
     528            uint8* bits = (uint8*)bitmap->Bits();
     529            uint32 bpr = bitmap->BytesPerRow();
     530            uint32 width = bitmap->Bounds().IntegerWidth() + 1;
     531            uint32 height = bitmap->Bounds().IntegerHeight() + 1;
     532            color_space format = bitmap->ColorSpace();
     533            if (format == B_CMAP8) {
     534                // replace gray with magic transparent index
     535            } else if (format == B_RGB32) {
     536                for (uint32 y = 0; y < height; y++) {
     537                    uint8* bitsHandle = bits;
     538                    for (uint32 x = 0; x < width; x++) {
     539                        if (bitsHandle[0] == 216
     540                            && bitsHandle[1] == 216
     541                            && bitsHandle[2] == 216) {
     542                            bitsHandle[3] = 0;  // make this pixel completely transparent
     543                        }
     544                        bitsHandle += 4;
     545                    }
     546                    bits += bpr;
     547                }
     548            }
     549        } else {
     550            delete bitmap;
     551            bitmap = NULL;
     552        }
     553    }
     554    return bitmap;
     555}
     556
     557// DrawBorder
     558bool
     559IconButton::DrawBorder() const
     560{
     561    return ((IsEnabled() && (_HasFlags(STATE_INSIDE)
     562        || _HasFlags(STATE_TRACKING))) || _HasFlags(STATE_FORCE_PRESSED));
     563}
     564
     565// DrawNormalBorder
     566void
     567IconButton::DrawNormalBorder(BRect r, rgb_color background,
     568    rgb_color shadow, rgb_color darkShadow,
     569    rgb_color lightShadow, rgb_color light)
     570{
     571    _DrawFrame(r, shadow, darkShadow, light, lightShadow);
     572}
     573
     574// DrawPressedBorder
     575void
     576IconButton::DrawPressedBorder(BRect r, rgb_color background,
     577    rgb_color shadow, rgb_color darkShadow,
     578    rgb_color lightShadow, rgb_color light)
     579{
     580    _DrawFrame(r, shadow, light, darkShadow, background);
     581}
     582
     583// IsValid
     584bool
     585IconButton::IsValid() const
     586{
     587    return (fNormalBitmap && fDisabledBitmap && fClickedBitmap
     588        && fDisabledClickedBitmap
     589        && fNormalBitmap->IsValid()
     590        && fDisabledBitmap->IsValid()
     591        && fClickedBitmap->IsValid()
     592        && fDisabledClickedBitmap->IsValid());
     593}
     594
     595// Value
     596int32
     597IconButton::Value() const
     598{
     599    return _HasFlags(STATE_PRESSED) ? B_CONTROL_ON : B_CONTROL_OFF;
     600}
     601
     602// SetValue
     603void
     604IconButton::SetValue(int32 value)
     605{
     606    if (value)
     607        _AddFlags(STATE_PRESSED);
     608    else
     609        _ClearFlags(STATE_PRESSED);
     610}
     611
     612// IsEnabled
     613bool
     614IconButton::IsEnabled() const
     615{
     616    return _HasFlags(STATE_ENABLED) ? B_CONTROL_ON : B_CONTROL_OFF;
     617}
     618
     619// SetEnabled
     620void
     621IconButton::SetEnabled(bool enabled)
     622{
     623    if (enabled)
     624        _AddFlags(STATE_ENABLED);
     625    else
     626        _ClearFlags(STATE_ENABLED | STATE_TRACKING | STATE_INSIDE);
     627}
     628
     629// _ConvertToRGB32
     630BBitmap*
     631IconButton::_ConvertToRGB32(const BBitmap* bitmap) const
     632{
     633    BBitmap* convertedBitmap = new(nothrow) BBitmap(bitmap->Bounds(),
     634        B_BITMAP_ACCEPTS_VIEWS, B_RGBA32);
     635    if (convertedBitmap && convertedBitmap->IsValid()) {
     636        memset(convertedBitmap->Bits(), 0, convertedBitmap->BitsLength());
     637        BView* helper = new BView(bitmap->Bounds(), "helper",
     638                                  B_FOLLOW_NONE, B_WILL_DRAW);
     639        if (convertedBitmap->Lock()) {
     640            convertedBitmap->AddChild(helper);
     641            helper->SetDrawingMode(B_OP_OVER);
     642            helper->DrawBitmap(bitmap, BPoint(0.0, 0.0));
     643            helper->Sync();
     644            convertedBitmap->Unlock();
     645        }
     646    } else {
     647        delete convertedBitmap;
     648        convertedBitmap = NULL;
     649    }
     650    return convertedBitmap;
     651}
     652
     653// _MakeBitmaps
     654status_t
     655IconButton::_MakeBitmaps(const BBitmap* bitmap)
     656{
     657    status_t status = bitmap ? bitmap->InitCheck() : B_BAD_VALUE;
     658    if (status >= B_OK) {
     659        // make our own versions of the bitmap
     660        BRect b(bitmap->Bounds());
     661        _DeleteBitmaps();
     662        color_space format = bitmap->ColorSpace();
     663        fNormalBitmap = new(nothrow) BBitmap(b, format);
     664        fDisabledBitmap = new(nothrow) BBitmap(b, format);
     665        fClickedBitmap = new(nothrow) BBitmap(b, format);
     666        fDisabledClickedBitmap = new(nothrow) BBitmap(b, format);
     667        if (IsValid()) {
     668            // copy bitmaps from file bitmap
     669            uint8* nBits = (uint8*)fNormalBitmap->Bits();
     670            uint8* dBits = (uint8*)fDisabledBitmap->Bits();
     671            uint8* cBits = (uint8*)fClickedBitmap->Bits();
     672            uint8* dcBits = (uint8*)fDisabledClickedBitmap->Bits();
     673            uint8* fBits = (uint8*)bitmap->Bits();
     674            int32 nbpr = fNormalBitmap->BytesPerRow();
     675            int32 fbpr = bitmap->BytesPerRow();
     676            int32 pixels = b.IntegerWidth() + 1;
     677            int32 lines = b.IntegerHeight() + 1;
     678            // nontransparent version:
     679            if (format == B_RGB32 || format == B_RGB32_BIG) {
     680                // iterate over color components
     681                for (int32 y = 0; y < lines; y++) {
     682                    for (int32 x = 0; x < pixels; x++) {
     683                        int32 nOffset = 4 * x;
     684                        int32 fOffset = 4 * x;
     685                        nBits[nOffset + 0] = fBits[fOffset + 0];
     686                        nBits[nOffset + 1] = fBits[fOffset + 1];
     687                        nBits[nOffset + 2] = fBits[fOffset + 2];
     688                        nBits[nOffset + 3] = 255;
     689                        // clicked bits are darker (lame method...)
     690                        cBits[nOffset + 0] = (uint8)((float)nBits[nOffset + 0] * 0.8);
     691                        cBits[nOffset + 1] = (uint8)((float)nBits[nOffset + 1] * 0.8);
     692                        cBits[nOffset + 2] = (uint8)((float)nBits[nOffset + 2] * 0.8);
     693                        cBits[nOffset + 3] = 255;
     694                        // disabled bits have less contrast (lame method...)
     695                        uint8 grey = 216;
     696                        float dist = (nBits[nOffset + 0] - grey) * 0.4;
     697                        dBits[nOffset + 0] = (uint8)(grey + dist);
     698                        dist = (nBits[nOffset + 1] - grey) * 0.4;
     699                        dBits[nOffset + 1] = (uint8)(grey + dist);
     700                        dist = (nBits[nOffset + 2] - grey) * 0.4;
     701                        dBits[nOffset + 2] = (uint8)(grey + dist);
     702                        dBits[nOffset + 3] = 255;
     703                        // disabled bits have less contrast (lame method...)
     704                        grey = 188;
     705                        dist = (nBits[nOffset + 0] - grey) * 0.4;
     706                        dcBits[nOffset + 0] = (uint8)(grey + dist);
     707                        dist = (nBits[nOffset + 1] - grey) * 0.4;
     708                        dcBits[nOffset + 1] = (uint8)(grey + dist);
     709                        dist = (nBits[nOffset + 2] - grey) * 0.4;
     710                        dcBits[nOffset + 2] = (uint8)(grey + dist);
     711                        dcBits[nOffset + 3] = 255;
     712                    }
     713                    nBits += nbpr;
     714                    dBits += nbpr;
     715                    cBits += nbpr;
     716                    dcBits += nbpr;
     717                    fBits += fbpr;
     718                }
     719            // transparent version:
     720            } else if (format == B_RGBA32 || format == B_RGBA32_BIG) {
     721                // iterate over color components
     722                for (int32 y = 0; y < lines; y++) {
     723                    for (int32 x = 0; x < pixels; x++) {
     724                        int32 nOffset = 4 * x;
     725                        int32 fOffset = 4 * x;
     726                        nBits[nOffset + 0] = fBits[fOffset + 0];
     727                        nBits[nOffset + 1] = fBits[fOffset + 1];
     728                        nBits[nOffset + 2] = fBits[fOffset + 2];
     729                        nBits[nOffset + 3] = fBits[fOffset + 3];
     730                        // clicked bits are darker (lame method...)
     731                        cBits[nOffset + 0] = (uint8)(nBits[nOffset + 0] * 0.8);
     732                        cBits[nOffset + 1] = (uint8)(nBits[nOffset + 1] * 0.8);
     733                        cBits[nOffset + 2] = (uint8)(nBits[nOffset + 2] * 0.8);
     734                        cBits[nOffset + 3] = fBits[fOffset + 3];
     735                        // disabled bits have less opacity
     736
     737                        uint8 grey = ((uint16)nBits[nOffset + 0] * 10
     738                            + nBits[nOffset + 1] * 60
     739                            + nBits[nOffset + 2] * 30) / 100;
     740                        float dist = (nBits[nOffset + 0] - grey) * 0.3;
     741                        dBits[nOffset + 0] = (uint8)(grey + dist);
     742                        dist = (nBits[nOffset + 1] - grey) * 0.3;
     743                        dBits[nOffset + 1] = (uint8)(grey + dist);
     744                        dist = (nBits[nOffset + 2] - grey) * 0.3;
     745                        dBits[nOffset + 2] = (uint8)(grey + dist);
     746                        dBits[nOffset + 3] = (uint8)(fBits[fOffset + 3] * 0.3);
     747                        // disabled bits have less contrast (lame method...)
     748                        dcBits[nOffset + 0] = (uint8)(dBits[nOffset + 0] * 0.8);
     749                        dcBits[nOffset + 1] = (uint8)(dBits[nOffset + 1] * 0.8);
     750                        dcBits[nOffset + 2] = (uint8)(dBits[nOffset + 2] * 0.8);
     751                        dcBits[nOffset + 3] = (uint8)(fBits[fOffset + 3] * 0.3);
     752                    }
     753                    nBits += nbpr;
     754                    dBits += nbpr;
     755                    cBits += nbpr;
     756                    dcBits += nbpr;
     757                    fBits += fbpr;
     758                }
     759            // unsupported format
     760            } else {
     761                printf("IconButton::_MakeBitmaps() - bitmap has unsupported colorspace\n");
     762                status = B_MISMATCHED_VALUES;
     763                _DeleteBitmaps();
     764            }
     765        } else {
     766            printf("IconButton::_MakeBitmaps() - error allocating local bitmaps\n");
     767            status = B_NO_MEMORY;
     768            _DeleteBitmaps();
     769        }
     770    } else
     771        printf("IconButton::_MakeBitmaps() - bitmap is not valid\n");
     772    return status;
     773}
     774
     775// _DeleteBitmaps
     776void
     777IconButton::_DeleteBitmaps()
     778{
     779    delete fNormalBitmap;
     780    fNormalBitmap = NULL;
     781    delete fDisabledBitmap;
     782    fDisabledBitmap = NULL;
     783    delete fClickedBitmap;
     784    fClickedBitmap = NULL;
     785    delete fDisabledClickedBitmap;
     786    fDisabledClickedBitmap = NULL;
     787}
     788
     789// _Update
     790void
     791IconButton::_Update()
     792{
     793    if (LockLooper()) {
     794        Invalidate();
     795        UnlockLooper();
     796    }
     797}
     798
     799// _AddFlags
     800void
     801IconButton::_AddFlags(uint32 flags)
     802{
     803    if (!(fButtonState & flags)) {
     804        fButtonState |= flags;
     805        _Update();
     806    }
     807}
     808
     809// _ClearFlags
     810void
     811IconButton::_ClearFlags(uint32 flags)
     812{
     813    if (fButtonState & flags) {
     814        fButtonState &= ~flags;
     815        _Update();
     816    }
     817}
     818
     819// _HasFlags
     820bool
     821IconButton::_HasFlags(uint32 flags) const
     822{
     823    return (fButtonState & flags);
     824}
     825
     826// _DrawFrame
     827void
     828IconButton::_DrawFrame(BRect r, rgb_color col1, rgb_color col2,
     829                       rgb_color col3, rgb_color col4)
     830{
     831    BeginLineArray(8);
     832        AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col1);
     833        AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col1);
     834        AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col2);
     835        AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col2);
     836        r.InsetBy(1.0, 1.0);
     837        AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col3);
     838        AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col3);
     839        AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col4);
     840        AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col4);
     841    EndLineArray();
     842}
  • src/kits/tracker/IconButton.h

    diff -Naur tracker_layout-haiku/src/kits/tracker/IconButton.h tracker_layout-aldeck/src/kits/tracker/IconButton.h
    old new  
     1/*
     2 * Copyright 2006-2010, Haiku.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Stephan Aßmus <superstippi@gmx.de>
     7 */
     8
     9/** gui class that loads an image from disk and shows it
     10    as clickable button */
     11
     12// TODO: inherit from BControl?
     13
     14// NOTE: this file is a duplicate of the version in Icon-O-Matic/generic
     15// it should be placed into a common folder for generic useful stuff
     16
     17#ifndef ICON_BUTTON_H
     18#define ICON_BUTTON_H
     19
     20#include <Invoker.h>
     21#include <String.h>
     22#include <View.h>
     23
     24class BBitmap;
     25class BMimeType;
     26
     27class IconButton : public BView, public BInvoker {
     28public:
     29                                IconButton(const char* name,
     30                                           uint32 id,
     31                                           uint32 size,
     32                                           const char* label = NULL,
     33                                           BMessage* message = NULL,
     34                                           BHandler* target = NULL);
     35    virtual                     ~IconButton();
     36
     37    // BView interface
     38    virtual void                MessageReceived(BMessage* message);
     39    virtual void                AttachedToWindow();
     40    virtual void                Draw(BRect updateRect);
     41    virtual void                MouseDown(BPoint where);
     42    virtual void                MouseUp(BPoint where);
     43    virtual void                MouseMoved(BPoint where, uint32 transit,
     44                                           const BMessage* message);
     45    virtual void                GetPreferredSize(float* width,
     46                                                 float* height);
     47    virtual BSize               MinSize();
     48    virtual BSize               MaxSize();
     49
     50
     51    // BInvoker interface
     52    virtual status_t            Invoke(BMessage* message = NULL);
     53
     54    // IconButton
     55            bool                IsValid() const;
     56
     57    virtual int32               Value() const;
     58    virtual void                SetValue(int32 value);
     59
     60            bool                IsEnabled() const;
     61            void                SetEnabled(bool enable);
     62
     63            void                SetPressed(bool pressed);
     64            bool                IsPressed() const;
     65            uint32              ID() const
     66                                    { return fID; }
     67
     68            status_t            SetIcon(int32 resourceID);
     69            status_t            SetIcon(const char* pathToBitmap);
     70            status_t            SetIcon(const BBitmap* bitmap);
     71            status_t            SetIcon(const BMimeType* fileType,
     72                                        bool small = true);
     73            status_t            SetIcon(const unsigned char* bitsFromQuickRes,
     74                                        uint32 width, uint32 height,
     75                                        color_space format,
     76                                        bool convertToBW = false);
     77            void                ClearIcon();
     78            void                TrimIcon(bool keepAspect = true);
     79
     80            BBitmap*            Bitmap() const;
     81                                    // caller has to delete the returned bitmap
     82
     83    virtual bool                DrawBorder() const;
     84    virtual void                DrawNormalBorder(BRect r,
     85                                                 rgb_color background,
     86                                                 rgb_color shadow,
     87                                                 rgb_color darkShadow,
     88                                                 rgb_color lightShadow,
     89                                                 rgb_color light);
     90    virtual void                DrawPressedBorder(BRect r,
     91                                                  rgb_color background,
     92                                                  rgb_color shadow,
     93                                                  rgb_color darkShadow,
     94                                                  rgb_color lightShadow,
     95                                                  rgb_color light);
     96
     97protected:
     98            enum {
     99                STATE_NONE          = 0x0000,
     100                STATE_TRACKING      = 0x0001,
     101                STATE_PRESSED       = 0x0002,
     102                STATE_ENABLED       = 0x0004,
     103                STATE_INSIDE        = 0x0008,
     104                STATE_FORCE_PRESSED = 0x0010,
     105            };
     106
     107            void                _AddFlags(uint32 flags);
     108            void                _ClearFlags(uint32 flags);
     109            bool                _HasFlags(uint32 flags) const;
     110
     111            void                _DrawFrame(BRect frame,
     112                                           rgb_color col1,
     113                                           rgb_color col2,
     114                                           rgb_color col3,
     115                                           rgb_color col4);
     116
     117// private:
     118            BBitmap*            _ConvertToRGB32(const BBitmap* bitmap) const;
     119            status_t            _MakeBitmaps(const BBitmap* bitmap);
     120            void                _DeleteBitmaps();
     121            void                _SendMessage() const;
     122            void                _Update();
     123
     124            uint32              fButtonState;
     125            int32               fID;
     126            uint32              fSize;
     127            BBitmap*            fNormalBitmap;
     128            BBitmap*            fDisabledBitmap;
     129            BBitmap*            fClickedBitmap;
     130            BBitmap*            fDisabledClickedBitmap;
     131            BString             fLabel;
     132
     133            BHandler*           fTargetCache;
     134};
     135
     136#endif // ICON_BUTTON_H
  • src/kits/tracker/Jamfile

    diff -Naur tracker_layout-haiku/src/kits/tracker/Jamfile tracker_layout-aldeck/src/kits/tracker/Jamfile
    old new  
    4242    FilePermissionsView.cpp
    4343    FindPanel.cpp
    4444    GroupedMenu.cpp
     45    IconButton.cpp
    4546    IconCache.cpp
    4647    IconMenuItem.cpp
    4748    InfoWindow.cpp
  • src/kits/tracker/Navigator.cpp

    diff -Naur tracker_layout-haiku/src/kits/tracker/Navigator.cpp tracker_layout-aldeck/src/kits/tracker/Navigator.cpp
    old new  
    3535#include "Commands.h"
    3636#include "ContainerWindow.h"
    3737#include "FSUtils.h"
     38#include "IconButton.h"
    3839#include "Model.h"
    3940#include "Navigator.h"
    4041#include "Tracker.h"
     42
     43#include <ControlLook.h>
     44#include <GroupLayoutBuilder.h>
     45#include <Region.h>
    4146#include <Window.h>
    4247#include <Picture.h>
    4348#include <TextControl.h>
     
    4853
    4954}
    5055
    51 // BPictureButton() will crash when giving zero pointers,
    52 // although we really want and have to set up the
    53 // pictures when we can, e.g. on a AttachedToWindow.
    54 static BPicture sPicture;
    55 
    56 BNavigatorButton::BNavigatorButton(BRect rect, const char *name, BMessage *message,
    57     int32 resIDon, int32 resIDoff, int32 resIDdisabled)
    58     :   BPictureButton(rect, name, &sPicture, &sPicture, message),
    59         fResIDOn(resIDon),
    60         fResIDOff(resIDoff),
    61         fResIDDisabled(resIDdisabled)
    62 {
    63     // Clear to background color to
    64     // avoid ugly border on click
    65     SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    66     SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    67     SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    68 }
    69 
    70 BNavigatorButton::~BNavigatorButton()
    71 {
    72 }
    73 
    74 void
    75 BNavigatorButton::AttachedToWindow()
    76 {
    77     BBitmap *bmpOn = 0;
    78     GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, fResIDOn, &bmpOn);
    79     SetPicture(bmpOn, true, true);
    80     delete bmpOn;
    81    
    82     BBitmap *bmpOff = 0;
    83     GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, fResIDOff, &bmpOff);
    84     SetPicture(bmpOff, true, false);
    85     delete bmpOff;
    86 
    87     BBitmap *bmpDisabled = 0;
    88     GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, fResIDDisabled, &bmpDisabled);
    89     SetPicture(bmpDisabled, false, false);
    90     SetPicture(bmpDisabled, false, true);
    91     delete bmpDisabled;
    92 }
    93 
    94 void
    95 BNavigatorButton::SetPicture(BBitmap *bitmap, bool enabled, bool on)
    96 {
    97     if (bitmap) {
    98         BPicture picture;
    99         BView view(bitmap->Bounds(), "", 0, 0);
    100         AddChild(&view);
    101         view.BeginPicture(&picture);
    102         view.SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    103         view.FillRect(view.Bounds());
    104         view.SetDrawingMode(B_OP_OVER);
    105         view.DrawBitmap(bitmap, BPoint(0, 0));
    106         view.EndPicture();
    107         RemoveChild(&view);
    108         if (enabled)
    109             if (on)
    110                 SetEnabledOn(&picture);
    111             else
    112                 SetEnabledOff(&picture);
    113         else
    114             if (on)
    115                 SetDisabledOn(&picture);
    116             else
    117                 SetDisabledOff(&picture);
    118     }   
    119 }
    120 
    121 
    12256BNavigator::BNavigator(const Model *model, BRect rect, uint32 resizeMask)
    12357    :   BView(rect, "Navigator", resizeMask, B_WILL_DRAW),
    124     fBack(0),
    125     fForw(0),
    126     fUp(0),
     58    fBackButton(NULL),
     59    fForwardButton(NULL),
     60    fUpButton(NULL),
    12761    fBackHistory(8, true),
    12862    fForwHistory(8, true)
    12963{
     
    13266   
    13367    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    13468
    135     float top = 2 + (be_plain_font->Size() - 8) / 2;
    136 
    137     // Set up widgets
    138     fBack = new BNavigatorButton(BRect(3, top, 21, top + 17), "Back",
    139         new BMessage(kNavigatorCommandBackward), R_ResBackNavActiveSel,
    140         R_ResBackNavActive, R_ResBackNavInactive);
    141     fBack->SetEnabled(false);
    142     AddChild(fBack);
    143 
    144     fForw = new BNavigatorButton(BRect(35, top, 53, top + 17), "Forw",
    145         new BMessage(kNavigatorCommandForward), R_ResForwNavActiveSel,
    146         R_ResForwNavActive, R_ResForwNavInactive);
    147     fForw->SetEnabled(false);
    148     AddChild(fForw);
    149 
    150     fUp = new BNavigatorButton(BRect(67, top, 84, top + 17), "Up",
    151         new BMessage(kNavigatorCommandUp), R_ResUpNavActiveSel,
    152         R_ResUpNavActive, R_ResUpNavInactive);
    153     fUp->SetEnabled(false);
    154     AddChild(fUp);
    155 
    156     fLocation = new BTextControl(BRect(97, 2, rect.Width() - 2, 21),
    157         "Location", "", "", new BMessage(kNavigatorCommandLocation),
    158         B_FOLLOW_LEFT_RIGHT);
    159     fLocation->SetDivider(0);
    160     AddChild(fLocation);
     69    // Back, Forward & Up
     70    fBackButton = new IconButton("Back", 0, 32, NULL,
     71        new BMessage(kNavigatorCommandBackward), this);
     72    fBackButton->SetIcon(201);
     73    fBackButton->TrimIcon();
     74     
     75    fForwardButton = new IconButton("Forward", 0, 32, NULL,
     76        new BMessage(kNavigatorCommandForward), this);
     77    fForwardButton->SetIcon(202);
     78    fForwardButton->TrimIcon();
     79     
     80    fUpButton = new IconButton("Up", 0, 32, NULL,
     81        new BMessage(kNavigatorCommandUp), this);
     82    fUpButton->SetIcon(203);
     83    fUpButton->TrimIcon();
     84         
     85    fLocation = new BTextControl("Location", "", "",
     86           new BMessage(kNavigatorCommandLocation));
     87    fLocation->SetDivider(50.0);
     88         
     89    // layout
     90    const float kInsetSpacing = 2;
     91             
     92    SetLayout(new BGroupLayout(B_VERTICAL));
     93    AddChild(BGroupLayoutBuilder(B_HORIZONTAL)
     94        .Add(fBackButton)
     95        .Add(fForwardButton)
     96        .Add(fUpButton)
     97        .Add(fLocation)
     98        .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing)
     99    );
    161100   
    162101}
    163102
     
    171110    // Inital setup of widget states
    172111    UpdateLocation(0, kActionSet);
    173112
    174     // All messages should arrive here
    175     fBack->SetTarget(this);
    176     fForw->SetTarget(this);
    177     fUp->SetTarget(this);
    178113    fLocation->SetTarget(this);
    179114}
    180115
    181116void
    182 BNavigator::Draw(BRect)
    183 {
    184     rgb_color bgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
    185     rgb_color shineColor = ui_color(B_SHINE_COLOR);
    186     rgb_color halfDarkColor = tint_color(bgColor, B_DARKEN_1_TINT);
    187     rgb_color darkColor = tint_color(bgColor, B_DARKEN_2_TINT);
    188     // Draws a beveled smooth border
    189     BeginLineArray(4);
    190     AddLine(Bounds().LeftTop(), Bounds().RightTop(), shineColor);
    191     AddLine(Bounds().LeftTop(), Bounds().LeftBottom() - BPoint(0, 1), shineColor);
    192     AddLine(Bounds().LeftBottom() - BPoint(-1, 1), Bounds().RightBottom() - BPoint(0, 1), halfDarkColor);
    193     AddLine(Bounds().LeftBottom(), Bounds().RightBottom(), darkColor);
    194     EndLineArray();
     117BNavigator::Draw(BRect updateRect)
     118    {
     119    BRegion clipper(updateRect);
     120    clipper.Exclude(fLocation->Frame());
     121    ConstrainClippingRegion(&clipper);
     122    // workaround, since we use B_DRAW_ON_CHILDREN to draw the gradient
     123    // also on the background of the buttons we need to avoid the fLocation
     124    // textfield as it doesn't blank some parts of itself properly.
     125    // TODO: either find a way to avoid using draw on children and achieve
     126    // the same effect and also look if we could do something in BTextField
     127         
     128    BRect bounds(Bounds());         
     129   
     130    rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
     131    SetHighColor(tint_color(base, B_DARKEN_2_TINT));
     132    StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
     133    bounds.bottom--;
     134         
     135    be_control_look->DrawButtonBackground(this, bounds, bounds, base, 0,
     136        BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);
    195137}
    196138
    197139void
     
    371313    BEntry entry;
    372314    if (entry.SetTo(fPath.Path()) == B_OK) {
    373315        BEntry parentEntry;
    374         fUp->SetEnabled(entry.GetParent(&parentEntry) == B_OK && !FSIsDeskDir(&parentEntry));
     316        fUpButton->SetEnabled(entry.GetParent(&parentEntry) == B_OK
     317            && !FSIsDeskDir(&parentEntry));
    375318    }
    376319
    377320    // Enable history buttons if history contains something
    378     fForw->SetEnabled(fForwHistory.CountItems() > 0);
    379     fBack->SetEnabled(fBackHistory.CountItems() > 1);
     321    fForwardButton->SetEnabled(fForwHistory.CountItems() > 0);
     322    fBackButton->SetEnabled(fBackHistory.CountItems() > 1);
    380323
    381324    // Avoid loss of selection and cursor position
    382325    if (action != kActionLocation)
  • src/kits/tracker/Navigator.h

    diff -Naur tracker_layout-haiku/src/kits/tracker/Navigator.h tracker_layout-aldeck/src/kits/tracker/Navigator.h
    old new  
    3939#include <PictureButton.h>
    4040#include <View.h>
    4141
     42#include "ContainerWindow.h"
     43
    4244class BTextControl;
    4345class BEntry;
     46class IconButton;
    4447
    4548namespace BPrivate {
    4649
     50
    4751enum NavigationAction
    4852{
    4953    kActionSet,
     
    5963    kNavigatorCommandLocation = 'NVLC'
    6064};
    6165
    62 // Custom BPictureButton which takes
    63 // bitmap resource IDs as arguments
    64 class BNavigatorButton : public BPictureButton {
    65 public:
    66     BNavigatorButton(BRect rect, const char *name, BMessage *message, int32 resIDon,
    67         int32 resIDoff, int32 resIDdisabled);
    68                      
    69     ~BNavigatorButton();
    70    
    71     virtual void AttachedToWindow();
    72 
    73     void SetPicture(BBitmap *, bool enabled, bool on);
    74 
    75 private:
    76     int32 fResIDOn;
    77     int32 fResIDOff;
    78     int32 fResIDDisabled;
    79 };
    80 
    8166class BNavigator : public BView {
    8267public:
    8368    BNavigator(const Model *model, BRect rect, uint32 resizeMask = B_FOLLOW_LEFT_RIGHT);
     
    10388
    10489private:
    10590
    106     BPath fPath;
    107     BNavigatorButton *fBack;
    108     BNavigatorButton *fForw;
    109     BNavigatorButton *fUp;
    110     BTextControl *fLocation;
     91    BPath               fPath;
     92    IconButton*         fBackButton;
     93    IconButton*         fForwardButton;
     94    IconButton*         fUpButton;
     95    BTextControl*       fLocation;
    11196
    112     BObjectList<BPath> fBackHistory;
    113     BObjectList<BPath> fForwHistory;
     97    BObjectList<BPath>  fBackHistory;
     98    BObjectList<BPath>  fForwHistory;
    11499
    115100    typedef BView _inherited;
    116101};
    117102
     103
    118104inline
    119105BContainerWindow *
    120106BNavigator::Window() const