diff --git a/src/kits/tracker/Utilities.cpp b/src/kits/tracker/Utilities.cpp index 95525574d2..cd529400dd 100644 --- a/src/kits/tracker/Utilities.cpp +++ b/src/kits/tracker/Utilities.cpp @@ -241,7 +241,6 @@ PeriodicUpdatePoses::DoPeriodicUpdate(bool forceRedraw) PeriodicUpdatePoses gPeriodicUpdatePoses; - } // namespace BPrivate @@ -276,7 +275,7 @@ PoseInfo::PrintToStream() } -// #pragma mark - +// #pragma mark - ExtendedPoseInfo size_t @@ -296,8 +295,7 @@ ExtendedPoseInfo::Size(int32 count) size_t ExtendedPoseInfo::SizeWithHeadroom() const { - return sizeof(ExtendedPoseInfo) + (fNumFrames + 1) - * sizeof(FrameLocation); + return sizeof(ExtendedPoseInfo) + (fNumFrames + 1) * sizeof(FrameLocation); } @@ -394,7 +392,7 @@ ExtendedPoseInfo::PrintToStream() } -// #pragma mark - +// #pragma mark - OffscreenBitmap OffscreenBitmap::OffscreenBitmap(BRect frame) @@ -475,7 +473,7 @@ OffscreenBitmap::View() const } -// #pragma mark - +// #pragma mark - BPrivate functions namespace BPrivate { @@ -553,12 +551,12 @@ FadeRGBA32Vertical(uint32* bits, int32 width, int32 height, int32 from, } // namespace BPrivate -// #pragma mark - +// #pragma mark - DraggableIcon DraggableIcon::DraggableIcon(BRect rect, const char* name, - const char* mimeType, icon_size size, const BMessage* message, - BMessenger target, uint32 resizeMask, uint32 flags) + const char* mimeType, icon_size size, const BMessage* message, + BMessenger target, uint32 resizeMask, uint32 flags) : BView(rect, name, resizeMask, flags), fMessage(*message), @@ -657,11 +655,11 @@ DraggableIcon::Draw(BRect) } -// #pragma mark - +// #pragma mark - FlickerFreeStringView FlickerFreeStringView::FlickerFreeStringView(BRect bounds, const char* name, - const char* text, uint32 resizeFlags, uint32 flags) + const char* text, uint32 resizeFlags, uint32 flags) : BStringView(bounds, name, text, resizeFlags, flags), fBitmap(NULL), @@ -671,7 +669,7 @@ FlickerFreeStringView::FlickerFreeStringView(BRect bounds, const char* name, FlickerFreeStringView::FlickerFreeStringView(BRect bounds, const char* name, - const char* text, BBitmap* inBitmap, uint32 resizeFlags, uint32 flags) + const char* text, BBitmap* inBitmap, uint32 resizeFlags, uint32 flags) : BStringView(bounds, name, text, resizeFlags, flags), fBitmap(NULL), @@ -695,7 +693,7 @@ FlickerFreeStringView::Draw(BRect) BView* offscreen = fBitmap->BeginUsing(bounds); - if (Parent()) { + if (Parent() != NULL) { fViewColor = Parent()->ViewColor(); fLowColor = Parent()->ViewColor(); } @@ -714,7 +712,7 @@ FlickerFreeStringView::Draw(BRect) else offscreen->FillRect(bounds, B_SOLID_LOW); - if (Text()) { + if (Text() != NULL) { BPoint loc; font_height height; @@ -762,7 +760,7 @@ void FlickerFreeStringView::AttachedToWindow() { _inherited::AttachedToWindow(); - if (Parent()) { + if (Parent() != NULL) { fViewColor = Parent()->ViewColor(); fLowColor = Parent()->ViewColor(); } @@ -793,7 +791,7 @@ FlickerFreeStringView::SetLowColor(rgb_color color) } -// #pragma mark - +// #pragma mark - TitledSeparatorItem TitledSeparatorItem::TitledSeparatorItem(const char* label) @@ -925,11 +923,11 @@ TitledSeparatorItem::Draw() } -// #pragma mark - +// #pragma mark - ShortcutFilter ShortcutFilter::ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier, - uint32 shortcutWhat, BHandler* target) + uint32 shortcutWhat, BHandler* target) : BMessageFilter(B_KEY_DOWN), fShortcutKey(shortcutKey), @@ -970,12 +968,11 @@ ShortcutFilter::Filter(BMessage* message, BHandler**) } -// #pragma mark - +// #pragma mark - BPrivate functions namespace BPrivate { - void EmbedUniqueVolumeInfo(BMessage* message, const BVolume* volume) { @@ -1522,8 +1519,11 @@ EachMenuItem(const BMenu* menu, bool recursive, } +// #pragma mark - PositionPassingMenuItem + + PositionPassingMenuItem::PositionPassingMenuItem(const char* title, - BMessage* message, char shortcut, uint32 modifiers) + BMessage* message, char shortcut, uint32 modifiers) : BMenuItem(title, message, shortcut, modifiers) { @@ -1581,6 +1581,9 @@ PositionPassingMenuItem::Invoke(BMessage* message) } +// #pragma mark - BPrivate functions + + bool BootedInSafeMode() { diff --git a/src/kits/tracker/Utilities.h b/src/kits/tracker/Utilities.h index 93a15545ca..3d766c29bc 100644 --- a/src/kits/tracker/Utilities.h +++ b/src/kits/tracker/Utilities.h @@ -94,91 +94,90 @@ extern bool gLocalizedNamePreferred; // misc typedefs, constants and structs -// Periodically updated poses (ones with a volume space bar) register -// themselfs in this global list. This way they can be iterated over instead -// of sending around update messages. - class PeriodicUpdatePoses { - public: - PeriodicUpdatePoses(); - ~PeriodicUpdatePoses(); + // Periodically updated poses (ones with a volume space bar) register + // themselfs in this global list. This way they can be iterated over instead + // of sending around update messages. +public: + PeriodicUpdatePoses(); + ~PeriodicUpdatePoses(); - typedef bool (*PeriodicUpdateCallback)(BPose* pose, void* cookie); + typedef bool (*PeriodicUpdateCallback)(BPose* pose, void* cookie); - void AddPose(BPose* pose, BPoseView* poseView, - PeriodicUpdateCallback callback, void* cookie); - bool RemovePose(BPose* pose, void** cookie); + void AddPose(BPose* pose, BPoseView* poseView, + PeriodicUpdateCallback callback, void* cookie); + bool RemovePose(BPose* pose, void** cookie); - void DoPeriodicUpdate(bool forceRedraw); + void DoPeriodicUpdate(bool forceRedraw); - private: - struct periodic_pose { - BPose* pose; - BPoseView* pose_view; - PeriodicUpdateCallback callback; - void* cookie; - }; +private: + struct periodic_pose { + BPose* pose; + BPoseView* pose_view; + PeriodicUpdateCallback callback; + void* cookie; + }; - Benaphore* fLock; - BObjectList fPoseList; + Benaphore* fLock; + BObjectList fPoseList; }; extern PeriodicUpdatePoses gPeriodicUpdatePoses; -// PoseInfo is the structure that gets saved as attributes for every node on -// disk, defining the node's position and visibility class PoseInfo { - public: - static void EndianSwap(void* castToThis); - void PrintToStream(); + // PoseInfo is the structure that gets saved as attributes for every node + // on disk, defining the node's position and visibility +public: + static void EndianSwap(void* castToThis); + void PrintToStream(); - bool fInvisible; - ino_t fInitedDirectory; - // For a location to be valid, fInitedDirectory has to contain - // the inode of the items parent directory. This makes it - // impossible to for instance zip up files and extract them in - // the same location. This should probably be reworked. - // Tracker could strip the file location attributes when dropping - // files into a closed folder. - BPoint fLocation; + bool fInvisible; + ino_t fInitedDirectory; + // For a location to be valid, fInitedDirectory has to contain + // the inode of the items parent directory. This makes it + // impossible to for instance zip up files and extract them in + // the same location. This should probably be reworked. + // Tracker could strip the file location attributes when dropping + // files into a closed folder. + BPoint fLocation; }; -// extends PoseInfo adding workspace support; used for desktop -// poses only class ExtendedPoseInfo { - public: - size_t Size() const; - static size_t Size(int32); - size_t SizeWithHeadroom() const; - static size_t SizeWithHeadroom(size_t); - bool HasLocationForFrame(BRect) const; - BPoint LocationForFrame(BRect) const; - bool SetLocationForFrame(BPoint, BRect); + // extends PoseInfo adding workspace support; used for desktop + // poses only +public: + size_t Size() const; + static size_t Size(int32); + size_t SizeWithHeadroom() const; + static size_t SizeWithHeadroom(size_t); + bool HasLocationForFrame(BRect) const; + BPoint LocationForFrame(BRect) const; + bool SetLocationForFrame(BPoint, BRect); - static void EndianSwap(void* castToThis); - void PrintToStream(); + static void EndianSwap(void* castToThis); + void PrintToStream(); + uint32 fWorkspaces; + bool fInvisible; + bool fShowFromBootOnly; + bool fReservedBool1; + bool fReservedBool2; + int32 fReservedInt1; + int32 fReservedInt2; + int32 fReservedInt3; + int32 fReservedInt4; + int32 fReservedInt5; + + int32 fNumFrames; + struct FrameLocation { + BPoint fLocation; + BRect fFrame; uint32 fWorkspaces; - bool fInvisible; - bool fShowFromBootOnly; - bool fReservedBool1; - bool fReservedBool2; - int32 fReservedInt1; - int32 fReservedInt2; - int32 fReservedInt3; - int32 fReservedInt4; - int32 fReservedInt5; + }; - int32 fNumFrames; - struct FrameLocation { - BPoint fLocation; - BRect fFrame; - uint32 fWorkspaces; - }; - - FrameLocation fLocations[0]; + FrameLocation fLocations[0]; }; // misc functions @@ -224,179 +223,180 @@ extern void FadeRGBA32Vertical(uint32* bits, int32 width, int32 height, class FlickerFreeStringView : public BStringView { // adds support for offscreen bitmap drawing for string views that update // often this would be better implemented as an option of BStringView - public: - FlickerFreeStringView(BRect bounds, const char* name, - const char* text, uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW); - FlickerFreeStringView(BRect bounds, const char* name, - const char* text, BBitmap* existingOffscreen, - uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW); - virtual ~FlickerFreeStringView(); - virtual void Draw(BRect); - virtual void AttachedToWindow(); - virtual void SetViewColor(rgb_color); - virtual void SetLowColor(rgb_color); +public: + FlickerFreeStringView(BRect bounds, const char* name, + const char* text, uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW); + FlickerFreeStringView(BRect bounds, const char* name, + const char* text, BBitmap* existingOffscreen, + uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW); + virtual ~FlickerFreeStringView(); + virtual void Draw(BRect); + virtual void AttachedToWindow(); + virtual void SetViewColor(rgb_color); + virtual void SetLowColor(rgb_color); - private: - OffscreenBitmap* fBitmap; - rgb_color fViewColor; - rgb_color fLowColor; - BBitmap* fOrigBitmap; +private: + OffscreenBitmap* fBitmap; + rgb_color fViewColor; + rgb_color fLowColor; + BBitmap* fOrigBitmap; - typedef BStringView _inherited; + typedef BStringView _inherited; }; class DraggableIcon : public BView { // used to determine a save location for a file - public: - DraggableIcon(BRect, const char*, const char* mimeType, icon_size, - const BMessage*, BMessenger, - uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW); - virtual ~DraggableIcon(); +public: + DraggableIcon(BRect, const char*, const char* mimeType, icon_size, + const BMessage*, BMessenger, + uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW); + virtual ~DraggableIcon(); - static BRect PreferredRect(BPoint offset, icon_size); - void SetTarget(BMessenger); + static BRect PreferredRect(BPoint offset, icon_size); + void SetTarget(BMessenger); - protected: - virtual void AttachedToWindow(); - virtual void MouseDown(BPoint); - virtual void Draw(BRect); +protected: + virtual void AttachedToWindow(); + virtual void MouseDown(BPoint); + virtual void Draw(BRect); - virtual bool DragStarted(BMessage* dragMessage); + virtual bool DragStarted(BMessage* dragMessage); - protected: - BBitmap* fBitmap; - BMessage fMessage; - BMessenger fTarget; +protected: + BBitmap* fBitmap; + BMessage fMessage; + BMessenger fTarget; }; class PositionPassingMenuItem : public BMenuItem { - public: - PositionPassingMenuItem(const char* title, BMessage*, - char shortcut = 0, uint32 modifiers = 0); +public: + PositionPassingMenuItem(const char* title, BMessage*, + char shortcut = 0, uint32 modifiers = 0); - PositionPassingMenuItem(BMenu*, BMessage*); + PositionPassingMenuItem(BMenu*, BMessage*); - protected: - virtual status_t Invoke(BMessage* = 0); - // appends the invoke location for NewFolder, etc. to use +protected: + virtual status_t Invoke(BMessage* = 0); + // appends the invoke location for NewFolder, etc. to use - private: - typedef BMenuItem _inherited; +private: + typedef BMenuItem _inherited; }; class Benaphore { // aka benaphore - public: - Benaphore(const char* name = "Light Lock") - : fSemaphore(create_sem(0, name)), - fCount(1) - { - } +public: + Benaphore(const char* name = "Light Lock") + : fSemaphore(create_sem(0, name)), + fCount(1) + { + } - ~Benaphore() - { - delete_sem(fSemaphore); - } + ~Benaphore() + { + delete_sem(fSemaphore); + } - bool Lock() - { - if (atomic_add(&fCount, -1) <= 0) - return acquire_sem(fSemaphore) == B_OK; + bool Lock() + { + if (atomic_add(&fCount, -1) <= 0) + return acquire_sem(fSemaphore) == B_OK; - return true; - } + return true; + } - void Unlock() - { - if (atomic_add(&fCount, 1) < 0) - release_sem(fSemaphore); - } + void Unlock() + { + if (atomic_add(&fCount, 1) < 0) + release_sem(fSemaphore); + } - bool IsLocked() const - { - return fCount <= 0; - } + bool IsLocked() const + { + return fCount <= 0; + } - private: - sem_id fSemaphore; - int32 fCount; +private: + sem_id fSemaphore; + int32 fCount; }; class SeparatorLine : public BView { - public: - SeparatorLine(BPoint, float, bool vertical, const char* name = ""); - virtual void Draw(BRect bounds); +public: + SeparatorLine(BPoint, float, bool vertical, const char* name = ""); + virtual void Draw(BRect bounds); }; class TitledSeparatorItem : public BMenuItem { - public: - TitledSeparatorItem(const char*); - virtual ~TitledSeparatorItem(); +public: + TitledSeparatorItem(const char*); + virtual ~TitledSeparatorItem(); - virtual void SetEnabled(bool state); + virtual void SetEnabled(bool state); - protected: - virtual void GetContentSize(float* width, float* height); - virtual void Draw(); +protected: + virtual void GetContentSize(float* width, float* height); + virtual void Draw(); - private: - typedef BMenuItem _inherited; +private: + typedef BMenuItem _inherited; }; class LooperAutoLocker { - public: - LooperAutoLocker(BHandler* handler) - : fHandler(handler), - fHasLock(handler->LockLooper()) - { - } +public: + LooperAutoLocker(BHandler* handler) + : fHandler(handler), + fHasLock(handler->LockLooper()) + { + } - ~LooperAutoLocker() - { - if (fHasLock) - fHandler->UnlockLooper(); - } + ~LooperAutoLocker() + { + if (fHasLock) + fHandler->UnlockLooper(); + } - bool operator!() const - { - return !fHasLock; - } + bool operator!() const + { + return !fHasLock; + } - bool IsLocked() const - { - return fHasLock; - } + bool IsLocked() const + { + return fHasLock; + } - private: - BHandler* fHandler; - bool fHasLock; +private: + BHandler* fHandler; + bool fHasLock; }; class ShortcutFilter : public BMessageFilter { - public: - ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier, - uint32 shortcutWhat, BHandler* target); +public: + ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier, + uint32 shortcutWhat, BHandler* target); - protected: - filter_result Filter(BMessage*, BHandler**); +protected: + filter_result Filter(BMessage*, BHandler**); - private: - uint32 fShortcutKey; - uint32 fShortcutModifier; - uint32 fShortcutWhat; - BHandler* fTarget; +private: + uint32 fShortcutKey; + uint32 fShortcutModifier; + uint32 fShortcutWhat; + BHandler* fTarget; }; + // iterates over all the refs in a message entry_ref* EachEntryRef(BMessage*, entry_ref* (*)(entry_ref*, void*), void* passThru = 0); @@ -447,6 +447,7 @@ bool operator!=(const rgb_color&, const rgb_color&); #endif + inline rgb_color Color(int32 r, int32 g, int32 b, int32 alpha = 255) { @@ -561,18 +562,19 @@ inline void PrintDirToStream(const BDirectory*, const char* = 0) {} va_end(ap); } - #define WRITELOG(_ARGS_) \ - if (logFile == 0) \ - logFile = fopen("/var/log/tracker.log", "a+"); \ - if (logFile != 0) { \ - thread_info info; \ - get_thread_info(find_thread(NULL), &info); \ - PrintToLogFile("[t %Ld] \"%s\" (%s:%i) ", system_time(), \ - info.name, __FILE__, __LINE__); \ - PrintToLogFile _ARGS_; \ - PrintToLogFile("\n"); \ - fflush(logFile); \ - } +#define WRITELOG(_ARGS_) \ + if (logFile == 0) \ + logFile = fopen("/var/log/tracker.log", "a+"); \ + \ + if (logFile != 0) { \ + thread_info info; \ + get_thread_info(find_thread(NULL), &info); \ + PrintToLogFile("[t %Ld] \"%s\" (%s:%i) ", system_time(), \ + info.name, __FILE__, __LINE__); \ + PrintToLogFile _ARGS_; \ + PrintToLogFile("\n"); \ + fflush(logFile); \ + } #else @@ -605,4 +607,5 @@ float ComputeTypeAheadScore(const char* text, const char* match, } // namespace BPrivate + #endif // _UTILITIES_H