* Cleaned up the header

* Reordered methods to group them logically
* Use nothrow version of new when instantiating BCheckBox from archive.

+alphabranch


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32687 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-08-26 10:30:27 +00:00
parent 49473fc52e
commit c5c20344eb
2 changed files with 266 additions and 274 deletions
+49 -82
View File
@@ -1,98 +1,56 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2009, Haiku Inc. All rights reserved.
// * Distributed under the terms of the MIT license.
// Permission is hereby granted, free of charge, to any person obtaining a */
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: CheckBox.h
// Author: Marc Flerackers ([email protected])
// Description: BCheckBox displays an on/off control.
//------------------------------------------------------------------------------
#ifndef _CHECK_BOX_H #ifndef _CHECK_BOX_H
#define _CHECK_BOX_H #define _CHECK_BOX_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h>
#include <Control.h> #include <Control.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
// BCheckBox class -------------------------------------------------------------
class BCheckBox : public BControl { class BCheckBox : public BControl {
public: public:
BCheckBox(BRect frame, BCheckBox(BRect frame, const char* name,
const char *name, const char* label, BMessage* message,
const char *label, uint32 resizingMode
BMessage *message, = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BCheckBox(const char *name,
const char *label,
BMessage *message,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BCheckBox(const char* name, const char* label,
BMessage* message, uint32 flags
= B_WILL_DRAW | B_NAVIGABLE);
BCheckBox(const char* label, BCheckBox(const char* label,
BMessage* message = NULL); BMessage* message = NULL);
BCheckBox(BMessage* archive);
virtual ~BCheckBox(); virtual ~BCheckBox();
/* Archiving */
BCheckBox(BMessage *archive);
static BArchivable* Instantiate(BMessage* archive); static BArchivable* Instantiate(BMessage* archive);
virtual status_t Archive(BMessage *archive, bool deep = true) const; virtual status_t Archive(BMessage* archive,
bool deep = true) const;
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MouseDown(BPoint point);
virtual void MessageReceived(BMessage *message);
virtual void WindowActivated(bool active);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void SetValue(int32 value);
virtual void GetPreferredSize(float *width, float *height);
virtual void ResizeToPreferred();
virtual status_t Invoke(BMessage *message = NULL);
virtual void FrameMoved(BPoint newLocation);
virtual void FrameResized(float width, float height);
virtual BHandler *ResolveSpecifier(BMessage *message,
int32 index,
BMessage *specifier,
int32 what,
const char *property);
virtual status_t GetSupportedSuites(BMessage *message);
virtual void MakeFocus(bool focused = true);
virtual void AllAttached(); virtual void AllAttached();
virtual void AllDetached(); virtual void AllDetached();
virtual status_t Perform(perform_code d, void *arg); virtual void FrameMoved(BPoint newLocation);
virtual void FrameResized(float width, float height);
virtual void WindowActivated(bool active);
virtual void MessageReceived(BMessage* message);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MouseDown(BPoint point);
virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit,
const BMessage* dragMessage);
virtual void GetPreferredSize(float* _width,
float* _height);
virtual void ResizeToPreferred();
virtual void InvalidateLayout(bool descendants = false); virtual void InvalidateLayout(bool descendants = false);
@@ -100,27 +58,36 @@ virtual BSize MinSize();
virtual BSize MaxSize(); virtual BSize MaxSize();
virtual BSize PreferredSize(); virtual BSize PreferredSize();
private: virtual void MakeFocus(bool focused = true);
virtual void SetValue(int32 value);
virtual status_t Invoke(BMessage* message = NULL);
virtual BHandler* ResolveSpecifier(BMessage* message,
int32 index, BMessage* specifier,
int32 what, const char* property);
virtual status_t GetSupportedSuites(BMessage* message);
virtual status_t Perform(perform_code code, void* data);
private:
// FBC padding
virtual void _ReservedCheckBox1(); virtual void _ReservedCheckBox1();
virtual void _ReservedCheckBox2(); virtual void _ReservedCheckBox2();
virtual void _ReservedCheckBox3(); virtual void _ReservedCheckBox3();
private:
BRect _CheckBoxFrame() const; BRect _CheckBoxFrame() const;
BSize _ValidatePreferredSize(); BSize _ValidatePreferredSize();
private:
// Forbidden
BCheckBox& operator=(const BCheckBox&); BCheckBox& operator=(const BCheckBox&);
private:
BSize fPreferredSize; BSize fPreferredSize;
bool fOutlined; bool fOutlined;
}; };
//------------------------------------------------------------------------------
#endif // _CHECK_BOX_H #endif // _CHECK_BOX_H
/*
* $Log $
*
* $Id $
*
*/
+147 -122
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2001-2007, Haiku Inc. * Copyright 2001-2009, Haiku Inc.
* 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])
* Stephan Aßmus <[email protected]>
*/ */
/*! BCheckBox displays an on/off control. */ /*! BCheckBox displays an on/off control. */
@@ -11,6 +12,8 @@
#include <CheckBox.h> #include <CheckBox.h>
#include <new>
#include <ControlLook.h> #include <ControlLook.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <Window.h> #include <Window.h>
@@ -36,7 +39,8 @@ BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
BCheckBox::BCheckBox(const char *name, const char *label, BMessage *message, BCheckBox::BCheckBox(const char *name, const char *label, BMessage *message,
uint32 flags) uint32 flags)
: BControl(name, label, message, flags | B_WILL_DRAW | B_NAVIGABLE), :
BControl(name, label, message, flags | B_WILL_DRAW | B_NAVIGABLE),
fPreferredSize(), fPreferredSize(),
fOutlined(false) fOutlined(false)
{ {
@@ -44,30 +48,35 @@ BCheckBox::BCheckBox(const char *name, const char *label, BMessage *message,
BCheckBox::BCheckBox(const char *label, BMessage *message) BCheckBox::BCheckBox(const char *label, BMessage *message)
: BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE), :
BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE),
fPreferredSize(), fPreferredSize(),
fOutlined(false) fOutlined(false)
{ {
} }
BCheckBox::BCheckBox(BMessage *archive)
:
BControl(archive),
fOutlined(false)
{
}
BCheckBox::~BCheckBox() BCheckBox::~BCheckBox()
{ {
} }
BCheckBox::BCheckBox(BMessage *archive) // #pragma mark -
: BControl(archive),
fOutlined(false)
{
}
BArchivable * BArchivable *
BCheckBox::Instantiate(BMessage *archive) BCheckBox::Instantiate(BMessage *archive)
{ {
if (validate_instantiation(archive, "BCheckBox")) if (validate_instantiation(archive, "BCheckBox"))
return new BCheckBox(archive); return new(std::nothrow) BCheckBox(archive);
return NULL; return NULL;
} }
@@ -80,6 +89,9 @@ BCheckBox::Archive(BMessage *archive, bool deep) const
} }
// #pragma mark -
void void
BCheckBox::Draw(BRect updateRect) BCheckBox::Draw(BRect updateRect)
{ {
@@ -254,6 +266,65 @@ BCheckBox::AttachedToWindow()
} }
void
BCheckBox::DetachedFromWindow()
{
BControl::DetachedFromWindow();
}
void
BCheckBox::AllAttached()
{
BControl::AllAttached();
}
void
BCheckBox::AllDetached()
{
BControl::AllDetached();
}
void
BCheckBox::FrameMoved(BPoint newLocation)
{
BControl::FrameMoved(newLocation);
}
void
BCheckBox::FrameResized(float width, float height)
{
BControl::FrameResized(width, height);
}
void
BCheckBox::WindowActivated(bool active)
{
BControl::WindowActivated(active);
}
// #pragma mark -
void
BCheckBox::MessageReceived(BMessage *message)
{
BControl::MessageReceived(message);
}
void
BCheckBox::KeyDown(const char *bytes, int32 numBytes)
{
BControl::KeyDown(bytes, numBytes);
}
void void
BCheckBox::MouseDown(BPoint point) BCheckBox::MouseDown(BPoint point)
{ {
@@ -298,27 +369,6 @@ BCheckBox::MouseDown(BPoint point)
} }
void
BCheckBox::MessageReceived(BMessage *message)
{
BControl::MessageReceived(message);
}
void
BCheckBox::WindowActivated(bool active)
{
BControl::WindowActivated(active);
}
void
BCheckBox::KeyDown(const char *bytes, int32 numBytes)
{
BControl::KeyDown(bytes, numBytes);
}
void void
BCheckBox::MouseUp(BPoint point) BCheckBox::MouseUp(BPoint point)
{ {
@@ -359,24 +409,7 @@ BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
} }
void // #pragma mark -
BCheckBox::DetachedFromWindow()
{
BControl::DetachedFromWindow();
}
void
BCheckBox::SetValue(int32 value)
{
value = value ? B_CONTROL_ON : B_CONTROL_OFF;
// we only accept boolean values
if (value != Value()) {
BControl::SetValueNoUpdate(value);
Invalidate(_CheckBoxFrame());
}
}
void void
@@ -406,6 +439,63 @@ BCheckBox::ResizeToPreferred()
} }
void
BCheckBox::InvalidateLayout(bool descendants)
{
// invalidate cached preferred size
fPreferredSize.Set(B_SIZE_UNSET, B_SIZE_UNSET);
BControl::InvalidateLayout(descendants);
}
BSize
BCheckBox::MinSize()
{
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
_ValidatePreferredSize());
}
BSize
BCheckBox::MaxSize()
{
return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
BSize(B_SIZE_UNLIMITED, _ValidatePreferredSize().height));
}
BSize
BCheckBox::PreferredSize()
{
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
_ValidatePreferredSize());
}
// #pragma mark -
void
BCheckBox::MakeFocus(bool focused)
{
BControl::MakeFocus(focused);
}
void
BCheckBox::SetValue(int32 value)
{
value = value ? B_CONTROL_ON : B_CONTROL_OFF;
// we only accept boolean values
if (value != Value()) {
BControl::SetValueNoUpdate(value);
Invalidate(_CheckBoxFrame());
}
}
status_t status_t
BCheckBox::Invoke(BMessage *message) BCheckBox::Invoke(BMessage *message)
{ {
@@ -413,20 +503,6 @@ BCheckBox::Invoke(BMessage *message)
} }
void
BCheckBox::FrameMoved(BPoint newLocation)
{
BControl::FrameMoved(newLocation);
}
void
BCheckBox::FrameResized(float width, float height)
{
BControl::FrameResized(width, height);
}
BHandler * BHandler *
BCheckBox::ResolveSpecifier(BMessage *message, int32 index, BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, const char *property) BMessage *specifier, int32 what, const char *property)
@@ -443,27 +519,6 @@ BCheckBox::GetSupportedSuites(BMessage *message)
} }
void
BCheckBox::MakeFocus(bool focused)
{
BControl::MakeFocus(focused);
}
void
BCheckBox::AllAttached()
{
BControl::AllAttached();
}
void
BCheckBox::AllDetached()
{
BControl::AllDetached();
}
status_t status_t
BCheckBox::Perform(perform_code code, void* _data) BCheckBox::Perform(perform_code code, void* _data)
{ {
@@ -520,38 +575,7 @@ BCheckBox::Perform(perform_code code, void* _data)
} }
void // #pragma mark - FBC padding
BCheckBox::InvalidateLayout(bool descendants)
{
// invalidate cached preferred size
fPreferredSize.Set(B_SIZE_UNSET, B_SIZE_UNSET);
BControl::InvalidateLayout(descendants);
}
BSize
BCheckBox::MinSize()
{
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
_ValidatePreferredSize());
}
BSize
BCheckBox::MaxSize()
{
return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
BSize(B_SIZE_UNLIMITED, _ValidatePreferredSize().height));
}
BSize
BCheckBox::PreferredSize()
{
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
_ValidatePreferredSize());
}
void BCheckBox::_ReservedCheckBox1() {} void BCheckBox::_ReservedCheckBox1() {}
@@ -559,13 +583,6 @@ void BCheckBox::_ReservedCheckBox2() {}
void BCheckBox::_ReservedCheckBox3() {} void BCheckBox::_ReservedCheckBox3() {}
BCheckBox &
BCheckBox::operator=(const BCheckBox &)
{
return *this;
}
BRect BRect
BCheckBox::_CheckBoxFrame() const BCheckBox::_CheckBoxFrame() const
{ {
@@ -597,3 +614,11 @@ BCheckBox::_ValidatePreferredSize()
return fPreferredSize; return fPreferredSize;
} }
BCheckBox &
BCheckBox::operator=(const BCheckBox &)
{
return *this;
}