BitmapButton.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 /
00003 /   File:           BitmapButton.h
00004 /
00005 /   Description:    Experimental class for a BButton control whose image
00006 /                   is taken from a BBitmap.
00007 /
00008 /   Copyright 2000, Be Incorporated, All Rights Reserved
00009 /
00010 *******************************************************************************/
00011 
00012 
00013 #ifndef _BITMAP_BUTTON_H
00014 #define _BITMAP_BUTTON_H
00015 
00016 #include <Button.h>
00017 #include <Bitmap.h>
00018 
00019 namespace BExperimental {
00020 
00021 class BBitmapButton : public BButton
00022 {
00023 public:
00024     // Create a new bitmap button.  The given bitmaps must exist for
00025     // the entire time this control exists; they will not be deallocated
00026     // when it is destroyed.  If no bitmaps are supplied, this control
00027     // will look like a normal BButton.  If the 'bmNormal' bitmap is
00028     // supplied and one or more of the other bitmaps are not, the image
00029     // for the missing bitmaps will automatically be generated by the
00030     // control.
00031     //
00032     // NOTE: Automatic bitmap generation only works for 32-bit source
00033     // bitmaps.
00034     
00035     BBitmapButton(BRect frame, const char* name,
00036                   const char* label,
00037                   BMessage* message,
00038                   const BBitmap* bmNormal = NULL,
00039                   const BBitmap* bmOver = NULL,
00040                   const BBitmap* bmPressed = NULL,
00041                   const BBitmap* bmDisabled = NULL,
00042                   const BBitmap* bmDisabledPressed = NULL,
00043                   uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP);
00044     virtual ~BBitmapButton();
00045 
00046     virtual void AttachedToWindow();
00047     virtual void MouseDown(BPoint where);
00048     virtual void MouseMoved(BPoint where, uint32 transit, const BMessage *drag);
00049     virtual void MouseUp(BPoint where);
00050     virtual void Draw(BRect updateRect);
00051     virtual void GetPreferredSize(float* width, float* height);
00052 
00053     virtual void MakeFocus(bool focusState = true);
00054     virtual void SetValue(int32 value);
00055     virtual void SetEnabled(bool on);
00056     virtual status_t Invoke(BMessage *msg = NULL);
00057     
00058     // Return the bitmap for the corresponding state.  If 'create'
00059     // is true, a bitmap will be generated if possible and a specific
00060     // one wasn't supplied.
00061     
00062     const BBitmap* NormalBitmap(bool create=true) const;
00063     const BBitmap* OverBitmap(bool create=true) const;
00064     const BBitmap* PressedBitmap(bool create=true) const;
00065     const BBitmap* DisabledBitmap(bool create=true) const;
00066     const BBitmap* DisabledPressedBitmap(bool create=true) const;
00067     
00068     void SetNormalBitmap(const BBitmap* bmap);
00069     void SetOverBitmap(const BBitmap* bmap);
00070     void SetPressedBitmap(const BBitmap* bmap);
00071     void SetDisabledBitmap(const BBitmap* bmap);
00072     void SetDisabledPressedBitmap(const BBitmap* bmap);
00073     
00074     // Set location of textual label around the drawn bitmap.
00075     // This is only used if the bmNormal bitmap is supplied as
00076     // well as a textual label for the control.
00077     
00078     enum label_position {
00079         LABEL_LEFT = 0,
00080         LABEL_TOP,
00081         LABEL_RIGHT,
00082         LABEL_BOTTOM
00083     };
00084     
00085     void SetLabelPosition(label_position pos);
00086     label_position LabelPosition() const;
00087     
00088 private:
00089     typedef BButton inherited;
00090     
00091     const BBitmap* RawBitmap() const;
00092     
00093     const BBitmap* fRawBitmap;
00094     const BBitmap* fNormalBitmap;
00095     const BBitmap* fOverBitmap;
00096     const BBitmap* fPressedBitmap;
00097     const BBitmap* fDisabledBitmap;
00098     const BBitmap* fDisabledPressedBitmap;
00099     
00100     bool fMadeNormal;
00101     bool fMadeOver;
00102     bool fMadePressed;
00103     bool fMadeDisabled;
00104     bool fMadeDisabledPressed;
00105     
00106     label_position fLabelPosition;
00107     
00108     bool fMousePressed;
00109     bool fMouseOver;
00110     
00111     bool fSettingValue;
00112 };
00113 
00114 }
00115 
00116 #endif

Copyright 2005 by yellowTAB GmbH, Be Inc., Palm Source Inc. and their respective legal successors
All rights reserved.