* 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 * 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);
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); BCheckBox(const char* name, const char* label,
BCheckBox(const char *name, BMessage* message, uint32 flags
const char *label, = B_WILL_DRAW | B_NAVIGABLE);
BMessage *message, BCheckBox(const char* label,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); BMessage* message = NULL);
BCheckBox(const char *label, BCheckBox(BMessage* archive);
BMessage *message = NULL);
virtual ~BCheckBox();
/* Archiving */ virtual ~BCheckBox();
BCheckBox(BMessage *archive);
static BArchivable *Instantiate(BMessage *archive);
virtual status_t Archive(BMessage *archive, bool deep = true) const;
virtual void Draw(BRect updateRect); static BArchivable* Instantiate(BMessage* archive);
virtual void AttachedToWindow(); virtual status_t Archive(BMessage* archive,
virtual void MouseDown(BPoint point); bool deep = true) const;
virtual void MessageReceived(BMessage *message); virtual void Draw(BRect updateRect);
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 BHandler *ResolveSpecifier(BMessage *message, virtual void AttachedToWindow();
int32 index, virtual void DetachedFromWindow();
BMessage *specifier, virtual void AllAttached();
int32 what, virtual void AllDetached();
const char *property);
virtual status_t GetSupportedSuites(BMessage *message);
virtual void MakeFocus(bool focused = true); virtual void FrameMoved(BPoint newLocation);
virtual void AllAttached(); virtual void FrameResized(float width, float height);
virtual void AllDetached(); 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 void MouseDown(BPoint point);
virtual BSize MaxSize(); virtual void MouseUp(BPoint point);
virtual BSize PreferredSize(); 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: private:
// FBC padding
virtual void _ReservedCheckBox1();
virtual void _ReservedCheckBox2();
virtual void _ReservedCheckBox3();
virtual void _ReservedCheckBox1(); private:
virtual void _ReservedCheckBox2(); BRect _CheckBoxFrame() const;
virtual void _ReservedCheckBox3(); BSize _ValidatePreferredSize();
BRect _CheckBoxFrame() const; private:
BSize _ValidatePreferredSize(); // 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 $
*
*/
+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. * 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,17 +39,27 @@ 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), :
fPreferredSize(), BControl(name, label, message, flags | B_WILL_DRAW | B_NAVIGABLE),
fOutlined(false) fPreferredSize(),
fOutlined(false)
{ {
} }
BCheckBox::BCheckBox(const char *label, BMessage *message) BCheckBox::BCheckBox(const char *label, BMessage *message)
: BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE), :
fPreferredSize(), BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE),
fOutlined(false) fPreferredSize(),
fOutlined(false)
{
}
BCheckBox::BCheckBox(BMessage *archive)
:
BControl(archive),
fOutlined(false)
{ {
} }
@@ -56,18 +69,14 @@ 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,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 void
BCheckBox::InvalidateLayout(bool descendants) 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::_ReservedCheckBox1() {}
void BCheckBox::_ReservedCheckBox2() {} 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;
}