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