Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add methods to get and set the name, version, and icon

  • Loading branch information...
commit 9f7ac4312ab99b6246252305143592c8c78c900e 1 parent 19ec466
@jscipione jscipione authored
Showing with 159 additions and 10 deletions.
  1. +10 −0 headers/private/shared/AboutWindow.h
  2. +149 −10 src/kits/shared/AboutWindow.cpp
View
10 headers/private/shared/AboutWindow.h
@@ -16,6 +16,7 @@
class AboutView;
+class BBitmap;
class BPoint;
class BHandler;
@@ -37,6 +38,15 @@ class BAboutWindow : public BWindow {
void AddVersionHistory(const char** history);
void AddExtraInfo(const char* extraInfo);
+ BBitmap* Icon();
+ void SetIcon(BBitmap* icon);
+
+ const char* Name();
+ void SetName(const char* name);
+
+ const char* Version();
+ void SetVersion(const char* version);
+
private:
AboutView* fAboutView;
BHandler* fCaller;
View
159 src/kits/shared/AboutWindow.cpp
@@ -49,6 +49,9 @@ class StripeView : public BView {
virtual void Draw(BRect updateRect);
+ BBitmap* Icon() const { return fIcon; };
+ void SetIcon(BBitmap* icon);
+
private:
BBitmap* fIcon;
};
@@ -62,14 +65,24 @@ class AboutView : public BGroupView {
BTextView* InfoView() const { return fInfoView; };
+ BBitmap* Icon();
+ status_t SetIcon(BBitmap* icon);
+
+ const char* Name();
+ status_t SetName(const char* name);
+
+ const char* Version();
+ status_t SetVersion(const char* version);
+
protected:
- const char* AppVersion(const char* signature);
- BBitmap* AppIcon(const char* signature);
+ const char* _GetVersionFromSignature(const char* signature);
+ BBitmap* _GetIconFromSignature(const char* signature);
private:
BStringView* fNameView;
BStringView* fVersionView;
BTextView* fInfoView;
+ StripeView* fStripeView;
};
@@ -81,13 +94,14 @@ StripeView::StripeView(BBitmap* icon)
BView("StripeView", B_WILL_DRAW),
fIcon(icon)
{
+ SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
+
float width = 0.0f;
if (icon != NULL)
width += icon->Bounds().Width() + 32.0f;
SetExplicitMinSize(BSize(width, B_SIZE_UNSET));
SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED));
- SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
@@ -116,7 +130,24 @@ StripeView::Draw(BRect updateRect)
}
-// #pragma mark -
+void
+StripeView::SetIcon(BBitmap* icon)
+{
+ if (fIcon != NULL)
+ delete fIcon;
+
+ fIcon = icon;
+
+ float width = 0.0f;
+ if (icon != NULL)
+ width += icon->Bounds().Width() + 32.0f;
+
+ SetExplicitMinSize(BSize(width, B_SIZE_UNSET));
+ SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED));
+};
+
+
+// #pragma mark - AboutView
AboutView::AboutView(const char* appName, const char* signature)
@@ -131,7 +162,8 @@ AboutView::AboutView(const char* appName, const char* signature)
fNameView->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE
| B_FONT_FLAGS);
- fVersionView = new BStringView("version", AppVersion(signature));
+ fVersionView = new BStringView("version",
+ _GetVersionFromSignature(signature));
fInfoView = new BTextView("info", B_WILL_DRAW);
fInfoView->SetExplicitMinSize(BSize(210.0, 160.0));
@@ -145,10 +177,12 @@ AboutView::AboutView(const char* appName, const char* signature)
"infoViewScroller", fInfoView, B_WILL_DRAW | B_FRAME_EVENTS,
false, true, B_PLAIN_BORDER);
+ fStripeView = new StripeView(_GetIconFromSignature(signature));
+
GroupLayout()->SetSpacing(0);
BLayoutBuilder::Group<>(this)
.AddGroup(B_HORIZONTAL, 0)
- .Add(new StripeView(AppIcon(signature)))
+ .Add(fStripeView)
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
.SetInsets(0, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
@@ -166,8 +200,11 @@ AboutView::~AboutView()
}
+// #pragma mark - AboutView protected methods
+
+
const char*
-AboutView::AppVersion(const char* signature)
+AboutView::_GetVersionFromSignature(const char* signature)
{
if (signature == NULL)
return NULL;
@@ -228,7 +265,7 @@ AboutView::AppVersion(const char* signature)
BBitmap*
-AboutView::AppIcon(const char* signature)
+AboutView::_GetIconFromSignature(const char* signature)
{
if (signature == NULL)
return NULL;
@@ -251,7 +288,64 @@ AboutView::AppIcon(const char* signature)
}
-// #pragma mark -
+// #pragma mark - AboutView public methods
+
+
+const char*
+AboutView::Name()
+{
+ return fNameView->Text();
+}
+
+
+status_t
+AboutView::SetName(const char* name)
+{
+ fNameView->SetText(name);
+
+ return B_OK;
+}
+
+
+const char*
+AboutView::Version()
+{
+ return fVersionView->Text();
+}
+
+
+status_t
+AboutView::SetVersion(const char* version)
+{
+ fVersionView->SetText(version);
+
+ return B_OK;
+}
+
+
+BBitmap*
+AboutView::Icon()
+{
+ if (fStripeView == NULL)
+ return NULL;
+
+ return fStripeView->Icon();
+}
+
+
+status_t
+AboutView::SetIcon(BBitmap* icon)
+{
+ if (fStripeView == NULL)
+ return B_NO_INIT;
+
+ fStripeView->SetIcon(icon);
+
+ return B_OK;
+}
+
+
+// #pragma mark - BAboutWindow
BAboutWindow::BAboutWindow(const char* appName, const char* signature)
@@ -283,6 +377,9 @@ BAboutWindow::~BAboutWindow()
}
+// #pragma mark - BAboutWindow virtual methods
+
+
bool
BAboutWindow::QuitRequested()
{
@@ -292,7 +389,7 @@ BAboutWindow::QuitRequested()
}
-// #pragma mark -
+// #pragma mark - BAboutWindow public methods
BPoint
@@ -463,3 +560,45 @@ BAboutWindow::AddExtraInfo(const char* extraInfo)
fAboutView->InfoView()->Insert(extra.String());
}
+
+
+const char*
+BAboutWindow::Name()
+{
+ return fAboutView->Name();
+}
+
+
+void
+BAboutWindow::SetName(const char* name)
+{
+ fAboutView->SetName(name);
+}
+
+
+const char*
+BAboutWindow::Version()
+{
+ return fAboutView->Version();
+}
+
+
+void
+BAboutWindow::SetVersion(const char* version)
+{
+ fAboutView->SetVersion(version);
+}
+
+
+BBitmap*
+BAboutWindow::Icon()
+{
+ return fAboutView->Icon();
+}
+
+
+void
+BAboutWindow::SetIcon(BBitmap* icon)
+{
+ fAboutView->SetIcon(icon);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.