wxBitmapButton added (doesn't work yet)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8190 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,20 +1,94 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/bmpbutton.h
|
||||||
|
// Purpose: wxBitmapButton class interface
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// Modified by:
|
||||||
|
// Created: 25.08.00
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 2000 Vadim Zeitlin
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_BMPBUTTON_H_BASE_
|
#ifndef _WX_BMPBUTTON_H_BASE_
|
||||||
#define _WX_BMPBUTTON_H_BASE_
|
#define _WX_BMPBUTTON_H_BASE_
|
||||||
|
|
||||||
#if defined(__WXMSW__)
|
#if wxUSE_BMPBUTTON
|
||||||
#include "wx/msw/bmpbuttn.h"
|
|
||||||
|
#include "wx/bitmap.h"
|
||||||
|
#include "wx/button.h"
|
||||||
|
|
||||||
|
WXDLLEXPORT_DATA(extern const wxChar*) wxButtonNameStr;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxBitmapButton: a button which shows bitmaps instead of the usual string.
|
||||||
|
// It has different bitmaps for different states (focused/disabled/pressed)
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxBitmapButtonBase : public wxButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxBitmapButtonBase() { m_marginX = m_marginY = 0; }
|
||||||
|
|
||||||
|
// set the bitmaps
|
||||||
|
void SetBitmapLabel(const wxBitmap& bitmap)
|
||||||
|
{ m_bmpNormal = bitmap; OnSetBitmap(); }
|
||||||
|
void SetBitmapSelected(const wxBitmap& sel)
|
||||||
|
{ m_bmpSelected = sel; OnSetBitmap(); };
|
||||||
|
void SetBitmapFocus(const wxBitmap& focus)
|
||||||
|
{ m_bmpFocus = focus; OnSetBitmap(); };
|
||||||
|
void SetBitmapDisabled(const wxBitmap& disabled)
|
||||||
|
{ m_bmpDisabled = disabled; OnSetBitmap(); };
|
||||||
|
void SetLabel(const wxBitmap& bitmap)
|
||||||
|
{ SetBitmapLabel(bitmap); }
|
||||||
|
|
||||||
|
// retrieve the bitmaps
|
||||||
|
const wxBitmap& GetBitmapLabel() const { return m_bmpNormal; }
|
||||||
|
const wxBitmap& GetBitmapSelected() const { return m_bmpSelected; }
|
||||||
|
const wxBitmap& GetBitmapFocus() const { return m_bmpFocus; }
|
||||||
|
const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; }
|
||||||
|
wxBitmap& GetBitmapLabel() { return m_bmpNormal; }
|
||||||
|
wxBitmap& GetBitmapSelected() { return m_bmpSelected; }
|
||||||
|
wxBitmap& GetBitmapFocus() { return m_bmpFocus; }
|
||||||
|
wxBitmap& GetBitmapDisabled() { return m_bmpDisabled; }
|
||||||
|
|
||||||
|
// set/get the margins around the button
|
||||||
|
virtual void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
|
||||||
|
int GetMarginX() const { return m_marginX; }
|
||||||
|
int GetMarginY() const { return m_marginY; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// function called when any of the bitmaps changes
|
||||||
|
virtual void OnSetBitmap() { }
|
||||||
|
|
||||||
|
// the bitmaps for various states
|
||||||
|
wxBitmap m_bmpNormal,
|
||||||
|
m_bmpSelected,
|
||||||
|
m_bmpFocus,
|
||||||
|
m_bmpDisabled;
|
||||||
|
|
||||||
|
// the margins around the bitmap
|
||||||
|
int m_marginX,
|
||||||
|
m_marginY;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__WXUNIVERSAL__)
|
||||||
|
#include "wx/univ/bmpbuttn.h"
|
||||||
|
#elif defined(__WXMSW__)
|
||||||
|
#include "wx/msw/bmpbuttn.h"
|
||||||
#elif defined(__WXMOTIF__)
|
#elif defined(__WXMOTIF__)
|
||||||
#include "wx/motif/bmpbuttn.h"
|
#include "wx/motif/bmpbuttn.h"
|
||||||
#elif defined(__WXGTK__)
|
#elif defined(__WXGTK__)
|
||||||
#include "wx/gtk/bmpbuttn.h"
|
#include "wx/gtk/bmpbuttn.h"
|
||||||
#elif defined(__WXQT__)
|
#elif defined(__WXQT__)
|
||||||
#include "wx/qt/bmpbuttn.h"
|
#include "wx/qt/bmpbuttn.h"
|
||||||
#elif defined(__WXMAC__)
|
#elif defined(__WXMAC__)
|
||||||
#include "wx/mac/bmpbuttn.h"
|
#include "wx/mac/bmpbuttn.h"
|
||||||
#elif defined(__WXPM__)
|
#elif defined(__WXPM__)
|
||||||
#include "wx/os2/bmpbuttn.h"
|
#include "wx/os2/bmpbuttn.h"
|
||||||
#elif defined(__WXSTUBS__)
|
#elif defined(__WXSTUBS__)
|
||||||
#include "wx/stubs/bmpbuttn.h"
|
#include "wx/stubs/bmpbuttn.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif // wxUSE_BMPBUTTON
|
||||||
|
|
||||||
|
#endif // _WX_BMPBUTTON_H_BASE_
|
||||||
|
@@ -30,6 +30,9 @@ public:
|
|||||||
// show the image in the button in addition to the label
|
// show the image in the button in addition to the label
|
||||||
virtual void SetImageLabel(const wxBitmap& bitmap) { }
|
virtual void SetImageLabel(const wxBitmap& bitmap) { }
|
||||||
|
|
||||||
|
// set the margins around the image
|
||||||
|
virtual void SetImageMargins(wxCoord x, wxCoord y) { }
|
||||||
|
|
||||||
// this wxButton method is called when the button becomes the default one
|
// this wxButton method is called when the button becomes the default one
|
||||||
// on its panel
|
// on its panel
|
||||||
virtual void SetDefault() { }
|
virtual void SetDefault() { }
|
||||||
|
@@ -15,71 +15,41 @@
|
|||||||
#pragma interface
|
#pragma interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/defs.h"
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_BMPBUTTON
|
|
||||||
|
|
||||||
#include "wx/object.h"
|
|
||||||
#include "wx/list.h"
|
|
||||||
#include "wx/control.h"
|
|
||||||
#include "wx/bitmap.h"
|
|
||||||
#include "wx/button.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// classes
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class wxBitmapButton;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// global data
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern const wxChar *wxButtonNameStr;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// wxBitmapButton
|
// wxBitmapButton
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxBitmapButton: public wxButton
|
class wxBitmapButton: public wxBitmapButtonBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxBitmapButton();
|
wxBitmapButton();
|
||||||
inline wxBitmapButton( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
|
wxBitmapButton(wxWindow *parent,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxWindowID id,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW,
|
const wxBitmap& bitmap,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxString& name = wxButtonNameStr )
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxBU_AUTODRAW,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr)
|
||||||
{
|
{
|
||||||
Create(parent, id, bitmap, pos, size, style, validator, name);
|
Create(parent, id, bitmap, pos, size, style, validator, name);
|
||||||
}
|
}
|
||||||
bool Create( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
|
bool Create(wxWindow *parent,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxWindowID id,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW,
|
const wxBitmap& bitmap,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxString& name = wxButtonNameStr);
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxBU_AUTODRAW,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr);
|
||||||
|
|
||||||
virtual void SetDefault();
|
virtual void SetDefault();
|
||||||
|
virtual bool Enable(bool enable = TRUE);
|
||||||
|
|
||||||
void SetLabel( const wxString &label );
|
void SetLabel( const wxString &label );
|
||||||
wxString GetLabel() const;
|
wxString GetLabel() const;
|
||||||
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); }
|
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); }
|
||||||
|
|
||||||
wxBitmap& GetBitmapDisabled() const { return (wxBitmap&) m_disabled; }
|
|
||||||
wxBitmap& GetBitmapFocus() const { return (wxBitmap&) m_focus; }
|
|
||||||
wxBitmap& GetBitmapLabel() const { return (wxBitmap&) m_bitmap; }
|
|
||||||
wxBitmap& GetBitmapSelected() const { return (wxBitmap&) m_selected; }
|
|
||||||
|
|
||||||
void SetBitmapDisabled( const wxBitmap& bitmap );
|
|
||||||
void SetBitmapFocus( const wxBitmap& bitmap );
|
|
||||||
void SetBitmapLabel( const wxBitmap& bitmap );
|
|
||||||
void SetBitmapSelected( const wxBitmap& bitmap );
|
|
||||||
|
|
||||||
void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
|
|
||||||
int GetMarginX() const { return m_marginX; }
|
|
||||||
int GetMarginY() const { return m_marginY; }
|
|
||||||
|
|
||||||
virtual bool Enable(bool enable);
|
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
@@ -92,19 +62,12 @@ public:
|
|||||||
|
|
||||||
bool m_hasFocus;
|
bool m_hasFocus;
|
||||||
bool m_isSelected;
|
bool m_isSelected;
|
||||||
wxBitmap m_bitmap;
|
|
||||||
wxBitmap m_disabled;
|
|
||||||
wxBitmap m_focus;
|
|
||||||
wxBitmap m_selected;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_marginX;
|
virtual void OnSetBitmap();
|
||||||
int m_marginY;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __BMPBUTTONH__
|
#endif // __BMPBUTTONH__
|
||||||
|
@@ -15,71 +15,41 @@
|
|||||||
#pragma interface
|
#pragma interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/defs.h"
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_BMPBUTTON
|
|
||||||
|
|
||||||
#include "wx/object.h"
|
|
||||||
#include "wx/list.h"
|
|
||||||
#include "wx/control.h"
|
|
||||||
#include "wx/bitmap.h"
|
|
||||||
#include "wx/button.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// classes
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class wxBitmapButton;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// global data
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern const wxChar *wxButtonNameStr;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// wxBitmapButton
|
// wxBitmapButton
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxBitmapButton: public wxButton
|
class wxBitmapButton: public wxBitmapButtonBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxBitmapButton();
|
wxBitmapButton();
|
||||||
inline wxBitmapButton( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
|
wxBitmapButton(wxWindow *parent,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxWindowID id,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW,
|
const wxBitmap& bitmap,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxString& name = wxButtonNameStr )
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxBU_AUTODRAW,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr)
|
||||||
{
|
{
|
||||||
Create(parent, id, bitmap, pos, size, style, validator, name);
|
Create(parent, id, bitmap, pos, size, style, validator, name);
|
||||||
}
|
}
|
||||||
bool Create( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
|
bool Create(wxWindow *parent,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxWindowID id,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW,
|
const wxBitmap& bitmap,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxString& name = wxButtonNameStr);
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxBU_AUTODRAW,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr);
|
||||||
|
|
||||||
virtual void SetDefault();
|
virtual void SetDefault();
|
||||||
|
virtual bool Enable(bool enable = TRUE);
|
||||||
|
|
||||||
void SetLabel( const wxString &label );
|
void SetLabel( const wxString &label );
|
||||||
wxString GetLabel() const;
|
wxString GetLabel() const;
|
||||||
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); }
|
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); }
|
||||||
|
|
||||||
wxBitmap& GetBitmapDisabled() const { return (wxBitmap&) m_disabled; }
|
|
||||||
wxBitmap& GetBitmapFocus() const { return (wxBitmap&) m_focus; }
|
|
||||||
wxBitmap& GetBitmapLabel() const { return (wxBitmap&) m_bitmap; }
|
|
||||||
wxBitmap& GetBitmapSelected() const { return (wxBitmap&) m_selected; }
|
|
||||||
|
|
||||||
void SetBitmapDisabled( const wxBitmap& bitmap );
|
|
||||||
void SetBitmapFocus( const wxBitmap& bitmap );
|
|
||||||
void SetBitmapLabel( const wxBitmap& bitmap );
|
|
||||||
void SetBitmapSelected( const wxBitmap& bitmap );
|
|
||||||
|
|
||||||
void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
|
|
||||||
int GetMarginX() const { return m_marginX; }
|
|
||||||
int GetMarginY() const { return m_marginY; }
|
|
||||||
|
|
||||||
virtual bool Enable(bool enable);
|
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
@@ -92,19 +62,12 @@ public:
|
|||||||
|
|
||||||
bool m_hasFocus;
|
bool m_hasFocus;
|
||||||
bool m_isSelected;
|
bool m_isSelected;
|
||||||
wxBitmap m_bitmap;
|
|
||||||
wxBitmap m_disabled;
|
|
||||||
wxBitmap m_focus;
|
|
||||||
wxBitmap m_selected;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_marginX;
|
virtual void OnSetBitmap();
|
||||||
int m_marginY;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __BMPBUTTONH__
|
#endif // __BMPBUTTONH__
|
||||||
|
@@ -16,60 +16,41 @@
|
|||||||
#pragma interface "bmpbuttn.h"
|
#pragma interface "bmpbuttn.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_BMPBUTTON
|
|
||||||
|
|
||||||
#include "wx/button.h"
|
#include "wx/button.h"
|
||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
|
|
||||||
WXDLLEXPORT_DATA(extern const wxChar*) wxButtonNameStr;
|
|
||||||
|
|
||||||
#define wxDEFAULT_BUTTON_MARGIN 4
|
#define wxDEFAULT_BUTTON_MARGIN 4
|
||||||
|
|
||||||
class WXDLLEXPORT wxBitmapButton: public wxButton
|
class WXDLLEXPORT wxBitmapButton: public wxBitmapButtonBase
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxBitmapButton() { m_marginX = wxDEFAULT_BUTTON_MARGIN; m_marginY = wxDEFAULT_BUTTON_MARGIN; }
|
wxBitmapButton()
|
||||||
wxBitmapButton(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
|
{ m_marginX = m_marginY = wxDEFAULT_BUTTON_MARGIN; }
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxBitmapButton(wxWindow *parent,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW,
|
wxWindowID id,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxBitmap& bitmap,
|
||||||
const wxString& name = wxButtonNameStr)
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxBU_AUTODRAW,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr)
|
||||||
{
|
{
|
||||||
Create(parent, id, bitmap, pos, size, style, validator, name);
|
Create(parent, id, bitmap, pos, size, style, validator, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
|
bool Create(wxWindow *parent,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxWindowID id,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW,
|
const wxBitmap& bitmap,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxString& name = wxButtonNameStr);
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxBU_AUTODRAW,
|
||||||
virtual void SetLabel(const wxBitmap& bitmap)
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
{
|
const wxString& name = wxButtonNameStr);
|
||||||
SetBitmapLabel(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void SetBitmapLabel(const wxBitmap& bitmap);
|
|
||||||
|
|
||||||
#if WXWIN_COMPATIBILITY
|
#if WXWIN_COMPATIBILITY
|
||||||
wxBitmap *GetBitmap() const { return (wxBitmap *) & m_buttonBitmap; }
|
wxBitmap *GetBitmap() const { return (wxBitmap *) & m_bmp; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxBitmap& GetBitmapLabel() const { return (wxBitmap&) m_buttonBitmap; }
|
|
||||||
wxBitmap& GetBitmapSelected() const { return (wxBitmap&) m_buttonBitmapSelected; }
|
|
||||||
wxBitmap& GetBitmapFocus() const { return (wxBitmap&) m_buttonBitmapFocus; }
|
|
||||||
wxBitmap& GetBitmapDisabled() const { return (wxBitmap&) m_buttonBitmapDisabled; }
|
|
||||||
|
|
||||||
void SetBitmapSelected(const wxBitmap& sel) { m_buttonBitmapSelected = sel; };
|
|
||||||
void SetBitmapFocus(const wxBitmap& focus) { m_buttonBitmapFocus = focus; };
|
|
||||||
void SetBitmapDisabled(const wxBitmap& disabled) { m_buttonBitmapDisabled = disabled; };
|
|
||||||
|
|
||||||
void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
|
|
||||||
int GetMarginX() const { return m_marginX; }
|
|
||||||
int GetMarginY() const { return m_marginY; }
|
|
||||||
|
|
||||||
// Implementation
|
// Implementation
|
||||||
virtual void SetDefault();
|
virtual void SetDefault();
|
||||||
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
|
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
|
||||||
@@ -77,16 +58,9 @@ public:
|
|||||||
virtual void DrawButtonFocus( WXHDC dc, int left, int top, int right, int bottom, bool sel );
|
virtual void DrawButtonFocus( WXHDC dc, int left, int top, int right, int bottom, bool sel );
|
||||||
virtual void DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg );
|
virtual void DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg );
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
wxBitmap m_buttonBitmap;
|
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
||||||
wxBitmap m_buttonBitmapSelected;
|
|
||||||
wxBitmap m_buttonBitmapFocus;
|
|
||||||
wxBitmap m_buttonBitmapDisabled;
|
|
||||||
int m_marginX;
|
|
||||||
int m_marginY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_BMPBUTTON
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// _WX_BMPBUTTN_H_
|
// _WX_BMPBUTTN_H_
|
||||||
|
73
include/wx/univ/bmpbuttn.h
Normal file
73
include/wx/univ/bmpbuttn.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/univ/bmpbuttn.h
|
||||||
|
// Purpose: wxBitmapButton class for wxUniversal
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// Modified by:
|
||||||
|
// Created: 25.08.00
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Vadim Zeitlin
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_UNIV_BMPBUTTN_H_
|
||||||
|
#define _WX_UNIV_BMPBUTTN_H_
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma interface "univbmpbuttn.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxBitmapButton : public wxBitmapButtonBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxBitmapButton() { }
|
||||||
|
|
||||||
|
wxBitmapButton(wxWindow *parent,
|
||||||
|
wxWindowID id,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr)
|
||||||
|
{
|
||||||
|
Create(parent, id, bitmap, pos, size, style, validator, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Create(wxWindow *parent,
|
||||||
|
wxWindowID id,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr);
|
||||||
|
|
||||||
|
virtual void SetMargins(int x, int y)
|
||||||
|
{
|
||||||
|
SetImageMargins(x, y);
|
||||||
|
|
||||||
|
wxBitmapButtonBase::SetMargins(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Enable(bool enable = TRUE);
|
||||||
|
|
||||||
|
virtual void SetCurrent(bool doit = TRUE);
|
||||||
|
|
||||||
|
virtual void Press();
|
||||||
|
virtual void Release();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void OnSetFocus(wxFocusEvent& event);
|
||||||
|
void OnKillFocus(wxFocusEvent& event);
|
||||||
|
|
||||||
|
// set bitmap to the given one if it's ok or to m_bmpNormal and return
|
||||||
|
// TRUE if the bitmap really changed
|
||||||
|
bool ChangeBitmap(const wxBitmap& bmp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _WX_UNIV_BMPBUTTN_H_
|
||||||
|
|
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
class WXDLLEXPORT wxInputHandler;
|
class WXDLLEXPORT wxInputHandler;
|
||||||
|
|
||||||
|
#include "wx/bitmap.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// the actions supported by this control
|
// the actions supported by this control
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -35,6 +37,21 @@ class WXDLLEXPORT wxButton : public wxButtonBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxButton() { Init(); }
|
wxButton() { Init(); }
|
||||||
|
wxButton(wxWindow *parent,
|
||||||
|
wxWindowID id,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
Create(parent, id, bitmap, label, pos, size, style, validator, name);
|
||||||
|
}
|
||||||
|
|
||||||
wxButton(wxWindow *parent,
|
wxButton(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString& label,
|
const wxString& label,
|
||||||
@@ -56,20 +73,36 @@ public:
|
|||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = 0,
|
long style = 0,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
|
const wxString& name = wxButtonNameStr)
|
||||||
|
{
|
||||||
|
return Create(parent, id, wxNullBitmap, label,
|
||||||
|
pos, size, style, validator, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Create(wxWindow *parent,
|
||||||
|
wxWindowID id,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxButtonNameStr);
|
const wxString& name = wxButtonNameStr);
|
||||||
|
|
||||||
virtual ~wxButton();
|
virtual ~wxButton();
|
||||||
|
|
||||||
|
virtual void SetImageLabel(const wxBitmap& bitmap);
|
||||||
|
virtual void SetImageMargins(wxCoord x, wxCoord y);
|
||||||
virtual void SetDefault();
|
virtual void SetDefault();
|
||||||
|
|
||||||
virtual bool IsPressed() const { return m_isPressed; }
|
virtual bool IsPressed() const { return m_isPressed; }
|
||||||
virtual bool IsDefault() const { return m_isDefault; }
|
virtual bool IsDefault() const { return m_isDefault; }
|
||||||
|
|
||||||
// wxButton actions
|
// wxButton actions
|
||||||
void Press();
|
|
||||||
void Release();
|
|
||||||
void Toggle();
|
void Toggle();
|
||||||
void Click();
|
virtual void Press();
|
||||||
|
virtual void Release();
|
||||||
|
virtual void Click();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool PerformAction(const wxControlAction& action,
|
virtual bool PerformAction(const wxControlAction& action,
|
||||||
@@ -80,9 +113,15 @@ protected:
|
|||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
// current state
|
||||||
bool m_isPressed,
|
bool m_isPressed,
|
||||||
m_isDefault;
|
m_isDefault;
|
||||||
|
|
||||||
|
// the (optional) image to show and the margins around it
|
||||||
|
wxBitmap m_bitmap;
|
||||||
|
wxCoord m_marginBmpX,
|
||||||
|
m_marginBmpY;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxButton)
|
DECLARE_DYNAMIC_CLASS(wxButton)
|
||||||
};
|
};
|
||||||
|
@@ -124,7 +124,7 @@ public:
|
|||||||
int GetStateFlags() const;
|
int GetStateFlags() const;
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
void SetCurrent(bool doit = TRUE);
|
virtual void SetCurrent(bool doit = TRUE);
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
|
|
||||||
@@ -158,6 +158,9 @@ protected:
|
|||||||
// draw the controls contents
|
// draw the controls contents
|
||||||
virtual void DoDraw(wxControlRenderer *renderer);
|
virtual void DoDraw(wxControlRenderer *renderer);
|
||||||
|
|
||||||
|
// adjust the size of the control to take into account its borders
|
||||||
|
wxSize AdjustSize(const wxSize& size) const;
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void OnMouse(wxMouseEvent& event);
|
void OnMouse(wxMouseEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
@@ -259,13 +259,18 @@ public:
|
|||||||
wxControlRenderer(wxControl *control, wxDC& dc, wxRenderer *renderer);
|
wxControlRenderer(wxControl *control, wxDC& dc, wxRenderer *renderer);
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
void DrawLabel();
|
void DrawLabel(const wxBitmap& bitmap = wxNullBitmap,
|
||||||
|
wxCoord marginX = 0, wxCoord marginY = 0);
|
||||||
void DrawBorder();
|
void DrawBorder();
|
||||||
void DrawButtonBorder();
|
void DrawButtonBorder();
|
||||||
// the line must be either horizontal or vertical
|
// the line must be either horizontal or vertical
|
||||||
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
|
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
|
||||||
void DrawFrame();
|
void DrawFrame();
|
||||||
void DrawBitmap(const wxBitmap& bitmap);
|
void DrawBitmap(const wxBitmap& bitmap);
|
||||||
|
void DrawBitmap(const wxBitmap& bitmap,
|
||||||
|
const wxRect& rect,
|
||||||
|
int alignment = wxALIGN_CENTRE | wxALIGN_CENTRE_VERTICAL,
|
||||||
|
wxStretch stretch = wxSTRETCH_NOT);
|
||||||
void DrawBackgroundBitmap();
|
void DrawBackgroundBitmap();
|
||||||
void DrawScrollbar(const wxScrollBar *scrollbar);
|
void DrawScrollbar(const wxScrollBar *scrollbar);
|
||||||
|
|
||||||
@@ -277,9 +282,6 @@ public:
|
|||||||
const wxRect& GetRect() const { return m_rect; }
|
const wxRect& GetRect() const { return m_rect; }
|
||||||
wxRect& GetRect() { return m_rect; }
|
wxRect& GetRect() { return m_rect; }
|
||||||
|
|
||||||
protected:
|
|
||||||
void DoDrawBitmap(const wxBitmap& bmp, int alignment, wxStretch stretch);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxControl *m_ctrl;
|
wxControl *m_ctrl;
|
||||||
wxRenderer *m_renderer;
|
wxRenderer *m_renderer;
|
||||||
|
@@ -767,23 +767,20 @@ protected:
|
|||||||
static int WidthDefault(int w) { return w == -1 ? 20 : w; }
|
static int WidthDefault(int w) { return w == -1 ? 20 : w; }
|
||||||
static int HeightDefault(int h) { return h == -1 ? 20 : h; }
|
static int HeightDefault(int h) { return h == -1 ? 20 : h; }
|
||||||
|
|
||||||
// sets the size to be size but take width and/or height from
|
// set the best size for the control if the default size was given:
|
||||||
// DoGetBestSize() if width/height of size is -1
|
// replaces the fields of size == -1 with the best values for them and
|
||||||
//
|
// calls SetSize() if needed
|
||||||
// NB: when calling this function from the ctor, the DoGetBestSize() of
|
void SetBestSize(const wxSize& size)
|
||||||
// the class with the same name as the ctor, not the real (most
|
|
||||||
// derived) one - but this is what we usually want
|
|
||||||
void SetSizeOrDefault(const wxSize& size = wxDefaultSize)
|
|
||||||
{
|
{
|
||||||
if ( size.x == -1 || size.y == -1 )
|
if ( size.x == -1 || size.y == -1 )
|
||||||
{
|
{
|
||||||
wxSize sizeDef = GetBestSize();
|
wxSize sizeBest = DoGetBestSize();
|
||||||
SetSize( size.x == -1 ? sizeDef.x : size.x,
|
if ( size.x != -1 )
|
||||||
size.y == -1 ? sizeDef.y : size.y);
|
sizeBest.x = size.x;
|
||||||
}
|
if ( size.y != -1 )
|
||||||
else
|
sizeBest.y = size.y;
|
||||||
{
|
|
||||||
SetSize(size);
|
SetSize(sizeBest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
samples/univ/open.xpm
Normal file
30
samples/univ/open.xpm
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* XPM */
|
||||||
|
static char *open_xpm[] = {
|
||||||
|
/* columns rows colors chars-per-pixel */
|
||||||
|
"20 19 5 1",
|
||||||
|
" c Gray0",
|
||||||
|
". c #7f007f000000",
|
||||||
|
"X c Yellow",
|
||||||
|
"o c Gray100",
|
||||||
|
"O c None",
|
||||||
|
/* pixels */
|
||||||
|
"OOOOOOOOOOOOOOOOOOOO",
|
||||||
|
"OOOOOOOOOOOOOOOOOOOO",
|
||||||
|
"OOOOOOOOOOO OOOOOO",
|
||||||
|
"OOOOOOOOOO OOO O OOO",
|
||||||
|
"OOOOOOOOOOOOOOO OOO",
|
||||||
|
"OOO OOOOOOOO OOO",
|
||||||
|
"OO XoX OOOOOOO",
|
||||||
|
"OO oXoXoXoXo OOOOOOO",
|
||||||
|
"OO XoXoXoXoX OOOOOOO",
|
||||||
|
"OO oXoX OO",
|
||||||
|
"OO XoX ......... OOO",
|
||||||
|
"OO oX ......... OOOO",
|
||||||
|
"OO X ......... OOOOO",
|
||||||
|
"OO ......... OOOOOO",
|
||||||
|
"OO OOOOOOO",
|
||||||
|
"OOOOOOOOOOOOOOOOOOOO",
|
||||||
|
"OOOOOOOOOOOOOOOOOOOO",
|
||||||
|
"OOOOOOOOOOOOOOOOOOOO",
|
||||||
|
"OOOOOOOOOOOOOOOOOOOO"
|
||||||
|
};
|
@@ -34,6 +34,7 @@
|
|||||||
#include "wx/frame.h"
|
#include "wx/frame.h"
|
||||||
#include "wx/dcclient.h"
|
#include "wx/dcclient.h"
|
||||||
|
|
||||||
|
#include "wx/bmpbuttn.h"
|
||||||
#include "wx/button.h"
|
#include "wx/button.h"
|
||||||
#include "wx/scrolbar.h"
|
#include "wx/scrolbar.h"
|
||||||
#include "wx/statbmp.h"
|
#include "wx/statbmp.h"
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "wx/generic/tip.xpm"
|
#include "wx/generic/tip.xpm"
|
||||||
|
#include "open.xpm"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
@@ -201,12 +203,33 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
|
|||||||
sb->SetScrollbar(0, 10, 100, 10);
|
sb->SetScrollbar(0, 10, 100, 10);
|
||||||
sb = new wxScrollBar(this, -1, wxPoint(200, 330), wxSize(-1, 150), wxSB_VERTICAL);
|
sb = new wxScrollBar(this, -1, wxPoint(200, 330), wxSize(-1, 150), wxSB_VERTICAL);
|
||||||
sb->SetScrollbar(50, 50, 100, 10);
|
sb->SetScrollbar(50, 50, 100, 10);
|
||||||
|
|
||||||
|
new wxButton(this, -1, wxBitmap(open_xpm), _T("&Open..."), wxPoint(10, 420));
|
||||||
|
|
||||||
|
wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
|
||||||
|
bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
|
||||||
|
bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
|
||||||
|
wxBitmapButton *bmpBtn = new wxBitmapButton
|
||||||
|
(
|
||||||
|
this, -1,
|
||||||
|
bmp1,
|
||||||
|
wxPoint(10, 470)
|
||||||
|
);
|
||||||
|
bmpBtn->SetBitmapSelected(bmp2);
|
||||||
|
bmpBtn->SetBitmapFocus(bmp3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyUnivFrame::OnButton(wxCommandEvent& event)
|
void MyUnivFrame::OnButton(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxLogDebug(_T("Button %d pressed."),
|
int btn = event.GetId();
|
||||||
event.GetId() == Univ_Button1 ? 1 : 2);
|
if ( btn == Univ_Button1 || btn == Univ_Button2 )
|
||||||
|
{
|
||||||
|
wxLogDebug(_T("Button %d pressed."), btn == Univ_Button1 ? 1 : 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogDebug(_T("Another button pressed."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyUnivFrame::OnLeftUp(wxMouseEvent& event)
|
void MyUnivFrame::OnLeftUp(wxMouseEvent& event)
|
||||||
|
@@ -241,7 +241,7 @@ void wxDCBase::DrawLabel(const wxString& text,
|
|||||||
{
|
{
|
||||||
x = rect.GetRight() - width;
|
x = rect.GetRight() - width;
|
||||||
}
|
}
|
||||||
else if ( alignment & wxALIGN_CENTRE )
|
else if ( alignment & wxALIGN_CENTRE_HORIZONTAL )
|
||||||
{
|
{
|
||||||
x = (rect.GetLeft() + rect.GetRight() - width) / 2;
|
x = (rect.GetLeft() + rect.GetRight() - width) / 2;
|
||||||
}
|
}
|
||||||
|
@@ -119,9 +119,6 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_acceptsFocus = TRUE;
|
m_acceptsFocus = TRUE;
|
||||||
|
|
||||||
m_marginX =
|
|
||||||
m_marginY = 0;
|
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
!CreateBase( parent, id, pos, size, style, validator, name ))
|
||||||
{
|
{
|
||||||
@@ -129,10 +126,10 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bitmap = bitmap;
|
m_bmpNormal =
|
||||||
m_disabled = bitmap;
|
m_bmpDisabled =
|
||||||
m_focus = bitmap;
|
m_bmpFocus =
|
||||||
m_selected = bitmap;
|
m_bmpSelected = bitmap;
|
||||||
|
|
||||||
m_widget = gtk_button_new();
|
m_widget = gtk_button_new();
|
||||||
|
|
||||||
@@ -141,21 +138,21 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
|
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m_bitmap.Ok())
|
if (m_bmpNormal.Ok())
|
||||||
{
|
{
|
||||||
wxSize newSize = size;
|
wxSize newSize = size;
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = (GdkBitmap *) NULL;
|
||||||
if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
|
if (m_bmpNormal.GetMask()) mask = m_bmpNormal.GetMask()->GetBitmap();
|
||||||
GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
|
GtkWidget *pixmap = gtk_pixmap_new( m_bmpNormal.GetPixmap(), mask );
|
||||||
|
|
||||||
gtk_widget_show( pixmap );
|
gtk_widget_show( pixmap );
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
|
gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
|
||||||
|
|
||||||
int border = 10;
|
int border = 10;
|
||||||
if (style & wxNO_BORDER) border = 4;
|
if (style & wxNO_BORDER) border = 4;
|
||||||
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
|
if (newSize.x == -1) newSize.x = m_bmpNormal.GetWidth()+border;
|
||||||
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
|
if (newSize.y == -1) newSize.y = m_bmpNormal.GetHeight()+border;
|
||||||
SetSize( newSize.x, newSize.y );
|
SetSize( newSize.x, newSize.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,28 +207,28 @@ void wxBitmapButton::ApplyWidgetStyle()
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmap()
|
void wxBitmapButton::SetBitmap()
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
|
||||||
|
|
||||||
wxBitmap the_one;
|
wxBitmap the_one;
|
||||||
|
|
||||||
if (!m_isEnabled)
|
if (!m_isEnabled)
|
||||||
the_one = m_disabled;
|
the_one = m_bmpDisabled;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_isSelected)
|
if (m_isSelected)
|
||||||
{
|
{
|
||||||
the_one = m_selected;
|
the_one = m_bmpSelected;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_hasFocus)
|
if (m_hasFocus)
|
||||||
the_one = m_focus;
|
the_one = m_bmpFocus;
|
||||||
else
|
else
|
||||||
the_one = m_bitmap;
|
the_one = m_bmpNormal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!the_one.Ok()) the_one = m_bitmap;
|
if (!the_one.Ok()) the_one = m_bmpNormal;
|
||||||
if (!the_one.Ok()) return;
|
if (!the_one.Ok()) return;
|
||||||
|
|
||||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||||
@@ -243,43 +240,8 @@ void wxBitmapButton::SetBitmap()
|
|||||||
gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask );
|
gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
|
void wxBitmapButton::OnSetBitmap()
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if ( ! m_disabled.Ok() ) return;
|
|
||||||
m_disabled = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if ( ! m_focus.Ok() ) return;
|
|
||||||
m_focus = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if (!m_bitmap.Ok()) return;
|
|
||||||
m_bitmap = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if ( ! m_selected.Ok() ) return;
|
|
||||||
m_selected = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -119,9 +119,6 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_acceptsFocus = TRUE;
|
m_acceptsFocus = TRUE;
|
||||||
|
|
||||||
m_marginX =
|
|
||||||
m_marginY = 0;
|
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
!CreateBase( parent, id, pos, size, style, validator, name ))
|
||||||
{
|
{
|
||||||
@@ -129,10 +126,10 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bitmap = bitmap;
|
m_bmpNormal =
|
||||||
m_disabled = bitmap;
|
m_bmpDisabled =
|
||||||
m_focus = bitmap;
|
m_bmpFocus =
|
||||||
m_selected = bitmap;
|
m_bmpSelected = bitmap;
|
||||||
|
|
||||||
m_widget = gtk_button_new();
|
m_widget = gtk_button_new();
|
||||||
|
|
||||||
@@ -141,21 +138,21 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
|
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m_bitmap.Ok())
|
if (m_bmpNormal.Ok())
|
||||||
{
|
{
|
||||||
wxSize newSize = size;
|
wxSize newSize = size;
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = (GdkBitmap *) NULL;
|
||||||
if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
|
if (m_bmpNormal.GetMask()) mask = m_bmpNormal.GetMask()->GetBitmap();
|
||||||
GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
|
GtkWidget *pixmap = gtk_pixmap_new( m_bmpNormal.GetPixmap(), mask );
|
||||||
|
|
||||||
gtk_widget_show( pixmap );
|
gtk_widget_show( pixmap );
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
|
gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
|
||||||
|
|
||||||
int border = 10;
|
int border = 10;
|
||||||
if (style & wxNO_BORDER) border = 4;
|
if (style & wxNO_BORDER) border = 4;
|
||||||
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
|
if (newSize.x == -1) newSize.x = m_bmpNormal.GetWidth()+border;
|
||||||
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
|
if (newSize.y == -1) newSize.y = m_bmpNormal.GetHeight()+border;
|
||||||
SetSize( newSize.x, newSize.y );
|
SetSize( newSize.x, newSize.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,28 +207,28 @@ void wxBitmapButton::ApplyWidgetStyle()
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmap()
|
void wxBitmapButton::SetBitmap()
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
|
||||||
|
|
||||||
wxBitmap the_one;
|
wxBitmap the_one;
|
||||||
|
|
||||||
if (!m_isEnabled)
|
if (!m_isEnabled)
|
||||||
the_one = m_disabled;
|
the_one = m_bmpDisabled;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_isSelected)
|
if (m_isSelected)
|
||||||
{
|
{
|
||||||
the_one = m_selected;
|
the_one = m_bmpSelected;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_hasFocus)
|
if (m_hasFocus)
|
||||||
the_one = m_focus;
|
the_one = m_bmpFocus;
|
||||||
else
|
else
|
||||||
the_one = m_bitmap;
|
the_one = m_bmpNormal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!the_one.Ok()) the_one = m_bitmap;
|
if (!the_one.Ok()) the_one = m_bmpNormal;
|
||||||
if (!the_one.Ok()) return;
|
if (!the_one.Ok()) return;
|
||||||
|
|
||||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||||
@@ -243,43 +240,8 @@ void wxBitmapButton::SetBitmap()
|
|||||||
gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask );
|
gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
|
void wxBitmapButton::OnSetBitmap()
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if ( ! m_disabled.Ok() ) return;
|
|
||||||
m_disabled = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if ( ! m_focus.Ok() ) return;
|
|
||||||
m_focus = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if (!m_bitmap.Ok()) return;
|
|
||||||
m_bitmap = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
|
||||||
|
|
||||||
if ( ! m_selected.Ok() ) return;
|
|
||||||
m_selected = bitmap;
|
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
|
|||||||
const wxValidator& validator,
|
const wxValidator& validator,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
m_buttonBitmap = bitmap;
|
m_bmpNormal = bitmap;
|
||||||
SetName(name);
|
SetName(name);
|
||||||
|
|
||||||
#if wxUSE_VALIDATORS
|
#if wxUSE_VALIDATORS
|
||||||
@@ -52,8 +52,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
|
|||||||
m_backgroundColour = parent->GetBackgroundColour();
|
m_backgroundColour = parent->GetBackgroundColour();
|
||||||
m_foregroundColour = parent->GetForegroundColour();
|
m_foregroundColour = parent->GetForegroundColour();
|
||||||
m_windowStyle = style;
|
m_windowStyle = style;
|
||||||
m_marginX = 0;
|
|
||||||
m_marginY = 0;
|
|
||||||
|
|
||||||
if ( style & wxBU_AUTODRAW )
|
if ( style & wxBU_AUTODRAW )
|
||||||
{
|
{
|
||||||
@@ -113,11 +111,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
|
|
||||||
{
|
|
||||||
m_buttonBitmap = bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
// VZ: should be at the very least less than wxDEFAULT_BUTTON_MARGIN
|
// VZ: should be at the very least less than wxDEFAULT_BUTTON_MARGIN
|
||||||
#define FOCUS_MARGIN 3
|
#define FOCUS_MARGIN 3
|
||||||
|
|
||||||
@@ -143,14 +136,14 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
|
|||||||
// choose the bitmap to use depending on the button state
|
// choose the bitmap to use depending on the button state
|
||||||
wxBitmap* bitmap;
|
wxBitmap* bitmap;
|
||||||
|
|
||||||
if ( isSelected && m_buttonBitmapSelected.Ok() )
|
if ( isSelected && m_bmpSelected.Ok() )
|
||||||
bitmap = &m_buttonBitmapSelected;
|
bitmap = &m_bmpSelected;
|
||||||
else if ((state & ODS_FOCUS) && m_buttonBitmapFocus.Ok())
|
else if ((state & ODS_FOCUS) && m_bmpFocus.Ok())
|
||||||
bitmap = &m_buttonBitmapFocus;
|
bitmap = &m_bmpFocus;
|
||||||
else if ((state & ODS_DISABLED) && m_buttonBitmapDisabled.Ok())
|
else if ((state & ODS_DISABLED) && m_bmpDisabled.Ok())
|
||||||
bitmap = &m_buttonBitmapDisabled;
|
bitmap = &m_bmpDisabled;
|
||||||
else
|
else
|
||||||
bitmap = &m_buttonBitmap;
|
bitmap = &m_bmpNormal;
|
||||||
|
|
||||||
if ( !bitmap->Ok() )
|
if ( !bitmap->Ok() )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
135
src/univ/bmpbuttn.cpp
Normal file
135
src/univ/bmpbuttn.cpp
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: univ/bmpbuttn.cpp
|
||||||
|
// Purpose: wxBitmapButton implementation
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// Modified by:
|
||||||
|
// Created: 25.08.00
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 2000 Vadim Zeitlin
|
||||||
|
// Licence: wxWindows license
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// declarations
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "univbmpbuttn.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if wxUSE_STATLINE
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#include "wx/bmpbuttn.h"
|
||||||
|
#include "wx/validate.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/univ/renderer.h"
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// implementation
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl)
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
|
||||||
|
EVT_SET_FOCUS(wxBitmapButton::OnSetFocus)
|
||||||
|
EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxBitmapButton
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool wxBitmapButton::Create(wxWindow *parent,
|
||||||
|
wxWindowID id,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxPoint &pos,
|
||||||
|
const wxSize &size,
|
||||||
|
long style,
|
||||||
|
const wxValidator& validator,
|
||||||
|
const wxString &name)
|
||||||
|
{
|
||||||
|
if ( !wxButton::Create(parent, id, bitmap, _T(""),
|
||||||
|
pos, size, style, validator, name) )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
m_bmpNormal = bitmap;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
|
||||||
|
{
|
||||||
|
wxBitmap bitmap = bmp.Ok() ? bmp : m_bmpNormal;
|
||||||
|
if ( bitmap != m_bitmap )
|
||||||
|
{
|
||||||
|
m_bitmap = bitmap;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmapButton::Enable(bool enable)
|
||||||
|
{
|
||||||
|
if ( !wxButton::Enable(enable) )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if ( !enable && ChangeBitmap(m_bmpDisabled) )
|
||||||
|
Refresh();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapButton::SetCurrent(bool doit)
|
||||||
|
{
|
||||||
|
ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal);
|
||||||
|
|
||||||
|
wxButton::SetCurrent(doit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
|
||||||
|
{
|
||||||
|
if ( ChangeBitmap(m_bmpFocus) )
|
||||||
|
Refresh();
|
||||||
|
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
|
||||||
|
{
|
||||||
|
if ( ChangeBitmap(m_bmpNormal) )
|
||||||
|
Refresh();
|
||||||
|
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapButton::Press()
|
||||||
|
{
|
||||||
|
ChangeBitmap(m_bmpSelected);
|
||||||
|
|
||||||
|
wxButton::Press();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapButton::Release()
|
||||||
|
{
|
||||||
|
ChangeBitmap(m_bmpNormal);
|
||||||
|
|
||||||
|
wxButton::Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_STATLINE
|
||||||
|
|
@@ -39,6 +39,14 @@
|
|||||||
#include "wx/univ/inphand.h"
|
#include "wx/univ/inphand.h"
|
||||||
#include "wx/univ/theme.h"
|
#include "wx/univ/theme.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// default margins around the image
|
||||||
|
static const wxCoord DEFAULT_BTN_MARGIN_X = 6;
|
||||||
|
static const wxCoord DEFAULT_BTN_MARGIN_Y = 3;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -57,6 +65,7 @@ void wxButton::Init()
|
|||||||
|
|
||||||
bool wxButton::Create(wxWindow *parent,
|
bool wxButton::Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
const wxString &label,
|
const wxString &label,
|
||||||
const wxPoint &pos,
|
const wxPoint &pos,
|
||||||
const wxSize &size,
|
const wxSize &size,
|
||||||
@@ -67,20 +76,26 @@ bool wxButton::Create(wxWindow *parent,
|
|||||||
// center label by default
|
// center label by default
|
||||||
if ( !(style & wxALIGN_MASK) )
|
if ( !(style & wxALIGN_MASK) )
|
||||||
{
|
{
|
||||||
style |= wxALIGN_CENTRE | wxALIGN_CENTRE_VERTICAL;
|
style |= wxALIGN_CENTRE_VERTICAL;
|
||||||
|
|
||||||
|
// normally, buttons are centered, but it looks better to put them
|
||||||
|
// near the image for the buttons which have one
|
||||||
|
if ( bitmap.Ok() )
|
||||||
|
{
|
||||||
|
style |= wxALIGN_LEFT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
style |= wxALIGN_CENTRE_HORIZONTAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) )
|
if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
SetLabel(label);
|
SetLabel(label);
|
||||||
|
SetImageLabel(bitmap);
|
||||||
if ( size.x == -1 || size.y == -1 )
|
SetBestSize(size);
|
||||||
{
|
|
||||||
wxSize sizeBest = DoGetBestSize();
|
|
||||||
SetSize(size.x == -1 ? sizeBest.x : size.x,
|
|
||||||
size.y == -1 ? sizeBest.y : size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -99,9 +114,17 @@ wxSize wxButton::DoGetBestSize() const
|
|||||||
wxCoord width, height;
|
wxCoord width, height;
|
||||||
dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
|
dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
|
||||||
|
|
||||||
wxSize sz(width, height);
|
if ( m_bitmap.Ok() )
|
||||||
wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this);
|
{
|
||||||
return sz;
|
// allocate extra space for the bitmap
|
||||||
|
wxCoord heightBmp = m_bitmap.GetHeight() + 2*m_marginBmpY;
|
||||||
|
if ( height < heightBmp )
|
||||||
|
height = heightBmp;
|
||||||
|
|
||||||
|
width += m_bitmap.GetWidth() + 2*m_marginBmpX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return AdjustSize(wxSize(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -111,7 +134,7 @@ wxSize wxButton::DoGetBestSize() const
|
|||||||
void wxButton::DoDraw(wxControlRenderer *renderer)
|
void wxButton::DoDraw(wxControlRenderer *renderer)
|
||||||
{
|
{
|
||||||
renderer->DrawButtonBorder();
|
renderer->DrawButtonBorder();
|
||||||
renderer->DrawLabel();
|
renderer->DrawLabel(m_bitmap, m_marginBmpX, m_marginBmpY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -130,7 +153,10 @@ void wxButton::Release()
|
|||||||
|
|
||||||
void wxButton::Toggle()
|
void wxButton::Toggle()
|
||||||
{
|
{
|
||||||
m_isPressed = !m_isPressed;
|
if ( m_isPressed )
|
||||||
|
Release();
|
||||||
|
else
|
||||||
|
Press();
|
||||||
|
|
||||||
if ( !m_isPressed )
|
if ( !m_isPressed )
|
||||||
{
|
{
|
||||||
@@ -166,9 +192,22 @@ bool wxButton::PerformAction(const wxControlAction& action,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
//
|
// misc
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxButton::SetImageLabel(const wxBitmap& bitmap)
|
||||||
|
{
|
||||||
|
m_bitmap = bitmap;
|
||||||
|
m_marginBmpX = DEFAULT_BTN_MARGIN_X;
|
||||||
|
m_marginBmpY = DEFAULT_BTN_MARGIN_Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxButton::SetImageMargins(wxCoord x, wxCoord y)
|
||||||
|
{
|
||||||
|
m_marginBmpX = x;
|
||||||
|
m_marginBmpY = y;
|
||||||
|
}
|
||||||
|
|
||||||
void wxButton::SetDefault()
|
void wxButton::SetDefault()
|
||||||
{
|
{
|
||||||
m_isDefault = TRUE;
|
m_isDefault = TRUE;
|
||||||
|
@@ -139,6 +139,17 @@ int wxControl::GetStateFlags() const
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// size
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxSize wxControl::AdjustSize(const wxSize& size) const
|
||||||
|
{
|
||||||
|
wxSize sz = size;
|
||||||
|
wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this);
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// mnemonics handling
|
// mnemonics handling
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -267,7 +278,8 @@ void wxControl::DoDraw(wxControlRenderer *renderer)
|
|||||||
|
|
||||||
void wxControl::OnFocus(wxFocusEvent& event)
|
void wxControl::OnFocus(wxFocusEvent& event)
|
||||||
{
|
{
|
||||||
Refresh();
|
// do nothing here for now...
|
||||||
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
UNIVOBJS = \
|
UNIVOBJS = \
|
||||||
|
bmpbuttn.o \
|
||||||
button.o \
|
button.o \
|
||||||
colschem.o \
|
colschem.o \
|
||||||
control.o \
|
control.o \
|
||||||
@@ -14,6 +15,7 @@ UNIVOBJS = \
|
|||||||
win32.o
|
win32.o
|
||||||
|
|
||||||
UNIVDEPS = \
|
UNIVDEPS = \
|
||||||
|
bmpbuttn.d \
|
||||||
button.d \
|
button.d \
|
||||||
colschem.d \
|
colschem.d \
|
||||||
control.d \
|
control.d \
|
||||||
|
@@ -156,8 +156,11 @@ wxControlActions wxStdButtonInputHandler::Map(wxControl *control,
|
|||||||
}
|
}
|
||||||
else // up
|
else // up
|
||||||
{
|
{
|
||||||
m_winCapture->ReleaseMouse();
|
if ( m_winCapture )
|
||||||
m_winCapture = NULL;
|
{
|
||||||
|
m_winCapture->ReleaseMouse();
|
||||||
|
m_winCapture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_winHasMouse )
|
if ( m_winHasMouse )
|
||||||
{
|
{
|
||||||
|
@@ -186,17 +186,39 @@ void wxControlRenderer::DrawBorder()
|
|||||||
m_renderer->DrawBackground(m_dc, m_rect, flags);
|
m_renderer->DrawBackground(m_dc, m_rect, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxControlRenderer::DrawLabel()
|
void wxControlRenderer::DrawLabel(const wxBitmap& bitmap,
|
||||||
|
wxCoord marginX, wxCoord marginY)
|
||||||
{
|
{
|
||||||
m_dc.SetFont(m_ctrl->GetFont());
|
m_dc.SetFont(m_ctrl->GetFont());
|
||||||
m_dc.SetTextForeground(m_ctrl->GetForegroundColour());
|
m_dc.SetTextForeground(m_ctrl->GetForegroundColour());
|
||||||
|
|
||||||
m_renderer->DrawLabel(m_dc,
|
wxRect rectLabel = m_rect;
|
||||||
m_ctrl->GetLabel(),
|
if ( bitmap.Ok() )
|
||||||
m_rect,
|
{
|
||||||
m_ctrl->GetStateFlags(),
|
wxRect rectBmp;
|
||||||
m_ctrl->GetAlignment(),
|
int width = bitmap.GetWidth();
|
||||||
m_ctrl->GetAccelIndex());
|
rectBmp.x = m_rect.x + marginX;
|
||||||
|
rectBmp.y = m_rect.y + marginY;
|
||||||
|
rectBmp.width = width;
|
||||||
|
rectBmp.height = m_rect.height - marginY;
|
||||||
|
|
||||||
|
DrawBitmap(bitmap, rectBmp, wxALIGN_CENTRE | wxALIGN_CENTRE_VERTICAL);
|
||||||
|
|
||||||
|
width += 2*marginX;
|
||||||
|
rectLabel.x += width;
|
||||||
|
rectLabel.width -= width;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString label = m_ctrl->GetLabel();
|
||||||
|
if ( !label.empty() )
|
||||||
|
{
|
||||||
|
m_renderer->DrawLabel(m_dc,
|
||||||
|
label,
|
||||||
|
rectLabel,
|
||||||
|
m_ctrl->GetStateFlags(),
|
||||||
|
m_ctrl->GetAlignment(),
|
||||||
|
m_ctrl->GetAccelIndex());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxControlRenderer::DrawFrame()
|
void wxControlRenderer::DrawFrame()
|
||||||
@@ -225,9 +247,9 @@ void wxControlRenderer::DrawButtonBorder()
|
|||||||
void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap)
|
void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap)
|
||||||
{
|
{
|
||||||
int style = m_ctrl->GetWindowStyle();
|
int style = m_ctrl->GetWindowStyle();
|
||||||
DoDrawBitmap(bitmap,
|
DrawBitmap(bitmap, m_rect,
|
||||||
style & wxALIGN_MASK,
|
style & wxALIGN_MASK,
|
||||||
style & wxBI_EXPAND ? wxEXPAND : wxSTRETCH_NOT);
|
style & wxBI_EXPAND ? wxEXPAND : wxSTRETCH_NOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxControlRenderer::DrawBackgroundBitmap()
|
void wxControlRenderer::DrawBackgroundBitmap()
|
||||||
@@ -237,13 +259,16 @@ void wxControlRenderer::DrawBackgroundBitmap()
|
|||||||
wxStretch stretch;
|
wxStretch stretch;
|
||||||
wxBitmap bmp = m_ctrl->GetBackgroundBitmap(&alignment, &stretch);
|
wxBitmap bmp = m_ctrl->GetBackgroundBitmap(&alignment, &stretch);
|
||||||
|
|
||||||
DoDrawBitmap(bmp, alignment, stretch);
|
DrawBitmap(bmp, m_rect, alignment, stretch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxControlRenderer::DoDrawBitmap(const wxBitmap& bmp,
|
void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap,
|
||||||
int alignment,
|
const wxRect& rect,
|
||||||
wxStretch stretch)
|
int alignment,
|
||||||
|
wxStretch stretch)
|
||||||
{
|
{
|
||||||
|
// we may change the bitmap if we stretch it
|
||||||
|
wxBitmap bmp = bitmap;
|
||||||
if ( !bmp.Ok() )
|
if ( !bmp.Ok() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -255,9 +280,9 @@ void wxControlRenderer::DoDrawBitmap(const wxBitmap& bmp,
|
|||||||
if ( stretch & wxTILE )
|
if ( stretch & wxTILE )
|
||||||
{
|
{
|
||||||
// tile the bitmap
|
// tile the bitmap
|
||||||
for ( ; x < m_rect.width; x += width )
|
for ( ; x < rect.width; x += width )
|
||||||
{
|
{
|
||||||
for ( y = 0; y < m_rect.height; y += height )
|
for ( y = 0; y < rect.height; y += height )
|
||||||
{
|
{
|
||||||
m_dc.DrawBitmap(bmp, x, y);
|
m_dc.DrawBitmap(bmp, x, y);
|
||||||
}
|
}
|
||||||
@@ -266,34 +291,34 @@ void wxControlRenderer::DoDrawBitmap(const wxBitmap& bmp,
|
|||||||
else if ( stretch & wxEXPAND )
|
else if ( stretch & wxEXPAND )
|
||||||
{
|
{
|
||||||
// stretch bitmap to fill the entire control
|
// stretch bitmap to fill the entire control
|
||||||
bmp = wxImage(bmp).Scale(m_rect.width, m_rect.height).ConvertToBitmap();
|
bmp = wxImage(bmp).Scale(rect.width, rect.height).ConvertToBitmap();
|
||||||
}
|
}
|
||||||
else // not stretched, not tiled
|
else // not stretched, not tiled
|
||||||
{
|
{
|
||||||
if ( alignment & wxALIGN_RIGHT )
|
if ( alignment & wxALIGN_RIGHT )
|
||||||
{
|
{
|
||||||
x = m_rect.GetRight() - width;
|
x = rect.GetRight() - width;
|
||||||
}
|
}
|
||||||
else if ( alignment & wxALIGN_CENTRE )
|
else if ( alignment & wxALIGN_CENTRE )
|
||||||
{
|
{
|
||||||
x = (m_rect.GetLeft() + m_rect.GetRight() - width) / 2;
|
x = (rect.GetLeft() + rect.GetRight() - width) / 2;
|
||||||
}
|
}
|
||||||
else // alignment & wxALIGN_LEFT
|
else // alignment & wxALIGN_LEFT
|
||||||
{
|
{
|
||||||
x = m_rect.GetLeft();
|
x = rect.GetLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( alignment & wxALIGN_BOTTOM )
|
if ( alignment & wxALIGN_BOTTOM )
|
||||||
{
|
{
|
||||||
y = m_rect.GetBottom() - height;
|
y = rect.GetBottom() - height;
|
||||||
}
|
}
|
||||||
else if ( alignment & wxALIGN_CENTRE_VERTICAL )
|
else if ( alignment & wxALIGN_CENTRE_VERTICAL )
|
||||||
{
|
{
|
||||||
y = (m_rect.GetTop() + m_rect.GetBottom() - height) / 2;
|
y = (rect.GetTop() + rect.GetBottom() - height) / 2;
|
||||||
}
|
}
|
||||||
else // alignment & wxALIGN_TOP
|
else // alignment & wxALIGN_TOP
|
||||||
{
|
{
|
||||||
y = m_rect.GetTop();
|
y = rect.GetTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -162,9 +162,8 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize,
|
|||||||
|
|
||||||
wxSize wxScrollBar::DoGetBestSize() const
|
wxSize wxScrollBar::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
wxSize sz(140, 140);
|
// completely arbitrary
|
||||||
wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this);
|
return AdjustSize(wxSize(140, 140));
|
||||||
return sz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -64,16 +64,7 @@ bool wxStaticBitmap::Create(wxWindow *parent,
|
|||||||
SetBitmap(label);
|
SetBitmap(label);
|
||||||
|
|
||||||
// and adjust our size to fit it after this
|
// and adjust our size to fit it after this
|
||||||
if ( size.x == -1 || size.y == -1 )
|
SetBestSize(size);
|
||||||
{
|
|
||||||
wxSize sizeBest = DoGetBestSize();
|
|
||||||
if ( size.x != -1 )
|
|
||||||
sizeBest.x = size.x;
|
|
||||||
if ( size.y != -1 )
|
|
||||||
sizeBest.y = size.y;
|
|
||||||
|
|
||||||
SetSize(sizeBest);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -113,9 +104,7 @@ wxIcon wxStaticBitmap::GetIcon() const
|
|||||||
|
|
||||||
wxSize wxStaticBitmap::DoGetBestSize() const
|
wxSize wxStaticBitmap::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
wxSize sz = wxStaticBitmapBase::DoGetBestSize();
|
return AdjustSize(wxStaticBitmapBase::DoGetBestSize());
|
||||||
wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this);
|
|
||||||
return sz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxStaticBitmap::DoDraw(wxControlRenderer *renderer)
|
void wxStaticBitmap::DoDraw(wxControlRenderer *renderer)
|
||||||
|
@@ -84,9 +84,7 @@ wxSize wxStaticText::DoGetBestSize() const
|
|||||||
wxCoord width, height;
|
wxCoord width, height;
|
||||||
dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
|
dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
|
||||||
|
|
||||||
wxSize sz(width, height);
|
return AdjustSize(wxSize(width, height));
|
||||||
wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this);
|
|
||||||
return sz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -249,7 +249,7 @@ wxInputHandler *wxGTKTheme::GetInputHandler(const wxString& control)
|
|||||||
// create a new handler
|
// create a new handler
|
||||||
n = m_handlerNames.Add(control);
|
n = m_handlerNames.Add(control);
|
||||||
|
|
||||||
if ( control == _T("wxButton") )
|
if ( control.Matches(_T("wx*Button")) )
|
||||||
handler = new wxStdButtonInputHandler(GetInputHandler(_T("wxControl")));
|
handler = new wxStdButtonInputHandler(GetInputHandler(_T("wxControl")));
|
||||||
else if ( control == _T("wxScrollBar") )
|
else if ( control == _T("wxScrollBar") )
|
||||||
handler = new wxGTKScrollBarInputHandler(m_renderer,
|
handler = new wxGTKScrollBarInputHandler(m_renderer,
|
||||||
@@ -284,7 +284,7 @@ wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col,
|
|||||||
case CONTROL:
|
case CONTROL:
|
||||||
if ( flags & wxCONTROL_PRESSED )
|
if ( flags & wxCONTROL_PRESSED )
|
||||||
{
|
{
|
||||||
return wxColour(0x7f7f7f);
|
return wxColour(0xc3c3c3);
|
||||||
}
|
}
|
||||||
else if ( flags & wxCONTROL_CURRENT )
|
else if ( flags & wxCONTROL_CURRENT )
|
||||||
{
|
{
|
||||||
@@ -892,9 +892,14 @@ void wxGTKRenderer::AdjustSize(wxSize *size, const wxWindow *window)
|
|||||||
{
|
{
|
||||||
if ( wxDynamicCast(window, wxButton) )
|
if ( wxDynamicCast(window, wxButton) )
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO: this is ad hoc...
|
||||||
size->x += 3*window->GetCharWidth();
|
size->x += 3*window->GetCharWidth();
|
||||||
size->y = (11*(window->GetCharHeight() + 8))/10;
|
wxCoord minBtnHeight = (11*(window->GetCharHeight() + 8))/10;
|
||||||
|
if ( size->y < minBtnHeight )
|
||||||
|
size->y = minBtnHeight;
|
||||||
|
|
||||||
|
// button border width
|
||||||
|
size->y += 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -283,7 +283,7 @@ wxInputHandler *wxWin32Theme::GetInputHandler(const wxString& control)
|
|||||||
// create a new handler
|
// create a new handler
|
||||||
n = m_handlerNames.Add(control);
|
n = m_handlerNames.Add(control);
|
||||||
|
|
||||||
if ( control == _T("wxButton") )
|
if ( control.Matches(_T("wx*Button")) )
|
||||||
handler = new wxStdButtonInputHandler(GetInputHandler(_T("wxControl")));
|
handler = new wxStdButtonInputHandler(GetInputHandler(_T("wxControl")));
|
||||||
else if ( control == _T("wxScrollBar") )
|
else if ( control == _T("wxScrollBar") )
|
||||||
handler = new wxWin32ScrollBarInputHandler(m_renderer,
|
handler = new wxWin32ScrollBarInputHandler(m_renderer,
|
||||||
|
Reference in New Issue
Block a user