1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 #include <vcl/customweld.hxx>
25 #include <vcl/toolbox.hxx>
26 #include <vcl/InterimItemWindow.hxx>
27 #include <sfx2/childwin.hxx>
28 #include <svl/lstner.hxx>
29 #include <svtools/stringtransfer.hxx>
30 #include <vcl/window.hxx>
31 #include <formula/opcode.hxx>
32 #include <svx/weldeditview.hxx>
34 namespace com::sun::star::accessibility
{ class XAccessible
; }
37 class ScAccessibleEditLineTextData
;
38 class ScAccessibleEditObject
;
39 class ScEditEngineDefaulter
;
41 class ScInputBarGroup
;
49 virtual void InsertAccessibleTextData( ScAccessibleEditLineTextData
& rTextData
) = 0;
50 virtual void RemoveAccessibleTextData( ScAccessibleEditLineTextData
& rTextData
) = 0;
51 virtual void SetTextString( const OUString
& rString
, bool bKitUpdate
) = 0;
52 virtual const OUString
& GetTextString() const = 0;
53 virtual void StartEditEngine() = 0;
54 virtual void StopEditEngine( bool bAll
) = 0;
55 virtual EditView
* GetEditView() const = 0;
56 virtual bool HasEditView() const = 0;
57 virtual void MakeDialogEditView() = 0;
58 virtual void SetFormulaMode( bool bSet
) = 0;
59 virtual bool IsInputActive() = 0;
60 virtual void TextGrabFocus() = 0;
61 virtual tools::Long
GetNumLines() const = 0;
62 virtual ~ScTextWndBase() {}
65 class ScTextWnd
: public WeldEditView
66 , public ScTextWndBase
69 ScTextWnd(ScTextWndGroup
& rParent
, ScTabViewShell
* pViewSh
);
70 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
71 virtual ~ScTextWnd() override
;
73 virtual void SetTextString( const OUString
& rString
, bool bKitUpdate
) override
;
74 virtual const OUString
& GetTextString() const override
;
76 bool IsInputActive() override
;
77 virtual EditView
* GetEditView() const override
;
78 virtual bool HasEditView() const override
;
80 const OutputDevice
& GetEditViewDevice() const;
82 // for function autopilots
83 virtual void MakeDialogEditView() override
;
85 virtual void StartEditEngine() override
;
86 virtual void StopEditEngine( bool bAll
) override
;
88 virtual void TextGrabFocus() override
;
90 virtual void StyleUpdated() override
;
92 // Triggered if scroll bar state should change
93 virtual void EditViewScrollStateChange() override
;
95 virtual void SetFormulaMode( bool bSet
) override
;
97 virtual css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessible() override
;
99 virtual void InsertAccessibleTextData( ScAccessibleEditLineTextData
& rTextData
) override
;
100 virtual void RemoveAccessibleTextData( ScAccessibleEditLineTextData
& rTextData
) override
;
102 virtual void Resize() override
;
104 int GetPixelHeightForLines(tools::Long nLines
);
105 int GetEditEngTxtHeight() const;
107 virtual tools::Long
GetNumLines() const override
;
108 void SetNumLines(tools::Long nLines
);
109 tools::Long
GetLastNumExpandedLines() const { return mnLastExpandedLines
; }
110 void SetLastNumExpandedLines(tools::Long nLastExpandedLines
) { mnLastExpandedLines
= nLastExpandedLines
; }
114 DECL_LINK(ModifyHdl
, LinkParamNone
*, void);
115 DECL_LINK(EditStatusHdl
, EditStatus
&, void);
118 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
120 virtual bool MouseMove( const MouseEvent
& rMEvt
) override
;
121 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
122 virtual bool MouseButtonUp( const MouseEvent
& rMEvt
) override
;
123 virtual bool Command( const CommandEvent
& rCEvt
) override
;
124 virtual bool KeyInput(const KeyEvent
& rKEvt
) override
;
125 virtual bool CanFocus() const override
;
126 virtual void GetFocus() override
;
128 virtual bool StartDrag() override
;
131 void ImplInitSettings();
132 void UpdateAutoCorrFlag();
134 void SetScrollBarRange();
136 void InitEditEngine();
140 rtl::Reference
<svt::OStringTransferable
> m_xHelper
;
142 typedef ::std::vector
< ScAccessibleEditLineTextData
* > AccTextDataVector
;
144 rtl::Reference
<ScAccessibleEditObject
> pAcc
;
148 AccTextDataVector maAccTextDatas
; // #i105267# text data may be cloned, remember all copies
153 // #102710#; this flag should be true if a key input or a command is handled
154 // it prevents the call of InputChanged in the ModifyHandler of the EditEngine
157 ScTabViewShell
* mpViewShell
;
158 ScTextWndGroup
& mrGroupBar
;
159 tools::Long mnLastExpandedLines
;
163 class ScPosWnd final
: public InterimItemWindow
, public SfxListener
// Display position
166 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
168 ImplSVEvent
* m_nAsyncGetFocusId
;
175 ScPosWnd( vcl::Window
* pParent
);
176 virtual ~ScPosWnd() override
;
177 virtual void dispose() override
;
179 void SetPos( const OUString
& rPosStr
); // Displayed Text
180 void SetFormulaMode( bool bSet
);
182 static OUString
createLocalRangeName(std::u16string_view rName
, std::u16string_view rTableName
);
185 DECL_LINK(OnAsyncGetFocus
, void*, void);
186 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
187 DECL_LINK(ActivateHdl
, weld::ComboBox
&, bool);
188 DECL_LINK(ModifyHdl
, weld::ComboBox
&, void);
189 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
190 DECL_LINK(FocusOutHdl
, weld::Widget
&, void);
192 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
195 void FillRangeNames();
196 void FillFunctions();
200 void ReleaseFocus_Impl();
203 class ScTextWndGroup
: public ScTextWndBase
206 ScTextWndGroup(ScInputBarGroup
& pParent
, ScTabViewShell
* pViewSh
);
207 virtual ~ScTextWndGroup() override
;
209 virtual void InsertAccessibleTextData(ScAccessibleEditLineTextData
& rTextData
) override
;
210 virtual EditView
* GetEditView() const override
;
211 const OutputDevice
& GetEditViewDevice() const;
212 Point
GetCursorScreenPixelPos(bool bBelowLine
);
213 tools::Long
GetLastNumExpandedLines() const;
214 void SetLastNumExpandedLines(tools::Long nLastExpandedLines
);
215 virtual tools::Long
GetNumLines() const override
;
216 int GetPixelHeightForLines(tools::Long nLines
);
217 weld::ScrolledWindow
& GetScrollWin();
218 virtual const OUString
& GetTextString() const override
;
219 virtual bool HasEditView() const override
;
220 virtual bool IsInputActive() override
;
221 virtual void MakeDialogEditView() override
;
222 virtual void RemoveAccessibleTextData(ScAccessibleEditLineTextData
& rTextData
) override
;
223 void SetScrollPolicy();
224 void SetNumLines(tools::Long nLines
);
225 virtual void SetFormulaMode(bool bSet
) override
;
226 virtual void SetTextString(const OUString
& rString
, bool bKitUpdate
) override
;
227 virtual void StartEditEngine() override
;
228 virtual void StopEditEngine(bool bAll
) override
;
229 virtual void TextGrabFocus() override
;
231 vcl::Window
& GetVclParent() { return mrParent
; }
234 std::unique_ptr
<ScTextWnd
> mxTextWnd
;
235 std::unique_ptr
<weld::ScrolledWindow
> mxScrollWin
;
236 std::unique_ptr
<weld::CustomWeld
> mxTextWndWin
;
237 vcl::Window
& mrParent
;
239 DECL_LINK(Impl_ScrollHdl
, weld::ScrolledWindow
&, void);
242 class ScInputBarGroup
: public InterimItemWindow
243 , public ScTextWndBase
246 ScInputBarGroup(vcl::Window
* Parent
, ScTabViewShell
* pViewSh
);
247 virtual ~ScInputBarGroup() override
;
248 virtual void dispose() override
;
249 virtual void InsertAccessibleTextData(ScAccessibleEditLineTextData
& rTextData
) override
;
250 virtual void RemoveAccessibleTextData(ScAccessibleEditLineTextData
& rTextData
) override
;
251 void SetTextString(const OUString
& rString
, bool bKitUpdate
) override
;
252 void StartEditEngine() override
;
253 virtual EditView
* GetEditView() const override
;
254 virtual bool HasEditView() const override
;
255 Point
GetCursorScreenPixelPos(bool bBelowLine
);
256 virtual void Resize() override
;
257 virtual void DataChanged(const DataChangedEvent
& rDCEvt
) override
;
258 virtual const OUString
& GetTextString() const override
;
259 virtual void StopEditEngine(bool bAll
) override
;
260 virtual void TextGrabFocus() override
;
261 void SetFormulaMode(bool bSet
) override
;
262 void MakeDialogEditView() override
;
263 bool IsInputActive() override
;
264 void IncrementVerticalSize();
265 void DecrementVerticalSize();
266 void NumLinesChanged();
267 virtual tools::Long
GetNumLines() const override
{ return mxTextWndGroup
->GetNumLines(); }
269 int GetPixelHeightForLines(tools::Long nLines
) const
271 return mxTextWndGroup
->GetPixelHeightForLines(nLines
);
274 weld::Builder
& GetBuilder() { return *m_xBuilder
; }
277 void TriggerToolboxLayout();
278 void SetBackgrounds();
280 std::unique_ptr
<weld::Container
> mxBackground
;
281 std::unique_ptr
<ScTextWndGroup
> mxTextWndGroup
;
282 std::unique_ptr
<weld::Button
> mxButtonUp
;
283 std::unique_ptr
<weld::Button
> mxButtonDown
;
285 DECL_LINK(ClickHdl
, weld::Button
&, void);
288 class ScInputWindow final
: public ToolBox
// Parent toolbox
291 ScInputWindow( vcl::Window
* pParent
, const SfxBindings
* pBind
);
292 virtual ~ScInputWindow() override
;
293 virtual void dispose() override
;
295 virtual void PixelInvalidate(const tools::Rectangle
* pRectangle
) override
;
296 virtual void SetSizePixel( const Size
& rNewSize
) override
;
297 virtual void Resize() override
;
298 virtual void Select() override
;
300 void SetFuncString( const OUString
& rString
, bool bDoEdit
= true );
301 void SetPosString( const OUString
& rStr
);
302 void SetTextString(const OUString
& rString
, bool bKitUpdate
);
304 void SetOkCancelMode();
305 void SetSumAssignMode();
306 void EnableButtons( bool bEnable
);
307 /// Update Input bar after the number of lines was changed externally
308 void NumLinesChanged();
311 void SetFormulaMode( bool bSet
);
313 bool IsInputActive();
314 EditView
* GetEditView();
315 vcl::Window
* GetEditWindow();
316 Point
GetCursorScreenPixelPos(bool bBelowLine
= false);
318 void TextGrabFocus();
319 void TextInvalidate();
320 void SwitchToTextWin();
324 // For function autopilots
325 void MakeDialogEditView();
327 void StopEditEngine( bool bAll
);
329 void SetInputHandler( ScInputHandler
* pNew
);
331 ScInputHandler
* GetInputHandler(){ return pInputHdl
;}
333 void StateChanged( StateChangedType nType
) override
;
334 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
335 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
336 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
337 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
339 void NotifyLOKClient();
341 void MenuHdl(std::u16string_view command
);
342 DECL_LINK( DropdownClickHdl
, ToolBox
*, void );
344 void AutoSum( bool& bRangeFinder
, bool& bSubTotal
, OpCode eCode
);
347 bool IsPointerAtResizePos();
349 VclPtr
<ScPosWnd
> aWndPos
;
350 VclPtr
<ScInputBarGroup
> mxTextWindow
;
351 ScInputHandler
* pInputHdl
;
352 ScTabViewShell
* mpViewShell
;
354 tools::Long mnStandardItemHeight
;
355 bool bIsOkCancelMode
;
359 class ScInputWindowWrapper
: public SfxChildWindow
362 ScInputWindowWrapper( vcl::Window
* pParent
,
364 SfxBindings
* pBindings
,
365 SfxChildWinInfo
* pInfo
);
367 SFX_DECL_CHILDWINDOW_WITHID(ScInputWindowWrapper
);
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */