wxCamArtControl Class Reference

A base class for controls using the CamArtProvider to paint themselves Notes: In the OIL See Also:. More...

#include <cartctl.h>

List of all members.

Public Member Functions

BOOL Create (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, wxCamArtControlStyle cacstyle=wxCACS_DEFAULT, wxString opdesc=wxString(_T("")))
 Initialize the control.
void Init ()
 wxCamArtControl ()
 wxCamArtControl (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, wxCamArtControlStyle cacstyle=wxCACS_DEFAULT, wxString opdesc=wxString(_T("")))
 ~wxCamArtControl ()
wxSize DoGetBestSize () const
 Initialize resources.
void OnPaint (wxPaintEvent &event)
 Paints the control.
void OnMouseEvent (wxMouseEvent &event)
 Handles mouse events.
void OnTimer (wxTimerEvent &event)
 Handles autorepeat timer events.
void OnInvoke (wxCamArtControlEvent &event)
 Handles deferred invoke events.
void NewBitmap ()
virtual void SetStyle (wxCamArtControlStyle style)
virtual wxCamArtControlStyle GetStyle () const
virtual void SetValue (UINT32 value)
virtual UINT32 GetValue ()
virtual bool Enable (boolenable=true)
virtual void SetLabel (const wxString &label)
wxString GetOpDesc ()
const ResourceID GetBitmapId ()
void SetBitmapId (ResourceID r=0)

Protected Member Functions

void Invoke ()
 Does the work of the button being pressed.
void FindBitmap ()
 Find the bitmap associated with the control, and set our cached size.
CamArtFlags GetArtFlags ()

Protected Attributes

wxCamArtControlStyle m_CamArtControlStyle
UINT32 m_Value
wxSize m_BestSize
CamArtFlags m_State
wxTimer m_Timer
UINT32 m_ARDelay
UINT32 m_ARRepeat
BOOL m_AREventPending
wxString m_OpDesc
ResourceID m_BitmapId


Detailed Description

A base class for controls using the CamArtProvider to paint themselves Notes: In the OIL See Also:.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
19/12/2005
This class is specificly written so it will provided cached vector-drawn art.

Definition at line 175 of file cartctl.h.


Constructor & Destructor Documentation

wxCamArtControl::wxCamArtControl  )  [inline]
 

Definition at line 201 of file cartctl.h.

00201 { Init(); }

wxCamArtControl::wxCamArtControl wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxValidator &  validator = wxDefaultValidator,
wxCamArtControlStyle  cacstyle = wxCACS_DEFAULT,
wxString  opdesc = wxString(_T(""))
[inline]
 

Definition at line 202 of file cartctl.h.

00203                                : Correct*/ long style = 0, const wxValidator& validator = wxDefaultValidator,
00204                      wxCamArtControlStyle cacstyle = wxCACS_DEFAULT,
00205                      wxString opdesc = wxString(_T("")))
00206                     {
00207                         Init();
00208                         ControlList::Get()->NewControl(this);
00209                         Create(parent, id, pos, size, style, validator, cacstyle, opdesc);
00210                     }

wxCamArtControl::~wxCamArtControl  )  [inline]
 

Definition at line 211 of file cartctl.h.

00211 { m_Timer.Stop(); }


Member Function Documentation

BOOL wxCamArtControl::Create wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxValidator &  validator = wxDefaultValidator,
wxCamArtControlStyle  cacstyle = wxCACS_DEFAULT,
wxString  opdesc = wxString(_T(""))
 

Initialize the control.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
parent - parent window [INPUTS] id - id to use pos - position size - size style - style validator - validator (up to here, all the same as wxControl) cacstyle - the style of CamArtControl to use, i.e. the flags passed opdesc - the opdescriptor to use, OR the empty string
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Definition at line 152 of file cartctl.cpp.

00153                                : Correct*/ long style, const wxValidator& validator,
00154                      wxCamArtControlStyle cacstyle,
00155                      wxString opdesc)
00156 {
00157     if (!wxControl::Create(parent, id, pos, size, style, validator))
00158         return FALSE;
00159 
00160     // Complete bodge to default to small button bars but large toolbars
00161     if (!(cacstyle & wxCACS_TOOLBACKGROUND))
00162         cacstyle = (wxCamArtControlStyle)(cacstyle | CAF_SMALL);
00163 
00164     m_CamArtControlStyle = cacstyle;
00165     m_OpDesc = opdesc;
00166     FindBitmap();
00167     return TRUE;
00168 }

wxSize wxCamArtControl::DoGetBestSize  )  const
 

Initialize resources.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
The best size for the control

Errors: via wxMessageBox

See also:
-

Definition at line 186 of file cartctl.cpp.

00187 {
00188     ((wxCamArtControl *)this)->FindBitmap();
00189 
00190     wxSize ret = m_BestSize; // ret( wxControl::DoGetBestSize() );
00191 
00192     if ((GetStyle() & wxCACS_TEXT) && (!(GetStyle() & wxCACS_EXACTFIT)))
00193     {
00194         wxSize DefaultSize;
00195         DefaultSize=wxButton::GetDefaultSize();
00196         if (GetStyle() & wxCACS_HALFHEIGHT)
00197             DefaultSize.y = (DefaultSize.y/2)-2;
00198         if (ret.x < DefaultSize.x) ret.x = DefaultSize.x;
00199         if (ret.y < DefaultSize.y) ret.y = DefaultSize.y;
00200     }
00201 
00202     CacheBestSize(ret);
00203     return ret;
00204 }

virtual bool wxCamArtControl::Enable bool  enable = true  )  [inline, virtual]
 

Definition at line 237 of file cartctl.h.

00237                       : Correct*/ bool Enable(bool /*TYPENOTE: Correct*/ enable = true)
00238         {
00239             if (!enable)
00240             {
00241                 m_State = (CamArtFlags)(m_State & ~CAF_BUTTONHOVER);
00242                 m_Timer.Stop(); // Don't process more events
00243             }
00244             return wxControl::Enable(enable);
00245         }

void wxCamArtControl::FindBitmap  )  [protected]
 

Find the bitmap associated with the control, and set our cached size.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
None

Errors: -

See also:
-

Definition at line 222 of file cartctl.cpp.

00223 {
00224     m_BestSize=(CamArtProvider::Get())->GetSize(GetBitmapId(), GetArtFlags(), GetLabel());
00225     return;
00226 }

CamArtFlags wxCamArtControl::GetArtFlags  )  [inline, protected]
 

Definition at line 270 of file cartctl.h.

00270 {return (CamArtFlags)(m_CamArtControlStyle | m_State | (IsEnabled()?0:CAF_GREYED));}

const ResourceID wxCamArtControl::GetBitmapId  )  [inline]
 

Definition at line 251 of file cartctl.h.

00251 {return m_BitmapId?m_BitmapId:GetId();}

wxString wxCamArtControl::GetOpDesc  )  [inline]
 

Definition at line 249 of file cartctl.h.

00249 {return m_OpDesc;}

virtual wxCamArtControlStyle wxCamArtControl::GetStyle  )  const [inline, virtual]
 

Definition at line 225 of file cartctl.h.

00225 { return m_CamArtControlStyle;}

virtual UINT32 wxCamArtControl::GetValue  )  [inline, virtual]
 

Definition at line 234 of file cartctl.h.

00234 { return m_Value;}

void wxCamArtControl::Init void   )  [inline]
 

Definition at line 187 of file cartctl.h.

00187                 {
00188                     m_Value=0;
00189                     m_CamArtControlStyle=wxCACS_DEFAULT;
00190                     m_BestSize=wxDefaultSize;
00191                     m_State=CAF_DEFAULT;
00192                     m_OpDesc=wxString(_T(""));
00193                     m_Timer.SetOwner(this, _R(IDC_WXCAMARTCONTROL_AUTOREPEAT));
00194                     m_ARDelay=500;
00195                     m_ARRepeat=50;
00196                     m_AREventPending=FALSE;
00197                     m_BitmapId=0;
00198                 }

void wxCamArtControl::Invoke  )  [protected]
 

Does the work of the button being pressed.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
We send ourselves our COMMAND event (which DialogManager picks up) and invoke the op descriptor attached ourselves.

Definition at line 430 of file cartctl.cpp.

00431 {
00432     if (!IsEnabled())
00433     {
00434         m_Timer.Stop();
00435         return; // Don't even send messages if the control is greyed
00436     }
00437 
00438     wxCommandEvent ButtonEvent(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
00439     ProcessEvent(ButtonEvent);
00440     // If it's attached to an OpDescriptor, we invoke it.
00441 //  ControlList::/*Get*/()->Invoke(this);
00442 }

void wxCamArtControl::NewBitmap  )  [inline]
 

Definition at line 222 of file cartctl.h.

00222 {FindBitmap(); Refresh();}

void wxCamArtControl::OnInvoke wxCamArtControlEvent event  ) 
 

Handles deferred invoke events.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the event [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
We do not process these immediately because otherwise the application does not have a chance to redraw between undo etc. Instead we send a deferred message back to ourselves

Definition at line 400 of file cartctl.cpp.

00401 {
00402     m_AREventPending = FALSE;
00403     if (!::wxGetMouseState().LeftDown())
00404     {
00405         m_Timer.Stop();
00406         return;
00407     }
00408     Invoke();
00409 }

void wxCamArtControl::OnMouseEvent wxMouseEvent &  event  ) 
 

Handles mouse events.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the event [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 269 of file cartctl.cpp.

00270 {
00271     CamArtFlags OldState = m_State;
00272     BOOL ButtonClick=FALSE;
00273 
00274     if ((m_CamArtControlStyle & wxCACS_PUSHBUTTON) && IsEnabled())
00275     {
00276         if (event.LeftDown() || event.LeftDClick())
00277         {
00278             if (m_CamArtControlStyle & wxCACS_TOGGLEBUTTON)
00279                 m_State = (CamArtFlags)(m_State ^ CAF_SELECTED);
00280             else
00281                 m_State = (CamArtFlags)(m_State | CAF_SELECTED);
00282             ButtonClick=TRUE;
00283         }
00284         else if (event.LeftUp())
00285         {
00286             if (!(m_CamArtControlStyle & wxCACS_TOGGLEBUTTON))
00287                 m_State = (CamArtFlags)(m_State & ~CAF_SELECTED);
00288             m_Timer.Stop();
00289         }
00290         else if (event.Leaving())
00291         {
00292             if (!(m_CamArtControlStyle & wxCACS_TOGGLEBUTTON))
00293                 m_State = (CamArtFlags)(m_State & ~CAF_SELECTED);
00294             m_State = (CamArtFlags)(m_State & ~CAF_BUTTONHOVER);
00295             m_Timer.Stop();
00296         }
00297         else if (event.Entering())
00298         {
00299             if (m_CamArtControlStyle & wxCACS_ALLOWHOVER)
00300                 m_State = (CamArtFlags)(m_State | CAF_BUTTONHOVER);
00301         }
00302         m_Value=(m_State & CAF_SELECTED)?1:0;
00303     }
00304 
00305     // Irritatingly wxMouseEvent does not propagate to the parent, but we expect it to.
00306     // so we have to fake it (sigh)
00307     // event.Skip(); // pretend we did not handle it, so it falls through to the dialog
00308 
00309     if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
00310     {
00311         wxWindow * pParent = GetParent();
00312         if (pParent && !pParent->IsBeingDeleted())
00313         {
00314             wxEvtHandler *pHandler = pParent->GetEventHandler();
00315             if (pHandler && pHandler->IsKindOf(CLASSINFO(DialogEventHandler))) // Only propagate to our own dialogs
00316             {
00317                 pHandler->ProcessEvent(event);
00318             }
00319         }
00320     }
00321 
00322     if (m_State != OldState)
00323     {
00324         Refresh();
00325     }
00326 
00327     if (ButtonClick)
00328     {
00329         Invoke();
00330         if (IsEnabled() && !(m_CamArtControlStyle & wxCACS_TOGGLEBUTTON) && !(m_CamArtControlStyle & wxCACS_NOAUTOREPEAT)) // Toggle buttons don't autorepeat
00331         {
00332             // We start the timer at the end, as the Op may be an INT32 one
00333             m_AREventPending = FALSE; // Just in case an event got lost in flight
00334             m_Timer.Start(m_ARDelay, TRUE);
00335         }
00336     }
00337 }

void wxCamArtControl::OnPaint wxPaintEvent &  event  ) 
 

Paints the control.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the event [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 244 of file cartctl.cpp.

00245 {
00246     wxPaintDC dc(this);
00247 
00248     wxRect rect = GetClientRect();
00249     CamArtProvider::Get()->Draw(dc, rect, GetBitmapId(), GetArtFlags(), GetLabel());
00250 }

void wxCamArtControl::OnTimer wxTimerEvent &  event  ) 
 

Handles autorepeat timer events.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the event [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
We do not process these immediately because otherwise the application does not have a chance to redraw between undo etc. Instead we send a deferred message back to ourselves

Definition at line 358 of file cartctl.cpp.

00359 {
00360     m_Timer.Stop();
00361 
00362     if (!IsEnabled())
00363         return; // Don't even send messages if the control is greyed
00364 
00365     // Sadly, what can happen is that the Op can set in place a redraw, and during the redraw
00366     // the button will left. But our timer gets her first. So we have to check whether the
00367     // button is still down
00368     if (!::wxGetMouseState().LeftDown())
00369         return;
00370 
00371     if (!m_AREventPending) // don't process if another event was pending
00372     {
00373         m_AREventPending = TRUE;
00374         wxCamArtControlEvent evt(wxEVT_CAMARTCONTROL_INVOKE, GetId());
00375         GetEventHandler()->AddPendingEvent(evt); // Send it off deferred
00376     }
00377 
00378     m_Timer.Start(m_ARRepeat, FALSE);
00379 }

void wxCamArtControl::SetBitmapId ResourceID  r = 0  )  [inline]
 

Definition at line 252 of file cartctl.h.

00252 {m_BitmapId=r; NewBitmap();}

virtual void wxCamArtControl::SetLabel const wxString &  label  )  [inline, virtual]
 

Definition at line 247 of file cartctl.h.

00247 {if (label!=GetLabel()) {wxControl::SetLabel(label); Refresh(TRUE);}}

virtual void wxCamArtControl::SetStyle wxCamArtControlStyle  style  )  [inline, virtual]
 

Definition at line 224 of file cartctl.h.

00224 { m_CamArtControlStyle=style; NewBitmap(); }

virtual void wxCamArtControl::SetValue UINT32  value  )  [inline, virtual]
 

Definition at line 227 of file cartctl.h.

00228         {
00229             m_Value=value;
00230             CamArtFlags o=m_State;
00231             if (value) m_State=(CamArtFlags)(m_State | CAF_SELECTED); else m_State =(CamArtFlags)(m_State & ~CAF_SELECTED);
00232             if (o!=m_State) Refresh();
00233         }


Member Data Documentation

UINT32 wxCamArtControl::m_ARDelay [protected]
 

Definition at line 261 of file cartctl.h.

BOOL wxCamArtControl::m_AREventPending [protected]
 

Definition at line 263 of file cartctl.h.

UINT32 wxCamArtControl::m_ARRepeat [protected]
 

Definition at line 262 of file cartctl.h.

wxSize wxCamArtControl::m_BestSize [protected]
 

Definition at line 257 of file cartctl.h.

ResourceID wxCamArtControl::m_BitmapId [protected]
 

Definition at line 272 of file cartctl.h.

wxCamArtControlStyle wxCamArtControl::m_CamArtControlStyle [protected]
 

Definition at line 255 of file cartctl.h.

wxString wxCamArtControl::m_OpDesc [protected]
 

Definition at line 265 of file cartctl.h.

CamArtFlags wxCamArtControl::m_State [protected]
 

Definition at line 258 of file cartctl.h.

wxTimer wxCamArtControl::m_Timer [protected]
 

Definition at line 260 of file cartctl.h.

UINT32 wxCamArtControl::m_Value [protected]
 

Definition at line 256 of file cartctl.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:03:15 2007 for Camelot by  doxygen 1.4.4