diff --git a/include/wx/bmpbuttn.h b/include/wx/bmpbuttn.h index f753cd2409..4b23b568c2 100644 --- a/include/wx/bmpbuttn.h +++ b/include/wx/bmpbuttn.h @@ -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_ #define _WX_BMPBUTTON_H_BASE_ -#if defined(__WXMSW__) -#include "wx/msw/bmpbuttn.h" +#if wxUSE_BMPBUTTON + +#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__) -#include "wx/motif/bmpbuttn.h" + #include "wx/motif/bmpbuttn.h" #elif defined(__WXGTK__) -#include "wx/gtk/bmpbuttn.h" + #include "wx/gtk/bmpbuttn.h" #elif defined(__WXQT__) -#include "wx/qt/bmpbuttn.h" + #include "wx/qt/bmpbuttn.h" #elif defined(__WXMAC__) -#include "wx/mac/bmpbuttn.h" + #include "wx/mac/bmpbuttn.h" #elif defined(__WXPM__) -#include "wx/os2/bmpbuttn.h" + #include "wx/os2/bmpbuttn.h" #elif defined(__WXSTUBS__) -#include "wx/stubs/bmpbuttn.h" + #include "wx/stubs/bmpbuttn.h" #endif -#endif +#endif // wxUSE_BMPBUTTON + +#endif // _WX_BMPBUTTON_H_BASE_ diff --git a/include/wx/button.h b/include/wx/button.h index cc7232fc7c..b9b1f0388b 100644 --- a/include/wx/button.h +++ b/include/wx/button.h @@ -30,6 +30,9 @@ public: // show the image in the button in addition to the label 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 // on its panel virtual void SetDefault() { } diff --git a/include/wx/gtk/bmpbuttn.h b/include/wx/gtk/bmpbuttn.h index 233e8d90e8..baae20d297 100644 --- a/include/wx/gtk/bmpbuttn.h +++ b/include/wx/gtk/bmpbuttn.h @@ -15,71 +15,41 @@ #pragma interface #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 -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- -class wxBitmapButton: public wxButton +class wxBitmapButton: public wxBitmapButtonBase { public: wxBitmapButton(); - inline wxBitmapButton( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr ) + wxBitmapButton(wxWindow *parent, + wxWindowID id, + const wxBitmap& bitmap, + 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); } - bool Create( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); + bool Create(wxWindow *parent, + wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxBU_AUTODRAW, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxButtonNameStr); + virtual void SetDefault(); + virtual bool Enable(bool enable = TRUE); void SetLabel( const wxString &label ); wxString GetLabel() const; 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 // -------------- @@ -92,19 +62,12 @@ public: bool m_hasFocus; bool m_isSelected; - wxBitmap m_bitmap; - wxBitmap m_disabled; - wxBitmap m_focus; - wxBitmap m_selected; protected: - int m_marginX; - int m_marginY; + virtual void OnSetBitmap(); private: DECLARE_DYNAMIC_CLASS(wxBitmapButton) }; -#endif - #endif // __BMPBUTTONH__ diff --git a/include/wx/gtk1/bmpbuttn.h b/include/wx/gtk1/bmpbuttn.h index 233e8d90e8..baae20d297 100644 --- a/include/wx/gtk1/bmpbuttn.h +++ b/include/wx/gtk1/bmpbuttn.h @@ -15,71 +15,41 @@ #pragma interface #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 -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- -class wxBitmapButton: public wxButton +class wxBitmapButton: public wxBitmapButtonBase { public: wxBitmapButton(); - inline wxBitmapButton( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr ) + wxBitmapButton(wxWindow *parent, + wxWindowID id, + const wxBitmap& bitmap, + 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); } - bool Create( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); + bool Create(wxWindow *parent, + wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxBU_AUTODRAW, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxButtonNameStr); + virtual void SetDefault(); + virtual bool Enable(bool enable = TRUE); void SetLabel( const wxString &label ); wxString GetLabel() const; 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 // -------------- @@ -92,19 +62,12 @@ public: bool m_hasFocus; bool m_isSelected; - wxBitmap m_bitmap; - wxBitmap m_disabled; - wxBitmap m_focus; - wxBitmap m_selected; protected: - int m_marginX; - int m_marginY; + virtual void OnSetBitmap(); private: DECLARE_DYNAMIC_CLASS(wxBitmapButton) }; -#endif - #endif // __BMPBUTTONH__ diff --git a/include/wx/msw/bmpbuttn.h b/include/wx/msw/bmpbuttn.h index 8fae23b520..fa4233e801 100644 --- a/include/wx/msw/bmpbuttn.h +++ b/include/wx/msw/bmpbuttn.h @@ -16,60 +16,41 @@ #pragma interface "bmpbuttn.h" #endif -#if wxUSE_BMPBUTTON - #include "wx/button.h" #include "wx/bitmap.h" -WXDLLEXPORT_DATA(extern const wxChar*) wxButtonNameStr; - #define wxDEFAULT_BUTTON_MARGIN 4 -class WXDLLEXPORT wxBitmapButton: public wxButton +class WXDLLEXPORT wxBitmapButton: public wxBitmapButtonBase { - DECLARE_DYNAMIC_CLASS(wxBitmapButton) - public: - wxBitmapButton() { m_marginX = wxDEFAULT_BUTTON_MARGIN; m_marginY = wxDEFAULT_BUTTON_MARGIN; } - wxBitmapButton(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr) + wxBitmapButton() + { m_marginX = m_marginY = wxDEFAULT_BUTTON_MARGIN; } + wxBitmapButton(wxWindow *parent, + wxWindowID id, + const wxBitmap& bitmap, + 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); } - bool Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxBU_AUTODRAW, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); - - virtual void SetLabel(const wxBitmap& bitmap) - { - SetBitmapLabel(bitmap); - } - - virtual void SetBitmapLabel(const wxBitmap& bitmap); + bool Create(wxWindow *parent, + wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxBU_AUTODRAW, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxButtonNameStr); #if WXWIN_COMPATIBILITY - wxBitmap *GetBitmap() const { return (wxBitmap *) & m_buttonBitmap; } + wxBitmap *GetBitmap() const { return (wxBitmap *) & m_bmp; } #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 virtual void SetDefault(); 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 DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg ); -protected: - wxBitmap m_buttonBitmap; - wxBitmap m_buttonBitmapSelected; - wxBitmap m_buttonBitmapFocus; - wxBitmap m_buttonBitmapDisabled; - int m_marginX; - int m_marginY; +private: + DECLARE_DYNAMIC_CLASS(wxBitmapButton) }; -#endif // wxUSE_BMPBUTTON - #endif // _WX_BMPBUTTN_H_ diff --git a/include/wx/univ/bmpbuttn.h b/include/wx/univ/bmpbuttn.h new file mode 100644 index 0000000000..be001c62da --- /dev/null +++ b/include/wx/univ/bmpbuttn.h @@ -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_ + diff --git a/include/wx/univ/button.h b/include/wx/univ/button.h index 4283a5cc16..c2849199cf 100644 --- a/include/wx/univ/button.h +++ b/include/wx/univ/button.h @@ -18,6 +18,8 @@ class WXDLLEXPORT wxInputHandler; +#include "wx/bitmap.h" + // ---------------------------------------------------------------------------- // the actions supported by this control // ---------------------------------------------------------------------------- @@ -35,6 +37,21 @@ class WXDLLEXPORT wxButton : public wxButtonBase { public: 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, wxWindowID id, const wxString& label, @@ -56,20 +73,36 @@ public: const wxSize& size = wxDefaultSize, long style = 0, 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); virtual ~wxButton(); + virtual void SetImageLabel(const wxBitmap& bitmap); + virtual void SetImageMargins(wxCoord x, wxCoord y); virtual void SetDefault(); virtual bool IsPressed() const { return m_isPressed; } virtual bool IsDefault() const { return m_isDefault; } // wxButton actions - void Press(); - void Release(); void Toggle(); - void Click(); + virtual void Press(); + virtual void Release(); + virtual void Click(); protected: virtual bool PerformAction(const wxControlAction& action, @@ -80,9 +113,15 @@ protected: // common part of all ctors void Init(); + // current state bool m_isPressed, m_isDefault; + // the (optional) image to show and the margins around it + wxBitmap m_bitmap; + wxCoord m_marginBmpX, + m_marginBmpY; + private: DECLARE_DYNAMIC_CLASS(wxButton) }; diff --git a/include/wx/univ/control.h b/include/wx/univ/control.h index 45acd4fbdb..502e981933 100644 --- a/include/wx/univ/control.h +++ b/include/wx/univ/control.h @@ -124,7 +124,7 @@ public: int GetStateFlags() const; // operations - void SetCurrent(bool doit = TRUE); + virtual void SetCurrent(bool doit = TRUE); // implementation only from now on @@ -158,6 +158,9 @@ protected: // draw the controls contents 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 void OnMouse(wxMouseEvent& event); void OnKeyDown(wxKeyEvent& event); diff --git a/include/wx/univ/renderer.h b/include/wx/univ/renderer.h index 3047b774d1..d9734c02d3 100644 --- a/include/wx/univ/renderer.h +++ b/include/wx/univ/renderer.h @@ -259,13 +259,18 @@ public: wxControlRenderer(wxControl *control, wxDC& dc, wxRenderer *renderer); // operations - void DrawLabel(); + void DrawLabel(const wxBitmap& bitmap = wxNullBitmap, + wxCoord marginX = 0, wxCoord marginY = 0); void DrawBorder(); void DrawButtonBorder(); // the line must be either horizontal or vertical void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); void DrawFrame(); 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 DrawScrollbar(const wxScrollBar *scrollbar); @@ -277,9 +282,6 @@ public: const wxRect& GetRect() const { return m_rect; } wxRect& GetRect() { return m_rect; } -protected: - void DoDrawBitmap(const wxBitmap& bmp, int alignment, wxStretch stretch); - private: wxControl *m_ctrl; wxRenderer *m_renderer; diff --git a/include/wx/window.h b/include/wx/window.h index f4fc98faed..4ab8d4d35f 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -767,23 +767,20 @@ protected: static int WidthDefault(int w) { return w == -1 ? 20 : w; } static int HeightDefault(int h) { return h == -1 ? 20 : h; } - // sets the size to be size but take width and/or height from - // DoGetBestSize() if width/height of size is -1 - // - // NB: when calling this function from the ctor, the DoGetBestSize() of - // 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) + // set the best size for the control if the default size was given: + // replaces the fields of size == -1 with the best values for them and + // calls SetSize() if needed + void SetBestSize(const wxSize& size) { if ( size.x == -1 || size.y == -1 ) { - wxSize sizeDef = GetBestSize(); - SetSize( size.x == -1 ? sizeDef.x : size.x, - size.y == -1 ? sizeDef.y : size.y); - } - else - { - SetSize(size); + wxSize sizeBest = DoGetBestSize(); + if ( size.x != -1 ) + sizeBest.x = size.x; + if ( size.y != -1 ) + sizeBest.y = size.y; + + SetSize(sizeBest); } } diff --git a/samples/univ/open.xpm b/samples/univ/open.xpm new file mode 100644 index 0000000000..ae9bbff976 --- /dev/null +++ b/samples/univ/open.xpm @@ -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" +}; diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index c9027978ae..2baec4b40e 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -34,6 +34,7 @@ #include "wx/frame.h" #include "wx/dcclient.h" + #include "wx/bmpbuttn.h" #include "wx/button.h" #include "wx/scrolbar.h" #include "wx/statbmp.h" @@ -47,6 +48,7 @@ // ---------------------------------------------------------------------------- #include "wx/generic/tip.xpm" +#include "open.xpm" // ---------------------------------------------------------------------------- // constants @@ -201,12 +203,33 @@ MyUnivFrame::MyUnivFrame(const wxString& title) sb->SetScrollbar(0, 10, 100, 10); sb = new wxScrollBar(this, -1, wxPoint(200, 330), wxSize(-1, 150), wxSB_VERTICAL); 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) { - wxLogDebug(_T("Button %d pressed."), - event.GetId() == Univ_Button1 ? 1 : 2); + int btn = event.GetId(); + 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) diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 5e7c4e91b5..bb79e97b6d 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -241,7 +241,7 @@ void wxDCBase::DrawLabel(const wxString& text, { x = rect.GetRight() - width; } - else if ( alignment & wxALIGN_CENTRE ) + else if ( alignment & wxALIGN_CENTRE_HORIZONTAL ) { x = (rect.GetLeft() + rect.GetRight() - width) / 2; } diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index b056ecbcbd..45c93c15a2 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -119,9 +119,6 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi m_needParent = TRUE; m_acceptsFocus = TRUE; - m_marginX = - m_marginY = 0; - if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { @@ -129,10 +126,10 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi return FALSE; } - m_bitmap = bitmap; - m_disabled = bitmap; - m_focus = bitmap; - m_selected = bitmap; + m_bmpNormal = + m_bmpDisabled = + m_bmpFocus = + m_bmpSelected = bitmap; 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 ); #endif - if (m_bitmap.Ok()) + if (m_bmpNormal.Ok()) { wxSize newSize = size; GdkBitmap *mask = (GdkBitmap *) NULL; - if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); - GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); + if (m_bmpNormal.GetMask()) mask = m_bmpNormal.GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( m_bmpNormal.GetPixmap(), mask ); gtk_widget_show( pixmap ); gtk_container_add( GTK_CONTAINER(m_widget), pixmap ); int border = 10; if (style & wxNO_BORDER) border = 4; - if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border; - if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border; + if (newSize.x == -1) newSize.x = m_bmpNormal.GetWidth()+border; + if (newSize.y == -1) newSize.y = m_bmpNormal.GetHeight()+border; SetSize( newSize.x, newSize.y ); } @@ -210,28 +207,28 @@ void wxBitmapButton::ApplyWidgetStyle() void wxBitmapButton::SetBitmap() { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") ); wxBitmap the_one; if (!m_isEnabled) - the_one = m_disabled; + the_one = m_bmpDisabled; else { if (m_isSelected) { - the_one = m_selected; + the_one = m_bmpSelected; } else { if (m_hasFocus) - the_one = m_focus; + the_one = m_bmpFocus; 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; GtkButton *bin = GTK_BUTTON( m_widget ); @@ -243,43 +240,8 @@ void wxBitmapButton::SetBitmap() 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(); } diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index b056ecbcbd..45c93c15a2 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -119,9 +119,6 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi m_needParent = TRUE; m_acceptsFocus = TRUE; - m_marginX = - m_marginY = 0; - if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { @@ -129,10 +126,10 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi return FALSE; } - m_bitmap = bitmap; - m_disabled = bitmap; - m_focus = bitmap; - m_selected = bitmap; + m_bmpNormal = + m_bmpDisabled = + m_bmpFocus = + m_bmpSelected = bitmap; 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 ); #endif - if (m_bitmap.Ok()) + if (m_bmpNormal.Ok()) { wxSize newSize = size; GdkBitmap *mask = (GdkBitmap *) NULL; - if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); - GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); + if (m_bmpNormal.GetMask()) mask = m_bmpNormal.GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( m_bmpNormal.GetPixmap(), mask ); gtk_widget_show( pixmap ); gtk_container_add( GTK_CONTAINER(m_widget), pixmap ); int border = 10; if (style & wxNO_BORDER) border = 4; - if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border; - if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border; + if (newSize.x == -1) newSize.x = m_bmpNormal.GetWidth()+border; + if (newSize.y == -1) newSize.y = m_bmpNormal.GetHeight()+border; SetSize( newSize.x, newSize.y ); } @@ -210,28 +207,28 @@ void wxBitmapButton::ApplyWidgetStyle() void wxBitmapButton::SetBitmap() { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") ); wxBitmap the_one; if (!m_isEnabled) - the_one = m_disabled; + the_one = m_bmpDisabled; else { if (m_isSelected) { - the_one = m_selected; + the_one = m_bmpSelected; } else { if (m_hasFocus) - the_one = m_focus; + the_one = m_bmpFocus; 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; GtkButton *bin = GTK_BUTTON( m_widget ); @@ -243,43 +240,8 @@ void wxBitmapButton::SetBitmap() 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(); } diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index f7ecd01084..026ac0cee9 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -40,7 +40,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit const wxValidator& validator, const wxString& name) { - m_buttonBitmap = bitmap; + m_bmpNormal = bitmap; SetName(name); #if wxUSE_VALIDATORS @@ -52,8 +52,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit m_backgroundColour = parent->GetBackgroundColour(); m_foregroundColour = parent->GetForegroundColour(); m_windowStyle = style; - m_marginX = 0; - m_marginY = 0; if ( style & wxBU_AUTODRAW ) { @@ -113,11 +111,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit return TRUE; } -void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) -{ - m_buttonBitmap = bitmap; -} - // VZ: should be at the very least less than wxDEFAULT_BUTTON_MARGIN #define FOCUS_MARGIN 3 @@ -143,14 +136,14 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item) // choose the bitmap to use depending on the button state wxBitmap* bitmap; - if ( isSelected && m_buttonBitmapSelected.Ok() ) - bitmap = &m_buttonBitmapSelected; - else if ((state & ODS_FOCUS) && m_buttonBitmapFocus.Ok()) - bitmap = &m_buttonBitmapFocus; - else if ((state & ODS_DISABLED) && m_buttonBitmapDisabled.Ok()) - bitmap = &m_buttonBitmapDisabled; + if ( isSelected && m_bmpSelected.Ok() ) + bitmap = &m_bmpSelected; + else if ((state & ODS_FOCUS) && m_bmpFocus.Ok()) + bitmap = &m_bmpFocus; + else if ((state & ODS_DISABLED) && m_bmpDisabled.Ok()) + bitmap = &m_bmpDisabled; else - bitmap = &m_buttonBitmap; + bitmap = &m_bmpNormal; if ( !bitmap->Ok() ) return FALSE; diff --git a/src/univ/bmpbuttn.cpp b/src/univ/bmpbuttn.cpp new file mode 100644 index 0000000000..7698bddd72 --- /dev/null +++ b/src/univ/bmpbuttn.cpp @@ -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 + diff --git a/src/univ/button.cpp b/src/univ/button.cpp index b169fdbda5..aadcbde566 100644 --- a/src/univ/button.cpp +++ b/src/univ/button.cpp @@ -39,6 +39,14 @@ #include "wx/univ/inphand.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 // ============================================================================ @@ -57,6 +65,7 @@ void wxButton::Init() bool wxButton::Create(wxWindow *parent, wxWindowID id, + const wxBitmap& bitmap, const wxString &label, const wxPoint &pos, const wxSize &size, @@ -67,20 +76,26 @@ bool wxButton::Create(wxWindow *parent, // center label by default 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) ) return FALSE; SetLabel(label); - - if ( size.x == -1 || size.y == -1 ) - { - wxSize sizeBest = DoGetBestSize(); - SetSize(size.x == -1 ? sizeBest.x : size.x, - size.y == -1 ? sizeBest.y : size.y); - } + SetImageLabel(bitmap); + SetBestSize(size); return TRUE; } @@ -99,9 +114,17 @@ wxSize wxButton::DoGetBestSize() const wxCoord width, height; dc.GetMultiLineTextExtent(GetLabel(), &width, &height); - wxSize sz(width, height); - wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this); - return sz; + if ( m_bitmap.Ok() ) + { + // 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) { renderer->DrawButtonBorder(); - renderer->DrawLabel(); + renderer->DrawLabel(m_bitmap, m_marginBmpX, m_marginBmpY); } // ---------------------------------------------------------------------------- @@ -130,7 +153,10 @@ void wxButton::Release() void wxButton::Toggle() { - m_isPressed = !m_isPressed; + if ( m_isPressed ) + Release(); + else + Press(); 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() { m_isDefault = TRUE; diff --git a/src/univ/control.cpp b/src/univ/control.cpp index fb362cff44..b747e71a7e 100644 --- a/src/univ/control.cpp +++ b/src/univ/control.cpp @@ -139,6 +139,17 @@ int wxControl::GetStateFlags() const return flags; } +// ---------------------------------------------------------------------------- +// size +// ---------------------------------------------------------------------------- + +wxSize wxControl::AdjustSize(const wxSize& size) const +{ + wxSize sz = size; + wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this); + return sz; +} + // ---------------------------------------------------------------------------- // mnemonics handling // ---------------------------------------------------------------------------- @@ -267,7 +278,8 @@ void wxControl::DoDraw(wxControlRenderer *renderer) void wxControl::OnFocus(wxFocusEvent& event) { - Refresh(); + // do nothing here for now... + event.Skip(); } // ---------------------------------------------------------------------------- diff --git a/src/univ/files.lst b/src/univ/files.lst index adce45ff63..b7d35978cc 100644 --- a/src/univ/files.lst +++ b/src/univ/files.lst @@ -1,4 +1,5 @@ UNIVOBJS = \ + bmpbuttn.o \ button.o \ colschem.o \ control.o \ @@ -14,6 +15,7 @@ UNIVOBJS = \ win32.o UNIVDEPS = \ + bmpbuttn.d \ button.d \ colschem.d \ control.d \ diff --git a/src/univ/inphand.cpp b/src/univ/inphand.cpp index 1dfd42102a..9f0571aef8 100644 --- a/src/univ/inphand.cpp +++ b/src/univ/inphand.cpp @@ -156,8 +156,11 @@ wxControlActions wxStdButtonInputHandler::Map(wxControl *control, } else // up { - m_winCapture->ReleaseMouse(); - m_winCapture = NULL; + if ( m_winCapture ) + { + m_winCapture->ReleaseMouse(); + m_winCapture = NULL; + } if ( m_winHasMouse ) { diff --git a/src/univ/renderer.cpp b/src/univ/renderer.cpp index 2cf9d6c2ad..8120fa1ef7 100644 --- a/src/univ/renderer.cpp +++ b/src/univ/renderer.cpp @@ -186,17 +186,39 @@ void wxControlRenderer::DrawBorder() 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.SetTextForeground(m_ctrl->GetForegroundColour()); - m_renderer->DrawLabel(m_dc, - m_ctrl->GetLabel(), - m_rect, - m_ctrl->GetStateFlags(), - m_ctrl->GetAlignment(), - m_ctrl->GetAccelIndex()); + wxRect rectLabel = m_rect; + if ( bitmap.Ok() ) + { + wxRect rectBmp; + int width = bitmap.GetWidth(); + 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() @@ -225,9 +247,9 @@ void wxControlRenderer::DrawButtonBorder() void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap) { int style = m_ctrl->GetWindowStyle(); - DoDrawBitmap(bitmap, - style & wxALIGN_MASK, - style & wxBI_EXPAND ? wxEXPAND : wxSTRETCH_NOT); + DrawBitmap(bitmap, m_rect, + style & wxALIGN_MASK, + style & wxBI_EXPAND ? wxEXPAND : wxSTRETCH_NOT); } void wxControlRenderer::DrawBackgroundBitmap() @@ -237,13 +259,16 @@ void wxControlRenderer::DrawBackgroundBitmap() wxStretch stretch; wxBitmap bmp = m_ctrl->GetBackgroundBitmap(&alignment, &stretch); - DoDrawBitmap(bmp, alignment, stretch); + DrawBitmap(bmp, m_rect, alignment, stretch); } -void wxControlRenderer::DoDrawBitmap(const wxBitmap& bmp, - int alignment, - wxStretch stretch) +void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap, + const wxRect& rect, + int alignment, + wxStretch stretch) { + // we may change the bitmap if we stretch it + wxBitmap bmp = bitmap; if ( !bmp.Ok() ) return; @@ -255,9 +280,9 @@ void wxControlRenderer::DoDrawBitmap(const wxBitmap& bmp, if ( stretch & wxTILE ) { // 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); } @@ -266,34 +291,34 @@ void wxControlRenderer::DoDrawBitmap(const wxBitmap& bmp, else if ( stretch & wxEXPAND ) { // 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 { if ( alignment & wxALIGN_RIGHT ) { - x = m_rect.GetRight() - width; + x = rect.GetRight() - width; } 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 { - x = m_rect.GetLeft(); + x = rect.GetLeft(); } if ( alignment & wxALIGN_BOTTOM ) { - y = m_rect.GetBottom() - height; + y = rect.GetBottom() - height; } 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 { - y = m_rect.GetTop(); + y = rect.GetTop(); } } diff --git a/src/univ/scrolbar.cpp b/src/univ/scrolbar.cpp index cfe348f1ca..c202027b14 100644 --- a/src/univ/scrolbar.cpp +++ b/src/univ/scrolbar.cpp @@ -162,9 +162,8 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, wxSize wxScrollBar::DoGetBestSize() const { - wxSize sz(140, 140); - wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this); - return sz; + // completely arbitrary + return AdjustSize(wxSize(140, 140)); } // ---------------------------------------------------------------------------- diff --git a/src/univ/statbmp.cpp b/src/univ/statbmp.cpp index f88615465e..9574d6ecf4 100644 --- a/src/univ/statbmp.cpp +++ b/src/univ/statbmp.cpp @@ -64,16 +64,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, SetBitmap(label); // and adjust our size to fit it after this - if ( size.x == -1 || size.y == -1 ) - { - wxSize sizeBest = DoGetBestSize(); - if ( size.x != -1 ) - sizeBest.x = size.x; - if ( size.y != -1 ) - sizeBest.y = size.y; - - SetSize(sizeBest); - } + SetBestSize(size); return TRUE; } @@ -113,9 +104,7 @@ wxIcon wxStaticBitmap::GetIcon() const wxSize wxStaticBitmap::DoGetBestSize() const { - wxSize sz = wxStaticBitmapBase::DoGetBestSize(); - wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this); - return sz; + return AdjustSize(wxStaticBitmapBase::DoGetBestSize()); } void wxStaticBitmap::DoDraw(wxControlRenderer *renderer) diff --git a/src/univ/stattext.cpp b/src/univ/stattext.cpp index ee40d60f47..ec7dd1c97a 100644 --- a/src/univ/stattext.cpp +++ b/src/univ/stattext.cpp @@ -84,9 +84,7 @@ wxSize wxStaticText::DoGetBestSize() const wxCoord width, height; dc.GetMultiLineTextExtent(GetLabel(), &width, &height); - wxSize sz(width, height); - wxTheme::Get()->GetRenderer()->AdjustSize(&sz, this); - return sz; + return AdjustSize(wxSize(width, height)); } // ---------------------------------------------------------------------------- diff --git a/src/univ/themes/gtk.cpp b/src/univ/themes/gtk.cpp index 372134dbbd..85487d6355 100644 --- a/src/univ/themes/gtk.cpp +++ b/src/univ/themes/gtk.cpp @@ -249,7 +249,7 @@ wxInputHandler *wxGTKTheme::GetInputHandler(const wxString& control) // create a new handler n = m_handlerNames.Add(control); - if ( control == _T("wxButton") ) + if ( control.Matches(_T("wx*Button")) ) handler = new wxStdButtonInputHandler(GetInputHandler(_T("wxControl"))); else if ( control == _T("wxScrollBar") ) handler = new wxGTKScrollBarInputHandler(m_renderer, @@ -284,7 +284,7 @@ wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col, case CONTROL: if ( flags & wxCONTROL_PRESSED ) { - return wxColour(0x7f7f7f); + return wxColour(0xc3c3c3); } else if ( flags & wxCONTROL_CURRENT ) { @@ -892,9 +892,14 @@ void wxGTKRenderer::AdjustSize(wxSize *size, const wxWindow *window) { if ( wxDynamicCast(window, wxButton) ) { - // TODO + // TODO: this is ad hoc... 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 { diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 2d9a1a714b..ec20b897e5 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -283,7 +283,7 @@ wxInputHandler *wxWin32Theme::GetInputHandler(const wxString& control) // create a new handler n = m_handlerNames.Add(control); - if ( control == _T("wxButton") ) + if ( control.Matches(_T("wx*Button")) ) handler = new wxStdButtonInputHandler(GetInputHandler(_T("wxControl"))); else if ( control == _T("wxScrollBar") ) handler = new wxWin32ScrollBarInputHandler(m_renderer,