From ae181f353b2e67cf6ed72bbf9b1ae05682adc5f0 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 19 Feb 2015 20:35:05 -0500 Subject: [PATCH] Deskbar: Save String object instead of pointer And add a SetLabel() that sets the truncated label when the label gets set. This will be useful so we can compare the truncated label to the normal label to tell if the label is truncated or not. --- src/apps/deskbar/TruncatableMenuItem.cpp | 28 ++++++++++++++---------- src/apps/deskbar/TruncatableMenuItem.h | 9 ++++++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/apps/deskbar/TruncatableMenuItem.cpp b/src/apps/deskbar/TruncatableMenuItem.cpp index edfdb729be..c8ed2ea33d 100644 --- a/src/apps/deskbar/TruncatableMenuItem.cpp +++ b/src/apps/deskbar/TruncatableMenuItem.cpp @@ -39,8 +39,6 @@ All rights reserved. #include -#include - #include "BarApp.h" #include "BarView.h" #include "ExpandoMenuBar.h" @@ -56,31 +54,28 @@ const float kSwitchWidth = 12.0f; TTruncatableMenuItem::TTruncatableMenuItem(const char* label, BMessage* message, char shortcut, uint32 modifiers) : - BMenuItem(label, message, shortcut, modifiers), - fTruncatedString(new BString()) + BMenuItem(label, message, shortcut, modifiers) { + fTruncatedString = label; } TTruncatableMenuItem::TTruncatableMenuItem(BMenu* menu, BMessage* message) : - BMenuItem(menu, message), - fTruncatedString(new BString()) + BMenuItem(menu, message) { } TTruncatableMenuItem::TTruncatableMenuItem(BMessage* data) : - BMenuItem(data), - fTruncatedString(new BString()) + BMenuItem(data) { } TTruncatableMenuItem::~TTruncatableMenuItem() { - delete fTruncatedString; } @@ -111,11 +106,22 @@ TTruncatableMenuItem::Label(float width) float labelWidth = menu->StringWidth(label); float offset = width - labelWidth; TruncateLabel(maxWidth - offset, truncatedLabel); - fTruncatedString->SetTo(truncatedLabel); + fTruncatedString.SetTo(truncatedLabel); free(truncatedLabel); - return fTruncatedString->String(); + return fTruncatedString.String(); } } + fTruncatedString.SetTo(label); + return label; } + + +void +TTruncatableMenuItem::SetLabel(const char* label) +{ + fTruncatedString.SetTo(label); + + BMenuItem::SetLabel(label); +} diff --git a/src/apps/deskbar/TruncatableMenuItem.h b/src/apps/deskbar/TruncatableMenuItem.h index 1039eeb220..803ec81358 100644 --- a/src/apps/deskbar/TruncatableMenuItem.h +++ b/src/apps/deskbar/TruncatableMenuItem.h @@ -38,8 +38,8 @@ All rights reserved. #include +#include -class BString; class TTruncatableMenuItem : public BMenuItem { public: @@ -52,8 +52,13 @@ public: virtual const char* Label(); virtual const char* Label(float width); + virtual void SetLabel(const char* label); + + const char* TruncatedLabel() const + { return fTruncatedString.String(); }; + private: - BString* fTruncatedString; + BString fTruncatedString; };