From cd94fddab267dad9683764eb2606994ae38479c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 28 Mar 2006 11:32:21 +0000 Subject: [PATCH] * Tracker wrote icons with the wrong type at several places. * Also replaced all B_COLOR_8_BIT with the B_CMAP8 constant. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16909 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/tracker/FSUtils.cpp | 15 +- src/kits/tracker/FavoritesConfig.cpp | 10 +- src/kits/tracker/IconMenuItem.cpp | 67 ++--- src/kits/tracker/Model.cpp | 2 +- src/kits/tracker/MountMenu.cpp | 4 +- src/kits/tracker/TrackerInitialState.cpp | 4 +- src/kits/tracker/Utilities.cpp | 353 ++++++++++++++--------- src/kits/tracker/Utilities.h | 2 +- 8 files changed, 271 insertions(+), 186 deletions(-) diff --git a/src/kits/tracker/FSUtils.cpp b/src/kits/tracker/FSUtils.cpp index 5ce1d0673d..13ffcc6ec3 100644 --- a/src/kits/tracker/FSUtils.cpp +++ b/src/kits/tracker/FSUtils.cpp @@ -2126,7 +2126,7 @@ FSGetDeskDir(BDirectory *deskDir, dev_t dev) status_t result = volume.InitCheck(); if (result != B_OK) return result; - + BPath path; result = find_directory(B_DESKTOP_DIRECTORY, &path, true, &volume); if (result != B_OK) @@ -2147,14 +2147,14 @@ FSGetDeskDir(BDirectory *deskDir, dev_t dev) LoadResource('ICON', kResDeskIcon, &size); if (data) - deskDir->WriteAttr(kAttrLargeIcon, B_COLOR_8_BIT_TYPE, 0, data, size); + deskDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size); data = GetTrackerResources()-> LoadResource('MICN', kResDeskIcon, &size); if (data) - deskDir->WriteAttr(kAttrMiniIcon, B_COLOR_8_BIT_TYPE, 0, data, size); - + deskDir->WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size); + return B_OK; } @@ -2631,10 +2631,9 @@ FSCreateTrashDirs() roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) { - if (volume.IsReadOnly() || !volume.IsPersistent()) continue; - + BPath path; find_directory(B_DESKTOP_DIRECTORY, &path, true, &volume); find_directory(B_TRASH_DIRECTORY, &path, true, &volume); @@ -2645,13 +2644,13 @@ FSCreateTrashDirs() const void* data = GetTrackerResources()-> LoadResource('ICON', kResTrashIcon, &size); if (data) { - trashDir.WriteAttr(kAttrLargeIcon, B_COLOR_8_BIT_TYPE, 0, + trashDir.WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size); } data = GetTrackerResources()-> LoadResource('MICN', kResTrashIcon, &size); if (data) { - trashDir.WriteAttr(kAttrMiniIcon, B_COLOR_8_BIT_TYPE, 0, + trashDir.WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size); } } diff --git a/src/kits/tracker/FavoritesConfig.cpp b/src/kits/tracker/FavoritesConfig.cpp index 096ad5adc3..b2cbeb4b09 100644 --- a/src/kits/tracker/FavoritesConfig.cpp +++ b/src/kits/tracker/FavoritesConfig.cpp @@ -1049,8 +1049,8 @@ TDraggableIconButton::AttachedToWindow() else SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fIcon = new BBitmap(BRect(0, 0, 31, 31), B_COLOR_8_BIT); - fIcon->SetBits(kLargeNewGroupIcon, fIcon->BitsLength(), 0, B_COLOR_8_BIT); + fIcon = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8); + fIcon->SetBits(kLargeNewGroupIcon, fIcon->BitsLength(), 0, B_CMAP8); // calculate correct frame for icon and label // sets icon rect and label rect for drawing ResizeToPreferred(); @@ -1250,14 +1250,14 @@ TContentsMenu::AttachedToWindow() fDownBtn->SetTarget(this, Window()); // cache the new group icon - fSmallGroupIcon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT); + fSmallGroupIcon = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8); fSmallGroupIcon->SetBits(kSmallNewGroupIcon, fSmallGroupIcon->BitsLength(), - 0, B_COLOR_8_BIT); + 0, B_CMAP8); // cache the symlink icon BMimeType symlink("application/x-vnd.Be-symlink"); if (symlink.InitCheck() == B_OK) { - fSymlinkIcon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT); + fSymlinkIcon = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8); if (symlink.GetIcon(fSymlinkIcon, B_MINI_ICON) != B_OK) fSymlinkIcon = NULL; } else diff --git a/src/kits/tracker/IconMenuItem.cpp b/src/kits/tracker/IconMenuItem.cpp index f1f7a6b5c6..230e2e3303 100644 --- a/src/kits/tracker/IconMenuItem.cpp +++ b/src/kits/tracker/IconMenuItem.cpp @@ -34,29 +34,29 @@ All rights reserved. // menu items with small icons. +#include "IconCache.h" +#include "IconMenuItem.h" + #include #include #include -#include "IconCache.h" -#include "IconMenuItem.h" - ModelMenuItem::ModelMenuItem(const Model *model, const char *title, - BMessage *message, char shortcut, uint32 modifiers, - bool drawText, bool extraPad) - : BMenuItem(title, message, shortcut, modifiers), - fModel(*model), - fHeightDelta(0), - fDrawText(drawText), - fExtraPad(extraPad) + BMessage *message, char shortcut, uint32 modifiers, + bool drawText, bool extraPad) + : BMenuItem(title, message, shortcut, modifiers), + fModel(*model), + fHeightDelta(0), + fDrawText(drawText), + fExtraPad(extraPad) { ThrowOnInitCheckError(&fModel); - // The 'fExtraPad' field is used to when this menu item is added to - // a menubar instead of a menu. Menus and MenuBars space out items - // differently (more space around items in a menu). This class wants - // to be able to space item the same, no matter where they are. The - // fExtraPad field allows for that. + // The 'fExtraPad' field is used to when this menu item is added to + // a menubar instead of a menu. Menus and MenuBars space out items + // differently (more space around items in a menu). This class wants + // to be able to space item the same, no matter where they are. The + // fExtraPad field allows for that. if (model->IsRoot()) SetLabel(model->Name()); @@ -189,10 +189,11 @@ ModelMenuItem::Invoke(BMessage *message) clone.AddInt64("when", system_time()); clone.AddPointer("source", this); - if ((modifiers() & B_OPTION_KEY) == 0) + if ((modifiers() & B_OPTION_KEY) == 0) { // if option not held, remove refs to close to prevent closing // parent window clone.RemoveData("nodeRefsToClose"); + } return BInvoker::Invoke(&clone); } @@ -226,8 +227,8 @@ SpecialModelMenuItem::DrawContent() IconMenuItem::IconMenuItem(const char *label, BMessage *message, BBitmap *icon) - : PositionPassingMenuItem(label, message), - fDeviceIcon(icon) + : PositionPassingMenuItem(label, message), + fDeviceIcon(icon) { // IconMenuItem is used in synchronously invoked menus, make sure // we invoke with a timeout @@ -236,18 +237,18 @@ IconMenuItem::IconMenuItem(const char *label, BMessage *message, BBitmap *icon) IconMenuItem::IconMenuItem(const char *label, BMessage *message, - const BNodeInfo *nodeInfo, icon_size which) - : PositionPassingMenuItem(label, message), - fDeviceIcon(NULL) + const BNodeInfo *nodeInfo, icon_size which) + : PositionPassingMenuItem(label, message), + fDeviceIcon(NULL) { if (nodeInfo) { - fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), B_COLOR_8_BIT); + fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), B_CMAP8); if (nodeInfo->GetTrackerIcon(fDeviceIcon, B_MINI_ICON)) { delete fDeviceIcon; fDeviceIcon = NULL; } } - + // IconMenuItem is used in synchronously invoked menus, make sure // we invoke with a timeout SetTimeout(kSynchMenuInvokeTimeout); @@ -255,18 +256,18 @@ IconMenuItem::IconMenuItem(const char *label, BMessage *message, IconMenuItem::IconMenuItem(const char *label, BMessage *message, - const char *iconType, icon_size which) - : PositionPassingMenuItem(label, message), - fDeviceIcon(NULL) + const char *iconType, icon_size which) + : PositionPassingMenuItem(label, message), + fDeviceIcon(NULL) { BMimeType mime(iconType); - fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), B_COLOR_8_BIT); + fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), B_CMAP8); if (mime.GetIcon(fDeviceIcon, which) != B_OK) { delete fDeviceIcon; fDeviceIcon = NULL; } - + // IconMenuItem is used in synchronously invoked menus, make sure // we invoke with a timeout SetTimeout(kSynchMenuInvokeTimeout); @@ -274,18 +275,18 @@ IconMenuItem::IconMenuItem(const char *label, BMessage *message, IconMenuItem::IconMenuItem(BMenu *submenu, BMessage *message, - const char *iconType, icon_size which) - : PositionPassingMenuItem(submenu, message), - fDeviceIcon(NULL) + const char *iconType, icon_size which) + : PositionPassingMenuItem(submenu, message), + fDeviceIcon(NULL) { BMimeType mime(iconType); - fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), B_COLOR_8_BIT); + fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), B_CMAP8); if (mime.GetIcon(fDeviceIcon, which) != B_OK) { delete fDeviceIcon; fDeviceIcon = NULL; } - + // IconMenuItem is used in synchronously invoked menus, make sure // we invoke with a timeout SetTimeout(kSynchMenuInvokeTimeout); diff --git a/src/kits/tracker/Model.cpp b/src/kits/tracker/Model.cpp index cf0ee972b6..e575d9936a 100644 --- a/src/kits/tracker/Model.cpp +++ b/src/kits/tracker/Model.cpp @@ -1327,7 +1327,7 @@ Model::TrackIconSource(icon_size size) else rect.Set(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1); - BBitmap bitmap(rect, B_COLOR_8_BIT); + BBitmap bitmap(rect, B_CMAP8); BModelOpener opener(this); diff --git a/src/kits/tracker/MountMenu.cpp b/src/kits/tracker/MountMenu.cpp index 368cb98401..768ba4cc15 100644 --- a/src/kits/tracker/MountMenu.cpp +++ b/src/kits/tracker/MountMenu.cpp @@ -78,7 +78,7 @@ AddOnePartitionAsMenuItem(Partition *partition, void *castToParams) AddOneAsMenuItemParams *params = (AddOneAsMenuItemParams *)castToParams; BBitmap *icon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), - B_COLOR_8_BIT); + B_CMAP8); get_device_icon(partition->GetDevice()->Name(), icon->Bits(), B_MINI_ICON); @@ -160,7 +160,7 @@ MountMenu::AddDynamicItem(add_state) while (volumeRoster.GetNextVolume(&volume) == B_OK) { if (volume.IsShared()) { needSeparator = true; - BBitmap *icon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT); + BBitmap *icon = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8); fs_info info; if (fs_stat_dev(volume.Device(), &info) != B_OK) { PRINT(("Cannot get mount menu item icon; bad device ID\n")); diff --git a/src/kits/tracker/TrackerInitialState.cpp b/src/kits/tracker/TrackerInitialState.cpp index d425b60ded..df8d306fee 100644 --- a/src/kits/tracker/TrackerInitialState.cpp +++ b/src/kits/tracker/TrackerInitialState.cpp @@ -158,8 +158,8 @@ TTracker::InstallMimeIfNeeded(const char *type, int32 bitsID, // whole mime type is installed and all attributes are set; nulls can // be passed for attributes that don't matter; returns true if anything // had to be changed - BBitmap largeIcon(BRect(0, 0, 31, 31), B_COLOR_8_BIT); - BBitmap miniIcon(BRect(0, 0, 15, 15), B_COLOR_8_BIT); + BBitmap largeIcon(BRect(0, 0, 31, 31), B_CMAP8); + BBitmap miniIcon(BRect(0, 0, 15, 15), B_CMAP8); char tmp[B_MIME_TYPE_LENGTH]; BMimeType mime(type); diff --git a/src/kits/tracker/Utilities.cpp b/src/kits/tracker/Utilities.cpp index 229232e095..bba91b5b1f 100644 --- a/src/kits/tracker/Utilities.cpp +++ b/src/kits/tracker/Utilities.cpp @@ -74,11 +74,16 @@ extern _IMPEXP_BE const uint32 MINI_ICON_TYPE; FILE *logFile = NULL; +static const float kMinSeparatorStubX = 10; +static const float kStubToStringSlotX = 5; + + namespace BPrivate { const rgb_color kBlack = {0, 0, 0, 255}; const rgb_color kWhite = {255, 255, 255, 255}; + uint32 HashString(const char *string, uint32 seed) { @@ -94,6 +99,7 @@ HashString(const char *string, uint32 seed) return result; } + uint32 AttrHashString(const char *string, uint32 type) { @@ -113,6 +119,7 @@ AttrHashString(const char *string, uint32 type) return hash; } + bool ValidateStream(BMallocIO *stream, uint32 key, int32 version) { @@ -126,6 +133,7 @@ ValidateStream(BMallocIO *stream, uint32 key, int32 version) return test_key == key && test_version == version; } + void DisallowFilenameKeys(BTextView *textView) { @@ -133,6 +141,7 @@ DisallowFilenameKeys(BTextView *textView) textView->DisallowChar('/'); } + void DisallowMetaKeys(BTextView *textView) { @@ -149,7 +158,8 @@ DisallowMetaKeys(BTextView *textView) } // namespace BPrivate -void + +void PoseInfo::EndianSwap(void *castToThis) { PoseInfo *self = (PoseInfo *)castToThis; @@ -159,7 +169,7 @@ PoseInfo::EndianSwap(void *castToThis) STATIC_ASSERT(sizeof(ino_t) == sizeof(int64)); self->fInitedDirectory = SwapInt64(self->fInitedDirectory); swap_data(B_POINT_TYPE, &self->fLocation, sizeof(BPoint), B_SWAP_ALWAYS); - + // do a sanity check on the icon position if (self->fLocation.x < -20000 || self->fLocation.x > 20000 || self->fLocation.y < -20000 || self->fLocation.y > 20000) { @@ -170,34 +180,40 @@ PoseInfo::EndianSwap(void *castToThis) } } -void + +void PoseInfo::PrintToStream() { PRINT(("%s, inode:%Lx, location %f %f\n", fInvisible ? "hidden" : "visible", fInitedDirectory, fLocation.x, fLocation.y)); } + // #pragma mark - -size_t + +size_t ExtendedPoseInfo::Size() const { return sizeof(ExtendedPoseInfo) + fNumFrames * sizeof(FrameLocation); } -size_t + +size_t ExtendedPoseInfo::Size(int32 count) { return sizeof(ExtendedPoseInfo) + count * sizeof(FrameLocation); } -size_t + +size_t ExtendedPoseInfo::SizeWithHeadroom() const { return sizeof(ExtendedPoseInfo) + (fNumFrames + 1) * sizeof(FrameLocation); } -size_t + +size_t ExtendedPoseInfo::SizeWithHeadroom(size_t oldSize) { int32 count = (ssize_t)oldSize - (ssize_t)sizeof(ExtendedPoseInfo); @@ -205,7 +221,7 @@ ExtendedPoseInfo::SizeWithHeadroom(size_t oldSize) count /= sizeof(FrameLocation); else count = 0; - + return Size(count + 1); } @@ -213,34 +229,41 @@ ExtendedPoseInfo::SizeWithHeadroom(size_t oldSize) bool ExtendedPoseInfo::HasLocationForFrame(BRect frame) const { - for (int32 index = 0; index < fNumFrames; index++) + for (int32 index = 0; index < fNumFrames; index++) { if (fLocations[index].fFrame == frame) return true; + } return false; } -BPoint + +BPoint ExtendedPoseInfo::LocationForFrame(BRect frame) const { - for (int32 index = 0; index < fNumFrames; index++) + for (int32 index = 0; index < fNumFrames; index++) { if (fLocations[index].fFrame == frame) return fLocations[index].fLocation; + } TRESPASS(); return BPoint(0, 0); } -bool + +bool ExtendedPoseInfo::SetLocationForFrame(BPoint newLocation, BRect frame) { - for (int32 index = 0; index < fNumFrames; index++) + for (int32 index = 0; index < fNumFrames; index++) { if (fLocations[index].fFrame == frame) { if (fLocations[index].fLocation == newLocation) return false; + fLocations[index].fLocation = newLocation; return true; } + } + fLocations[fNumFrames].fFrame = frame; fLocations[fNumFrames].fLocation = newLocation; fLocations[fNumFrames].fWorkspaces = 0xffffffff; @@ -248,7 +271,8 @@ ExtendedPoseInfo::SetLocationForFrame(BPoint newLocation, BRect frame) return true; } -void + +void ExtendedPoseInfo::EndianSwap(void *castToThis) { ExtendedPoseInfo *self = (ExtendedPoseInfo *)castToThis; @@ -257,7 +281,7 @@ ExtendedPoseInfo::EndianSwap(void *castToThis) self->fWorkspaces = SwapUInt32(self->fWorkspaces); self->fNumFrames = SwapInt32(self->fNumFrames); - + for (int32 index = 0; index < self->fNumFrames; index++) { swap_data(B_POINT_TYPE, &self->fLocations[index].fLocation, sizeof(BPoint), B_SWAP_ALWAYS); @@ -275,29 +299,37 @@ ExtendedPoseInfo::EndianSwap(void *castToThis) } } -void + +void ExtendedPoseInfo::PrintToStream() { } + // #pragma mark - + OffscreenBitmap::OffscreenBitmap(BRect frame) - : fBitmap(NULL) + : + fBitmap(NULL) { NewBitmap(frame); } + OffscreenBitmap::OffscreenBitmap() - : fBitmap(NULL) + : + fBitmap(NULL) { } + OffscreenBitmap::~OffscreenBitmap() { delete fBitmap; } + void OffscreenBitmap::NewBitmap(BRect bounds) { @@ -319,21 +351,25 @@ OffscreenBitmap::NewBitmap(BRect bounds) } } + BView * OffscreenBitmap::BeginUsing(BRect frame) { if (!fBitmap || fBitmap->Bounds() != frame) NewBitmap(frame); + fBitmap->Lock(); return View(); } + void OffscreenBitmap::DoneUsing() { fBitmap->Unlock(); } + BBitmap * OffscreenBitmap::Bitmap() const { @@ -342,6 +378,7 @@ OffscreenBitmap::Bitmap() const return fBitmap; } + BView * OffscreenBitmap::View() const { @@ -432,11 +469,11 @@ FadeRGBA32Vertical(uint32 *bits, int32 width, int32 height, int32 from, int32 to DraggableIcon::DraggableIcon(BRect rect, const char *name, const char *mimeType, - icon_size size, const BMessage *message, BMessenger target, uint32 resizeMask, - uint32 flags) - : BView(rect, name, resizeMask, flags), - fMessage(*message), - fTarget(target) + icon_size size, const BMessage *message, BMessenger target, + uint32 resizeMask, uint32 flags) + : BView(rect, name, resizeMask, flags), + fMessage(*message), + fTarget(target) { fBitmap = new BBitmap(Bounds(), kDefaultIconDepth); BMimeType mime(mimeType); @@ -451,18 +488,20 @@ DraggableIcon::DraggableIcon(BRect rect, const char *name, const char *mimeType, } -void -DraggableIcon::SetTarget(BMessenger target) -{ - fTarget = target; -} - DraggableIcon::~DraggableIcon() { delete fBitmap; } -BRect + +void +DraggableIcon::SetTarget(BMessenger target) +{ + fTarget = target; +} + + +BRect DraggableIcon::PreferredRect(BPoint offset, icon_size size) { BRect result(0, 0, size - 1, size - 1); @@ -470,7 +509,8 @@ DraggableIcon::PreferredRect(BPoint offset, icon_size size) return result; } -void + +void DraggableIcon::AttachedToWindow() { BView *parent = Parent(); @@ -480,7 +520,8 @@ DraggableIcon::AttachedToWindow() } } -void + +void DraggableIcon::MouseDown(BPoint point) { if (!DragStarted(&fMessage)) @@ -501,8 +542,8 @@ DraggableIcon::MouseDown(BPoint point) view->SetHighColor(0, 0, 0, 0); view->FillRect(view->Bounds()); view->SetDrawingMode(B_OP_ALPHA); - view->SetHighColor(0, 0, 0, 128); // set the level of transparency by - // value + view->SetHighColor(0, 0, 0, 128); + // set the level of transparency by value view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE); view->DrawBitmap(fBitmap); view->Sync(); @@ -510,12 +551,14 @@ DraggableIcon::MouseDown(BPoint point) DragMessage(&fMessage, dragBitmap, B_OP_ALPHA, point, fTarget.Target(0)); } -bool + +bool DraggableIcon::DragStarted(BMessage *) { return true; } + void DraggableIcon::Draw(BRect) { @@ -523,36 +566,41 @@ DraggableIcon::Draw(BRect) DrawBitmap(fBitmap); } + // #pragma mark - + FlickerFreeStringView::FlickerFreeStringView(BRect bounds, const char *name, - const char *text, uint32 resizeFlags, uint32 flags) - : BStringView(bounds, name, text, resizeFlags, flags), - fBitmap(NULL), - fOrigBitmap(NULL) + const char *text, uint32 resizeFlags, uint32 flags) + : BStringView(bounds, name, text, resizeFlags, flags), + fBitmap(NULL), + fOrigBitmap(NULL) { } + FlickerFreeStringView::FlickerFreeStringView(BRect bounds, const char *name, - const char *text, BBitmap *inBitmap, uint32 resizeFlags, uint32 flags) - : BStringView(bounds, name, text, resizeFlags, flags), - fBitmap(NULL), - fOrigBitmap(inBitmap) + const char *text, BBitmap *inBitmap, uint32 resizeFlags, uint32 flags) + : BStringView(bounds, name, text, resizeFlags, flags), + fBitmap(NULL), + fOrigBitmap(inBitmap) { } + FlickerFreeStringView::~FlickerFreeStringView() { delete fBitmap; } -void + +void FlickerFreeStringView::Draw(BRect) { BRect bounds(Bounds()); if (!fBitmap) fBitmap = new OffscreenBitmap(Bounds()); - + BView *offscreen = fBitmap->BeginUsing(bounds); if (Parent()) { @@ -583,28 +631,28 @@ FlickerFreeStringView::Draw(BRect) edge_info eInfo; switch (Alignment()) { case B_ALIGN_LEFT: - { - // If the first char has a negative left edge give it - // some more room by shifting that much more to the right. - font.GetEdges(Text(), 1, &eInfo); - loc.x = bounds.left + (2 - eInfo.left); - break; - } + { + // If the first char has a negative left edge give it + // some more room by shifting that much more to the right. + font.GetEdges(Text(), 1, &eInfo); + loc.x = bounds.left + (2 - eInfo.left); + break; + } case B_ALIGN_CENTER: - { - float width = StringWidth(Text()); - float center = (bounds.right - bounds.left) / 2; - loc.x = center - (width/2); - break; - } + { + float width = StringWidth(Text()); + float center = (bounds.right - bounds.left) / 2; + loc.x = center - (width/2); + break; + } case B_ALIGN_RIGHT: - { - float width = StringWidth(Text()); - loc.x = bounds.right - width - 2; - break; - } + { + float width = StringWidth(Text()); + loc.x = bounds.right - width - 2; + break; + } } loc.y = bounds.bottom - (1 + height.descent); offscreen->MovePenTo(loc); @@ -616,7 +664,8 @@ FlickerFreeStringView::Draw(BRect) fBitmap->DoneUsing(); } -void + +void FlickerFreeStringView::AttachedToWindow() { _inherited::AttachedToWindow(); @@ -628,7 +677,8 @@ FlickerFreeStringView::AttachedToWindow() SetLowColor(B_TRANSPARENT_32_BIT); } -void + +void FlickerFreeStringView::SetViewColor(rgb_color color) { if (fViewColor != color) { @@ -638,7 +688,8 @@ FlickerFreeStringView::SetViewColor(rgb_color color) _inherited::SetViewColor(B_TRANSPARENT_32_BIT); } -void + +void FlickerFreeStringView::SetLowColor(rgb_color color) { if (fLowColor != color) { @@ -648,10 +699,12 @@ FlickerFreeStringView::SetLowColor(rgb_color color) _inherited::SetLowColor(B_TRANSPARENT_32_BIT); } + // #pragma mark - + TitledSeparatorItem::TitledSeparatorItem(const char *label) - : BMenuItem(label, 0) + : BMenuItem(label, 0) { _inherited::SetEnabled(false); } @@ -661,20 +714,20 @@ TitledSeparatorItem::~TitledSeparatorItem() { } -void + +void TitledSeparatorItem::SetEnabled(bool) { // leave disabled } -void + +void TitledSeparatorItem::GetContentSize(float *width, float *height) { _inherited::GetContentSize(width, height); } -const float kMinSeparatorStubX = 10; -const float kStubToStringSlotX = 5; inline rgb_color ShiftMenuBackgroundColor(float by) @@ -682,7 +735,8 @@ ShiftMenuBackgroundColor(float by) return tint_color(ui_color(B_MENU_BACKGROUND_COLOR), by); } -void + +void TitledSeparatorItem::Draw() { BRect frame(Frame()); @@ -700,21 +754,21 @@ TitledSeparatorItem::Draw() frame.left += 1; frame.right -= 1; } - + float startX = frame.left; float endX = frame.right; - + float maxStringWidth = endX - startX - (2 * kMinSeparatorStubX + 2 * kStubToStringSlotX); // ToDo: // handle case where maxStringWidth turns out negative here - + BString truncatedLabel(Label()); parent->TruncateString(&truncatedLabel, B_TRUNCATE_END, maxStringWidth); maxStringWidth = parent->StringWidth(truncatedLabel.String()); - + // first calculate the length of the stub part of the // divider line, so we can use it for secondStartX float firstEndX = ((endX - startX) - maxStringWidth) / 2 - kStubToStringSlotX; @@ -727,7 +781,7 @@ TitledSeparatorItem::Draw() firstEndX += startX; parent->PushState(); - + int32 y = (int32) (frame.top + (frame.bottom - frame.top) / 2); parent->BeginLineArray(minfo.separator == 2 ? 6 : 4); @@ -756,7 +810,7 @@ TitledSeparatorItem::Draw() ShiftMenuBackgroundColor(B_DARKEN_1_TINT)); parent->EndLineArray(); - + font_height finfo; parent->GetFontHeight(&finfo); @@ -774,19 +828,22 @@ TitledSeparatorItem::Draw() parent->PopState(); } + // #pragma mark - + ShortcutFilter::ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier, - uint32 shortcutWhat, BHandler *target) - : BMessageFilter(B_KEY_DOWN), - fShortcutKey(shortcutKey), - fShortcutModifier(shortcutModifier), - fShortcutWhat(shortcutWhat), - fTarget(target) + uint32 shortcutWhat, BHandler *target) + : BMessageFilter(B_KEY_DOWN), + fShortcutKey(shortcutKey), + fShortcutModifier(shortcutModifier), + fShortcutWhat(shortcutWhat), + fTarget(target) { } -filter_result + +filter_result ShortcutFilter::Filter(BMessage *message, BHandler **) { if (message->what == B_KEY_DOWN) { @@ -794,7 +851,7 @@ ShortcutFilter::Filter(BMessage *message, BHandler **) uint32 rawKeyChar = 0; uint8 byte = 0; int32 key = 0; - + if (message->FindInt32("modifiers", (int32 *)&modifiers) != B_OK || message->FindInt32("raw_char", (int32 *)&rawKeyChar) != B_OK || message->FindInt8("byte", (int8 *)&byte) != B_OK @@ -815,10 +872,13 @@ ShortcutFilter::Filter(BMessage *message, BHandler **) return B_DISPATCH_MESSAGE; } + // #pragma mark - + + namespace BPrivate { -void +void EmbedUniqueVolumeInfo(BMessage *message, const BVolume *volume) { BDirectory rootDirectory; @@ -842,7 +902,7 @@ MatchArchivedVolume(BVolume *result, const BMessage *message, int32 index) { time_t created; off_t capacity; - + if (message->FindInt32("creationDate", index, &created) != B_OK || message->FindInt64("capacity", index, &capacity) != B_OK) return B_ERROR; @@ -920,6 +980,7 @@ MatchArchivedVolume(BVolume *result, const BMessage *message, int32 index) return B_DEV_BAD_DRIVE_NUM; } + void StringFromStream(BString *string, BMallocIO *stream, bool endianSwap) { @@ -927,7 +988,7 @@ StringFromStream(BString *string, BMallocIO *stream, bool endianSwap) stream->Read(&length, sizeof(length)); if (endianSwap) length = SwapInt32(length); - + if (length <= 0 || length > 10000) { // ToDo: // should fail here @@ -940,6 +1001,7 @@ StringFromStream(BString *string, BMallocIO *stream, bool endianSwap) string->UnlockBuffer(length); } + void StringToStream(const BString *string, BMallocIO *stream) { @@ -948,13 +1010,15 @@ StringToStream(const BString *string, BMallocIO *stream) stream->Write(string->String(), (size_t)string->Length() + 1); } + int32 ArchiveSize(const BString *string) { return string->Length() + 1 + (ssize_t)sizeof(int32); } -int32 + +int32 CountRefs(const BMessage *message) { uint32 type; @@ -964,6 +1028,7 @@ CountRefs(const BMessage *message) return count; } + static entry_ref * EachEntryRefCommon(BMessage *message, entry_ref *(*func)(entry_ref *, void *), void *passThru, int32 maxCount) @@ -986,17 +1051,20 @@ EachEntryRefCommon(BMessage *message, entry_ref *(*func)(entry_ref *, void *), return NULL; } -bool + +bool ContainsEntryRef(const BMessage *message, const entry_ref *ref) { entry_ref match; - for (int32 index = 0; (message->FindRef("refs", index, &match) == B_OK); index++) + for (int32 index = 0; (message->FindRef("refs", index, &match) == B_OK); index++) { if (*ref == match) return true; + } return false; } + entry_ref * EachEntryRef(BMessage *message, entry_ref *(*func)(entry_ref *, void *), void *passThru) @@ -1006,13 +1074,15 @@ EachEntryRef(BMessage *message, entry_ref *(*func)(entry_ref *, void *), typedef entry_ref *(*EachEntryIteratee)(entry_ref *, void *); -const entry_ref *EachEntryRef(const BMessage *message, - const entry_ref *(*func)(const entry_ref *, void *), void *passThru) +const entry_ref * +EachEntryRef(const BMessage *message, const entry_ref *(*func)(const entry_ref *, void *), + void *passThru) { return EachEntryRefCommon(const_cast(message), (EachEntryIteratee)func, passThru, -1); } + entry_ref * EachEntryRef(BMessage *message, entry_ref *(*func)(entry_ref *, void *), void *passThru, int32 maxCount) @@ -1020,6 +1090,7 @@ EachEntryRef(BMessage *message, entry_ref *(*func)(entry_ref *, void *), return EachEntryRefCommon(message, func, passThru, maxCount); } + const entry_ref * EachEntryRef(const BMessage *message, const entry_ref *(*func)(const entry_ref *, void *), void *passThru, int32 maxCount) @@ -1028,16 +1099,19 @@ EachEntryRef(const BMessage *message, const entry_ref *(*func)(const entry_ref * (EachEntryIteratee)func, passThru, maxCount); } -void + +void TruncateLeaf(BString *string) { - for (int32 index = string->Length(); index >= 0; index--) + for (int32 index = string->Length(); index >= 0; index--) { if ((*string)[index] == '/') { string->Truncate(index + 1); return; } + } } + int64 StringToScalar(const char *text) { @@ -1059,9 +1133,10 @@ StringToScalar(const char *text) } else if (strstr(buffer, "byte") || strstr(buffer, "BYTE")) { val = strtoll(buffer, &end, 10); val *= kGBSize; - } else + } else { // no suffix, try plain byte conversion val = strtoll(buffer, &end, 10); + } delete [] buffer; return val; @@ -1069,7 +1144,7 @@ StringToScalar(const char *text) #if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI && !defined(__HAIKU__) -bool +bool operator==(const rgb_color &a, const rgb_color &b) { return a.red == b.red @@ -1078,7 +1153,8 @@ operator==(const rgb_color &a, const rgb_color &b) && a.alpha == b.alpha; } -bool + +bool operator!=(const rgb_color &a, const rgb_color &b) { return !operator==(a, b); @@ -1086,6 +1162,7 @@ operator!=(const rgb_color &a, const rgb_color &b) #endif + static BRect LineBounds(BPoint where, float length, bool vertical) { @@ -1096,19 +1173,21 @@ LineBounds(BPoint where, float length, bool vertical) result.bottom = result.top + length; else result.right = result.left + length; - + return result; } + SeparatorLine::SeparatorLine(BPoint where, float length, bool vertical, const char *name) - : BView(LineBounds(where, length, vertical), name, - B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) + : BView(LineBounds(where, length, vertical), name, + B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } -void + +void SeparatorLine::Draw(BRect) { BRect bounds(Bounds()); @@ -1126,6 +1205,7 @@ SeparatorLine::Draw(BRect) EndLineArray(); } + void HexDump(const void *buf, int32 length) { @@ -1140,7 +1220,6 @@ HexDump(const void *buf, int32 length) printf( "0x%06x: ", (int)offset); for (index = 0; index < kBytesPerLine; index++) { - if (remain-- > 0) printf("%02x%c", buffer[index], remain > 0 ? ',' : ' '); else @@ -1150,7 +1229,6 @@ HexDump(const void *buf, int32 length) remain = length; printf(" \'"); for (index = 0; index < kBytesPerLine; index++) { - if (remain-- > 0) printf("%c", buffer[index] > ' ' ? buffer[index] : '.'); else @@ -1161,11 +1239,11 @@ HexDump(const void *buf, int32 length) length -= kBytesPerLine; if (length <= 0) break; - } fflush(stdout); } + void EnableNamedMenuItem(BMenu *menu, const char *itemName, bool on) { @@ -1174,6 +1252,7 @@ EnableNamedMenuItem(BMenu *menu, const char *itemName, bool on) item->SetEnabled(on); } + void MarkNamedMenuItem(BMenu *menu, const char *itemName, bool on) { @@ -1182,6 +1261,7 @@ MarkNamedMenuItem(BMenu *menu, const char *itemName, bool on) item->SetMarked(on); } + void EnableNamedMenuItem(BMenu *menu, uint32 commandName, bool on) { @@ -1190,6 +1270,7 @@ EnableNamedMenuItem(BMenu *menu, uint32 commandName, bool on) item->SetEnabled(on); } + void MarkNamedMenuItem(BMenu *menu, uint32 commandName, bool on) { @@ -1198,16 +1279,17 @@ MarkNamedMenuItem(BMenu *menu, uint32 commandName, bool on) item->SetMarked(on); } + void DeleteSubmenu(BMenuItem *submenuItem) { if (!submenuItem) return; - + BMenu *menu = submenuItem->Submenu(); if (!menu) return; - + for (;;) { BMenuItem *item = menu->RemoveItem((int32)0); if (!item) @@ -1217,7 +1299,8 @@ DeleteSubmenu(BMenuItem *submenuItem) } } -status_t + +status_t GetAppSignatureFromAttr(BFile *file, char *result) { // This call is a performance improvement that @@ -1226,12 +1309,9 @@ GetAppSignatureFromAttr(BFile *file, char *result) // the resource fork is scanned to read the attribute #ifdef B_APP_FILE_INFO_IS_FAST - BAppFileInfo appFileInfo(file); return appFileInfo.GetSignature(result); - #else - ssize_t readResult = file->ReadAttr(kAttrAppSignature, B_MIME_STRING_TYPE, 0, result, B_MIME_TYPE_LENGTH); @@ -1239,10 +1319,10 @@ GetAppSignatureFromAttr(BFile *file, char *result) return (status_t)readResult; return B_OK; - -#endif +#endif // B_APP_FILE_INFO_IS_FAST } + status_t GetAppIconFromAttr(BFile *file, BBitmap *result, icon_size size) { @@ -1252,12 +1332,9 @@ GetAppIconFromAttr(BFile *file, BBitmap *result, icon_size size) // the resource fork is scanned to read the icons #ifdef B_APP_FILE_INFO_IS_FAST - BAppFileInfo appFileInfo(file); return appFileInfo.GetIcon(result, size); - #else - const char *attrName = size == B_LARGE_ICON ? kAttrLargeIcon : kAttrMiniIcon; uint32 type = size == B_LARGE_ICON ? LARGE_ICON_TYPE : MINI_ICON_TYPE; char buffer[1024]; @@ -1268,17 +1345,16 @@ GetAppIconFromAttr(BFile *file, BBitmap *result, icon_size size) return err; ssize_t readResult = file->ReadAttr(attrName, type, 0, buffer, (size_t)ainfo.size); - if (readResult <= 0) return (status_t)readResult; - result->SetBits(buffer, result->BitsLength(), 0, B_COLOR_8_BIT); + result->SetBits(buffer, result->BitsLength(), 0, B_CMAP8); return B_OK; - -#endif +#endif // B_APP_FILE_INFO_IS_FAST } + status_t GetFileIconFromAttr(BNode *file, BBitmap *result, icon_size size) { @@ -1286,7 +1362,8 @@ GetFileIconFromAttr(BNode *file, BBitmap *result, icon_size size) return fileInfo.GetIcon(result, size); } -void + +void PrintToStream(rgb_color color) { printf("r:%x, g:%x, b:%x, a:%x\n", @@ -1303,6 +1380,7 @@ EachMenuItem(BMenu *menu, bool recursive, BMenuItem *(*func)(BMenuItem *)) BMenuItem *result = (func)(item); if (result) return result; + if (recursive) { BMenu *submenu = menu->SubmenuAt(index); if (submenu) @@ -1313,6 +1391,7 @@ EachMenuItem(BMenu *menu, bool recursive, BMenuItem *(*func)(BMenuItem *)) return NULL; } + extern const BMenuItem * EachMenuItem(const BMenu *menu, bool recursive, BMenuItem *(*func)(const BMenuItem *)) { @@ -1322,34 +1401,38 @@ EachMenuItem(const BMenu *menu, bool recursive, BMenuItem *(*func)(const BMenuIt BMenuItem *result = (func)(item); if (result) return result; + if (recursive) { BMenu *submenu = menu->SubmenuAt(index); if (submenu) return EachMenuItem(submenu, true, func); } } - + return NULL; } + PositionPassingMenuItem::PositionPassingMenuItem(const char *title, - BMessage *message, char shortcut, uint32 modifiers) - : BMenuItem(title, message, shortcut, modifiers) + BMessage *message, char shortcut, uint32 modifiers) + : BMenuItem(title, message, shortcut, modifiers) { } + PositionPassingMenuItem::PositionPassingMenuItem(BMenu *menu, - BMessage *message) - : BMenuItem(menu, message) + BMessage *message) + : BMenuItem(menu, message) { } + status_t PositionPassingMenuItem::Invoke(BMessage *message) { if (!Menu()) return B_ERROR; - + if (!IsEnabled()) return B_ERROR; @@ -1376,8 +1459,7 @@ PositionPassingMenuItem::Invoke(BMessage *message) // use the window position only, if the item was invoked from the menu // menu->Window() points to the window the item was invoked from - if (dynamic_cast(menu->Window()) == NULL) - { + if (dynamic_cast(menu->Window()) == NULL) { LooperAutoLocker lock(menu); if (lock.IsLocked()) { BPoint invokeOrigin(menu->Window()->Frame().LeftTop()); @@ -1388,7 +1470,8 @@ PositionPassingMenuItem::Invoke(BMessage *message) return BInvoker::Invoke(&clone); } -bool + +bool BootedInSafeMode() { const char *safeMode = getenv("SAFEMODE"); @@ -1396,7 +1479,7 @@ BootedInSafeMode() } -void +void _ThrowOnError(status_t error, const char *DEBUG_ONLY(file), int32 DEBUG_ONLY(line)) { if (error != B_OK) { @@ -1405,7 +1488,8 @@ _ThrowOnError(status_t error, const char *DEBUG_ONLY(file), int32 DEBUG_ONLY(lin } } -void + +void _ThrowIfNotSize(ssize_t size, const char *DEBUG_ONLY(file), int32 DEBUG_ONLY(line)) { if (size < B_OK) { @@ -1414,7 +1498,8 @@ _ThrowIfNotSize(ssize_t size, const char *DEBUG_ONLY(file), int32 DEBUG_ONLY(lin } } -void + +void _ThrowOnError(status_t error, const char *DEBUG_ONLY(debugString), const char *DEBUG_ONLY(file), int32 DEBUG_ONLY(line)) { diff --git a/src/kits/tracker/Utilities.h b/src/kits/tracker/Utilities.h index fc75506f1d..936b03dd2f 100644 --- a/src/kits/tracker/Utilities.h +++ b/src/kits/tracker/Utilities.h @@ -75,7 +75,7 @@ const int64 kTBSize = kGBSize * kKBSize; const int32 kMiniIconSeparator = 3; -const color_space kDefaultIconDepth = B_COLOR_8_BIT; +const color_space kDefaultIconDepth = B_CMAP8; // misc typedefs, constants and structs