* 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
+68 -101
View File
@@ -1,126 +1,93 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// 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.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef _CHECK_BOX_H
#define _CHECK_BOX_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h>
#include <Control.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
// BCheckBox class -------------------------------------------------------------
class BCheckBox : public BControl {
public:
BCheckBox(BRect frame,
const char *name,
const char *label,
BMessage *message,
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);
BCheckBox(const char *label,
BMessage *message = NULL);
virtual ~BCheckBox();
BCheckBox(BRect frame, const char* name,
const char* label, BMessage* message,
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);
BCheckBox(const char* label,
BMessage* message = NULL);
BCheckBox(BMessage* archive);
/* Archiving */
BCheckBox(BMessage *archive);
static BArchivable *Instantiate(BMessage *archive);
virtual status_t Archive(BMessage *archive, bool deep = true) const;
virtual ~BCheckBox();
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
virtual void MouseDown(BPoint point);
static BArchivable* Instantiate(BMessage* archive);
virtual status_t Archive(BMessage* archive,
bool deep = true) const;
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 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 void Draw(BRect updateRect);
virtual BHandler *ResolveSpecifier(BMessage *message,
int32 index,
BMessage *specifier,
int32 what,
const char *property);
virtual status_t GetSupportedSuites(BMessage *message);
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void AllAttached();
virtual void AllDetached();
virtual void MakeFocus(bool focused = true);
virtual void AllAttached();
virtual void AllDetached();
virtual void FrameMoved(BPoint newLocation);
virtual void FrameResized(float width, float height);
virtual void WindowActivated(bool active);
virtual status_t Perform(perform_code d, void *arg);
virtual void MessageReceived(BMessage* message);
virtual void InvalidateLayout(bool descendants = false);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual BSize MinSize();
virtual BSize MaxSize();
virtual BSize PreferredSize();
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 BSize MinSize();
virtual BSize MaxSize();
virtual BSize PreferredSize();
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 _ReservedCheckBox2();
virtual void _ReservedCheckBox3();
virtual void _ReservedCheckBox1();
virtual void _ReservedCheckBox2();
virtual void _ReservedCheckBox3();
private:
BRect _CheckBoxFrame() const;
BSize _ValidatePreferredSize();
BRect _CheckBoxFrame() const;
BSize _ValidatePreferredSize();
private:
// Forbidden
BCheckBox& operator=(const BCheckBox&);
BCheckBox &operator=(const BCheckBox &);
BSize fPreferredSize;
bool fOutlined;
private:
BSize fPreferredSize;
bool fOutlined;
};
//------------------------------------------------------------------------------
#endif // _CHECK_BOX_H
/*
* $Log $
*
* $Id $
*
*/
+198 -173
View File
@@ -1,9 +1,10 @@
/*
* Copyright 2001-2007, Haiku Inc.
* Copyright 2001-2009, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marc Flerackers ([email protected])
* Stephan Aßmus <[email protected]>
*/
/*! BCheckBox displays an on/off control. */
@@ -11,6 +12,8 @@
#include <CheckBox.h>
#include <new>
#include <ControlLook.h>
#include <LayoutUtils.h>
#include <Window.h>
@@ -36,17 +39,27 @@ BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
BCheckBox::BCheckBox(const char *name, const char *label, BMessage *message,
uint32 flags)
: BControl(name, label, message, flags | B_WILL_DRAW | B_NAVIGABLE),
fPreferredSize(),
fOutlined(false)
:
BControl(name, label, message, flags | B_WILL_DRAW | B_NAVIGABLE),
fPreferredSize(),
fOutlined(false)
{
}
BCheckBox::BCheckBox(const char *label, BMessage *message)
: BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE),
fPreferredSize(),
fOutlined(false)
:
BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE),
fPreferredSize(),
fOutlined(false)
{
}
BCheckBox::BCheckBox(BMessage *archive)
:
BControl(archive),
fOutlined(false)
{
}
@@ -56,18 +69,14 @@ BCheckBox::~BCheckBox()
}
BCheckBox::BCheckBox(BMessage *archive)
: BControl(archive),
fOutlined(false)
{
}
// #pragma mark -
BArchivable *
BCheckBox::Instantiate(BMessage *archive)
{
if (validate_instantiation(archive, "BCheckBox"))
return new BCheckBox(archive);
return new(std::nothrow) BCheckBox(archive);
return NULL;
}
@@ -80,6 +89,9 @@ BCheckBox::Archive(BMessage *archive, bool deep) const
}
// #pragma mark -
void
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
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
BCheckBox::MouseUp(BPoint point)
{
@@ -359,24 +409,7 @@ BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
}
void
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());
}
}
// #pragma mark -
void
@@ -406,120 +439,6 @@ BCheckBox::ResizeToPreferred()
}
status_t
BCheckBox::Invoke(BMessage *message)
{
return BControl::Invoke(message);
}
void
BCheckBox::FrameMoved(BPoint newLocation)
{
BControl::FrameMoved(newLocation);
}
void
BCheckBox::FrameResized(float width, float height)
{
BControl::FrameResized(width, height);
}
BHandler *
BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, const char *property)
{
return BControl::ResolveSpecifier(message, index, specifier, what,
property);
}
status_t
BCheckBox::GetSupportedSuites(BMessage *message)
{
return BControl::GetSupportedSuites(message);
}
void
BCheckBox::MakeFocus(bool focused)
{
BControl::MakeFocus(focused);
}
void
BCheckBox::AllAttached()
{
BControl::AllAttached();
}
void
BCheckBox::AllDetached()
{
BControl::AllDetached();
}
status_t
BCheckBox::Perform(perform_code code, void* _data)
{
switch (code) {
case PERFORM_CODE_MIN_SIZE:
((perform_data_min_size*)_data)->return_value
= BCheckBox::MinSize();
return B_OK;
case PERFORM_CODE_MAX_SIZE:
((perform_data_max_size*)_data)->return_value
= BCheckBox::MaxSize();
return B_OK;
case PERFORM_CODE_PREFERRED_SIZE:
((perform_data_preferred_size*)_data)->return_value
= BCheckBox::PreferredSize();
return B_OK;
case PERFORM_CODE_LAYOUT_ALIGNMENT:
((perform_data_layout_alignment*)_data)->return_value
= BCheckBox::LayoutAlignment();
return B_OK;
case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
((perform_data_has_height_for_width*)_data)->return_value
= BCheckBox::HasHeightForWidth();
return B_OK;
case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
{
perform_data_get_height_for_width* data
= (perform_data_get_height_for_width*)_data;
BCheckBox::GetHeightForWidth(data->width, &data->min, &data->max,
&data->preferred);
return B_OK;
}
case PERFORM_CODE_SET_LAYOUT:
{
perform_data_set_layout* data = (perform_data_set_layout*)_data;
BCheckBox::SetLayout(data->layout);
return B_OK;
}
case PERFORM_CODE_INVALIDATE_LAYOUT:
{
perform_data_invalidate_layout* data
= (perform_data_invalidate_layout*)_data;
BCheckBox::InvalidateLayout(data->descendants);
return B_OK;
}
case PERFORM_CODE_DO_LAYOUT:
{
BCheckBox::DoLayout();
return B_OK;
}
}
return BControl::Perform(code, _data);
}
void
BCheckBox::InvalidateLayout(bool descendants)
{
@@ -554,18 +473,116 @@ BCheckBox::PreferredSize()
}
// #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
BCheckBox::Invoke(BMessage *message)
{
return BControl::Invoke(message);
}
BHandler *
BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, const char *property)
{
return BControl::ResolveSpecifier(message, index, specifier, what,
property);
}
status_t
BCheckBox::GetSupportedSuites(BMessage *message)
{
return BControl::GetSupportedSuites(message);
}
status_t
BCheckBox::Perform(perform_code code, void* _data)
{
switch (code) {
case PERFORM_CODE_MIN_SIZE:
((perform_data_min_size*)_data)->return_value
= BCheckBox::MinSize();
return B_OK;
case PERFORM_CODE_MAX_SIZE:
((perform_data_max_size*)_data)->return_value
= BCheckBox::MaxSize();
return B_OK;
case PERFORM_CODE_PREFERRED_SIZE:
((perform_data_preferred_size*)_data)->return_value
= BCheckBox::PreferredSize();
return B_OK;
case PERFORM_CODE_LAYOUT_ALIGNMENT:
((perform_data_layout_alignment*)_data)->return_value
= BCheckBox::LayoutAlignment();
return B_OK;
case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
((perform_data_has_height_for_width*)_data)->return_value
= BCheckBox::HasHeightForWidth();
return B_OK;
case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
{
perform_data_get_height_for_width* data
= (perform_data_get_height_for_width*)_data;
BCheckBox::GetHeightForWidth(data->width, &data->min, &data->max,
&data->preferred);
return B_OK;
}
case PERFORM_CODE_SET_LAYOUT:
{
perform_data_set_layout* data = (perform_data_set_layout*)_data;
BCheckBox::SetLayout(data->layout);
return B_OK;
}
case PERFORM_CODE_INVALIDATE_LAYOUT:
{
perform_data_invalidate_layout* data
= (perform_data_invalidate_layout*)_data;
BCheckBox::InvalidateLayout(data->descendants);
return B_OK;
}
case PERFORM_CODE_DO_LAYOUT:
{
BCheckBox::DoLayout();
return B_OK;
}
}
return BControl::Perform(code, _data);
}
// #pragma mark - FBC padding
void BCheckBox::_ReservedCheckBox1() {}
void BCheckBox::_ReservedCheckBox2() {}
void BCheckBox::_ReservedCheckBox3() {}
BCheckBox &
BCheckBox::operator=(const BCheckBox &)
{
return *this;
}
BRect
BCheckBox::_CheckBoxFrame() const
{
@@ -597,3 +614,11 @@ BCheckBox::_ValidatePreferredSize()
return fPreferredSize;
}
BCheckBox &
BCheckBox::operator=(const BCheckBox &)
{
return *this;
}