21 #ifndef AKNSMILEYMODEL_H |
21 #ifndef AKNSMILEYMODEL_H |
22 #define AKNSMILEYMODEL_H |
22 #define AKNSMILEYMODEL_H |
23 |
23 |
24 // INCLUDES |
24 // INCLUDES |
25 #include <AknIconObserver.h> |
25 #include <AknIconObserver.h> |
26 |
26 #include <AknsItemID.h> |
|
27 #include "AknSmileyUtils.h" |
27 #include "AknSmileyImage.h" |
28 #include "AknSmileyImage.h" |
28 |
29 |
29 |
30 |
30 // CLASS DECLARATION |
31 // CLASS DECLARATION |
31 |
32 |
32 |
33 |
33 //////////////////////////////////////////////////////////////////// |
34 //////////////////////////////////////////////////////////////////// |
34 |
35 |
35 const TInt KSmileyNameLength = 8; |
36 const TInt KSmileyNameLength = 8; |
|
37 typedef TBuf<KSmileyNameLength> TSmileyText; |
|
38 typedef RArray<TSmileyText> RSmileyTextArray; |
|
39 typedef RArray<TChar> RSmileyCodeArray; |
36 |
40 |
37 NONSHARABLE_CLASS(TSmileyIconInfo) |
41 NONSHARABLE_CLASS(TSmileyIconInfo) |
38 { |
42 { |
39 public: |
43 public: |
40 TSmileyIconInfo(); |
44 TSmileyIconInfo(); |
41 TSmileyIconInfo(const TSmileyIconInfo& aInfo); |
45 TSmileyIconInfo(const TSmileyIconInfo& aInfo); |
42 void Reset(); |
46 void Reset(); |
43 |
47 |
44 TBuf<KSmileyNameLength> iName; |
48 TInt iIndex; |
45 TInt iId; |
49 TAknsItemID iSkinItemID; // from skin |
46 TAknsItemID iSkinItemID; // from skin |
50 TInt iDefaultStillImageID; // from mif |
47 TInt iDefaultThumbnailID; // from mif |
51 TInt iDefaultAnimationImageID; // from mif |
48 TInt iDefaultAnimationID; // from mif |
52 }; |
49 }; |
53 |
50 |
54 //////////////////////////////////////////////////////////////////// |
51 //////////////////////////////////////////////////////////////////// |
55 |
52 |
56 class CSmileyIcon : public CAknSmileyIcon, public MSmileyImageObserver |
53 class CSmileyIcon; |
57 { |
54 |
58 public: |
55 class MSmileyIconObserver |
59 static CSmileyIcon* NewL(const TSmileyIconInfo& aInfo, MAknSmileyObserver* aObserver); |
56 { |
|
57 public: |
|
58 virtual void ThumbnailLoaded(CSmileyIcon* aSmileyIcon)=0; |
|
59 virtual void AnimationChanged(CSmileyIcon* aSmileyIcon)=0; |
|
60 }; |
|
61 |
|
62 //////////////////////////////////////////////////////////////////// |
|
63 |
|
64 class CSmileyIcon : public CBase, public MSmileyImageObserver |
|
65 { |
|
66 public: |
|
67 static CSmileyIcon* NewL(const TSmileyIconInfo& aInfo, MSmileyIconObserver* aObserver); |
|
68 virtual ~CSmileyIcon(); |
60 virtual ~CSmileyIcon(); |
69 |
61 |
70 private: |
62 private: |
71 CSmileyIcon(const TSmileyIconInfo& aInfo, MSmileyIconObserver* aObserver); |
63 CSmileyIcon(MAknSmileyObserver* aObserver); |
72 void ConstructL(); |
64 void ConstructL(const TSmileyIconInfo& aInfo); |
73 |
65 |
74 public: |
66 public: // from AknSmileyIcon |
75 const TDesC& Name() const { return iInfo.iName; } |
67 virtual const CFbsBitmap* Image() const; |
76 TInt Id() const { return iInfo.iId; } |
68 virtual const CFbsBitmap* Mask() const; |
77 |
69 virtual TBool ReadyToDraw() const; |
78 TBool ReadyToDraw() const; |
70 virtual void SetSize(const TSize& aSize); |
79 const CFbsBitmap* Image() const; |
71 virtual const TSize& Size() const; |
80 const CFbsBitmap* Mask() const; |
72 virtual void PlayAnimationL(TInt aRepeat=0, TInt aDelay=0); |
81 |
73 virtual void StopAnimation(); |
82 public: |
|
83 void LoadThumbnailL(); |
|
84 TBool ThumbnailReady() const; |
|
85 |
|
86 void PlayAnimationL(TInt aRepeat, TInt aDelay); |
|
87 void StopAnimation(); |
|
88 |
|
89 public: |
|
90 void SetSize(const TSize& aSize); |
|
91 const TSize& Size() const; |
|
92 |
74 |
93 private: // from MSmileyImageObserver |
75 private: // from MSmileyImageObserver |
94 virtual void BitmapChanged(CSmileyImage* aSmileyImage, CFbsBitmap* aBitmap); |
76 virtual void BitmapChanged(CSmileyImage* aSmileyImage, CFbsBitmap* aBitmap); |
95 |
77 |
96 private: |
78 public: |
97 TBool ShouldShowAnimation() const; |
79 TInt Index() const; |
98 |
80 void LoadStillImageL(TInt aDelay=0); |
99 private: |
81 TBool StillImageIsReadyToDraw() const; |
100 const TSmileyIconInfo iInfo; |
82 TBool AnimationImageIsReadyToDraw() const; |
101 MSmileyIconObserver* iSmileyIconObserver; |
83 |
102 |
84 void AddVariant(const TDesC& aText, TChar aBaseCode); |
103 CSmileyImage* iThumbnailImage; |
85 TInt VariantCount() const; |
|
86 const TDesC& Text(TInt aVariant=0) const; |
|
87 TChar Code(TInt aVariant=0) const; |
|
88 |
|
89 private: |
|
90 MAknSmileyObserver* iSmileyIconObserver; |
|
91 TInt iIndex; |
|
92 CSmileyImage* iStillImage; |
104 CSmileyImage* iAnimationImage; |
93 CSmileyImage* iAnimationImage; |
105 |
94 RSmileyTextArray iTextArray; |
|
95 RSmileyCodeArray iCodeArray; |
106 }; |
96 }; |
107 |
97 |
108 typedef RArray<CSmileyIcon*> RSmileyIconPtrArray; |
98 typedef RArray<CSmileyIcon*> RSmileyIconPtrArray; |
|
99 NONSHARABLE_CLASS(TSmileyCodeIndex) |
|
100 { |
|
101 public: |
|
102 TSmileyCodeIndex(CSmileyIcon* aSmileyIcon, TInt aVariant=0) : iSmileyIcon(aSmileyIcon), iVariant(aVariant) {} |
|
103 CSmileyIcon* Smiley() const { return iSmileyIcon; } |
|
104 const TDesC& Text() const { return iSmileyIcon->Text(iVariant); } |
|
105 private: |
|
106 CSmileyIcon* iSmileyIcon; |
|
107 TInt iVariant; |
|
108 }; |
|
109 typedef RArray<TSmileyCodeIndex> RSmileyCodeIndexArray; |
109 |
110 |
110 |
111 |
111 //////////////////////////////////////////////////////////////////// |
112 //////////////////////////////////////////////////////////////////// |
112 |
113 |
113 class CSmileyTnumbnailAsynLoader : public CBase |
114 class CSmileyTnumbnailAsynLoader : public CBase |
120 void DiscardAll(); |
121 void DiscardAll(); |
121 TInt TaskCount() const; |
122 TInt TaskCount() const; |
122 void DoNextTaskL(); |
123 void DoNextTaskL(); |
123 |
124 |
124 private: |
125 private: |
125 RSmileyIconPtrArray iTaskArray; |
126 RSmileyIconPtrArray iLoadingTaskArray; |
126 TBool iIsLoading; |
127 |
127 |
128 }; |
128 }; |
129 |
129 |
130 //////////////////////////////////////////////////////////////////// |
130 //////////////////////////////////////////////////////////////////// |
131 |
131 |
132 class CSmileyTextTreeNode; |
132 class CSmileyModel : public CBase, public MSmileyIconObserver |
133 |
133 { |
134 class CSmileyModel : public CBase, public MAknSmileyObserver |
134 public: |
135 { |
135 CSmileyModel(MSmileyIconObserver* aObserver); |
136 public: |
136 ~CSmileyModel(); |
137 CSmileyModel(MAknSmileyObserver* aObserver); |
|
138 virtual ~CSmileyModel(); |
137 |
139 |
138 public: |
140 public: |
139 void LoadResourceL(); |
141 void LoadResourceL(); |
140 void ReleaseResource(); |
142 void ReleaseResource(); |
141 void LoadThumbnailAsyn(TInt aIndex); |
143 |
|
144 public: |
|
145 TInt ConvertCodesToTextL(TDes& aText); |
|
146 TInt ConvertTextToCodesL(TDes& aText); |
|
147 const TDesC& Text(TChar aCode) const; |
|
148 TBool IsSmiley(TChar aCode) const; |
|
149 |
|
150 public: |
142 void SetSize(const TSize& aSize); |
151 void SetSize(const TSize& aSize); |
143 |
152 void SetSizeByFont(const CFont* aFont); |
144 public: |
153 |
145 enum TIconId |
154 public: |
146 { |
155 void DrawText(CWindowGc& aGc, const TDesC& aText, const CFont* aFont, const TPoint& aPosition) const; |
147 EIconSwitchToSmiley = 0, |
156 void DrawText(CWindowGc& aGc, const TDesC& aText, const TAknLayoutText& aLayout, TBool aUseLogicalToVisualConversion=EFalse) const; |
148 EIconSwitchToSct, |
157 void DrawText(CWindowGc& aGc, const TDesC& aText, const CFont* aFont, const TRect& aBox, TInt aBaselineOffset, |
149 EIconSmiley |
158 CGraphicsContext::TTextAlign aAlignment=CGraphicsContext::ELeft, TInt aLeftMargin=0) const; |
150 }; |
159 |
151 |
160 private: |
152 CSmileyIcon* operator[](TInt aIndex) const; |
161 void DrawText(CWindowGc& aGc, const TDesC& aText, const CFont* aFont, const TRect& aBox, const TPoint& aOffset) const; |
|
162 |
|
163 public: |
153 TInt Count() const; |
164 TInt Count() const; |
|
165 CAknSmileyIcon* Smiley(TChar aCode) const; |
|
166 CAknSmileyIcon* operator[](TInt aIndex) const; |
154 |
167 |
155 private: // from MSmileyIconObserver |
168 private: // from MSmileyIconObserver |
156 virtual void ThumbnailLoaded(CSmileyIcon* aSmileyIcon); |
169 virtual void SmileyStillImageLoaded(CAknSmileyIcon* aSmileyIcon); |
157 virtual void AnimationChanged(CSmileyIcon* aSmileyIcon); |
170 virtual void SmileyAnimationChanged(CAknSmileyIcon* aSmileyIcon); |
158 |
171 |
159 private: |
172 public: // for smiley picker |
160 MSmileyIconObserver* iSmileyIconObserver; |
173 CAknSmileyIcon* SwitchToSmileyIcon() const; |
|
174 CAknSmileyIcon* SwitchToSctIcon() const; |
|
175 TChar SwitchToSmileyCode() const; |
|
176 TChar SwitchToSctCode() const; |
|
177 |
|
178 TChar SmileyCode(TInt aIndex, TInt aVariant=0) const; |
|
179 TChar SmileyCode(const CAknSmileyIcon* aSmileyIcon) const; |
|
180 |
|
181 void LoadStillImagesL(const TDesC& aText); |
|
182 void PlayAnimationL(const TDesC& aText, TInt aRepeat=0, TInt aDelay=0); |
|
183 void StopAnimation(const TDesC& aText); |
|
184 |
|
185 private: |
|
186 void LoadStillImageL(TChar aChar); |
|
187 void PlayAnimationL(TChar aChar, TInt aRepeat=0, TInt aDelay=0); |
|
188 void StopAnimation(TChar aChar); |
|
189 |
|
190 private: |
|
191 const TDesC& Text(TInt aIndex, TInt aVariant=0) const; |
|
192 TInt ArrayCount() const; |
|
193 |
|
194 private: |
|
195 MAknSmileyObserver* iSmileyIconObserver; |
|
196 CSmileyTnumbnailAsynLoader iSmileyLoader; |
161 RSmileyIconPtrArray iSmileyIconArray; |
197 RSmileyIconPtrArray iSmileyIconArray; |
162 CSmileyTnumbnailAsynLoader iSmileyThumbnailLoader; |
198 RSmileyCodeIndexArray iSmileyCodeIndexArray; |
|
199 |
|
200 CSmileyTextTreeNode* iTextSearchTree; |
|
201 TBuf<1024*2> iConvertBuffer; |
163 |
202 |
164 }; |
203 }; |
165 |
204 |
166 #endif // AKNSMILEYMODEL_H |
205 #endif // AKNSMILEYMODEL_H |