* cleanup

* use std::nothrow



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28886 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2009-01-11 19:06:45 +00:00
parent b47e734742
commit 168353694e
2 changed files with 118 additions and 173 deletions
+72 -119
View File
@@ -1,151 +1,104 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2008, Haiku, Inc.
// * 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"), * Authors:
// to deal in the Software without restriction, including without limitation * Graham MacDonald ([email protected])
// 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: PictureButton.h
// Author: Graham MacDonald ([email protected])
// Description: BPictureButton displays and controls a picture button in a
// window.
//------------------------------------------------------------------------------
#ifndef _PICTURE_BUTTON_H #ifndef _PICTURE_BUTTON_H
#define _PICTURE_BUTTON_H #define _PICTURE_BUTTON_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h> #include <BeBuild.h>
#include <Control.h> #include <Control.h>
#include <Picture.h> /* For convenience */ #include <Picture.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
enum { enum {
B_ONE_STATE_BUTTON, B_ONE_STATE_BUTTON,
B_TWO_STATE_BUTTON B_TWO_STATE_BUTTON
}; };
// BPictureButton class --------------------------------------------------------
class BPictureButton : public BControl class BPictureButton : public BControl
{ {
public: public:
BPictureButton (BRect frame, BPictureButton(BRect frame, const char* name, BPicture* off,
const char* name, BPicture* on, BMessage* message,
BPicture *off, uint32 behavior = B_ONE_STATE_BUTTON,
BPicture *on, uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
BMessage *message, uint32 flgs = B_WILL_DRAW | B_NAVIGABLE);
uint32 behavior = B_ONE_STATE_BUTTON, BPictureButton(BMessage* data);
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flgs = B_WILL_DRAW | B_NAVIGABLE);
BPictureButton (BMessage *data);
virtual ~BPictureButton ();
virtual ~BPictureButton();
static BArchivable *Instantiate (BMessage *data);
virtual status_t Archive (BMessage *data, bool deep = true) const;
virtual void Draw (BRect updateRect);
virtual void MouseDown (BPoint point);
virtual void KeyDown (const char *bytes, int32 numBytes);
virtual void SetEnabledOn (BPicture *on);
virtual void SetEnabledOff (BPicture *off);
virtual void SetDisabledOn (BPicture *on);
virtual void SetDisabledOff (BPicture *off);
BPicture *EnabledOn () const;
BPicture *EnabledOff () const;
BPicture *DisabledOn () const;
BPicture *DisabledOff () const;
virtual void SetBehavior (uint32 behavior);
uint32 Behavior () const;
virtual void MessageReceived (BMessage *msg);
virtual void MouseUp (BPoint point);
virtual void WindowActivated (bool state);
virtual void MouseMoved (BPoint pt, uint32 code, const BMessage *msg);
virtual void AttachedToWindow ();
virtual void DetachedFromWindow ();
virtual void SetValue (int32 value);
virtual status_t Invoke (BMessage *msg = NULL);
virtual void FrameMoved (BPoint new_position);
virtual void FrameResized (float new_width, float new_height);
virtual BHandler *ResolveSpecifier (BMessage *msg,
int32 index,
BMessage *specifier,
int32 form,
const char *property);
virtual status_t GetSupportedSuites (BMessage *data);
virtual void ResizeToPreferred ();
virtual void GetPreferredSize (float *width, float *height);
virtual void MakeFocus (bool state = true);
virtual void AllAttached ();
virtual void AllDetached ();
// Private or reserved ----------------------------------------------------- static BArchivable* Instantiate(BMessage* data);
virtual status_t Perform (perform_code d, void *arg); virtual status_t Archive(BMessage* data, bool deep = true) const;
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void SetEnabledOn(BPicture* on);
virtual void SetEnabledOff(BPicture* off);
virtual void SetDisabledOn(BPicture* on);
virtual void SetDisabledOff(BPicture* off);
BPicture* EnabledOn() const;
BPicture* EnabledOff() const;
BPicture* DisabledOn() const;
BPicture* DisabledOff() const;
virtual void SetBehavior(uint32 behavior);
uint32 Behavior() const;
virtual void MessageReceived(BMessage* message);
virtual void MouseUp(BPoint point);
virtual void WindowActivated(bool state);
virtual void MouseMoved(BPoint pt, uint32 code,
const BMessage* message);
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void SetValue(int32 value);
virtual status_t Invoke(BMessage* message = NULL);
virtual void FrameMoved(BPoint newPosition);
virtual void FrameResized(float newWidth, float newHeight);
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 form, const char* p);
virtual status_t GetSupportedSuites(BMessage* data);
virtual void ResizeToPreferred();
virtual void GetPreferredSize(float* width, float* height);
virtual void MakeFocus(bool state = true);
virtual void AllAttached();
virtual void AllDetached();
virtual status_t Perform(perform_code d, void* arg);
private: private:
virtual void _ReservedPictureButton1 (); virtual void _ReservedPictureButton1();
virtual void _ReservedPictureButton2 (); virtual void _ReservedPictureButton2();
virtual void _ReservedPictureButton3 (); virtual void _ReservedPictureButton3();
BPictureButton &operator= (const BPictureButton &); BPictureButton &operator=(const BPictureButton &);
void Redraw (); void _Redraw();
void InitData (); void _InitData();
BPicture *fEnabledOff; BPicture* fEnabledOff;
BPicture *fEnabledOn; BPicture* fEnabledOn;
BPicture *fDisabledOff; BPicture* fDisabledOff;
BPicture *fDisabledOn; BPicture* fDisabledOn;
bool fOutlined; bool unused;
uint32 fBehavior; uint32 fBehavior;
uint32 _reserved[4]; uint32 _reserved[4];
}; };
//------------------------------------------------------------------------------
#endif /* _PICTURE_BUTTON_H */
/*
* $Log $
*
* $Id $
*
*/
#endif
+46 -54
View File
@@ -1,34 +1,32 @@
/* /*
* Copyright 2001-2005, 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:
* Graham MacDonald ([email protected]) * Graham MacDonald ([email protected])
*/ */
/** BPictureButton displays and controls a picture button in a window. */
#include <PictureButton.h> #include <PictureButton.h>
#include <binary_compatibility/Interface.h> #include <binary_compatibility/Interface.h>
#include <new>
BPictureButton::BPictureButton(BRect frame, const char* name,
BPicture *off, BPicture *on, BMessage *message, BPictureButton::BPictureButton(BRect frame, const char* name,
BPicture* off, BPicture* on, BMessage* message,
uint32 behavior, uint32 resizeMask, uint32 flags) uint32 behavior, uint32 resizeMask, uint32 flags)
: BControl(frame, name, "", message, resizeMask, flags), : BControl(frame, name, "", message, resizeMask, flags),
fDisabledOff(NULL), fDisabledOff(NULL),
fDisabledOn(NULL), fDisabledOn(NULL),
fOutlined(false), fBehavior(behavior)
fBehavior(behavior)
{ {
fEnabledOff = new BPicture(*off); fEnabledOff = new (std::nothrow)BPicture(*off);
fEnabledOn = new BPicture(*on); fEnabledOn = new (std::nothrow) BPicture(*on);
} }
BPictureButton::BPictureButton(BMessage *data) BPictureButton::BPictureButton(BMessage* data)
: BControl(data), : BControl(data),
fEnabledOff(NULL), fEnabledOff(NULL),
fEnabledOn(NULL), fEnabledOn(NULL),
@@ -38,21 +36,21 @@ BPictureButton::BPictureButton(BMessage *data)
BMessage pictureArchive; BMessage pictureArchive;
// Default to 1 state button if not here - is this valid? // Default to 1 state button if not here - is this valid?
if (data->FindInt32 ("_behave", (int32 *)&fBehavior) != B_OK) if (data->FindInt32 ("_behave", (int32* )&fBehavior) != B_OK)
fBehavior = B_ONE_STATE_BUTTON; fBehavior = B_ONE_STATE_BUTTON;
// Now expand the pictures: // Now expand the pictures:
if (data->FindMessage("_e_on", &pictureArchive) == B_OK) if (data->FindMessage("_e_on", &pictureArchive) == B_OK)
fEnabledOn = new BPicture(&pictureArchive); fEnabledOn = new (std::nothrow) BPicture(&pictureArchive);
if (data->FindMessage("_e_off", &pictureArchive) == B_OK) if (data->FindMessage("_e_off", &pictureArchive) == B_OK)
fEnabledOff = new BPicture(&pictureArchive); fEnabledOff = new (std::nothrow) BPicture(&pictureArchive);
if (data->FindMessage("_d_on", &pictureArchive) == B_OK) if (data->FindMessage("_d_on", &pictureArchive) == B_OK)
fDisabledOn = new BPicture(&pictureArchive); fDisabledOn = new (std::nothrow) BPicture(&pictureArchive);
if (data->FindMessage("_d_off", &pictureArchive) == B_OK) if (data->FindMessage("_d_off", &pictureArchive) == B_OK)
fDisabledOff = new BPicture(&pictureArchive); fDisabledOff = new (std::nothrow) BPicture(&pictureArchive);
} }
@@ -65,18 +63,18 @@ BPictureButton::~BPictureButton()
} }
BArchivable * BArchivable*
BPictureButton::Instantiate(BMessage *data) BPictureButton::Instantiate(BMessage* data)
{ {
if ( validate_instantiation(data, "BPictureButton")) if ( validate_instantiation(data, "BPictureButton"))
return new BPictureButton(data); return new (std::nothrow) BPictureButton(data);
return NULL; return NULL;
} }
status_t status_t
BPictureButton::Archive(BMessage *data, bool deep) const BPictureButton::Archive(BMessage* data, bool deep) const
{ {
status_t err = BControl::Archive(data, deep); status_t err = BControl::Archive(data, deep);
if (err != B_OK) if (err != B_OK)
@@ -118,22 +116,17 @@ BPictureButton::Archive(BMessage *data, bool deep) const
void void
BPictureButton::Draw(BRect updateRect) BPictureButton::Draw(BRect updateRect)
{ {
BRect rect = Bounds();
// We should request the view's base color which normaly is (216,216,216)
rgb_color color = ui_color(B_PANEL_BACKGROUND_COLOR);
if (IsEnabled()) { if (IsEnabled()) {
if (Value() == B_CONTROL_ON) if (Value() == B_CONTROL_ON)
DrawPicture(fEnabledOn); DrawPicture(fEnabledOn);
else else
DrawPicture(fEnabledOff); DrawPicture(fEnabledOff);
} else { } else {
if (fDisabledOff == NULL if (fDisabledOff == NULL
|| (fDisabledOn == NULL && fBehavior == B_TWO_STATE_BUTTON)) || (fDisabledOn == NULL && fBehavior == B_TWO_STATE_BUTTON))
debugger("Need to set the 'disabled' pictures for this BPictureButton "); debugger("Need to set the 'disabled' pictures for this BPictureButton ");
if (Value() == B_CONTROL_ON) if (Value() == B_CONTROL_ON)
DrawPicture(fDisabledOn); DrawPicture(fDisabledOn);
else else
@@ -142,7 +135,7 @@ BPictureButton::Draw(BRect updateRect)
if (IsFocus()) { if (IsFocus()) {
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeRect(rect, B_SOLID_HIGH); StrokeRect(Bounds(), B_SOLID_HIGH);
} }
} }
@@ -190,7 +183,7 @@ BPictureButton::MouseUp(BPoint point)
void void
BPictureButton::MouseMoved(BPoint point, uint32 transit, const BMessage *msg) BPictureButton::MouseMoved(BPoint point, uint32 transit, const BMessage* msg)
{ {
if (IsEnabled() && IsTracking()) { if (IsEnabled() && IsTracking()) {
if (transit == B_EXITED_VIEW) if (transit == B_EXITED_VIEW)
@@ -203,7 +196,7 @@ BPictureButton::MouseMoved(BPoint point, uint32 transit, const BMessage *msg)
void void
BPictureButton::KeyDown(const char *bytes, int32 numBytes) BPictureButton::KeyDown(const char* bytes, int32 numBytes)
{ {
if (numBytes == 1) { if (numBytes == 1) {
switch (bytes[0]) { switch (bytes[0]) {
@@ -229,59 +222,59 @@ BPictureButton::KeyDown(const char *bytes, int32 numBytes)
void void
BPictureButton::SetEnabledOn(BPicture *on) BPictureButton::SetEnabledOn(BPicture* on)
{ {
delete fEnabledOn; delete fEnabledOn;
fEnabledOn = new BPicture(*on); fEnabledOn = new (std::nothrow) BPicture(*on);
} }
void void
BPictureButton::SetEnabledOff(BPicture *off) BPictureButton::SetEnabledOff(BPicture* off)
{ {
delete fEnabledOff; delete fEnabledOff;
fEnabledOff = new BPicture(*off); fEnabledOff = new (std::nothrow) BPicture(*off);
} }
void void
BPictureButton::SetDisabledOn(BPicture *on) BPictureButton::SetDisabledOn(BPicture* on)
{ {
delete fDisabledOn; delete fDisabledOn;
fDisabledOn = new BPicture(*on); fDisabledOn = new (std::nothrow) BPicture(*on);
} }
void void
BPictureButton::SetDisabledOff(BPicture *off) BPictureButton::SetDisabledOff(BPicture* off)
{ {
delete fDisabledOff; delete fDisabledOff;
fDisabledOff = new BPicture(*off); fDisabledOff = new (std::nothrow) BPicture(*off);
} }
BPicture * BPicture*
BPictureButton::EnabledOn() const BPictureButton::EnabledOn() const
{ {
return fEnabledOn; return fEnabledOn;
} }
BPicture * BPicture*
BPictureButton::EnabledOff() const BPictureButton::EnabledOff() const
{ {
return fEnabledOff; return fEnabledOff;
} }
BPicture * BPicture*
BPictureButton::DisabledOn() const BPictureButton::DisabledOn() const
{ {
return fDisabledOn; return fDisabledOn;
} }
BPicture * BPicture*
BPictureButton::DisabledOff() const BPictureButton::DisabledOff() const
{ {
return fDisabledOff; return fDisabledOff;
@@ -303,7 +296,7 @@ BPictureButton::Behavior() const
void void
BPictureButton::MessageReceived(BMessage *msg) BPictureButton::MessageReceived(BMessage* msg)
{ {
BControl::MessageReceived(msg); BControl::MessageReceived(msg);
} }
@@ -338,7 +331,7 @@ BPictureButton::SetValue(int32 value)
status_t status_t
BPictureButton::Invoke(BMessage *msg) BPictureButton::Invoke(BMessage* msg)
{ {
return BControl::Invoke(msg); return BControl::Invoke(msg);
} }
@@ -358,16 +351,16 @@ BPictureButton::FrameResized(float newWidth, float newHeight)
} }
BHandler * BHandler*
BPictureButton::ResolveSpecifier(BMessage *msg, int32 index, BPictureButton::ResolveSpecifier(BMessage* msg, int32 index,
BMessage *specifier, int32 form, const char *property) BMessage* specifier, int32 form, const char* property)
{ {
return BControl::ResolveSpecifier(msg, index, specifier, form, property); return BControl::ResolveSpecifier(msg, index, specifier, form, property);
} }
status_t status_t
BPictureButton::GetSupportedSuites(BMessage *data) BPictureButton::GetSupportedSuites(BMessage* data)
{ {
return BControl::GetSupportedSuites(data); return BControl::GetSupportedSuites(data);
} }
@@ -383,7 +376,6 @@ BPictureButton::ResizeToPreferred()
void void
BPictureButton::GetPreferredSize(float* _width, float* _height) BPictureButton::GetPreferredSize(float* _width, float* _height)
{ {
// Need to do some test to see what the Be method returns...
BControl::GetPreferredSize(_width, _height); BControl::GetPreferredSize(_width, _height);
} }
@@ -470,7 +462,7 @@ void BPictureButton::_ReservedPictureButton2() {}
void BPictureButton::_ReservedPictureButton3() {} void BPictureButton::_ReservedPictureButton3() {}
BPictureButton & BPictureButton&
BPictureButton::operator=(const BPictureButton &button) BPictureButton::operator=(const BPictureButton &button)
{ {
return *this; return *this;
@@ -478,13 +470,13 @@ BPictureButton::operator=(const BPictureButton &button)
void void
BPictureButton::Redraw() BPictureButton::_Redraw()
{ {
} }
void void
BPictureButton::InitData() BPictureButton::_InitData()
{ {
} }