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 <com/sun/star/awt/XProgressMonitor.hpp>
23 #include <com/sun/star/awt/XButton.hpp>
24 #include <com/sun/star/awt/XLayoutConstrains.hpp>
25 #include <rtl/ref.hxx>
26 
27 #include <vector>
28 #include <memory>
29 
30 #include <basecontainercontrol.hxx>
31 
32 namespace com::sun::star::awt { class XFixedText; }
33 namespace com::sun::star::awt { class XControlModel; }
34 
35 namespace unocontrols {
36 
37 class ProgressBar;
38 
39 #define PROGRESSMONITOR_FREEBORDER                      10                                                      // border around and between the controls
40 #define PROGRESSMONITOR_DEFAULT_TOPIC                   ""
41 #define PROGRESSMONITOR_DEFAULT_TEXT                    ""
42 #define PROGRESSMONITOR_LINECOLOR_BRIGHT                sal_Int32(Color( 0xFF, 0xFF, 0xFF ))             // white
43 #define PROGRESSMONITOR_LINECOLOR_SHADOW                sal_Int32(Color( 0x00, 0x00, 0x00 ))             // black
44 #define PROGRESSMONITOR_DEFAULT_WIDTH                   350
45 #define PROGRESSMONITOR_DEFAULT_HEIGHT                  100
46 
47 /// Item of TextList
48 struct IMPL_TextlistItem
49 {
50     OUString sTopic;          /// Left site of textline in dialog
51     OUString sText;          /// Right site of textline in dialog
52 };
53 
54 class ProgressMonitor final : public css::awt::XLayoutConstrains
55                         , public css::awt::XButton
56                         , public css::awt::XProgressMonitor
57                         , public BaseContainerControl
58 {
59 public:
60     ProgressMonitor( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
61 
62     virtual ~ProgressMonitor() override;
63 
64     //  XInterface
65 
66     /**
67         @short      give answer, if interface is supported
68         @descr      The interfaces are searched by type.
69 
70         @seealso    XInterface
71 
72         @param      "rType" is the type of searched interface.
73 
74         @return     Any     information about found interface
75 
76         @onerror    A RuntimeException is thrown.
77     */
78 
79     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
80 
81     /**
82         @short      increment refcount
83         @seealso    XInterface
84         @seealso    release()
85         @onerror    A RuntimeException is thrown.
86     */
87 
88     virtual void SAL_CALL acquire() noexcept override;
89 
90     /**
91         @short      decrement refcount
92         @seealso    XInterface
93         @seealso    acquire()
94         @onerror    A RuntimeException is thrown.
95     */
96 
97     virtual void SAL_CALL release() noexcept override;
98 
99     //  XTypeProvider
100 
101     /**
102         @short      get information about supported interfaces
103         @seealso    XTypeProvider
104         @return     Sequence of types of all supported interfaces
105 
106         @onerror    A RuntimeException is thrown.
107     */
108 
109     virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
110 
111     //  XAggregation
112 
113     virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& aType ) override;
114 
115     //  XProgressMonitor
116 
117     /**
118         @short      add topic to dialog
119         @descr      Add a topic with a text in right textlist (used for FixedText-member).<BR>
120                     ( "beforeProgress" fix the right list ). The dialog metric is recalculated.
121 
122         @seealso    removeText(), updateText()
123 
124         @param      sTopic              Name of topic<BR>
125                                          [sTopic != "" && sTopic != NULL]
126         @param      sText               Value of topic<BR>
127                                          [sText != "" && sText != NULL]
128         @param      bbeforeProgress     Position of topic<BR>
129                                          [True => before progressbar / False => below progressbar]
130         @onerror    DEBUG   = Assertion<BR>
131                     RELEASE = nothing
132     */
133 
134     virtual void SAL_CALL addText(
135         const OUString& sTopic ,
136         const OUString& sText ,
137         sal_Bool bbeforeProgress
138     ) override;
139 
140     virtual void SAL_CALL removeText(
141         const OUString& sTopic ,
142         sal_Bool bbeforeProgress
143     ) override;
144 
145     virtual void SAL_CALL updateText(
146         const OUString&  sTopic ,
147         const OUString&  sText ,
148         sal_Bool bbeforeProgress
149     ) override;
150 
151     //  XProgressBar
152 
153     virtual void SAL_CALL setForegroundColor( sal_Int32 nColor ) override;
154 
155     virtual void SAL_CALL setBackgroundColor( sal_Int32 nColor ) override;
156 
157     virtual void SAL_CALL setValue( sal_Int32 nValue ) override;
158 
159     virtual void SAL_CALL setRange( sal_Int32   nMin    ,
160                                     sal_Int32   nMax    ) override;
161 
162     virtual sal_Int32 SAL_CALL getValue() override;
163 
164     //  XButton
165 
166     virtual void SAL_CALL addActionListener(
167         const css::uno::Reference< css::awt::XActionListener >& xListener
168     ) override;
169 
170     virtual void SAL_CALL removeActionListener(
171         const css::uno::Reference< css::awt::XActionListener >& xListener
172     ) override;
173 
174     virtual void SAL_CALL setLabel( const OUString& sLabel ) override;
175 
176     virtual void SAL_CALL setActionCommand( const OUString& sCommand ) override;
177 
178     //  XLayoutConstrains
179 
180     virtual css::awt::Size SAL_CALL getMinimumSize() override;
181 
182     virtual css::awt::Size SAL_CALL getPreferredSize() override;
183 
184     virtual css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override;
185 
186     //  XControl
187 
188     virtual void SAL_CALL createPeer(
189         const css::uno::Reference< css::awt::XToolkit     >& xToolkit ,
190         const css::uno::Reference< css::awt::XWindowPeer  >& xParent
191     ) override;
192 
193     virtual sal_Bool SAL_CALL setModel( const css::uno::Reference< css::awt::XControlModel >& xModel ) override;
194 
195     virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override;
196 
197     //  XComponent
198 
199     virtual void SAL_CALL dispose() override;
200 
201     //  XWindow
202 
203     virtual void SAL_CALL setPosSize(   sal_Int32   nX      ,
204                                         sal_Int32   nY      ,
205                                         sal_Int32   nWidth  ,
206                                         sal_Int32   nHeight ,
207                                         sal_Int16   nFlags  ) override;
208 
209 private:
210     virtual void impl_paint( sal_Int32 nX ,
211                              sal_Int32 nY ,
212                              const css::uno::Reference< css::awt::XGraphics >& xGraphics ) override;
213 
214     using BaseControl::impl_recalcLayout;
215 
216     void impl_recalcLayout();
217 
218     void impl_rebuildFixedText();
219 
220     void impl_cleanMemory();
221 
222     IMPL_TextlistItem* impl_searchTopic( std::u16string_view sTopic , bool bbeforeProgress );
223 
224 // debug methods
225 
226     static bool impl_debug_checkParameter( std::u16string_view sTopic, std::u16string_view sText );    // addText, updateText
227     static bool impl_debug_checkParameter( std::u16string_view rTopic );                           // removeText
228 
229 // private variables
230 
231 private:
232     ::std::vector < std::unique_ptr<IMPL_TextlistItem> > maTextlist_Top;         // Elements before progress
233     css::uno::Reference< css::awt::XFixedText >   m_xTopic_Top;   // (used, if parameter "beforeProgress"=true in "addText, updateText, removeText")
234     css::uno::Reference< css::awt::XFixedText >   m_xText_Top;
235 
236     ::std::vector < std::unique_ptr<IMPL_TextlistItem> > maTextlist_Bottom;      // Elements below of progress
237     css::uno::Reference< css::awt::XFixedText >   m_xTopic_Bottom;   // (used, if parameter "beforeProgress"=false in "addText, updateText, removeText")
238     css::uno::Reference< css::awt::XFixedText >   m_xText_Bottom;
239 
240     rtl::Reference<ProgressBar>                   m_xProgressBar;
241     css::uno::Reference< css::awt::XButton >      m_xButton;
242     css::awt::Rectangle                           m_a3DLine;
243 };
244 
245 }
246 
247 
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
249