diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-05-14 13:32:28 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-05-14 13:35:06 +0900 |
commit | 8d9b429e8c304eaf91988c17b753d6496789bed1 (patch) | |
tree | 6f94e1567a91654b352e55b84ebecadac4207c94 | |
parent | 571bbac2c738d96f61464b04e0e63a4fc0531b8d (diff) |
refactor starmath view/edit classes to use RenderContext
Change-Id: I741e596a665119b50597586e9b0b5e8339a826ae
-rw-r--r-- | starmath/inc/edit.hxx | 127 | ||||
-rw-r--r-- | starmath/source/edit.cxx | 26 | ||||
-rw-r--r-- | starmath/source/view.cxx | 129 |
3 files changed, 127 insertions, 155 deletions
diff --git a/starmath/inc/edit.hxx b/starmath/inc/edit.hxx index 35557fb491b1..485ca0c31197 100644 --- a/starmath/inc/edit.hxx +++ b/starmath/inc/edit.hxx @@ -40,30 +40,25 @@ class SmCmdBoxWindow; class SmEditAccessible; class CommandEvent; -/**************************************************************************/ - - void SmGetLeftSelectionPart(const ESelection &rSelection, - sal_Int32 &nPara, sal_uInt16 &nPos); - -/**************************************************************************/ +void SmGetLeftSelectionPart(const ESelection &rSelection, sal_Int32 &nPara, sal_uInt16 &nPos); class SmEditWindow : public vcl::Window, public DropTargetHelper { - ::com::sun::star::uno::Reference< - ::com::sun::star::accessibility::XAccessible > xAccessible; - SmEditAccessible * pAccessible; + css::uno::Reference<css::accessibility::XAccessible> xAccessible; + SmEditAccessible* pAccessible; - SmCmdBoxWindow &rCmdBox; + SmCmdBoxWindow& rCmdBox; std::unique_ptr<EditView> pEditView; - VclPtr<ScrollBar> pHScrollBar, - pVScrollBar; - VclPtr<ScrollBarBox> pScrollBox; - Idle aModifyIdle, - aCursorMoveIdle; - ESelection aOldSelection; + VclPtr<ScrollBar> pHScrollBar; + VclPtr<ScrollBar> pVScrollBar; + VclPtr<ScrollBarBox> pScrollBox; + Idle aModifyIdle; + Idle aCursorMoveIdle; + ESelection aOldSelection; virtual void KeyInput(const KeyEvent& rKEvt) SAL_OVERRIDE; virtual void Command(const CommandEvent& rCEvt) SAL_OVERRIDE; + DECL_LINK(MenuSelectHdl, Menu *); DECL_LINK_TYPED(ModifyTimerHdl, Idle *, void); DECL_LINK_TYPED(CursorMoveTimerHdl, Idle *, void); @@ -74,70 +69,72 @@ class SmEditWindow : public vcl::Window, public DropTargetHelper virtual void MouseButtonUp(const MouseEvent &rEvt) SAL_OVERRIDE; virtual void MouseButtonDown(const MouseEvent &rEvt) SAL_OVERRIDE; - virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) SAL_OVERRIDE; - virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) SAL_OVERRIDE; + virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) SAL_OVERRIDE; + virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) SAL_OVERRIDE; virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE; DECL_LINK(EditStatusHdl ,EditStatus *); DECL_LINK(ScrollHdl, ScrollBar *); - void CreateEditView(); - - Rectangle AdjustScrollBars(); - void SetScrollBarRanges(); - void InitScrollBars(); - void InvalidateSlots(); - void UpdateStatus( bool bSetDocModified = false ); + void CreateEditView(); + Rectangle AdjustScrollBars(); + void SetScrollBarRanges(); + void InitScrollBars(); + void InvalidateSlots(); + void UpdateStatus(bool bSetDocModified = false); public: - SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ); + SmEditWindow(SmCmdBoxWindow& rMyCmdBoxWin); virtual ~SmEditWindow(); - virtual void dispose() SAL_OVERRIDE; + virtual void dispose() SAL_OVERRIDE; - SmDocShell * GetDoc(); - SmViewShell * GetView(); - EditView * GetEditView(); - EditEngine * GetEditEngine(); - SfxItemPool * GetEditEngineItemPool(); + SmDocShell* GetDoc(); + SmViewShell* GetView(); + EditView* GetEditView(); + EditEngine* GetEditEngine(); + SfxItemPool* GetEditEngineItemPool(); // Window - virtual void SetText(const OUString &rText) SAL_OVERRIDE; - virtual OUString GetText() const SAL_OVERRIDE; - virtual void GetFocus() SAL_OVERRIDE; - virtual void LoseFocus() SAL_OVERRIDE; - - ESelection GetSelection() const; - void SetSelection(const ESelection &rSel); - - bool IsEmpty() const; - bool IsSelected() const; - bool IsAllSelected() const; - void Cut(); - void Copy(); - void Paste(); - void Delete(); - void SelectAll(); - void InsertText(const OUString &rText); - void InsertCommand(sal_uInt16 nCommand); - void MarkError(const Point &rPos); - void SelNextMark(); - void SelPrevMark(); - static bool HasMark(const OUString &rText); - - void Flush(); - void DeleteEditView( SmViewShell &rView ); - - void ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg ); - - bool HandleWheelCommands( const CommandEvent &rCEvt ); - bool IsInlineEditEnabled(); - void StartCursorMove(); + virtual void SetText(const OUString& rText) SAL_OVERRIDE; + virtual OUString GetText() const SAL_OVERRIDE; + virtual void GetFocus() SAL_OVERRIDE; + virtual void LoseFocus() SAL_OVERRIDE; + + ESelection GetSelection() const; + void SetSelection(const ESelection& rSel); + + bool IsEmpty() const; + bool IsSelected() const; + bool IsAllSelected() const; + void Cut(); + void Copy(); + void Paste(); + void Delete(); + void SelectAll(); + void InsertText(const OUString& rText); + void InsertCommand(sal_uInt16 nCommand); + void MarkError(const Point &rPos); + void SelNextMark(); + void SelPrevMark(); + static bool HasMark(const OUString &rText); + + void Flush(); + void DeleteEditView(SmViewShell& rView); + + 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() SAL_OVERRIDE; + virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() SAL_OVERRIDE; using Window::GetAccessible; - SmEditAccessible * GetAccessible() { return pAccessible; } + SmEditAccessible* GetAccessible() + { + return pAccessible; + } }; diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx index 3213a3477fd4..65906f0ab762 100644 --- a/starmath/source/edit.cxx +++ b/starmath/source/edit.cxx @@ -503,20 +503,20 @@ void SmEditWindow::KeyInput(const KeyEvent& rKEvt) } // get the current char of the key event - sal_Unicode charCode = rKEvt.GetCharCode(); - OUString close; + sal_Unicode cCharCode = rKEvt.GetCharCode(); + OUString sClose; - if (charCode == '{') - close = " }"; - else if (charCode == '[') - close = " ]"; - else if (charCode == '(') - close = " )"; + if (cCharCode == '{') + sClose = " }"; + else if (cCharCode == '[') + sClose = " ]"; + else if (cCharCode == '(') + sClose = " )"; // auto close the current character only when needed - if (!close.isEmpty() && autoClose) + if (!sClose.isEmpty() && autoClose) { - pEditView->InsertText(close); + pEditView->InsertText(sClose); // position it at center of brackets aSelection.nStartPos += 2; aSelection.nEndPos = aSelection.nStartPos; @@ -527,11 +527,11 @@ void SmEditWindow::KeyInput(const KeyEvent& rKEvt) } } -void SmEditWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect) +void SmEditWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) { if (!pEditView) CreateEditView(); - pEditView->Paint(rRect); + pEditView->Paint(rRect, &rRenderContext); } void SmEditWindow::CreateEditView() @@ -542,7 +542,7 @@ void SmEditWindow::CreateEditView() //! For example when the program is used by the document-converter if (!pEditView && pEditEngine) { - pEditView.reset(new EditView( pEditEngine, this )); + pEditView.reset(new EditView(pEditEngine, this)); pEditEngine->InsertView( pEditView.get() ); if (!pVScrollBar) diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx index 65a1eccbe48e..a5c541cce82d 100644 --- a/starmath/source/view.cxx +++ b/starmath/source/view.cxx @@ -86,26 +86,22 @@ #define SmViewShell #include "smslots.hxx" -using namespace com::sun::star; -using namespace com::sun::star::accessibility; -using namespace com::sun::star::uno; +using namespace css; +using namespace css::accessibility; +using namespace css::uno; - - -SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell): - ScrollableWindow(&pShell->GetViewFrame()->GetWindow(), 0), - pAccessible(0), - pViewShell(pShell), - nZoom(100) +SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell) + : ScrollableWindow(&pShell->GetViewFrame()->GetWindow(), 0) + , pAccessible(0) + , pViewShell(pShell) + , nZoom(100) { // docking windows are usually hidden (often already done in the // resource) and will be shown by the sfx framework. Hide(); - const Fraction aFraction (1,1); - SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction)); - - ApplyColorConfigValues( SM_MOD()->GetColorConfig() ); + const Fraction aFraction(1, 1); + SetMapMode(MapMode(MAP_100TH_MM, Point(), aFraction, aFraction)); SetTotalSize(); @@ -131,30 +127,27 @@ void SmGraphicWindow::dispose() ScrollableWindow::dispose(); } -void SmGraphicWindow::StateChanged( StateChangedType eType ) +void SmGraphicWindow::StateChanged(StateChangedType eType) { - if ( eType == StateChangedType::InitShow ) + if (eType == StateChangedType::InitShow) Show(); - ScrollableWindow::StateChanged( eType ); + ScrollableWindow::StateChanged(eType); } -void SmGraphicWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg ) +void SmGraphicWindow::ApplyColorConfigValues(const svtools::ColorConfig &rColorCfg) { // Note: SetTextColor not necessary since the nodes that // get painted have the color information. #if OSL_DEBUG_LEVEL > 1 // ColorData nVal = rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor; #endif - SetBackground( Color( (ColorData) rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor ) ); - Invalidate(); + SetBackground(Color( (ColorData) rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor)); } void SmGraphicWindow::DataChanged( const DataChangedEvent& rEvt ) { - ApplyColorConfigValues( SM_MOD()->GetColorConfig() ); - ScrollableWindow::DataChanged( rEvt ); } @@ -165,7 +158,6 @@ void SmGraphicWindow::MouseButtonDown(const MouseEvent& rMEvt) GrabFocus(); - // set formula-cursor and selection of edit window according to the // position clicked at @@ -267,7 +259,7 @@ void SmGraphicWindow::LoseFocus() void SmGraphicWindow::RepaintViewShellDoc() { - SmDocShell *pDoc = pViewShell->GetDoc(); + SmDocShell* pDoc = pViewShell->GetDoc(); if (pDoc) pDoc->Repaint(); } @@ -292,7 +284,7 @@ void SmGraphicWindow::CaretBlinkStart() { if (!IsInlineEditEnabled()) return; - if ( aCaretBlinkTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME ) + if (aCaretBlinkTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME) aCaretBlinkTimer.Start(); } @@ -383,27 +375,29 @@ const SmNode * SmGraphicWindow::SetCursorPos(sal_uInt16 nRow, sal_uInt16 nCol) return pNode; } -void SmGraphicWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle&) +void SmGraphicWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle&) { - SAL_WARN_IF( !pViewShell, "starmath", "view shell missing" ); + SAL_WARN_IF(!pViewShell, "starmath", "view shell missing"); - SmDocShell &rDoc = *pViewShell->GetDoc(); + ApplyColorConfigValues(SM_MOD()->GetColorConfig()); + + SmDocShell& rDoc = *pViewShell->GetDoc(); Point aPoint; - rDoc.DrawFormula(*this, aPoint, true); //! modifies aPoint to be the topleft + rDoc.DrawFormula(rRenderContext, aPoint, true); //! modifies aPoint to be the topleft //! corner of the formula SetFormulaDrawPos(aPoint); - if(IsInlineEditEnabled()) + if (IsInlineEditEnabled()) { //Draw cursor if any... - if(pViewShell->GetDoc()->HasCursor() && IsLineVisible()) - pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint, IsCursorVisible()); + if (pViewShell->GetDoc()->HasCursor() && IsLineVisible()) + pViewShell->GetDoc()->GetCursor().Draw(rRenderContext, aPoint, IsCursorVisible()); } else { SetIsCursorVisible(false); // (old) cursor must be drawn again - const SmEditWindow *pEdit = pViewShell->GetEditWindow(); + const SmEditWindow* pEdit = pViewShell->GetEditWindow(); if (pEdit) { // get new position for formula-cursor (for possible altered formula) sal_Int32 nRow; @@ -413,7 +407,7 @@ void SmGraphicWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectan nCol++; const SmNode *pFound = SetCursorPos(static_cast<sal_uInt16>(nRow), nCol); - SmModule *pp = SM_MOD(); + SmModule *pp = SM_MOD(); if (pFound && pp->GetConfig()->IsShowFormulaCursor()) ShowCursor(true); } @@ -718,7 +712,7 @@ SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWi SetSizePixel(LogicToPixel(Size(292 , 94), MapMode(MAP_APPFONT))); SetText(SM_RESSTR(STR_CMDBOXWINDOW)); - Hide (); + Hide(); aInitialFocusTimer.SetTimeoutHdl(LINK(this, SmCmdBoxWindow, InitialFocusTimerHdl)); aInitialFocusTimer.SetTimeout(100); @@ -746,29 +740,21 @@ SmViewShell * SmCmdBoxWindow::GetView() void SmCmdBoxWindow::Resize() { - Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel()); - aRect.Left() += CMD_BOX_PADDING; - aRect.Top() += CMD_BOX_PADDING_TOP; - aRect.Right() -= CMD_BOX_PADDING; - aRect.Bottom() -= CMD_BOX_PADDING; - - DecorationView aView(this); - aRect = aView.DrawFrame( aRect, DrawFrameStyle::In, DrawFrameFlags::NoDraw ); - - aEdit->SetPosSizePixel(aRect.TopLeft(), aRect.GetSize()); SfxDockingWindow::Resize(); Invalidate(); } -void SmCmdBoxWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle& /*rRect*/) +void SmCmdBoxWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/) { - Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel()); + Rectangle aRect = Rectangle(Point(0, 0), rRenderContext.GetOutputSizePixel()); aRect.Left() += CMD_BOX_PADDING; aRect.Top() += CMD_BOX_PADDING_TOP; aRect.Right() -= CMD_BOX_PADDING; aRect.Bottom() -= CMD_BOX_PADDING; - DecorationView aView(this); + aEdit->SetPosSizePixel(aRect.TopLeft(), aRect.GetSize()); + + DecorationView aView(&rRenderContext); aView.DrawFrame( aRect, DrawFrameStyle::In ); } @@ -913,9 +899,6 @@ SmCmdBoxWrapper::~SmCmdBoxWrapper() } #endif - -/**************************************************************************/ - struct SmViewShell_Impl { std::unique_ptr<sfx2::DocumentInserter> pDocInserter; @@ -1019,7 +1002,6 @@ Size SmViewShell::GetTextLineSize(OutputDevice& rDevice, const OUString& rLine) return aSize; } - Size SmViewShell::GetTextSize(OutputDevice& rDevice, const OUString& rText, long MaxWidth) { Size aSize; @@ -1167,10 +1149,7 @@ void SmViewShell::DrawText(OutputDevice& rDevice, const Point& rPosition, const } } -void SmViewShell::Impl_Print( - OutputDevice &rOutDev, - const SmPrintUIOptions &rPrintUIOptions, - Rectangle aOutRect, Point aZeroPoint ) +void SmViewShell::Impl_Print(OutputDevice &rOutDev, const SmPrintUIOptions &rPrintUIOptions, Rectangle aOutRect, Point aZeroPoint ) { const bool bIsPrintTitle = rPrintUIOptions.getBoolValue( PRTUIOPT_TITLE_ROW, true ); const bool bIsPrintFrame = rPrintUIOptions.getBoolValue( PRTUIOPT_BORDER, true ); @@ -1353,30 +1332,27 @@ VclPtr<SfxTabPage> SmViewShell::CreatePrintOptionsPage(vcl::Window *pParent, return SmPrintOptionsTabPage::Create(pParent, rOptions); } - SmEditWindow *SmViewShell::GetEditWindow() { - SmCmdBoxWrapper *pWrapper = static_cast<SmCmdBoxWrapper *>( GetViewFrame()-> - GetChildWindow( SmCmdBoxWrapper::GetChildWindowId() ) ); + SmCmdBoxWrapper* pWrapper = static_cast<SmCmdBoxWrapper*>( + GetViewFrame()->GetChildWindow(SmCmdBoxWrapper::GetChildWindowId())); - if (pWrapper != NULL) + if (pWrapper != nullptr) { SmEditWindow& rEditWin = pWrapper->GetEditWindow(); return &rEditWin; } - return NULL; + return nullptr; } - void SmViewShell::SetStatusText(const OUString& rText) { aStatusText = rText; GetViewFrame()->GetBindings().Invalidate(SID_TEXTSTATUS); } - -void SmViewShell::ShowError( const SmErrorDesc *pErrorDesc ) +void SmViewShell::ShowError(const SmErrorDesc* pErrorDesc) { SAL_WARN_IF( !GetDoc(), "starmath", "Document missing" ); if (pErrorDesc || 0 != (pErrorDesc = GetDoc()->GetParser().GetError(0)) ) @@ -1387,7 +1363,6 @@ void SmViewShell::ShowError( const SmErrorDesc *pErrorDesc ) } } - void SmViewShell::NextError() { SAL_WARN_IF( !GetDoc(), "starmath", "Document missing" ); @@ -1413,11 +1388,11 @@ void SmViewShell::Insert( SfxMedium& rMedium ) SmDocShell *pDoc = GetDoc(); bool bRet = false; - uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage(); - uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); - if ( xNameAccess.is() && xNameAccess->getElementNames().getLength() ) + uno::Reference <embed::XStorage> xStorage = rMedium.GetStorage(); + uno::Reference <container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY); + if (xNameAccess.is() && xNameAccess->getElementNames().getLength()) { - if ( xNameAccess->hasByName( OUString("content.xml") ) || xNameAccess->hasByName( OUString("Content.xml") )) + if (xNameAccess->hasByName(OUString("content.xml")) || xNameAccess->hasByName(OUString("Content.xml"))) { // is this a fabulous math package ? Reference<com::sun::star::frame::XModel> xModel(pDoc->GetModel()); @@ -1426,7 +1401,7 @@ void SmViewShell::Insert( SfxMedium& rMedium ) } } - if( bRet ) + if (bRet) { OUString aText = pDoc->GetText(); SmEditWindow *pEditWin = GetEditWindow(); @@ -1448,34 +1423,34 @@ void SmViewShell::Insert( SfxMedium& rMedium ) void SmViewShell::InsertFrom(SfxMedium &rMedium) { - bool bSuccess = false; - SmDocShell *pDoc = GetDoc(); - SvStream *pStream = rMedium.GetInStream(); + bool bSuccess = false; + SmDocShell* pDoc = GetDoc(); + SvStream* pStream = rMedium.GetInStream(); if (pStream) { const OUString& rFltName = rMedium.GetFilter()->GetFilterName(); if ( rFltName == MATHML_XML ) { - Reference<com::sun::star::frame::XModel> xModel( pDoc->GetModel() ); + Reference<css::frame::XModel> xModel(pDoc->GetModel()); SmXMLImportWrapper aEquation(xModel); //!! modifies the result of pDoc->GetText() !! bSuccess = 0 == aEquation.Import(rMedium); } } - if( bSuccess ) + if (bSuccess) { OUString aText = pDoc->GetText(); SmEditWindow *pEditWin = GetEditWindow(); if (pEditWin) - pEditWin->InsertText( aText ); + pEditWin->InsertText(aText); else SAL_WARN( "starmath", "EditWindow missing" ); pDoc->Parse(); pDoc->SetModified(true); - SfxBindings &rBnd = GetViewFrame()->GetBindings(); + SfxBindings& rBnd = GetViewFrame()->GetBindings(); rBnd.Invalidate(SID_GAPHIC_SM); rBnd.Invalidate(SID_TEXT); } |