summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@novell.com>2010-10-23 17:52:33 +0100
committerMichael Meeks <michael.meeks@novell.com>2010-10-23 17:52:33 +0100
commitf1b82f5c544e8e34ae46f3fabf284a113fc482ba (patch)
tree60e5ab66f2e72f38624d4b62c63ef73cb8250fb0
parent01f4b50072f4d06aad01d3a310e9b6e946988129 (diff)
re-instate the nasty old editing paths as a run-time conditionalfeature/editable-formulae
-rw-r--r--starmath/inc/edit.hxx6
-rw-r--r--starmath/inc/node.hxx11
-rw-r--r--starmath/inc/view.hxx20
-rw-r--r--starmath/source/document.cxx6
-rw-r--r--starmath/source/edit.cxx61
-rw-r--r--starmath/source/view.cxx155
6 files changed, 235 insertions, 24 deletions
diff --git a/starmath/inc/edit.hxx b/starmath/inc/edit.hxx
index cd0c6cbf4f..7249cc3a44 100644
--- a/starmath/inc/edit.hxx
+++ b/starmath/inc/edit.hxx
@@ -65,13 +65,15 @@ class SmEditWindow : public Window, public DropTargetHelper
ScrollBar *pHScrollBar,
*pVScrollBar;
ScrollBarBox *pScrollBox;
- Timer aModifyTimer;
+ Timer aModifyTimer,
+ aCursorMoveTimer;
ESelection aOldSelection;
virtual void KeyInput(const KeyEvent& rKEvt);
virtual void Command(const CommandEvent& rCEvt);
DECL_LINK(MenuSelectHdl, Menu *);
DECL_LINK(ModifyTimerHdl, Timer *);
+ DECL_LINK(CursorMoveTimerHdl, Timer *);
virtual void DataChanged( const DataChangedEvent& );
virtual void Resize();
@@ -133,6 +135,8 @@ public:
void ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg );
BOOL HandleWheelCommands( const CommandEvent &rCEvt );
+ bool IsInlineEditEnabled();
+ void StartCursorMove();
// for Accessibility
virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index f6a33a6e98..7f7981d9a2 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -34,9 +34,10 @@
#include <iostream>
#include <stdio.h>
-//My special assert macro
-//TODO: replace this with DBG_ASSERT when this patch moves to production, can be done using search/replace
-#define j_assert(cond, msg) do{ \
+#define j_assert(cond, msg) DBG_ASSERT(cond, msg)
+#if 0
+// easier to read assert macro
+ do{ \
if(!(cond)) \
{ \
std::cerr<<"Failed assertion: "<<msg<<", at line "; \
@@ -48,7 +49,9 @@
fprintf(stderr, "%d in %s\n", __LINE__, f + 1); \
} \
} while(false)
-//TODO: Comment out below to disable dumpasdot
+#endif
+
+// Comment out below to disable dumpasdot
#define DEBUG_ENABLE_DUMPASDOT
#include "parse.hxx"
diff --git a/starmath/inc/view.hxx b/starmath/inc/view.hxx
index 67e83ac243..f867e4a9df 100644
--- a/starmath/inc/view.hxx
+++ b/starmath/inc/view.hxx
@@ -51,8 +51,23 @@ class SmPrintUIOptions;
class SmGraphicWindow : public ScrollableWindow
{
- Point aFormulaDrawPos;
+ Point aFormulaDrawPos;
+ // old style editing pieces
+ Rectangle aCursorRect;
+ bool bIsCursorVisible;
+public:
+ BOOL IsCursorVisible() const { return bIsCursorVisible; }
+ void ShowCursor(BOOL bShow);
+ const SmNode * SetCursorPos(USHORT nRow, USHORT nCol);
+protected:
+ void SetIsCursorVisible(BOOL bVis) { bIsCursorVisible = bVis; }
+ using Window::SetCursor;
+ void SetCursor(const SmNode *pNode);
+ void SetCursor(const Rectangle &rRect);
+ bool IsInlineEditEnabled() const;
+
+private:
::com::sun::star::uno::Reference<
::com::sun::star::accessibility::XAccessible > xAccessible;
SmGraphicAccessible * pAccessible;
@@ -298,6 +313,9 @@ public:
void SetInsertIntoEditWindow(BOOL bEditWindowHadFocusLast = TRUE){
bInsertIntoEditWindow = bEditWindowHadFocusLast;
}
+ bool IsInlineEditEnabled() const {
+ return false;
+ }
};
#endif
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 7029228e9e..d2d893f57c 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -98,6 +98,7 @@
#include <sfx2/sfxsids.hrc>
#include <svx/svxids.hrc>
#include "cursor.hxx"
+#include "visitors.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::accessibility;
@@ -435,8 +436,6 @@ SfxItemPool& SmDocShell::GetEditEngineItemPool()
OSL_ENSURE( pEditEngineItemPool, "EditEngineItemPool missing" );
return *pEditEngineItemPool;
}
-//TODO: Move to the top of the file...
-#include "visitors.hxx"
void SmDocShell::DrawFormula(OutputDevice &rDev, Point &rPosition, BOOL bDrawSelection)
{
@@ -530,8 +529,7 @@ Size SmDocShell::GetSize()
}
void SmDocShell::InvalidateCursor(){
- if(pCursor)
- delete pCursor;
+ delete pCursor;
pCursor = NULL;
}
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index 397406573e..a9a1ad2394 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -96,6 +96,11 @@ void SmGetLeftSelectionPart(const ESelection aSel,
}
}
+bool SmEditWindow::IsInlineEditEnabled()
+{
+ return GetView()->IsInlineEditEnabled();
+}
+
////////////////////////////////////////
SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
@@ -122,6 +127,12 @@ SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
aModifyTimer.SetTimeoutHdl(LINK(this, SmEditWindow, ModifyTimerHdl));
aModifyTimer.SetTimeout(500);
+ if (!IsInlineEditEnabled())
+ {
+ aCursorMoveTimer.SetTimeoutHdl(LINK(this, SmEditWindow, CursorMoveTimerHdl));
+ aCursorMoveTimer.SetTimeout(500);
+ }
+
// if not called explicitly the this edit window within the
// command window will just show an empty gray panel.
Show();
@@ -132,6 +143,7 @@ SmEditWindow::~SmEditWindow()
{
aModifyTimer.Stop();
+ StartCursorMove();
// #112565# clean up of classes used for accessibility
// must be done before EditView (and thus EditEngine) is no longer
@@ -156,6 +168,12 @@ SmEditWindow::~SmEditWindow()
delete pScrollBox;
}
+void SmEditWindow::StartCursorMove()
+{
+ if (!IsInlineEditEnabled())
+ aCursorMoveTimer.Stop();
+}
+
void SmEditWindow::InvalidateSlots()
{
SfxBindings& rBind = GetView()->GetViewFrame()->GetBindings();
@@ -253,6 +271,35 @@ IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
return 0;
}
+IMPL_LINK(SmEditWindow, CursorMoveTimerHdl, Timer *, EMPTYARG /*pTimer*/)
+ // every once in a while check cursor position (selection) of edit
+ // window and if it has changed (try to) set the formula-cursor
+ // according to that.
+{
+ if (IsInlineEditEnabled())
+ return 0;
+
+ ESelection aNewSelection(GetSelection());
+
+ if (!aNewSelection.IsEqual(aOldSelection))
+ {
+ SmViewShell *pView = rCmdBox.GetView();
+ if (pView)
+ {
+ // get row and column to look for
+ USHORT nRow, nCol;
+ SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
+ nRow++;
+ nCol++;
+ pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
+ aOldSelection = aNewSelection;
+ }
+ }
+ aCursorMoveTimer.Stop();
+
+ return 0;
+}
+
void SmEditWindow::Resize()
{
if (!pEditView)
@@ -286,6 +333,8 @@ void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
else
Window::MouseButtonUp (rEvt);
+ if (!IsInlineEditEnabled())
+ CursorMoveTimerHdl(&aCursorMoveTimer);
InvalidateSlots();
}
@@ -390,6 +439,8 @@ void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
}
else
{
+ StartCursorMove();
+
if (!pEditView)
CreateEditView();
if ( !pEditView->PostKeyEvent(rKEvt) )
@@ -616,7 +667,7 @@ void SmEditWindow::GetFocus()
pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
//Let SmViewShell know we got focus
- if(GetView())
+ if(GetView() && IsInlineEditEnabled())
GetView()->SetInsertIntoEditWindow(TRUE);
}
@@ -700,7 +751,7 @@ void SmEditWindow::InsertCommand(USHORT nCommand)
}
aModifyTimer.Start();
-
+ StartCursorMove();
GrabFocus();
}
}
@@ -887,6 +938,7 @@ void SmEditWindow::InsertText(const String& Text)
{
pEditView->InsertText(Text);
aModifyTimer.Start();
+ StartCursorMove();
}
}
@@ -904,6 +956,11 @@ void SmEditWindow::Flush()
new SfxStringItem(SID_TEXT, GetText()), 0L);
}
}
+ if (aCursorMoveTimer.IsActive())
+ {
+ aCursorMoveTimer.Stop();
+ CursorMoveTimerHdl(&aCursorMoveTimer);
+ }
}
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index f06244b3f2..7e98170f5c 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -169,16 +169,50 @@ void SmGraphicWindow::MouseButtonDown(const MouseEvent& rMEvt)
Point aPos (PixelToLogic(rMEvt.GetPosPixel())
- GetFormulaDrawPos());
- const SmNode* pTree = pViewShell->GetDoc()->GetFormulaTree();
-
+ const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
+ if (!pTree)
+ return;
+
+ if (IsInlineEditEnabled()) {
+ // if it was clicked inside the formula then get the appropriate node
+ if (pTree->OrientedDist(aPos) <= 0)
+ pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, !rMEvt.IsShift());
+ return;
+ }
+ const SmNode *pNode = 0;
// if it was clicked inside the formula then get the appropriate node
if (pTree->OrientedDist(aPos) <= 0)
- pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, !rMEvt.IsShift());
+ pNode = pTree->FindRectClosestTo(aPos);
+
+ if (pNode)
+ { SmEditWindow *pEdit = pViewShell->GetEditWindow();
+ const SmToken aToken (pNode->GetToken());
+
+ // set selection to the beginning of the token
+ ESelection aSel (aToken.nRow - 1, aToken.nCol - 1);
+
+ if (rMEvt.GetClicks() != 1 || aToken.eType == TPLACE)
+ aSel.nEndPos = aSel.nEndPos + sal::static_int_cast< USHORT >(aToken.aText.Len());
+
+ pEdit->SetSelection(aSel);
+ SetCursor(pNode);
+
+ // allow for immediate editing and
+ //! implicitly synchronize the cursor position mark in this window
+ pEdit->GrabFocus();
+ }
}
}
+bool SmGraphicWindow::IsInlineEditEnabled() const
+{
+ return pViewShell->GetEditWindow()->IsInlineEditEnabled();
+}
+
void SmGraphicWindow::GetFocus()
{
+ if (!IsInlineEditEnabled())
+ return;
pViewShell->GetEditWindow()->Flush();
//Let view shell know what insertions should be done in visual editor
pViewShell->SetInsertIntoEditWindow(FALSE);
@@ -197,6 +231,80 @@ void SmGraphicWindow::LoseFocus()
}
}
+void SmGraphicWindow::ShowCursor(BOOL bShow)
+ // shows or hides the formula-cursor depending on 'bShow' is TRUE or not
+{
+ if (IsInlineEditEnabled())
+ return;
+
+ BOOL bInvert = bShow != IsCursorVisible();
+
+ if (bInvert)
+ InvertTracking(aCursorRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW);
+
+ SetIsCursorVisible(bShow);
+}
+
+
+void SmGraphicWindow::SetCursor(const SmNode *pNode)
+{
+ if (IsInlineEditEnabled())
+ return;
+
+ const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
+
+ // get appropriate rectangle
+ Point aOffset (pNode->GetTopLeft() - pTree->GetTopLeft()),
+ aTLPos (GetFormulaDrawPos() + aOffset);
+ aTLPos.X() -= pNode->GetItalicLeftSpace();
+ Size aSize (pNode->GetItalicSize());
+ Point aBRPos (aTLPos.X() + aSize.Width(), aTLPos.Y() + aSize.Height());
+
+ SetCursor(Rectangle(aTLPos, aSize));
+}
+
+void SmGraphicWindow::SetCursor(const Rectangle &rRect)
+ // sets cursor to new position (rectangle) 'rRect'.
+ // The old cursor will be removed, and the new one will be shown if
+ // that is activated in the ConfigItem
+{
+ if (IsInlineEditEnabled())
+ return;
+
+ SmModule *pp = SM_MOD();
+
+ if (IsCursorVisible())
+ ShowCursor(FALSE); // clean up remainings of old cursor
+ aCursorRect = rRect;
+ if (pp->GetConfig()->IsShowFormulaCursor())
+ ShowCursor(TRUE); // draw new cursor
+}
+
+const SmNode * SmGraphicWindow::SetCursorPos(USHORT nRow, USHORT nCol)
+ // looks for a VISIBLE node in the formula tree with it's token at
+ // (or around) the position 'nRow', 'nCol' in the edit window
+ // (row and column numbering starts with 1 there!).
+ // If there is such a node the formula-cursor is set to cover that nodes
+ // rectangle. If not the formula-cursor will be hidden.
+ // In any case the search result is being returned.
+{
+ if (IsInlineEditEnabled())
+ return NULL;
+
+ // find visible node with token at nRow, nCol
+ const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree(),
+ *pNode = 0;
+ if (pTree)
+ pNode = pTree->FindTokenAt(nRow, nCol);
+
+ if (pNode)
+ SetCursor(pNode);
+ else
+ ShowCursor(FALSE);
+
+ return pNode;
+}
+
void SmGraphicWindow::Paint(const Rectangle&)
{
OSL_ENSURE(pViewShell, "Sm : NULL pointer");
@@ -207,9 +315,27 @@ void SmGraphicWindow::Paint(const Rectangle&)
rDoc.DrawFormula(*this, aPoint, TRUE); //! modifies aPoint to be the topleft
//! corner of the formula
SetFormulaDrawPos(aPoint);
- //Draw cursor if any...
- if(pViewShell->GetDoc()->HasCursor())
- pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint);
+ if(IsInlineEditEnabled()) {
+ //Draw cursor if any...
+ if(pViewShell->GetDoc()->HasCursor())
+ pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint);
+ } else {
+ SetIsCursorVisible(FALSE); // (old) cursor must be drawn again
+
+ const SmEditWindow *pEdit = pViewShell->GetEditWindow();
+ if (pEdit)
+ { // get new position for formula-cursor (for possible altered formula)
+ USHORT nRow, nCol;
+ SmGetLeftSelectionPart(pEdit->GetSelection(), nRow, nCol);
+ nRow++;
+ nCol++;
+ const SmNode *pFound = SetCursorPos(nRow, nCol);
+
+ SmModule *pp = SM_MOD();
+ if (pFound && pp->GetConfig()->IsShowFormulaCursor())
+ ShowCursor(TRUE);
+ }
+ }
}
@@ -223,6 +349,11 @@ void SmGraphicWindow::SetTotalSize ()
void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
{
+ if (!IsInlineEditEnabled()) {
+ if (! (GetView() && GetView()->KeyInput(rKEvt)) )
+ ScrollableWindow::KeyInput(rKEvt);
+ return;
+ }
USHORT nCode = rKEvt.GetKeyCode().GetCode();
SmCursor& rCursor = pViewShell->GetDoc()->GetCursor();
switch(nCode)
@@ -1360,8 +1491,8 @@ void SmViewShell::Execute(SfxRequest& rReq)
bVal = !pp->GetConfig()->IsShowFormulaCursor();
pp->GetConfig()->SetShowFormulaCursor(bVal);
- //GetGraphicWindow().ShowCursor(bVal);
- //TODO Consider disabling this option!!!
+ if (!IsInlineEditEnabled())
+ GetGraphicWindow().ShowCursor(bVal);
break;
}
case SID_DRAW:
@@ -1506,9 +1637,9 @@ void SmViewShell::Execute(SfxRequest& rReq)
const SfxInt16Item& rItem =
(const SfxInt16Item&)rReq.GetArgs()->Get(SID_INSERTCOMMAND);
- if (pWin && bInsertIntoEditWindow)
+ if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
pWin->InsertCommand(rItem.GetValue());
- if (GetDoc() && !bInsertIntoEditWindow) {
+ if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow)) {
GetDoc()->GetCursor().InsertCommand(rItem.GetValue());
GetGraphicWindow().GrabFocus();
}
@@ -1520,9 +1651,9 @@ void SmViewShell::Execute(SfxRequest& rReq)
const SfxStringItem& rItem =
(const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTSYMBOL);
- if (pWin && bInsertIntoEditWindow)
+ if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
pWin->InsertText(rItem.GetValue());
- if(GetDoc() && !bInsertIntoEditWindow)
+ if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow))
GetDoc()->GetCursor().InsertSpecial(rItem.GetValue());
break;
}