messagingappbase/msgeditor/modelsrc/MsgEditorCommon.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   112     
       
   113     TAknLayoutRect msgMainLayout;
       
   114     msgMainLayout.LayoutRect( mainPaneRect,
       
   115                               AknLayoutScalable_Apps::main_msg_pane().LayoutLine() );
       
   116 
       
   117     return msgMainLayout.Rect();
       
   118     }
       
   119 
       
   120 EXPORT_C TRect MsgEditorCommons::MsgDataPane()
       
   121     {
       
   122     TRect msgMainPane = MsgEditorCommons::MsgMainPane();
       
   123     
       
   124 #ifdef RD_SCALABLE_UI_V2
       
   125     msgMainPane.Move( -msgMainPane.iTl );
       
   126 #endif // RD_SCALABLE_UI_V2
       
   127 
       
   128     TAknLayoutRect msgDataLayout;
       
   129     msgDataLayout.LayoutRect(
       
   130         msgMainPane,
       
   131         AknLayoutScalable_Apps::msg_data_pane().LayoutLine() );
       
   132         
       
   133     return msgDataLayout.Rect();
       
   134     }
       
   135 
       
   136 EXPORT_C TRect MsgEditorCommons::MsgHeaderPane()
       
   137     {
       
   138     return MsgEditorCommons::MsgDataPane();
       
   139     }
       
   140 
       
   141 EXPORT_C TRect MsgEditorCommons::MsgBodyPane()
       
   142     {
       
   143     return MsgEditorCommons::MsgDataPane();
       
   144     }
       
   145 
       
   146 EXPORT_C void MsgEditorCommons::RoundToNextLine( TInt& aValue, TInt aLineHeight )
       
   147     {
       
   148     TInt remainder( aValue % aLineHeight );
       
   149     if ( remainder != 0 )
       
   150         {
       
   151         aValue < 0 ? aValue -= aLineHeight + remainder :
       
   152                      aValue += aLineHeight - remainder;
       
   153         }
       
   154     }
       
   155 
       
   156 EXPORT_C void MsgEditorCommons::RoundToPreviousLine( TInt& aValue, TInt aLineHeight )
       
   157     {
       
   158     TInt remainder( aValue % aLineHeight );
       
   159     if ( remainder != 0 )
       
   160         {
       
   161         aValue -= remainder;
       
   162         }
       
   163     }
       
   164 
       
   165 //  End of File