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:
42 
43  SAL_DLLPRIVATE void ImplInitControlData();
44 
45  Control (const Control &) = delete;
46  Control & operator= (const Control &) = delete;
47 
48 protected:
49  Control( WindowType nType );
50  virtual void FillLayoutData() const;
51 
52  // helper method for composite controls
53  void AppendLayoutData( const Control& rSubControl ) const;
54 
56  void CreateLayoutData() const;
58  bool HasLayoutData() const;
59 
72  bool ImplCallEventListenersAndHandler(
73  VclEventId nEvent, std::function<void()> const & callHandler
74  );
75 
76  void CallEventListeners( VclEventId nEvent, void* pData = nullptr );
77 
87  tools::Rectangle DrawControlText( OutputDevice& _rTargetDevice, const tools::Rectangle& _rRect,
88  const OUString& _rStr, DrawTextFlags _nStyle,
89  MetricVector* _pVector, OUString* _pDisplayText,
90  const Size* i_pDeviceSize = nullptr ) const;
91 
92  tools::Rectangle GetControlTextRect( OutputDevice& _rTargetDevice, const tools::Rectangle & rRect,
93  const OUString& _rStr, DrawTextFlags _nStyle,
94  Size* o_pDeviceSize = nullptr ) const;
95 
96  virtual const vcl::Font&
97  GetCanonicalFont( const StyleSettings& _rStyle ) const;
98  virtual const Color&
99  GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
100 
101  void ImplInitSettings();
102 
103  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
104 
105 public:
106  SAL_DLLPRIVATE void ImplClearLayoutData() const;
125  SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect );
126 
127 public:
128  explicit Control( vcl::Window* pParent, WinBits nWinStyle = 0 );
129  virtual ~Control() override;
130  virtual void dispose() override;
131 
132  virtual void EnableRTL ( bool bEnable = true ) override;
133 
134  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
135  virtual void StateChanged( StateChangedType nStateChange ) override;
136  virtual void Resize() override;
137 
138  // invalidates layout data
139  virtual void SetText( const OUString& rStr ) override;
140  // gets the displayed text
141  virtual OUString GetDisplayText() const override;
142  // returns the bounding box for the character at index nIndex (in control coordinates)
143  tools::Rectangle GetCharacterBounds( long nIndex ) const;
144  // returns the character index for corresponding to rPoint (in control coordinates)
145  // -1 is returned if no character is at that point
146  long GetIndexForPoint( const Point& rPoint ) const;
147  // returns the interval [start,end] of line nLine
148  // returns [-1,-1] for an invalid line
149  Pair GetLineStartEnd( long nLine ) const;
162  long ToRelativeLineIndex( long nIndex ) const;
163 
164  void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; }
165 
168  bool HasControlFocus() const { return mbHasControlFocus; }
169 
170  void SetLayoutDataParent( const Control* pParent ) const;
171 
172  virtual Size GetOptimalSize() const override;
173 
177  void SetReferenceDevice( OutputDevice* _referenceDevice );
178  OutputDevice* GetReferenceDevice() const;
179 
180  vcl::Font GetUnzoomedControlPointFont() const;
181  void SetShowAccelerator (bool val);
182 };
183 
184 #endif // INCLUDED_VCL_CTRL_HXX
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetText(const OUString &rStr)
Definition: window.cxx:3056
std::vector< tools::Rectangle > MetricVector
Definition: outdev.hxx:137
#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:145
StateChangedType
Definition: window.hxx:310
sal_Int64 WinBits
VclEventId
Definition: vclevent.hxx:37
virtual OUString GetDisplayText() const
Definition: window.cxx:3091
bool mbShowAccelerator
Definition: ctrl.hxx:40
Link< Control &, void > maLoseFocusHdl
Definition: ctrl.hxx:41
virtual bool EventNotify(NotifyEvent &rNEvt)
Definition: event.cxx:103
bool mbHasControlFocus
Definition: ctrl.hxx:39
virtual void ApplySettings(vcl::RenderContext &rRenderContext)
Definition: window.cxx:3826
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
virtual void Resize()
Definition: window.cxx:1830
DrawTextFlags
Definition: outdev.hxx:142
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:164
virtual void EnableRTL(bool bEnable=true) override
bool HasControlFocus() const
determines whether the control currently has the focus
Definition: ctrl.hxx:168
virtual void StateChanged(StateChangedType nStateChange)
Definition: window.cxx:1935
OutputDevice & operator=(const OutputDevice &)=delete
void CallEventListeners(VclEventId nEvent, void *pData=nullptr)
Definition: event.cxx:217