* now accepts NULL arguments for "width" and "height" in GetPreferredSize()
* minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15086 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,18 +3,20 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Marc Flerackers ([email protected])
|
* Marc Flerackers ([email protected])
|
||||||
* Mike Wilber
|
* Mike Wilber
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
* Ivan Tonizza
|
* Ivan Tonizza
|
||||||
* Stephan Aßmus, <[email protected]>
|
* Stephan Aßmus, <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
BButton::BButton(BRect frame, const char *name, const char *label, BMessage *message,
|
BButton::BButton(BRect frame, const char *name, const char *label, BMessage *message,
|
||||||
uint32 resizingMode, uint32 flags)
|
uint32 resizingMode, uint32 flags)
|
||||||
: BControl(frame, name, label, message, resizingMode, flags |= B_WILL_DRAW),
|
: BControl(frame, name, label, message, resizingMode, flags |= B_WILL_DRAW),
|
||||||
@@ -47,8 +49,8 @@ BButton::Instantiate(BMessage *archive)
|
|||||||
{
|
{
|
||||||
if (validate_instantiation(archive, "BButton"))
|
if (validate_instantiation(archive, "BButton"))
|
||||||
return new BButton(archive);
|
return new BButton(archive);
|
||||||
else
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -382,14 +384,12 @@ BButton::MouseDown(BPoint point)
|
|||||||
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
|
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
|
||||||
SetTracking(true);
|
SetTracking(true);
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Window()->UpdateIfNeeded();
|
Window()->UpdateIfNeeded();
|
||||||
|
|
||||||
snooze(40000);
|
snooze(40000);
|
||||||
|
|
||||||
GetMouse(&point, &buttons, true);
|
GetMouse(&point, &buttons, true);
|
||||||
@@ -548,20 +548,25 @@ BButton::SetValue(int32 value)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BButton::GetPreferredSize(float *width, float *height)
|
BButton::GetPreferredSize(float *_width, float *_height)
|
||||||
{
|
{
|
||||||
font_height fh;
|
if (_height) {
|
||||||
GetFontHeight(&fh);
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
|
||||||
*height = 12.0f + (float)ceil(fh.ascent + fh.descent);
|
*_height = 12.0f + (float)ceil(fontHeight.ascent + fontHeight.descent)
|
||||||
*width = 20.0f + (float)ceil(StringWidth(Label()));
|
+ (fDrawAsDefault ? 6.0f : 0);
|
||||||
|
}
|
||||||
if (*width < 75.0f)
|
|
||||||
*width = 75.0f;
|
|
||||||
|
|
||||||
if (fDrawAsDefault) {
|
if (_width) {
|
||||||
*width += 6.0f;
|
float width = 20.0f + (float)ceil(StringWidth(Label()));
|
||||||
*height += 6.0f;
|
if (width < 75.0f)
|
||||||
|
width = 75.0f;
|
||||||
|
|
||||||
|
if (fDrawAsDefault)
|
||||||
|
width += 6.0f;
|
||||||
|
|
||||||
|
*_width = width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,9 +748,11 @@ BButton::DrawFocusLine(float x, float y, float width, bool visible)
|
|||||||
{
|
{
|
||||||
if (visible)
|
if (visible)
|
||||||
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
||||||
else
|
else {
|
||||||
SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||||
B_LIGHTEN_1_TINT));
|
B_LIGHTEN_1_TINT));
|
||||||
|
}
|
||||||
|
|
||||||
// Blue Line
|
// Blue Line
|
||||||
StrokeLine(BPoint(x, y), BPoint(x + width, y));
|
StrokeLine(BPoint(x, y), BPoint(x + width, y));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user