uifw/AvKon/src/akninfrm.cpp
changeset 0 2f259fa3e83a
child 10 9f56a4e1b8ab
child 14 3320e4e6e8bb
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *
       
    16 */
       
    17 
       
    18 
       
    19 // Akninfrm.cpp
       
    20 //
       
    21 // Copyright (c) 1997-2001 Symbian Ltd.  All rights reserved.
       
    22 //
       
    23 #include <akninfrm.h>
       
    24 #include <eikenv.h>
       
    25 #include <barsread.h>
       
    26 #include <eikedwin.h>
       
    27 
       
    28 #include <AknsDrawUtils.h>
       
    29 #include <AknsBasicBackgroundControlContext.h>
       
    30 #include <aknlists.h>
       
    31 #include <AknsFrameBackgroundControlContext.h>
       
    32 
       
    33 #include <aknconsts.h>
       
    34 #include <avkon.mbg>
       
    35 
       
    36 #include <aknlayout.cdl.h>
       
    37 #include <aknlayoutscalable_avkon.cdl.h>
       
    38 #include <aknlayoutscalable_apps.cdl.h>
       
    39 #include <aknapaclayout.cdl.h>
       
    40 #include <AknIconUtils.h>
       
    41 
       
    42 #include "akntrace.h"
       
    43 CAknInputFrame::CAknInputFrame() 
       
    44     {
       
    45     }
       
    46 
       
    47 EXPORT_C CAknInputFrame::~CAknInputFrame()
       
    48     {
       
    49     AknsUtils::DeregisterControlPosition( iField );
       
    50     delete iIcon;
       
    51     delete iPopupFindCC;
       
    52     delete iPopupListCC;
       
    53     delete iFileName;
       
    54 
       
    55     if ( iFlags & EOwnsInputContext )
       
    56         {
       
    57         delete iInputContext;
       
    58         }
       
    59     
       
    60     if ( iFlags & EOwnsField )
       
    61         {
       
    62         delete iField;
       
    63         }
       
    64     }
       
    65 
       
    66 /**
       
    67  * Creates CAknInputFrame. 
       
    68  * Gets six parameters:
       
    69  * CCoeControl* aField	  - Control, which will be located inside the input frame.
       
    70  * TBool aOwner           - Defines the ownership of the control.
       
    71  * const TDesC& aFileName - Bitmap file name and path.
       
    72  * TInt aBitmapId         - Bitmap Id
       
    73  * TInt aMaskId           - Bitmap Mask Id
       
    74  * TUint32 aFlags		  - Flags	
       
    75  *
       
    76  * 
       
    77  */
       
    78 EXPORT_C CAknInputFrame* CAknInputFrame::NewL(CCoeControl* aField, TBool aOwner, const TDesC& aFileName, TInt aBitmapId,
       
    79                                               TInt aMaskId, TUint32 aFlags)
       
    80     {
       
    81     CAknInputFrame* bf = new (ELeave) CAknInputFrame;
       
    82     CleanupStack::PushL(bf);
       
    83     bf->ConstructL(aField, aOwner, aFileName, aBitmapId, aMaskId, aFlags);
       
    84     CleanupStack::Pop();
       
    85     return bf;
       
    86     }
       
    87 
       
    88 /**
       
    89  * Creates CAknInputFrame. 
       
    90  * Gets six parameters:
       
    91  * CCoeControl* aField	  - Control, which will be located inside the input frame.
       
    92  * TBool aOwner           - Defines the ownership of the control.
       
    93  * CGulIcon* aIcon        - Bitmap file name and path.
       
    94  * TUint32 aFlags		  - Flags	
       
    95  *
       
    96  * 
       
    97  */
       
    98 EXPORT_C CAknInputFrame* CAknInputFrame::NewL(CCoeControl* aField,TBool aOwner, CGulIcon* aIcon, TUint32 aFlags)
       
    99     {
       
   100     CAknInputFrame* bf = new (ELeave) CAknInputFrame;
       
   101     CleanupStack::PushL(bf);
       
   102     bf->ConstructL(aField,aOwner, aIcon, aFlags);
       
   103     CleanupStack::Pop();
       
   104     return bf;
       
   105     }
       
   106 
       
   107 void CAknInputFrame::ConstructL( CCoeControl* aField,
       
   108                                  TBool aOwner,
       
   109                                  CGulIcon* aIcon,
       
   110                                  TUint32 aFlags )
       
   111     {
       
   112     BaseConstructL(aField, aOwner, aFlags);
       
   113     iIcon=aIcon; // May not leave after this
       
   114     }
       
   115 
       
   116 void CAknInputFrame::ConstructL( CCoeControl* aField,
       
   117                                  TBool aOwner,
       
   118                                  const TDesC& aFileName,
       
   119                                  TInt aBitmapId,
       
   120                                  TInt aMaskId,
       
   121                                  TUint32 aFlags )
       
   122     {
       
   123     BaseConstructL(aField, aOwner, aFlags);
       
   124     iFileName = aFileName.Alloc();
       
   125     iBitmapId = aBitmapId;
       
   126     iMaskId = aMaskId;
       
   127     
       
   128     if(aFileName.Length())
       
   129         {
       
   130         if( aFileName.Compare( KAvkonBitmapFile ) == 0 )
       
   131             {
       
   132             // If the icon comes from Avkon MBM, set skin IID if known
       
   133             switch( aBitmapId )
       
   134                 {
       
   135                 case EMbmAvkonQgn_indi_find_glass:
       
   136                     iIconSkinID = KAknsIIDQgnIndiFindGlass;
       
   137                     break;
       
   138                 case EMbmAvkonQgn_indi_find_glass_pinb:
       
   139                     iIconSkinID = KAknsIIDQgnIndiFindTitle;
       
   140                     break;
       
   141                 case EMbmAvkonQgn_indi_find_goto:
       
   142                     iIconSkinID = KAknsIIDQgnIndiFindGoto;
       
   143                     break;
       
   144                 default:
       
   145                     iIconSkinID = KAknsIIDNone;
       
   146                     break;
       
   147                 }
       
   148             }
       
   149 		CAknInputFrame::CreateIconL();
       
   150         }
       
   151     }
       
   152 
       
   153 void CAknInputFrame::BaseConstructL( CCoeControl* aField, TBool aOwner, TUint32 aFlags )
       
   154     {
       
   155     iFlags = aFlags;
       
   156 
       
   157     if ( aField )
       
   158         {
       
   159         aField->SetContainerWindowL(*this);
       
   160         aField->SetObserver(this);
       
   161         static_cast<CEikBorderedControl*>( aField )->SetBorder( TGulBorder::ENone );
       
   162         }
       
   163 
       
   164     // Construct context for popup find background
       
   165     if( iFlags & EPopupLayout )
       
   166         {
       
   167         iPopupFindCC = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrPopup, Rect(), Rect(), EFalse );
       
   168         }
       
   169     // Construct context for popup list background
       
   170     if  ( iFlags & EPopupWindowLayout )
       
   171         {
       
   172         iPopupListCC = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnFrPopupCenter, Rect(), EFalse );
       
   173         }
       
   174     
       
   175     if ( aOwner )
       
   176         {
       
   177         iFlags|=EOwnsField;
       
   178         }
       
   179     
       
   180     iField = aField; // May not leave after this
       
   181     iIconSkinID = KAknsIIDNone;
       
   182     }
       
   183 
       
   184 EXPORT_C void CAknInputFrame::ConstructFromResourceL(TResourceReader& aReader)
       
   185     {
       
   186     TPtrC filename = aReader.ReadTPtrC();
       
   187     TInt32 pid = aReader.ReadInt16();
       
   188     TInt32 mid = aReader.ReadInt16();
       
   189     TInt32 flags = aReader.ReadInt16();
       
   190     const TInt ctrlType = aReader.ReadInt16();
       
   191     TPtrC infoText = aReader.ReadTPtrC(); // discarded, since infotext is deprecated
       
   192 
       
   193     CCoeControl* field = EikControlFactory::CreateByTypeL(ctrlType).iControl;
       
   194     CleanupStack::PushL(field);
       
   195     field -> ConstructFromResourceL(aReader);
       
   196     ConstructL(field,ETrue,filename,pid,mid,flags);
       
   197     CleanupStack::Pop(); // field
       
   198     if ((ctrlType==EEikCtGlobalTextEditor) || (ctrlType==EEikCtEdwin))
       
   199         {
       
   200         TMargins8 margins;
       
   201         margins.SetAllValuesTo(0);
       
   202         STATIC_CAST(CEikBorderedControl*,iField)->SetBorder(TGulBorder::ENone);                
       
   203         STATIC_CAST(CEikEdwin*,field)->SetBorderViewMargins(margins);
       
   204         }
       
   205     }
       
   206 
       
   207 /**
       
   208 * Return pointer to field 
       
   209 */
       
   210 EXPORT_C CCoeControl* CAknInputFrame::Field() const
       
   211     {
       
   212     return iField;
       
   213     }
       
   214 
       
   215 EXPORT_C void CAknInputFrame::SetInfoTextL(const TDesC& /*aText*/)
       
   216     {
       
   217     RDebug::Printf("%s: Warning: deprecated method CAknInputFrame::SetInfoTextL() called", __FILE__ );
       
   218     }
       
   219 
       
   220 /**
       
   221 * Sets additional icon to input frame 
       
   222 * Gets one parameter:
       
   223 * CGulIcon* aIcon          - Icon.
       
   224 */
       
   225 void CAknInputFrame::SetIcon( CGulIcon* aIcon )
       
   226     {
       
   227     delete iIcon;
       
   228     iIcon = aIcon;
       
   229     iIconSkinID = KAknsIIDNone;
       
   230     }
       
   231 
       
   232 TUint CAknInputFrame::Flags() const
       
   233     {
       
   234     return iFlags;
       
   235     }
       
   236 
       
   237 void CAknInputFrame::SetFlags( TUint aNewFlags )
       
   238     {
       
   239     iFlags = aNewFlags;
       
   240     }
       
   241 
       
   242 EXPORT_C void CAknInputFrame::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType)
       
   243     {
       
   244     if (aEventType == EEventRequestFocus)
       
   245         {
       
   246         FocusChanged(EDrawNow);
       
   247         }
       
   248     }
       
   249 
       
   250 void CAknInputFrame::PrepareForFocusLossL()
       
   251     {
       
   252     iField->PrepareForFocusLossL();
       
   253     }
       
   254 
       
   255 EXPORT_C TKeyResponse CAknInputFrame::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   256     {
       
   257     if ( iField )
       
   258         {
       
   259         return iField->OfferKeyEventL( aKeyEvent, aType );
       
   260         }
       
   261     return EKeyWasNotConsumed;
       
   262     }
       
   263 
       
   264 void CAknInputFrame::SizeChanged()
       
   265     {
       
   266     // There are 5 different layouts to be handled by this component:
       
   267     // --------------------------------------------------------------
       
   268     // Standard          ( fixed find pane in column lists )
       
   269     // PopupLayout       ( popup find pane in any mainpane list )
       
   270     // PinbLayout        ( used by pinboard app )
       
   271     // ClockAppLayout    ( has been removed from laf - fall back to standard )
       
   272     // PopupWindowLayout ( used by list query and popuplist )
       
   273     _AKNTRACE_FUNC_ENTER;
       
   274     TRect parent( Rect() );       // parent for components
       
   275     TRect editorParent( Rect() ); // parent for the editor
       
   276     TRect rect( Rect() );         // rect of the whole shebang
       
   277     TAknLayoutRect r;            // common temporary layout rect
       
   278 
       
   279     TBool apac( AknLayoutUtils::Variant() == EApacVariant && ( iFlags & EShowIndicators ) );
       
   280     
       
   281     TAknWindowComponentLayout outline = AknLayoutScalable_Avkon::input_find_pane();
       
   282     TAknWindowLineLayout iconPos = AknLayoutScalable_Avkon::find_popup_pane_g1().LayoutLine();
       
   283     TAknTextComponentLayout   editor = AknLayoutScalable_Avkon::input_popup_find_pane_t1( apac ? 2 : 0 );
       
   284 
       
   285 
       
   286     if ( iFlags & EPopupLayout ) // popup find box 
       
   287         {
       
   288         _AKNTRACE( "[%s][%s] PopupLayout", 
       
   289         		"CAknInputFrame", __FUNCTION__ );
       
   290         r.LayoutRect( parent, AknLayoutScalable_Avkon::find_popup_pane() );
       
   291         parent = r.Rect();
       
   292         r.LayoutRect( r.Rect(), AknLayoutScalable_Avkon::input_popup_find_pane_cp() );
       
   293         editorParent = r.Rect();
       
   294         outline  = AknLayoutScalable_Avkon::input_popup_find_pane_cp();
       
   295         iconPos  = AknLayoutScalable_Avkon::find_popup_pane_g1().LayoutLine();
       
   296         editor = AknLayoutScalable_Avkon::input_popup_find_pane_t1( apac ? 2 : 0 );
       
   297         if ( iPopupFindCC )
       
   298             {
       
   299             r.LayoutRect( rect, AknLayoutScalable_Avkon::find_popup_pane() );
       
   300             iPopupFindCC->SetFrameRects( rect, r.Rect() );
       
   301             }
       
   302         }
       
   303     else if ( iFlags & EPinbLayout ) // used by pinboard app
       
   304         {
       
   305         _AKNTRACE( "[%s][%s] PinbLayout", 
       
   306                 "CAknInputFrame", __FUNCTION__ );
       
   307         outline = AknLayoutScalable_Apps::input_focus_pane_cp01(0);
       
   308         iconPos = AknLayoutScalable_Apps::find_pinb_pane_g1(0);
       
   309         editor = AknLayoutScalable_Apps::find_pinb_pane_t2( apac ? 1 : 0 );
       
   310         }
       
   311 
       
   312     else if ( iFlags & EPopupWindowLayout )     // list query or popup list
       
   313         {
       
   314         _AKNTRACE( "[%s][%s] PopupWindowLayout", 
       
   315                  "CAknInputFrame", __FUNCTION__ );
       
   316         outline = AknLayoutScalable_Avkon::input_popup_find_pane_cp();
       
   317         iconPos = AknLayoutScalable_Avkon::find_popup_pane_g1();
       
   318         
       
   319         TAknTextComponentLayout textComponentLayout(
       
   320             TAknWindowComponentLayout::ComposeText( outline, 
       
   321                 AknLayoutScalable_Avkon::input_popup_find_pane_t1( apac ? 2 : 0 ) ) );
       
   322                 
       
   323         editor = textComponentLayout;
       
   324         
       
   325         if ( iPopupListCC )
       
   326             {
       
   327             iPopupListCC->SetRect( rect );
       
   328             }
       
   329         }
       
   330     else // standard find pane
       
   331         {
       
   332         _AKNTRACE( "[%s][%s] Standard Layout", 
       
   333                  "CAknInputFrame", __FUNCTION__ );
       
   334         outline = AknLayoutScalable_Avkon::input_find_pane();
       
   335         iconPos = AknLayoutScalable_Avkon::find_pane_g1();
       
   336         editor = AknLayoutScalable_Avkon::input_find_pane_t2( apac ? 1: 0 );
       
   337         r.LayoutRect( rect, AknLayoutScalable_Avkon::input_find_pane() );
       
   338         editorParent = r.Rect();
       
   339         }
       
   340 
       
   341 
       
   342 
       
   343     // --- set size and position of the frame around editor ---
       
   344     r.LayoutRect( parent, outline );
       
   345     iOutlineRect = r.Rect();
       
   346     _AKNTRACE( "[%s][%s] iOutlineRect: %s:%d,%d %s:%d,%d", 
       
   347             "CAknInputFrame", __FUNCTION__, 
       
   348             "LT", iOutlineRect.iTl.iX, iOutlineRect.iTl.iY, 
       
   349             "BR", iOutlineRect.iBr.iX, iOutlineRect.iBr.iY );
       
   350 
       
   351     if ( !iInputContext )
       
   352         {
       
   353         // we need to provide own context if one does not exist
       
   354         // because old style drawing did kind of work even
       
   355         // without calling SetInputContext( ... )
       
   356         iInputContext = CAknsFrameBackgroundControlContext::NewL(
       
   357             KAknsIIDQsnFrInput, TRect(0,0,0,0), TRect(0,0,0,0), EFalse );
       
   358         iFlags = iFlags | EOwnsInputContext;
       
   359         // also need to provide skin for the editor in this case
       
   360         static_cast<CEikEdwin*>( iField )->SetSkinBackgroundControlContextL( iInputContext );
       
   361         }
       
   362 
       
   363     if ( iInputContext )
       
   364         {
       
   365         // this layout is actually from form!
       
   366         // there exists no layout for find box :-/ but this should do
       
   367         // no help from adaptation layer either
       
   368         r.LayoutRect( iOutlineRect, AknLayoutScalable_Avkon::input_focus_pane_g1() );
       
   369         iInputContext->SetFrameRects( iOutlineRect, r.Rect() );
       
   370 
       
   371         // and chain transparent contexts properly
       
   372         MAknsControlContext* bg = iPopupFindCC ? iPopupFindCC : iPopupListCC;
       
   373         if( !bg )
       
   374             {
       
   375             bg = AknsDrawUtils::ControlContext( this );
       
   376             }
       
   377         iInputContext->SetParentContext( bg );
       
   378         }
       
   379 
       
   380     // --- set magnifying glass icon size & position ---
       
   381     iMagnIconPos.LayoutRect( parent, iconPos);
       
   382     CFbsBitmap* iconBitmap = iIcon->Bitmap();
       
   383     if ( iconBitmap  )
       
   384         {
       
   385         AknIconUtils::SetSize( iconBitmap, iMagnIconPos.Rect().Size() );
       
   386         }
       
   387     // --- layout the editor ---
       
   388     AknLayoutUtils::LayoutEdwin( static_cast<CEikEdwin*>( iField ),
       
   389                                  editorParent,
       
   390                                  editor.LayoutLine(),
       
   391                                  EAknsCIQsnTextColorsCG25,
       
   392                                  0,
       
   393                                  ETrue );    
       
   394                                  
       
   395     AknsUtils::RegisterControlPosition( iField );  // prevent flicker
       
   396     _AKNTRACE_FUNC_EXIT;
       
   397     }
       
   398 
       
   399 EXPORT_C TSize CAknInputFrame::MinimumSize()
       
   400     {        
       
   401     return TSize(0,0);
       
   402     }
       
   403  
       
   404 void CAknInputFrame::FocusChanged( TDrawNow aDrawNow )
       
   405     {
       
   406     iField->SetFocus( IsFocused(), aDrawNow );
       
   407     }
       
   408 
       
   409 void CAknInputFrame::Draw( const TRect& /*aRect*/ ) const
       
   410     {
       
   411     CWindowGc& gc = SystemGc();
       
   412     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   413     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   414     TRect rect( Rect() );
       
   415     
       
   416     if ( iFlags & EPopupLayout ) // popup find box
       
   417         {
       
   418         // draw background behind the frame
       
   419         AknsDrawUtils::Background( skin, cc, this, gc, rect );
       
   420         // draw background & frames of popup find window
       
   421         AknsDrawUtils::Background( skin, iPopupFindCC, gc, rect );
       
   422         }
       
   423     else if ( iFlags & EPopupWindowLayout ) // popuplist / list query
       
   424         {    
       
   425         // If softkeys are embedded to popup, background is drawn in popup
       
   426         if ( !( iFlags & EPopupWindowEmbeddedSoftkeys ) )
       
   427             {
       
   428             AknsDrawUtils::Background( skin, iPopupListCC, gc, rect );
       
   429             }
       
   430         }
       
   431     else  // standard fixed find pane or pinboard
       
   432         {
       
   433         // 'this' is required for parent absolute layouts 
       
   434         AknsDrawUtils::Background( skin, cc, this, gc, rect );
       
   435         }
       
   436 
       
   437 
       
   438     // draw the frame (and bg) around editor. currently same for all layouts
       
   439     // We have to use BackGround() because
       
   440     // - frame is transparent
       
   441     // - frame has parent context if popup layout is used
       
   442     // - frame also acts as background for the editor
       
   443     // 'this' is required for parent absolute layouts 
       
   444     AknsDrawUtils::BackgroundBetweenRects( skin, iInputContext, this, gc, iOutlineRect, iField->Rect() );
       
   445     
       
   446     // draw the icon
       
   447     CFbsBitmap* iconBitmap = iIcon->Bitmap();
       
   448     CFbsBitmap* iconMask = iIcon->Mask();
       
   449     iMagnIconPos.DrawImage( gc, iconBitmap, iconMask );
       
   450     }
       
   451 
       
   452 
       
   453 EXPORT_C void CAknInputFrame::SetLineState(TBool aLineVisible)
       
   454     {
       
   455     if (!aLineVisible)
       
   456         {
       
   457         iFlags |= EFixedFindWithoutLine;
       
   458         }
       
   459     else
       
   460         {
       
   461         iFlags &= ~EFixedFindWithoutLine;
       
   462         }
       
   463     }
       
   464 
       
   465 EXPORT_C void CAknInputFrame::SetInputContext(CAknsFrameBackgroundControlContext* aContext)
       
   466     {
       
   467     if ( iInputContext && iFlags & EOwnsInputContext )
       
   468         {
       
   469         delete iInputContext;
       
   470         iInputContext = NULL;
       
   471         iFlags = iFlags &~ EOwnsInputContext;
       
   472         }
       
   473     iInputContext = aContext;
       
   474     }
       
   475 
       
   476 void CAknInputFrame::CreateIconL()
       
   477 	{
       
   478     CFbsBitmap *icon;
       
   479     CFbsBitmap *mask;
       
   480     
       
   481     TSize iconSize( 0, 0 );
       
   482     
       
   483     if ( iIcon && iIcon->Bitmap() )
       
   484         {
       
   485         iconSize = iIcon->Bitmap()->SizeInPixels();         
       
   486         }
       
   487     
       
   488     AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   489                                 iIconSkinID,
       
   490                                 icon, mask, *iFileName, iBitmapId, iMaskId );
       
   491 
       
   492     delete iIcon;
       
   493     iIcon = NULL;
       
   494     
       
   495     iIcon = CGulIcon::NewL(icon, mask);                                 
       
   496 
       
   497     if ( iconSize != TSize( 0, 0 ) )
       
   498         {
       
   499         AknIconUtils::SetSize( iIcon->Bitmap(), iconSize );
       
   500         }
       
   501 	}
       
   502 	
       
   503 
       
   504 
       
   505 void CAknInputFrame::HandleResourceChange( TInt aType )
       
   506     {
       
   507     CCoeControl::HandleResourceChange( aType );
       
   508     switch ( aType )
       
   509         {
       
   510         case KAknsMessageSkinChange:
       
   511         case KEikDynamicLayoutVariantSwitch:
       
   512             CreateIconL();
       
   513             break;
       
   514             
       
   515         default:
       
   516             break;
       
   517         }
       
   518     }
       
   519 // End of File