idlehomescreen/widgetmanager/src/wmdetailsdlg.cpp
changeset 5 c743ef5928ba
parent 2 08c6ee43b396
child 34 d05a55b217df
--- a/idlehomescreen/widgetmanager/src/wmdetailsdlg.cpp	Tue Jan 26 11:48:23 2010 +0200
+++ b/idlehomescreen/widgetmanager/src/wmdetailsdlg.cpp	Tue Feb 02 00:04:13 2010 +0200
@@ -28,7 +28,7 @@
 #include <aknlayoutscalable_avkon.cdl.h>
 #include <aknlayoutscalable_apps.cdl.h>
 #include <AknsBasicBackgroundControlContext.h>
-
+#include <AknMarqueeControl.h>
 #include <widgetmanagerview.rsg>
 #include "widgetmanager.hrh"
 #include "wmdetailsdlg.h"
@@ -40,24 +40,6 @@
 // MEMBER FUNCTIONS
 
 // ---------------------------------------------------------
-// FullScreenRect
-// rectangle representing the screen
-// ---------------------------------------------------------
-//
-TRect FullScreenRect()
-    {
-    TRect screen;
-    CCoeEnv* env = CCoeEnv::Static();
-    if ( env )
-        {
-        CWsScreenDevice* screenDevice = env->ScreenDevice();
-        if ( screenDevice )
-            screen.SetRect( TPoint(0,0), screenDevice->SizeInPixels() );
-        }
-    return screen;
-    }
-
-// ---------------------------------------------------------
 // CWmDetailsDlg::NewL
 // ---------------------------------------------------------
 //
@@ -66,12 +48,11 @@
 	        const TDesC& aDescription,
 	        TBool  aCanBeAdded,
             const CFbsBitmap* aLogoBmp,
-            const CFbsBitmap* aLogoMask,
-            CAknsBasicBackgroundControlContext* aBgContext )
+            const CFbsBitmap* aLogoMask )
     {
     CWmDetailsDlg* self = new ( ELeave ) CWmDetailsDlg( aCanBeAdded );
     CleanupStack::PushL( self );
-    self->ConstructL( aName, aDescription, aLogoBmp, aLogoMask, aBgContext );
+    self->ConstructL( aName, aDescription, aLogoBmp, aLogoMask );
     CleanupStack::Pop( self );
     return self;
     }
@@ -82,9 +63,10 @@
 //
 CWmDetailsDlg::CWmDetailsDlg( TBool  aCanBeAdded )
     : CAknDialog(),
-    iCanBeAdded( aCanBeAdded )
+    iCanBeAdded( aCanBeAdded ),
+    iNeedToScroll( EFalse )
     {
-    iBorder = TGulBorder::ERaisedControl;
+    iBorder = TGulBorder::ERaisedControl;    
     }
 
 // ---------------------------------------------------------
@@ -93,13 +75,16 @@
 //
 CWmDetailsDlg::~CWmDetailsDlg()
     {
+    StopMarquee();
     iEikonEnv->RemoveFromStack( iRtEditor );
     iEikonEnv->RemoveFromStack( this );
     delete iRtEditor;
+    delete iMarquee;
     delete iName;
     delete iDescription;
     delete iLogoBmp;
-    delete iLogoMask;	
+    delete iLogoMask;
+    delete iBgContext;
     }
 
 // -----------------------------------------------------------------------------
@@ -126,8 +111,7 @@
 			const TDesC& aName,
 	        const TDesC& aDescription,
             const CFbsBitmap* aLogoBmp,
-            const CFbsBitmap* aLogoMask,
-            CAknsBasicBackgroundControlContext* aBgContext )
+            const CFbsBitmap* aLogoMask )
     {
     if ( !aLogoBmp )
         {
@@ -136,10 +120,12 @@
  
 	CAknDialog::ConstructL( R_AVKON_DIALOG_EMPTY_MENUBAR );
     
-	iBgContext = aBgContext;
+	iBgContext = CAknsBasicBackgroundControlContext::NewL( 
+	        KAknsIIDQsnFrPopupCenter, TRect(0,0,1,1), EFalse);
+
 	iName = aName.AllocL();
 	iDescription = aDescription.AllocL();
-	
+
 	// create bitmap and duplicate handle
 	iLogoBmp = new ( ELeave ) CFbsBitmap;
     TSize newSize = TSize( aLogoBmp->SizeInPixels().iWidth ,
@@ -155,7 +141,7 @@
         User::LeaveIfError( iLogoMask->Create( newSize, aLogoMask->DisplayMode() ) );    
         User::LeaveIfError( iLogoMask->Duplicate( aLogoMask->Handle() ) );
         }
-
+    
     iEikonEnv->AddWindowShadow( static_cast<CCoeControl*>(this) );
     }
 
@@ -195,11 +181,17 @@
                     EEikEdwinDisplayOnly |
                     EEikEdwinReadOnly );
 
-    iRtEditor->SetSkinBackgroundControlContextL( iBgContext );
-    
     CEikScrollBarFrame* scrollBarFrame = iRtEditor->CreateScrollBarFrameL();
     scrollBarFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
-                                             CEikScrollBarFrame::EOff );
+                                             CEikScrollBarFrame::EOff ); // set to EAuto 
+                                             // when layout fixed. ~wk04_2010
+                                             // currently scrollbar overlaps cba.
+    
+    iMarquee = CAknMarqueeControl::NewL();
+    TCallBack callback( RedrawCallback, this );
+    iMarquee->SetRedrawCallBack( callback );
+    iMarquee->SetLoops( 1 );
+    iMarquee->SetContainerWindowL( *this );
     
     InsertAndFormatContentL();
     iRtEditor->UpdateScrollBarsL();
@@ -212,14 +204,8 @@
 void CWmDetailsDlg::InsertAndFormatContentL()
     {
     CRichText* richText = iRtEditor->RichText();
-    const TInt KMinTxtLength = 100;
     
     richText->Reset();
-    if ( iDescription->Des().Length() <= KMinTxtLength )
-        {     
-        richText->InsertL( richText->DocumentLength(),
-                CEditableText::ELineBreak );
-        }
     richText->InsertL( richText->DocumentLength(), *iDescription );
 
     // change the color of the text according to the skin color
@@ -263,7 +249,12 @@
 //
 TInt CWmDetailsDlg::CountComponentControls() const
     {
-    return iRtEditor ? 1 : 0;
+    TInt count( 0 );
+    if ( iRtEditor )
+        count++;
+    if ( iMarquee )
+        count++;
+    return count;
     }
 
 //------------------------------------------------------------------------------
@@ -276,6 +267,8 @@
         {
         case 0:
             return iRtEditor;
+        case 1:
+            return iMarquee;
         default:
             return NULL;
         }
@@ -294,43 +287,17 @@
     }
 
 // -----------------------------------------------------------------------------
-// CWmDetailsDlg::WmDetailsDialogRect
-// -----------------------------------------------------------------------------
-//
-TRect CWmDetailsDlg::WmDetailsDialogRect()
-    {
-    TRect mainPane, dlgRect;    
-    TPoint topLeft;
-    TInt desiredW, desiredH;    
-    AknLayoutUtils::LayoutMetricsRect( 
-            AknLayoutUtils::EApplicationWindow, mainPane );
-
-    if ( Layout_Meta_Data::IsLandscapeOrientation() )
-        {
-        desiredW = ( mainPane.Width() - (mainPane.Width()/4) );
-        desiredH = ( mainPane.Height() - (mainPane.Height()/5) );        
-        topLeft.iX = ( ( mainPane.Width() - desiredW ) /2);
-        topLeft.iY = ( ( mainPane.Height() - desiredH ) /2);
-        dlgRect.SetRect( topLeft, TSize( desiredW, desiredH ) );
-        }
-    else
-        {
-        desiredH = ( mainPane.Height() - (mainPane.Height()/4) );
-        desiredW = ( mainPane.Width() - (mainPane.Width()/5) );
-        topLeft.iX = ( ( mainPane.Width() - desiredW ) /2);
-        topLeft.iY = ( ( mainPane.Height() - desiredH ) /2);
-        dlgRect.SetRect( topLeft, TSize( desiredW, desiredH ) );        
-        }
-    return dlgRect;
-    }
-
-// -----------------------------------------------------------------------------
 // CWmDetailsDlg::SetSizeAndPosition
 // -----------------------------------------------------------------------------
 //
 void CWmDetailsDlg::SetSizeAndPosition( const TSize& /*aSize*/ )
     {    
-    SetRect( WmDetailsDialogRect() );
+    TRect mainPane;
+    AknLayoutUtils::LayoutMetricsRect(
+            AknLayoutUtils::EApplicationWindow, mainPane );
+    TAknWindowLineLayout dlgWindow = AknLayoutScalable_Apps
+               ::popup_wgtman_window().LayoutLine();
+    AknLayoutUtils::LayoutControl( this, mainPane, dlgWindow );
     }
 
 // -----------------------------------------------------------------------------
@@ -341,32 +308,29 @@
     {
     CAknDialog::SizeChanged();
     TRect rect = Rect();
-    if ( iBgContext ) { iBgContext->SetRect( FullScreenRect() ); }
+    if ( iBgContext ) { iBgContext->SetRect( rect ); }
     if ( iRtEditor ) 
         {
-        const TInt offSet = 5;
-        TRect cbaRect;
-        AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EControlPane, cbaRect );
-        
-        TInt logoH = iLogoBmp->SizeInPixels().iHeight;
-        
-        TInt height, width;
-        if ( Layout_Meta_Data::IsLandscapeOrientation() )
-            {        
-            height = ( (rect.Height() - logoH) - (cbaRect.Height() * 2) - offSet );
+        TAknLayoutRect layoutRect;
+        TAknWindowLineLayout contentPane = AknLayoutScalable_Apps
+                   ::wgtman_content_pane().LayoutLine();        
+        TAknWindowLineLayout rtePane = AknLayoutScalable_Apps
+                   ::wgtman_list_pane().LayoutLine();
+        layoutRect.LayoutRect( rect, contentPane );
+        AknLayoutUtils::LayoutControl( iRtEditor, layoutRect.Rect(), rtePane );
+        CEikScrollBarFrame* sbFrame = iRtEditor->ScrollBarFrame();
+        if ( sbFrame && sbFrame->VScrollBarVisibility() != CEikScrollBarFrame::EOff )
+            {
+            CEikScrollBar* scrollBar = sbFrame->VerticalScrollBar();
+            TAknWindowLineLayout scrollPane = AknLayoutScalable_Apps
+                           ::scroll_pane_cp036().LayoutLine();
+            AknLayoutUtils::LayoutControl( scrollBar, layoutRect.Rect(), scrollPane );
             }
-        else
-            {
-            height = ( (rect.Height() - logoH) - (cbaRect.Height() * 1.5) - offSet );
-            }
- 
-        width = ( rect.Width() - (CEikScrollBar::DefaultScrollBarBreadth() * 4 ) - offSet );
-        TPoint point = TPoint( rect.iTl.iX + offSet, rect.iTl.iY + logoH + offSet );
-        TSize size = TSize( width, height );
-        iRtEditor->SetRect( TRect( point, size ) );
         TRAP_IGNORE( 
             iRtEditor->SetSkinBackgroundControlContextL( iBgContext );
             InsertAndFormatContentL(); );
+
+        StartMarquee();
         }
     }
 
@@ -453,58 +417,62 @@
         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
         }
 
-    // to fix scrollbar background issue in richtext editor
-    if ( iRtEditor ) 
-        {
-        MAknsControlContext* ccRte = AknsDrawUtils::ControlContext( iRtEditor );
-        AknsDrawUtils::Background( skin, ccRte, iRtEditor, gc, iRtEditor->Rect() );
-        }
-    
     // draw logo
-    TRect bmpRect( TPoint(0,0), TSize( iLogoBmp->SizeInPixels() ) );
-    TPoint point = TPoint( innerRect.iTl.iX + offSet,
-                           innerRect.iTl.iY + offSet );
+    TAknLayoutRect layoutRect;
+    TAknWindowLineLayout headingPane = AknLayoutScalable_Apps
+               ::wgtman_heading_pane().LayoutLine();        
+    layoutRect.LayoutRect( rect, headingPane );
 
-    if ( iLogoBmp && iLogoMask )
+    if( iLogoBmp && iLogoMask )
         {
-        gc.BitBltMasked( point, iLogoBmp, 
-                         bmpRect, iLogoMask, ETrue );
+        TAknLayoutRect logoLayout;
+        logoLayout.LayoutRect( layoutRect.Rect(),AknLayoutScalable_Apps
+                ::wgtman_heading_pane_g1().LayoutLine() );        
+        logoLayout.DrawImage( gc, iLogoBmp, iLogoMask );
         }
-    else
-        {
-        gc.BitBlt( point, iLogoBmp, bmpRect );
-        }
-
-    // draw name
-    point.iX += (bmpRect.Width() + offSet);
     
     AknsUtils::GetCachedColor( 
                     skin, color, 
                     KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
 
     // DRAW TEXT
-    const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont );
+    TAknTextLineLayout titleTextLayout = 
+              AknLayoutScalable_Apps::wgtman_heading_pane_t1().LayoutLine();
+    TAknLayoutText textLayoutTitle;
+    textLayoutTitle.LayoutText( layoutRect.Rect(), titleTextLayout );
+    
+    const CFont* font = textLayoutTitle.Font();
+    if ( !font ) 
+        {
+        font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont ); 
+        }
+
     gc.UseFont( font );
     gc.SetPenColor( color );
     gc.SetPenStyle( CGraphicsContext::ESolidPen );
-    point.iY += (bmpRect.Height() - (font->HeightInPixels() /2 ) );
-    CGraphicsContext::TDrawTextParam param;
     
-    HBufC* buf = iName->Des().Alloc();
-    if ( buf )
+    TBool truncate( ETrue );
+
+    // check if name needs scrolling
+    if ( textLayoutTitle.Font()->TextWidthInPixels( *iName ) > 
+        textLayoutTitle.TextRect().Width() && IsFocused() )
         {
-        TPtr bufPtr = buf->Des();
-        TextUtils::ClipToFit( bufPtr, *font, (innerRect.Width() - point.iX ) );
-        gc.DrawText( bufPtr ,point, param );
-        delete buf;
+        const_cast<CWmDetailsDlg&>(*this).iNeedToScroll = ETrue;
+        const_cast<CWmDetailsDlg&>(*this).StartMarquee();
+        truncate = iMarquee->DrawText(
+                        gc, textLayoutTitle.TextRect(), *iName,               
+                        (textLayoutTitle.TextRect().Height() - font->FontMaxDescent()),
+                        CGraphicsContext::ELeft, *font );
         }
-    else
+
+    if ( truncate )
         {
-        gc.DrawText( *iName ,point, param );
+        const_cast<CWmDetailsDlg&>(*this).StopMarquee();
+        textLayoutTitle.DrawText( gc, *iName, ETrue, color );
         }
-    
+
     gc.DiscardFont();
-    
+
     // draw the rounded rectangle as border
     const TInt KFrameRoundRadius = 3;
     const TInt KBorderWidth = 2;
@@ -528,5 +496,67 @@
     gc.SetPenStyle( CGraphicsContext::ENullPen );
     }
 
+// ---------------------------------------------------------
+// CWmDetailsDlg::RedrawCallback
+// ---------------------------------------------------------
+//
+TInt CWmDetailsDlg::RedrawCallback( TAny* aPtr )
+    {
+    CWmDetailsDlg* self = 
+        static_cast<CWmDetailsDlg*>( aPtr );
+    if ( !self->iNeedToScroll )
+        {
+        self->StopMarquee();    
+        }
+    self->DrawDeferred();
+    return static_cast<TBool>( ETrue );
+    }
+
+// ---------------------------------------------------------
+// CWmDetailsDlg::StartMarquee
+// ---------------------------------------------------------
+//
+void CWmDetailsDlg::StartMarquee()
+    {
+    if ( iMarquee && iNeedToScroll &&
+        !iMarquee->IsMarqueeOn() )
+        {
+        iMarquee->Reset();
+        iMarquee->EnableMarquee( iNeedToScroll );
+        iMarquee->Start();
+        }
+    }
+
+// ---------------------------------------------------------
+// CWmDetailsDlg::StopMarquee
+// ---------------------------------------------------------
+//
+void CWmDetailsDlg::StopMarquee()
+    {
+    if ( iMarquee && iMarquee->IsMarqueeOn() )
+        {
+        iMarquee->EnableMarquee( EFalse );
+        iMarquee->Stop();        
+        }
+    }
+
+// ---------------------------------------------------------
+// CWmDetailsDlg::FocusChanged
+// ---------------------------------------------------------
+//
+void CWmDetailsDlg::FocusChanged( TDrawNow aDrawNow )
+    {
+    CCoeControl::FocusChanged( aDrawNow );
+    if ( IsFocused() )
+        {
+        StartMarquee();
+        }
+    else
+        {
+        StopMarquee();
+        }
+    }
+
+
 // End of File