/*
 * pawsbutton.h - Author: Andrew Craig
 *
 * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation (version 2 of the License)
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
// pawsbutton.h: interface for the pawsButton class.
//
//////////////////////////////////////////////////////////////////////

#ifndef PAWS_BUTTON_HEADER
#define PAWS_BUTTON_HEADER

#include "pawswidget.h"



/** A simple button widget.
 */
class pawsButton : public pawsWidget
{
public:
    pawsButton();
    virtual ~pawsButton();

    virtual bool Setup( iDocumentNode* node );
    bool SelfPopulate( iDocumentNode *node);
    
    void SetUpImage(const csString & image);
    void SetDownImage(const csString & image);

    void SetSound(const csString & sound);

    virtual void Draw();

    virtual bool OnMouseDown( int button, int modifiers, int x, int y );
    virtual bool OnMouseUp( int button, int modifiers, int x, int y );
    virtual bool OnKeyDown( int keyCode, int key, int modifiers );

    virtual bool IsDown()  { return down; }
    virtual void SetState  ( bool isDown ) { down = isDown; }
    virtual bool GetState  () { return down; }
    /// Set the toggle attribute. To change toggle state use SetState
    virtual void SetToggle ( bool t )      { toggle = t; }
    virtual void SetNotify ( pawsWidget* widget );

    void SetText(const char* text);
    const char* GetText() { return buttonLabel; }

    virtual void Flash ( bool state ) { if (state && !down) flash = 1; else flash = 0; }
protected:

    virtual bool CheckKeyHandled(int keyCode);

    /// Track to see if the button is down.
    bool down;

    /// Image to draw when button is pressed.
    pawsImage* pressedImage;

    /// Image to draw when button is released.
    pawsImage* releasedImage;

    /// Check to see if this is a toggle button.
    bool toggle;

    /// Text shown in button
    csString buttonLabel;

    /// Keyboard equivalent of clicking on this button
    char keybinding;

    /// Widget to which event notifications are sent. If NULL, notifications go to parent
    pawsWidget* notify;

    /// Style -- right now only ShadowText supported
    int style;

    /// The state if the button is flashing, 0 is no flashing
    int flash;

	/// Button can trigger sound effects with this
    csRef<iSndSysData> sound_click;
};

//----------------------------------------------------------------------
CREATE_PAWS_FACTORY( pawsButton );

#endif 
