notepad/notepad1/LibSrc/NpdViewerLaf.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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:  Implementation of Decoration graphics of Editor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AknUtils.h>
       
    21 #include <AknIconArray.h>
       
    22 #include <gulicon.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <AknIconUtils.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 #include <AknsFrameBackgroundControlContext.h>
       
    27 #include <applayout.cdl.h>
       
    28 #include <skinlayout.cdl.h>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <aknlayoutscalable_apps.cdl.h>
       
    31 #include <aknappui.h>
       
    32 #include <NpdLib.rsg>
       
    33 #include <npdlib.mbg>
       
    34 #include <eikdialg.h>
       
    35 #include <aknlayout.cdl.h>
       
    36 #include "NpdLib.hrh"
       
    37 #include "NpdViewerLaf.h"
       
    38 #include "NpdEditorDialog.h"
       
    39 #include "NpdEdwin.h"
       
    40 
       
    41 
       
    42 _LIT(KNpdMbmDrive, "Z:");
       
    43 _LIT(KNpdLibMbmFile, "npdlib.mbm");
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CNotepadViewerLaf::CNotepadViewerLaf
       
    49 // public Constructor
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CNotepadViewerLaf::CNotepadViewerLaf(CEikDialog* aParent)
       
    53     : CCoeControl(), iParent(aParent)
       
    54     {
       
    55     // Note: These two lines are for enabling Window Server Autoflush. This
       
    56     // 		 allows you to execute drawing code step-by-step and see the 
       
    57     //		 the changes as they happen. 
       
    58     //
       
    59     //		 To enable autoflush, uncomment the code lines below, and press
       
    60     //		 CTRL+SHIFT+ALT+F in the emulator. 
       
    61   	//RWsSession &ws = iEikonEnv->WsSession();
       
    62   	//ws.SetAutoFlush( ETrue );
       
    63 
       
    64 	iSkinUsed = ETrue;
       
    65 	iBgContext = NULL;
       
    66     iStartPage = ETrue;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CNotepadViewerLaf::~CNotepadViewerLaf
       
    71 // Destructor
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CNotepadViewerLaf::~CNotepadViewerLaf()
       
    75     {
       
    76     delete iTopPageIcon;
       
    77     delete iTopPageMask;
       
    78     delete iMidPageIcon;
       
    79     delete iMidPageMask;
       
    80 	delete iBgContext;
       
    81 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
    82 		{
       
    83 		delete iTopLeftCornerIcon;
       
    84 		delete iTopRightCornerIcon;
       
    85 		delete iTopLeftCornerMask;
       
    86 		delete iTopRightCornerMask;
       
    87 		}
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CNotepadViewerLaf::SetImage
       
    92 // public new function
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CNotepadViewerLaf::SetImage( TBool aOnTopOfPage )
       
    96     {
       
    97     if ( aOnTopOfPage != iStartPage )
       
    98         {
       
    99         iStartPage = aOnTopOfPage;
       
   100         DrawNow();
       
   101         }
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CNotepadViewerLaf::AddRectsAndLayout
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CNotepadViewerLaf::AddRectsAndLayout(const TRect& aRect, RRegion& aRegion)
       
   109     {
       
   110     if(iSkinUsed)
       
   111     	{
       
   112 	  	TAknLayoutRect upperEdgeSkinTl;
       
   113   		TAknLayoutRect upperEdgeSkinTr;
       
   114  
       
   115  		upperEdgeSkinTl.LayoutRect( aRect, SkinLayout::Notepad_skin_element_placing_Line_2() );  // <CDL LAYOUT>
       
   116   		upperEdgeSkinTr.LayoutRect( aRect, SkinLayout::Notepad_skin_element_placing_Line_3() );  // <CDL LAYOUT>
       
   117    
       
   118   		TRect pageTopRect( aRect.iTl/*upperEdgeSkinTl.Rect().iTl*/, upperEdgeSkinTr.Rect().iBr );
       
   119     	aRegion.AddRect(pageTopRect);
       
   120     	}
       
   121     else
       
   122     	{
       
   123 //   	    aRegion.AddRect(aRect, AppLayout::Note_writing_layout_elements_Line_4());		
       
   124     	}
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CNotepadViewerLaf::ConstructFromResourceL
       
   129 // public from CCoeControl
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CNotepadViewerLaf::ConstructFromResourceL(TResourceReader& /*aReader*/)
       
   133     {
       
   134 	TInt ignor;
       
   135      TRAP(ignor,
       
   136         iBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrNotepad, TRect(0,0,0,0), TRect(0,0,0,0), EFalse );
       
   137         );
       
   138 
       
   139 	if (iBgContext)
       
   140 		{
       
   141 	    TFileName mbmfile(KNpdMbmDrive);
       
   142 	    
       
   143     	//mbmfile.Append(KDC_RESOURCE_FILES_DIR);
       
   144     	
       
   145     	mbmfile.Append(KDC_APP_BITMAP_DIR);
       
   146     	mbmfile.Append(KNpdLibMbmFile);
       
   147     	
       
   148 		MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   149 		AknsUtils::CreateIconL(skin,KAknsIIDQsnFrNotepadSideT,iTopPageIcon,iTopPageMask,mbmfile,EMbmNpdlibQsn_fr_notepad_side_t,EMbmNpdlibQsn_fr_notepad_side_t_mask  );
       
   150 		AknsUtils::CreateIconL(skin,KAknsIIDQsnFrNotepadContSideT,iMidPageIcon,iMidPageMask,mbmfile,EMbmNpdlibQsn_fr_notepad_cont_side_t ,EMbmNpdlibQsn_fr_notepad_cont_side_t_mask ); 
       
   151 		if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   152 			{
       
   153 			AknsUtils::CreateIconL(skin,KAknsIIDQsnFrNotepadCornerTl,iTopLeftCornerIcon,iTopLeftCornerMask,mbmfile,EMbmNpdlibQsn_fr_notepad_corner_tl ,EMbmNpdlibQsn_fr_notepad_corner_tl_mask ); 
       
   154 			AknsUtils::CreateIconL(skin,KAknsIIDQsnFrNotepadCornerTr,iTopRightCornerIcon,iTopRightCornerMask,mbmfile,EMbmNpdlibQsn_fr_notepad_corner_tr ,EMbmNpdlibQsn_fr_notepad_corner_tr_mask ); 
       
   155 			}
       
   156 		}
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CNotepadViewerLaf::SetContainerWindowL
       
   161 // cf. CEikEdwin::SetContainerWindowL.
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CNotepadViewerLaf::SetContainerWindowL(const CCoeControl& aContainer)
       
   165     {
       
   166     if ( !OwnsWindow() )
       
   167         {
       
   168         CreateWindowL(&aContainer); // include SetMopParent
       
   169         }
       
   170     else
       
   171         {
       
   172         CCoeControl::SetContainerWindowL(aContainer);
       
   173         }
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CNotepadViewerLaf::SizeChanged
       
   178 // protected from CCoeControl
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CNotepadViewerLaf::SizeChanged()
       
   182     {
       
   183     TRect rect( iParent->Rect() );
       
   184 
       
   185     RRegion region;
       
   186     AddRectsAndLayout(rect, region);
       
   187     Window().SetShape(region);
       
   188     region.Close();	
       
   189 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   190 		{
       
   191 		TAknLayoutRect bgLayout;
       
   192 		TAknLayoutRect mainNotesPane;
       
   193 		TRect tempMainPane;
       
   194 		TRect statusPane;
       
   195     	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane);
       
   196 		AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,statusPane);
       
   197 		TRect mainPane(TPoint(0, 0), tempMainPane.Size());
       
   198 		mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine());
       
   199 		bgLayout.LayoutRect(mainNotesPane.Rect(), AknLayoutScalable_Apps::bg_notes_pane().LayoutLine());
       
   200 		iTlCornerLayout.LayoutRect(bgLayout.Rect(), AknLayoutScalable_Apps::bg_notes_pane_g2().LayoutLine());
       
   201 		iTrCornerLayout.LayoutRect(bgLayout.Rect(), AknLayoutScalable_Apps::bg_notes_pane_g3().LayoutLine());
       
   202 		iBitmapLayout.LayoutRect(bgLayout.Rect(), AknLayoutScalable_Apps::notes_bg_pane_g6().LayoutLine());
       
   203 		}
       
   204 	else
       
   205 		{
       
   206 		iBitmapLayout.LayoutRect(rect, AppLayout::Note_writing_layout_elements_Line_4());
       
   207 		}
       
   208     AknIconUtils::SetSize(iTopPageIcon, iBitmapLayout.Rect().Size());
       
   209     AknIconUtils::SetSize(iMidPageIcon, iBitmapLayout.Rect().Size());
       
   210     AknIconUtils::SetSize(iTopPageMask, iBitmapLayout.Rect().Size());
       
   211     AknIconUtils::SetSize(iMidPageMask, iBitmapLayout.Rect().Size());
       
   212 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   213 		{
       
   214 		AknIconUtils::SetSize(iTopLeftCornerIcon, iTlCornerLayout.Rect().Size());
       
   215 		AknIconUtils::SetSize(iTopRightCornerIcon, iTrCornerLayout.Rect().Size());
       
   216 		AknIconUtils::SetSize(iTopLeftCornerMask, iTlCornerLayout.Rect().Size());
       
   217 		AknIconUtils::SetSize(iTopRightCornerMask, iTrCornerLayout.Rect().Size());
       
   218 		}
       
   219 
       
   220    	TAknLayoutRect mainpaneSkinCenter;
       
   221    	mainpaneSkinCenter.LayoutRect( rect, SkinLayout::Notepad_skin_element_placing_Line_1() );  // <CDL LAYOUT>
       
   222     iBgContext->SetFrameRects(rect,mainpaneSkinCenter.Rect());// = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrNotepad, iBackgroundRect, TRect(0,0,0,0), EFalse );
       
   223     SetPosition(rect.iTl);
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CNotepadViewerLaf::Draw
       
   228 // private from CCoeControl
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CNotepadViewerLaf::Draw(const TRect& aRect) const
       
   232     {
       
   233     CWindowGc& gc = SystemGc();
       
   234 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   235     TRect main_pane = iParent->Rect();
       
   236 	TBool skinUsed = ETrue;
       
   237 	gc.Clear(aRect);
       
   238 	if(iBgContext)
       
   239 		{
       
   240     	skinUsed = AknsDrawUtils::Background( skin, iBgContext, gc, iBitmapLayout.Rect());
       
   241 		if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   242 			{
       
   243 			iTlCornerLayout.DrawImage(SystemGc(), iTopLeftCornerIcon, iTopLeftCornerMask);
       
   244 			iTrCornerLayout.DrawImage(SystemGc(), iTopRightCornerIcon, iTopRightCornerMask);
       
   245 			}
       
   246 
       
   247 		if (skinUsed)
       
   248 			{	
       
   249  		    if(!iStartPage)
       
   250     		    {
       
   251 				TAknLayoutRect line2Rect;
       
   252 				TAknLayoutRect line6Rect;
       
   253 				TAknLayoutRect line3Rect;
       
   254 				if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   255 					{
       
   256 					TRect tempMainPane;
       
   257 					TRect statusPane;
       
   258     				AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane);
       
   259 					AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,statusPane);
       
   260 					TRect mainPane(TPoint(0, 0), tempMainPane.Size());
       
   261 					TAknLayoutRect mainNotesPane;
       
   262 					mainNotesPane.LayoutRect(mainPane, 
       
   263 						AknLayoutScalable_Apps::main_notes_pane().LayoutLine());
       
   264 
       
   265 					line2Rect.LayoutRect( mainNotesPane.Rect(), 
       
   266 						SkinLayout::Notepad_skin_element_placing_Line_2() );
       
   267 					line6Rect.LayoutRect( mainNotesPane.Rect(), 
       
   268 						SkinLayout::Notepad_skin_element_placing_Line_6() );
       
   269 					line3Rect.LayoutRect( mainNotesPane.Rect(), 
       
   270 						SkinLayout::Notepad_skin_element_placing_Line_3() );
       
   271 					}
       
   272 				else
       
   273 					{
       
   274 					TRect application = iAvkonAppUi->ApplicationRect();
       
   275 					TAknLayoutRect scrLayout;
       
   276 					scrLayout.LayoutRect(application,AknLayout::screen());
       
   277 					TAknLayoutRect statusPaneLayout;
       
   278 					TAknLayoutRect controlPaneLayout;
       
   279 					statusPaneLayout.LayoutRect( scrLayout.Rect(), AknLayout::status_pane(scrLayout.Rect(), 0) );
       
   280 					controlPaneLayout.LayoutRect( scrLayout.Rect(), AknLayout::control_pane(scrLayout.Rect()) );
       
   281 					TRect clientRect( TPoint(0,0), TSize(scrLayout.Rect().Width() , scrLayout.Rect().Height()-statusPaneLayout.Rect().Height()-controlPaneLayout.Rect().Height() ) );
       
   282 					line2Rect.LayoutRect(clientRect,SkinLayout::Notepad_skin_element_placing_Line_2());
       
   283 					line6Rect.LayoutRect(clientRect,SkinLayout::Notepad_skin_element_placing_Line_6());
       
   284 					line3Rect.LayoutRect(clientRect,SkinLayout::Notepad_skin_element_placing_Line_3());
       
   285 					}
       
   286 				AknsDrawUtils::DrawCachedImage(skin, gc, 
       
   287    					line2Rect.Rect(), KAknsIIDQsnFrNotepadCornerTl );
       
   288    				AknsDrawUtils::DrawCachedImage(skin, gc, 
       
   289    					line6Rect.Rect(), KAknsIIDQsnFrNotepadSideT );
       
   290    				AknsDrawUtils::DrawCachedImage(skin, gc, 
       
   291    					line3Rect.Rect(), KAknsIIDQsnFrNotepadCornerTr );
       
   292         		}
       
   293 			}
       
   294 		}
       
   295 	if(!skinUsed || !iBgContext)
       
   296 		{
       
   297 
       
   298    		AknsDrawUtils::DrawCachedImage(AknsUtils::SkinInstance(), gc, main_pane, KAknsIIDQsnBgAreaMain );
       
   299 
       
   300 	    if(iStartPage)
       
   301     	    {
       
   302         	iBitmapLayout.DrawImage(SystemGc(), iTopPageIcon, iTopPageMask);
       
   303         	}
       
   304     	else
       
   305         	{
       
   306         	iBitmapLayout.DrawImage(SystemGc(), iMidPageIcon, iMidPageMask);
       
   307     	   	}
       
   308 		}
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------
       
   312 // CNotepadEdwin::MopSupplyObject(TTypeUid aId)
       
   313 // Handles a change to the control's resources.
       
   314 // ---------------------------------------------------------
       
   315 //
       
   316 TTypeUid::Ptr CNotepadViewerLaf::MopSupplyObject(TTypeUid aId)
       
   317 	{
       
   318 	if(aId.iUid == MAknsControlContext::ETypeId)
       
   319 		{
       
   320 		return MAknsControlContext::SupplyMopObject(aId, iBgContext);
       
   321 		}
       
   322 	return CCoeControl::MopSupplyObject(aId);
       
   323 	}
       
   324 
       
   325 void CNotepadViewerLaf::HandleResourceChange(TInt aType)
       
   326     {
       
   327 		if(aType == KAknsMessageSkinChange)
       
   328 			{
       
   329 				if(iBgContext)
       
   330 				{
       
   331 					delete iBgContext;
       
   332 					iBgContext = NULL;
       
   333 				}
       
   334 				TInt ignor;
       
   335 				
       
   336 				TRAP(ignor,
       
   337 				 iBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrNotepad, TRect(0,0,0,0), TRect(0,0,0,0), EFalse );
       
   338 				 );
       
   339 
       
   340 				if (iBgContext)
       
   341 				{
       
   342 				    TFileName mbmfile(KNpdMbmDrive);
       
   343 				   	mbmfile.Append(KDC_APP_BITMAP_DIR);
       
   344     				mbmfile.Append(KNpdLibMbmFile);
       
   345     	
       
   346 					MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   347 					TRAP_IGNORE( AknsUtils::CreateIconL(skin,KAknsIIDQsnFrNotepadSideT,iTopPageIcon,iTopPageMask,mbmfile,EMbmNpdlibQsn_fr_notepad_side_t,EMbmNpdlibQsn_fr_notepad_side_t_mask ) );
       
   348 					TRAP_IGNORE( AknsUtils::CreateIconL(skin,KAknsIIDQsnFrNotepadContSideT,iMidPageIcon,iMidPageMask,mbmfile,EMbmNpdlibQsn_fr_notepad_cont_side_t ,EMbmNpdlibQsn_fr_notepad_cont_side_t_mask ) ); 
       
   349 				}
       
   350 				
       
   351 				SizeChanged();
       
   352 				DrawDeferred();
       
   353 			
       
   354 			}
       
   355 		
       
   356     }
       
   357 // End of File