/src/libreoffice/sc/source/ui/inc/inputwin.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <set> |
23 | | #include <vector> |
24 | | #include <memory> |
25 | | #include <vcl/customweld.hxx> |
26 | | #include <vcl/toolbox.hxx> |
27 | | #include <vcl/InterimItemWindow.hxx> |
28 | | #include <sfx2/childwin.hxx> |
29 | | #include <svl/lstner.hxx> |
30 | | #include <svtools/stringtransfer.hxx> |
31 | | #include <vcl/window.hxx> |
32 | | #include <formula/opcode.hxx> |
33 | | #include <svx/weldeditview.hxx> |
34 | | #include "inputhdl.hxx" |
35 | | |
36 | | class EditView; |
37 | | class ScAccessibleEditLineTextData; |
38 | | class ScAccessibleEditObject; |
39 | | class ScTextWndGroup; |
40 | | class ScInputBarGroup; |
41 | | class ScTabViewShell; |
42 | | |
43 | | class ScTextWndBase |
44 | | { |
45 | | public: |
46 | | virtual void InsertAccessibleTextData( ScAccessibleEditLineTextData& rTextData ) = 0; |
47 | | virtual void RemoveAccessibleTextData( ScAccessibleEditLineTextData& rTextData ) = 0; |
48 | | virtual void SetTextString( const OUString& rString, bool bKitUpdate ) = 0; |
49 | | virtual const OUString& GetTextString() const = 0; |
50 | | virtual void StartEditEngine(const ErrorHdl& errorHdl) = 0; |
51 | | virtual void StopEditEngine( bool bAll ) = 0; |
52 | | virtual EditView* GetEditView() const = 0; |
53 | | virtual bool HasEditView() const = 0; |
54 | | virtual void MakeDialogEditView() = 0; |
55 | | virtual void SetFormulaMode( bool bSet ) = 0; |
56 | | virtual bool IsInputActive() = 0; |
57 | | virtual void TextGrabFocus() = 0; |
58 | | virtual tools::Long GetNumLines() const = 0; |
59 | 0 | virtual ~ScTextWndBase() {} |
60 | | }; |
61 | | |
62 | | class ScTextWnd : public WeldEditView |
63 | | , public ScTextWndBase |
64 | | { |
65 | | public: |
66 | | ScTextWnd(ScTextWndGroup& rParent, ScTabViewShell* pViewSh); |
67 | | virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; |
68 | | virtual ~ScTextWnd() override; |
69 | | |
70 | | virtual void SetTextString( const OUString& rString, bool bKitUpdate ) override; |
71 | | virtual const OUString& GetTextString() const override; |
72 | | |
73 | | bool IsInputActive() override; |
74 | | virtual EditView* GetEditView() const override; |
75 | | virtual bool HasEditView() const override; |
76 | | |
77 | | const OutputDevice& GetEditViewDevice() const; |
78 | | |
79 | | // for function autopilots |
80 | | virtual void MakeDialogEditView() override; |
81 | | |
82 | | virtual void StartEditEngine(const ErrorHdl& errorHdl) override; |
83 | | virtual void StopEditEngine( bool bAll ) override; |
84 | | |
85 | | virtual void TextGrabFocus() override; |
86 | | |
87 | | virtual void StyleUpdated() override; |
88 | | |
89 | | // Triggered if scroll bar state should change |
90 | | virtual void EditViewScrollStateChange() override; |
91 | | |
92 | | virtual void SetFormulaMode( bool bSet ) override; |
93 | | |
94 | | virtual rtl::Reference<comphelper::OAccessible> CreateAccessible() override; |
95 | | |
96 | | virtual void InsertAccessibleTextData( ScAccessibleEditLineTextData& rTextData ) override; |
97 | | virtual void RemoveAccessibleTextData( ScAccessibleEditLineTextData& rTextData ) override; |
98 | | |
99 | | virtual void Resize() override; |
100 | | |
101 | | int GetPixelHeightForLines(tools::Long nLines); |
102 | | int GetEditEngTxtHeight() const; |
103 | | |
104 | | virtual tools::Long GetNumLines() const override; |
105 | | void SetNumLines(tools::Long nLines); |
106 | 0 | tools::Long GetLastNumExpandedLines() const { return mnLastExpandedLines; } |
107 | 0 | void SetLastNumExpandedLines(tools::Long nLastExpandedLines) { mnLastExpandedLines = nLastExpandedLines; } |
108 | | |
109 | | void DoScroll(); |
110 | | |
111 | | DECL_LINK(ModifyHdl, LinkParamNone*, void); |
112 | | DECL_LINK(EditStatusHdl, EditStatus&, void); |
113 | | |
114 | | protected: |
115 | | virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; |
116 | | |
117 | | virtual bool MouseMove( const MouseEvent& rMEvt ) override; |
118 | | virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override; |
119 | | virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override; |
120 | | virtual bool Command( const CommandEvent& rCEvt ) override; |
121 | | virtual bool KeyInput(const KeyEvent& rKEvt) override; |
122 | | virtual bool CanFocus() const override; |
123 | | virtual void GetFocus() override; |
124 | | |
125 | | virtual bool StartDrag() override; |
126 | | |
127 | | private: |
128 | | void ImplInitSettings(); |
129 | | void UpdateAutoCorrFlag(); |
130 | | |
131 | | void SetScrollBarRange(); |
132 | | |
133 | | void InitEditEngine(); |
134 | | |
135 | | void UpdateFocus(const ErrorHdl& errorHdl); |
136 | | |
137 | | rtl::Reference<svt::OStringTransferable> m_xHelper; |
138 | | |
139 | | typedef ::std::vector< ScAccessibleEditLineTextData* > AccTextDataVector; |
140 | | |
141 | | rtl::Reference<ScAccessibleEditObject> pAcc; |
142 | | |
143 | | OUString aString; |
144 | | vcl::Font aTextFont; |
145 | | AccTextDataVector maAccTextDatas; // #i105267# text data may be cloned, remember all copies |
146 | | bool bIsRTL; |
147 | | bool bIsInsertMode; |
148 | | bool bFormulaMode; |
149 | | |
150 | | // #102710#; this flag should be true if a key input or a command is handled |
151 | | // it prevents the call of InputChanged in the ModifyHandler of the EditEngine |
152 | | bool bInputMode; |
153 | | |
154 | | ScTabViewShell* mpViewShell; |
155 | | ScTextWndGroup& mrGroupBar; |
156 | | tools::Long mnLastExpandedLines; |
157 | | bool mbInvalidate; |
158 | | }; |
159 | | |
160 | | class ScPosWnd final : public InterimItemWindow, public SfxListener // Display position |
161 | | { |
162 | | private: |
163 | | std::unique_ptr<weld::ComboBox> m_xWidget; |
164 | | |
165 | | ImplSVEvent* m_nAsyncGetFocusId; |
166 | | |
167 | | OUString aPosStr; |
168 | | void* nTipVisible; |
169 | | bool bFormulaMode; |
170 | | std::set<OUString> aRangeNames; |
171 | | |
172 | | public: |
173 | | ScPosWnd(vcl::Window* pParent, ScTabViewShell* pViewSh); |
174 | | virtual ~ScPosWnd() override; |
175 | | virtual void dispose() override; |
176 | | |
177 | | void SetPos( const OUString& rPosStr ); // Displayed Text |
178 | | void SetFormulaMode( bool bSet ); |
179 | | |
180 | | static OUString createLocalRangeName(std::u16string_view rName, std::u16string_view rTableName); |
181 | | |
182 | | private: |
183 | | DECL_LINK(OnAsyncGetFocus, void*, void); |
184 | | DECL_LINK(KeyInputHdl, const KeyEvent&, bool); |
185 | | DECL_LINK(ActivateHdl, weld::ComboBox&, bool); |
186 | | DECL_LINK(ModifyHdl, weld::ComboBox&, void); |
187 | | DECL_LINK(FocusInHdl, weld::Widget&, void); |
188 | | DECL_LINK(FocusOutHdl, weld::Widget&, void); |
189 | | |
190 | | virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; |
191 | | |
192 | | private: |
193 | | void FillRangeNames(bool initialize = false); |
194 | | void FillFunctions(); |
195 | | void DoEnter(); |
196 | | void HideTip(); |
197 | | |
198 | | void ReleaseFocus_Impl(); |
199 | | }; |
200 | | |
201 | | class ScTextWndGroup : public ScTextWndBase |
202 | | { |
203 | | public: |
204 | | ScTextWndGroup(ScInputBarGroup& pParent, ScTabViewShell* pViewSh); |
205 | | virtual ~ScTextWndGroup() override; |
206 | | |
207 | | virtual void InsertAccessibleTextData(ScAccessibleEditLineTextData& rTextData) override; |
208 | | virtual EditView* GetEditView() const override; |
209 | | const OutputDevice& GetEditViewDevice() const; |
210 | | Point GetCursorScreenPixelPos(bool bBelowLine); |
211 | | tools::Long GetLastNumExpandedLines() const; |
212 | | void SetLastNumExpandedLines(tools::Long nLastExpandedLines); |
213 | | virtual tools::Long GetNumLines() const override; |
214 | | int GetPixelHeightForLines(tools::Long nLines); |
215 | | weld::ScrolledWindow& GetScrollWin(); |
216 | | virtual const OUString& GetTextString() const override; |
217 | | virtual bool HasEditView() const override; |
218 | | virtual bool IsInputActive() override; |
219 | | virtual void MakeDialogEditView() override; |
220 | | virtual void RemoveAccessibleTextData(ScAccessibleEditLineTextData& rTextData) override; |
221 | | void SetScrollPolicy(); |
222 | | void SetNumLines(tools::Long nLines); |
223 | | virtual void SetFormulaMode(bool bSet) override; |
224 | | virtual void SetTextString(const OUString& rString, bool bKitUpdate) override; |
225 | | virtual void StartEditEngine(const ErrorHdl& errorHdl) override; |
226 | | virtual void StopEditEngine(bool bAll) override; |
227 | | virtual void TextGrabFocus() override; |
228 | | |
229 | 0 | vcl::Window& GetVclParent() { return mrParent; } |
230 | | |
231 | | private: |
232 | | std::unique_ptr<ScTextWnd> mxTextWnd; |
233 | | std::unique_ptr<weld::ScrolledWindow> mxScrollWin; |
234 | | std::unique_ptr<weld::CustomWeld> mxTextWndWin; |
235 | | vcl::Window& mrParent; |
236 | | |
237 | | DECL_LINK(Impl_ScrollHdl, weld::ScrolledWindow&, void); |
238 | | }; |
239 | | |
240 | | class ScInputBarGroup : public InterimItemWindow |
241 | | , public ScTextWndBase |
242 | | { |
243 | | public: |
244 | | ScInputBarGroup(vcl::Window* Parent, ScTabViewShell* pViewSh); |
245 | | virtual ~ScInputBarGroup() override; |
246 | | virtual void dispose() override; |
247 | | virtual void InsertAccessibleTextData(ScAccessibleEditLineTextData& rTextData) override; |
248 | | virtual void RemoveAccessibleTextData(ScAccessibleEditLineTextData& rTextData) override; |
249 | | void SetTextString(const OUString& rString, bool bKitUpdate) override; |
250 | | void StartEditEngine(const ErrorHdl& errorHdl) override; |
251 | | virtual EditView* GetEditView() const override; |
252 | | virtual bool HasEditView() const override; |
253 | | Point GetCursorScreenPixelPos(bool bBelowLine); |
254 | | virtual void Resize() override; |
255 | | virtual void DataChanged(const DataChangedEvent& rDCEvt) override; |
256 | | virtual const OUString& GetTextString() const override; |
257 | | virtual void StopEditEngine(bool bAll) override; |
258 | | virtual void TextGrabFocus() override; |
259 | | void SetFormulaMode(bool bSet) override; |
260 | | void MakeDialogEditView() override; |
261 | | bool IsInputActive() override; |
262 | | void IncrementVerticalSize(); |
263 | | void DecrementVerticalSize(); |
264 | | void NumLinesChanged(); |
265 | 0 | virtual tools::Long GetNumLines() const override { return mxTextWndGroup->GetNumLines(); } |
266 | | |
267 | | int GetPixelHeightForLines(tools::Long nLines) const |
268 | 0 | { |
269 | 0 | return mxTextWndGroup->GetPixelHeightForLines(nLines); |
270 | 0 | } |
271 | | |
272 | 0 | weld::Builder& GetBuilder() { return *m_xBuilder; } |
273 | | |
274 | | private: |
275 | | void TriggerToolboxLayout(); |
276 | | void SetBackgrounds(); |
277 | | |
278 | | std::unique_ptr<weld::Container> mxBackground; |
279 | | std::unique_ptr<ScTextWndGroup> mxTextWndGroup; |
280 | | std::unique_ptr<weld::Button> mxButtonUp; |
281 | | std::unique_ptr<weld::Button> mxButtonDown; |
282 | | |
283 | | DECL_LINK(ClickHdl, weld::Button&, void); |
284 | | }; |
285 | | |
286 | | class ScInputWindow final : public ToolBox // Parent toolbox |
287 | | { |
288 | | public: |
289 | | ScInputWindow( vcl::Window* pParent, const SfxBindings* pBind ); |
290 | | virtual ~ScInputWindow() override; |
291 | | virtual void dispose() override; |
292 | | |
293 | | virtual void PixelInvalidate(const tools::Rectangle* pRectangle) override; |
294 | | virtual void SetSizePixel( const Size& rNewSize ) override; |
295 | | virtual void Resize() override; |
296 | | virtual void Select() override; |
297 | | |
298 | | void SetFuncString( const OUString& rString, bool bDoEdit = true ); |
299 | | void SetPosString( const OUString& rStr ); |
300 | | void SetTextString(const OUString& rString, bool bKitUpdate); |
301 | | |
302 | | void SetOkCancelMode(); |
303 | | void SetSumAssignMode(); |
304 | | void EnableButtons( bool bEnable ); |
305 | | /// Update Input bar after the number of lines was changed externally |
306 | | void NumLinesChanged(); |
307 | | |
308 | | void StartFormula(); |
309 | | void SetFormulaMode( bool bSet ); |
310 | | |
311 | | bool IsInputActive(); |
312 | | EditView* GetEditView(); |
313 | | vcl::Window* GetEditWindow(); |
314 | | Point GetCursorScreenPixelPos(bool bBelowLine = false); |
315 | | |
316 | | void TextGrabFocus(); |
317 | | void TextInvalidate(); |
318 | | void SwitchToTextWin(); |
319 | | |
320 | | void PosGrabFocus(); |
321 | | |
322 | | // For function autopilots |
323 | | void MakeDialogEditView(); |
324 | | |
325 | | void StopEditEngine( bool bAll ); |
326 | | |
327 | | void SetInputHandler( ScInputHandler* pNew ); |
328 | | |
329 | 0 | ScInputHandler* GetInputHandler(){ return pInputHdl;} |
330 | | |
331 | | void StateChanged( StateChangedType nType ) override; |
332 | | virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; |
333 | | virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; |
334 | | virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; |
335 | | virtual void MouseMove( const MouseEvent& rMEvt ) override; |
336 | | |
337 | | void NotifyLOKClient(); |
338 | | |
339 | | void MenuHdl(std::u16string_view command); |
340 | | DECL_LINK( DropdownClickHdl, ToolBox*, void ); |
341 | | |
342 | | void AutoSum( bool& bRangeFinder, bool& bSubTotal, OpCode eCode ); |
343 | | |
344 | | private: |
345 | | bool IsPointerAtResizePos(); |
346 | | |
347 | | VclPtr<ScPosWnd> aWndPos; |
348 | | VclPtr<ScInputBarGroup> mxTextWindow; |
349 | | ScInputHandler* pInputHdl; |
350 | | ScTabViewShell* mpViewShell; |
351 | | tools::Long mnMaxY; |
352 | | tools::Long mnStandardItemHeight; |
353 | | bool bIsOkCancelMode; |
354 | | bool bInResize; |
355 | | }; |
356 | | |
357 | | class ScInputWindowWrapper : public SfxChildWindow |
358 | | { |
359 | | public: |
360 | | ScInputWindowWrapper( vcl::Window* pParent, |
361 | | sal_uInt16 nId, |
362 | | SfxBindings* pBindings, |
363 | | SfxChildWinInfo* pInfo ); |
364 | | |
365 | | SFX_DECL_CHILDWINDOW_WITHID(ScInputWindowWrapper); |
366 | | }; |
367 | | |
368 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |