1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef RPTUI_CONDFORMAT_HXX 29 #define RPTUI_CONDFORMAT_HXX 30 31 #include "ModuleHelper.hxx" 32 33 #include <com/sun/star/report/XReportControlModel.hpp> 34 35 #include <vcl/dialog.hxx> 36 #include <vcl/button.hxx> 37 #include <vcl/fixed.hxx> 38 #include <vcl/scrbar.hxx> 39 40 #include <boost/shared_ptr.hpp> 41 #include <boost/noncopyable.hpp> 42 43 #include <vector> 44 45 // ............................................................................. 46 namespace rptui 47 { 48 // ............................................................................. 49 50 #define MAX_CONDITIONS (size_t)3 51 52 class OReportController; 53 class Condition; 54 55 //========================================================================= 56 //= IConditionalFormatAction 57 //========================================================================= 58 class SAL_NO_VTABLE IConditionalFormatAction 59 { 60 public: 61 virtual void addCondition( size_t _nAddAfterIndex ) = 0; 62 virtual void deleteCondition( size_t _nCondIndex ) = 0; 63 virtual void applyCommand( size_t _nCondIndex, sal_uInt16 _nCommandId, const ::Color _aColor ) = 0; 64 virtual void moveConditionUp( size_t _nCondIndex ) = 0; 65 virtual void moveConditionDown( size_t _nCondIndex ) = 0; 66 virtual ::rtl::OUString getDataField() const = 0; 67 }; 68 69 /************************************************************************* 70 |* 71 |* Conditional formatting dialog 72 |* 73 \************************************************************************/ 74 class ConditionalFormattingDialog :public ModalDialog 75 ,public IConditionalFormatAction 76 ,private ::boost::noncopyable 77 { 78 typedef ::boost::shared_ptr< Condition > ConditionPtr; 79 typedef ::std::vector< ConditionPtr > Conditions; 80 81 OModuleClient m_aModuleClient; 82 Window m_aConditionPlayground; 83 Conditions m_aConditions; 84 FixedLine m_aSeparator; 85 OKButton m_aPB_OK; 86 CancelButton m_aPB_CANCEL; 87 HelpButton m_aPB_Help; 88 ScrollBar m_aCondScroll; 89 90 ::rptui::OReportController& m_rController; 91 ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlModel > 92 m_xFormatConditions; 93 ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlModel > 94 m_xCopy; 95 96 bool m_bDeletingCondition; 97 98 public: 99 ConditionalFormattingDialog( 100 Window* pParent, 101 const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlModel>& _xHoldAlive, 102 ::rptui::OReportController& _rController 103 ); 104 virtual ~ConditionalFormattingDialog(); 105 106 // Dialog overridables 107 virtual short Execute(); 108 109 // IConditionalFormatAction overridables 110 virtual void addCondition( size_t _nAddAfterIndex ); 111 virtual void deleteCondition( size_t _nCondIndex ); 112 virtual void applyCommand( size_t _nCondIndex, sal_uInt16 _nCommandId, const ::Color _aColor ); 113 virtual void moveConditionUp( size_t _nCondIndex ); 114 virtual void moveConditionDown( size_t _nCondIndex ); 115 virtual ::rtl::OUString getDataField() const; 116 117 protected: 118 virtual long PreNotify( NotifyEvent& rNEvt ); 119 120 private: 121 DECL_LINK( OnScroll, ScrollBar* ); 122 123 private: 124 /// returns the current number of conditions 125 size_t impl_getConditionCount() const { return m_aConditions.size(); } 126 127 /** adds a condition 128 @param _nNewCondIndex 129 the index of the to-be-inserted condition 130 */ 131 void impl_addCondition_nothrow( size_t _nNewCondIndex ); 132 133 /// deletes the condition with the given index 134 void impl_deleteCondition_nothrow( size_t _nCondIndex ); 135 136 /// moves the condition with the given index one position 137 void impl_moveCondition_nothrow( size_t _nCondIndex, bool _bMoveUp ); 138 139 /// does the dialog layouting 140 void impl_layoutAll(); 141 142 /// does the layout for the condition windows 143 void impl_layoutConditions( Point& _out_rBelowLastVisible ); 144 145 /// called when the number of conditions has changed in any way 146 void impl_conditionCountChanged(); 147 148 /// initializes the conditions from m_xCopy 149 void impl_initializeConditions(); 150 151 /// tells all our Condition instances their new index 152 void impl_updateConditionIndicies(); 153 154 /// returns the number of the condition which has the (child path) focus 155 size_t impl_getFocusedConditionIndex( sal_Int32 _nFallBackIfNone ) const; 156 157 /// returns the index of the first visible condition 158 size_t impl_getFirstVisibleConditionIndex() const; 159 160 /// returns the index of the last visible condition 161 size_t impl_getLastVisibleConditionIndex() const; 162 163 /// determines the width of a Condition 164 long impl_getConditionWidth() const; 165 166 /// focuses the condition with the given index, making it visible if necessary 167 void impl_focusCondition( size_t _nCondIndex ); 168 169 /// updates the scrollbar range. (does not update the scrollbar visibility) 170 void impl_updateScrollBarRange(); 171 172 /// determines whether we need a scrollbar for the conditions 173 bool impl_needScrollBar() const { return m_aConditions.size() > MAX_CONDITIONS; } 174 175 /// scrolls the condition with the given index to the top position 176 void impl_scrollTo( size_t _nTopCondIndex ); 177 178 /// ensures the condition with the given index is visible 179 void impl_ensureConditionVisible( size_t _nCondIndex ); 180 }; 181 182 // ............................................................................. 183 } // namespace rptui 184 // ............................................................................. 185 186 #endif // RPTUI_CONDFORMAT_HXX 187