From f74f8600855ae5490b57b17dc593774f46459711 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 16 Jun 2019 10:57:41 +0200 Subject: [PATCH] BitmapButton: move from WebPositive to libshared Remove a currently unused copy of it from HaikuDepot. Change-Id: Idb97fae8e7190da6bc1049b3c1f1df929ea91bab Reviewed-on: https://review.haiku-os.org/c/1506 Reviewed-by: waddlesplash --- .../private/shared}/BitmapButton.h | 15 +- src/apps/haikudepot/Jamfile | 1 - src/apps/haikudepot/ui/PackageInfoView.cpp | 3 +- .../haikudepot/ui_generic/BitmapButton.cpp | 144 ------------------ src/apps/haikudepot/ui_generic/BitmapButton.h | 44 ------ src/apps/webpositive/BrowserWindow.cpp | 4 +- src/apps/webpositive/Jamfile | 1 - src/apps/webpositive/URLInputGroup.cpp | 2 +- .../support => kits/shared}/BitmapButton.cpp | 16 +- src/kits/shared/Jamfile | 1 + 10 files changed, 24 insertions(+), 207 deletions(-) rename {src/apps/webpositive/support => headers/private/shared}/BitmapButton.h (72%) delete mode 100644 src/apps/haikudepot/ui_generic/BitmapButton.cpp delete mode 100644 src/apps/haikudepot/ui_generic/BitmapButton.h rename src/{apps/webpositive/support => kits/shared}/BitmapButton.cpp (85%) diff --git a/src/apps/webpositive/support/BitmapButton.h b/headers/private/shared/BitmapButton.h similarity index 72% rename from src/apps/webpositive/support/BitmapButton.h rename to headers/private/shared/BitmapButton.h index 432adcb34e..10473d0ec0 100644 --- a/src/apps/webpositive/support/BitmapButton.h +++ b/headers/private/shared/BitmapButton.h @@ -6,26 +6,29 @@ #define BITMAP_BUTTON_H #include +#include class BBitmap; -class BitmapButton : public BButton { +namespace BPrivate { + +class BBitmapButton : public BButton { public: enum { BUTTON_BACKGROUND = 0, MENUBAR_BACKGROUND, }; - BitmapButton(const char* resourceName, + BBitmapButton(const char* resourceName, BMessage* message); - BitmapButton(const uint8* bits, uint32 width, + BBitmapButton(const uint8* bits, uint32 width, uint32 height, color_space format, BMessage* message); - virtual ~BitmapButton(); + virtual ~BBitmapButton(); virtual BSize MinSize(); virtual BSize MaxSize(); @@ -40,5 +43,9 @@ private: uint32 fBackgroundMode; }; +}; + +using BPrivate::BBitmapButton; + #endif // BITMAP_BUTTON_H diff --git a/src/apps/haikudepot/Jamfile b/src/apps/haikudepot/Jamfile index 70328c207d..817fa77d24 100644 --- a/src/apps/haikudepot/Jamfile +++ b/src/apps/haikudepot/Jamfile @@ -113,7 +113,6 @@ local textDocumentSources = local applicationSources = App.cpp BarberPole.cpp - BitmapButton.cpp BitmapView.cpp DecisionProvider.cpp FeaturedPackagesView.cpp diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp b/src/apps/haikudepot/ui/PackageInfoView.cpp index d7733bd371..03e95f1e80 100644 --- a/src/apps/haikudepot/ui/PackageInfoView.cpp +++ b/src/apps/haikudepot/ui/PackageInfoView.cpp @@ -36,7 +36,6 @@ #include #include -#include "BitmapButton.h" #include "BitmapView.h" #include "LinkView.h" #include "LinkedBitmapView.h" @@ -1446,4 +1445,4 @@ PackageInfoView::Clear() fPackageListener->SetPackage(PackageInfoRef(NULL)); fPackage.Unset(); -} \ No newline at end of file +} diff --git a/src/apps/haikudepot/ui_generic/BitmapButton.cpp b/src/apps/haikudepot/ui_generic/BitmapButton.cpp deleted file mode 100644 index 11d9d6d7f4..0000000000 --- a/src/apps/haikudepot/ui_generic/BitmapButton.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2013, Stephan Aßmus . - * All rights reserved. Distributed under the terms of the MIT License. - */ - - -#include "BitmapButton.h" - -#include -#include -#include - - -BitmapButton::BitmapButton(const char* name, BMessage* message) - : - BitmapView(name), - BInvoker(message, NULL, NULL), - fMouseInside(false), - fMouseDown(false) -{ - SetScaleBitmap(false); -} - - -BitmapButton::~BitmapButton() -{ -} - - -void -BitmapButton::AttachedToWindow() -{ - // TODO: Init fMouseInside - BitmapView::AttachedToWindow(); -} - -void -BitmapButton::MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage) -{ - int32 buttons = 0; - if (Window() != NULL && Window()->CurrentMessage() != NULL) - Window()->CurrentMessage()->FindInt32("buttons", &buttons); - - bool ignoreEvent = dragMessage != NULL || (!fMouseDown && buttons != 0); - - _SetMouseInside(!ignoreEvent && transit == B_INSIDE_VIEW); -} - - -void -BitmapButton::MouseDown(BPoint where) -{ - if (fMouseInside) { - _SetMouseDown(true); - SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); - } -} - - -void -BitmapButton::MouseUp(BPoint where) -{ - _SetMouseDown(false); - if (fMouseInside) - Invoke(); -} - - -BSize -BitmapButton::MinSize() -{ - BSize size = BitmapView::MinSize(); - size.width += 6; - size.height += 6; - return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); -} - - -BSize -BitmapButton::PreferredSize() -{ - BSize size = MinSize(); - return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size); -} - - -BSize -BitmapButton::MaxSize() -{ - BSize size = MinSize(); - return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size); -} - - -// #pragma mark - - - -void -BitmapButton::DrawBackground(BRect& bounds, BRect updateRect) -{ - if (Message() != NULL && (fMouseInside || fMouseDown)) { - rgb_color color = LowColor(); - uint32 flags = 0; - if (fMouseDown) - flags |= BControlLook::B_ACTIVATED; - - be_control_look->DrawButtonFrame(this, bounds, updateRect, - color, color, flags); - be_control_look->DrawButtonBackground(this, bounds, updateRect, - color, flags); - } else { - BitmapView::DrawBackground(bounds, updateRect); - } -} - - -// #pragma mark - - - -void -BitmapButton::_SetMouseInside(bool inside) -{ - if (fMouseInside == inside) - return; - - fMouseInside = inside; - - if (Message() != NULL) - Invalidate(); -} - - -void -BitmapButton::_SetMouseDown(bool down) -{ - if (fMouseDown == down) - return; - - fMouseDown = down; - - if (Message() != NULL) - Invalidate(); -} diff --git a/src/apps/haikudepot/ui_generic/BitmapButton.h b/src/apps/haikudepot/ui_generic/BitmapButton.h deleted file mode 100644 index ee951fec00..0000000000 --- a/src/apps/haikudepot/ui_generic/BitmapButton.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013, Stephan Aßmus . - * All rights reserved. Distributed under the terms of the MIT License. - */ -#ifndef BITMAP_BUTTON_H -#define BITMAP_BUTTON_H - - -#include - -#include "BitmapView.h" - - -class BitmapButton : public BitmapView, public BInvoker { -public: - BitmapButton(const char* name, - BMessage* message = NULL); - virtual ~BitmapButton(); - - virtual void AttachedToWindow(); - - virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage); - virtual void MouseDown(BPoint where); - virtual void MouseUp(BPoint where); - - virtual BSize MinSize(); - virtual BSize PreferredSize(); - virtual BSize MaxSize(); - -protected: - virtual void DrawBackground(BRect& bounds, - BRect updateRect); - -private: - void _SetMouseInside(bool inside); - void _SetMouseDown(bool down); - -private: - bool fMouseInside; - bool fMouseDown; -}; - -#endif // BITMAP_VIEW_H diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index bb0cdeb84b..5328bcd973 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -605,10 +605,10 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, ) ; - BitmapButton* toggleFullscreenButton = new BitmapButton(kWindowIconBits, + BBitmapButton* toggleFullscreenButton = new BBitmapButton(kWindowIconBits, kWindowIconWidth, kWindowIconHeight, kWindowIconFormat, new BMessage(TOGGLE_FULLSCREEN)); - toggleFullscreenButton->SetBackgroundMode(BitmapButton::MENUBAR_BACKGROUND); + toggleFullscreenButton->SetBackgroundMode(BBitmapButton::MENUBAR_BACKGROUND); BGroupLayout* menuBarGroup = BLayoutBuilder::Group<>(B_HORIZONTAL, 0.0) .Add(mainMenu) diff --git a/src/apps/webpositive/Jamfile b/src/apps/webpositive/Jamfile index fa1f1dc3d7..bf82ab804c 100644 --- a/src/apps/webpositive/Jamfile +++ b/src/apps/webpositive/Jamfile @@ -18,7 +18,6 @@ local sources = # support BaseURL.cpp - BitmapButton.cpp BookmarkBar.cpp FontSelectionView.cpp SettingsMessage.cpp diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp index d4fff1af8b..7c9d6e75e2 100644 --- a/src/apps/webpositive/URLInputGroup.cpp +++ b/src/apps/webpositive/URLInputGroup.cpp @@ -609,7 +609,7 @@ URLInputGroup::URLInputGroup(BMessage* goMessage) // TODO: Fix in Haiku, no in-built support for archived BBitmaps from // resources? // fGoButton = new BitmapButton("kActionGo", NULL); - fGoButton = new BitmapButton(kGoBitmapBits, kGoBitmapWidth, + fGoButton = new BBitmapButton(kGoBitmapBits, kGoBitmapWidth, kGoBitmapHeight, kGoBitmapFormat, goMessage); GroupLayout()->AddView(fGoButton, 0.0f); diff --git a/src/apps/webpositive/support/BitmapButton.cpp b/src/kits/shared/BitmapButton.cpp similarity index 85% rename from src/apps/webpositive/support/BitmapButton.cpp rename to src/kits/shared/BitmapButton.cpp index 009079969c..7fa7f6deeb 100644 --- a/src/apps/webpositive/support/BitmapButton.cpp +++ b/src/kits/shared/BitmapButton.cpp @@ -15,7 +15,7 @@ static const float kFrameInset = 2; -BitmapButton::BitmapButton(const char* resourceName, BMessage* message) +BBitmapButton::BBitmapButton(const char* resourceName, BMessage* message) : BButton("", message), fBitmap(BTranslationUtils::GetBitmap(resourceName)), @@ -24,7 +24,7 @@ BitmapButton::BitmapButton(const char* resourceName, BMessage* message) } -BitmapButton::BitmapButton(const uint8* bits, uint32 width, uint32 height, +BBitmapButton::BBitmapButton(const uint8* bits, uint32 width, uint32 height, color_space format, BMessage* message) : BButton("", message), @@ -35,14 +35,14 @@ BitmapButton::BitmapButton(const uint8* bits, uint32 width, uint32 height, } -BitmapButton::~BitmapButton() +BBitmapButton::~BBitmapButton() { delete fBitmap; } BSize -BitmapButton::MinSize() +BBitmapButton::MinSize() { BSize min(0, 0); if (fBitmap) { @@ -56,21 +56,21 @@ BitmapButton::MinSize() BSize -BitmapButton::MaxSize() +BBitmapButton::MaxSize() { return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); } BSize -BitmapButton::PreferredSize() +BBitmapButton::PreferredSize() { return MinSize(); } void -BitmapButton::Draw(BRect updateRect) +BBitmapButton::Draw(BRect updateRect) { BRect bounds(Bounds()); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); @@ -109,7 +109,7 @@ BitmapButton::Draw(BRect updateRect) void -BitmapButton::SetBackgroundMode(uint32 mode) +BBitmapButton::SetBackgroundMode(uint32 mode) { if (fBackgroundMode != mode) { fBackgroundMode = mode; diff --git a/src/kits/shared/Jamfile b/src/kits/shared/Jamfile index 60680cab2d..61482d65d9 100644 --- a/src/kits/shared/Jamfile +++ b/src/kits/shared/Jamfile @@ -29,6 +29,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { AboutMenuItem.cpp ArgumentVector.cpp AttributeUtilities.cpp + BitmapButton.cpp CalendarView.cpp ColorQuantizer.cpp CommandPipe.cpp