In some ways, this is unrelated, but I had to combine this anyhow:
* Extend the PaneSwitch BControl from Tracker, so it can draw on/off labels. This has the added benefit that you can click the label to expand/collapse, like for example in the Get Info window (Permissions). * I also added font-sensitivity features to PaneSwitch, and it can be used in layouted windows (untested). * This made the "DrawButton" in the Installer superfluous. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30348 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -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 <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
@@ -4,8 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "InstallerWindow.h"
|
#include "InstallerWindow.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
@@ -18,8 +20,11 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
#include <TranslatorFormats.h>
|
#include <TranslatorFormats.h>
|
||||||
|
|
||||||
|
#include "DialogPane.h"
|
||||||
#include "PartitionMenuItem.h"
|
#include "PartitionMenuItem.h"
|
||||||
|
|
||||||
|
|
||||||
#define DRIVESETUP_SIG "application/x-vnd.Haiku-DriveSetup"
|
#define DRIVESETUP_SIG "application/x-vnd.Haiku-DriveSetup"
|
||||||
|
|
||||||
const uint32 BEGIN_MESSAGE = 'iBGN';
|
const uint32 BEGIN_MESSAGE = 'iBGN';
|
||||||
@@ -130,9 +135,12 @@ InstallerWindow::InstallerWindow(BRect frame_rect)
|
|||||||
fBackBox->AddChild(fPackagesScrollView);
|
fBackBox->AddChild(fPackagesScrollView);
|
||||||
fPackagesScrollView->Hide();
|
fPackagesScrollView->Hide();
|
||||||
|
|
||||||
fDrawButton = new DrawButton(BRect(bounds.left + 12, bounds.bottom - 33,
|
fDrawButton = new PaneSwitch(BRect(bounds.left + 12, bounds.bottom - 33,
|
||||||
bounds.left + 120, bounds.bottom - 20), "options_button",
|
bounds.left + 120, bounds.bottom - 20), "options_button");
|
||||||
"Fewer options", "More options", new BMessage(SHOW_BOTTOM_MESSAGE));
|
|
||||||
|
fDrawButton->SetLabels("Fewer options", "More options");
|
||||||
|
fDrawButton->SetMessage(new BMessage(SHOW_BOTTOM_MESSAGE));
|
||||||
|
|
||||||
fBackBox->AddChild(fDrawButton);
|
fBackBox->AddChild(fDrawButton);
|
||||||
|
|
||||||
fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false);
|
fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
* Copyright 2005, Jérôme DUVAL. All rights reserved.
|
* Copyright 2005, Jérôme DUVAL. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _InstallerWindow_h
|
#ifndef _InstallerWindow_h
|
||||||
#define _InstallerWindow_h
|
#define _InstallerWindow_h
|
||||||
|
|
||||||
@@ -14,12 +13,16 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "CopyEngine.h"
|
#include "CopyEngine.h"
|
||||||
#include "DrawButton.h"
|
|
||||||
#include "PackageViews.h"
|
#include "PackageViews.h"
|
||||||
|
|
||||||
#define INSTALLER_RIGHT 402
|
#define INSTALLER_RIGHT 402
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
class PaneSwitch;
|
||||||
|
};
|
||||||
|
|
||||||
enum InstallStatus {
|
enum InstallStatus {
|
||||||
kReadyForInstall,
|
kReadyForInstall,
|
||||||
kInstalling,
|
kInstalling,
|
||||||
@@ -53,7 +56,7 @@ class InstallerWindow : public BWindow {
|
|||||||
static int ComparePackages(const void *firstArg, const void *secondArg);
|
static int ComparePackages(const void *firstArg, const void *secondArg);
|
||||||
BBox *fBackBox;
|
BBox *fBackBox;
|
||||||
BButton *fBeginButton, *fSetupButton;
|
BButton *fBeginButton, *fSetupButton;
|
||||||
DrawButton *fDrawButton;
|
PaneSwitch *fDrawButton;
|
||||||
bool fDriveSetupLaunched;
|
bool fDriveSetupLaunched;
|
||||||
InstallStatus fInstallStatus;
|
InstallStatus fInstallStatus;
|
||||||
BTextView *fStatusView;
|
BTextView *fStatusView;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ SubDirHdrs [ FDirName $(HAIKU_TOP) src kits tracker ] ;
|
|||||||
|
|
||||||
Application Installer :
|
Application Installer :
|
||||||
CopyEngine.cpp
|
CopyEngine.cpp
|
||||||
DrawButton.cpp
|
|
||||||
FSUtils.cpp
|
FSUtils.cpp
|
||||||
InstallerApp.cpp
|
InstallerApp.cpp
|
||||||
InstallerCopyLoopControl.cpp
|
InstallerCopyLoopControl.cpp
|
||||||
|
|||||||
+154
-40
@@ -32,10 +32,13 @@ names are registered trademarks or trademarks of their respective holders.
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Window.h"
|
|
||||||
#include "DialogPane.h"
|
#include "DialogPane.h"
|
||||||
|
|
||||||
|
#include <LayoutUtils.h>
|
||||||
|
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
|
|
||||||
const uint32 kValueChanged = 'swch';
|
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,
|
PaneSwitch::PaneSwitch(BRect frame, const char *name, bool leftAligned,
|
||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
: BControl(frame, name, "", 0, resizeMask, flags),
|
:
|
||||||
|
BControl(frame, name, "", 0, resizeMask, flags),
|
||||||
fLeftAligned(leftAligned),
|
fLeftAligned(leftAligned),
|
||||||
fPressing(false)
|
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<PaneSwitch>::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
|
void
|
||||||
PaneSwitch::DoneTracking(BPoint point)
|
PaneSwitch::DoneTracking(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -341,42 +491,6 @@ PaneSwitch::Track(BPoint point, uint32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PaneSwitch::MouseDown(BPoint)
|
|
||||||
{
|
|
||||||
if (!IsEnabled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
fPressing = true;
|
|
||||||
MouseDownThread<PaneSwitch>::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
|
void
|
||||||
PaneSwitch::DrawInState(PaneSwitch::State state)
|
PaneSwitch::DrawInState(PaneSwitch::State state)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -104,18 +104,35 @@ DialogPane::Mode() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PaneSwitch : public BControl {
|
class PaneSwitch : public BControl {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PaneSwitch(BRect frame, const char *name, bool leftAligned = true,
|
PaneSwitch(BRect frame, const char* name,
|
||||||
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
bool leftAligned = true,
|
||||||
|
uint32 resizeMask
|
||||||
|
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
|
|
||||||
virtual void Draw(BRect );
|
PaneSwitch(const char* name,
|
||||||
virtual void MouseDown(BPoint );
|
bool leftAligned = true,
|
||||||
protected:
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
|
|
||||||
void DoneTracking(BPoint );
|
virtual ~PaneSwitch();
|
||||||
void Track(BPoint, uint32);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void DoneTracking(BPoint where);
|
||||||
|
void Track(BPoint where, uint32);
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
kCollapsed,
|
kCollapsed,
|
||||||
@@ -125,8 +142,14 @@ protected:
|
|||||||
|
|
||||||
virtual void DrawInState(PaneSwitch::State state);
|
virtual void DrawInState(PaneSwitch::State state);
|
||||||
|
|
||||||
|
private:
|
||||||
bool fLeftAligned;
|
bool fLeftAligned;
|
||||||
bool fPressing;
|
bool fPressing;
|
||||||
|
|
||||||
|
char* fLabelOn;
|
||||||
|
char* fLabelOff;
|
||||||
|
|
||||||
|
static const int32 sLatchSize = 11;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -946,22 +946,11 @@ AttributeView::AttributeView(BRect rect, Model *model)
|
|||||||
|
|
||||||
fPermissionsSwitch = new PaneSwitch(BRect(), "Permissions");
|
fPermissionsSwitch = new PaneSwitch(BRect(), "Permissions");
|
||||||
fPermissionsSwitch->SetMessage(new BMessage(kPermissionsSelected));
|
fPermissionsSwitch->SetMessage(new BMessage(kPermissionsSelected));
|
||||||
|
fPermissionsSwitch->SetLabels(NULL, "Permissions");
|
||||||
AddChild(fPermissionsSwitch);
|
AddChild(fPermissionsSwitch);
|
||||||
|
fPermissionsSwitch->ResizeToPreferred();
|
||||||
BStringView *stringView = new BStringView(BRect(), "Permissions", "Permissions");
|
fPermissionsSwitch->MoveTo(kBorderWidth + 3,
|
||||||
|
Bounds().bottom - 3 - fPermissionsSwitch->Bounds().Height());
|
||||||
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);
|
|
||||||
|
|
||||||
InitStrings(model);
|
InitStrings(model);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user