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

toolbutton.h

Go to the documentation of this file.
00001 
00002 // Name:        wx/toolbutton.h
00003 // Purpose:     wxToolButtonBase class
00004 // Author:      Mark McCormack
00005 // Modified by: Francesco Montorsi
00006 // Created:     10/04/04
00007 // RCS-ID:      $Id: toolbutton.h,v 1.8 2005/05/12 14:02:29 frm Exp $
00008 // Copyright:   (c) 2004 Mark McCormack
00009 // Licence:     wxWindows licence
00011 
00012 //#define wxEX_USE_GENERIC_TOOLBUTTON   // - intended for debugging on wxMSW only
00013 
00014 #ifndef _WX_TOOLBUTTONBASE_H_
00015 #define _WX_TOOLBUTTONBASE_H_
00016 
00017 // ----------------------------------------------------------------------------
00018 // headers
00019 // ----------------------------------------------------------------------------
00020 
00021 #include <wx/defs.h>
00022 #include <wx/control.h>
00023 #include <wx/settings.h>
00024 #include <wx/gdi.h>
00025 #include "wx/export.h"
00026 
00027 // not required since wxButtonNameStr is already defined in button.h
00028 //extern WXDLLIMPEXP_DATA_DI(const wxChar*) wxButtonNameStr;
00029 
00030 #define wxDEFAULT_DRAW_SIZE             8
00031 
00032 // ----------------------------------------------------------------------------
00033 // wxToolButtonBase
00034 // ----------------------------------------------------------------------------
00035 
00036 class WXDLLIMPEXP_DI wxToolButtonBase : public wxControl
00037 {
00038 public:
00039     virtual void Init() {
00040         drawMargin_ = 0;
00041         drawSize_ = wxDEFAULT_DRAW_SIZE;
00042     }
00043 
00044     void SetDrawMargin( int drawMargin ) { drawMargin_ = drawMargin; }
00045     void SetDrawSize( int drawSize ) { drawSize_ = drawSize; }
00046     void SetBitmap( wxBitmap &bitmap ) { bitmap_ = bitmap; }
00047     
00048 protected:
00049     bool sendClickEvent() {
00050         // create the button-click event
00051         wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, GetId() );
00052         event.SetEventObject( this );
00053         return GetEventHandler()->ProcessEvent( event );
00054     }
00055 
00056     void drawButtonImage( wxDC &dc, wxRect& rect ) {
00057         if( bitmap_.Ok() ) {
00058             // draw custom image (centered)
00059             int ox = (rect.width / 2) - (bitmap_.GetWidth() / 2) + rect.x;
00060             int oy = (rect.height / 2) - (bitmap_.GetHeight() / 2) + rect.y;
00061             dc.DrawBitmap( bitmap_, ox, oy, true );
00062         }
00063         else {
00064             // for now, do a cross if no bitmap
00065          wxColour crossColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
00066          wxPen pen( crossColour, 1, 1 );
00067             g_gdi.DrawClose( dc, rect, pen, drawSize_ );
00068        }
00069     }
00070 
00071 protected:
00072     int drawMargin_;
00073     int drawSize_;
00074     wxBitmap bitmap_;
00075 };
00076 
00077 // ----------------------------------------------------------------------------
00078 // include the platform-specific class declaration
00079 // ----------------------------------------------------------------------------
00080 
00081 #ifdef wxEX_USE_GENERIC_TOOLBUTTON
00082     #include "wx/generic/toolbutton.h"    
00083 #else
00084     #if defined(__WXMSW__)
00085         #include "wx/msw/toolbutton.h"                
00086     #else
00087         // other platform-specific implementation are not currently available...
00088         #define wxEX_USE_GENERIC_TOOLBUTTON
00089         #include "wx/generic/toolbutton.h"        
00090     #endif
00091 #endif
00092 
00093 #endif
00094     // _WX_TOOLBUTTONBASE_H_

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