1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef RPTUI_CONDITION_HXX
25 #define RPTUI_CONDITION_HXX
26 
27 #include "conditionalexpression.hxx"
28 
29 #include <com/sun/star/report/XFormatCondition.hpp>
30 
31 #include <dbaccess/ToolBoxHelper.hxx>
32 
33 #include <svx/fntctrl.hxx>
34 
35 #include <svtools/valueset.hxx>
36 
37 #include <vcl/fixed.hxx>
38 #include <vcl/lstbox.hxx>
39 #include <vcl/field.hxx>
40 #include <vcl/button.hxx>
41 #include <vcl/toolbox.hxx>
42 
43 #include <memory>
44 
45 namespace svx { class ToolboxButtonColorUpdater; }
46 
47 namespace rptui
48 {
49     class ConditionalFormattingDialog;
50     class OColorPopup;
51     class OReportController;
52     class IConditionalFormatAction;
53     class Condition;
54 
55     class ConditionField : public Edit
56     {
57         Condition*  m_pParent;
58         Edit*       m_pSubEdit;
59         PushButton  m_aFormula;
60 
61         DECL_LINK( OnFormula,   Button* );
62     public:
63         ConditionField( Condition* pParent, const ResId& rResId );
64         virtual ~ConditionField();
65         virtual void Resize();
66     };
67 
68     //========================================================================
69     //= Condition
70     //========================================================================
71     class Condition :public Control
72                     ,public dbaui::OToolBoxHelper
73     {
74         ::rptui::OReportController& m_rController;
75         IConditionalFormatAction&   m_rAction;
76         FixedLine                   m_aHeader;
77         ListBox                     m_aConditionType;
78         ListBox                     m_aOperationList;
79         ConditionField              m_aCondLHS;
80         FixedText                   m_aOperandGlue;
81         ConditionField              m_aCondRHS;
82         ToolBox                     m_aActions;
83         SvxFontPrevWindow           m_aPreview;
84         ImageButton                 m_aMoveUp;
85         ImageButton                 m_aMoveDown;
86         PushButton                  m_aAddCondition;
87         PushButton                  m_aRemoveCondition;
88         OColorPopup*                m_pColorFloat;
89 
90         ::svx::ToolboxButtonColorUpdater*   m_pBtnUpdaterFontColor; // updates the color below the toolbar icon
91         ::svx::ToolboxButtonColorUpdater*   m_pBtnUpdaterBackgroundColor;
92 
93 
94         size_t                          m_nCondIndex;
95         long                            m_nLastKnownWindowWidth;
96         bool                            m_bInDestruction;
97 
98         ConditionalExpressions          m_aConditionalExpressions;
99 
100         DECL_LINK( OnFormatAction,      ToolBox* );
101         DECL_LINK( DropdownClick,       ToolBox* );
102         DECL_LINK( OnConditionAction,   Button* );
103 
104     public:
105         Condition( Window* _pParent, IConditionalFormatAction& _rAction, ::rptui::OReportController& _rController );
106         virtual ~Condition();
107 
108         /** will be called when the id of the image list is needed.
109             @param  _eBitmapSet
110                 <svtools/imgdef.hxx>
111             @param  _bHiContast
112                 <TRUE/> when in high contrast mode.
113         */
114         virtual ImageList getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const;
115 
116         /** will be called when the controls need to be resized.
117         */
118         virtual void resizeControls(const Size& _rDiff);
119 
120         /** sets the props at the control
121             @param  _xCondition the source
122         */
123         void setCondition(const com::sun::star::uno::Reference< com::sun::star::report::XFormatCondition >& _xCondition);
124 
125         /** fills from the control
126             _xCondition the destination
127         */
128         void fillFormatCondition(const com::sun::star::uno::Reference< com::sun::star::report::XFormatCondition >& _xCondition);
129 
130         /** updates the toolbar
131             _xCondition the destination
132         */
133         void updateToolbar(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlFormat >& _xCondition);
134 
135         /// tells the condition its new index within the dialog's condition array
136         void setConditionIndex( size_t _nCondIndex, size_t _nCondCount );
137 
138         /// returns the condition's index within the dialog's condition array
getConditionIndex() const139         size_t  getConditionIndex() const { return m_nCondIndex; }
140 
141         /** determines whether the condition is actually empty
142         */
143         bool    isEmpty() const;
144 
145         /** forward to the parent class
146         */
147         void    ApplyCommand(sal_uInt16 _nCommandId, const ::Color& _aColor );
148 
getController() const149         inline ::rptui::OReportController& getController() const { return m_rController; }
150 
151     protected:
152         virtual void StateChanged( StateChangedType nStateChange );
153         virtual void DataChanged( const DataChangedEvent& rDCEvt );
154         virtual void Paint( const Rectangle& rRect );
155         virtual void Resize();
156         virtual void GetFocus();
157 
158     private:
159         void    impl_layoutAll();
160         void    impl_layoutOperands();
161 
162         /// determines the rectangle to be occupied by the toolbar, including the border drawn around it
163         Rectangle   impl_getToolBarBorderRect() const;
164 
165         inline  ConditionType
166                     impl_getCurrentConditionType() const;
167 
168         inline  ComparisonOperation
169                     impl_getCurrentComparisonOperation() const;
170 
171         void    impl_setCondition( const ::rtl::OUString& _rConditionFormula );
172 
173     private:
174         DECL_LINK( OnTypeSelected, ListBox* );
175         DECL_LINK( OnOperationSelected, ListBox* );
176     };
177 
178     // -------------------------------------------------------------------------
impl_getCurrentConditionType() const179     inline ConditionType Condition::impl_getCurrentConditionType() const
180     {
181         return sal::static_int_cast< ConditionType >( m_aConditionType.GetSelectEntryPos() );
182     }
183 
184     // -------------------------------------------------------------------------
impl_getCurrentComparisonOperation() const185     inline ComparisonOperation Condition::impl_getCurrentComparisonOperation() const
186     {
187         return sal::static_int_cast< ComparisonOperation >( m_aOperationList.GetSelectEntryPos() );
188     }
189 
190 // =============================================================================
191 } // namespace rptui
192 // =============================================================================
193 #endif // RPTUI_CONDITION_HXX
194 
195