From ef4aa90f49ad43b0a2df11a04336ae19ac35e4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 10 Feb 2006 17:07:38 +0000 Subject: [PATCH] Added public InnerFrame() and TopBorderOffset() methods. If you don't like the naming, please shout :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16335 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Box.h | 5 ++- src/kits/interface/Box.cpp | 84 ++++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/headers/os/interface/Box.h b/headers/os/interface/Box.h index 0f85f9317b..eca9488820 100644 --- a/headers/os/interface/Box.h +++ b/headers/os/interface/Box.h @@ -1,5 +1,5 @@ /* - * Copyright 2005, Haiku, Inc. All Rights Reserved. + * Copyright 2005-2006, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _BOX_H @@ -26,6 +26,9 @@ class BBox : public BView { virtual void SetBorder(border_style border); border_style Border() const; + float TopBorderOffset(); + BRect InnerFrame(); + void SetLabel(const char* string); status_t SetLabel(BView* viewLabel); diff --git a/src/kits/interface/Box.cpp b/src/kits/interface/Box.cpp index 79e879035f..b0194a292a 100644 --- a/src/kits/interface/Box.cpp +++ b/src/kits/interface/Box.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2005, Haiku, Inc. + * Copyright (c) 2001-2006, Haiku, Inc. * Distributed under the terms of the MIT license. * * Authors: @@ -22,7 +22,7 @@ BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags, border_style border) : BView(frame, name, resizingMode, flags | B_FRAME_EVENTS), - fStyle(border) + fStyle(border) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -35,22 +35,6 @@ BBox::BBox(BMessage *archive) : BView(archive) { _InitObject(archive); - - const char *string; - - if (archive->FindString("_label", &string) == B_OK) - SetLabel(string); - - bool aBool; - int32 anInt32; - - if (archive->FindBool("_style", &aBool) == B_OK) - fStyle = aBool ? B_FANCY_BORDER : B_PLAIN_BORDER; - else if (archive->FindInt32("_style", &anInt32) == B_OK) - fStyle = (border_style)anInt32; - - if (archive->FindBool("_lblview", &aBool) == B_OK) - fLabelView = ChildAt(0); } @@ -107,6 +91,42 @@ BBox::Border() const } +//! This function is not part of the R5 API and is not yet finalized yet +float +BBox::TopBorderOffset() +{ + float labelHeight = 0; + + if (fLabel != NULL) + labelHeight = fLabelBox->Height(); + else if (fLabelView != NULL) + labelHeight = fLabelView->Bounds().Height(); + + return labelHeight / 2.0f; +} + + +//! This function is not part of the R5 API and is not yet finalized yet +BRect +BBox::InnerFrame() +{ + float borderSize = Border() == B_FANCY_BORDER ? 2.0f + : Border() == B_PLAIN_BORDER ? 1.0f : 0.0f; + float labelHeight = 0.0f; + + if (fLabel != NULL) + labelHeight = fLabelBox->Height(); + else if (fLabelView != NULL) + labelHeight = fLabelView->Bounds().Height(); + + BRect rect = Bounds().InsetByCopy(borderSize, borderSize); + if (labelHeight) + rect.top = Bounds().top + labelHeight; + + return rect; +} + + void BBox::SetLabel(const char *string) { @@ -427,24 +447,44 @@ BBox::operator=(const BBox &) void -BBox::_InitObject(BMessage *data) +BBox::_InitObject(BMessage* archive) { - fLabel = NULL; fBounds = Bounds(); + + fLabel = NULL; fLabelView = NULL; + fLabelBox = NULL; int32 flags = 0; BFont font(be_bold_font); - if (!data || !data->HasString("_fname")) + if (!archive || !archive->HasString("_fname")) flags = B_FONT_FAMILY_AND_STYLE; - if (!data || !data->HasFloat("_fflt")) + if (!archive || !archive->HasFloat("_fflt")) flags |= B_FONT_SIZE; if (flags != 0) SetFont(&font, flags); + + if (archive != NULL) { + const char *string; + if (archive->FindString("_label", &string) == B_OK) + SetLabel(string); + + bool fancy; + int32 style; + + if (archive->FindBool("_style", &fancy) == B_OK) + fStyle = fancy ? B_FANCY_BORDER : B_PLAIN_BORDER; + else if (archive->FindInt32("_style", &style) == B_OK) + fStyle = (border_style)style; + + bool hasLabelView; + if (archive->FindBool("_lblview", &hasLabelView) == B_OK) + fLabelView = ChildAt(0); + } }