avoid conflict between wxBookCtrlBase::DoSetSelection() and the derived classes;...
[wxWidgets.git] / include / wx / gtk / animate.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/animate.h
3 // Purpose: Animation classes
4 // Author: Julian Smart and Guillermo Rodriguez Garcia
5 // Modified by: Francesco Montorsi
6 // Created: 13/8/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GTKANIMATEH__
13 #define _WX_GTKANIMATEH__
14
15 #include "wx/defs.h"
16 #include <gdk-pixbuf/gdk-pixbuf.h>
17
18 // ----------------------------------------------------------------------------
19 // wxAnimation
20 // Unlike the generic wxAnimation object (see generic\animate.cpp), we won't
21 // use directly wxAnimationHandlers as gdk-pixbuf already provides the
22 // concept of handler and will automatically use the available handlers.
23 // Like generic wxAnimation object, this implementation of wxAnimation is
24 // refcounted so that assignment is very fast
25 // ----------------------------------------------------------------------------
26
27 class WXDLLEXPORT wxAnimation : public wxAnimationBase
28 {
29 public:
30 wxAnimation(const wxAnimation &tocopy)
31 { m_pixbuf=tocopy.m_pixbuf; if (m_pixbuf) g_object_ref(m_pixbuf); }
32 wxAnimation(GdkPixbufAnimation *p = NULL)
33 { m_pixbuf=p; }
34 ~wxAnimation()
35 { UnRef(); }
36
37 wxAnimation &operator= (const wxAnimation &tocopy)
38 {
39 m_pixbuf=tocopy.m_pixbuf;
40 if (m_pixbuf) g_object_ref(m_pixbuf);
41 return *this;
42 }
43
44 bool operator == (const wxAnimation& anim) const
45 { return m_pixbuf == anim.m_pixbuf; }
46 bool operator != (const wxAnimation& anim) const
47 { return m_pixbuf != anim.m_pixbuf; }
48
49 virtual bool IsOk() const
50 { return m_pixbuf != NULL; }
51
52
53 // unfortunately GdkPixbufAnimation does not expose these info:
54
55 virtual size_t GetFrameCount() const
56 { return 0; }
57 virtual wxImage GetFrame(size_t i) const
58 { return wxNullImage; }
59
60 // we can retrieve the delay for a frame only after building
61 // a GdkPixbufAnimationIter...
62 virtual int GetDelay(size_t i) const
63 { return 0; }
64
65 virtual wxSize GetSize() const
66 { return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf),
67 gdk_pixbuf_animation_get_height(m_pixbuf)); }
68
69 virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
70 virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
71
72 void UnRef()
73 {
74 if (m_pixbuf)
75 g_object_unref(m_pixbuf);
76 m_pixbuf = NULL;
77 }
78
79 public: // used by GTK callbacks
80
81 GdkPixbufAnimation *GetPixbuf() const
82 { return m_pixbuf; }
83 void SetPixbuf(GdkPixbufAnimation *p)
84 { m_pixbuf=p; if (m_pixbuf) g_object_ref(m_pixbuf); }
85
86 protected:
87 GdkPixbufAnimation *m_pixbuf;
88
89 // used temporary by Load()
90 //bool m_bLoadComplete;
91
92 protected:
93 DECLARE_DYNAMIC_CLASS(wxAnimation)
94 };
95
96
97
98 // ----------------------------------------------------------------------------
99 // wxAnimationCtrl
100 // ----------------------------------------------------------------------------
101
102 // Resize to animation size if this is set
103 #define wxAN_FIT_ANIMATION 0x0010
104
105 class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase
106 {
107 public:
108 wxAnimationCtrl() {}
109 wxAnimationCtrl(wxWindow *parent,
110 wxWindowID id,
111 const wxAnimation& anim = wxNullAnimation,
112 const wxPoint& pos = wxDefaultPosition,
113 const wxSize& size = wxDefaultSize,
114 long style = wxAC_DEFAULT_STYLE,
115 const wxString& name = wxAnimationCtrlNameStr)
116 {
117 Create(parent, id, anim, pos, size, style, name);
118 }
119
120 bool Create(wxWindow *parent, wxWindowID id,
121 const wxAnimation& anim = wxNullAnimation,
122 const wxPoint& pos = wxDefaultPosition,
123 const wxSize& size = wxDefaultSize,
124 long style = wxAC_DEFAULT_STYLE,
125 const wxString& name = wxAnimationCtrlNameStr);
126
127 ~wxAnimationCtrl();
128
129 public: // event handler
130
131 void OnTimer(wxTimerEvent &);
132
133 public: // public API
134
135 virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY);
136
137 virtual void SetAnimation(const wxAnimation &anim);
138 virtual wxAnimation GetAnimation() const
139 { return wxAnimation(m_anim); }
140
141 virtual bool Play();
142 virtual void Stop();
143
144 virtual bool IsPlaying() const;
145
146 bool SetBackgroundColour( const wxColour &colour );
147
148 protected:
149
150 virtual wxSize DoGetBestSize() const;
151 void FitToAnimation();
152 void ClearToBackgroundColour();
153
154 void ResetAnim()
155 {
156 if (m_anim)
157 g_object_unref(m_anim);
158 m_anim = NULL;
159 }
160
161 void ResetIter()
162 {
163 if (m_iter)
164 g_object_unref(m_iter);
165 m_iter = NULL;
166 }
167
168 protected: // internal vars
169
170 GdkPixbufAnimation *m_anim;
171 GdkPixbufAnimationIter *m_iter;
172
173 wxTimer m_timer;
174 bool m_bPlaying;
175
176 private:
177 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl)
178 DECLARE_EVENT_TABLE()
179 };
180
181 #endif // _WX_GTKANIMATEH__