widgetmanager/src/wmdetailsdlg.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 * Implementation of the widget details dlg for WidgetManager
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <gdi.h>
       
    21 #include <eikrted.h> // for CRichTextEditor
       
    22 #include <txtrich.h> // for CRichText
       
    23 #include <AknUtils.h> // for AknUtils
       
    24 #include <AknsUtils.h> // MAknsSkinInstance
       
    25 #include <AknsDrawUtils.h> // AknsDrawUtils
       
    26 #include <applayout.cdl.h> //layout
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include <aknlayoutscalable_avkon.cdl.h>
       
    29 #include <aknlayoutscalable_apps.cdl.h>
       
    30 #include <AknsBasicBackgroundControlContext.h>
       
    31 
       
    32 #include <widgetmanagerview.rsg>
       
    33 #include "widgetmanager.hrh"
       
    34 #include "wmdetailsdlg.h"
       
    35 
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 
       
    40 // MEMBER FUNCTIONS
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // FullScreenRect
       
    44 // rectangle representing the screen
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 TRect FullScreenRect()
       
    48     {
       
    49     TRect screen;
       
    50     CCoeEnv* env = CCoeEnv::Static();
       
    51     if ( env )
       
    52         {
       
    53         CWsScreenDevice* screenDevice = env->ScreenDevice();
       
    54         if ( screenDevice )
       
    55             screen.SetRect( TPoint(0,0), screenDevice->SizeInPixels() );
       
    56         }
       
    57     return screen;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CWmDetailsDlg::NewL
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 CWmDetailsDlg* CWmDetailsDlg::NewL(
       
    65 			const TDesC& aName,
       
    66 	        const TDesC& aDescription,
       
    67 	        TBool  aCanBeAdded,
       
    68             const CFbsBitmap* aLogoBmp,
       
    69             const CFbsBitmap* aLogoMask,
       
    70             CAknsBasicBackgroundControlContext* aBgContext )
       
    71     {
       
    72     CWmDetailsDlg* self = new ( ELeave ) CWmDetailsDlg( aCanBeAdded );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL( aName, aDescription, aLogoBmp, aLogoMask, aBgContext );
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CWmDetailsDlg::CWmDetailsDlg
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 CWmDetailsDlg::CWmDetailsDlg( TBool  aCanBeAdded )
       
    84     : CAknDialog(),
       
    85     iCanBeAdded( aCanBeAdded )
       
    86     {
       
    87     iBorder = TGulBorder::ERaisedControl;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CWmDetailsDlg::~CWmDetailsDlg
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 CWmDetailsDlg::~CWmDetailsDlg()
       
    95     {
       
    96     iEikonEnv->RemoveFromStack( iRtEditor );
       
    97     iEikonEnv->RemoveFromStack( this );
       
    98     delete iRtEditor;
       
    99     delete iName;
       
   100     delete iDescription;
       
   101     delete iLogoBmp;
       
   102     delete iLogoMask;	
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CWmDetailsDlg::ExecuteLD
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TInt CWmDetailsDlg::ExecuteLD()
       
   110     {
       
   111     if ( iCanBeAdded )
       
   112         {
       
   113         return CAknDialog::ExecuteLD( R_WM_DETAILS_ADD_DIALOG );
       
   114         }
       
   115     else
       
   116         {
       
   117         return CAknDialog::ExecuteLD( R_WM_DETAILS_ONLY_DIALOG );
       
   118         }
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CWmDetailsDlg::ConstructL
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 void CWmDetailsDlg::ConstructL(
       
   126 			const TDesC& aName,
       
   127 	        const TDesC& aDescription,
       
   128             const CFbsBitmap* aLogoBmp,
       
   129             const CFbsBitmap* aLogoMask,
       
   130             CAknsBasicBackgroundControlContext* aBgContext )
       
   131     {
       
   132     if ( !aLogoBmp )
       
   133         {
       
   134         User::Leave( KErrArgument );
       
   135         }
       
   136  
       
   137 	CAknDialog::ConstructL( R_AVKON_DIALOG_EMPTY_MENUBAR );
       
   138     
       
   139 	iBgContext = aBgContext;
       
   140 	iName = aName.AllocL();
       
   141 	iDescription = aDescription.AllocL();
       
   142 	
       
   143 	// create bitmap and duplicate handle
       
   144 	iLogoBmp = new ( ELeave ) CFbsBitmap;
       
   145     TSize newSize = TSize( aLogoBmp->SizeInPixels().iWidth ,
       
   146                            aLogoBmp->SizeInPixels().iHeight );
       
   147     User::LeaveIfError( iLogoBmp->Create( newSize, aLogoBmp->DisplayMode() ) );    
       
   148     User::LeaveIfError( iLogoBmp->Duplicate( aLogoBmp->Handle() ) );
       
   149 	
       
   150     if ( aLogoMask )
       
   151         {
       
   152         iLogoMask = new ( ELeave ) CFbsBitmap;
       
   153         newSize = TSize( aLogoMask->SizeInPixels().iWidth ,
       
   154                          aLogoMask->SizeInPixels().iHeight );
       
   155         User::LeaveIfError( iLogoMask->Create( newSize, aLogoMask->DisplayMode() ) );    
       
   156         User::LeaveIfError( iLogoMask->Duplicate( aLogoMask->Handle() ) );
       
   157         }
       
   158 
       
   159     iEikonEnv->AddWindowShadow( static_cast<CCoeControl*>(this) );
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CWmDetailsDlg::OkToExitL
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 TBool CWmDetailsDlg::OkToExitL( TInt aButtonId )
       
   167 	{
       
   168     if ( aButtonId == ECbaAddToHs ||
       
   169 		aButtonId == EAknSoftkeyClose )
       
   170         {
       
   171         // Close dlg
       
   172         return ETrue;
       
   173         }
       
   174     return EFalse;
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CWmDetailsDlg::PreLayoutDynInitL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CWmDetailsDlg::PreLayoutDynInitL()
       
   182     {
       
   183     iRtEditor = new(ELeave) CEikRichTextEditor();
       
   184     iRtEditor->ConstructL( this, 
       
   185                         0, 
       
   186                         0, 
       
   187                         CEikEdwin::EReadOnly | 
       
   188                         CEikEdwin::ENoAutoSelection | 
       
   189                         CEikEdwin::EAvkonDisableCursor |
       
   190                         CEikEdwin::EDisplayOnly );
       
   191     iRtEditor->SetContainerWindowL(*this);
       
   192     iRtEditor->SetAknEditorFlags( 
       
   193                     EAknEditorFlagEnableScrollBars | 
       
   194                     EEikEdwinAvkonDisableCursor |
       
   195                     EEikEdwinDisplayOnly |
       
   196                     EEikEdwinReadOnly );
       
   197 
       
   198     iRtEditor->SetSkinBackgroundControlContextL( iBgContext );
       
   199     
       
   200     CEikScrollBarFrame* scrollBarFrame = iRtEditor->CreateScrollBarFrameL();
       
   201     scrollBarFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   202                                              CEikScrollBarFrame::EOff );
       
   203     
       
   204     InsertAndFormatContentL();
       
   205     iRtEditor->UpdateScrollBarsL();
       
   206     }
       
   207 
       
   208 //------------------------------------------------------------------------------
       
   209 // CWmDetailsDlg::InsertAndFormatContentL
       
   210 //------------------------------------------------------------------------------
       
   211 //
       
   212 void CWmDetailsDlg::InsertAndFormatContentL()
       
   213     {
       
   214     CRichText* richText = iRtEditor->RichText();
       
   215     const TInt KMinTxtLength = 100;
       
   216     
       
   217     richText->Reset();
       
   218     if ( iDescription->Des().Length() <= KMinTxtLength )
       
   219         {     
       
   220         richText->InsertL( richText->DocumentLength(),
       
   221                 CEditableText::ELineBreak );
       
   222         }
       
   223     richText->InsertL( richText->DocumentLength(), *iDescription );
       
   224 
       
   225     // change the color of the text according to the skin color
       
   226     TRgb color = KRgbBlack;
       
   227     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   228     AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
       
   229                                                     EAknsCIQsnTextColorsCG6 );
       
   230 
       
   231     // Format text 
       
   232     iRtEditor->SetSelectionL( 0, richText->DocumentLength() );
       
   233 
       
   234     // Get a logical font to base my font on:
       
   235     const CFont* logicalFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont);
       
   236     // Extract font information
       
   237     TFontSpec fontspec = logicalFont->FontSpecInTwips();
       
   238     TCharFormat charFormat(fontspec.iTypeface.iName, fontspec.iHeight);
       
   239     TCharFormatMask charFormatMask;
       
   240     CParaFormat paraFormat;
       
   241     TParaFormatMask paraFormatMask;
       
   242     paraFormat.iHorizontalAlignment = CParaFormat::EJustifiedAlign;
       
   243     charFormat.iFontPresentation.iTextColor = color;
       
   244     paraFormatMask.SetAttrib(EAttAlignment);
       
   245     charFormatMask.SetAttrib(EAttFontTypeface);
       
   246     charFormatMask.SetAttrib(EAttFontHeight);
       
   247     charFormatMask.SetAttrib(EAttColor);
       
   248     iRtEditor->ApplyParaFormatL(&paraFormat, paraFormatMask);
       
   249     iRtEditor->ApplyCharFormatL(charFormat, charFormatMask);
       
   250     iRtEditor->ClearSelectionL();
       
   251     }
       
   252 
       
   253 //------------------------------------------------------------------------------
       
   254 // CWmDetailsDlg::CountComponentControls
       
   255 //------------------------------------------------------------------------------
       
   256 //
       
   257 TInt CWmDetailsDlg::CountComponentControls() const
       
   258     {
       
   259     return iRtEditor ? 1 : 0;
       
   260     }
       
   261 
       
   262 //------------------------------------------------------------------------------
       
   263 // CWmDetailsDlg::ComponentControl
       
   264 //------------------------------------------------------------------------------
       
   265 //
       
   266 CCoeControl* CWmDetailsDlg::ComponentControl(TInt aIndex) const
       
   267     {
       
   268     switch (aIndex)
       
   269         {
       
   270         case 0:
       
   271             return iRtEditor;
       
   272         default:
       
   273             return NULL;
       
   274         }
       
   275     }
       
   276 
       
   277 //------------------------------------------------------------------------------
       
   278 // CWmDetailsDlg::ActivateL
       
   279 //------------------------------------------------------------------------------
       
   280 //
       
   281 void CWmDetailsDlg::ActivateL()
       
   282 	{
       
   283     CAknDialog::ActivateL();
       
   284 	iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityDialog );
       
   285     iEikonEnv->EikAppUi()->AddToStackL( iRtEditor );    
       
   286     iRtEditor->SetFocus( ETrue );
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CWmDetailsDlg::WmDetailsDialogRect
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TRect CWmDetailsDlg::WmDetailsDialogRect()
       
   294     {
       
   295     TRect mainPane, dlgRect;    
       
   296     TPoint topLeft;
       
   297     TInt desiredW, desiredH;    
       
   298     AknLayoutUtils::LayoutMetricsRect( 
       
   299             AknLayoutUtils::EApplicationWindow, mainPane );
       
   300 
       
   301     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   302         {
       
   303         desiredW = ( mainPane.Width() - (mainPane.Width()/4) );
       
   304         desiredH = ( mainPane.Height() - (mainPane.Height()/5) );        
       
   305         topLeft.iX = ( ( mainPane.Width() - desiredW ) /2);
       
   306         topLeft.iY = ( ( mainPane.Height() - desiredH ) /2);
       
   307         dlgRect.SetRect( topLeft, TSize( desiredW, desiredH ) );
       
   308         }
       
   309     else
       
   310         {
       
   311         desiredH = ( mainPane.Height() - (mainPane.Height()/4) );
       
   312         desiredW = ( mainPane.Width() - (mainPane.Width()/5) );
       
   313         topLeft.iX = ( ( mainPane.Width() - desiredW ) /2);
       
   314         topLeft.iY = ( ( mainPane.Height() - desiredH ) /2);
       
   315         dlgRect.SetRect( topLeft, TSize( desiredW, desiredH ) );        
       
   316         }
       
   317     return dlgRect;
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CWmDetailsDlg::SetSizeAndPosition
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CWmDetailsDlg::SetSizeAndPosition( const TSize& /*aSize*/ )
       
   325     {    
       
   326     SetRect( WmDetailsDialogRect() );
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CWmDetailsDlg::SizeChanged
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 void CWmDetailsDlg::SizeChanged()
       
   334     {
       
   335     CAknDialog::SizeChanged();
       
   336     TRect rect = Rect();
       
   337     if ( iBgContext ) { iBgContext->SetRect( FullScreenRect() ); }
       
   338     if ( iRtEditor ) 
       
   339         {
       
   340         const TInt offSet = 5;
       
   341         TRect cbaRect;
       
   342         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EControlPane, cbaRect );
       
   343         
       
   344         TInt logoH = iLogoBmp->SizeInPixels().iHeight;
       
   345         
       
   346         TInt height, width;
       
   347         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   348             {        
       
   349             height = ( (rect.Height() - logoH) - (cbaRect.Height() * 2) - offSet );
       
   350             }
       
   351         else
       
   352             {
       
   353             height = ( (rect.Height() - logoH) - (cbaRect.Height() * 1.5) - offSet );
       
   354             }
       
   355  
       
   356         width = ( rect.Width() - (CEikScrollBar::DefaultScrollBarBreadth() * 4 ) - offSet );
       
   357         TPoint point = TPoint( rect.iTl.iX + offSet, rect.iTl.iY + logoH + offSet );
       
   358         TSize size = TSize( width, height );
       
   359         iRtEditor->SetRect( TRect( point, size ) );
       
   360         TRAP_IGNORE( 
       
   361             iRtEditor->SetSkinBackgroundControlContextL( iBgContext );
       
   362             InsertAndFormatContentL(); );
       
   363         }
       
   364     }
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // CWmDetailsDlg::SupplyMopObject
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 TTypeUid::Ptr CWmDetailsDlg::MopSupplyObject( TTypeUid aId )
       
   371     {
       
   372     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   373         {
       
   374         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   375         }
       
   376     return CAknDialog::MopSupplyObject( aId );
       
   377     }
       
   378 	
       
   379 // ----------------------------------------------------------------------------
       
   380 // CWmDetailsDlg::OfferKeyEventL
       
   381 // ----------------------------------------------------------------------------
       
   382 //
       
   383 TKeyResponse CWmDetailsDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType )
       
   384 	{
       
   385 	if (aType == EEventKey)
       
   386 		{
       
   387 		switch (aKeyEvent.iCode)
       
   388 			{			
       
   389 			case EKeyEscape:
       
   390 				{
       
   391 				// framework calls this when dialog must shut down
       
   392 				return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   393         		}
       
   394 			case EKeyDownArrow:
       
   395                 {
       
   396                 if ( iRtEditor )
       
   397                     {
       
   398                     iRtEditor->MoveCursorL(TCursorPosition::EFPageDown, EFalse);
       
   399                     return EKeyWasConsumed;
       
   400                     }
       
   401                 }
       
   402             case EKeyUpArrow:
       
   403                 {
       
   404                 if ( iRtEditor )
       
   405                     {
       
   406                     iRtEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
       
   407                     return EKeyWasConsumed;
       
   408                     }
       
   409                 }				
       
   410             default:
       
   411 				{
       
   412 				if ( iRtEditor )
       
   413 					{
       
   414 					return iRtEditor->OfferKeyEventL( aKeyEvent, aType );
       
   415 					}
       
   416 			    break;
       
   417 				}
       
   418 			}
       
   419 		}
       
   420 	return CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   421 	}
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CWmDetailsDlg::Draw
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 void CWmDetailsDlg::Draw( const TRect& /*aRect*/ ) const
       
   428     {
       
   429     CWindowGc& gc = SystemGc();
       
   430     TRect rect = Rect();
       
   431     TRect innerRect( rect );
       
   432     TRgb color = KRgbBlack;
       
   433     const TInt offSet = 5;
       
   434 
       
   435     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   436     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   437 
       
   438     // draw background
       
   439     if ( !AknsDrawUtils::Background( skin, cc, this, gc, innerRect ) )
       
   440         {
       
   441         gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   442         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   443         gc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
       
   444         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   445         gc.DrawRect( innerRect );
       
   446         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   447         }
       
   448 
       
   449     // to fix scrollbar background issue in richtext editor
       
   450     if ( iRtEditor ) 
       
   451         {
       
   452         MAknsControlContext* ccRte = AknsDrawUtils::ControlContext( iRtEditor );
       
   453         AknsDrawUtils::Background( skin, ccRte, iRtEditor, gc, iRtEditor->Rect() );
       
   454         }
       
   455     
       
   456     // draw logo
       
   457     TRect bmpRect( TPoint(0,0), TSize( iLogoBmp->SizeInPixels() ) );
       
   458     TPoint point = TPoint( innerRect.iTl.iX + offSet,
       
   459                            innerRect.iTl.iY + offSet );
       
   460 
       
   461     if ( iLogoBmp && iLogoMask )
       
   462         {
       
   463         gc.BitBltMasked( point, iLogoBmp, 
       
   464                          bmpRect, iLogoMask, ETrue );
       
   465         }
       
   466     else
       
   467         {
       
   468         gc.BitBlt( point, iLogoBmp, bmpRect );
       
   469         }
       
   470 
       
   471     // draw name
       
   472     point.iX += (bmpRect.Width() + offSet);
       
   473     
       
   474     AknsUtils::GetCachedColor( 
       
   475                     skin, color, 
       
   476                     KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   477 
       
   478     // DRAW TEXT
       
   479     const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont );
       
   480     gc.UseFont( font );
       
   481     gc.SetPenColor( color );
       
   482     gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   483     point.iY += (bmpRect.Height() - (font->HeightInPixels() /2 ) );
       
   484     CGraphicsContext::TDrawTextParam param;
       
   485     
       
   486     HBufC* buf = iName->Des().Alloc();
       
   487     if ( buf )
       
   488         {
       
   489         TPtr bufPtr = buf->Des();
       
   490         TextUtils::ClipToFit( bufPtr, *font, (innerRect.Width() - point.iX ) );
       
   491         gc.DrawText( bufPtr ,point, param );
       
   492         delete buf;
       
   493         }
       
   494     else
       
   495         {
       
   496         gc.DrawText( *iName ,point, param );
       
   497         }
       
   498     
       
   499     gc.DiscardFont();
       
   500     
       
   501     // draw the rounded rectangle as border
       
   502     const TInt KFrameRoundRadius = 3;
       
   503     const TInt KBorderWidth = 2;
       
   504     gc.SetPenSize( TSize( KBorderWidth, KBorderWidth ) );    
       
   505     gc.DrawRoundRect( innerRect, TSize( KFrameRoundRadius, KFrameRoundRadius ) );
       
   506     
       
   507     // draw shadow
       
   508     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   509     gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   510     gc.SetBrushColor( color );
       
   511     gc.SetPenColor( color );
       
   512     TRect rightShadowArea = Rect();
       
   513     rightShadowArea.iTl.iX = rightShadowArea.iBr.iX - offSet;
       
   514     rightShadowArea.iTl.iY += offSet/2;
       
   515     gc.DrawRect(rightShadowArea);
       
   516     TRect bottomShadowArea = Rect();
       
   517     bottomShadowArea.iTl.iX += offSet/2;
       
   518     bottomShadowArea.iTl.iY += bottomShadowArea.iBr.iY - offSet;
       
   519     gc.DrawRect( bottomShadowArea );
       
   520     gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   521     gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   522     }
       
   523 
       
   524 // End of File
       
   525