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:
parent
dd2625bfb0
commit
3e3d7acb90
@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Autolock.h>
|
||||
@ -18,8 +20,11 @@
|
||||
#include <String.h>
|
||||
#include <TranslationUtils.h>
|
||||
#include <TranslatorFormats.h>
|
||||
|
||||
#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);
|
||||
|
@ -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 <String.h>
|
||||
#include <TextView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#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;
|
||||
|
@ -7,7 +7,6 @@ SubDirHdrs [ FDirName $(HAIKU_TOP) src kits tracker ] ;
|
||||
|
||||
Application Installer :
|
||||
CopyEngine.cpp
|
||||
DrawButton.cpp
|
||||
FSUtils.cpp
|
||||
InstallerApp.cpp
|
||||
InstallerCopyLoopControl.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 <LayoutUtils.h>
|
||||
|
||||
#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<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
|
||||
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
|
||||
PaneSwitch::DrawInState(PaneSwitch::State state)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user