* Made the button bar no longer draw over the menu bar, and it now uses the
BControlLook to draw its bottom border instead of using a BBox, and have the parent move it around to make it somehow fit (or not). * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29913 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+97
-67
@@ -33,76 +33,83 @@ All rights reserved.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ButtonBar.h"
|
#include "ButtonBar.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <ControlLook.h>
|
||||||
|
|
||||||
|
|
||||||
struct BBDivider {
|
struct BBDivider {
|
||||||
float where;
|
float where;
|
||||||
float vmargin;
|
float vmargin;
|
||||||
BmapButton *button;
|
BmapButton* button;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int32 kDividerBlockSize = 8;
|
static const int32 kDividerBlockSize = 8;
|
||||||
|
|
||||||
ButtonBar::ButtonBar(BRect frame, const char *name, uint8 enabledOffset, uint8 disabledOffset,
|
|
||||||
uint8 rollOffset, uint8 pressedOffset, float Hmargin, float Vmargin,
|
ButtonBar::ButtonBar(BRect frame, const char* name, uint8 enabledOffset,
|
||||||
uint32 resizeMask, int32 flags, border_style border)
|
uint8 disabledOffset, uint8 rollOffset, uint8 pressedOffset,
|
||||||
: BBox(frame, name, resizeMask, flags, border),
|
float Hmargin, float Vmargin, uint32 resizeMask, int32 flags)
|
||||||
fMaxHeight(0),
|
: BView(frame, name, resizeMask, flags),
|
||||||
fMaxWidth(0),
|
fMaxHeight(0),
|
||||||
fNextXOffset(Hmargin),
|
fMaxWidth(0),
|
||||||
fHMargin(Hmargin),
|
fNextXOffset(Hmargin),
|
||||||
fVMargin(Vmargin),
|
fHMargin(Hmargin),
|
||||||
fEnabledOffset(enabledOffset),
|
fVMargin(Vmargin),
|
||||||
fDisabledOffset(disabledOffset),
|
fEnabledOffset(enabledOffset),
|
||||||
fRollOffset(rollOffset),
|
fDisabledOffset(disabledOffset),
|
||||||
fPressedOffset(pressedOffset),
|
fRollOffset(rollOffset),
|
||||||
fDividerArray(NULL),
|
fPressedOffset(pressedOffset),
|
||||||
fDividers(0),
|
fDividerArray(NULL),
|
||||||
fShowLabels(true)
|
fDividers(0),
|
||||||
|
fShowLabels(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonBar::~ButtonBar(void)
|
|
||||||
|
ButtonBar::~ButtonBar()
|
||||||
{
|
{
|
||||||
if (fDividerArray)
|
free(fDividerArray);
|
||||||
free(fDividerArray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BmapButton *ButtonBar::AddButton(const char *label, int32 baseID, BMessage *msg)
|
|
||||||
|
BmapButton*
|
||||||
|
ButtonBar::AddButton(const char *label, int32 baseID, BMessage *msg)
|
||||||
{
|
{
|
||||||
BmapButton *button;
|
BmapButton* button = new BmapButton(BRect(0, 0, 31, 31), label, label,
|
||||||
|
baseID + fEnabledOffset, baseID + fDisabledOffset, baseID + fRollOffset,
|
||||||
button = new BmapButton(BRect(0, 0, 31, 31), label, label, baseID+fEnabledOffset,
|
baseID + fPressedOffset, fShowLabels, msg,
|
||||||
baseID+fDisabledOffset, baseID+fRollOffset, baseID+fPressedOffset,
|
B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||||
fShowLabels, msg, B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
|
||||||
|
|
||||||
fButtonList.AddItem(button);
|
fButtonList.AddItem(button);
|
||||||
AddChild(button);
|
AddChild(button);
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonBar::Arrange(bool fixedWidth)
|
|
||||||
|
void
|
||||||
|
ButtonBar::Arrange(bool fixedWidth)
|
||||||
{
|
{
|
||||||
// Reset Positioning Info
|
// Reset Positioning Info
|
||||||
fNextXOffset = fHMargin;
|
fNextXOffset = fHMargin;
|
||||||
fMaxHeight = 0;
|
fMaxHeight = 0;
|
||||||
fMaxWidth = 0;
|
fMaxWidth = 0;
|
||||||
|
|
||||||
int32 i;
|
int32 i;
|
||||||
float width, height;
|
float width, height;
|
||||||
BmapButton *button;
|
BmapButton *button;
|
||||||
|
|
||||||
// Determine Largest button dimensions
|
// Determine Largest button dimensions
|
||||||
for (i = 0; (button = (BmapButton *)fButtonList.ItemAt(i)) != NULL; i++)
|
for (i = 0; (button = (BmapButton*)fButtonList.ItemAt(i)) != NULL; i++) {
|
||||||
{
|
|
||||||
button->GetPreferredSize(&width, &height);
|
button->GetPreferredSize(&width, &height);
|
||||||
if (height > fMaxHeight)
|
if (height > fMaxHeight)
|
||||||
fMaxHeight = height;
|
fMaxHeight = height;
|
||||||
if (width > fMaxWidth)
|
if (width > fMaxWidth)
|
||||||
fMaxWidth = width;
|
fMaxWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arrange buttons
|
// Arrange buttons
|
||||||
for (i = 0; (button = (BmapButton *)fButtonList.ItemAt(i)) != NULL; i++) {
|
for (i = 0; (button = (BmapButton *)fButtonList.ItemAt(i)) != NULL; i++) {
|
||||||
button->MoveTo(fNextXOffset, fVMargin);
|
button->MoveTo(fNextXOffset, fVMargin);
|
||||||
@@ -115,69 +122,92 @@ void ButtonBar::Arrange(bool fixedWidth)
|
|||||||
fNextXOffset += width + fHMargin;
|
fNextXOffset += width + fHMargin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move dividers to match
|
// Move dividers to match
|
||||||
for(i = 0; i < fDividers; i++) {
|
for (i = 0; i < fDividers; i++) {
|
||||||
if (fDividerArray[i].button)
|
if (fDividerArray[i].button) {
|
||||||
fDividerArray[i].where = fDividerArray[i].button->Frame().right + floor(fHMargin/2);
|
fDividerArray[i].where = fDividerArray[i].button->Frame().right
|
||||||
else
|
+ floor(fHMargin/2);
|
||||||
|
} else
|
||||||
fDividerArray[i].where = floor(fHMargin / 2);
|
fDividerArray[i].where = floor(fHMargin / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonBar::GetPreferredSize(float *width, float *height)
|
|
||||||
|
void
|
||||||
|
ButtonBar::GetPreferredSize(float* width, float* height)
|
||||||
{
|
{
|
||||||
*width = fNextXOffset + fHMargin;
|
*width = fNextXOffset + fHMargin;
|
||||||
*height = fMaxHeight + (2 * fVMargin);
|
*height = fMaxHeight + (2 * fVMargin) + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonBar::AttachedToWindow(void)
|
|
||||||
|
void
|
||||||
|
ButtonBar::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent())
|
if (Parent())
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
BBox::AttachedToWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonBar::Draw(BRect updateRect)
|
|
||||||
|
void
|
||||||
|
ButtonBar::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
BBox::Draw(updateRect);
|
rgb_color high = tint_color(ViewColor(), 1.1);
|
||||||
rgb_color high = { 184, 184, 184, 255 };
|
rgb_color low = tint_color(ViewColor(), 0.8);
|
||||||
rgb_color low = { 232, 232, 232, 255 };
|
BRect bounds = Bounds();
|
||||||
BRect bounds = Bounds();
|
|
||||||
float where, vmargin;
|
BeginLineArray(fDividers * 2);
|
||||||
|
|
||||||
BeginLineArray(fDividers*2);
|
for (int32 i = 0; i < fDividers; i++) {
|
||||||
for (int32 i=0; i<fDividers; i++) {
|
float where = fDividerArray[i].where;
|
||||||
where = fDividerArray[i].where;
|
float vmargin = fDividerArray[i].vmargin;
|
||||||
vmargin = fDividerArray[i].vmargin;
|
|
||||||
AddLine(BPoint(where, fVMargin+vmargin), BPoint(where, bounds.bottom-fVMargin-vmargin), high);
|
AddLine(BPoint(where, fVMargin + vmargin),
|
||||||
AddLine(BPoint(where+1, fVMargin+vmargin), BPoint(where+1, bounds.bottom-fVMargin-vmargin), low);
|
BPoint(where, bounds.bottom - fVMargin - vmargin), high);
|
||||||
|
AddLine(BPoint(where + 1, fVMargin + vmargin),
|
||||||
|
BPoint(where + 1, bounds.bottom - fVMargin - vmargin), low);
|
||||||
}
|
}
|
||||||
EndLineArray();
|
EndLineArray();
|
||||||
|
|
||||||
|
be_control_look->DrawBorder(this, bounds, updateRect, ViewColor(),
|
||||||
|
B_FANCY_BORDER, 0, BControlLook::B_BOTTOM_BORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonBar::AddDivider(float vmargin)
|
|
||||||
|
void
|
||||||
|
ButtonBar::AddDivider(float vmargin)
|
||||||
{
|
{
|
||||||
// Do we need to allocate memory?
|
// Do we need to allocate memory?
|
||||||
if (fDividers == 0)
|
if (fDividers == 0) {
|
||||||
fDividerArray = (BBDivider *)malloc(sizeof(BBDivider)*kDividerBlockSize);
|
fDividerArray = (BBDivider*)malloc(sizeof(BBDivider)
|
||||||
if ((fDividers % kDividerBlockSize) == 0)
|
* kDividerBlockSize);
|
||||||
fDividerArray = (BBDivider *)realloc(fDividerArray, sizeof(BBDivider)*kDividerBlockSize*((fDividers/kDividerBlockSize)+1));
|
}
|
||||||
|
if ((fDividers % kDividerBlockSize) == 0) {
|
||||||
|
fDividerArray = (BBDivider*)realloc(fDividerArray,
|
||||||
|
sizeof(BBDivider) * kDividerBlockSize
|
||||||
|
* ((fDividers/kDividerBlockSize) + 1));
|
||||||
|
}
|
||||||
|
|
||||||
// Cache the location and the button which proceeds it
|
// Cache the location and the button which proceeds it
|
||||||
// The button is stored because we may later wish to change the layout
|
// The button is stored because we may later wish to change the layout
|
||||||
fDividerArray[fDividers].vmargin = vmargin;
|
fDividerArray[fDividers].vmargin = vmargin;
|
||||||
fDividerArray[fDividers].where = fNextXOffset+floor(fHMargin/2);
|
fDividerArray[fDividers].where = fNextXOffset + floorf(fHMargin / 2);
|
||||||
fDividerArray[fDividers].button = (BmapButton *)fButtonList.ItemAt(fButtonList.CountItems()-1);
|
fDividerArray[fDividers].button = (BmapButton*)fButtonList.ItemAt(
|
||||||
|
fButtonList.CountItems() - 1);
|
||||||
fDividers++;
|
fDividers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonBar::ShowLabels(bool show)
|
|
||||||
|
void
|
||||||
|
ButtonBar::ShowLabels(bool show)
|
||||||
{
|
{
|
||||||
BmapButton *button;
|
BmapButton* button;
|
||||||
|
|
||||||
// Set show label flags on buttons
|
// Set show label flags on buttons
|
||||||
for (int32 i=0; (button = (BmapButton *)fButtonList.ItemAt(i)) != NULL; i++)
|
for (int32 i = 0; (button = (BmapButton*)fButtonList.ItemAt(i)) != NULL;
|
||||||
|
i++) {
|
||||||
button->ShowLabel(show);
|
button->ShowLabel(show);
|
||||||
|
}
|
||||||
fShowLabels = show;
|
fShowLabels = show;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,14 +41,13 @@ All rights reserved.
|
|||||||
|
|
||||||
struct BBDivider;
|
struct BBDivider;
|
||||||
|
|
||||||
class ButtonBar : public BBox {
|
class ButtonBar : public BView {
|
||||||
public:
|
public:
|
||||||
ButtonBar(BRect frame, const char *name, uint8 enabledOffset,
|
ButtonBar(BRect frame, const char *name, uint8 enabledOffset,
|
||||||
uint8 disabledOffset, uint8 rollOffset, uint8 pressedOffset,
|
uint8 disabledOffset, uint8 rollOffset, uint8 pressedOffset,
|
||||||
float Hmargin, float Vmargin,
|
float Hmargin, float Vmargin,
|
||||||
uint32 resizeMask = B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
|
uint32 resizeMask = B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
|
||||||
int32 flags = B_NAVIGABLE_JUMP | B_FRAME_EVENTS | B_WILL_DRAW,
|
int32 flags = B_NAVIGABLE_JUMP | B_FRAME_EVENTS | B_WILL_DRAW);
|
||||||
border_style border = B_FANCY_BORDER);
|
|
||||||
virtual ~ButtonBar( void );
|
virtual ~ButtonBar( void );
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
|
|||||||
@@ -493,11 +493,10 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
|
|||||||
if (showButtonBar) {
|
if (showButtonBar) {
|
||||||
BuildButtonBar();
|
BuildButtonBar();
|
||||||
fButtonBar->ShowLabels(showButtonBar);
|
fButtonBar->ShowLabels(showButtonBar);
|
||||||
fButtonBar->Arrange(/* True for all buttons same size, false to just fit */
|
fButtonBar->Arrange(MDR_DIALECT_CHOICE(true, true));
|
||||||
MDR_DIALECT_CHOICE (true, true));
|
|
||||||
fButtonBar->GetPreferredSize(&bbwidth, &bbheight);
|
fButtonBar->GetPreferredSize(&bbwidth, &bbheight);
|
||||||
fButtonBar->ResizeTo(Bounds().right+3, bbheight+1);
|
fButtonBar->ResizeTo(Bounds().right, bbheight);
|
||||||
fButtonBar->MoveTo(-1, height-1);
|
fButtonBar->MoveTo(0, height);
|
||||||
fButtonBar->Show();
|
fButtonBar->Show();
|
||||||
} else
|
} else
|
||||||
fButtonBar = NULL;
|
fButtonBar = NULL;
|
||||||
@@ -646,8 +645,8 @@ TMailWindow::UpdateViews()
|
|||||||
fButtonBar->Arrange(/* True for all buttons same size, false to just fit */
|
fButtonBar->Arrange(/* True for all buttons same size, false to just fit */
|
||||||
MDR_DIALECT_CHOICE (true, true));
|
MDR_DIALECT_CHOICE (true, true));
|
||||||
fButtonBar->GetPreferredSize( &bbwidth, &bbheight);
|
fButtonBar->GetPreferredSize( &bbwidth, &bbheight);
|
||||||
fButtonBar->ResizeTo(Bounds().right+3, bbheight+1);
|
fButtonBar->ResizeTo(Bounds().right, bbheight);
|
||||||
fButtonBar->MoveTo(-1, nextY-1);
|
fButtonBar->MoveTo(0, nextY);
|
||||||
nextY += bbheight + 1;
|
nextY += bbheight + 1;
|
||||||
if (fButtonBar->IsHidden())
|
if (fButtonBar->IsHidden())
|
||||||
fButtonBar->Show();
|
fButtonBar->Show();
|
||||||
|
|||||||
Reference in New Issue
Block a user