|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 // This module contains all the main logic connected with movement and selection in CGridImg. |
|
17 // |
|
18 #include "GRDSTD.H" |
|
19 #include "GRDPANIC.H" |
|
20 |
|
21 #if !defined(__WINC__) |
|
22 #include <w32std.h> |
|
23 #endif |
|
24 |
|
25 |
|
26 GLREF_C void CleanupGc(TAny* aObject); |
|
27 |
|
28 void CGridImg::DrawCursorOrRegionL(TUint aMoveFlags) |
|
29 { |
|
30 // |
|
31 // Does the appropriate operation on the cursor given the conditions in the parameters |
|
32 // |
|
33 if (iGridLay->IsRowPermanentlySelected()) |
|
34 aMoveFlags|=EIsRowSelected; |
|
35 RRegion oldRegion; |
|
36 CleanupClose<RRegion>::PushL(oldRegion); |
|
37 AppendTotalHighlightRegionL(oldRegion); |
|
38 TInt oldCursorRow=iCursorPos.iRow; |
|
39 TInt selectCount=iSelected->Count(); |
|
40 if (selectCount) |
|
41 { |
|
42 if (aMoveFlags&EIsWithSelect) |
|
43 { |
|
44 if (aMoveFlags&EIsAtBoundary) |
|
45 iNewCursorPos = iCursorPos; |
|
46 else |
|
47 UpdateSelectedRegion(selectCount,aMoveFlags); |
|
48 } |
|
49 else |
|
50 { |
|
51 if (aMoveFlags&EIsWithControl) |
|
52 { |
|
53 if (aMoveFlags&(EIsRowSelected|EIsColumnSelected)) |
|
54 AddLabelToRegionL(aMoveFlags); |
|
55 else |
|
56 { |
|
57 iAnchorPos=iCursorPos=iNewCursorPos; |
|
58 StartSelectedRegionL(aMoveFlags); |
|
59 } |
|
60 } |
|
61 else |
|
62 { |
|
63 iSelected->Reset(); |
|
64 if ((aMoveFlags&(EIsRowSelected|EIsColumnSelected)) && (!(aMoveFlags&EIsAtBoundary) |
|
65 || iGridLay->IsRowPermanentlySelected())) |
|
66 { |
|
67 AddLabelToRegionL(aMoveFlags); |
|
68 } |
|
69 else |
|
70 { |
|
71 if (aMoveFlags&EIsAtBoundary) |
|
72 iNewCursorPos=iCursorPos=iAnchorPos; |
|
73 else |
|
74 iCursorPos=iNewCursorPos; |
|
75 } |
|
76 } |
|
77 } |
|
78 } |
|
79 else |
|
80 { |
|
81 if (aMoveFlags&EIsAtBoundary) |
|
82 iNewCursorPos = iCursorPos; |
|
83 else |
|
84 { |
|
85 if (aMoveFlags&(EIsWithSelect|EIsWithControl)) |
|
86 { |
|
87 if (aMoveFlags&EIsWithSelect) |
|
88 StartSelectedRegionL(aMoveFlags); |
|
89 else |
|
90 { |
|
91 if (aMoveFlags&(EIsRowSelected|EIsColumnSelected)) |
|
92 AddLabelToRegionL(aMoveFlags); |
|
93 else |
|
94 { |
|
95 iAnchorPos=iCursorPos=iNewCursorPos; |
|
96 StartSelectedRegionL(aMoveFlags); |
|
97 } |
|
98 } |
|
99 } |
|
100 else |
|
101 { |
|
102 if (aMoveFlags&(EIsRowSelected|EIsColumnSelected)) |
|
103 AddLabelToRegionL(aMoveFlags); |
|
104 else |
|
105 iCursorPos = iNewCursorPos; |
|
106 } |
|
107 } |
|
108 } |
|
109 if (iCursorPos.iRow!=oldCursorRow || aMoveFlags&EIsColumnSelected) |
|
110 { |
|
111 RemoveRowLabelFromRegionL(oldCursorRow,oldRegion); |
|
112 RemoveRowLabelFromRegionL(iCursorPos.iRow,oldRegion); |
|
113 #if !defined(__WINC__) |
|
114 CreateGc(iGc); |
|
115 CleanupStack::PushL(TCleanupItem(CleanupGc,this)); |
|
116 DrawSideGridLabelIfOnScreenL(oldCursorRow); |
|
117 DrawSideGridLabelIfOnScreenL(iCursorPos.iRow); |
|
118 CleanupStack::PopAndDestroy(); // gc cleanup |
|
119 #endif |
|
120 } |
|
121 HighlightNewRegionFromOldL(oldRegion); |
|
122 CleanupStack::PopAndDestroy(); // oldRegion |
|
123 } |
|
124 |
|
125 void CGridImg::UpdateSelectedRegion(TInt aSelectCount,TUint aMoveFlags) |
|
126 { |
|
127 // |
|
128 // Updates the latest selected region in accordance with the passed parameters. |
|
129 // |
|
130 __ASSERT_DEBUG(aSelectCount>0,Panic(ECellRegionNothingSelected)); |
|
131 |
|
132 TRangeRef range = (*iSelected)[aSelectCount-1]; |
|
133 TRangeRef bounds(iGridLay->GridRange()); |
|
134 if (aMoveFlags&EIsAbsoluteMove) |
|
135 { |
|
136 if (((aMoveFlags&(EIsColumnSelected|EIsRowSelected|EIsWithDrag))==EIsColumnSelected) |
|
137 || (iSelected->IsColSelectedLastIndex(iCursorPos.iCol) && (aMoveFlags&EIsWithDrag) |
|
138 && !iSelected->IsRowSelectedLastIndex(iCursorPos.iRow))) |
|
139 { |
|
140 iGridLay->LimitCell(iNewCursorPos); |
|
141 range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
142 range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
143 range.iFrom.iRow = bounds.iFrom.iRow; |
|
144 range.iTo.iRow = bounds.iTo.iRow; |
|
145 iCursorPos.iCol = iNewCursorPos.iCol; |
|
146 iNewCursorPos.iRow = iCursorPos.iRow; |
|
147 } |
|
148 else if (((aMoveFlags&(EIsRowSelected|EIsColumnSelected|EIsWithDrag))==EIsRowSelected) |
|
149 || (iSelected->IsRowSelectedLastIndex(iCursorPos.iRow) && (aMoveFlags&EIsWithDrag) |
|
150 && !iSelected->IsColSelectedLastIndex(iCursorPos.iCol))) |
|
151 { |
|
152 iGridLay->LimitCell(iNewCursorPos); |
|
153 range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
154 range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
155 range.iFrom.iCol = bounds.iFrom.iCol; |
|
156 range.iTo.iCol = bounds.iTo.iCol; |
|
157 iCursorPos.iRow = iNewCursorPos.iRow; |
|
158 iNewCursorPos.iCol = iCursorPos.iCol; |
|
159 } |
|
160 else if ((aMoveFlags&(EIsRowSelected|EIsColumnSelected|EIsWithDrag))== |
|
161 (EIsRowSelected|EIsColumnSelected)) |
|
162 { |
|
163 range = bounds; |
|
164 iNewCursorPos = iCursorPos = bounds.iTo; |
|
165 } |
|
166 else if (!(iSelected->IsRangeSelectedLastIndex(iGridLay->GridRange()) && |
|
167 (aMoveFlags&EIsWithDrag))) |
|
168 { |
|
169 iGridLay->LimitCell(iNewCursorPos); |
|
170 range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
171 range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
172 range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
173 range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
174 iCursorPos = iNewCursorPos; |
|
175 } |
|
176 } |
|
177 else |
|
178 { |
|
179 if (iNewCursorPos.iRow != iCursorPos.iRow) |
|
180 { |
|
181 range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
182 range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
183 iCursorPos.iRow = iNewCursorPos.iRow; |
|
184 } |
|
185 if (iNewCursorPos.iCol != iCursorPos.iCol && !iGridLay->IsRowPermanentlySelected()) |
|
186 { |
|
187 range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
188 range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
189 iCursorPos.iCol = iNewCursorPos.iCol; |
|
190 } |
|
191 } |
|
192 iSelected->SetLastCellRange(range); |
|
193 } |
|
194 |
|
195 void CGridImg::AddLabelToRegionL(TUint aMoveFlags) |
|
196 { |
|
197 // |
|
198 // Adds an entire row/column/grid to the selected region |
|
199 // depending on iNewCursorPos |
|
200 // |
|
201 if ((aMoveFlags&(EIsRowSelected|EIsColumnSelected))==(EIsRowSelected|EIsColumnSelected)) |
|
202 { |
|
203 TRangeRef gridRange=iGridLay->GridRange(); |
|
204 iSelected->AddCellRangeL(gridRange); |
|
205 iAnchorPos.iRow=(iGridLay->IsHorizontalTitleLine()) ? iGridLay->TitleRange().iFrom.iRow |
|
206 : iGridLay->VisibleRange().iFrom.iRow; |
|
207 iAnchorPos.iCol=(iGridLay->IsVerticalTitleLine()) ? iGridLay->TitleRange().iFrom.iCol |
|
208 : iGridLay->VisibleRange().iFrom.iCol; |
|
209 iCursorPos=iNewCursorPos=iGridLay->GridRange().iTo; |
|
210 } |
|
211 else if (aMoveFlags&EIsColumnSelected) |
|
212 { |
|
213 iSelected->AddColL(iNewCursorPos.iCol); |
|
214 iAnchorPos.iCol = iCursorPos.iCol = iNewCursorPos.iCol; |
|
215 iAnchorPos.iRow=(iGridLay->IsHorizontalTitleLine()) ? iGridLay->TitleRange().iFrom.iRow |
|
216 : iGridLay->VisibleRange().iFrom.iRow; |
|
217 iCursorPos.iRow = iNewCursorPos.iRow = iGridLay->GridRange().iTo.iRow; |
|
218 } |
|
219 else if (aMoveFlags&EIsRowSelected) |
|
220 { |
|
221 iSelected->AddRowL(iNewCursorPos.iRow); |
|
222 iAnchorPos.iRow = iCursorPos.iRow = iNewCursorPos.iRow; |
|
223 iAnchorPos.iCol=(iGridLay->IsVerticalTitleLine()) ? iGridLay->TitleRange().iFrom.iCol |
|
224 : iGridLay->VisibleRange().iFrom.iCol; |
|
225 iCursorPos.iCol = iNewCursorPos.iCol = iGridLay->GridRange().iTo.iCol; |
|
226 } |
|
227 } |
|
228 |
|
229 void CGridImg::StartSelectedRegionL(TUint aMoveFlags) |
|
230 { |
|
231 // |
|
232 // Sets the anchor to the current cursor position and selects the region between |
|
233 // the anchor and the new cursor position |
|
234 // |
|
235 if (aMoveFlags&(EIsRowSelected|EIsColumnSelected) && (aMoveFlags&EIsWithDrag)) |
|
236 return; |
|
237 iAnchorPos = iCursorPos; |
|
238 iCursorPos = iNewCursorPos; |
|
239 TRangeRef range; |
|
240 if ((aMoveFlags&EIsColumnSelected) && (aMoveFlags&EIsRowSelected)) |
|
241 range = iGridLay->GridRange(); |
|
242 else |
|
243 { |
|
244 range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
245 range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow); |
|
246 range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
247 range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol); |
|
248 if (aMoveFlags&EIsRowSelected) |
|
249 { |
|
250 TRangeRef gridRange=iGridLay->GridRange(); |
|
251 range.iFrom.iCol = gridRange.iFrom.iCol; |
|
252 range.iTo.iCol = gridRange.iTo.iCol; |
|
253 } |
|
254 if (aMoveFlags&EIsColumnSelected) |
|
255 { |
|
256 TRangeRef gridRange=iGridLay->GridRange(); |
|
257 range.iFrom.iRow = gridRange.iFrom.iRow; |
|
258 range.iTo.iRow = gridRange.iTo.iRow; |
|
259 } |
|
260 } |
|
261 iSelected->AddCellRangeL(range); |
|
262 } |