Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

toolbutton.cpp

Go to the documentation of this file.
00001 
00002 // Name:        generic/wxToolButton.cpp
00003 // Purpose:     wxToolButton implementation.
00004 // Author:      Mark McCormack
00005 // Modified by:
00006 // Created:     19/05/04
00007 // RCS-ID:      $Id: toolbutton.cpp,v 1.5 2005/05/12 14:04:48 frm Exp $
00008 // Copyright:   (c) 2004 Mark McCormack
00009 // Licence:     wxWindows license
00011 
00012 #include <wx/toolbutton.h>
00013 
00014 #ifdef wxEX_USE_GENERIC_TOOLBUTTON
00015 
00016 #include <wx/gdi.h>
00017 #include <wx/dcclient.h>
00018 #include <wx/settings.h>
00019 
00020 // XXX: it doesn't seem to be possible to click this button quickly on
00021 // wxMSW (is this the 'double-click' event handling of Windows getting in the way?)
00022 
00023 // ----------------------------------------------------------------------------
00024 // wxToolButton implementation
00025 // ----------------------------------------------------------------------------
00026 
00027 IMPLEMENT_DYNAMIC_CLASS( wxToolButton, wxControl )
00028 
00029 BEGIN_EVENT_TABLE( wxToolButton, wxControl )
00030     EVT_ERASE_BACKGROUND( wxToolButton::OnErase )
00031     EVT_PAINT( wxToolButton::OnPaint )
00032     EVT_LEFT_DOWN( wxToolButton::OnLeftDown )
00033     EVT_LEFT_UP( wxToolButton::OnLeftUp )
00034     EVT_ENTER_WINDOW( wxToolButton::OnEnter ) 
00035     EVT_LEAVE_WINDOW( wxToolButton::OnLeave ) 
00036 END_EVENT_TABLE()
00037 
00038 // ----------------------------------------------------------------------------
00039 
00040 bool wxToolButton::Create( wxWindow *parent,
00041                            wxWindowID id,
00042                            const wxPoint& pos,
00043                            const wxSize& size,
00044                            long style,
00045                            const wxString& name ) {
00046 
00047     // create the controls
00048     if( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) {
00049         return FALSE;
00050     }
00051     SetSizeHints(size);
00052     
00053     return TRUE;
00054 }
00055 
00056 wxToolButton::~wxToolButton() {
00057 }
00058 
00059 void wxToolButton::Init() {
00060     // init.
00061     pressed_ = false;
00062     hovered_ = false;
00063 
00064     wxToolButtonBase::Init();       
00065 }
00066 
00067 void wxToolButton::OnErase( wxEraseEvent& event ) {
00068     // skip erase
00069 }
00070 
00071 void wxToolButton::OnPaint( wxPaintEvent& event ) {
00072     wxPaintDC dc(this);
00073     wxRect cr = GetClientRect();
00074     g_gdi.DrawBackground( dc, cr );
00075 
00076  if( hovered_ ) {
00077         wxRect cr = GetClientRect();
00078         wxColour raisedColour = wxSystemSettings::GetColour( pressed_ ? wxSYS_COLOUR_3DDKSHADOW : wxSYS_COLOUR_3DHIGHLIGHT );
00079   wxPen raisedPen( raisedColour, 1, 1 );
00080         wxColour shadowColour = wxSystemSettings::GetColour( pressed_ ? wxSYS_COLOUR_3DHIGHLIGHT : wxSYS_COLOUR_3DDKSHADOW );
00081   wxPen shadowPen( shadowColour, 1, 1 );
00082         cr.width--;
00083         cr.height--;
00084         cr.Deflate( drawMargin_, drawMargin_ ) ;
00085 
00086         // draw top-left
00087         dc.SetPen( raisedPen );
00088         dc.DrawLine( cr.x, cr.y, cr.width, cr.y );
00089         dc.DrawLine( cr.x, cr.y, cr.x, cr.height );
00090 
00091         // draw bottom-right
00092         dc.SetPen( shadowPen );
00093         dc.DrawLine( cr.width, cr.y, cr.width, cr.height+1 );
00094         dc.DrawLine( cr.x, cr.height, cr.width+1, cr.height );
00095  }
00096     
00097     // draw cross
00098     if( pressed_ & hovered_ ) cr.Offset( 1, 1 );
00099     drawButtonImage( dc, cr );
00100 }
00101 
00102 void wxToolButton::OnEnter( wxMouseEvent& event ) {
00103     hovered_ = true;
00104     Refresh();
00105 }
00106 
00107 void wxToolButton::OnLeave( wxMouseEvent& event ) {
00108     hovered_ = false;
00109     Refresh();
00110 }
00111 
00112 void wxToolButton::OnLeftDown( wxMouseEvent& event ) {
00113     pressed_ = true;
00114     CaptureMouse();
00115     Refresh();
00116 }
00117 
00118 void wxToolButton::OnLeftUp( wxMouseEvent& event ) {
00119     if( pressed_ ) {
00120         pressed_ = false;
00121         ReleaseMouse();
00122         Refresh();
00123         if( hovered_ ) {
00124             sendClickEvent();
00125         }
00126     }
00127 }
00128 
00129 #endif  // wxEX_USE_GENERIC_TOOLBUTTON

Generated on Sat May 14 14:54:39 2005 for wxDockIt by  doxygen 1.4.2