LibreOffice Module vcl (master)  1
ctrl.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_VCL_CTRL_HXX
21 #define INCLUDED_VCL_CTRL_HXX
22 
23 #include <tools/link.hxx>
24 #include <vcl/dllapi.h>
25 #include <vcl/window.hxx>
26 #include <memory>
27 
28 // forward
29 namespace vcl { struct ImplControlData; }
30 class StyleSettings;
31 
32 
34 {
35 protected:
36  std::unique_ptr<vcl::ImplControlData> mpControlData;
37 
38 private:
43 
44  SAL_DLLPRIVATE void ImplInitControlData();
45 
46  Control (const Control &) = delete;
47  Control & operator= (const Control &) = delete;
48 
49 protected:
50  Control( WindowType nType );
51  virtual void FillLayoutData() const;
52 
53  // helper method for composite controls
54  void AppendLayoutData( const Control& rSubControl ) const;
55 
57  void CreateLayoutData() const;
59  bool HasLayoutData() const;
60 
73  bool ImplCallEventListenersAndHandler(
74  VclEventId nEvent, std::function<void()> const & callHandler
75  );
76 
77  void CallEventListeners( VclEventId nEvent, void* pData = nullptr );
78 
88  tools::Rectangle DrawControlText( OutputDevice& _rTargetDevice, const tools::Rectangle& _rRect,
89  const OUString& _rStr, DrawTextFlags _nStyle,
90  MetricVector* _pVector, OUString* _pDisplayText,
91  const Size* i_pDeviceSize = nullptr ) const;
92 
93  tools::Rectangle GetControlTextRect( OutputDevice& _rTargetDevice, const tools::Rectangle & rRect,
94  const OUString& _rStr, DrawTextFlags _nStyle,
95  Size* o_pDeviceSize = nullptr ) const;
96 
97  virtual const vcl::Font&
98  GetCanonicalFont( const StyleSettings& _rStyle ) const;
99  virtual const Color&
100  GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
101 
102  void ImplInitSettings();
103 
104  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
105 
106 public:
107  SAL_DLLPRIVATE void ImplClearLayoutData() const;
126  SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect );
127 
128 public:
129  explicit Control( vcl::Window* pParent, WinBits nWinStyle = 0 );
130  virtual ~Control() override;
131  virtual void dispose() override;
132 
133  virtual void EnableRTL ( bool bEnable = true ) override;
134 
135  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
136  virtual void StateChanged( StateChangedType nStateChange ) override;
137  virtual void Resize() override;
138 
139  // invalidates layout data
140  virtual void SetText( const OUString& rStr ) override;
141  // gets the displayed text
142  virtual OUString GetDisplayText() const override;
143  // returns the bounding box for the character at index nIndex (in control coordinates)
144  tools::Rectangle GetCharacterBounds( long nIndex ) const;
145  // returns the character index for corresponding to rPoint (in control coordinates)
146  // -1 is returned if no character is at that point
147  long GetIndexForPoint( const Point& rPoint ) const;
148  // returns the interval [start,end] of line nLine
149  // returns [-1,-1] for an invalid line
150  Pair GetLineStartEnd( long nLine ) const;
163  long ToRelativeLineIndex( long nIndex ) const;
164 
165  void SetGetFocusHdl( const Link<Control&,void>& rLink ) { maGetFocusHdl = rLink; }
166  void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; }
167 
170  bool HasControlFocus() const { return mbHasControlFocus; }
171 
172  void SetLayoutDataParent( const Control* pParent ) const;
173 
174  virtual Size GetOptimalSize() const override;
175 
179  void SetReferenceDevice( OutputDevice* _referenceDevice );
180  OutputDevice* GetReferenceDevice() const;
181 
182  vcl::Font GetUnzoomedControlPointFont() const;
183  void SetShowAccelerator (bool val);
184 };
185 
186 #endif // INCLUDED_VCL_CTRL_HXX
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetText(const OUString &rStr)
Definition: window.cxx:3031
std::vector< tools::Rectangle > MetricVector
Definition: outdev.hxx:139
Link< Control &, void > maGetFocusHdl
Definition: ctrl.hxx:41
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
virtual Size GetOptimalSize() const
Definition: window3.cxx:33
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: window.cxx:142
StateChangedType
Definition: window.hxx:311
sal_Int64 WinBits
VclEventId
Definition: vclevent.hxx:41
virtual OUString GetDisplayText() const
Definition: window.cxx:3066
bool mbShowAccelerator
Definition: ctrl.hxx:40
Link< Control &, void > maLoseFocusHdl
Definition: ctrl.hxx:42
virtual bool EventNotify(NotifyEvent &rNEvt)
Definition: event.cxx:103
bool mbHasControlFocus
Definition: ctrl.hxx:39
virtual void ApplySettings(vcl::RenderContext &rRenderContext)
Definition: window.cxx:3805
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
virtual void Resize()
Definition: window.cxx:1799
DrawTextFlags
Definition: outdev.hxx:144
WindowType
Definition: ctrl.hxx:33
std::unique_ptr< vcl::ImplControlData > mpControlData
Definition: ctrl.hxx:36
void SetLoseFocusHdl(const Link< Control &, void > &rLink)
Definition: ctrl.hxx:166
virtual void EnableRTL(bool bEnable=true) override
bool HasControlFocus() const
determines whether the control currently has the focus
Definition: ctrl.hxx:170
virtual void StateChanged(StateChangedType nStateChange)
Definition: window.cxx:1904
OutputDevice & operator=(const OutputDevice &)=delete
void SetGetFocusHdl(const Link< Control &, void > &rLink)
Definition: ctrl.hxx:165
void CallEventListeners(VclEventId nEvent, void *pData=nullptr)
Definition: event.cxx:213