* Made preferences window font sensitive, this fixes bug #196.

* BottomPrefsView is no longer needed (just contained two buttons, moved
  their creation to the PrefsWindow class).
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16705 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-03-11 17:12:27 +00:00
parent bd0a76ccc4
commit eb8d1e3895
7 changed files with 430 additions and 394 deletions

View File

@ -1,53 +0,0 @@
//****************************************************************************************
//
// File: BottomPrefsView.cpp
//
// Written by: Daniel Switkin
//
// Copyright 1999, Be Incorporated
//
//****************************************************************************************
#include "BottomPrefsView.h"
#include "Common.h"
#include <interface/Button.h>
#include <stdlib.h>
BottomPrefsView::BottomPrefsView(BRect rect, const char *name) :
BView(rect, name, B_FOLLOW_NONE, B_WILL_DRAW) {
// Set the background color dynamically, don't hardcode 216, 216, 216
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BRect r = Bounds();
r.right -= 13;
float width = be_plain_font->StringWidth("OK") + 20;
r.left = (width > 75) ? (r.right - width) : (r.right - 75);
r.top += 10;
r.bottom = r.top + 24;
BButton *ok = new BButton(r, "OKButton", "OK", new BMessage(PRV_BOTTOM_OK));
AddChild(ok);
r.right = r.left - 10;
width = be_plain_font->StringWidth("Defaults") + 20;
r.left = (width > 75) ? (r.right - width) : (r.right - 75);
BButton *defaults = new BButton(r, "DefaultsButton", "Defaults", new BMessage(PRV_BOTTOM_DEFAULTS));
AddChild(defaults);
ok->MakeDefault(true);
}
// Do a little drawing to fit better with BTabView
void BottomPrefsView::Draw(BRect rect) {
PushState();
BRect bounds = Bounds();
SetHighColor(255, 255, 255, 255);
StrokeLine(BPoint(0, 0), BPoint(bounds.right - 1, 0));
StrokeLine(BPoint(0, 0), BPoint(0, bounds.bottom - 1));
SetHighColor(96, 96, 96, 255);
StrokeLine(BPoint(bounds.right, 0), BPoint(bounds.right, bounds.bottom));
StrokeLine(BPoint(0, bounds.bottom), BPoint(bounds.right, bounds.bottom));
PopState();
}

View File

@ -1,22 +0,0 @@
//****************************************************************************************
//
// File: BottomPrefsView.h
//
// Written by: Daniel Switkin
//
// Copyright 1999, Be Incorporated
//
//****************************************************************************************
#ifndef BOTTOMPREFSVIEW_H
#define BOTTOMPREFSVIEW_H
#include <interface/View.h>
class BottomPrefsView : public BView {
public:
BottomPrefsView(BRect rect, const char *name);
void Draw(BRect rect);
};
#endif

View File

@ -1,227 +1,293 @@
//****************************************************************************************
//
// File: ConfigView.cpp
//
// Written by: Daniel Switkin
//
// Copyright 1999, Be Incorporated
//
//****************************************************************************************
/*
* Copyright 2002-2006 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Copyright 1999, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* Written by: Daniel Switkin
*/
#include "ConfigView.h"
#include "Common.h"
#include "PulseApp.h"
#include "PrefsWindow.h"
#include <interface/Box.h>
#include <CheckBox.h>
#include <RadioButton.h>
#include <TextControl.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
RTColorControl::RTColorControl(BPoint point, BMessage *message)
: BColorControl(point, B_CELLS_32x8, 6, "ColorControl", message, false) {
RTColorControl::RTColorControl(BPoint point, BMessage *message)
: BColorControl(point, B_CELLS_32x8, 6, "ColorControl", message, false)
{
}
// Send a message every time the color changes, not just
// when the mouse button is released
void RTColorControl::SetValue(int32 color) {
/*!
Send a message every time the color changes, not just
when the mouse button is released
*/
void
RTColorControl::SetValue(int32 color)
{
BColorControl::SetValue(color);
Invoke();
}
// A single class for all three prefs views, needs to be
// customized below to give each control the right message
ConfigView::ConfigView(BRect rect, const char *name, int mode, Prefs *prefs) :
BView(rect, name, B_FOLLOW_NONE, B_WILL_DRAW) {
this->mode = mode;
first_time_attached = true;
fadecolors = NULL;
active = idle = frame = NULL;
iconwidth = NULL;
// #pragma mark -
BRect r(6, 5, 296, 115);
BBox *bbox = new BBox(r, "BBox");
bbox->SetLabel("Bar Colors");
AddChild(bbox);
if (mode == NORMAL_WINDOW_MODE) {
colorcontrol = new RTColorControl(BPoint(10, 20),
new BMessage(PRV_NORMAL_CHANGE_COLOR));
} else if (mode == MINI_WINDOW_MODE) {
colorcontrol = new RTColorControl(BPoint(10, 20),
new BMessage(PRV_MINI_CHANGE_COLOR));
} else {
colorcontrol = new RTColorControl(BPoint(10, 20),
new BMessage(PRV_DESKBAR_CHANGE_COLOR));
}
bbox->AddChild(colorcontrol);
r = colorcontrol->Frame();
r.top = r.bottom + 10;
r.bottom = r.top + 15;
/*!
A single class for all three prefs views, needs to be
customized below to give each control the right message
*/
ConfigView::ConfigView(BRect rect, const char *name, uint32 mode, BMessenger& target,
Prefs *prefs)
: BBox(rect, name, B_FOLLOW_NONE, B_WILL_DRAW),
fMode(mode),
fTarget(target),
fPrefs(prefs),
fFirstTimeAttached(true)
{
fFadeCheckBox = NULL;
fActiveButton = fIdleButton = fFrameButton = NULL;
fIconWidthControl = NULL;
if (mode == NORMAL_WINDOW_MODE) {
r.right = r.left + be_plain_font->StringWidth("Fade colors") + 20;
fadecolors = new BCheckBox(r, "FadeColors", "Fade colors",
SetLabel("Bar Colors");
font_height fontHeight;
be_bold_font->GetHeight(&fontHeight);
fColorControl = new RTColorControl(BPoint(10, 5.0f + fontHeight.ascent
+ fontHeight.descent), new BMessage(fMode));
fColorControl->ResizeToPreferred();
AddChild(fColorControl);
rect = fColorControl->Frame();
rect.top = rect.bottom + 10.0f;
rect.bottom = rect.top + 15.0f;
if (mode == PRV_NORMAL_CHANGE_COLOR) {
// normal mode
fFadeCheckBox = new BCheckBox(rect, "FadeColors", "Fade colors",
new BMessage(PRV_NORMAL_FADE_COLORS));
bbox->AddChild(fadecolors);
colorcontrol->SetValue(prefs->normal_bar_color);
fadecolors->SetValue(prefs->normal_fade_colors);
} else if (mode == MINI_WINDOW_MODE) {
r.right = r.left + be_plain_font->StringWidth("Active color") + 20;
active = new BRadioButton(r, "ActiveColor", "Active color",
fFadeCheckBox->ResizeToPreferred();
AddChild(fFadeCheckBox);
fColorControl->SetValue(fPrefs->normal_bar_color);
fFadeCheckBox->SetValue(fPrefs->normal_fade_colors);
} else if (mode == PRV_MINI_CHANGE_COLOR) {
// mini mode
fActiveButton = new BRadioButton(rect, "ActiveColor", "Active color",
new BMessage(PRV_MINI_ACTIVE));
bbox->AddChild(active);
active->SetValue(B_CONTROL_ON);
r.left = r.right + 5;
r.right = r.left + be_plain_font->StringWidth("Idle color") + 20;
idle = new BRadioButton(r, "IdleColor", "Idle color",
fActiveButton->ResizeToPreferred();
fActiveButton->SetValue(B_CONTROL_ON);
AddChild(fActiveButton);
rect.left = fActiveButton->Frame().right + 5.0f;
fIdleButton = new BRadioButton(rect, "IdleColor", "Idle color",
new BMessage(PRV_MINI_IDLE));
bbox->AddChild(idle);
r.left = r.right + 5;
r.right = r.left + be_plain_font->StringWidth("Frame color") + 20;
frame = new BRadioButton(r, "FrameColor", "Frame color",
fIdleButton->ResizeToPreferred();
AddChild(fIdleButton);
rect.left = fIdleButton->Frame().right + 5.0f;
fFrameButton = new BRadioButton(rect, "FrameColor", "Frame color",
new BMessage(PRV_MINI_FRAME));
bbox->AddChild(frame);
colorcontrol->SetValue(prefs->mini_active_color);
fFrameButton->ResizeToPreferred();
AddChild(fFrameButton);
fColorControl->SetValue(fPrefs->mini_active_color);
} else {
bbox->ResizeBy(0, 20);
r.right = r.left + be_plain_font->StringWidth("Active color") + 20;
active = new BRadioButton(r, "ActiveColor", "Active color",
// deskbar mode
fActiveButton = new BRadioButton(rect, "ActiveColor", "Active color",
new BMessage(PRV_DESKBAR_ACTIVE));
bbox->AddChild(active);
active->SetValue(B_CONTROL_ON);
r.left = r.right + 5;
r.right = r.left + be_plain_font->StringWidth("Idle color") + 20;
idle = new BRadioButton(r, "IdleColor", "Idle color",
fActiveButton->ResizeToPreferred();
fActiveButton->SetValue(B_CONTROL_ON);
AddChild(fActiveButton);
rect.left = fActiveButton->Frame().right + 5.0f;
fIdleButton = new BRadioButton(rect, "IdleColor", "Idle color",
new BMessage(PRV_DESKBAR_IDLE));
bbox->AddChild(idle);
r.left = r.right + 5;
r.right = r.left + be_plain_font->StringWidth("Frame color") + 20;
frame = new BRadioButton(r, "FrameColor", "Frame color",
fIdleButton->ResizeToPreferred();
AddChild(fIdleButton);
rect.left = fIdleButton->Frame().right + 5.0f;
fFrameButton = new BRadioButton(rect, "FrameColor", "Frame color",
new BMessage(PRV_DESKBAR_FRAME));
bbox->AddChild(frame);
r.top = active->Frame().bottom + 1;
r.bottom = r.top + 15;
r.left = 10;
r.right = r.left + be_plain_font->StringWidth("Width of icon:") + 5 + 30;
fFrameButton->ResizeToPreferred();
AddChild(fFrameButton);
rect.left = fColorControl->Frame().left;
rect.top = fActiveButton->Frame().bottom + 5.0f;
char temp[10];
sprintf(temp, "%d", prefs->deskbar_icon_width);
iconwidth = new BTextControl(r, "Width", "Width of icon:", temp,
snprintf(temp, sizeof(temp), "%d", fPrefs->deskbar_icon_width);
fIconWidthControl = new BTextControl(rect, "Width", "Width of icon:", temp,
new BMessage(PRV_DESKBAR_ICON_WIDTH));
bbox->AddChild(iconwidth);
iconwidth->SetDivider(be_plain_font->StringWidth("Width of icon:") + 5);
//iconwidth->SetModificationMessage(new BMessage(PRV_DESKBAR_ICON_WIDTH));
for (int x = 0; x < 256; x++) {
if (x < '0' || x > '9') iconwidth->TextView()->DisallowChar(x);
AddChild(fIconWidthControl);
fIconWidthControl->SetDivider(be_plain_font->StringWidth(
fIconWidthControl->Label()) + 5.0f);
for (int c = 0; c < 256; c++) {
if (!isdigit(c))
fIconWidthControl->TextView()->DisallowChar(c);
}
iconwidth->TextView()->SetMaxBytes(2);
fIconWidthControl->TextView()->SetMaxBytes(2);
colorcontrol->SetValue(prefs->deskbar_active_color);
float width, height;
fIconWidthControl->GetPreferredSize(&width, &height);
fIconWidthControl->ResizeTo(fIconWidthControl->Divider() + 32.0f
+ fIconWidthControl->StringWidth("999"), height);
fColorControl->SetValue(fPrefs->deskbar_active_color);
}
}
void ConfigView::AttachedToWindow() {
void
ConfigView::GetPreferredSize(float* _width, float* _height)
{
float right, bottom;
if (fMode == PRV_NORMAL_CHANGE_COLOR) {
// normal mode
bottom = fFadeCheckBox->Frame().bottom;
right = fFadeCheckBox->Frame().right;
} else if (fMode == PRV_MINI_CHANGE_COLOR) {
// mini mode
bottom = fIdleButton->Frame().bottom;
right = fFrameButton->Frame().right;
} else {
// deskbar mode
bottom = fIconWidthControl->Frame().bottom;
right = fFrameButton->Frame().right;
}
if (right < fColorControl->Frame().right)
right = fColorControl->Frame().right;
if (right < 300)
right = 300;
if (_width)
*_width = right + 10.0f;
if (_height)
*_height = bottom + 8.0f;
}
void
ConfigView::AttachedToWindow()
{
BView::AttachedToWindow();
// AttachedToWindow() gets called every time this tab is brought
// to the front, but we only want this initialization to happen once
if (first_time_attached) {
if (fFirstTimeAttached) {
if (Parent() != NULL)
SetViewColor(Parent()->ViewColor());
else
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BMessenger messenger(this);
colorcontrol->SetTarget(messenger);
if (fadecolors != NULL) fadecolors->SetTarget(messenger);
if (active != NULL) active->SetTarget(messenger);
if (idle != NULL) idle->SetTarget(messenger);
if (frame != NULL) frame->SetTarget(messenger);
if (iconwidth != NULL) iconwidth->SetTarget(messenger);
first_time_attached = false;
fColorControl->SetTarget(messenger);
if (fFadeCheckBox != NULL)
fFadeCheckBox->SetTarget(messenger);
if (fActiveButton != NULL)
fActiveButton->SetTarget(messenger);
if (fIdleButton != NULL)
fIdleButton->SetTarget(messenger);
if (fFrameButton != NULL)
fFrameButton->SetTarget(messenger);
if (fIconWidthControl != NULL)
fIconWidthControl->SetTarget(messenger);
fFirstTimeAttached = false;
}
}
void ConfigView::MessageReceived(BMessage *message) {
PrefsWindow *prefswindow = (PrefsWindow *)Window();
if (prefswindow == NULL) return;
Prefs *prefs = prefswindow->prefs;
BMessenger *messenger = prefswindow->messenger;
void
ConfigView::MessageReceived(BMessage *message)
{
switch (message->what) {
// These two send the color and the status of the fade checkbox together
case PRV_NORMAL_FADE_COLORS:
case PRV_NORMAL_CHANGE_COLOR: {
bool fade_colors = (bool)fadecolors->Value();
int32 bar_color = colorcontrol->Value();
case PRV_NORMAL_CHANGE_COLOR:
{
bool fade_colors = (bool)fFadeCheckBox->Value();
int32 bar_color = fColorControl->Value();
message->AddInt32("color", bar_color);
message->AddBool("fade", fade_colors);
prefs->normal_fade_colors = fade_colors;
prefs->normal_bar_color = bar_color;
messenger->SendMessage(message);
fPrefs->normal_fade_colors = fade_colors;
fPrefs->normal_bar_color = bar_color;
fTarget.SendMessage(message);
break;
}
// Share the single color control among three values
case PRV_MINI_ACTIVE:
colorcontrol->SetValue(prefs->mini_active_color);
fColorControl->SetValue(fPrefs->mini_active_color);
break;
case PRV_MINI_IDLE:
colorcontrol->SetValue(prefs->mini_idle_color);
fColorControl->SetValue(fPrefs->mini_idle_color);
break;
case PRV_MINI_FRAME:
colorcontrol->SetValue(prefs->mini_frame_color);
fColorControl->SetValue(fPrefs->mini_frame_color);
break;
case PRV_MINI_CHANGE_COLOR: {
int32 color = colorcontrol->Value();
if (active->Value()) {
prefs->mini_active_color = color;
} else if (idle->Value()) {
prefs->mini_idle_color = color;
} else {
prefs->mini_frame_color = color;
}
message->AddInt32("active_color", prefs->mini_active_color);
message->AddInt32("idle_color", prefs->mini_idle_color);
message->AddInt32("frame_color", prefs->mini_frame_color);
messenger->SendMessage(message);
int32 color = fColorControl->Value();
if (fActiveButton->Value())
fPrefs->mini_active_color = color;
else if (fIdleButton->Value())
fPrefs->mini_idle_color = color;
else
fPrefs->mini_frame_color = color;
message->AddInt32("active_color", fPrefs->mini_active_color);
message->AddInt32("idle_color", fPrefs->mini_idle_color);
message->AddInt32("frame_color", fPrefs->mini_frame_color);
fTarget.SendMessage(message);
break;
}
case PRV_DESKBAR_ACTIVE:
colorcontrol->SetValue(prefs->deskbar_active_color);
fColorControl->SetValue(fPrefs->deskbar_active_color);
break;
case PRV_DESKBAR_IDLE:
colorcontrol->SetValue(prefs->deskbar_idle_color);
fColorControl->SetValue(fPrefs->deskbar_idle_color);
break;
case PRV_DESKBAR_FRAME:
colorcontrol->SetValue(prefs->deskbar_frame_color);
fColorControl->SetValue(fPrefs->deskbar_frame_color);
break;
case PRV_DESKBAR_ICON_WIDTH:
UpdateDeskbarIconWidth();
break;
case PRV_DESKBAR_CHANGE_COLOR: {
int32 color = colorcontrol->Value();
if (active->Value()) {
prefs->deskbar_active_color = color;
} else if (idle->Value()) {
prefs->deskbar_idle_color = color;
} else {
prefs->deskbar_frame_color = color;
}
message->AddInt32("active_color", prefs->deskbar_active_color);
message->AddInt32("idle_color", prefs->deskbar_idle_color);
message->AddInt32("frame_color", prefs->deskbar_frame_color);
messenger->SendMessage(message);
int32 color = fColorControl->Value();
if (fActiveButton->Value())
fPrefs->deskbar_active_color = color;
else if (fIdleButton->Value())
fPrefs->deskbar_idle_color = color;
else
fPrefs->deskbar_frame_color = color;
message->AddInt32("active_color", fPrefs->deskbar_active_color);
message->AddInt32("idle_color", fPrefs->deskbar_idle_color);
message->AddInt32("frame_color", fPrefs->deskbar_frame_color);
fTarget.SendMessage(message);
break;
}
case PRV_BOTTOM_DEFAULTS:
ResetDefaults();
_ResetDefaults();
break;
default:
BView::MessageReceived(message);
@ -229,15 +295,13 @@ void ConfigView::MessageReceived(BMessage *message) {
}
}
void ConfigView::UpdateDeskbarIconWidth() {
PrefsWindow *prefswindow = (PrefsWindow *)Window();
if (prefswindow == NULL) return;
Prefs *prefs = prefswindow->prefs;
BMessenger *messenger = prefswindow->messenger;
void
ConfigView::UpdateDeskbarIconWidth()
{
// Make sure the width shows at least one pixel per CPU and
// that it will fit in the tray in any Deskbar orientation
int width = atoi(iconwidth->Text());
int width = atoi(fIconWidthControl->Text());
int min_width = GetMinimumViewWidth();
if (width < min_width || width > 50) {
char temp[10];
@ -248,63 +312,60 @@ void ConfigView::UpdateDeskbarIconWidth() {
strcpy(temp, "50");
width = 50;
}
iconwidth->SetText(temp);
fIconWidthControl->SetText(temp);
}
BMessage *message = new BMessage(PRV_DESKBAR_ICON_WIDTH);
message->AddInt32("width", width);
prefs->deskbar_icon_width = width;
messenger->SendMessage(message);
delete message;
fPrefs->deskbar_icon_width = width;
BMessage message(PRV_DESKBAR_ICON_WIDTH);
message.AddInt32("width", width);
fTarget.SendMessage(&message);
}
// Only reset our own controls to default
void ConfigView::ResetDefaults() {
PrefsWindow *prefswindow = (PrefsWindow *)Window();
if (prefswindow == NULL) return;
Prefs *prefs = prefswindow->prefs;
BMessenger *messenger = prefswindow->messenger;
if (mode == NORMAL_WINDOW_MODE) {
colorcontrol->SetValue(DEFAULT_NORMAL_BAR_COLOR);
fadecolors->SetValue(DEFAULT_NORMAL_FADE_COLORS);
} else if (mode == MINI_WINDOW_MODE) {
prefs->mini_active_color = DEFAULT_MINI_ACTIVE_COLOR;
prefs->mini_idle_color = DEFAULT_MINI_IDLE_COLOR;
prefs->mini_frame_color = DEFAULT_MINI_FRAME_COLOR;
if (active->Value()) {
colorcontrol->SetValue(DEFAULT_MINI_ACTIVE_COLOR);
} else if (idle->Value()) {
colorcontrol->SetValue(DEFAULT_MINI_IDLE_COLOR);
} else {
colorcontrol->SetValue(DEFAULT_MINI_FRAME_COLOR);
}
void
ConfigView::_ResetDefaults()
{
if (fMode == PRV_NORMAL_CHANGE_COLOR) {
fColorControl->SetValue(DEFAULT_NORMAL_BAR_COLOR);
fFadeCheckBox->SetValue(DEFAULT_NORMAL_FADE_COLORS);
} else if (fMode == PRV_MINI_CHANGE_COLOR) {
fPrefs->mini_active_color = DEFAULT_MINI_ACTIVE_COLOR;
fPrefs->mini_idle_color = DEFAULT_MINI_IDLE_COLOR;
fPrefs->mini_frame_color = DEFAULT_MINI_FRAME_COLOR;
if (fActiveButton->Value())
fColorControl->SetValue(DEFAULT_MINI_ACTIVE_COLOR);
else if (fIdleButton->Value())
fColorControl->SetValue(DEFAULT_MINI_IDLE_COLOR);
else
fColorControl->SetValue(DEFAULT_MINI_FRAME_COLOR);
BMessage *message = new BMessage(PRV_MINI_CHANGE_COLOR);
message->AddInt32("active_color", DEFAULT_MINI_ACTIVE_COLOR);
message->AddInt32("idle_color", DEFAULT_MINI_IDLE_COLOR);
message->AddInt32("frame_color", DEFAULT_MINI_FRAME_COLOR);
messenger->SendMessage(message);
fTarget.SendMessage(message);
} else {
prefs->deskbar_active_color = DEFAULT_DESKBAR_ACTIVE_COLOR;
prefs->deskbar_idle_color = DEFAULT_DESKBAR_IDLE_COLOR;
prefs->deskbar_frame_color = DEFAULT_DESKBAR_FRAME_COLOR;
if (active->Value()) {
colorcontrol->SetValue(DEFAULT_DESKBAR_ACTIVE_COLOR);
} else if (idle->Value()) {
colorcontrol->SetValue(DEFAULT_DESKBAR_IDLE_COLOR);
} else {
colorcontrol->SetValue(DEFAULT_DESKBAR_FRAME_COLOR);
}
fPrefs->deskbar_active_color = DEFAULT_DESKBAR_ACTIVE_COLOR;
fPrefs->deskbar_idle_color = DEFAULT_DESKBAR_IDLE_COLOR;
fPrefs->deskbar_frame_color = DEFAULT_DESKBAR_FRAME_COLOR;
if (fActiveButton->Value())
fColorControl->SetValue(DEFAULT_DESKBAR_ACTIVE_COLOR);
else if (fIdleButton->Value())
fColorControl->SetValue(DEFAULT_DESKBAR_IDLE_COLOR);
else
fColorControl->SetValue(DEFAULT_DESKBAR_FRAME_COLOR);
BMessage *message = new BMessage(PRV_DESKBAR_CHANGE_COLOR);
message->AddInt32("active_color", DEFAULT_DESKBAR_ACTIVE_COLOR);
message->AddInt32("idle_color", DEFAULT_DESKBAR_IDLE_COLOR);
message->AddInt32("frame_color", DEFAULT_DESKBAR_FRAME_COLOR);
messenger->SendMessage(message);
fTarget.SendMessage(message);
char temp[10];
sprintf(temp, "%d", DEFAULT_DESKBAR_ICON_WIDTH);
iconwidth->SetText(temp);
fIconWidthControl->SetText(temp);
// Need to force the model message to be sent
iconwidth->Invoke();
fIconWidthControl->Invoke();
}
}

View File

@ -1,47 +1,61 @@
//****************************************************************************************
//
// File: ConfigView.h
//
// Written by: Daniel Switkin
//
// Copyright 1999, Be Incorporated
//
//****************************************************************************************
/*
* Copyright 2002-2006 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Copyright 1999, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* Written by: Daniel Switkin
*/
#ifndef CONFIG_VIEW_H
#define CONFIG_VIEW_H
#ifndef CONFIGVIEW_H
#define CONFIGVIEW_H
#include <interface/CheckBox.h>
#include <interface/RadioButton.h>
#include <interface/TextControl.h>
#include <interface/ColorControl.h>
#include "Prefs.h"
#include <Box.h>
#include <ColorControl.h>
class BCheckBox;
class BRadioButton;
class BTextControl;
class RTColorControl : public BColorControl {
public:
RTColorControl(BPoint point, BMessage *message);
void SetValue(int32 color);
};
class ConfigView : public BView {
class ConfigView : public BBox {
public:
ConfigView(BRect rect, const char *name, int mode, Prefs *prefs);
void AttachedToWindow();
void MessageReceived(BMessage *message);
ConfigView(BRect rect, const char *name, uint32 mode,
BMessenger& target, Prefs *prefs);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void GetPreferredSize(float* _width, float* _height);
void UpdateDeskbarIconWidth();
private:
void ResetDefaults();
bool first_time_attached;
int mode;
RTColorControl *colorcontrol;
void _ResetDefaults();
int32 fMode;
BMessenger fTarget;
Prefs* fPrefs;
RTColorControl* fColorControl;
bool fFirstTimeAttached;
// For Normal
BCheckBox *fadecolors;
BCheckBox* fFadeCheckBox;
// For Mini and Deskbar
BRadioButton *active, *idle, *frame;
BRadioButton* fActiveButton;
BRadioButton* fIdleButton;
BRadioButton* fFrameButton;
// For Deskbar
BTextControl *iconwidth;
BTextControl* fIconWidthControl;
};
#endif
#endif // CONFIG_VIEW_H

View File

@ -4,15 +4,14 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders shared ;
if $(TARGET_PLATFORM) != haiku {
UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ;
UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ;
}
if $(TARGET_PLATFORM) = r5 {
SubDirC++Flags -DR5_COMPATIBLE ;
}
Application Pulse :
BottomPrefsView.cpp
Application Pulse :
ConfigView.cpp
CPUButton.cpp
DeskbarPulseView.cpp
@ -28,7 +27,3 @@ Application Pulse :
: be
: Pulse.rdef
;
if $(HAIKU_COMPATIBLE) {
LinkAgainst Pulse : libroot.so ;
}

View File

@ -1,98 +1,133 @@
//****************************************************************************************
//
// File: PrefsWindow.cpp
//
// Written by: Daniel Switkin
//
// Copyright 1999, Be Incorporated
//
//****************************************************************************************
/*
* Copyright 2002-2006 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Copyright 1999, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* Written by: Daniel Switkin
*/
#include "PrefsWindow.h"
#include "Common.h"
#include "PulseApp.h"
#include "BottomPrefsView.h"
#include "ConfigView.h"
#include <interface/TabView.h>
#include <interface/TextControl.h>
#include <interface/Box.h>
//#include <Box.h>
#include <Button.h>
#include <TabView.h>
#include <TextControl.h>
#include <stdlib.h>
#include <stdio.h>
PrefsWindow::PrefsWindow(BRect rect, const char *name, BMessenger *messenger, Prefs *prefs) :
BWindow(rect, name, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE |
B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS) {
this->messenger = messenger;
this->prefs = prefs;
PrefsWindow::PrefsWindow(BRect rect, const char *name, BMessenger *messenger, Prefs *prefs)
: BWindow(rect, name, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
| B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS),
fTarget(*messenger),
fPrefs(prefs)
{
// This gives a nice look, and sets the background color correctly
BRect bounds = Bounds();
BBox *parent = new BBox(bounds, "ParentView", B_FOLLOW_NONE, B_PLAIN_BORDER);
AddChild(parent);
BView* topView = new BView(bounds, "ParentView", B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
bounds.top += 10;
bounds.bottom -= 45;
BTabView *tabview = new BTabView(bounds, "TabView");
tabview->SetFont(be_plain_font);
tabview->SetViewColor(parent->ViewColor());
tabview->ContainerView()->SetViewColor(parent->ViewColor());
parent->AddChild(tabview);
fTabView = new BTabView(bounds, "TabView", B_WIDTH_FROM_LABEL);
fTabView->SetFont(be_plain_font);
topView->AddChild(fTabView);
BRect rect = fTabView->ContainerView()->Bounds();
rect.InsetBy(5, 5);
ConfigView *normalView = new ConfigView(rect, "Normal Mode",
PRV_NORMAL_CHANGE_COLOR, fTarget, prefs);
fTabView->AddTab(normalView);
ConfigView *miniView = new ConfigView(rect, "Mini Mode", PRV_MINI_CHANGE_COLOR,
fTarget, prefs);
fTabView->AddTab(miniView);
BRect viewsize = tabview->ContainerView()->Bounds();
viewsize.InsetBy(5, 5);
ConfigView *normal = new ConfigView(viewsize, "Normal Mode", NORMAL_WINDOW_MODE, prefs);
normal->SetViewColor(tabview->ViewColor());
tabview->AddTab(normal);
ConfigView *mini = new ConfigView(viewsize, "Mini Mode", MINI_WINDOW_MODE, prefs);
mini->SetViewColor(tabview->ViewColor());
tabview->AddTab(mini);
ConfigView *deskbar = new ConfigView(viewsize, "Deskbar Mode", DESKBAR_MODE, prefs);
deskbar->SetViewColor(tabview->ViewColor());
tabview->AddTab(deskbar);
tabview->Select(0);
bounds.top = bounds.bottom + 1;
bounds.bottom += 45;
BottomPrefsView *bottomprefsview = new BottomPrefsView(bounds, "BottomPrefsView");
parent->AddChild(bottomprefsview);
ConfigView *deskbarView = new ConfigView(rect, "Deskbar Mode", PRV_DESKBAR_CHANGE_COLOR,
fTarget, prefs);
fTabView->AddTab(deskbarView);
float width, height;
deskbarView->GetPreferredSize(&width, &height);
normalView->ResizeTo(width, height);
miniView->ResizeTo(width, height);
deskbarView->ResizeTo(width, height);
fTabView->Select(0L);
fTabView->ResizeTo(deskbarView->Bounds().Width() + 16.0f, deskbarView->Bounds().Height()
+ fTabView->ContainerView()->Frame().top + 16.0f);
BButton *okButton = new BButton(rect, "ok", "OK", new BMessage(PRV_BOTTOM_OK),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
okButton->ResizeToPreferred();
okButton->MoveTo(Bounds().Width() - 8.0f - okButton->Bounds().Width(),
Bounds().Height() - 8.0f - okButton->Bounds().Height());
topView->AddChild(okButton);
BButton *defaultsButton = new BButton(okButton->Frame(), "defaults", "Defaults",
new BMessage(PRV_BOTTOM_DEFAULTS), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
defaultsButton->ResizeToPreferred();
defaultsButton->MoveBy(-defaultsButton->Bounds().Width() - 10.0f, 0.0f);
topView->AddChild(defaultsButton);
okButton->MakeDefault(true);
fTabView->SetResizingMode(B_FOLLOW_NONE);
ResizeTo(fTabView->Frame().Width(), fTabView->Frame().bottom + 16.0f
+ okButton->Bounds().Height());
}
void PrefsWindow::MessageReceived(BMessage *message) {
PrefsWindow::~PrefsWindow()
{
fPrefs->prefs_window_rect = Frame();
fPrefs->Save();
}
void
PrefsWindow::MessageReceived(BMessage *message)
{
switch (message->what) {
case PRV_BOTTOM_OK: {
case PRV_BOTTOM_OK:
{
Hide();
BTabView *tabview = (BTabView *)FindView("TabView");
tabview->Select(2);
fTabView->Select(2);
ConfigView *deskbar = (ConfigView *)FindView("Deskbar Mode");
deskbar->UpdateDeskbarIconWidth();
if (Lock()) Quit();
PostMessage(B_QUIT_REQUESTED);
break;
}
case PRV_BOTTOM_DEFAULTS: {
BTabView *tabview = (BTabView *)FindView("TabView");
BTab *tab = tabview->TabAt(tabview->Selection());
case PRV_BOTTOM_DEFAULTS:
{
BTab *tab = fTabView->TabAt(fTabView->Selection());
BView *view = tab->View();
view->MessageReceived(message);
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}
void PrefsWindow::Quit() {
messenger->SendMessage(new BMessage(PRV_QUIT));
BWindow::Quit();
}
PrefsWindow::~PrefsWindow() {
prefs->prefs_window_rect = Frame();
prefs->Save();
delete messenger;
bool
PrefsWindow::QuitRequested()
{
fTarget.SendMessage(new BMessage(PRV_QUIT));
return true;
}

View File

@ -1,29 +1,35 @@
//****************************************************************************************
//
// File: PrefsWindow.h
//
// Written by: Daniel Switkin
//
// Copyright 1999, Be Incorporated
//
//****************************************************************************************
/*
* Copyright 2002-2006 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Copyright 1999, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* Written by: Daniel Switkin
*/
#ifndef PREFS_WINDOW_H
#define PREFS_WINDOW_H
#ifndef PREFSWINDOW_H
#define PREFSWINDOW_H
#include <interface/Window.h>
#include <app/Messenger.h>
#include "Prefs.h"
#include <Messenger.h>
#include <Window.h>
class BTabView;
class PrefsWindow : public BWindow {
public:
PrefsWindow(BRect rect, const char *name, BMessenger *messenger, Prefs *prefs);
void MessageReceived(BMessage *message);
~PrefsWindow();
void Quit();
virtual ~PrefsWindow();
Prefs *prefs;
BMessenger *messenger;
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested();
private:
BTabView* fTabView;
BMessenger fTarget;
Prefs* fPrefs;
};
#endif
#endif // PREFS_WINDOW_H