Commits

Oliver-Rainer Wittmann  committed eba2fa3

textalignment01: #i105270# - Enhance Calc's text formatting to support new writing direction dependent text alignments

  • Participants
  • Parent commits 52a74bb

Comments (0)

Files changed (35)

File cui/source/inc/align.hxx

 
 namespace svx {
 
+// --> OD #i105270#
+class HorJustConnection;
+// <--
 // ============================================================================
 
 class AlignmentTabPage : public SfxTabPage
     void                UpdateEnableControls();
 
     DECL_LINK( UpdateEnableHdl, void* );
+    // --> OD #i105270#
+    DECL_LINK( ChangedTextDirectionHdl, void* );
+    // <--
 
 private:
     FixedLine           maFlAlignment;
     TriStateBox         maBtnShrink;
     FixedText           maFtFrameDir;
     FrameDirListBox     maLbFrameDir;
+
+    // --> OD #i105270#
+    HorJustConnection*  mpHorJustItemConnection;
+    // <--
 };
 
 // ============================================================================

File cui/source/tabpages/align.cxx

 // horizontal alignment -------------------------------------------------------
 
 typedef sfx::ValueItemWrapper< SvxHorJustifyItem, SvxCellHorJustify, USHORT > HorJustItemWrapper;
-typedef sfx::ListBoxConnection< HorJustItemWrapper > HorJustConnection;
+// --> OD #i105270#
+typedef sfx::ListBoxConnection< HorJustItemWrapper > HorJustConnectionBase;
+
+class HorJustConnection : public HorJustConnectionBase
+{
+    private:
+        SvxFrameDirection meTextDirection;
+    
+    public:
+        explicit HorJustConnection( USHORT nSlot, 
+                                    ListBox& rListBox,
+                                    const HorJustConnection::MapEntryType* pMap = 0, 
+                                    sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT )
+            : HorJustConnectionBase( nSlot, rListBox, pMap, nFlags )
+            , meTextDirection( FRMDIR_HORI_LEFT_TOP )
+        {}
+
+        ItemValueType GetControlItemValue( const SfxItemSet& rOldSet,
+                                           bool& orbDoesControlItemValueDiffersFromOldValue )
+        {
+            ItemValueType aCtrlItemValue = 
+                        mxCtrlWrp->GetValueFromPos( mxCtrlWrp->GetNotFoundPos() );
+            
+            orbDoesControlItemValueDiffersFromOldValue = false;
+
+            if ( !mxCtrlWrp->IsControlDontKnow() )
+            {
+                // first store the control value in a local variable
+                ControlValueType aCtrlValue( mxCtrlWrp->GetControlValue() );
+                // convert to item value type -> possible to convert i.e. from 'T' to 'const T&'
+                aCtrlItemValue = aCtrlValue;
+                // map provided values SVX_HOR_JUSTIFY_LEFT and SVX_HOR_JUSTIFY_RIGHT
+                // to text direction dependent values SVX_HOR_JUSTIFY_START resp.
+                // SVX_HOR_JUSTIFY_END
+                if ( aCtrlItemValue == SVX_HOR_JUSTIFY_LEFT )
+                {
+                    if ( meTextDirection == FRMDIR_HORI_RIGHT_TOP )
+                    {
+                        aCtrlItemValue = SVX_HOR_JUSTIFY_END;
+                    }
+                    else
+                    {
+                        aCtrlItemValue = SVX_HOR_JUSTIFY_START;
+                    }
+                }
+                else if ( aCtrlItemValue == SVX_HOR_JUSTIFY_RIGHT )
+                {
+                    if ( meTextDirection == FRMDIR_HORI_RIGHT_TOP )
+                    {
+                        aCtrlItemValue = SVX_HOR_JUSTIFY_START;
+                    }
+                    else
+                    {
+                        aCtrlItemValue = SVX_HOR_JUSTIFY_END;
+                    }
+                }
+                
+                const ItemType* pOldItem = maItemWrp.GetUniqueItem( rOldSet );
+                // do not rely on existence of ItemValueType::operator!=
+                if ( !pOldItem || 
+                     !(maItemWrp.GetItemValue( *pOldItem ) == aCtrlItemValue) )
+                {
+                    orbDoesControlItemValueDiffersFromOldValue = true;
+                }  
+            }      
+
+            return aCtrlItemValue;
+        }            
+
+        void UpdateTextDirection( const SvxFrameDirection eTextDirection,
+                                  const SfxItemSet& rCoreAttrs )
+        {
+            bool bDoesControlItemValueDiffersFromOldValue( false );
+            const ItemValueType aFormerCtrlItemValue =
+                GetControlItemValue( rCoreAttrs, 
+                                     bDoesControlItemValueDiffersFromOldValue );
+            
+            const SvxFrameDirection eOldTextDirection( meTextDirection );
+    
+            meTextDirection = FRMDIR_HORI_LEFT_TOP;
+            if ( eTextDirection != FRMDIR_ENVIRONMENT )
+            {
+                meTextDirection = eTextDirection;
+            }
+            else
+            {        
+                if ( rCoreAttrs.GetItemState( SID_ENVIRONMENT_TEXTDIRECTION ) != SFX_ITEM_SET )
+                {
+                    DBG_ASSERT( false, "<HorJustConnection::UpdateTextDirection(..)> - environment text direction not provided!" );
+                }
+                else
+                {        
+                    const SvxFrameDirectionItem& rEnvironmentFrameDirItem =
+                        static_cast<const SvxFrameDirectionItem&>(rCoreAttrs.Get( SID_ENVIRONMENT_TEXTDIRECTION ));
+                    meTextDirection = static_cast<SvxFrameDirection>(rEnvironmentFrameDirItem.GetValue());
+                }            
+            }
+
+            // adjust representation of text direction dependent text alignment 
+            // values in the list box, if the text direction has changed and 
+            // the text alignment has not been changed in the list box.
+            if ( meTextDirection != eOldTextDirection &&
+                 !bDoesControlItemValueDiffersFromOldValue )
+            {
+                if ( aFormerCtrlItemValue == SVX_HOR_JUSTIFY_START )
+                {
+                    if ( meTextDirection == FRMDIR_HORI_RIGHT_TOP )
+                    {
+                        mxCtrlWrp->SetControlValue( SVX_HOR_JUSTIFY_RIGHT );
+                    }
+                    else
+                    {
+                        mxCtrlWrp->SetControlValue( SVX_HOR_JUSTIFY_LEFT );
+                    }
+                }
+                else if ( aFormerCtrlItemValue == SVX_HOR_JUSTIFY_END )
+                {
+                    if ( meTextDirection == FRMDIR_HORI_RIGHT_TOP )
+                    {
+                        mxCtrlWrp->SetControlValue( SVX_HOR_JUSTIFY_LEFT );
+                    }
+                    else
+                    {
+                        mxCtrlWrp->SetControlValue( SVX_HOR_JUSTIFY_RIGHT );
+                    }
+                }
+                mxCtrlWrp->GetControl().GetSelectHdl().Call( this );
+            }            
+        }    
+
+        virtual void Reset( const SfxItemSet& rItemSet )
+        {
+            const ItemType* pItem = maItemWrp.GetUniqueItem( rItemSet );
+            mxCtrlWrp->SetControlDontKnow( pItem == 0 );
+            if ( pItem )
+            {        
+                // map text direction dependent values SVX_HOR_JUSTIFY_START
+                // and SVX_HOR_JUSTIFY_END to SVX_HOR_JUSTIFY_LEFT resp. 
+                // SVX_HOR_JUSTIFY_RIGHT for the list box.
+                ItemValueType aItemValue = maItemWrp.GetItemValue( *pItem );
+                if ( aItemValue == SVX_HOR_JUSTIFY_START )
+                {
+                    if ( meTextDirection == FRMDIR_HORI_RIGHT_TOP )
+                    {
+                        aItemValue = SVX_HOR_JUSTIFY_RIGHT;
+                    }
+                    else
+                    {
+                        aItemValue = SVX_HOR_JUSTIFY_LEFT;
+                    }
+                }
+                else if ( aItemValue == SVX_HOR_JUSTIFY_END )
+                {
+                    if ( meTextDirection == FRMDIR_HORI_RIGHT_TOP )
+                    {
+                        aItemValue = SVX_HOR_JUSTIFY_LEFT;
+                    }
+                    else
+                    {
+                        aItemValue = SVX_HOR_JUSTIFY_RIGHT;
+                    }
+                }
+
+                mxCtrlWrp->SetControlValue( aItemValue );
+            }
+        }    
+    
+        virtual bool FillItemSet( SfxItemSet& rDestSet, 
+                                  const SfxItemSet& rOldSet )
+        {
+            bool bChanged = false;
+            ItemValueType aNewValue = GetControlItemValue( rOldSet, bChanged );
+            if ( bChanged )
+            {
+                USHORT nWhich = sfx::ItemWrapperHelper::GetWhichId( rDestSet, maItemWrp.GetSlotId() );
+                std::auto_ptr< ItemType > xItem(
+                    static_cast< ItemType* >( maItemWrp.GetDefaultItem( rDestSet ).Clone() ) );
+                xItem->SetWhich( nWhich );
+                maItemWrp.SetItemValue( *xItem, aNewValue );
+                rDestSet.Put( *xItem );
+            }
+            else
+            {        
+                sfx::ItemWrapperHelper::RemoveDefaultItem( rDestSet, rOldSet, maItemWrp.GetSlotId() );
+            }
+
+            return bChanged;
+        }    
+};            
+// <--
 
 static const HorJustConnection::MapEntryType s_pHorJustMap[] =
 {
     maBtnShrink     ( this, CUI_RES( BTN_SHRINK ) ),
     maFtFrameDir    ( this, CUI_RES( FT_TEXTFLOW ) ),
     maLbFrameDir    ( this, CUI_RES( LB_FRAMEDIR ) )
+
+    // --> OD #i105270#
+    , mpHorJustItemConnection( 0 )
+    // <--
 {
     InitVsRefEgde();
 
     maOrientHlp.AddDependentWindow( maCbAsianMode,  STATE_NOCHECK );
 
     Link aLink = LINK( this, AlignmentTabPage, UpdateEnableHdl );
-
     maLbHorAlign.SetSelectHdl( aLink );
     maBtnWrap.SetClickHdl( aLink );
 
         maFtFrameDir.Hide();
         maLbFrameDir.Hide();
     }
+    // --> OD #i105270#
+    else
+    {
+        Link aLink = LINK( this, AlignmentTabPage, ChangedTextDirectionHdl );
+        maLbFrameDir.SetSelectHdl( aLink );
+    }
+    // <--
 
 	// diese Page braucht ExchangeSupport
 	SetExchangeSupport();
 	FreeResource();
 
     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maFtHorAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
-    AddItemConnection( new HorJustConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maLbHorAlign, s_pHorJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
+    // --> OD #i105270#
+    // keep <HorHustConnection> instance in order to update the text direction.
+    // note: ownership is given up by calling <AddItemConnection>
+    mpHorJustItemConnection = new HorJustConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maLbHorAlign, s_pHorJustMap, sfx::ITEMCONN_HIDE_UNKNOWN );
+    AddItemConnection( mpHorJustItemConnection );
+    // <--
     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_INDENT, maFtIndent, sfx::ITEMCONN_HIDE_UNKNOWN ) );
     AddItemConnection( new sfx::UInt16MetricConnection( SID_ATTR_ALIGN_INDENT, maEdIndent, FUNIT_TWIP, sfx::ITEMCONN_HIDE_UNKNOWN ) );
     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maFtVerAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
 {
     SfxTabPage::Reset( rCoreAttrs );
     UpdateEnableControls();
+    // --> OD #i105270#
+    {
+        SvxFrameDirection eTextDirection = FRMDIR_ENVIRONMENT;
+        const USHORT _nFrmDirWhich = GetWhich( SID_ATTR_FRAMEDIRECTION );
+        if ( SFX_ITEM_AVAILABLE <= rCoreAttrs.GetItemState( _nFrmDirWhich ) )
+        {
+            const SvxFrameDirectionItem& rFrameDirItem = 
+                    static_cast<const SvxFrameDirectionItem&>(rCoreAttrs.Get( _nFrmDirWhich ));
+            eTextDirection = static_cast<SvxFrameDirection>(rFrameDirItem.GetValue());
+        }
+        mpHorJustItemConnection->UpdateTextDirection( eTextDirection,
+                                                      rCoreAttrs );
+    }
+    // <--
 }
 
 int AlignmentTabPage::DeactivatePage( SfxItemSet* _pSet )
     return 0;
 }
 
+// --> OD #i105270#
+IMPL_LINK( AlignmentTabPage, ChangedTextDirectionHdl, void*, EMPTYARG )
+{
+    const SvxFrameDirection eDir = maLbFrameDir.GetSelectEntryValue();
+    mpHorJustItemConnection->UpdateTextDirection( eDir, GetItemSet() );
+    return 0;
+}
+// <--
 // ============================================================================
 
 } // namespace svx

File sc/inc/document.hxx

 #include "formula/grammar.hxx"
 #include <com/sun/star/chart2/XChartDocument.hpp>
 #include "scdllapi.h"
+// --> OD #i105270#
+#include <editeng/frmdir.hxx>
+// <--
 
 #include <memory>
 #include <map>
 	void			SetAsianKerning(BOOL bNew);
 
 	BYTE			GetEditTextDirection(SCTAB nTab) const;	// EEHorizontalTextDirection values
+    // --> OD #i105270#
+    const SvxFrameDirection GetTextDirection( const SfxItemSet& rAttrSet,
+                                              const SCTAB nTab ) const;
+    // EEHorizontalTextDirection values are returned
+    const BYTE GetHorizontalEditTextDirection( const SfxItemSet& rAttrSet,
+                                                const SCTAB nTab ) const;
+
+    const SvxFrameDirection GetDocumentDefaultTextDirection() const;
+    // EEHorizontalTextDirection values are returned
+    const BYTE GetDocumentDefaultHorizontalEditTextDirection() const;
+    // <--
 
 	SC_DLLPUBLIC ScLkUpdMode		GetLinkMode() const				{ return eLinkMode ;}
 	void			SetLinkMode( ScLkUpdMode nSet )	{ 	eLinkMode  = nSet;}

File sc/inc/patattr.hxx

 #include <unotools/fontcvt.hxx>
 #include <editeng/svxenum.hxx>
 #include "scdllapi.h"
+// --> OD #i105270#
+#include <address.hxx>
+// <--
 
 class Font;
 class OutputDevice;
 
 	long					GetRotateVal( const SfxItemSet* pCondSet ) const;
 	BYTE					GetRotateDir( const SfxItemSet* pCondSet ) const;
+
+    // --> OD #i105270#
+    // determination of the indentation value.
+    // if text is aligned at left edge
+    //  indentation == value of attribute ATTR_INDENT
+    // otherwise
+    //  indentation == 0
+    // parameters <rDoc> and <nTab> needed in order to determine the text
+    // direction in case that the text alignment attribute value is depending
+    // on the text direction.
+    // parameter <pCondSet> needed in order to provide indentation from the 
+    // conditional attribute set, if returned indentation value shall be 
+    // value of attribute ATTR_INDENT.
+    const USHORT            GetIndentation( const ScDocument& rDoc,
+                                            const SCTAB nTab,
+                                            const SfxItemSet* pCondSet = 0 ) const;
+    // <--
 };
 
 

File sc/source/core/data/attarray.cxx

             //  called only if the sheet is LTR, so physical=logical alignment can be assumed
             SvxCellHorJustify eHorJust = (SvxCellHorJustify)
                     ((const SvxHorJustifyItem&) pPattern->GetItem( ATTR_HOR_JUSTIFY )).GetValue();
-            if ( eHorJust == SVX_HOR_JUSTIFY_RIGHT || eHorJust == SVX_HOR_JUSTIFY_CENTER )
+            // --> OD #i105270#
+            // - SVX_HOR_JUSTIFY_RIGHT still considered for legacy reasons
+            // - Consider SVX_HOR_JUSTIFY_END which on LTR means alignment at the right edge
+            if ( eHorJust == SVX_HOR_JUSTIFY_RIGHT || 
+                 eHorJust == SVX_HOR_JUSTIFY_CENTER ||
+                 eHorJust == SVX_HOR_JUSTIFY_END )
+            // <--
+            {
                 bFound = true;
+            }
         }
     }
 
 	{
 		const ScPatternAttr* pOldPattern = pData[nIndex].pPattern;
 		const SfxItemSet& rOldSet = pOldPattern->GetItemSet();
-		const SfxPoolItem* pItem;
-
-		BOOL bNeedJust = ( rOldSet.GetItemState( ATTR_HOR_JUSTIFY, FALSE, &pItem ) != SFX_ITEM_SET
-						|| ((const SvxHorJustifyItem*)pItem)->GetValue() != SVX_HOR_JUSTIFY_LEFT );
-		USHORT nOldValue = ((const SfxUInt16Item&)rOldSet.Get( ATTR_INDENT )).GetValue();
+        // --> OD #i105270#
+        bool bNeedToSetHorJust = false;
+        SvxCellHorJustify eNewHorJust = SVX_HOR_JUSTIFY_START; // only of relevance, if <bNeedToSetHorJust> set.
+        {
+            const SfxPoolItem* pItem;
+            const SfxItemState eHorJustItemState = rOldSet.GetItemState( ATTR_HOR_JUSTIFY, FALSE, &pItem );
+            if ( eHorJustItemState != SFX_ITEM_SET )
+            {
+                bNeedToSetHorJust = true;
+                eNewHorJust = ( pDocument->GetTextDirection( rOldSet, nTab ) == FRMDIR_HORI_RIGHT_TOP )
+                              ? SVX_HOR_JUSTIFY_END
+                              : SVX_HOR_JUSTIFY_START;
+            }
+            else
+            {
+                const SvxCellHorJustify eHorJust = (SvxCellHorJustify)
+                        static_cast<const SvxHorJustifyItem*>(pItem)->GetValue();
+                if ( pDocument->GetTextDirection( rOldSet, nTab ) == FRMDIR_HORI_RIGHT_TOP )
+                {
+                    if ( eHorJust != SVX_HOR_JUSTIFY_END )
+                    {
+                        bNeedToSetHorJust = true;
+                        eNewHorJust = SVX_HOR_JUSTIFY_END;
+                    }
+                }
+                else
+                {
+                    if ( eHorJust != SVX_HOR_JUSTIFY_START )
+                    {
+                        bNeedToSetHorJust = true;
+                        eNewHorJust = SVX_HOR_JUSTIFY_START;
+                    }
+                }
+            }
+        }    
+        // <--
+        const USHORT nOldValue = ((const SfxUInt16Item&)rOldSet.Get( ATTR_INDENT )).GetValue();
 		USHORT nNewValue = nOldValue;
 		if ( bIncrement )
 		{
 			}
 		}
 
-		if ( bNeedJust || nNewValue != nOldValue )
+        if ( bNeedToSetHorJust || nNewValue != nOldValue )
 		{
 			SCROW nThisEnd = pData[nIndex].nRow;
 			SCROW nAttrRow = Min( nThisEnd, nEndRow );
 			ScPatternAttr aNewPattern(*pOldPattern);
 			aNewPattern.GetItemSet().Put( SfxUInt16Item( ATTR_INDENT, nNewValue ) );
-			if ( bNeedJust )
+            // --> OD #i105270#
+            if ( bNeedToSetHorJust )
+            {        
 				aNewPattern.GetItemSet().Put(
-								SvxHorJustifyItem( SVX_HOR_JUSTIFY_LEFT, ATTR_HOR_JUSTIFY ) );
+                                SvxHorJustifyItem( eNewHorJust, ATTR_HOR_JUSTIFY ) );
+            }
+            // <--
 			SetPatternArea( nThisStart, nAttrRow, &aNewPattern, TRUE );
 
 			nThisStart = nThisEnd + 1;

File sc/source/core/data/column2.cxx

 			pMargin = (const SvxMarginItem*) pCondItem;
 		else
 			pMargin = (const SvxMarginItem*) &pPattern->GetItem(ATTR_MARGIN);
-		USHORT nIndent = 0;
-		if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
-		{
-			if (pCondSet &&
-					pCondSet->GetItemState(ATTR_INDENT, TRUE, &pCondItem) == SFX_ITEM_SET)
-				nIndent = ((const SfxUInt16Item*)pCondItem)->GetValue();
-			else
-				nIndent = ((const SfxUInt16Item&)pPattern->GetItem(ATTR_INDENT)).GetValue();
-		}
+        
+        // --> OD #i105270#
+        const USHORT nIndent = pPattern->GetIndentation( *pDocument, nTab, pCondSet );
+        // <--
 
 		BYTE nScript = pDocument->GetScriptType( nCol, nRow, nTab, pCell );
 		if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();

File sc/source/core/data/documen8.cxx

     return sal::static_int_cast<BYTE>(eRet);
 }
 
+// --> OD #i105270#
+const SvxFrameDirection ScDocument::GetTextDirection( const SfxItemSet& rAttrSet,
+                                                      const SCTAB nTab ) const
+{
+    SvxFrameDirection eTextDir = FRMDIR_ENVIRONMENT;
+
+    if ( !(rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SFX_ITEM_DONTCARE) )
+    {
+        eTextDir = (SvxFrameDirection)((const SvxFrameDirectionItem&)rAttrSet.Get( ATTR_WRITINGDIR )).GetValue();
+    }
+
+    if ( eTextDir == FRMDIR_ENVIRONMENT )
+    {        
+        const EEHorizontalTextDirection eHoriTextDir = 
+                    (EEHorizontalTextDirection)GetEditTextDirection( nTab );
+        switch ( eHoriTextDir )
+        {
+            case EE_HTEXTDIR_L2R:
+            {
+                eTextDir = FRMDIR_HORI_LEFT_TOP;
+            }
+            break;
+            case EE_HTEXTDIR_R2L:
+            {
+                eTextDir = FRMDIR_HORI_RIGHT_TOP;
+            }
+            break;
+            default:
+            {
+                DBG_ASSERT( false,
+                            "<ScDocument::GetTextDirection()> - unexpected value of edit text direction for given table sheet!" );
+            }    
+        }
+    }
+
+    return eTextDir;
+}
+
+const BYTE ScDocument::GetHorizontalEditTextDirection( const SfxItemSet& rAttrSet,
+                                                       const SCTAB nTab ) const
+{
+    EEHorizontalTextDirection eRet = EE_HTEXTDIR_DEFAULT;
+
+    if ( !(rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SFX_ITEM_DONTCARE) )
+    {
+        SvxFrameDirection eTextDir = 
+            (SvxFrameDirection)((const SvxFrameDirectionItem&)rAttrSet.Get( ATTR_WRITINGDIR )).GetValue();
+        if ( eTextDir == FRMDIR_ENVIRONMENT )
+        {        
+            eRet = (EEHorizontalTextDirection)GetEditTextDirection( nTab );
+        }
+        else if ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+        {        
+            eRet = EE_HTEXTDIR_R2L;
+        }
+        else
+        {        
+            eRet = EE_HTEXTDIR_L2R;
+        }
+    }
+    else
+    {        
+        eRet = (EEHorizontalTextDirection)GetEditTextDirection( nTab );
+    }
+
+    return sal::static_int_cast<BYTE>(eRet);
+}    
+
+const SvxFrameDirection ScDocument::GetDocumentDefaultTextDirection() const
+{
+    SvxFrameDirection eDocumentDefaultTextDir = FRMDIR_HORI_LEFT_TOP;
+
+    // text direction of the default page style is taken as the document's 
+    // default text direction.
+    SfxStyleSheetBase* pStyle = 
+        xPoolHelper->GetStylePool()->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), 
+                                           SFX_STYLE_FAMILY_PAGE );
+    if ( !pStyle )
+    {
+        DBG_ASSERT( false, 
+                    "<ScDocument::GetDocumentDefaultTextDirection()> - missing default page style!" );
+        return eDocumentDefaultTextDir;
+    }
+
+    const SfxItemSet& rStyleSet = pStyle->GetItemSet();
+    eDocumentDefaultTextDir = (SvxFrameDirection)
+        ((const SvxFrameDirectionItem&)rStyleSet.Get( ATTR_WRITINGDIR )).GetValue();
+
+    DBG_ASSERT( eDocumentDefaultTextDir == FRMDIR_HORI_LEFT_TOP ||
+                eDocumentDefaultTextDir == FRMDIR_HORI_RIGHT_TOP, 
+                "<ScDocument::GetDocumentDefaultTextDirection()> - unexpected value of the default page style's text direction!" );
+
+    return eDocumentDefaultTextDir;
+}            
+
+const BYTE ScDocument::GetDocumentDefaultHorizontalEditTextDirection() const
+{
+    EEHorizontalTextDirection eRet = EE_HTEXTDIR_L2R;
+
+    const SvxFrameDirection eDocumentDefaultTextDir = GetDocumentDefaultTextDirection();
+    if ( eDocumentDefaultTextDir == FRMDIR_HORI_LEFT_TOP )
+    {        
+        eRet = EE_HTEXTDIR_L2R;
+    }
+    else if ( eDocumentDefaultTextDir == FRMDIR_HORI_RIGHT_TOP )
+    {        
+        eRet = EE_HTEXTDIR_R2L;
+    }
+    else
+    {
+        DBG_ASSERT( false, 
+                    "<ScDocument::GetDocumentDefaultHorizontalEditTextDirection()> - unexpected value of the document default page style's text direction." );
+    }            
+
+    return sal::static_int_cast<BYTE>(eRet);
+}    
+// <--
+
 //------------------------------------------------------------------------
 
 void ScDocument::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo,

File sc/source/core/data/dpoutput.cxx

 		if ( nStrId==STR_PIVOT_STYLE_RESULT || nStrId==STR_PIVOT_STYLE_TITLE )
             rSet.Put( SvxWeightItem( WEIGHT_BOLD, ATTR_FONT_WEIGHT ) );
 		if ( nStrId==STR_PIVOT_STYLE_CATEGORY || nStrId==STR_PIVOT_STYLE_TITLE )
-            rSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_LEFT, ATTR_HOR_JUSTIFY ) );
+            rSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_START, ATTR_HOR_JUSTIFY ) );
 	}
 
 	pDoc->ApplyStyleAreaTab( nCol1, nRow1, nCol2, nRow2, nTab, *pStyle );

File sc/source/core/data/patattr.cxx

 
     if (rEditSet.GetItemState(EE_PARA_JUST,TRUE,&pItem) == SFX_ITEM_SET)
 	{
-		SvxCellHorJustify eVal;
+        SvxCellHorJustify eVal = SVX_HOR_JUSTIFY_STANDARD;
 		switch ( ((const SvxAdjustItem*)pItem)->GetAdjust() )
 		{
-			case SVX_ADJUST_LEFT:
-				// #30154# EditEngine Default ist bei dem GetAttribs() ItemSet
-				// immer gesetzt!
-				// ob links oder rechts entscheiden wir selbst bei Text/Zahl
-				eVal = SVX_HOR_JUSTIFY_STANDARD;
-				break;
-			case SVX_ADJUST_RIGHT:
-				eVal = SVX_HOR_JUSTIFY_RIGHT;
-				break;
 			case SVX_ADJUST_BLOCK:
 				eVal = SVX_HOR_JUSTIFY_BLOCK;
 				break;
 			case SVX_ADJUST_BLOCKLINE:
 				eVal = SVX_HOR_JUSTIFY_BLOCK;
 				break;
+            // --> OD #i105270#
+            case SVX_ADJUST_START:
+                // treat as EditEngine's default 
+                // Thus, SVX_HOR_JUSTIFY_STANDARD instead of SVX_HOR_JUSTIFY_START
+                eVal = SVX_HOR_JUSTIFY_STANDARD;
+                break;
+            case SVX_ADJUST_END:
+                eVal = SVX_HOR_JUSTIFY_END;
+                break;
+            // <--
+            // #i105270-TODO# - LEFT and RIGHT may not occur, if other TODO is solved
+            case SVX_ADJUST_LEFT: // legacy
+                // #30154# EditEngine Default ist bei dem GetAttribs() ItemSet
+                // immer gesetzt!
+                // ob links oder rechts entscheiden wir selbst bei Text/Zahl
+                eVal = SVX_HOR_JUSTIFY_STANDARD;
+                break;
+            case SVX_ADJUST_RIGHT: // legacy
+                eVal = SVX_HOR_JUSTIFY_RIGHT;
+                break;
             case SVX_ADJUST_INVALID_ENUM_END:
-				eVal = SVX_HOR_JUSTIFY_RIGHT;
-				break;
-			default:
 				eVal = SVX_HOR_JUSTIFY_STANDARD;
 		}
 		if ( eVal != SVX_HOR_JUSTIFY_STANDARD )
 	SvxCellHorJustify eHorJust = (SvxCellHorJustify)
 		((const SvxHorJustifyItem&)rMySet.Get(ATTR_HOR_JUSTIFY)).GetValue();
 
-	SvxAdjust eSvxAdjust;
+    SvxAdjust eSvxAdjust = SVX_ADJUST_START;
 	switch (eHorJust)
 	{
-		case SVX_HOR_JUSTIFY_RIGHT:	 eSvxAdjust = SVX_ADJUST_RIGHT;	 break;
+        // --> OD #i105270#
+        case SVX_HOR_JUSTIFY_STANDARD: 
+        case SVX_HOR_JUSTIFY_REPEAT:
+        case SVX_HOR_JUSTIFY_START:  eSvxAdjust = SVX_ADJUST_START;  break;
+        case SVX_HOR_JUSTIFY_END:    eSvxAdjust = SVX_ADJUST_END;  break;
+        // #i105270-TODO# - map to START depending on text direction?
+        case SVX_HOR_JUSTIFY_LEFT:   eSvxAdjust = SVX_ADJUST_LEFT;  break; // legacy
+        // #i105270-TODO# - map to START depending on text direction?
+        case SVX_HOR_JUSTIFY_RIGHT:  eSvxAdjust = SVX_ADJUST_RIGHT;  break; // legacy
+        // <--
 		case SVX_HOR_JUSTIFY_CENTER: eSvxAdjust = SVX_ADJUST_CENTER; break;
 		case SVX_HOR_JUSTIFY_BLOCK:	 eSvxAdjust = SVX_ADJUST_BLOCK;	 break;
-		default:					 eSvxAdjust = SVX_ADJUST_LEFT;	 break;
 	}
 	pEditSet->Put( SvxAdjustItem( eSvxAdjust, EE_PARA_JUST ) );
 }
 	return nRet;
 }
 
+// --> OD #i105270#
+const USHORT ScPatternAttr::GetIndentation( const ScDocument& rDoc,
+                                            const SCTAB nTab,
+                                            const SfxItemSet* pCondSet ) const
+{
+    USHORT nIndentation = 0;
 
+    bool bProvideAttrIndentValue = false;
+    {
+        const SvxCellHorJustify eHorJust = (SvxCellHorJustify)
+            static_cast<const SvxHorJustifyItem&>(GetItem( ATTR_HOR_JUSTIFY )).GetValue();
+        if ( eHorJust == SVX_HOR_JUSTIFY_START && 
+             rDoc.GetTextDirection( GetItemSet(), nTab ) != FRMDIR_HORI_RIGHT_TOP )
+        {
+            bProvideAttrIndentValue = true;
+        }
+        else if ( eHorJust == SVX_HOR_JUSTIFY_END && 
+                  rDoc.GetTextDirection( GetItemSet(), nTab ) == FRMDIR_HORI_RIGHT_TOP )
+        {
+            bProvideAttrIndentValue = true;
+        }
+        else if ( eHorJust == SVX_HOR_JUSTIFY_LEFT ) // legacy
+        {
+            bProvideAttrIndentValue = true;
+        }
+    }
 
+    if ( bProvideAttrIndentValue )
+    {
+        const SfxPoolItem* pCondIndentItem = 0;
+        if ( pCondSet &&
+             pCondSet->GetItemState(ATTR_INDENT, TRUE, &pCondIndentItem) == SFX_ITEM_SET )
+        {
+            nIndentation = static_cast<const SfxUInt16Item*>(pCondIndentItem)->GetValue();
+        }
+        else
+        {        
+            nIndentation = static_cast<const SfxUInt16Item&>(GetItem(ATTR_INDENT)).GetValue();
+        }
+    }
+    
+    return nIndentation;    
+}
+// <--
 

File sc/source/core/data/table1.cxx

         else
         {
             // STANDARD is LEFT (only text is handled here)
-            bool bRight = ( eHorJust == SVX_HOR_JUSTIFY_RIGHT );
+            // --> OD #i105270#
+            bool bRight = ( eHorJust == SVX_HOR_JUSTIFY_START &&
+                            pDocument->GetTextDirection( ( pCondSet 
+                                                           ? *pCondSet
+                                                           : pPattern->GetItemSet() ),
+                                                         nTab )
+                                == FRMDIR_HORI_RIGHT_TOP ) ||
+                          ( eHorJust == SVX_HOR_JUSTIFY_END &&
+                            pDocument->GetTextDirection( ( pCondSet 
+                                                           ? *pCondSet
+                                                           : pPattern->GetItemSet() ),
+                                                          nTab )
+                                != FRMDIR_HORI_RIGHT_TOP ) ||
+                          ( eHorJust == SVX_HOR_JUSTIFY_RIGHT );
+            // <--
             if ( IsLayoutRTL() )
                 bRight = !bRight;
             if ( bRight )

File sc/source/core/tool/editutil.cxx

 	}
 
 	const SvxMarginItem* pMargin = (const SvxMarginItem*)&pPattern->GetItem(ATTR_MARGIN);
-	USHORT nIndent = 0;
-	if ( ((const SvxHorJustifyItem&)pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue() ==
-				SVX_HOR_JUSTIFY_LEFT )
-		nIndent = ((const SfxUInt16Item&)pPattern->GetItem(ATTR_INDENT)).GetValue();
+    // --> OD #i105270#
+    const USHORT nIndent = pPattern->GetIndentation( *pDoc, nTab );
+    // <--
 	long nPixDifX	= (long) ( ( pMargin->GetLeftMargin() + nIndent ) * nPPTX );
 	aStartPos.X()	+= nPixDifX * nLayoutSign;
 	nCellX			-= nPixDifX + (long) ( pMargin->GetRightMargin() * nPPTX );		// wegen Umbruch etc.

File sc/source/core/tool/interpr1.cxx

                         pDok->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY );
                     switch( pJustAttr->GetValue() )
                     {
+                        // --> OD #i105270#
+                        case SVX_HOR_JUSTIFY_START:
+                        {
+                            const ScPatternAttr* pPattern = 
+                                pDok->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() );
+                            const SvxFrameDirection eTextDir =
+                                pDok->GetTextDirection( pPattern->GetItemSet(), 
+                                                        aCellPos.Tab() );
+                            if ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+                            {
+                                aFuncResult = '"';
+                            }
+                            else
+                            {
+                                aFuncResult = '\'';
+                            }            
+                        }
+                        break;        
+                        case SVX_HOR_JUSTIFY_END:
+                        {
+                            const ScPatternAttr* pPattern = 
+                                pDok->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() );
+                            const SvxFrameDirection eTextDir =
+                                pDok->GetTextDirection( pPattern->GetItemSet(), 
+                                                        aCellPos.Tab() );
+                            if ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+                            {
+                                aFuncResult = '\'';
+                            }
+                            else
+                            {
+                                aFuncResult = '"';
+                            }            
+                        }
+                        break;        
+                        // <--
                         case SVX_HOR_JUSTIFY_STANDARD:
                         case SVX_HOR_JUSTIFY_LEFT:
                         case SVX_HOR_JUSTIFY_BLOCK:     aFuncResult = '\''; break;

File sc/source/ui/Accessibility/AccessibleText.cxx

 
         // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
         long nIndent = 0;
-        const SvxHorJustifyItem* pHorJustifyItem = static_cast< const SvxHorJustifyItem* >(
-            pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY ) );
-        SvxCellHorJustify eHorJust = ( pHorJustifyItem ? static_cast< SvxCellHorJustify >( pHorJustifyItem->GetValue() ) : SVX_HOR_JUSTIFY_STANDARD );
-        if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
-        {
-            const SfxUInt16Item* pIndentItem = static_cast< const SfxUInt16Item* >(
-                pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_INDENT ) );
-            if ( pIndentItem )
+        // --> OD #i105270#
+//        const SvxHorJustifyItem* pHorJustifyItem = static_cast< const SvxHorJustifyItem* >(
+//            pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY ) );
+//        const SvxCellHorJustify eHorJust = 
+//                ( pHorJustifyItem 
+//                  ? static_cast< SvxCellHorJustify >( pHorJustifyItem->GetValue() ) 
+//                  : SVX_HOR_JUSTIFY_STANDARD );
+//        if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
+//        {
+//            const SfxUInt16Item* pIndentItem = static_cast< const SfxUInt16Item* >(
+//                pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_INDENT ) );
+//            if ( pIndentItem )
+//            {
+//                nIndent = static_cast< long >( pIndentItem->GetValue() );
+//            }
+//        }
+        SvxCellHorJustify eHorJust = SVX_HOR_JUSTIFY_STANDARD;
+        SvxFrameDirection eTextDir = FRMDIR_HORI_LEFT_TOP;
+        { 
+            const ScPatternAttr* pPatternAttr = pDoc->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() );
+            if ( pPatternAttr )
             {
-                nIndent = static_cast< long >( pIndentItem->GetValue() );
+                eHorJust = static_cast<SvxCellHorJustify>(
+                                static_cast<const SvxHorJustifyItem&>(
+                                    pPatternAttr->GetItem( ATTR_HOR_JUSTIFY )).GetValue());
+        
+                eTextDir = pDoc->GetTextDirection( pPatternAttr->GetItemSet(), aCellPos.Tab() );
+                                                
+                nIndent = pPatternAttr->GetIndentation( *pDoc, aCellPos.Tab() ); 
             }
         }
+        // <--
 
         const SvxMarginItem* pMarginItem = static_cast< const SvxMarginItem* >(
             pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_MARGIN ) );
         pEditEngine->SetPaperSize( aSize );
 
         // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
-        if ( eHorJust == SVX_HOR_JUSTIFY_STANDARD && pDoc->HasValueData( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
+        if ( eHorJust == SVX_HOR_JUSTIFY_STANDARD && 
+             pDoc->HasValueData( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
         {
             pEditEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
         }
         long nTextHeight = aTextSize.Height();
 
         long nOffsetX = nLeftM;
-        long nDiffX = nTextWidth - nWidth;
-        if ( nDiffX > 0 )
         {
-            switch ( eHorJust )
+            long nDiffX = nTextWidth - nWidth;
+            if ( nDiffX > 0 )
             {
-                case SVX_HOR_JUSTIFY_RIGHT:
+                switch ( eHorJust )
+                {
+                    // --> OD #i105270#
+                    case SVX_HOR_JUSTIFY_START:
+                        {
+                            if ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+                            {
+                                nOffsetX -= nDiffX;
+                            }
+                        }
+                        break;
+                    case SVX_HOR_JUSTIFY_END:
+                        {
+                            if ( eTextDir != FRMDIR_HORI_RIGHT_TOP )
+                            {
+                                nOffsetX -= nDiffX;
+                            }
+                        }
+                        break;
+                    // <--
+                    case SVX_HOR_JUSTIFY_RIGHT: // legacy
+                        {
+                            nOffsetX -= nDiffX;
+                        }
+                        break;
+                    case SVX_HOR_JUSTIFY_CENTER:
+                        {
+                            nOffsetX -= nDiffX / 2;
+                        }
+                        break;
+                    default:
+                        {
+                        }
+                        break;
+                }
+            }
+        }
+
+        long nOffsetY = 0;
+        {
+            const SvxVerJustifyItem* pVerJustifyItem = static_cast< const SvxVerJustifyItem* >(
+                pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_VER_JUSTIFY ) );
+            SvxCellVerJustify eVerJust = ( pVerJustifyItem ? static_cast< SvxCellVerJustify >( pVerJustifyItem->GetValue() ) : SVX_VER_JUSTIFY_STANDARD );
+            switch ( eVerJust )
+            {
+                case SVX_VER_JUSTIFY_STANDARD:
+                case SVX_VER_JUSTIFY_BOTTOM:
                     {
-                        nOffsetX -= nDiffX;
+                        nOffsetY = nSizeY - nBottomM - nTextHeight;
                     }
                     break;
-                case SVX_HOR_JUSTIFY_CENTER:
+                case SVX_VER_JUSTIFY_CENTER:
                     {
-                        nOffsetX -= nDiffX / 2;
+                        nOffsetY = ( nSizeY - nTopM - nBottomM - nTextHeight ) / 2 + nTopM;
                     }
                     break;
                 default:
                     {
+                        nOffsetY = nTopM;
                     }
                     break;
             }
         }
 
-        long nOffsetY = 0;
-        const SvxVerJustifyItem* pVerJustifyItem = static_cast< const SvxVerJustifyItem* >(
-            pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_VER_JUSTIFY ) );
-        SvxCellVerJustify eVerJust = ( pVerJustifyItem ? static_cast< SvxCellVerJustify >( pVerJustifyItem->GetValue() ) : SVX_VER_JUSTIFY_STANDARD );
-        switch ( eVerJust )
-        {
-            case SVX_VER_JUSTIFY_STANDARD:
-            case SVX_VER_JUSTIFY_BOTTOM:
-                {
-                    nOffsetY = nSizeY - nBottomM - nTextHeight;
-                }
-                break;
-            case SVX_VER_JUSTIFY_CENTER:
-                {
-                    nOffsetY = ( nSizeY - nTopM - nBottomM - nTextHeight ) / 2 + nTopM;
-                }
-                break;
-            default:
-                {
-                    nOffsetY = nTopM;
-                }
-                break;
-        }
-
         if ( mpAccessibleCell )
         {
             mpAccessibleCell->SetOffset( Point( nOffsetX, nOffsetY ) );

File sc/source/ui/app/inputhdl.cxx

 
 static const sal_Char __FAR_DATA pMinDelimiters[] = " !\"";
 
-extern USHORT nEditAdjust;		//! Member an ViewData
+// --> OD #i105270# - refactoring
+//extern USHORT nEditAdjust;        //! Member an ViewData
+// <--
 
 //==================================================================
 
 
 void ScInputHandler::UpdateAdjust( sal_Unicode cTyped )
 {
-	SvxAdjust eSvxAdjust;
+    SvxAdjust eSvxAdjust = SVX_ADJUST_START;
     switch (eAttrAdjust)
 	{
 		case SVX_HOR_JUSTIFY_STANDARD:
 				eSvxAdjust = bNumber ? SVX_ADJUST_RIGHT : SVX_ADJUST_LEFT;
 			}
 			break;
-		case SVX_HOR_JUSTIFY_BLOCK:
+        // --> OD #i105270#
+        case SVX_HOR_JUSTIFY_REPEAT:
+        case SVX_HOR_JUSTIFY_START:
+            eSvxAdjust = SVX_ADJUST_START;
+            break;
+        case SVX_HOR_JUSTIFY_END:
+            eSvxAdjust = SVX_ADJUST_END;
+            break;
+        // <--
+        case SVX_HOR_JUSTIFY_BLOCK:
 			eSvxAdjust = SVX_ADJUST_BLOCK;
 			break;
 		case SVX_HOR_JUSTIFY_CENTER:
 			eSvxAdjust = SVX_ADJUST_CENTER;
 			break;
-		case SVX_HOR_JUSTIFY_RIGHT:
+        case SVX_HOR_JUSTIFY_RIGHT: // legacy
 			eSvxAdjust = SVX_ADJUST_RIGHT;
 			break;
-		default:	// SVX_HOR_JUSTIFY_LEFT
+        case SVX_HOR_JUSTIFY_LEFT: // legacy
 			eSvxAdjust = SVX_ADJUST_LEFT;
 			break;
 	}
 		((const SfxBoolItem&)pLastPattern->GetItem( ATTR_VERTICAL_ASIAN )).GetValue();
 	if ( bAsianVertical )
 	{
-		//	always edit at top of cell -> LEFT when editing vertically
-		eSvxAdjust = SVX_ADJUST_LEFT;
+        //  always edit at top of cell -> START when editing vertically
+        // --> OD #i105270#
+        eSvxAdjust = SVX_ADJUST_START;
+        // <--
 	}
 
 	pEditDefaults->Put( SvxAdjustItem( eSvxAdjust, EE_PARA_JUST ) );
 	pEngine->SetDefaults( *pEditDefaults );
 
-    nEditAdjust = sal::static_int_cast<USHORT>(eSvxAdjust);     //! set at ViewData or with PostEditView
+    // --> OD #i105270# - refactoring
+//    nEditAdjust = sal::static_int_cast<USHORT>(eSvxAdjust);     //! set at ViewData or with PostEditView
+    if ( pActiveViewSh )
+    {
+        pActiveViewSh->GetViewData()->SetEditAdjust( sal::static_int_cast<USHORT>(eSvxAdjust) );
+    }
+    else
+    {
+        DBG_ASSERT( false, 
+                    "<ScInputHandler::UpdateAdjust(..)> - Can not access <ScViewData> instance to set <EditAdjust>!" );
+    }            
+    // <--
 
 	pEngine->SetVertical( bAsianVertical );
 }
 	{
 		ScViewData* pViewData = pActiveViewSh->GetViewData();
 
-		BOOL bNeedGrow = ( nEditAdjust != SVX_ADJUST_LEFT );		// rechtsbuendig immer
+        // #i105270-TODO# - needed to handle SVX_ADJUST_START and/or SVX_ADJUST_END?
+        // --> OD #i105270# - refactoring
+//        BOOL bNeedGrow = ( nEditAdjust != SVX_ADJUST_LEFT );
+        BOOL bNeedGrow = ( pViewData->GetEditAdjust() != SVX_ADJUST_LEFT );
+        // <--
 		if (!bNeedGrow)
 		{
 				//	Cursor vor dem Ende?

File sc/source/ui/app/transobj.cxx

 					if ( ((const SvxHorJustifyItem*) pDestDoc->GetAttr(
 							nCol,nRow,nDestTab, ATTR_HOR_JUSTIFY))->GetValue() ==
 							SVX_HOR_JUSTIFY_STANDARD )
+                    {
+                        // #i105270-TODO# - apply SVX_HOR_JUSTIFY_END ?
 						pDestDoc->ApplyAttr( nCol,nRow,nDestTab,
 								SvxHorJustifyItem(SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY) );
+                    }
 				}
 				else if (pFCell->IsValue())
 				{

File sc/source/ui/docshell/docsh.cxx

 #include <comphelper/processfactory.hxx>
 #include "uiitems.hxx"
 #include "cellsuno.hxx"
+// --> OD #i105270#
+#include <patattr.hxx>
+// <--
 
 using namespace com::sun::star;
 using ::rtl::OUString;
 }
 
 
-void lcl_ScDocShell_GetFixedWidthString( String& rStr, const ScDocument& rDoc,
-        SCTAB nTab, SCCOL nCol, BOOL bValue, SvxCellHorJustify eHorJust )
+// --> OD #i105270# - added parameter <eTextDir> and its consideration
+void lcl_ScDocShell_GetFixedWidthString( String& rStr, 
+                                         const ScDocument& rDoc,
+                                         const SCTAB nTab, 
+                                         const SCCOL nCol, 
+                                         const BOOL bValue, 
+                                         SvxCellHorJustify eHorJust,
+                                         const SvxFrameDirection eTextDir )
 {
     xub_StrLen nLen = lcl_ScDocShell_GetColWidthInChars(
             rDoc.GetColWidth( nCol, nTab ) );
     if ( nLen > rStr.Len() )
     {
         if ( bValue && eHorJust == SVX_HOR_JUSTIFY_STANDARD )
+        {        
             eHorJust = SVX_HOR_JUSTIFY_RIGHT;
+        }
+        // --> OD #i105270#
+        else if ( eHorJust == SVX_HOR_JUSTIFY_START &&
+                  eTextDir == FRMDIR_HORI_RIGHT_TOP )
+        {
+            eHorJust = SVX_HOR_JUSTIFY_RIGHT;
+        }
+        else if ( eHorJust == SVX_HOR_JUSTIFY_END &&
+                  eTextDir != FRMDIR_HORI_RIGHT_TOP )
+        {
+            eHorJust = SVX_HOR_JUSTIFY_RIGHT;
+        }
+        // <--
         switch ( eHorJust )
         {
             case SVX_HOR_JUSTIFY_RIGHT:
         }
     }
 }
+// <--
 
 
 void lcl_ScDocShell_WriteEmptyFixedWidthString( SvStream& rStream,
         const ScDocument& rDoc, SCTAB nTab, SCCOL nCol )
 {
     String aString;
+    // --> OD #i105270#
     lcl_ScDocShell_GetFixedWidthString( aString, rDoc, nTab, nCol, FALSE,
-            SVX_HOR_JUSTIFY_STANDARD );
+                                        SVX_HOR_JUSTIFY_STANDARD,
+                                        FRMDIR_HORI_LEFT_TOP );
+    // <--
     rStream.WriteUnicodeOrByteText( aString );
 }
 
 
         if ( bFixedWidth )
         {
-            SvxCellHorJustify eHorJust = (SvxCellHorJustify)
-                ((const SvxHorJustifyItem*) aDocument.GetAttr( nCol, nRow,
-                nTab, ATTR_HOR_JUSTIFY ))->GetValue();
+            const SvxCellHorJustify eHorJust = (SvxCellHorJustify)
+                ((const SvxHorJustifyItem*) aDocument.GetAttr( 
+                            nCol, nRow, nTab, ATTR_HOR_JUSTIFY ))->GetValue();
+            // --> OD #i105270#
+            SvxFrameDirection eTextDir = FRMDIR_HORI_LEFT_TOP;
+            {
+                const ScPatternAttr* pPatternAttr = aDocument.GetPattern( nCol, nRow, nTab );
+                if ( pPatternAttr )
+                {
+                    eTextDir = 
+                        aDocument.GetTextDirection( pPatternAttr->GetItemSet(), nTab );
+                }
+            }
             lcl_ScDocShell_GetFixedWidthString( aString, aDocument, nTab, nCol,
-                    !bString, eHorJust );
+                                                !bString, eHorJust, eTextDir );
             rStream.WriteUnicodeOrByteText( aString );
         }
         else

File sc/source/ui/docshell/docsh4.cxx

 		pBindings->Invalidate( FID_RESET_PRINTZOOM );
 		pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
 		pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
-	}
+        // --> OD #i105270#
+        pBindings->Invalidate( SID_ALIGNLEFT );
+        pBindings->Invalidate( SID_ALIGNRIGHT );
+        pBindings->Invalidate( SID_ALIGNBLOCK );
+        pBindings->Invalidate( SID_ALIGNCENTERHOR );
+        // pseudo slots for Format menu
+        pBindings->Invalidate( SID_ALIGN_ANY_HDEFAULT );
+        pBindings->Invalidate( SID_ALIGN_ANY_LEFT );
+        pBindings->Invalidate( SID_ALIGN_ANY_HCENTER );
+        pBindings->Invalidate( SID_ALIGN_ANY_RIGHT );
+        pBindings->Invalidate( SID_ALIGN_ANY_JUSTIFIED );
+        // <--
+    }
 }
 
 void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,

File sc/source/ui/drawfunc/drtxtob.cxx

 
 			case SID_ALIGNLEFT:
             case SID_ALIGN_ANY_LEFT:
-				aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
+                // --> OD #i105270#
+                {    
+                    SvxAdjust eNewAdjust = SVX_ADJUST_START;
+                    OutlinerView* pOLV = pView->IsTextEdit() 
+                                         ? pView->GetTextEditOutlinerView() 
+                                         : 0;
+                    const bool bIsRightToLeft( pOLV && pOLV->IsCursorInRightToLeftText() );
+                    if ( bIsRightToLeft )
+                    {
+                        eNewAdjust = SVX_ADJUST_END;
+                    }
+                    aNewAttr.Put( SvxAdjustItem( eNewAdjust, EE_PARA_JUST ) );
+                }
+                // <--
 				break;
 
 			case SID_ALIGNCENTERHOR:
 
 			case SID_ALIGNRIGHT:
             case SID_ALIGN_ANY_RIGHT:
-				aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
+                // --> OD #i105270#
+                {    
+                    SvxAdjust eNewAdjust = SVX_ADJUST_END;
+                    OutlinerView* pOLV = pView->IsTextEdit() 
+                                         ? pView->GetTextEditOutlinerView() 
+                                         : 0;
+                    const bool bIsRightToLeft( pOLV && pOLV->IsCursorInRightToLeftText() );
+                    if ( bIsRightToLeft )
+                    {
+                        eNewAdjust = SVX_ADJUST_START;
+                    }
+                    aNewAttr.Put( SvxAdjustItem( eNewAdjust, EE_PARA_JUST ) );
+                }
+                // <--
 				break;
 
 			case SID_ALIGNBLOCK:
 
 	//	Ausrichtung
 
+    // --> OD #i105270#
+    OutlinerView* pOLV = pView->IsTextEdit() 
+                         ? pView->GetTextEditOutlinerView() 
+                         : 0;
+    const bool bIsRightToLeft( pOLV && pOLV->IsCursorInRightToLeftText() );
+    // <--
 	SvxAdjust eAdj = ((const SvxAdjustItem&)aAttrSet.Get(EE_PARA_JUST)).GetAdjust();
 	switch( eAdj )
 	{
+        // --> OD #i105270#
+        case SVX_ADJUST_START:
+            {
+                if ( bIsRightToLeft )
+                {
+                    rDestSet.Put( SfxBoolItem( SID_ALIGNRIGHT, TRUE ) );
+                }
+                else
+                {
+                    rDestSet.Put( SfxBoolItem( SID_ALIGNLEFT, TRUE ) );
+                }
+            }
+            break;        
+        case SVX_ADJUST_END:
+            {
+                if ( bIsRightToLeft )
+                {
+                    rDestSet.Put( SfxBoolItem( SID_ALIGNLEFT, TRUE ) );
+                }
+                else
+                {
+                    rDestSet.Put( SfxBoolItem( SID_ALIGNRIGHT, TRUE ) );
+                }
+            }
+            break;        
+        // <--
 		case SVX_ADJUST_LEFT:
 			rDestSet.Put( SfxBoolItem( SID_ALIGNLEFT, TRUE ) );
 			break;
         }
 	}
     // pseudo slots for Format menu
-    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_LEFT,      eAdj == SVX_ADJUST_LEFT ) );
+    // --> OD #i105270#
+    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_LEFT,      
+                               ( ( eAdj == SVX_ADJUST_START && !bIsRightToLeft ) ||
+                                 ( eAdj == SVX_ADJUST_END && bIsRightToLeft ) ||
+                                 eAdj == SVX_ADJUST_LEFT ) ) );
+    // <--
     rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_HCENTER,   eAdj == SVX_ADJUST_CENTER ) );
-    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_RIGHT,     eAdj == SVX_ADJUST_RIGHT ) );
+    // --> OD #i105270#
+    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_RIGHT,     
+                               ( ( eAdj == SVX_ADJUST_END && !bIsRightToLeft ) ||
+                                 ( eAdj == SVX_ADJUST_START && bIsRightToLeft ) ||
+                                 eAdj == SVX_ADJUST_RIGHT ) ) );
+    // <--
     rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_JUSTIFIED, eAdj == SVX_ADJUST_BLOCK ) );
 
 	//	Zeilenabstand

File sc/source/ui/drawfunc/drtxtob2.cxx

                 aAttr.Put( SvxFrameDirectionItem(
                                 bLeft ? FRMDIR_HORI_LEFT_TOP : FRMDIR_HORI_RIGHT_TOP,
                                 EE_PARA_WRITINGDIR ) );
-                aAttr.Put( SvxAdjustItem(
-                                bLeft ? SVX_ADJUST_LEFT : SVX_ADJUST_RIGHT,
-                                EE_PARA_JUST ) );
+                // --> OD #i105270#
+                aAttr.Put( SvxAdjustItem( SVX_ADJUST_START, EE_PARA_JUST ) );
+                // <--
                 pView->SetAttributes( aAttr );
 				pViewData->GetScDrawView()->InvalidateDrawTextAttrs();
 				rReq.Done();		//! Done(aAttr) ?

File sc/source/ui/inc/autofmt.hxx

 #include <svtools/scriptedtext.hxx>
 #include <svx/framelinkarray.hxx>
 #include "scdllapi.h"
-
+// --> OD #i105270#
+#include <editeng/frmdir.hxx>
+// <--
 //------------------------------------------------------------------------
 
 class ScAutoFormat;
     const String            aStrSouth;
     const String            aStrSum;
     SvNumberFormatter*      pNumFmt;
+
+    // --> OD #i105270#
+    SvxFrameDirection meTextDir;
+    // <--
 	//-------------------------------------------
 	SC_DLLPRIVATE void	Init			();
 	SC_DLLPRIVATE void	DoPaint			( const Rectangle& rRect );

File sc/source/ui/inc/output.hxx

 	BOOL	bAnyRotated;		// intern
 	BOOL	bAnyClipped;		// intern
 	BOOL	bTabProtected;
-	BYTE	nTabTextDirection;	// EEHorizontalTextDirection values
 	BOOL	bLayoutRTL;
 
 	// #i74769# use SdrPaintWindow direct, remember it during BeginDrawLayers/EndDrawLayers
 
 	BOOL			IsAvailable( SCCOL nX, SCROW nY );
 
-	void			GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY,
-                                   SCCOL nCellX, SCROW nCellY, long nNeeded,
+    void            GetOutputArea( SCCOL nX, SCSIZE nArrY, 
+                                   long nPosX, long nPosY,
+                                   SCCOL nCellX, SCROW nCellY, 
+                                   long nNeeded,
                                    const ScPatternAttr& rPattern,
-                                   USHORT nHorJustify, bool bCellIsValue,
-                                   bool bBreak, bool bOverwrite,
+                                   const USHORT nHorJustify, 
+                                   bool bCellIsValue,
+                                   bool bBreak, 
+                                   bool bOverwrite,
                                    OutputAreaParam& rParam );
 
     void            ShrinkEditEngine( EditEngine& rEngine, const Rectangle& rAlignRect,

File sc/source/ui/inc/viewdata.hxx

 	SCCOL				nEditStartCol;
 	SCCOL				nEditEndCol;				// Ende der Edit-View
 	SCROW				nEditEndRow;
+    // --> OD #i105270# - refactoring
+    USHORT              nEditAdjust;
+    // <--
 	SCCOL				nTabStartCol;				// fuer Enter nach Tab
 	ScRange				aDelRange;					// fuer AutoFill-Loeschen
 
 	SCCOL			GetEditEndCol() const			{ return nEditEndCol; }
 	SCROW			GetEditEndRow() const			{ return nEditEndRow; }
 
+    // --> OD #i105270# - refactoring
+    void            SetEditAdjust( const USHORT nNewEditAdjust )
+    {
+        nEditAdjust = nNewEditAdjust;
+    }            
+    const USHORT    GetEditAdjust() const
+    {
+        return nEditAdjust;
+    }            
+    // <--
 	Rectangle		GetEditArea( ScSplitPos eWhich, SCCOL nPosX, SCROW nPosY, Window* pWin,
 									const ScPatternAttr* pPattern, BOOL bForceToTop );
 

File sc/source/ui/miscdlgs/autofmt.cxx

 #include "document.hxx"
 #include "docsh.hxx"
 #include "tabvwsh.hxx"
+// --> OD #i105270#
+#include <patattr.hxx>
+// <--
 
 #define FRAME_OFFSET 4
 
         aStrMid         ( ScResId( STR_MID ) ),
         aStrSouth       ( ScResId( STR_SOUTH ) ),
         aStrSum         ( ScResId( STR_SUM ) ),
-		pNumFmt			( new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), ScGlobal::eLnge ) )
+        pNumFmt         ( new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), ScGlobal::eLnge ) ),
+        // --> OD #i105270#
+        meTextDir       ( FRMDIR_HORI_LEFT_TOP )
+        // <--
 {
-	Init();
+    Init();
 }
 
 //------------------------------------------------------------------------
 		if ( cellString.Len() > 0 )
 		{
 			Size				aStrSize;
-            USHORT              nFmtIndex       = GetFormatIndex( nCol, nRow );
+            const USHORT        nFmtIndex       = GetFormatIndex( nCol, nRow );
             Rectangle           cellRect        = maArray.GetCellRect( nCol, nRow );
             Point               aPos            = cellRect.TopLeft();
 			USHORT				nRightX 		= 0;
-			BOOL				bJustify		= pCurData->GetIncludeJustify();
-            SvxHorJustifyItem    aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY );
-			SvxCellHorJustify	   eJustification;
+            const BOOL          bJustify        = pCurData->GetIncludeJustify();
 
 			//-------------
 			// Ausrichtung:
 			//-------------
-            eJustification  = mbRTL ? SVX_HOR_JUSTIFY_RIGHT : bJustify ?
-                (SvxCellHorJustify)(((const SvxHorJustifyItem*)pCurData->GetItem( nFmtIndex, ATTR_HOR_JUSTIFY ))->GetValue()) :
-                SVX_HOR_JUSTIFY_STANDARD;
+            const SvxCellHorJustify eJustification = 
+                mbRTL 
+                ? SVX_HOR_JUSTIFY_RIGHT 
+                : ( bJustify 
+                    ? (SvxCellHorJustify)(((const SvxHorJustifyItem*)pCurData->GetItem( nFmtIndex, ATTR_HOR_JUSTIFY ))->GetValue()) 
+                    : SVX_HOR_JUSTIFY_STANDARD );
 
 			if ( pCurData->GetIncludeFont() )
 			{
 				while ( ( theMaxStrSize.Width() <= aStrSize.Width() )
 					&& ( cellString.Len() > 1 ) )
 				{
-					if( eJustification == SVX_HOR_JUSTIFY_RIGHT )
+                    // --> OD #i105270#
+                    if ( ( eJustification == SVX_HOR_JUSTIFY_START &&
+                           meTextDir == FRMDIR_HORI_RIGHT_TOP ) ||
+                         ( eJustification == SVX_HOR_JUSTIFY_END &&
+                           meTextDir != FRMDIR_HORI_RIGHT_TOP ) ||
+                         ( eJustification == SVX_HOR_JUSTIFY_RIGHT ) )
+                    // <--
+                    {        
 						cellString.Erase( 0, 1 );
+                    }
 					else
+                    {        
 						cellString.Erase( cellString.Len() - 1 );
+                    }
 
                     aScriptedText.SetText( cellString, xBreakIter );
                     aStrSize = aScriptedText.GetTextSize();
 
 				switch ( eJustification )
 				{
+                    // --> OD #i105270#
+                    case SVX_HOR_JUSTIFY_START:
+                        if ( meTextDir == FRMDIR_HORI_RIGHT_TOP )
+                        {
+                            aPos.X() += nRightX;
+                        }
+                        else
+                        {        
+                            aPos.X() += FRAME_OFFSET;
+                        }
+                        break;
+                    case SVX_HOR_JUSTIFY_END:
+                        if ( meTextDir == FRMDIR_HORI_RIGHT_TOP )
+                        {
+                            aPos.X() += FRAME_OFFSET;
+                        }
+                        else
+                        {        
+                            aPos.X() += nRightX;
+                        }
+                        break;
+                    // <--
 					case SVX_HOR_JUSTIFY_LEFT:
 						aPos.X() += FRAME_OFFSET;
 						break;
     SfxViewShell* p = pFrame->GetViewShell();
     ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell* >( p );
     ScViewData* pViewData = pViewSh->GetViewData();
-    SCTAB nCurrentTab = pViewData->GetTabNo();
+    const SCTAB nCurrentTab = pViewData->GetTabNo();
     ScDocument* pDoc = pViewData->GetDocument();
     mbRTL = pDoc->IsLayoutRTL( nCurrentTab );
+
+    // --> OD #i105270#
+    meTextDir = pDoc->GetTextDirection( pViewSh->GetSelectionPattern()->GetItemSet(), nCurrentTab ) ;
+    // <--
 }
 
 //------------------------------------------------------------------------

File sc/source/ui/pagedlg/tphfedit.cxx

 	pSet->Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
 	pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
 	pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
-	if (mbRTL)
-		pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );	
+    // --> OD #i105270#
+    // no longer needed as default text alignment is SVX_ADJUST_START which is
+    // depending on the writing direction.
+//    if (mbRTL)
+//        pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
+    // <--
 	pEdEngine->SetDefaults( pSet );
 }
 

File sc/source/ui/view/formatsh.cxx

 
 namespace {
 
-SvxCellHorJustify lclConvertSlotToHAlign( USHORT nSlot )
+// --> OD #i105270#    
+SvxCellHorJustify lclConvertSlotToHAlign( const USHORT nSlot, 
+                                          const SvxFrameDirection eTextDir )
 {
     SvxCellHorJustify eHJustify = SVX_HOR_JUSTIFY_STANDARD;
     switch( nSlot )
     {
         case SID_ALIGN_ANY_HDEFAULT:    eHJustify = SVX_HOR_JUSTIFY_STANDARD;   break;
-        case SID_ALIGN_ANY_LEFT:        eHJustify = SVX_HOR_JUSTIFY_LEFT;       break;
+        case SID_ALIGN_ANY_LEFT:
+            if ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+            {
+                eHJustify = SVX_HOR_JUSTIFY_END;
+            }
+            else
+            {
+                eHJustify = SVX_HOR_JUSTIFY_START;
+            }            
+            break;
         case SID_ALIGN_ANY_HCENTER:     eHJustify = SVX_HOR_JUSTIFY_CENTER;     break;
-        case SID_ALIGN_ANY_RIGHT:       eHJustify = SVX_HOR_JUSTIFY_RIGHT;      break;
+        case SID_ALIGN_ANY_RIGHT:
+            if ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+            {
+                eHJustify = SVX_HOR_JUSTIFY_START;
+            }
+            else
+            {
+                eHJustify = SVX_HOR_JUSTIFY_END;
+            }            
+            break;
         case SID_ALIGN_ANY_JUSTIFIED:   eHJustify = SVX_HOR_JUSTIFY_BLOCK;      break;
         default:    DBG_ERRORFILE( "lclConvertSlotToHAlign - invalid slot" );
     }
     return eHJustify;
 }
+// <--
 
 SvxCellVerJustify lclConvertSlotToVAlign( USHORT nSlot )
 {
 
 //------------------------------------------------------------------
 
-#define APPLY_HOR_JUSTIFY(j) \
-	{																		\
-		if ( !pHorJustify || (eHorJustify != (j) ) )                        \
-			pTabViewShell->ApplyAttr( SvxHorJustifyItem( (j) ) );                          \
-		else                                                                \
-			pTabViewShell->ApplyAttr( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD ) );     \
-	}
-
-#define APPLY_VER_JUSTIFY(j) \
-	{																		\
-		if ( !pVerJustify || (eVerJustify != (j) ) )                        \
-			pTabViewShell->ApplyAttr( SvxVerJustifyItem( (j) ) );                          \
-		else                                                                \
-			pTabViewShell->ApplyAttr( SvxVerJustifyItem( SVX_VER_JUSTIFY_STANDARD ) );     \
-	}
-
 void ScFormatShell::ExecuteAlignment( SfxRequest& rReq )
 {
 	ScTabViewShell*	pTabViewShell  		= GetViewData()->GetViewShell();
         case SID_ALIGN_ANY_HCENTER:
         case SID_ALIGN_ANY_RIGHT:
         case SID_ALIGN_ANY_JUSTIFIED:
-            pTabViewShell->ApplyAttr( SvxHorJustifyItem( lclConvertSlotToHAlign( nSlot ), ATTR_HOR_JUSTIFY ) );
+        {
+            // --> OD #i105270#
+            const SvxFrameDirection eTextDir =
+                    GetViewData()->GetDocument()->GetTextDirection( 
+                        pTabViewShell->GetSelectionPattern()->GetItemSet(),
+                        GetViewData()->GetTabNo() );
+            pTabViewShell->ApplyAttr( SvxHorJustifyItem( lclConvertSlotToHAlign( nSlot, eTextDir ), ATTR_HOR_JUSTIFY ) );
+            // <--
+        }
         break;
         case SID_ALIGN_ANY_VDEFAULT:
         case SID_ALIGN_ANY_TOP:
 
 		const SfxItemSet&		 rAttrSet	= pTabViewShell->GetSelectionPattern()->GetItemSet();
 		const SfxPoolItem*       pItem       = NULL;
-		const SvxHorJustifyItem* pHorJustify = NULL;
-		const SvxVerJustifyItem* pVerJustify = NULL;
-		SvxCellHorJustify        eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
-		SvxCellVerJustify        eVerJustify = SVX_VER_JUSTIFY_STANDARD;
 
+        const SvxHorJustifyItem* pHorJustify = NULL;
+        SvxCellHorJustify        eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
 		if (rAttrSet.GetItemState(ATTR_HOR_JUSTIFY, TRUE,&pItem ) == SFX_ITEM_SET)
 		{
 			pHorJustify = (const SvxHorJustifyItem*)pItem;
 			eHorJustify = SvxCellHorJustify( pHorJustify->GetValue() );
 		}
+
+        const SvxVerJustifyItem* pVerJustify = NULL;
+        SvxCellVerJustify        eVerJustify = SVX_VER_JUSTIFY_STANDARD;
 		if (rAttrSet.GetItemState(ATTR_VER_JUSTIFY, TRUE,&pItem ) == SFX_ITEM_SET)
 		{
 			pVerJustify = (const SvxVerJustifyItem*)pItem;
 		switch ( nSlot )
 		{
 			case SID_ALIGNLEFT:
+            {    
 				rReq.SetSlot( SID_H_ALIGNCELL );
-				rReq.AppendItem( SvxHorJustifyItem(
-					!pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_LEFT) ?
-					SVX_HOR_JUSTIFY_LEFT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
+                // --> OD #i105270#
+                SvxCellHorJustify eNewHorJustify( SVX_HOR_JUSTIFY_STANDARD );
+                const SvxFrameDirection eTextDir = 
+                    pViewData->GetDocument()->GetTextDirection( rAttrSet, 
+                                                                pViewData->GetTabNo() );
+                if ( !pHorJustify ||
+                     !( ( eHorJustify == SVX_HOR_JUSTIFY_START &&
+                          eTextDir != FRMDIR_HORI_RIGHT_TOP ) ||
+                        ( eHorJustify == SVX_HOR_JUSTIFY_END &&
+                          eTextDir == FRMDIR_HORI_RIGHT_TOP ) ||
+                        ( eHorJustify == SVX_HOR_JUSTIFY_LEFT ) ) )
+                {
+                    eNewHorJustify = ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+                                     ? SVX_HOR_JUSTIFY_END
+                                     : SVX_HOR_JUSTIFY_START;
+                }
+                rReq.AppendItem( SvxHorJustifyItem( eNewHorJustify, SID_H_ALIGNCELL ) );
+                // <--
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_LEFT );
-                //break;
+            }
 
 			case SID_ALIGNRIGHT:
+            {    
 				rReq.SetSlot( SID_H_ALIGNCELL );
-				rReq.AppendItem( SvxHorJustifyItem(
-					!pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_RIGHT) ?
-					SVX_HOR_JUSTIFY_RIGHT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
+                // --> OD #i105270#
+                SvxCellHorJustify eNewHorJustify( SVX_HOR_JUSTIFY_STANDARD );
+                const SvxFrameDirection eTextDir = 
+                    pViewData->GetDocument()->GetTextDirection( rAttrSet, 
+                                                                pViewData->GetTabNo() );
+                if ( !pHorJustify ||
+                     !( ( eHorJustify == SVX_HOR_JUSTIFY_START &&
+                          eTextDir == FRMDIR_HORI_RIGHT_TOP ) ||
+                        ( eHorJustify == SVX_HOR_JUSTIFY_END &&
+                          eTextDir != FRMDIR_HORI_RIGHT_TOP ) ||
+                        ( eHorJustify == SVX_HOR_JUSTIFY_RIGHT ) ) )
+                {
+                    eNewHorJustify = ( eTextDir == FRMDIR_HORI_RIGHT_TOP )
+                                     ? SVX_HOR_JUSTIFY_START
+                                     : SVX_HOR_JUSTIFY_END;
+                }
+                rReq.AppendItem( SvxHorJustifyItem( eNewHorJustify, SID_H_ALIGNCELL ) );
+                // <--
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_RIGHT );
-                //break;
+            }
 
 			case SID_ALIGNCENTERHOR:
 				rReq.SetSlot( SID_H_ALIGNCELL );
 					SVX_HOR_JUSTIFY_CENTER : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_CENTER );
-                //break;
 
 			case SID_ALIGNBLOCK:
 				rReq.SetSlot( SID_H_ALIGNCELL );
 					SVX_HOR_JUSTIFY_BLOCK : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_BLOCK );
-                //break;
 
 			case SID_ALIGNTOP:
 				rReq.SetSlot( SID_V_ALIGNCELL );
 					SVX_VER_JUSTIFY_TOP : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_TOP );
-                //break;
 
 			case SID_ALIGNBOTTOM:
 				rReq.SetSlot( SID_V_ALIGNCELL );
 					SVX_VER_JUSTIFY_BOTTOM : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_BOTTOM );
-                //break;
 
 			case SID_ALIGNCENTERVER:
 				rReq.SetSlot( SID_V_ALIGNCELL );
 					SVX_VER_JUSTIFY_CENTER : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
 				ExecuteSlot( rReq, GetInterface() );
 				return;
-//				APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_CENTER );
-                //break;
 
 			default:
 			break;
 	}
 
 	rBindings.Update();
-//	rReq.Done();
 
 	if( pNewSet )
 	{
 
 }
 
-#undef APPLY_HOR_JUSTIFY
-#undef APPLY_VER_JUSTIFY
 
 //------------------------------------------------------------------
 
 					case SVX_HOR_JUSTIFY_STANDARD:
 						break;
 
+                    // --> OD #i105270#
+                    case SVX_HOR_JUSTIFY_START:
+                        if ( GetViewData()->GetDocument()->GetTextDirection( rAttrSet, GetViewData()->GetTabNo() )
+                                == FRMDIR_HORI_RIGHT_TOP )
+                        {
+                            nWhich = SID_ALIGNRIGHT;
+                        }
+                        else
+                        {        
+                            nWhich = SID_ALIGNLEFT;
+                        }
+                        break;
+                    case SVX_HOR_JUSTIFY_END:
+                        if ( GetViewData()->GetDocument()->GetTextDirection( rAttrSet, GetViewData()->GetTabNo() )
+                                == FRMDIR_HORI_RIGHT_TOP )
+                        {
+                            nWhich = SID_ALIGNLEFT;
+                        }
+                        else
+                        {        
+                            nWhich = SID_ALIGNRIGHT;
+                        }
+                        break;
+                    // <--
 					case SVX_HOR_JUSTIFY_LEFT:
 						nWhich = SID_ALIGNLEFT;
 						break;
 
 void ScFormatShell::GetAlignState( SfxItemSet& rSet )
 {
-	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
-	const SfxItemSet& rAttrSet    = pTabViewShell->GetSelectionPattern()->GetItemSet();
-	SfxWhichIter	aIter(rSet);
-	USHORT			nWhich = aIter.FirstWhich();
+    ScTabViewShell* pTabViewShell   = GetViewData()->GetViewShell();
+    const SfxItemSet& rAttrSet    = pTabViewShell->GetSelectionPattern()->GetItemSet();
+    SfxWhichIter    aIter(rSet);
+    USHORT          nWhich = aIter.FirstWhich();
 
     SvxCellHorJustify eHAlign = SVX_HOR_JUSTIFY_STANDARD;
     bool bHasHAlign = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY ) != SFX_ITEM_DONTCARE;
     if( bHasVAlign )
         eVAlign = (SvxCellVerJustify)((const SvxVerJustifyItem&) rAttrSet.Get( ATTR_VER_JUSTIFY )).GetValue();
 
-	while ( nWhich )
-	{
-		switch ( nWhich )
-		{
-			case SID_H_ALIGNCELL:
+    while ( nWhich )
+    {
+        switch ( nWhich )
+        {
+            case SID_H_ALIGNCELL:
                 if ( bHasHAlign )
                     rSet.Put( SvxHorJustifyItem( eHAlign, nWhich ));
-			break;
-			case SID_V_ALIGNCELL:
+            break;
+            case SID_V_ALIGNCELL:
                 if ( bHasVAlign )
                     rSet.Put( SvxVerJustifyItem( eVAlign, nWhich ));
-			break;
+            break;
 
             // pseudo slots for Format menu
             case SID_ALIGN_ANY_HDEFAULT:
             case SID_ALIGN_ANY_HCENTER:
             case SID_ALIGN_ANY_RIGHT:
             case SID_ALIGN_ANY_JUSTIFIED:
-                rSet.Put( SfxBoolItem( nWhich, bHasHAlign && (eHAlign == lclConvertSlotToHAlign( nWhich )) ) );
+            {
+                // --> OD #i105270#
+                const SvxFrameDirection eTextDir =
+                    GetViewData()->GetDocument()->GetTextDirection( rAttrSet,
+                                                                    GetViewData()->GetTabNo() );
+                rSet.Put( SfxBoolItem( nWhich, bHasHAlign && (eHAlign == lclConvertSlotToHAlign( nWhich, eTextDir )) ) );
+                // <--
+            }
             break;
             case SID_ALIGN_ANY_VDEFAULT:
             case SID_ALIGN_ANY_TOP:
             case SID_ALIGN_ANY_BOTTOM:
                 rSet.Put( SfxBoolItem( nWhich, bHasVAlign && (eVAlign == lclConvertSlotToVAlign( nWhich )) ) );
             break;
-		}
-		nWhich = aIter.NextWhich();
-	}
+        }
+        nWhich = aIter.NextWhich();
+    }
 }
 
 void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
     BOOL bTopBottom = !bVertDontCare && !bLeftRight &&
         ((const SfxBoolItem&) rAttrSet.Get( ATTR_VERTICAL_ASIAN )).GetValue();
 
-    BOOL bBidiDontCare = (rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SFX_ITEM_DONTCARE);
-    EEHorizontalTextDirection eBidiDir = EE_HTEXTDIR_DEFAULT;
-    if ( !bBidiDontCare )
-    {
-        SvxFrameDirection eCellDir = (SvxFrameDirection)((const SvxFrameDirectionItem&)
-                                        rAttrSet.Get( ATTR_WRITINGDIR )).GetValue();
-        if ( eCellDir == FRMDIR_ENVIRONMENT )
-            eBidiDir = (EEHorizontalTextDirection)GetViewData()->GetDocument()->
-                                GetEditTextDirection( GetViewData()->GetTabNo() );
-        else if ( eCellDir == FRMDIR_HORI_RIGHT_TOP )
-            eBidiDir = EE_HTEXTDIR_R2L;
-        else
-            eBidiDir = EE_HTEXTDIR_L2R;