|
1 // Copyright (c) 2005-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 // Implements the query dialog box used for asking users input on row |
|
15 // and column resize.\n |
|
16 // Also implements the Grid Window which handles the user |
|
17 // inputs on the Grid Table.\n |
|
18 // Copy of COEGRID.CPP except for OfferKeyEvent and HandlePointerEvent\n |
|
19 // Copy of COEGRID.CPP except for OfferKeyEvent and HandlePointerEvent |
|
20 // |
|
21 // |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent - Internal Symbian test code |
|
26 */ |
|
27 |
|
28 #include <coemain.h> |
|
29 #include "COEGRID.H" |
|
30 |
|
31 #define KGridPointerRepeatDelayInMicroSeconds 10000 |
|
32 |
|
33 #define KGridRectForPointerRepeats (TRect(-1000,-1000,1000,1000)) |
|
34 |
|
35 /** |
|
36 Static function to construct the Grid Window.\n |
|
37 Grid Window is a control on which the Grid table is displayed .\n |
|
38 Invokes the second phase constructor.\n |
|
39 |
|
40 @return : Pointer to the newly constructed Grid window.\n |
|
41 |
|
42 */ |
|
43 CGrid2Win* CGrid2Win::NewL(CCoeControl* aWin,CGridLay *aGridLay,CGridImg *aGridImg) |
|
44 { |
|
45 CGrid2Win *self=new(ELeave) CGrid2Win(aGridLay,aGridImg); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aWin); |
|
48 CleanupStack::Pop(); |
|
49 return self; |
|
50 } |
|
51 /** |
|
52 Two argument Constructor.\n |
|
53 Constructs a Grid Window taking GridLay and Grid Img as arguments.\n |
|
54 */ |
|
55 CGrid2Win::CGrid2Win(CGridLay *aGridLay,CGridImg *aGridImg) |
|
56 : iGridLay(aGridLay), |
|
57 iGridImg(aGridImg) |
|
58 {} |
|
59 /** |
|
60 Second phase constructor for the Grid Window.\n |
|
61 Creates a control's window which is the child of the application's window group.\n |
|
62 Allows pointer grabs in a window in order to receive pointer events.\n |
|
63 Sets the window as the default window.\n |
|
64 */ |
|
65 void CGrid2Win::ConstructL(CCoeControl* aWin) |
|
66 { |
|
67 CreateWindowL(aWin); |
|
68 Window().PointerFilter(EPointerFilterDrag,0); |
|
69 Window().SetPointerGrab(ETrue); |
|
70 iGridImg->SetWindow(&Window()); |
|
71 if (iGridLay->IsIndefiniteRowBoundaries()) |
|
72 iGridLay->SetUniformRowHeight(ETrue); |
|
73 } |
|
74 /** |
|
75 Destructor for Grid Window.\n |
|
76 */ |
|
77 CGrid2Win::~CGrid2Win() |
|
78 { |
|
79 } |
|
80 /** |
|
81 |
|
82 @return Pointer to the GridLay object owned by the Grid Window.\n |
|
83 |
|
84 The function is invoked in case modifications |
|
85 need to be made to the layout of the grid.\n |
|
86 */ |
|
87 CGridLay* CGrid2Win::GridLay() const |
|
88 { |
|
89 return iGridLay; |
|
90 } |
|
91 /** |
|
92 @return Pointer to the GridImg object owned by the Grid Window.\n |
|
93 |
|
94 The function is invoked whenever there is a need to redraw the contents of the grid.\n |
|
95 */ |
|
96 CGridImg* CGrid2Win::GridImg() const |
|
97 { |
|
98 return iGridImg; |
|
99 } |
|
100 /** |
|
101 Draws the Grid Window.\n |
|
102 The function is invoked by the window server.\n |
|
103 This function is used for window server-initiated redrawing of controls, |
|
104 and for some application-initiated drawing.\n |
|
105 It should be implemented by each control.\n |
|
106 |
|
107 */ |
|
108 void CGrid2Win::Draw(const TRect& aRect) const |
|
109 { |
|
110 CWindowGc& gc=SystemGc(); |
|
111 gc.DrawRect(Rect()); |
|
112 TRAPD(err,iGridImg->DrawL(&gc,aRect)); |
|
113 __ASSERT_ALWAYS(!err,User::Panic(_L("DrawL(&gc,aRect) 2"),err)); |
|
114 } |
|
115 /** |
|
116 The function provides handlers for various key events such as \n |
|
117 Ctrl+ KeyUpArrow.\n |
|
118 Ctrl+ KeyDownArrow.\n |
|
119 Ctrl+ KeyRightArrow.\n |
|
120 Ctrl+ KeyLeftArrow.\n |
|
121 Ctrl+ KeyHome.\n |
|
122 Ctrl+ KeyEnd.\n |
|
123 Ctrl+ KeyPageup.\n |
|
124 Ctrl+ KeyPageDown.\n |
|
125 KeyUpArrow.\n |
|
126 KeyDownArrow.\n |
|
127 KeyRightArrow.\n |
|
128 KeyLeftArrow.\n |
|
129 KeyHome.\n |
|
130 KeyEnd.\n |
|
131 KeyPageup.\n |
|
132 KeyPageDown.\n |
|
133 The function differs from the corresponding function in CGridWin as the |
|
134 Resize mode is not taken into consideration while handling the key events.\n |
|
135 |
|
136 @return : TKeyResponse indicating whether the key event has been handled or not.\n |
|
137 |
|
138 */ |
|
139 TKeyResponse CGrid2Win::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/) |
|
140 // Tells GridImg to do the appropriate action on a keypress. |
|
141 { |
|
142 TUint selectState=0; |
|
143 if (aKeyEvent.iModifiers&EModifierCtrl) |
|
144 { |
|
145 switch (aKeyEvent.iCode) |
|
146 { |
|
147 case EKeyUpArrow: |
|
148 iGridImg->MoveCursorL(EMovePageUp,selectState); |
|
149 break; |
|
150 case EKeyDownArrow: |
|
151 iGridImg->MoveCursorL(EMovePageDown,selectState); |
|
152 break; |
|
153 case EKeyLeftArrow: |
|
154 iGridImg->MoveCursorL(EMovePageLeft,selectState); |
|
155 break; |
|
156 case EKeyRightArrow: |
|
157 iGridImg->MoveCursorL(EMovePageRight,selectState); |
|
158 break; |
|
159 case EKeyHome: |
|
160 iGridImg->MoveCursorL(EMoveHome,selectState); |
|
161 break; |
|
162 case EKeyEnd: |
|
163 iGridImg->MoveCursorL(EMoveEnd,selectState); |
|
164 break; |
|
165 case EKeyPageUp: |
|
166 iGridImg->MoveCursorL(EMoveColumnStart,selectState); |
|
167 break; |
|
168 case EKeyPageDown: |
|
169 iGridImg->MoveCursorL(EMoveColumnEnd,selectState); |
|
170 break; |
|
171 default: |
|
172 return EKeyWasNotConsumed; |
|
173 } |
|
174 } |
|
175 else |
|
176 { |
|
177 switch (aKeyEvent.iCode) |
|
178 { |
|
179 case EKeyUpArrow: |
|
180 iGridImg->MoveCursorL(EMoveRowUp,selectState); |
|
181 break; |
|
182 case EKeyDownArrow: |
|
183 iGridImg->MoveCursorL(EMoveRowDown,selectState); |
|
184 break; |
|
185 case EKeyLeftArrow: |
|
186 iGridImg->MoveCursorL(EMoveColumnLeft,selectState); |
|
187 break; |
|
188 case EKeyRightArrow: |
|
189 iGridImg->MoveCursorL(EMoveColumnRight,selectState); |
|
190 break; |
|
191 case EKeyPageUp: |
|
192 iGridImg->MoveCursorL(EMovePageUp,selectState); |
|
193 break; |
|
194 case EKeyPageDown: |
|
195 iGridImg->MoveCursorL(EMovePageDown,selectState); |
|
196 break; |
|
197 case EKeyHome: |
|
198 iGridImg->MoveCursorL(EMoveRowStart,selectState); |
|
199 break; |
|
200 case EKeyEnd: |
|
201 iGridImg->MoveCursorL(EMoveRowEnd,selectState); |
|
202 break; |
|
203 default: |
|
204 return EKeyWasNotConsumed; |
|
205 } |
|
206 } |
|
207 return EKeyWasConsumed; |
|
208 } |
|
209 /** |
|
210 The function provides handlers for Pointer events.\n |
|
211 Handles the following pointer events \n |
|
212 1. Pointer Drag.\n |
|
213 2. Double click event.\n |
|
214 3. Pointer Button Down.\n |
|
215 */ |
|
216 void CGrid2Win::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
217 { |
|
218 // |
|
219 // Tells GridImg to do the appropriate action on a pointer event |
|
220 // |
|
221 if (aPointerEvent.iType==TPointerEvent::EDrag || aPointerEvent.iType==TPointerEvent::EButtonRepeat |
|
222 && !iGridImg->MainRect().Contains(aPointerEvent.iPosition)) |
|
223 { |
|
224 Window().RequestPointerRepeatEvent(KGridPointerRepeatDelayInMicroSeconds,KGridRectForPointerRepeats); |
|
225 } |
|
226 TPointerEvent event=aPointerEvent; |
|
227 if (event.iType==TPointerEvent::EButtonRepeat) |
|
228 event.iType=TPointerEvent::EDrag; |
|
229 else if (event.iModifiers&EModifierDoubleClick) |
|
230 event.iType=TPointerEvent::EButton1Down; |
|
231 |
|
232 if (event.iType == TPointerEvent::EButton1Up) |
|
233 iGridImg->FinishLabelDragL(); |
|
234 else if (event.iType == TPointerEvent::EButton1Down) |
|
235 { |
|
236 if (!iGridImg->StartLabelDrag(event.iPosition)) |
|
237 iGridImg->SetCursorWithPointerL(event.iPosition,0); |
|
238 } |
|
239 else if (event.iType == TPointerEvent::EDrag) |
|
240 { |
|
241 if (!iGridImg->UpdateLabelDrag(event.iPosition)) |
|
242 iGridImg->SetCursorWithPointerL(event.iPosition,CGridImg::EIsWithDrag); |
|
243 } |
|
244 } |
|
245 /** |
|
246 Shrinks the Grid. |
|
247 The shrinking is achieved by adding value of (1,1) to the top left corner.\n |
|
248 and subtracting the same coordinates from the bottom right corner of the grid.\n |
|
249 */ |
|
250 void CGrid2Win::SizeChanged() |
|
251 { |
|
252 TRect rect(Size()); |
|
253 rect.Shrink(1,1); |
|
254 iGridImg->SetGridRect(rect); |
|
255 iGridLay->ResetVisibleToCell(); |
|
256 } |
|
257 /** |
|
258 Draw the cell corresponding to the reference.\n |
|
259 Calls the DrawCellL function of the CGridImg class.\n |
|
260 */ |
|
261 void CGrid2Win::DrawCellL(const TCellRef& aCell) const |
|
262 { |
|
263 iGridImg->DrawCellL(aCell); |
|
264 } |
|
265 /** |
|
266 Draws the rectangle corresponding to the range.\n |
|
267 Invokes the DrawRangeL function of the CGridImg class.\n |
|
268 */ |
|
269 void CGrid2Win::DrawRangeL(const TRangeRef& aRange) const |
|
270 { |
|
271 iGridImg->DrawRangeL(aRange); |
|
272 } |
|
273 /** |
|
274 Draws the currently selected region.\n |
|
275 Invokes the corresponding function of the CGridImg class.\n |
|
276 */ |
|
277 void CGrid2Win::DrawSelectedL() const |
|
278 { |
|
279 iGridImg->DrawSelectedL(); |
|
280 } |
|
281 /** |
|
282 @return the cell reference where the cursor is located.\n |
|
283 |
|
284 Delegates the task to the corresponding function of CGridImg function.\n |
|
285 */ |
|
286 TCellRef CGrid2Win::CursorPos() const |
|
287 { |
|
288 return iGridImg->CursorPos(); |
|
289 } |
|
290 /** |
|
291 Sets the cursor position to the cell reference sent as an argument.\n |
|
292 */ |
|
293 void CGrid2Win::SetCursorPosL(const TCellRef& aCursorPos) const |
|
294 { |
|
295 iGridImg->SetCursorPosL(aCursorPos); |
|
296 } |
|
297 /** |
|
298 Scrolls the grid by the minimum necessary to |
|
299 allow the specified cell to become visible.\n |
|
300 The offset to the cell required to be visible is calculated and |
|
301 a scroll operation is performed.\n |
|
302 */ |
|
303 void CGrid2Win::ExposeCellL(const TCellRef& aCell) const |
|
304 { |
|
305 TPoint offset=iGridLay->ExposeCell(aCell); |
|
306 iGridImg->ScrollL(offset); |
|
307 } |