messagingappbase/msgeditor/modelsrc/MsgEditorCommon.cpp
changeset 79 2981cb3aa489
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     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:   Contains collection of commonly used 'utility' functions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <aknenv.h>
       
    23 #include <AknUtils.h>
       
    24 #include <aknlayout.cdl.h>
       
    25 #include <applayout.cdl.h>
       
    26 #include <aknlayoutscalable_apps.cdl.h>
       
    27 #include <AknStatuspaneUtils.h>     // for AknStatuspaneUtils
       
    28 
       
    29 #include "MsgEditorCommon.h"
       
    30 #include "MsgEditorModelPanic.h"        // Panics
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // MsgEditorCommons::MaxBodyHeight
       
    36 //
       
    37 // Gets the value for maximum body height for variants.
       
    38 // Replaces const TInt KMsgMaxBodyHeight definition in msgeditorcommon.h
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 EXPORT_C TInt MsgEditorCommons::MaxBodyHeight()
       
    42     {
       
    43     return ( EditorViewHeigth() / MsgBaseLineDelta() ) * MsgBaseLineDelta();
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // MsgEditorCommons::MsgBaseLineDelta
       
    48 //
       
    49 // Gets the value for maximum base line for variants.
       
    50 // Replaces const TInt KMsgBaseLineDelta definition in msgeditorcommon.h
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 EXPORT_C TInt MsgEditorCommons::MsgBaseLineDelta()
       
    54     {
       
    55     TInt baseLine = 0;
       
    56 
       
    57     TAknLayoutRect msgTextPane;
       
    58     msgTextPane.LayoutRect(
       
    59         MsgEditorCommons::MsgDataPane(),
       
    60         AknLayoutScalable_Apps::msg_text_pane( 0 ).LayoutLine() );
       
    61     baseLine = msgTextPane.Rect().Height();
       
    62 
       
    63     // We cannot handle non-positive baseLine values. Panic
       
    64     // intentionally if such baseLine is present! This indicates
       
    65     // serious problems with the layout data.
       
    66     __ASSERT_ALWAYS( baseLine > 0, Panic( EMsgLayoutUndetermined ) );
       
    67     return baseLine;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // MsgEditorCommons::MsgBaseLineOffset
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 EXPORT_C TInt MsgEditorCommons::MsgBaseLineOffset()
       
    75     {
       
    76     TInt baseLineOffset = 0;
       
    77     TInt baseLine = MsgEditorCommons::MsgBaseLineDelta();
       
    78     baseLineOffset = MsgEditorCommons::MsgMainPane().Height() % baseLine;
       
    79         
       
    80     return baseLineOffset;
       
    81     }
       
    82 
       
    83 
       
    84 EXPORT_C TInt MsgEditorCommons::ScreenWidth()
       
    85     {
       
    86     TRect screen;
       
    87     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
    88     return screen.Width();
       
    89     }
       
    90 
       
    91 EXPORT_C TInt MsgEditorCommons::ScreenHeigth()
       
    92     {
       
    93     TRect screen;
       
    94     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
    95     return screen.Height();
       
    96     }
       
    97 
       
    98 EXPORT_C TInt MsgEditorCommons::EditorViewWidth()
       
    99     {
       
   100     return MsgEditorCommons::MsgMainPane().Width();
       
   101     }
       
   102 
       
   103 EXPORT_C TInt MsgEditorCommons::EditorViewHeigth()
       
   104     {
       
   105     return MsgEditorCommons::MsgMainPane().Height();
       
   106     }
       
   107 
       
   108 EXPORT_C TRect MsgEditorCommons::MsgMainPane()
       
   109     {
       
   110     TRect mainPaneRect;
       
   111     
       
   112     CEikonEnv* eikEnv = CEikonEnv::Static();    
       
   113     if ( eikEnv && eikEnv->EikAppUi() )
       
   114         {
       
   115         mainPaneRect = eikEnv->EikAppUi()->ClientRect();    
       
   116         }
       
   117     else
       
   118         {
       
   119         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   120         }
       
   121 
       
   122     TAknLayoutRect msgMainLayout;
       
   123     msgMainLayout.LayoutRect( mainPaneRect,
       
   124                               AknLayoutScalable_Apps::main_msg_pane().LayoutLine() );
       
   125 
       
   126     return msgMainLayout.Rect();
       
   127     }
       
   128 
       
   129 EXPORT_C TRect MsgEditorCommons::MsgDataPane()
       
   130     {
       
   131     TRect msgMainPane = MsgEditorCommons::MsgMainPane();
       
   132     
       
   133 #ifdef RD_SCALABLE_UI_V2
       
   134     msgMainPane.Move( -msgMainPane.iTl );
       
   135 #endif // RD_SCALABLE_UI_V2
       
   136 
       
   137     TAknLayoutRect msgDataLayout;
       
   138     msgDataLayout.LayoutRect(
       
   139         msgMainPane,
       
   140         AknLayoutScalable_Apps::msg_data_pane().LayoutLine() );
       
   141         
       
   142     return msgDataLayout.Rect();
       
   143     }
       
   144 
       
   145 EXPORT_C TRect MsgEditorCommons::MsgHeaderPane()
       
   146     {
       
   147     return MsgEditorCommons::MsgDataPane();
       
   148     }
       
   149 
       
   150 EXPORT_C TRect MsgEditorCommons::MsgBodyPane()
       
   151     {
       
   152     return MsgEditorCommons::MsgDataPane();
       
   153     }
       
   154 
       
   155 EXPORT_C void MsgEditorCommons::RoundToNextLine( TInt& aValue, TInt aLineHeight )
       
   156     {
       
   157     TInt remainder( aValue % aLineHeight );
       
   158     if ( remainder != 0 )
       
   159         {
       
   160         aValue < 0 ? aValue -= aLineHeight + remainder :
       
   161                      aValue += aLineHeight - remainder;
       
   162         }
       
   163     }
       
   164 
       
   165 EXPORT_C void MsgEditorCommons::RoundToPreviousLine( TInt& aValue, TInt aLineHeight )
       
   166     {
       
   167     TInt remainder( aValue % aLineHeight );
       
   168     if ( remainder != 0 )
       
   169         {
       
   170         aValue -= remainder;
       
   171         }
       
   172     }
       
   173 
       
   174 //  End of File