|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation for TAknTreeListViewItem class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknUtils.h> |
|
20 #include <skinlayout.cdl.h> |
|
21 #include <aknlayoutscalable_avkon.cdl.h> |
|
22 #include <AknsBasicBackgroundControlContext.h> |
|
23 #include <AknsDrawUtils.h> |
|
24 |
|
25 #include "akntreelistview.h" |
|
26 #include "akntreelistviewitem.h" |
|
27 #include "akntree.h" |
|
28 |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Default C++ constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 TAknTreeListViewItem::TAknTreeListViewItem() |
|
37 : iItem( NULL ), |
|
38 iRect(), |
|
39 iLineSegmentRect() |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // C++ constructor. |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 TAknTreeListViewItem::TAknTreeListViewItem( CAknTreeItem* aItem, |
|
49 const TRect& aRect ) |
|
50 : iItem( aItem ), |
|
51 iRect( aRect ), |
|
52 iLineSegmentRect() |
|
53 { |
|
54 // Call this to calculate also the line segment rectangle. |
|
55 SetRect( aRect ); |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Copy constructor. |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 TAknTreeListViewItem::TAknTreeListViewItem( const TAknTreeListViewItem& aItem ) |
|
64 : iItem( aItem.iItem ), |
|
65 iRect( aItem.iRect ), |
|
66 iLineSegmentRect( aItem.iLineSegmentRect ) |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Returns the tree item contained in view item. |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CAknTreeItem* TAknTreeListViewItem::Item() const |
|
76 { |
|
77 return iItem; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Sets the tree item the view item is representing. |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void TAknTreeListViewItem::SetItem( CAknTreeItem* aItem ) |
|
86 { |
|
87 iItem = aItem; |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Returns the view item rectangle. |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 TRect TAknTreeListViewItem::Rect() const |
|
96 { |
|
97 return iRect; |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // Sets the view item rectangle. |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void TAknTreeListViewItem::SetRect( const TRect& aRect ) |
|
106 { |
|
107 iRect = aRect; |
|
108 |
|
109 // Get rectangle for structure lines. |
|
110 TInt lineVariety = 0; // Type. |
|
111 iLineSegmentRect = CAknTreeListView::RectFromLayout( aRect, |
|
112 AknLayoutScalable_Avkon::list_single_graphic_hl_pane_g1( lineVariety ) ); |
|
113 } |
|
114 |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Returns the rectangle reserved for the tree item. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TRect TAknTreeListViewItem::ItemRect( TInt aViewLevel, TBool aIndention, |
|
121 TInt aIndentionWidth ) const |
|
122 { |
|
123 __ASSERT_DEBUG( aViewLevel >= NULL, User::Invariant() ); |
|
124 |
|
125 TRect itemRect; |
|
126 if ( iItem ) |
|
127 { |
|
128 TInt itemLevel = aIndention ? iItem->Level() : 1; |
|
129 TInt indentLevel = ( itemLevel - 1 ) - aViewLevel; |
|
130 TInt indentWidth = ( aIndentionWidth < 0 ) ? |
|
131 LineSegmentWidth() : aIndentionWidth; |
|
132 TInt indent = indentLevel * indentWidth; |
|
133 |
|
134 itemRect = TRect( TPoint( iRect.iTl.iX + indent, iRect.iTl.iY ), |
|
135 TSize( Max( iRect.Width() - indent, iItem->MinimumSize().iWidth ), |
|
136 iRect.Height() ) ); |
|
137 |
|
138 if ( AknLayoutUtils::LayoutMirrored() ) |
|
139 { |
|
140 itemRect.Move( ( iRect.iBr.iX - itemRect.iBr.iX ) - indent, 0 ); |
|
141 } |
|
142 } |
|
143 return itemRect; |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // Returns the rectangle reserved for the tree item highlight. |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TRect TAknTreeListViewItem::HighlightRect( TInt aViewLevel, |
|
152 TBool aIndention, TInt aIndentionWidth ) const |
|
153 { |
|
154 TRect highlightRect; |
|
155 if ( iItem ) |
|
156 { |
|
157 TRect itemRect( ItemRect( aViewLevel, aIndention, aIndentionWidth ) ); |
|
158 |
|
159 TInt variety = 0; |
|
160 highlightRect = CAknTreeListView::RectFromLayout( itemRect, |
|
161 AknLayoutScalable_Avkon::list_highlight_pane_cp34( variety ) ); |
|
162 } |
|
163 return highlightRect; |
|
164 } |
|
165 |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // Returns the rectangle for tree structure line segment at given index. |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 TRect TAknTreeListViewItem::LineSegmentRect( TUint aIndex ) const |
|
172 { |
|
173 TRect rect = iLineSegmentRect; |
|
174 if ( AknLayoutUtils::LayoutMirrored() ) |
|
175 { |
|
176 rect.Move( -iLineSegmentRect.Width() * aIndex, 0 ); |
|
177 } |
|
178 else |
|
179 { |
|
180 rect.Move( iLineSegmentRect.Width() * aIndex, 0 ); |
|
181 } |
|
182 return rect; |
|
183 } |
|
184 |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // Returns the width of one tree structure line segment. |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 TInt TAknTreeListViewItem::LineSegmentWidth() const |
|
191 { |
|
192 return iLineSegmentRect.Width(); |
|
193 } |
|
194 |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // Draws the tree structure lines for one list row, highlight, and item. |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void TAknTreeListViewItem::Draw( CWindowGc& aGc, CAknTree& aTree, |
|
201 const TRect& aRect, TBool aFocused, TInt aViewLevel, |
|
202 TBool aStructureLines, TBool aIndention, TInt aIndentionWidth ) const |
|
203 { |
|
204 if ( iItem ) |
|
205 { |
|
206 const TRect itemRect = |
|
207 ItemRect( aViewLevel, aIndention, aIndentionWidth ); |
|
208 |
|
209 // Draw the tree structure lines for the item. |
|
210 TInt itemLevel = aIndention ? iItem->Level() : 1; |
|
211 TInt indentLevel = ( itemLevel - 1 ) - aViewLevel; |
|
212 if ( aStructureLines && indentLevel > 0 ) |
|
213 { |
|
214 const CAknTreeNode* parent = iItem->Parent(); |
|
215 |
|
216 TRect segmentRect = LineSegmentRect( --indentLevel ); |
|
217 |
|
218 if ( parent->Index( iItem ) == parent->ChildCount() - 1 ) |
|
219 { |
|
220 DrawLineSegment( aGc, aTree, segmentRect, ELineEnd ); |
|
221 } |
|
222 else |
|
223 { |
|
224 DrawLineSegment( aGc, aTree, segmentRect, ELineBranch ); |
|
225 } |
|
226 |
|
227 while ( indentLevel > 0 ) |
|
228 { |
|
229 segmentRect = LineSegmentRect( --indentLevel ); |
|
230 if ( parent->Parent()->Index( parent ) < |
|
231 parent->Parent()->ChildCount() - 1 ) |
|
232 { |
|
233 DrawLineSegment( aGc, aTree, segmentRect, ELineStraight ); |
|
234 } |
|
235 parent = parent->Parent(); |
|
236 } |
|
237 } |
|
238 |
|
239 TRect intersection = aRect; |
|
240 intersection.Intersection( itemRect ); |
|
241 |
|
242 TRect newRect( itemRect ); |
|
243 newRect.iBr.iY -= iView->Offset(); |
|
244 newRect.iTl.iY -= iView->Offset(); |
|
245 |
|
246 iItem->Draw( aGc, newRect, intersection, aFocused ); |
|
247 } |
|
248 } |
|
249 |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // Mediates pointer events to the contained tree item. |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void TAknTreeListViewItem::HandlePointerEventL( |
|
256 const TPointerEvent& aPointerEvent, TInt aViewLevel, TBool aIndention, |
|
257 TInt aIndentionWidth ) |
|
258 { |
|
259 if ( iItem ) |
|
260 { |
|
261 TRect itemRect = ItemRect( aViewLevel, aIndention, aIndentionWidth ); |
|
262 if ( itemRect.Contains( aPointerEvent.iPosition ) ) |
|
263 { |
|
264 iItem->HandlePointerEventL( aPointerEvent, itemRect ); |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // Draws one segment of tree structure lines. |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void TAknTreeListViewItem::DrawLineSegment( CWindowGc& aGc, CAknTree& aTree, |
|
275 const TRect& aSegmentRect, TLineSegmentType aType ) const |
|
276 { |
|
277 TRect newRect( aSegmentRect ); |
|
278 newRect.iBr.iY -= iView->Offset(); |
|
279 newRect.iTl.iY -= iView->Offset(); |
|
280 |
|
281 switch( aType ) |
|
282 { |
|
283 case ELineStraight: |
|
284 { |
|
285 aTree.DrawIcon( CAknTree::ELineStraightIndication, |
|
286 newRect.Size(), aGc, |
|
287 newRect.iTl, newRect.Size() ); |
|
288 break; |
|
289 } |
|
290 case ELineEnd: |
|
291 { |
|
292 aTree.DrawIcon( CAknTree::ELineEndIndication, |
|
293 newRect.Size(), aGc, |
|
294 newRect.iTl, newRect.Size() ); |
|
295 break; |
|
296 } |
|
297 case ELineBranch: |
|
298 { |
|
299 aTree.DrawIcon( CAknTree::ELineBranchIndication, |
|
300 newRect.Size(), aGc, |
|
301 newRect.iTl, newRect.Size() ); |
|
302 break; |
|
303 } |
|
304 default: |
|
305 break; |
|
306 } |
|
307 } |
|
308 |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // Sets view |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 void TAknTreeListViewItem::SetView( CAknTreeListView* aView ) |
|
315 { |
|
316 iView = aView; |
|
317 } |
|
318 |