commonuisupport/grid/tef/COEGRID.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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. Also implements the Grid Window which handles the user 
       
    16 // inputs on the Grid Table.\n
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent - Internal Symbian test code
       
    23 */
       
    24 
       
    25 #include <gdi.h>
       
    26 #include <coemain.h>
       
    27 #include "COEGRID.H"
       
    28 #include <grdstd.h>
       
    29 
       
    30 #define KGridPointerRepeatDelayInMicroSeconds	10000
       
    31 
       
    32 #define KGridRectForPointerRepeats		(TRect(-1000,-1000,1000,1000))
       
    33 /**
       
    34   Function invoked in case of PANIC.\n
       
    35 */
       
    36 GLDEF_C void Panic(TCoeGridPanic aPanic)
       
    37 	{
       
    38 	User::Panic(_L("COEGRID"),aPanic);
       
    39 	}
       
    40 
       
    41 //
       
    42 // class CTGridQueryDialog
       
    43 //
       
    44 
       
    45 CTGridQueryDialog::~CTGridQueryDialog()
       
    46 	{
       
    47 	//iEikonEnv->RemoveFromStack(this);	
       
    48 	}
       
    49 
       
    50 /*
       
    51 TBool CTGridQueryDialog::ExecuteLD()
       
    52 	{
       
    53 	ConstructL();
       
    54     CActiveScheduler::Start();
       
    55 	TBool exitConfirmed=iExitConfirmed;
       
    56 	delete this;
       
    57 	return exitConfirmed;
       
    58 	}
       
    59 */
       
    60 
       
    61 /**   Single argument Constructor for CTGridQueryDialog  */
       
    62 
       
    63 CTGridQueryDialog::CTGridQueryDialog(TBool& aIsColumn)
       
    64 	: iIsColumn(aIsColumn)
       
    65 	{}
       
    66 /**
       
    67   Second phase constructor for the query dialog.\n
       
    68   Creates a control window , 
       
    69   Set the control's extent and draws the control after activating the dialog.\n
       
    70 */
       
    71 void CTGridQueryDialog::ConstructL()
       
    72 	{
       
    73 	CreateWindowL();
       
    74 	SetExtent(TPoint(0,0),TSize(600,100));
       
    75 	//iEikonEnv->AddDialogLikeControlToStackL(this);
       
    76 	ActivateL();
       
    77 	DrawNow();
       
    78 	}
       
    79 /**
       
    80   Draw function related to CTGridQueryDialog box.\n
       
    81   Draws the dialog box with three options for resize column,row and to skip.\n
       
    82 */
       
    83 void CTGridQueryDialog::Draw(const TRect& /*aRect*/) const
       
    84 	{
       
    85 	CWindowGc& gc=iCoeEnv->SystemGc();
       
    86 	gc.SetPenColor(KRgbBlack);
       
    87 	gc.SetBrushColor(KRgbGray);
       
    88 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    89 	TRect border=Rect();
       
    90 	gc.DrawRect(border);
       
    91 	border.Shrink(5,5);
       
    92 	gc.DrawRect(border);
       
    93 	border.Shrink(5,5);
       
    94 	gc.SetBrushColor(KRgbBlack);
       
    95 	gc.UseFont(iCoeEnv->NormalFont());
       
    96 	TPoint pos=border.iTl;
       
    97 	pos.iY+=20;
       
    98 	gc.DrawText(_L("Press [C] to resize column, [R] to resize row, [Esc] to cancel"),pos);
       
    99 	pos.iY+=30;
       
   100 	gc.DrawText(_L("Resize with arrow keys, then [Enter] to resize or [Esc] to cancel"),pos);
       
   101 	}
       
   102  /**
       
   103     Auxilliary Fn for T-Grid0Step-RunTestStepL
       
   104     The query dialog box is used to handle user inputs regarding resizing.\n
       
   105     Handles the following key events.\n
       
   106     Esc Key Event - Skips the Resize.\n
       
   107     'r' Key Event - Invoked for resizing the row.\n
       
   108     'c' Key Event - Invoked for resizing the row.\n
       
   109  */   
       
   110 TKeyResponse CTGridQueryDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   111 	{
       
   112 	if(aType==EEventKey)
       
   113 		{
       
   114 		switch(User::LowerCase(aKeyEvent.iCode))
       
   115 			{
       
   116 		case EKeyEscape:
       
   117 			iExitConfirmed=EFalse;						
       
   118 		//	CActiveScheduler::Stop();
       
   119 			break;
       
   120 		case 'c': //C
       
   121 			iExitConfirmed=ETrue;
       
   122 			iIsColumn=ETrue;
       
   123 		//	CActiveScheduler::Stop();
       
   124 			break;
       
   125 		case 'r':  //R
       
   126 			iExitConfirmed=ETrue;
       
   127 			iIsColumn=EFalse;
       
   128 		//	CActiveScheduler::Stop();
       
   129 			break;
       
   130 		default:
       
   131 			break;
       
   132 			}
       
   133 		}
       
   134 	return EKeyWasConsumed;
       
   135 	}
       
   136 
       
   137 /**
       
   138   Static function to construct the Grid Window.\n
       
   139   Grid Window is a control on which the Grid table is displayed .\n
       
   140   Invokes the second phase constructor.\n
       
   141 */
       
   142 CGridWin* CGridWin::NewL(CCoeControl* aWin,CGridLay *aGridLay,CGridImg *aGridImg)
       
   143 	{
       
   144 	CGridWin *self=new(ELeave) CGridWin(aGridLay,aGridImg);
       
   145 	CleanupStack::PushL(self);
       
   146 	self->ConstructL(aWin);
       
   147 	CleanupStack::Pop();
       
   148 	return self;
       
   149 	}
       
   150 /**
       
   151   Sets the resize mode for the Grid Window.\n
       
   152   The typical values of the mode will be to resize column or row .\n
       
   153   The function is invoked when the user chooses to resize row or column.\n
       
   154 */
       
   155 void CGridWin::SetResizeMode(TResizeMode aMode)
       
   156 	{
       
   157 	iResizeMode=aMode;
       
   158 	}
       
   159 /**
       
   160   Returns the current resize mode for the Grid Window.\n
       
   161   The typical values of the mode will be to resize column or row .\n
       
   162 */
       
   163 TInt CGridWin::ResizeMode()
       
   164 	{
       
   165 	return iResizeMode;
       
   166 	}
       
   167 /**
       
   168   Two argument Constructor.\n
       
   169   Constructs a Grid Window taking GridLay and Grid Image as arguments.\n
       
   170 */
       
   171 CGridWin::CGridWin(CGridLay *aGridLay,CGridImg *aGridImg)
       
   172 	: iGridLay(aGridLay),
       
   173 	iGridImg(aGridImg),
       
   174 	iResizeMode(EResizeOff)
       
   175 	{}
       
   176 /**
       
   177   Second phase constructor for the Grid Window.\n
       
   178   Creates a control's window which is the child of the application's window group.\n
       
   179   Allows pointer grabs in a window in order to receive pointer events.\n
       
   180   Sets the window as the default window.\n
       
   181 */
       
   182 void CGridWin::ConstructL(CCoeControl* aWin)
       
   183 	{
       
   184 	CreateWindowL(aWin);
       
   185 	Window().PointerFilter(EPointerFilterDrag,0);
       
   186 	Window().SetPointerGrab(ETrue);
       
   187 	iGridImg->SetWindow(&Window());
       
   188 	if (iGridLay->IsIndefiniteRowBoundaries())
       
   189 		iGridLay->SetUniformRowHeight(ETrue);
       
   190 	}
       
   191 /**
       
   192   Destructor for the  Grid Window class.\n
       
   193 */
       
   194 CGridWin::~CGridWin()
       
   195 	{
       
   196 	}
       
   197 /**
       
   198   
       
   199   @return Pointer to the GridLay object owned by the Grid Window.\n
       
   200  
       
   201   The function is invoked in case modifications 
       
   202   need to be made to the layout of the grid.\n
       
   203 */
       
   204 CGridLay* CGridWin::GridLay() const
       
   205 	{
       
   206 	return iGridLay;
       
   207 	}
       
   208 /**
       
   209   @return Pointer to the GridImg object owned by the Grid Window.\n
       
   210  
       
   211   The function is invoked whenever there is a need to redraw the contents of the grid.\n
       
   212 */
       
   213 CGridImg* CGridWin::GridImg() const
       
   214 	{
       
   215 	return iGridImg;
       
   216 	}
       
   217 /**
       
   218   Draws the Grid Window.\n
       
   219   The function is invoked by the window server.\n
       
   220   This function is used for window server-initiated redrawing of controls,
       
   221   and for some application-initiated drawing.\n
       
   222   It should be implemented by each control.\n
       
   223  
       
   224 */
       
   225 void CGridWin::Draw(const TRect& aRect) const
       
   226 	{
       
   227 	CWindowGc& gc=SystemGc();
       
   228 	gc.DrawRect(Rect());
       
   229 	TRAPD(err,iGridImg->DrawL(&gc,aRect));
       
   230 	__ASSERT_ALWAYS(!err,User::Panic(_L("DrawL(&gc,aRect)"),err));
       
   231 	}
       
   232 
       
   233 TKeyResponse CGridWin::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
       
   234 // Tells GridImg to do the appropriate action on a keypress.
       
   235 	{
       
   236 	if(iResizeMode!=EResizeOff)
       
   237 		{
       
   238 		TKeyResponse response=EKeyWasNotConsumed;
       
   239 		if(iResizeMode==EResizeColumn)
       
   240 			{
       
   241 			switch(aKeyEvent.iCode)
       
   242 				{
       
   243 			case EKeyLeftArrow:
       
   244 				iGridImg->UpdateLabelResize(-4);
       
   245 				response=EKeyWasConsumed;
       
   246 				break;
       
   247 			case EKeyRightArrow:
       
   248 				iGridImg->UpdateLabelResize(4);
       
   249 				response=EKeyWasConsumed;
       
   250 				break;
       
   251 				}
       
   252 			}
       
   253 		else if(iResizeMode==EResizeRow)
       
   254 			{
       
   255 			switch(aKeyEvent.iCode)
       
   256 				{
       
   257 			case EKeyUpArrow:
       
   258 				iGridImg->UpdateLabelResize(-4);
       
   259 				response=EKeyWasConsumed;
       
   260 				break;
       
   261 			case EKeyDownArrow:
       
   262 				iGridImg->UpdateLabelResize(4);
       
   263 				response=EKeyWasConsumed;
       
   264 				break;
       
   265 				}
       
   266 			}
       
   267 		switch(aKeyEvent.iCode)
       
   268 			{
       
   269 		case EKeyEnter:
       
   270 			iGridImg->FinishLabelResizeL(ETrue);
       
   271 			iResizeMode=EResizeOff;
       
   272 			response=EKeyWasConsumed;
       
   273 			break;
       
   274 		case EKeyEscape:
       
   275 			iGridImg->FinishLabelResizeL(EFalse);
       
   276 			iResizeMode=EResizeOff;
       
   277 			response=EKeyWasConsumed;
       
   278 			break;
       
   279 			}
       
   280 		return response;
       
   281 		}
       
   282 	else
       
   283 		{
       
   284 		TUint selectState=0;
       
   285 		if (aKeyEvent.iModifiers&EModifierShift)
       
   286 			selectState=CGridImg::EIsWithSelect;
       
   287 		if (aKeyEvent.iModifiers&EModifierCtrl)
       
   288 			{
       
   289 			switch (aKeyEvent.iCode)
       
   290 				{
       
   291 			case EKeyUpArrow:
       
   292 				iGridImg->MoveCursorL(EMovePageUp,selectState);
       
   293 				break;
       
   294 			case EKeyDownArrow:
       
   295 				iGridImg->MoveCursorL(EMovePageDown,selectState);
       
   296 				break;
       
   297 			case EKeyLeftArrow:
       
   298 				iGridImg->MoveCursorL(EMovePageLeft,selectState);
       
   299 				break;
       
   300 			case EKeyRightArrow:
       
   301 				iGridImg->MoveCursorL(EMovePageRight,selectState);
       
   302 				break;
       
   303 			case EKeyHome:
       
   304 				iGridImg->MoveCursorL(EMoveHome,selectState);
       
   305 				break;
       
   306 			case EKeyEnd:
       
   307 				iGridImg->MoveCursorL(EMoveEnd,selectState);
       
   308 				break;
       
   309 			case EKeyPageUp:
       
   310 				iGridImg->MoveCursorL(EMoveColumnStart,selectState);
       
   311 				break;
       
   312 			case EKeyPageDown:
       
   313 				iGridImg->MoveCursorL(EMoveColumnEnd,selectState);
       
   314 				break;
       
   315 			default:
       
   316 				return EKeyWasNotConsumed;
       
   317 				}
       
   318 			}
       
   319 		else
       
   320 			{
       
   321 			switch (aKeyEvent.iCode)
       
   322 				{
       
   323 			case EKeyUpArrow:
       
   324 				iGridImg->MoveCursorL(EMoveRowUp,selectState);
       
   325 				break;
       
   326 			case EKeyDownArrow:
       
   327 				iGridImg->MoveCursorL(EMoveRowDown,selectState);
       
   328 				break;
       
   329 			case EKeyLeftArrow:
       
   330 				iGridImg->MoveCursorL(EMoveColumnLeft,selectState);
       
   331 				break;
       
   332 			case EKeyRightArrow:
       
   333 				iGridImg->MoveCursorL(EMoveColumnRight,selectState);
       
   334 				break;
       
   335 			case EKeyPageUp:
       
   336 				iGridImg->MoveCursorL(EMovePageUp,selectState);
       
   337 				break;
       
   338 			case EKeyPageDown:
       
   339 				iGridImg->MoveCursorL(EMovePageDown,selectState);
       
   340 				break;
       
   341 			case EKeyHome:
       
   342 				iGridImg->MoveCursorL(EMoveRowStart,selectState);
       
   343 				break;
       
   344 			case EKeyEnd:
       
   345 				iGridImg->MoveCursorL(EMoveRowEnd,selectState);
       
   346 				break;
       
   347 			default:
       
   348 				return EKeyWasNotConsumed;
       
   349 				}
       
   350 			}
       
   351 		}
       
   352 	return EKeyWasConsumed;
       
   353 	}
       
   354 /**
       
   355   Function handles the pointer events received by the control Window.\n
       
   356   Handles the following events.\n
       
   357   1. Pointer Drag.\n
       
   358   2. Double click.\n
       
   359   3. Ctrl+ ButtonDown.\n
       
   360   4. Shift+ Select.\n
       
   361 */
       
   362 void CGridWin::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   363 	{
       
   364 	//
       
   365 	// Tells GridImg to do the appropriate action on a pointer event
       
   366 	//
       
   367     if (aPointerEvent.iType==TPointerEvent::EDrag || aPointerEvent.iType==TPointerEvent::EButtonRepeat
       
   368 		&& !iGridImg->MainRect().Contains(aPointerEvent.iPosition))
       
   369 		{
       
   370         Window().RequestPointerRepeatEvent(KGridPointerRepeatDelayInMicroSeconds,KGridRectForPointerRepeats);
       
   371 		}
       
   372 	TPointerEvent event=aPointerEvent;
       
   373 	if (event.iType==TPointerEvent::EButtonRepeat)
       
   374 		event.iType=TPointerEvent::EDrag;
       
   375 	else if (event.iModifiers&EModifierDoubleClick)
       
   376 		event.iType=TPointerEvent::EButton1Down;
       
   377 
       
   378 	TUint flagList=0;
       
   379 	if (event.iModifiers&EModifierCtrl)
       
   380 		flagList=CGridImg::EIsWithControl;
       
   381 	if (event.iType == TPointerEvent::EButton1Up)
       
   382 		iGridImg->FinishLabelDragL();
       
   383 	else if (event.iType == TPointerEvent::EButton1Down)
       
   384 		{
       
   385 		if (!iGridImg->StartLabelDrag(event.iPosition))
       
   386 			{
       
   387 			if (event.iModifiers&EModifierShift)
       
   388 				flagList|=CGridImg::EIsWithSelect;
       
   389 			iGridImg->SetCursorWithPointerL(event.iPosition,flagList);
       
   390 			}
       
   391 		}
       
   392 	else if (event.iType == TPointerEvent::EDrag)
       
   393 		{
       
   394 		if (!iGridImg->UpdateLabelDrag(event.iPosition))
       
   395 			{
       
   396 			flagList|=CGridImg::EIsWithSelect|CGridImg::EIsWithDrag;
       
   397 			iGridImg->SetCursorWithPointerL(event.iPosition,flagList);
       
   398 			}
       
   399 		}
       
   400 	}
       
   401 /**
       
   402   Shrinks the Grid. 
       
   403   The shrinking is achieved by adding value of (1,1) to the top left corner.\n
       
   404   and subtracting the same coordinates from the bottom right corner of the grid.\n
       
   405 */
       
   406 void CGridWin::SizeChanged()
       
   407 	{
       
   408 	TRect rect(Size());
       
   409 	rect.Shrink(1,1);
       
   410 	iGridImg->SetGridRect(rect);
       
   411 	iGridLay->ResetVisibleToCell();
       
   412 	}
       
   413 /**
       
   414   Draw the cell corresponding to the reference.\n
       
   415   Calls the DrawCellL function of the CGridImg class.\n
       
   416 */
       
   417 void CGridWin::DrawCellL(const TCellRef& aCell) const
       
   418 	{
       
   419 	iGridImg->DrawCellL(aCell);
       
   420 	}
       
   421 /**
       
   422   Draws the rectangle corresponding to the range.\n
       
   423   Invokes the DrawRangeL function of the CGridImg class.\n
       
   424 */
       
   425 void CGridWin::DrawRangeL(const TRangeRef& aRange) const
       
   426 	{
       
   427 	iGridImg->DrawRangeL(aRange);
       
   428 	}
       
   429 /**
       
   430   Draws the currently selected region.\n
       
   431   Invokes the corresponding function of the CGridImg class.\n
       
   432 */
       
   433 void CGridWin::DrawSelectedL() const
       
   434 	{
       
   435 	iGridImg->DrawSelectedL();
       
   436 	}
       
   437 /**
       
   438   @return the cell reference where the cursor is located.\n
       
   439  
       
   440   Delegates the task to the corresponding function of CGridImg function.\n
       
   441 */
       
   442 TCellRef CGridWin::CursorPos() const
       
   443 	{
       
   444 	return iGridImg->CursorPos();
       
   445 	}
       
   446 /**
       
   447   Sets the cursor position to the cell reference sent as an argument.\n
       
   448 */
       
   449 void CGridWin::SetCursorPosL(const TCellRef& aCursorPos) const
       
   450 	{
       
   451 	iGridImg->SetCursorPosL(aCursorPos);
       
   452 	}
       
   453 /**
       
   454   Scrolls the grid by the minimum necessary to 
       
   455   allow the specified cell to become visible.\n
       
   456   The offset to the cell required to be visible is calculated and 
       
   457   a scroll operation is performed.\n
       
   458 */
       
   459 void CGridWin::ExposeCellL(const TCellRef& aCell) const
       
   460 	{
       
   461 	TPoint offset=iGridLay->ExposeCell(aCell);
       
   462 	iGridImg->ScrollL(offset);
       
   463 	}