tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / inputwin.hxx
blobd98b5a85c56fa1d1534dc0769fb0b3c199627fcd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <vector>
23 #include <memory>
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; }
36 class EditView;
37 class ScAccessibleEditLineTextData;
38 class ScAccessibleEditObject;
39 class ScEditEngineDefaulter;
40 class ScTextWndGroup;
41 class ScInputBarGroup;
42 class ScInputHandler;
43 class ScTabViewShell;
44 struct EENotify;
46 class ScTextWndBase
48 public:
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
68 public:
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; }
112 void DoScroll();
114 DECL_LINK(ModifyHdl, LinkParamNone*, void);
115 DECL_LINK(EditStatusHdl, EditStatus&, void);
117 protected:
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;
130 private:
131 void ImplInitSettings();
132 void UpdateAutoCorrFlag();
134 void SetScrollBarRange();
136 void InitEditEngine();
138 void UpdateFocus();
140 rtl::Reference<svt::OStringTransferable> m_xHelper;
142 typedef ::std::vector< ScAccessibleEditLineTextData* > AccTextDataVector;
144 rtl::Reference<ScAccessibleEditObject> pAcc;
146 OUString aString;
147 vcl::Font aTextFont;
148 AccTextDataVector maAccTextDatas; // #i105267# text data may be cloned, remember all copies
149 bool bIsRTL;
150 bool bIsInsertMode;
151 bool bFormulaMode;
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
155 bool bInputMode;
157 ScTabViewShell* mpViewShell;
158 ScTextWndGroup& mrGroupBar;
159 tools::Long mnLastExpandedLines;
160 bool mbInvalidate;
163 class ScPosWnd final : public InterimItemWindow, public SfxListener // Display position
165 private:
166 std::unique_ptr<weld::ComboBox> m_xWidget;
168 ImplSVEvent* m_nAsyncGetFocusId;
170 OUString aPosStr;
171 void* nTipVisible;
172 bool bFormulaMode;
174 public:
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);
184 private:
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;
194 private:
195 void FillRangeNames();
196 void FillFunctions();
197 void DoEnter();
198 void HideTip();
200 void ReleaseFocus_Impl();
203 class ScTextWndGroup : public ScTextWndBase
205 public:
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; }
233 private:
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
245 public:
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; }
276 private:
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
290 public:
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();
310 void StartFormula();
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();
322 void PosGrabFocus();
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 );
346 private:
347 bool IsPointerAtResizePos();
349 VclPtr<ScPosWnd> aWndPos;
350 VclPtr<ScInputBarGroup> mxTextWindow;
351 ScInputHandler* pInputHdl;
352 ScTabViewShell* mpViewShell;
353 tools::Long mnMaxY;
354 tools::Long mnStandardItemHeight;
355 bool bIsOkCancelMode;
356 bool bInResize;
359 class ScInputWindowWrapper : public SfxChildWindow
361 public:
362 ScInputWindowWrapper( vcl::Window* pParent,
363 sal_uInt16 nId,
364 SfxBindings* pBindings,
365 SfxChildWinInfo* pInfo );
367 SFX_DECL_CHILDWINDOW_WITHID(ScInputWindowWrapper);
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */