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_CONDFORMAT_HXX 25 #define RPTUI_CONDFORMAT_HXX 26 27 #include "ModuleHelper.hxx" 28 29 #include <com/sun/star/report/XReportControlModel.hpp> 30 31 #include <vcl/dialog.hxx> 32 #include <vcl/button.hxx> 33 #include <vcl/fixed.hxx> 34 #include <vcl/scrbar.hxx> 35 36 #include <boost/shared_ptr.hpp> 37 #include <boost/noncopyable.hpp> 38 39 #include <vector> 40 41 // ............................................................................. 42 namespace rptui 43 { 44 // ............................................................................. 45 46 #define MAX_CONDITIONS (size_t)3 47 48 class OReportController; 49 class Condition; 50 51 //========================================================================= 52 //= IConditionalFormatAction 53 //========================================================================= 54 class SAL_NO_VTABLE IConditionalFormatAction 55 { 56 public: 57 virtual void addCondition( size_t _nAddAfterIndex ) = 0; 58 virtual void deleteCondition( size_t _nCondIndex ) = 0; 59 virtual void applyCommand( size_t _nCondIndex, sal_uInt16 _nCommandId, const ::Color _aColor ) = 0; 60 virtual void moveConditionUp( size_t _nCondIndex ) = 0; 61 virtual void moveConditionDown( size_t _nCondIndex ) = 0; 62 virtual ::rtl::OUString getDataField() const = 0; 63 }; 64 65 /************************************************************************* 66 |* 67 |* Conditional formatting dialog 68 |* 69 \************************************************************************/ 70 class ConditionalFormattingDialog :public ModalDialog 71 ,public IConditionalFormatAction 72 ,private ::boost::noncopyable 73 { 74 typedef ::boost::shared_ptr< Condition > ConditionPtr; 75 typedef ::std::vector< ConditionPtr > Conditions; 76 77 OModuleClient m_aModuleClient; 78 Window m_aConditionPlayground; 79 Conditions m_aConditions; 80 FixedLine m_aSeparator; 81 OKButton m_aPB_OK; 82 CancelButton m_aPB_CANCEL; 83 HelpButton m_aPB_Help; 84 ScrollBar m_aCondScroll; 85 86 ::rptui::OReportController& m_rController; 87 ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlModel > 88 m_xFormatConditions; 89 ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlModel > 90 m_xCopy; 91 92 bool m_bDeletingCondition; 93 94 public: 95 ConditionalFormattingDialog( 96 Window* pParent, 97 const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlModel>& _xHoldAlive, 98 ::rptui::OReportController& _rController 99 ); 100 virtual ~ConditionalFormattingDialog(); 101 102 // Dialog overridables 103 virtual short Execute(); 104 105 // IConditionalFormatAction overridables 106 virtual void addCondition( size_t _nAddAfterIndex ); 107 virtual void deleteCondition( size_t _nCondIndex ); 108 virtual void applyCommand( size_t _nCondIndex, sal_uInt16 _nCommandId, const ::Color _aColor ); 109 virtual void moveConditionUp( size_t _nCondIndex ); 110 virtual void moveConditionDown( size_t _nCondIndex ); 111 virtual ::rtl::OUString getDataField() const; 112 113 protected: 114 virtual long PreNotify( NotifyEvent& rNEvt ); 115 116 private: 117 DECL_LINK( OnScroll, ScrollBar* ); 118 119 private: 120 /// returns the current number of conditions impl_getConditionCount() const121 size_t impl_getConditionCount() const { return m_aConditions.size(); } 122 123 /** adds a condition 124 @param _nNewCondIndex 125 the index of the to-be-inserted condition 126 */ 127 void impl_addCondition_nothrow( size_t _nNewCondIndex ); 128 129 /// deletes the condition with the given index 130 void impl_deleteCondition_nothrow( size_t _nCondIndex ); 131 132 /// moves the condition with the given index one position 133 void impl_moveCondition_nothrow( size_t _nCondIndex, bool _bMoveUp ); 134 135 /// does the dialog layouting 136 void impl_layoutAll(); 137 138 /// does the layout for the condition windows 139 void impl_layoutConditions( Point& _out_rBelowLastVisible ); 140 141 /// called when the number of conditions has changed in any way 142 void impl_conditionCountChanged(); 143 144 /// initializes the conditions from m_xCopy 145 void impl_initializeConditions(); 146 147 /// tells all our Condition instances their new index 148 void impl_updateConditionIndicies(); 149 150 /// returns the number of the condition which has the (child path) focus 151 size_t impl_getFocusedConditionIndex( sal_Int32 _nFallBackIfNone ) const; 152 153 /// returns the index of the first visible condition 154 size_t impl_getFirstVisibleConditionIndex() const; 155 156 /// returns the index of the last visible condition 157 size_t impl_getLastVisibleConditionIndex() const; 158 159 /// determines the width of a Condition 160 long impl_getConditionWidth() const; 161 162 /// focuses the condition with the given index, making it visible if necessary 163 void impl_focusCondition( size_t _nCondIndex ); 164 165 /// updates the scrollbar range. (does not update the scrollbar visibility) 166 void impl_updateScrollBarRange(); 167 168 /// determines whether we need a scrollbar for the conditions impl_needScrollBar() const169 bool impl_needScrollBar() const { return m_aConditions.size() > MAX_CONDITIONS; } 170 171 /// scrolls the condition with the given index to the top position 172 void impl_scrollTo( size_t _nTopCondIndex ); 173 174 /// ensures the condition with the given index is visible 175 void impl_ensureConditionVisible( size_t _nCondIndex ); 176 }; 177 178 // ............................................................................. 179 } // namespace rptui 180 // ............................................................................. 181 182 #endif // RPTUI_CONDFORMAT_HXX 183