diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-10-28 21:25:40 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-10-28 21:45:16 -0400 |
commit | 5e56dc2da031706e6a6d67306e3bcae3faf01ae9 (patch) | |
tree | 879df8c118ecc406af8e295628c6f49b774f43ff | |
parent | ad3292e2b3adee95e6a0473ee8a5c29df2e20c90 (diff) |
Allow activation of cell even when the document is read-only.
This behavior is very handy when checking for referenced cells
visually by pressing F2. No cell content modification is allowed
of course. (n#647982)
-rw-r--r-- | sc/source/ui/app/inputhdl.cxx | 265 | ||||
-rw-r--r-- | sc/source/ui/inc/inputhdl.hxx | 12 |
2 files changed, 143 insertions, 134 deletions
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index a292e70f8a83..697f573cf630 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -1831,167 +1831,177 @@ void ScInputHandler::RemoveRangeFinder() DeleteRangeFinder(); // loescht die Liste und die Markierungen auf der Tabelle } -BOOL ScInputHandler::StartTable( sal_Unicode cTyped, BOOL bFromCommand ) +bool ScInputHandler::StartTable( sal_Unicode cTyped, bool bFromCommand, bool bInputActivated ) { - // returns TRUE if a new edit mode was started + bool bNewTable = false; - BOOL bNewTable = FALSE; + if (bModified || !ValidCol(aCursorPos.Col())) + return false; - if (!bModified && ValidCol(aCursorPos.Col())) + if (pActiveViewSh) { - if (pActiveViewSh) - { - ImplCreateEditEngine(); - UpdateActiveView(); - SyncViews(); + ImplCreateEditEngine(); + UpdateActiveView(); + SyncViews(); - ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); + ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); - const ScMarkData& rMark = pActiveViewSh->GetViewData()->GetMarkData(); - ScEditableTester aTester; - if ( rMark.IsMarked() || rMark.IsMultiMarked() ) - aTester.TestSelection( pDoc, rMark ); - else - aTester.TestSelectedBlock( pDoc, aCursorPos.Col(),aCursorPos.Row(), - aCursorPos.Col(),aCursorPos.Row(), rMark ); - if ( aTester.IsEditable() ) - { - // UpdateMode is enabled again in ScViewData::SetEditEngine (and not needed otherwise) - pEngine->SetUpdateMode( FALSE ); + const ScMarkData& rMark = pActiveViewSh->GetViewData()->GetMarkData(); + ScEditableTester aTester; + if ( rMark.IsMarked() || rMark.IsMultiMarked() ) + aTester.TestSelection( pDoc, rMark ); + else + aTester.TestSelectedBlock( + pDoc, aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Col(), aCursorPos.Row(), rMark ); - // Attribute in EditEngine uebernehmen + bool bStartInputMode = true; - const ScPatternAttr* pPattern = pDoc->GetPattern( aCursorPos.Col(), - aCursorPos.Row(), - aCursorPos.Tab() ); - if (pPattern != pLastPattern) + if (!aTester.IsEditable()) + { + bProtected = TRUE; + // We allow read-only input mode activation when explicit cell + // activation is requested (double-click or F2) and if it's not + // part of an array. + bool bShowError = !bInputActivated || aTester.GetMessageId() != STR_PROTECTIONERR; + if (bShowError) + { + eMode = SC_INPUT_NONE; + StopInputWinEngine( TRUE ); + UpdateFormulaMode(); + if ( pActiveViewSh && ( !bFromCommand || !bCommandErrorShown ) ) { - // Prozent-Format? + // #97673# Prevent repeated error messages for the same cell from command events + // (for keyboard events, multiple messages are wanted). + // Set the flag before showing the error message because the command handler + // for the next IME command may be called when showing the dialog. + if ( bFromCommand ) + bCommandErrorShown = TRUE; - const SfxItemSet& rAttrSet = pPattern->GetItemSet(); - const SfxPoolItem* pItem; + pActiveViewSh->GetActiveWin()->GrabFocus(); + pActiveViewSh->ErrorMessage(aTester.GetMessageId()); + } + bStartInputMode = false; + } + } - if ( SFX_ITEM_SET == rAttrSet.GetItemState( ATTR_VALUE_FORMAT, TRUE, &pItem ) ) - { - ULONG nFormat = ((const SfxUInt32Item*)pItem)->GetValue(); - bCellHasPercentFormat = ( NUMBERFORMAT_PERCENT == - pDoc->GetFormatTable()->GetType( nFormat ) ); - } - else - bCellHasPercentFormat = FALSE; // Default: kein Prozent + if (bStartInputMode) + { + // UpdateMode is enabled again in ScViewData::SetEditEngine (and not needed otherwise) + pEngine->SetUpdateMode( FALSE ); - // Gueltigkeit angegeben? + // Attribute in EditEngine uebernehmen - if ( SFX_ITEM_SET == rAttrSet.GetItemState( ATTR_VALIDDATA, TRUE, &pItem ) ) - nValidation = ((const SfxUInt32Item*)pItem)->GetValue(); - else - nValidation = 0; + const ScPatternAttr* pPattern = pDoc->GetPattern( aCursorPos.Col(), + aCursorPos.Row(), + aCursorPos.Tab() ); + if (pPattern != pLastPattern) + { + // Prozent-Format? - // EditEngine Defaults + const SfxItemSet& rAttrSet = pPattern->GetItemSet(); + const SfxPoolItem* pItem; - // Hier auf keinen Fall SetParaAttribs, weil die EditEngine evtl. - // schon gefuellt ist (bei Edit-Zellen). - // SetParaAttribs wuerde dann den Inhalt aendern + if ( SFX_ITEM_SET == rAttrSet.GetItemState( ATTR_VALUE_FORMAT, TRUE, &pItem ) ) + { + ULONG nFormat = ((const SfxUInt32Item*)pItem)->GetValue(); + bCellHasPercentFormat = ( NUMBERFORMAT_PERCENT == + pDoc->GetFormatTable()->GetType( nFormat ) ); + } + else + bCellHasPercentFormat = FALSE; // Default: kein Prozent - //! ER 30.08.00 The SetDefaults is now (since MUST/src602 - //! EditEngine changes) implemented as a SetParaAttribs. - //! Any problems? + // Gueltigkeit angegeben? - pPattern->FillEditItemSet( pEditDefaults ); - pEngine->SetDefaults( *pEditDefaults ); - pLastPattern = pPattern; - bLastIsSymbol = pPattern->IsSymbolFont(); + if ( SFX_ITEM_SET == rAttrSet.GetItemState( ATTR_VALIDDATA, TRUE, &pItem ) ) + nValidation = ((const SfxUInt32Item*)pItem)->GetValue(); + else + nValidation = 0; - // Background color must be known for automatic font color. - // For transparent cell background, the document background color must be used. + // EditEngine Defaults - Color aBackCol = ((const SvxBrushItem&) - pPattern->GetItem( ATTR_BACKGROUND )).GetColor(); - ScModule* pScMod = SC_MOD(); - // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed TRUE) - if ( aBackCol.GetTransparency() > 0 || - Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) - aBackCol.SetColor( pScMod->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor ); - pEngine->SetBackgroundColor( aBackCol ); + // Hier auf keinen Fall SetParaAttribs, weil die EditEngine evtl. + // schon gefuellt ist (bei Edit-Zellen). + // SetParaAttribs wuerde dann den Inhalt aendern - // Ausrichtung + //! ER 30.08.00 The SetDefaults is now (since MUST/src602 + //! EditEngine changes) implemented as a SetParaAttribs. + //! Any problems? - eAttrAdjust = (SvxCellHorJustify)((const SvxHorJustifyItem&)pPattern-> - GetItem(ATTR_HOR_JUSTIFY)).GetValue(); - if ( eAttrAdjust == SVX_HOR_JUSTIFY_REPEAT && - static_cast<const SfxBoolItem&>(pPattern->GetItem(ATTR_LINEBREAK)).GetValue() ) - { - // #i31843# "repeat" with "line breaks" is treated as default alignment - eAttrAdjust = SVX_HOR_JUSTIFY_STANDARD; - } - } - - // UpdateSpellSettings enables online spelling if needed - // -> also call if attributes are unchanged + pPattern->FillEditItemSet( pEditDefaults ); + pEngine->SetDefaults( *pEditDefaults ); + pLastPattern = pPattern; + bLastIsSymbol = pPattern->IsSymbolFont(); - UpdateSpellSettings( TRUE ); // uses pLastPattern + // Background color must be known for automatic font color. + // For transparent cell background, the document background color must be used. - // Edit-Engine fuellen + Color aBackCol = ((const SvxBrushItem&) + pPattern->GetItem( ATTR_BACKGROUND )).GetColor(); + ScModule* pScMod = SC_MOD(); + // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed TRUE) + if ( aBackCol.GetTransparency() > 0 || + Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) + aBackCol.SetColor( pScMod->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor ); + pEngine->SetBackgroundColor( aBackCol ); - String aStr; - if (bTextValid) - { - pEngine->SetText(aCurrentText); - aStr = aCurrentText; - bTextValid = FALSE; - aCurrentText.Erase(); - } - else - aStr = GetEditText(pEngine); + // Ausrichtung - if (aStr.Len() > 3 && // Matrix-Formel ? - aStr.GetChar(0) == '{' && - aStr.GetChar(1) == '=' && - aStr.GetChar(aStr.Len()-1) == '}') + eAttrAdjust = (SvxCellHorJustify)((const SvxHorJustifyItem&)pPattern-> + GetItem(ATTR_HOR_JUSTIFY)).GetValue(); + if ( eAttrAdjust == SVX_HOR_JUSTIFY_REPEAT && + static_cast<const SfxBoolItem&>(pPattern->GetItem(ATTR_LINEBREAK)).GetValue() ) { - aStr.Erase(0,1); - aStr.Erase(aStr.Len()-1,1); - pEngine->SetText(aStr); - if ( pInputWin ) - pInputWin->SetTextString(aStr); + // #i31843# "repeat" with "line breaks" is treated as default alignment + eAttrAdjust = SVX_HOR_JUSTIFY_STANDARD; } + } - UpdateAdjust( cTyped ); + // UpdateSpellSettings enables online spelling if needed + // -> also call if attributes are unchanged - if ( bAutoComplete ) - GetColData(); + UpdateSpellSettings( TRUE ); // uses pLastPattern - if ( ( aStr.GetChar(0) == '=' || aStr.GetChar(0) == '+' || aStr.GetChar(0) == '-' ) && - !cTyped && !bCreatingFuncView ) - InitRangeFinder(aStr); // Formel wird editiert -> RangeFinder + // Edit-Engine fuellen - bNewTable = TRUE; // -> PostEditView-Aufruf + String aStr; + if (bTextValid) + { + pEngine->SetText(aCurrentText); + aStr = aCurrentText; + bTextValid = FALSE; + aCurrentText.Erase(); } else - { - bProtected = TRUE; - eMode = SC_INPUT_NONE; - StopInputWinEngine( TRUE ); - UpdateFormulaMode(); - if ( pActiveViewSh && ( !bFromCommand || !bCommandErrorShown ) ) - { - // #97673# Prevent repeated error messages for the same cell from command events - // (for keyboard events, multiple messages are wanted). - // Set the flag before showing the error message because the command handler - // for the next IME command may be called when showing the dialog. - if ( bFromCommand ) - bCommandErrorShown = TRUE; + aStr = GetEditText(pEngine); - pActiveViewSh->GetActiveWin()->GrabFocus(); - pActiveViewSh->ErrorMessage(aTester.GetMessageId()); - } + if (aStr.Len() > 3 && // Matrix-Formel ? + aStr.GetChar(0) == '{' && + aStr.GetChar(1) == '=' && + aStr.GetChar(aStr.Len()-1) == '}') + { + aStr.Erase(0,1); + aStr.Erase(aStr.Len()-1,1); + pEngine->SetText(aStr); + if ( pInputWin ) + pInputWin->SetTextString(aStr); } - } - if (!bProtected && pInputWin) - pInputWin->SetOkCancelMode(); + UpdateAdjust( cTyped ); + + if ( bAutoComplete ) + GetColData(); + + if ( ( aStr.GetChar(0) == '=' || aStr.GetChar(0) == '+' || aStr.GetChar(0) == '-' ) && + !cTyped && !bCreatingFuncView ) + InitRangeFinder(aStr); // Formel wird editiert -> RangeFinder + + bNewTable = true; // -> PostEditView-Aufruf + } } + if (!bProtected && pInputWin) + pInputWin->SetOkCancelMode(); + return bNewTable; } @@ -2065,7 +2075,7 @@ BOOL ScInputHandler::DataChanging( sal_Unicode cTyped, BOOL bFromCommand ) bInOwnChange = TRUE; // disable ModifyHdl (reset in DataChanged) if ( eMode == SC_INPUT_NONE ) - return StartTable( cTyped, bFromCommand ); + return StartTable( cTyped, bFromCommand, false ); else return FALSE; } @@ -2261,7 +2271,6 @@ void ScInputHandler::InvalidateAttribs() } } - // // --------------- public Methoden -------------------------------------------- // @@ -2297,7 +2306,7 @@ void ScInputHandler::SetMode( ScInputMode eNewMode ) { if (eOldMode == SC_INPUT_NONE) // not when switching between modes { - if (StartTable(0, FALSE)) // 0 = look at existing document content for text or number + if (StartTable(0, false, eMode == SC_INPUT_TABLE)) { if (pActiveViewSh) pActiveViewSh->GetViewData()->GetDocShell()->PostEditView( pEngine, aCursorPos ); @@ -3661,7 +3670,6 @@ BOOL ScInputHandler::GetTextAndFields( ScEditEngineDefaulter& rDestEngine ) return bRet; } - //------------------------------------------------------------------------ // Methoden fuer FunktionsAutopiloten: // InputGetSelection, InputSetSelection, InputReplaceSelection, InputGetFormulaStr @@ -3817,7 +3825,4 @@ ScInputHdlState& ScInputHdlState::operator=( const ScInputHdlState& r ) return *this; } - - - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx index d0ebd7a271e2..b6fb5eead65a 100644 --- a/sc/source/ui/inc/inputhdl.hxx +++ b/sc/source/ui/inc/inputhdl.hxx @@ -126,7 +126,14 @@ private: private: void UpdateActiveView(); void SyncViews( EditView* pSourceView = NULL ); - BOOL StartTable( sal_Unicode cTyped, BOOL bFromCommand ); + /** + * @param cTyped typed character. If 0, look at existing document content + * for text or number. + * @param bInputActivated true if the cell input mode is activated (via + * F2), false otherwise. + * @return true if the new edit mode has been started. + */ + bool StartTable( sal_Unicode cTyped, bool bFromCommand, bool bInputActivated ); void RemoveSelection(); void UpdateFormulaMode(); void InvalidateAttribs(); @@ -188,7 +195,6 @@ public: void ViewShellGone(ScTabViewShell* pViewSh); void SetRefViewShell(ScTabViewShell* pRefVsh) {pRefViewSh=pRefVsh;} - void NotifyChange( const ScInputHdlState* pState, BOOL bForce = FALSE, ScTabViewShell* pSourceSh = NULL, BOOL bStopEditing = TRUE); @@ -290,8 +296,6 @@ private: EditTextObject* pEditData; }; - - #endif |