diff --git a/src/apps/installer/DrawButton.cpp b/src/apps/installer/DrawButton.cpp deleted file mode 100644 index dddd4d9f08..0000000000 --- a/src/apps/installer/DrawButton.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2005, Jérôme Duval. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Reworked from DarkWyrm version in CDPlayer - */ -#include -#include -#include "DrawButton.h" - -DrawButton::DrawButton(BRect frame, const char *name, const char *labelOn, const char* labelOff, - BMessage *msg, int32 resize, int32 flags) - : PaneSwitch(frame, name, "", resize, flags) -{ - fLabelOn = strdup(labelOn); - fLabelOff = strdup(labelOff); - SetMessage(msg); -} - - -DrawButton::~DrawButton(void) -{ - free(fLabelOn); - free(fLabelOff); -} - - -void -DrawButton::Draw(BRect update) -{ - BPoint point(18, 9); - if (Value()) { - DrawString(fLabelOn, point); - } else { - DrawString(fLabelOff, point); - } - PaneSwitch::Draw(update); -} diff --git a/src/apps/installer/DrawButton.h b/src/apps/installer/DrawButton.h deleted file mode 100644 index bf0ea7736a..0000000000 --- a/src/apps/installer/DrawButton.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2005, Jérôme Duval. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Reworked from DarkWyrm version in CDPlayer - */ - -#ifndef _DRAW_BUTTON_H -#define _DRAW_BUTTON_H - -#include "DialogPane.h" - -class DrawButton : public PaneSwitch -{ - public: - DrawButton(BRect frame, const char *name, const char *labelOn, const char* labelOff, - BMessage *msg, int32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP, - int32 flags = B_WILL_DRAW | B_NAVIGABLE); - ~DrawButton(void); - - void Draw(BRect update); - private: - char *fLabelOn, *fLabelOff; -}; - -#endif diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index 841dc6dec1..8f2652cffb 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -4,8 +4,10 @@ */ #include "InstallerWindow.h" + #include #include + #include #include #include @@ -18,8 +20,11 @@ #include #include #include + +#include "DialogPane.h" #include "PartitionMenuItem.h" + #define DRIVESETUP_SIG "application/x-vnd.Haiku-DriveSetup" const uint32 BEGIN_MESSAGE = 'iBGN'; @@ -130,9 +135,12 @@ InstallerWindow::InstallerWindow(BRect frame_rect) fBackBox->AddChild(fPackagesScrollView); fPackagesScrollView->Hide(); - fDrawButton = new DrawButton(BRect(bounds.left + 12, bounds.bottom - 33, - bounds.left + 120, bounds.bottom - 20), "options_button", - "Fewer options", "More options", new BMessage(SHOW_BOTTOM_MESSAGE)); + fDrawButton = new PaneSwitch(BRect(bounds.left + 12, bounds.bottom - 33, + bounds.left + 120, bounds.bottom - 20), "options_button"); + + fDrawButton->SetLabels("Fewer options", "More options"); + fDrawButton->SetMessage(new BMessage(SHOW_BOTTOM_MESSAGE)); + fBackBox->AddChild(fDrawButton); fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false); diff --git a/src/apps/installer/InstallerWindow.h b/src/apps/installer/InstallerWindow.h index ecaa862a51..3ab3c77a19 100644 --- a/src/apps/installer/InstallerWindow.h +++ b/src/apps/installer/InstallerWindow.h @@ -2,7 +2,6 @@ * Copyright 2005, Jérôme DUVAL. All rights reserved. * Distributed under the terms of the MIT License. */ - #ifndef _InstallerWindow_h #define _InstallerWindow_h @@ -14,12 +13,16 @@ #include #include #include + #include "CopyEngine.h" -#include "DrawButton.h" #include "PackageViews.h" #define INSTALLER_RIGHT 402 +namespace BPrivate { + class PaneSwitch; +}; + enum InstallStatus { kReadyForInstall, kInstalling, @@ -53,7 +56,7 @@ class InstallerWindow : public BWindow { static int ComparePackages(const void *firstArg, const void *secondArg); BBox *fBackBox; BButton *fBeginButton, *fSetupButton; - DrawButton *fDrawButton; + PaneSwitch *fDrawButton; bool fDriveSetupLaunched; InstallStatus fInstallStatus; BTextView *fStatusView; diff --git a/src/apps/installer/Jamfile b/src/apps/installer/Jamfile index 41a2320d5e..a10e64686d 100644 --- a/src/apps/installer/Jamfile +++ b/src/apps/installer/Jamfile @@ -7,7 +7,6 @@ SubDirHdrs [ FDirName $(HAIKU_TOP) src kits tracker ] ; Application Installer : CopyEngine.cpp - DrawButton.cpp FSUtils.cpp InstallerApp.cpp InstallerCopyLoopControl.cpp diff --git a/src/kits/tracker/DialogPane.cpp b/src/kits/tracker/DialogPane.cpp index 2e943e05f6..56deacce95 100644 --- a/src/kits/tracker/DialogPane.cpp +++ b/src/kits/tracker/DialogPane.cpp @@ -32,10 +32,13 @@ names are registered trademarks or trademarks of their respective holders. All rights reserved. */ -#include "Window.h" #include "DialogPane.h" + +#include + #include "Thread.h" #include "Utilities.h" +#include "Window.h" const uint32 kValueChanged = 'swch'; @@ -300,18 +303,165 @@ DialogPane::MessageReceived(BMessage *message) } -// #pragma mark - +// #pragma mark - PaneSwitch PaneSwitch::PaneSwitch(BRect frame, const char *name, bool leftAligned, - uint32 resizeMask, uint32 flags) - : BControl(frame, name, "", 0, resizeMask, flags), - fLeftAligned(leftAligned), - fPressing(false) + uint32 resizeMask, uint32 flags) + : + BControl(frame, name, "", 0, resizeMask, flags), + fLeftAligned(leftAligned), + fPressing(false), + fLabelOn(NULL), + fLabelOff(NULL) { } +PaneSwitch::PaneSwitch(const char *name, bool leftAligned, uint32 flags) + : + BControl(name, "", 0, flags), + fLeftAligned(leftAligned), + fPressing(false), + fLabelOn(NULL), + fLabelOff(NULL) +{ +} + + +PaneSwitch::~PaneSwitch() +{ + SetLabels(NULL, NULL); +} + + +void +PaneSwitch::Draw(BRect) +{ + BRect bounds(Bounds()); + + // Draw the label, if any + const char* label = fLabelOff; + if (fLabelOn != NULL && Value() == B_CONTROL_ON) + label = fLabelOn; + + if (label != NULL) { + BPoint point; + float labelDist = sLatchSize + ceilf(sLatchSize / 2.0); + if (fLeftAligned) + point.x = labelDist; + else + point.x = bounds.right - labelDist - StringWidth(label); + + font_height fontHeight; + GetFontHeight(&fontHeight); + point.y = (bounds.top + bounds.bottom + - ceilf(fontHeight.ascent) - ceilf(fontHeight.descent)) / 2 + + ceilf(fontHeight.ascent); + + DrawString(label, point); + } + + // draw the latch + if (fPressing) + DrawInState(kPressed); + else if (Value()) + DrawInState(kExpanded); + else + DrawInState(kCollapsed); + + // ...and the focus indication + if (!IsFocus() || !Window()->IsActive()) + return; + + rgb_color markColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); + + BeginLineArray(2); + AddLine(BPoint(bounds.left + 2, bounds.bottom - 1), + BPoint(bounds.right - 2, bounds.bottom - 1), markColor); + AddLine(BPoint(bounds.left + 2, bounds.bottom), + BPoint(bounds.right - 2, bounds.bottom), kWhite); + EndLineArray(); +} + + +void +PaneSwitch::MouseDown(BPoint) +{ + if (!IsEnabled()) + return; + + fPressing = true; + MouseDownThread::TrackMouse(this, &PaneSwitch::DoneTracking, + &PaneSwitch::Track); + Invalidate(); +} + + +void +PaneSwitch::GetPreferredSize(float* _width, float* _height) +{ + BSize size = MinSize(); + if (_width) + *_width = size.width; + if (_height) + *_height = size.height; +} + + +BSize +PaneSwitch::MinSize() +{ + BSize size; + float onLabelWidth = StringWidth(fLabelOn); + float offLabelWidth = StringWidth(fLabelOff); + float labelWidth = max_c(onLabelWidth, offLabelWidth); + size.width = sLatchSize; + if (labelWidth > 0.0) + size.width += ceilf(sLatchSize / 2.0) + labelWidth; + font_height fontHeight; + GetFontHeight(&fontHeight); + size.height = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent); + size.height = max_c(size.height, sLatchSize); + return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); +} + + +BSize +PaneSwitch::MaxSize() +{ + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), MinSize()); +} + + +BSize +PaneSwitch::PreferredSize() +{ + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), MinSize()); +} + + +void +PaneSwitch::SetLabels(const char* labelOn, const char* labelOff) +{ + free(fLabelOn); + free(fLabelOff); + + if (labelOn != NULL) + fLabelOn = strdup(labelOn); + else + fLabelOn = NULL; + + if (labelOff != NULL) + fLabelOff = strdup(labelOff); + else + fLabelOff = NULL; + + Invalidate(); + InvalidateLayout(); +} + + void PaneSwitch::DoneTracking(BPoint point) { @@ -341,42 +491,6 @@ PaneSwitch::Track(BPoint point, uint32) } -void -PaneSwitch::MouseDown(BPoint) -{ - if (!IsEnabled()) - return; - - fPressing = true; - MouseDownThread::TrackMouse(this, &PaneSwitch::DoneTracking, - &PaneSwitch::Track); - Invalidate(); -} - - -void -PaneSwitch::Draw(BRect) -{ - if (fPressing) - DrawInState(kPressed); - else if (Value()) - DrawInState(kExpanded); - else - DrawInState(kCollapsed); - - rgb_color markColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - - bool focused = IsFocus() && Window()->IsActive(); - BRect bounds(Bounds()); - BeginLineArray(2); - AddLine(BPoint(bounds.left + 2, bounds.bottom - 1), - BPoint(bounds.right - 2, bounds.bottom - 1), focused ? markColor : ViewColor()); - AddLine(BPoint(bounds.left + 2, bounds.bottom), - BPoint(bounds.right - 2, bounds.bottom), focused ? kWhite : ViewColor()); - EndLineArray(); -} - - void PaneSwitch::DrawInState(PaneSwitch::State state) { diff --git a/src/kits/tracker/DialogPane.h b/src/kits/tracker/DialogPane.h index db1b891283..a4008139fe 100644 --- a/src/kits/tracker/DialogPane.h +++ b/src/kits/tracker/DialogPane.h @@ -104,29 +104,52 @@ DialogPane::Mode() const } class PaneSwitch : public BControl { - public: - PaneSwitch(BRect frame, const char *name, bool leftAligned = true, - uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + PaneSwitch(BRect frame, const char* name, + bool leftAligned = true, + uint32 resizeMask + = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + + PaneSwitch(const char* name, + bool leftAligned = true, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + + virtual ~PaneSwitch(); + + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); + + virtual void GetPreferredSize(float* _width, + float* _height); + + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + + void SetLabels(const char* labelOn, + const char* labelOff); - virtual void Draw(BRect ); - virtual void MouseDown(BPoint ); protected: + void DoneTracking(BPoint where); + void Track(BPoint where, uint32); - void DoneTracking(BPoint ); - void Track(BPoint, uint32); + enum State { + kCollapsed, + kPressed, + kExpanded + }; - enum State { - kCollapsed, - kPressed, - kExpanded - }; + virtual void DrawInState(PaneSwitch::State state); - virtual void DrawInState(PaneSwitch::State state); - - bool fLeftAligned; - bool fPressing; +private: + bool fLeftAligned; + bool fPressing; + + char* fLabelOn; + char* fLabelOff; + + static const int32 sLatchSize = 11; }; } // namespace BPrivate diff --git a/src/kits/tracker/InfoWindow.cpp b/src/kits/tracker/InfoWindow.cpp index adecf867fc..285e8dfb35 100644 --- a/src/kits/tracker/InfoWindow.cpp +++ b/src/kits/tracker/InfoWindow.cpp @@ -946,22 +946,11 @@ AttributeView::AttributeView(BRect rect, Model *model) fPermissionsSwitch = new PaneSwitch(BRect(), "Permissions"); fPermissionsSwitch->SetMessage(new BMessage(kPermissionsSelected)); + fPermissionsSwitch->SetLabels(NULL, "Permissions"); AddChild(fPermissionsSwitch); - - BStringView *stringView = new BStringView(BRect(), "Permissions", "Permissions"); - - AddChild(stringView); - - stringView->ResizeToPreferred(); - - BRect bounds = Bounds(), stringViewBounds = stringView->Bounds(); - fPermissionsSwitch->MoveTo(kBorderWidth + 3, bounds.bottom - stringViewBounds.bottom + - (stringViewBounds.bottom - 11) / 2); - - stringView->MoveTo(kBorderWidth + 11 + 3, bounds.bottom - - stringViewBounds.bottom); - - fPermissionsSwitch->ResizeTo(10, 11); + fPermissionsSwitch->ResizeToPreferred(); + fPermissionsSwitch->MoveTo(kBorderWidth + 3, + Bounds().bottom - 3 - fPermissionsSwitch->Bounds().Height()); InitStrings(model); }