|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : aknexquerycontainer.cpp 00004 * Part of : Query example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004 - 2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <eikenv.h> 00018 #include <eiklabel.h> // For label control 00019 #include <eikclb.h> // For listbox 00020 #include <eiktxlbm.h> // For listbox model 00021 #include <eikclbd.h> // For listbox data 00022 #include <aknlists.h> // For list pane 00023 #include <aknpopup.h> 00024 #include <aknpopupheadingpane.h> 00025 #include <akniconarray.h> 00026 #include <AknMessageQueryDialog.h> // for global message query 00027 #include <aknglobalconfirmationquery.h> // for global message query 00028 #include <StringLoader.h> 00029 #include <avkon.hrh> 00030 #include <avkon.rsg> 00031 #include <AKNEXQUERY.mbg> 00032 #include <AknListQueryDialog.h> 00033 #include <AknExQuery.rsg> 00034 #include "AknExQuery.hrh" 00035 #include "AknExQueryView.h" 00036 #include "AknExQueryContainer.h" 00037 #include "AknExQueryTimeAndDurationListEventHandler.h" 00038 00039 // ================= MEMBER FUNCTIONS ========================================= 00040 00041 // ---------------------------------------------------------------------------- 00042 // CAknExQueryContainer::CAknExQueryContainer() 00043 // Overload constructor. 00044 //----------------------------------------------------------------------------- 00045 // 00046 CAknExQueryContainer::CAknExQueryContainer( CAknExQueryView* aView ) 00047 : iView( aView ) 00048 { 00049 } 00050 00051 // ---------------------------------------------------------------------------- 00052 // CAknExQueryContainer::ConstructL() 00053 // two phased constructor 00054 //----------------------------------------------------------------------------- 00055 // 00056 void CAknExQueryContainer::ConstructL( const TRect& aRect ) 00057 { 00058 // Creates window. 00059 CreateWindowL(); 00060 00061 // Creates label object. 00062 if ( !iLabel ) 00063 { 00064 iLabel = new ( ELeave ) CEikLabel; 00065 iLabel->SetContainerWindowL( *this ); 00066 if (AknLayoutUtils::Variant() == EApacVariant) 00067 { 00068 iLabel->SetFont( ApacPlain16() ); 00069 } 00070 else 00071 { 00072 iLabel->SetFont( LatinBold19() ); 00073 } 00074 00075 SetTextToLabelL( R_AKNEXQUERY_TITLE_MESSAGE ); 00076 } 00077 00078 SetRect( aRect ); // Sets rectangle of frame. 00079 ActivateL(); // Activates the window. ( Ready to draw ) 00080 } 00081 00082 // ---------------------------------------------------------------------------- 00083 // CAknExQueryContainer::~CAknExQueryContainer() 00084 // Destructor. 00085 // ---------------------------------------------------------------------------- 00086 // 00087 CAknExQueryContainer::~CAknExQueryContainer() 00088 { 00089 delete iLabel; 00090 delete iLabelResultMessage; 00091 delete iListBox; 00092 delete iHandler; 00093 00094 delete iGlobalListQuery; 00095 delete iGlobalListObserver; 00096 } 00097 00098 // ---------------------------------------------------------------------------- 00099 // CAknExQueryContainer::ShowConfirmationQueryL() 00100 // Display of Confirmation Query. 00101 // ---------------------------------------------------------------------------- 00102 // 00103 void CAknExQueryContainer::ShowConfirmationQueryL( 00104 const TInt aResourceId, 00105 const TInt aTextResourceId, 00106 const TBool aPromptFlag, 00107 const TBool aToneFlag, 00108 const TBool aHeaderTextAndImageFlag, 00109 const CAknQueryDialog::TTone aTone 00110 ) 00111 { 00112 iDisplayDialog = ETrue; 00113 SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); 00114 CAknQueryDialog* dlg; 00115 00116 if ( aHeaderTextAndImageFlag ) 00117 { 00118 dlg = CAknQueryDialog::NewL( aTone ); 00119 dlg->PrepareLC( aResourceId ); 00120 TBuf<KAknExQueryTextBufLength> prompt; 00121 iCoeEnv->ReadResource( prompt, R_AKNEXQUERY_NUMQUERY_WITHHEAD_HEAD ); 00122 dlg->QueryHeading()->SetTextL( prompt ); 00123 SetIconL( dlg, EMbmAknexqueryAnchor_id, EMbmAknexqueryAnchor_id_mask ); 00124 dlg->RunLD(); 00125 } 00126 else 00127 { 00128 if ( !aTextResourceId ) 00129 { 00130 dlg = CAknQueryDialog::NewL( aTone ); 00131 } 00132 else 00133 { 00134 TBuf<KAknExQueryTextBufLength> prompt; 00135 iCoeEnv->ReadResource( prompt, aTextResourceId ); 00136 00137 if ( aPromptFlag ) 00138 { 00139 dlg = CAknQueryDialog::NewL( aTone ); 00140 CleanupStack::PushL( dlg ); 00141 dlg->SetPromptL( prompt ); 00142 CleanupStack::Pop(); 00143 } 00144 else if ( aToneFlag ) 00145 { 00146 dlg = new ( ELeave ) CAknQueryDialog( prompt, aTone ); 00147 } 00148 else 00149 { 00150 dlg = new ( ELeave ) CAknQueryDialog( prompt ); 00151 } 00152 } 00153 ShowResultMessageL( dlg->ExecuteLD( aResourceId ) ); 00154 } 00155 iDisplayDialog = EFalse; 00156 } 00157 00158 // ---------------------------------------------------------------------------- 00159 // CAknExQueryContainer::ShowResultMessageL() 00160 // Display return value of dialog. 00161 // ---------------------------------------------------------------------------- 00162 // 00163 void CAknExQueryContainer::ShowResultMessageL( TBool aResult ) 00164 { 00165 TInt res( R_AKNEXQUERY_NO_OR_CANCEL_MESSAGE ); 00166 00167 if ( aResult ) 00168 { 00169 res = R_AKNEXQUERY_YES_OR_OK_MESSAGE; 00170 } 00171 00172 TBuf<KAknExQueryTextBufLength> messageConfirmationQuery; 00173 iCoeEnv->ReadResource( messageConfirmationQuery, res ); 00174 00175 ShowMessageL( messageConfirmationQuery ); 00176 } 00177 00178 // ---------------------------------------------------------------------------- 00179 // CAknExQueryContainer::ShowDataQueryL() 00180 // Display of Data Query. 00181 // ---------------------------------------------------------------------------- 00182 // 00183 void CAknExQueryContainer::ShowDataQueryL( 00184 const TInt aQueryResourceId, 00185 const TInt aTextResourceId, 00186 const TInt aPromptResourceId, 00187 const TInt aMaxLength, 00188 const TBool aDisplayFlag ) 00189 { 00190 iDisplayDialog = ETrue; 00191 SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); 00192 00193 TBuf<KAknExQueryTextBufLength> textData; 00194 if ( aTextResourceId ) 00195 { 00196 iCoeEnv->ReadResource( textData, aTextResourceId ); 00197 } 00198 00199 CAknTextQueryDialog* dlg; 00200 if ( !aPromptResourceId ) 00201 { 00202 dlg = new ( ELeave )CAknTextQueryDialog( 00203 textData, CAknQueryDialog::ENoTone ); 00204 } 00205 else 00206 { 00207 TBuf<KAknExQueryTextBufLength> prompt; 00208 iCoeEnv->ReadResource( prompt, aTextResourceId ); 00209 dlg = CAknTextQueryDialog::NewL( 00210 textData, CAknQueryDialog::ENoTone ); 00211 CleanupStack::PushL( dlg ); 00212 dlg->SetPromptL( prompt ); 00213 CleanupStack::Pop(); // dlg 00214 } 00215 00216 if ( aMaxLength ) 00217 { 00218 dlg->SetMaxLength( aMaxLength ); 00219 } 00220 00221 TBool answer( dlg->ExecuteLD( aQueryResourceId ) ); 00222 00223 if ( aDisplayFlag && answer ) 00224 { 00225 iLabelResultMessage->SetTextL( textData ); 00226 } 00227 00228 iDisplayDialog = EFalse; 00229 00230 DrawNow(); 00231 } 00232 00233 // ---------------------------------------------------------------------------- 00234 // CAknExQueryContainer::ShowListQueryL() 00235 // Display of List Query. 00236 // ---------------------------------------------------------------------------- 00237 // 00238 void CAknExQueryContainer::ShowListQueryL( const TInt aResourceId ) 00239 { 00240 iDisplayDialog = ETrue; 00241 SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); 00242 CArrayFixFlat<TInt>* indexArray = NULL; 00243 CAknListQueryDialog* dlg; 00244 TInt index( 0 ); 00245 00246 if ( aResourceId == R_AKNEXQUERY_MULTI_SELECTION_LIST_QUERY ) 00247 { 00248 00249 indexArray = new ( ELeave ) CArrayFixFlat<TInt>( 6 ); 00250 CleanupStack::PushL( indexArray ); 00251 dlg = new ( ELeave ) CAknListQueryDialog( indexArray ); 00252 00253 } 00254 else 00255 { 00256 dlg = new ( ELeave ) CAknListQueryDialog( &index ); 00257 } 00258 00259 TInt answer( dlg->ExecuteLD( aResourceId ) ); 00260 00261 TBuf<KAknExQueryTextBufLength> text; 00262 if ( aResourceId == R_AKNEXQUERY_LIST_QUERY ) 00263 { 00264 if ( answer ) 00265 { 00266 TBuf<KAknExQueryTextBufLength> baseText; 00267 iCoeEnv->ReadResource( baseText, R_AKNEXQUERY_ITEM_SELECTED ); 00268 text.Format( baseText, index+1 ); 00269 ShowMessageL( text ); 00270 } 00271 else 00272 { 00273 iCoeEnv->ReadResource( text, R_AKNEXQUERY_QUERYDISCARDED ); 00274 ShowMessageL( text ); 00275 } 00276 } 00277 00278 if ( indexArray ) 00279 { 00280 CleanupStack::PopAndDestroy(); 00281 } 00282 iDisplayDialog = EFalse; 00283 } 00284 00285 00286 // ---------------------------------------------------------------------------- 00287 // CAknExQueryContainer::PopoutListBoxL() 00288 // Create handler. 00289 // ---------------------------------------------------------------------------- 00290 // 00291 void CAknExQueryContainer::PopoutListBoxL() 00292 { 00293 SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); 00294 00295 CreateListBoxL(); 00296 00297 iHandler->HandleListBoxEventL( 00298 iListBox, MEikListBoxObserver::EEventEnterKeyPressed ); 00299 } 00300 00301 // ---------------------------------------------------------------------------- 00302 // CAknExQueryContainer::CreateListBoxL() 00303 // Creates listbox object. 00304 // ---------------------------------------------------------------------------- 00305 // 00306 void CAknExQueryContainer::CreateListBoxL() 00307 { 00308 DeleteListBoxL(); 00309 00310 TInt resourceId = R_AKNEXQUERY_MULTILINE_TIME_AND_DURATION_LIST_ITEM; 00311 iHandler = new ( ELeave ) CAknExQueryTimeAndDurationListEventHandler( 00312 this ); 00313 00314 TInt flags( CEikListBox::EPopout | CEikListBox::ELeftDownInViewRect ); 00315 iListBox = new ( ELeave ) CEikColumnListBox; 00316 iListBox->ConstructL( this, flags ); 00317 00318 iListBox->SetListBoxObserver( iHandler ); 00319 iListBox->SetBorder( TGulBorder::EShallowRaised ); 00320 iListBox->CreateScrollBarFrameL( ETrue ); 00321 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 00322 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); 00323 00324 // Creates list items 00325 CDesCArray* textArray = iCoeEnv->ReadDesCArrayResourceL( resourceId ); 00326 iListBox->Model()->SetItemTextArray( textArray ); 00327 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); 00328 00329 // Sets pixel values of width. 00330 TRect rect( TPoint( KAknExQueryListBoxRectPointX, 00331 KAknExQueryListBoxRectPointY ), 00332 TSize( KAknExQueryListBoxRectWidth, 00333 KAknExQueryListBoxRectHeight ) ); 00334 00335 CColumnListBoxData* columnData = iListBox->ItemDrawer()->ColumnData(); 00336 columnData->SetColumnWidthPixelL( KAknExQueryNameColumnIndex, 00337 rect.Width() ); 00338 columnData->SetColumnWidthPixelL( KAknExQueryNameGapColumnIndex, 00339 rect.Width() ); 00340 00341 // Gets current number of list box items. 00342 TInt numberOfItems( iListBox->Model()->NumberOfItems() ); 00343 // Gets new height of list box. 00344 TInt height( iListBox->CalcHeightBasedOnNumOfItems( numberOfItems ) ); 00345 // If new height is less than defined height of list box 00346 // sets new height to list box height. 00347 if ( height < rect.Height() ) 00348 { 00349 rect.SetHeight( height ); 00350 } 00351 00352 iListBox->SetRect( rect ); // Sets rectangle of list box. 00353 ActivateL(); 00354 } 00355 00356 // ---------------------------------------------------------------------------- 00357 // CAknExQueryContainer::DeleteListBoxL() 00358 // Deletes listbox object. 00359 // ---------------------------------------------------------------------------- 00360 // 00361 void CAknExQueryContainer::DeleteListBoxL() 00362 { 00363 if ( iListBox ) 00364 { 00365 delete iListBox; 00366 iListBox = NULL; 00367 } 00368 if ( iHandler ) 00369 { 00370 delete iHandler; 00371 iHandler = NULL; 00372 } 00373 } 00374 00375 // ---------------------------------------------------------------------------- 00376 // CAknExQueryContainer::CreateLabelL() 00377 // Creates label object. 00378 // ---------------------------------------------------------------------------- 00379 // 00380 void CAknExQueryContainer::CreateLabelL( TInt aResourceId ) 00381 { 00382 if ( !iLabelResultMessage ) 00383 { 00384 iLabelResultMessage = new ( ELeave ) CEikLabel; 00385 iLabelResultMessage->SetContainerWindowL( *this ); 00386 iLabelResultMessage->SetRect( Rect() ); 00387 iLabelResultMessage->SetAlignment( EHCenterVTop ); 00388 iLabelResultMessage->SetPosition( AKNEXQUERY_LABEL2_POSITION ); 00389 if (AknLayoutUtils::Variant() == EApacVariant) 00390 { 00391 iLabelResultMessage->SetFont( ApacPlain16() ); 00392 } 00393 else 00394 { 00395 iLabelResultMessage->SetFont( LatinBold19() ); 00396 } 00397 } 00398 00399 TBuf<KAknExQueryTextBufLength> labelText; 00400 iCoeEnv->ReadResource( labelText, aResourceId ); 00401 iLabelResultMessage->SetTextL( labelText ); 00402 } 00403 00404 // ---------------------------------------------------------------------------- 00405 // CAknExQueryContainer::DeleteLabelL() 00406 // Deletes label object. 00407 // ---------------------------------------------------------------------------- 00408 // 00409 void CAknExQueryContainer::DeleteLabelL() 00410 { 00411 delete iLabelResultMessage; 00412 iLabelResultMessage = NULL; 00413 } 00414 00415 // ---------------------------------------------------------------------------- 00416 // CAknExQueryContainer::SetTextToLabelL() 00417 // Set Label text. 00418 // ---------------------------------------------------------------------------- 00419 // 00420 void CAknExQueryContainer::SetTextToLabelL( TInt aResourceId ) 00421 { 00422 TBuf<KAknExQueryTextBufLength> messageString; 00423 iCoeEnv->ReadResource( messageString, aResourceId ); 00424 iLabel->SetTextL( messageString ); 00425 DrawNow(); 00426 } 00427 00428 00429 // ---------------------------------------------------------------------------- 00430 // CAknExQueryContainer::ShowMessageL( const TDesC& aMessage ) 00431 // Show Message. 00432 // ---------------------------------------------------------------------------- 00433 // 00434 void CAknExQueryContainer::ShowMessageL( const TDesC& aMessage ) 00435 { 00436 iLabelResultMessage->SetTextL( aMessage ); 00437 DrawNow(); 00438 } 00439 00440 // ---------------------------------------------------------------------------- 00441 // CAknExQueryContainer::OfferKeyEventL() 00442 // Handles the key events. 00443 // ---------------------------------------------------------------------------- 00444 // 00445 TKeyResponse CAknExQueryContainer::OfferKeyEventL( 00446 const TKeyEvent& aKeyEvent, 00447 TEventCode aType ) 00448 { 00449 if ( aType != EEventKey ) 00450 { 00451 return EKeyWasNotConsumed; 00452 } 00453 switch ( aKeyEvent.iCode ) 00454 { 00455 case EKeySpace: 00456 if ( iDisplayDialog ) 00457 { 00458 return EKeyWasNotConsumed; 00459 } 00460 iView->DisplayNextOutlineL(); 00461 DrawNow(); 00462 break; 00463 default: 00464 if ( !iDisplayDialog && iListBox ) 00465 { 00466 return iListBox->OfferKeyEventL( aKeyEvent, aType ); 00467 } 00468 else 00469 { 00470 return EKeyWasNotConsumed; 00471 } 00472 } 00473 return EKeyWasConsumed; 00474 } 00475 00476 // ---------------------------------------------------------------------------- 00477 // CAknExQueryContainer::SizeChanged() 00478 // Called by framework when the view size is changed 00479 // ---------------------------------------------------------------------------- 00480 // 00481 void CAknExQueryContainer::SizeChanged() 00482 { 00483 if ( iLabel ) 00484 { 00485 iLabel->SetExtent( AKNEXQUERY_LABEL_ORIGIN, Size() ); 00486 iLabel->SetAlignment( EHCenterVCenter ); 00487 } 00488 } 00489 00490 // ---------------------------------------------------------------------------- 00491 // CAknExQueryContainer::CountComponentControls() const 00492 // Returns number of component. 00493 // ---------------------------------------------------------------------------- 00494 // 00495 TInt CAknExQueryContainer::CountComponentControls() const 00496 { 00497 TInt count( KAknExQueryCountComponentControls ); 00498 if ( iLabelResultMessage ) 00499 { 00500 count++; 00501 } 00502 if ( iListBox ) 00503 { 00504 count++; 00505 } 00506 return count; 00507 } 00508 00509 // ---------------------------------------------------------------------------- 00510 // CAknExQueryContainer::ComponentControl( TInt aIndex ) const 00511 // Returns pointer to particular component. 00512 // ---------------------------------------------------------------------------- 00513 // 00514 CCoeControl* CAknExQueryContainer::ComponentControl( TInt aIndex ) const 00515 { 00516 switch ( aIndex ) 00517 { 00518 case EAknExQueryComponentLabel: 00519 return iLabel; 00520 case EAknExQueryComponentLabel2: 00521 if ( iLabelResultMessage ) 00522 { 00523 return iLabelResultMessage; 00524 } 00525 else 00526 { 00527 return iListBox; 00528 } 00529 case EAknExQueryComponentListBox: 00530 return iListBox; 00531 default: 00532 return NULL; 00533 } 00534 } 00535 00536 // ---------------------------------------------------------------------------- 00537 // CAknExQueryContainer::Draw( const TRect& aRect ) const 00538 // 00539 // ---------------------------------------------------------------------------- 00540 // 00541 void CAknExQueryContainer::Draw( const TRect& aRect ) const 00542 { 00543 CWindowGc& gc = SystemGc(); 00544 gc.SetPenStyle( CGraphicsContext::ENullPen ); 00545 gc.SetBrushColor( KAknExQueryGray ); 00546 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00547 gc.DrawRect( aRect ); 00548 } 00549 00550 // ---------------------------------------------------------------------------- 00551 // CAknExQueryContainer::ShowMultiLineTimeAndDurationLayoutL 00552 // Display of MultiLine Time with Duration Query 00553 // ---------------------------------------------------------------------------- 00554 void CAknExQueryContainer::ShowMultiLineTimeAndDurationLayoutL( 00555 const TInt aResourceId, 00556 const TInt aTopResourceId) 00557 { 00558 iDisplayDialog = ETrue; 00559 SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); 00560 00561 TBuf<KAknExQueryTextBufLength> bufferRes; 00562 00563 iCoeEnv -> ReadResource(bufferRes, aTopResourceId); 00564 00565 TTime topDateTime; 00566 topDateTime.Set(bufferRes); 00567 topDateTime.HomeTime(); 00568 00569 TTimeIntervalSeconds bottomDuration = 300; // set timer field to 5 minutes 00570 00571 CAknMultiLineDataQueryDialog* dlg = 00572 CAknMultiLineDataQueryDialog::NewL( topDateTime, bottomDuration ); 00573 00574 dlg->ExecuteLD( aResourceId ); 00575 00576 iDisplayDialog = EFalse; 00577 } 00578 00579 // ---------------------------------------------------------------------------- 00580 // CAknExQueryContainer::SetIconL() 00581 // Set Icon dynamically 00582 // ---------------------------------------------------------------------------- 00583 void CAknExQueryContainer::SetIconL( CAknQueryDialog* aDlg, 00584 TInt32 aBitmap, 00585 TInt32 aMask ) 00586 { 00587 CEikImage* image = new ( ELeave ) CEikImage(); 00588 CleanupStack::PushL( image ); 00589 00590 CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL( 00591 KAknExQueryMbmFilePath, aBitmap ); 00592 CleanupStack::PushL( bitmap ); 00593 CFbsBitmap* mask = iEikonEnv->CreateBitmapL( 00594 KAknExQueryMbmFilePath, aMask ); 00595 CleanupStack::PushL( mask ); 00596 00597 image->SetBitmap( bitmap ); 00598 image->SetMask( mask ); 00599 CleanupStack::Pop( 2 ); //mask and bitmap 00600 00601 aDlg->QueryHeading()->SetHeaderImageL( image ); 00602 CleanupStack::PopAndDestroy(); //image 00603 } 00604 00605 // ---------------------------------------------------------------------------- 00606 // CAknExQueryContainer::ShowGlobalListQueryL() 00607 // ---------------------------------------------------------------------------- 00608 // 00609 void CAknExQueryContainer::ShowGlobalListQueryL() 00610 { 00611 iDisplayDialog = ETrue; 00612 SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); 00613 00614 CDesCArray* textArray = iCoeEnv->ReadDesCArrayResourceL( 00615 R_AKNEXQUERY_SUB_POPUP_DATA ); 00616 00617 CleanupStack::PushL( textArray ); 00618 00619 if ( iGlobalListObserver ) 00620 { 00621 iGlobalListObserver->Cancel(); 00622 delete iGlobalListObserver; 00623 iGlobalListObserver = NULL; 00624 } 00625 iGlobalListObserver = CAknExQueryGlobalListObserver::NewL( this ); 00626 iGlobalListObserver->UnsetSelectItemFlag(); 00627 00628 iGlobalListObserver->Start(); 00629 00630 if ( iGlobalListQuery ) 00631 { 00632 delete iGlobalListQuery; 00633 iGlobalListQuery = NULL; 00634 } 00635 iGlobalListQuery = CAknGlobalListQuery::NewL(); 00636 00637 iGlobalListObserver->SetSelectItemFlag(); 00638 iGlobalListQuery->ShowListQueryL( 00639 textArray, 00640 iGlobalListObserver->iStatus, 00641 0 ); 00642 00643 CleanupStack::PopAndDestroy(); // textArray 00644 iDisplayDialog = EFalse; 00645 } 00646 00647 // End of File
|
© Nokia 2009 |