Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
12 : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU Lesser General Public License version 3
14 : * only, as published by the Free Software Foundation.
15 : *
16 : * OpenOffice.org is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU Lesser General Public License version 3 for more details
20 : * (a copy is included in the LICENSE file that accompanied this code).
21 : *
22 : * You should have received a copy of the GNU Lesser General Public License
23 : * version 3 along with OpenOffice.org. If not, see
24 : * <http://www.openoffice.org/license.html>
25 : * for a copy of the LGPLv3 License.
26 : *
27 : * This file incorporates work covered by the following license notice:
28 : *
29 : * Licensed to the Apache Software Foundation (ASF) under one or more
30 : * contributor license agreements. See the NOTICE file distributed
31 : * with this work for additional information regarding copyright
32 : * ownership. The ASF licenses this file to you under the Apache
33 : * License, Version 2.0 (the "License"); you may not use this file
34 : * except in compliance with the License. You may obtain a copy of
35 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
36 : ************************************************************************/
37 :
38 : #ifndef SC_PVLAYDLG_HXX
39 : #define SC_PVLAYDLG_HXX
40 :
41 : #include <memory>
42 : #include <vector>
43 :
44 : #include <boost/ptr_container/ptr_vector.hpp>
45 : #include <boost/scoped_ptr.hpp>
46 :
47 : #include <formula/funcutl.hxx>
48 : #include <svtools/stdctrl.hxx>
49 : #include <vcl/lstbox.hxx>
50 : #include <vcl/morebtn.hxx>
51 : #include <vcl/scrbar.hxx>
52 :
53 : #include "anyrefdg.hxx"
54 : #include "fieldwnd.hxx"
55 :
56 : /*==========================================================================*\
57 :
58 : An instance of the class ScPivotLayoutDlg is a (semi-)modal dialog
59 : that can be associated to the mouse fields with column headings of
60 : the three pivot categories "column", "row" and "data".
61 :
62 : The dialog receives information about these headers (name,
63 : type (number/string) and function mask) in the label data structure
64 : Furthermore, three pivot field arrays are passed on, with which the three
65 : category windows are initialized. A window class is represented by an
66 : instance of class FieldWindow. Such a window is responsible for the
67 : representation of data structures on the screen. It reports on mouse
68 : actions in the dialogue and provides appropriate methods for
69 : changing the representation. The dialogue provides the adjustment of the
70 : internal data structures with respect to the representation on the screen.
71 : Another FieldWindow(Select) provides all table headers for selection,
72 : is thus "read only".
73 :
74 : \*==========================================================================*/
75 :
76 : class ScViewData;
77 : class ScDocument;
78 : struct ScPivotFuncData;
79 : class ScDPObject;
80 :
81 : class ScPivotLayoutDlg : public ScAnyRefDlg
82 : {
83 : typedef boost::ptr_vector<ScPivotFuncData> ScDPFuncDataVec;
84 :
85 : /** data source type */
86 : enum DataSrcType {
87 : SRC_REF, /// range reference
88 : SRC_NAME, /// range name
89 : SRC_INVALID /// invalid range
90 : };
91 : public:
92 : ScPivotLayoutDlg(
93 : SfxBindings* pB,
94 : SfxChildWindow* pCW,
95 : Window* pParent,
96 : const ScDPObject& rDPObject,
97 : bool bNewOutput );
98 : virtual ~ScPivotLayoutDlg();
99 :
100 : void NotifyDoubleClick ( ScPivotFieldType eType, size_t nFieldIndex );
101 : PointerStyle NotifyMouseButtonDown( ScPivotFieldType eType, size_t nFieldIndex );
102 : void NotifyFieldFocus ( ScPivotFieldType eType, bool bGotFocus );
103 : void NotifyMoveFieldToEnd ( ScPivotFieldType eToType );
104 : void NotifyRemoveField ( ScPivotFieldType eType, size_t nFieldIndex );
105 :
106 : Size GetStdFieldBtnSize() const;
107 :
108 : /**
109 : * Drop currently dragged field item into specified position.
110 : *
111 : * @param rScrPos screen position of mouse cursor.
112 : * @param eToType type of field at mouse cursor position.
113 : */
114 : void DropFieldItem( const Point& rScrPos, ScPivotFieldType eToType );
115 :
116 : /**
117 : * Get pointer style at current mouse position during dragging of field
118 : * item.
119 : */
120 : PointerStyle GetPointerStyleAtPoint( const Point& rScrPos, ScPivotFieldType eFieldType );
121 :
122 : /**
123 : * Determine the type of field at mouse cursor position.
124 : *
125 : * @param rScrPos mouse cursor position (screen position).
126 : */
127 : ScPivotFieldType GetFieldTypeAtPoint( const Point& rScrPos ) const;
128 :
129 : protected:
130 : virtual void Deactivate();
131 : virtual void SetReference( const ScRange& rRef, ScDocument* pDoc );
132 : virtual sal_Bool IsRefInputMode() const;
133 : virtual void SetActive();
134 : virtual sal_Bool Close();
135 :
136 : private:
137 : /** Returns the localized function name for the specified (1-based) resource index. */
138 0 : inline const rtl::OUString& GetFuncName( sal_uInt16 nFuncIdx ) const { return maFuncNames[nFuncIdx-1]; }
139 :
140 : /** Fills the field windows from the current pivot table settings. */
141 : void InitFieldWindows();
142 : /** Sets focus to the specified field control, if it is not empty. */
143 : void GrabFieldFocus( ScDPFieldControlBase& rFieldWindow );
144 :
145 : void InitWndSelect(const ScDPLabelDataVector& rLabels);
146 : void InitWndData(const std::vector<ScPivotField>& rFields);
147 : void InitFieldWindow ( const ::std::vector<ScPivotField>& rFields, ScPivotFieldType eType );
148 : void AdjustDlgSize();
149 : Point DlgPos2WndPos ( const Point& rPt, Window& rWnd );
150 : ScDPLabelData* GetLabelData ( SCsCOL nCol, size_t* pPos = NULL );
151 : rtl::OUString GetLabelString(SCsCOL nCol);
152 : bool IsOrientationAllowed( SCsCOL nCol, ScPivotFieldType eType );
153 : rtl::OUString GetFuncString( sal_uInt16& rFuncMask, bool bIsValue = true );
154 : bool Contains( ScDPFuncDataVec* pArr, const ScPivotFuncData& rData, size_t& nAt );
155 : void Remove ( ScDPFuncDataVec* pArr, size_t nAt );
156 : void Insert ( ScDPFuncDataVec* pArr, const ScPivotFuncData& rFData, size_t nAt );
157 :
158 : void AddField ( size_t nFromIndex,
159 : ScPivotFieldType eToType, const Point& rAtPos );
160 : void AppendField(size_t nFromIndex, ScPivotFieldType eToType);
161 : void MoveField ( ScPivotFieldType eFromType, size_t nFromIndex,
162 : ScPivotFieldType eToType, const Point& rAtPos );
163 : void MoveFieldToEnd(ScPivotFieldType eFromType, size_t nFromIndex, ScPivotFieldType eToType);
164 : void RemoveField ( ScPivotFieldType eRemType, size_t nRemIndex );
165 :
166 : bool GetPivotArrays( ::std::vector<ScPivotField>& rPageFields,
167 : ::std::vector<ScPivotField>& rColFields,
168 : ::std::vector<ScPivotField>& rRowFields,
169 : ::std::vector<ScPivotField>& rDataFields );
170 :
171 : void UpdateSrcRange();
172 : void RepaintFieldWindows();
173 :
174 : /**
175 : * Initialize control sizes and the dialog size which depends on them.
176 : */
177 : void InitControlAndDlgSizes();
178 :
179 : ScDPFieldControlBase* GetFieldWindow(ScPivotFieldType eType);
180 :
181 : /**
182 : * Get pointers to field windows that are <b>not</b> the window of
183 : * specified type. The select window type is not included.
184 : */
185 : void GetOtherFieldWindows(
186 : ScPivotFieldType eType, ScDPFieldControlBase*& rpWnd1, ScDPFieldControlBase*& rpWnd2);
187 :
188 : ScDPFuncDataVec* GetFieldDataArray(ScPivotFieldType eType);
189 :
190 : /**
191 : * Like GetOtherFieldWindows(), get pointers to data arrays of the fields
192 : * that are <b>not</b> the specified field type.
193 : */
194 : void GetOtherDataArrays(
195 : ScPivotFieldType eType, ScDPFuncDataVec*& rpArr1, ScDPFuncDataVec*& rpArr2);
196 :
197 : sal_uInt8 GetNextDupCount(const ScDPFuncDataVec& rArr, const ScPivotFuncData& rData, size_t nDataIndex) const;
198 :
199 : // Handler
200 : DECL_LINK( ClickHdl, PushButton * );
201 : DECL_LINK( OkHdl, void * );
202 : DECL_LINK( CancelHdl, void * );
203 : DECL_LINK( MoreClickHdl, void * );
204 : DECL_LINK( EdOutModifyHdl, void * );
205 : DECL_LINK( EdInModifyHdl, void * );
206 : DECL_LINK( SelAreaHdl, void * );
207 : DECL_LINK( GetFocusHdl, formula::RefEdit* );
208 :
209 : private:
210 : struct FieldRect
211 : {
212 : const Rectangle* mpRect;
213 : ScPivotFieldType meType;
214 :
215 : FieldRect(const Rectangle* pRect, ScPivotFieldType eType);
216 : };
217 :
218 : typedef boost::scoped_ptr<ScDPObject> ScDPObjectPtr;
219 :
220 : FixedLine maFlLayout;
221 : FixedText maFtPage;
222 : ScDPPageFieldControl maWndPage;
223 : FixedText maFtCol;
224 : ScDPColFieldControl maWndCol;
225 : FixedText maFtRow;
226 : ScDPRowFieldControl maWndRow;
227 : FixedText maFtData;
228 : ScDPDataFieldControl maWndData;
229 : ScDPSelectFieldControl maWndSelect;
230 : FixedInfo maFtInfo;
231 :
232 : FixedLine maFlAreas;
233 : FixedText maFtInArea;
234 : ::formula::RefEdit maEdInPos;
235 : ::formula::RefButton maRbInPos;
236 : ListBox maLbOutPos;
237 : FixedText maFtOutArea;
238 : formula::RefEdit maEdOutPos;
239 : formula::RefButton maRbOutPos;
240 : CheckBox maBtnIgnEmptyRows;
241 : CheckBox maBtnDetectCat;
242 : CheckBox maBtnTotalCol;
243 : CheckBox maBtnTotalRow;
244 : CheckBox maBtnFilter;
245 : CheckBox maBtnDrillDown;
246 :
247 : OKButton maBtnOk;
248 : CancelButton maBtnCancel;
249 : HelpButton maBtnHelp;
250 : PushButton maBtnRemove;
251 : PushButton maBtnOptions;
252 : MoreButton maBtnMore;
253 : std::vector<rtl::OUString> maFuncNames; /// Localized function names from resource.
254 : ScDPObjectPtr mxDlgDPObject; /// Clone of the pivot table object this dialog is based on.
255 : ScPivotParam maPivotData; /// The pivot table field configuration.
256 : ScDPLabelDataVector maLabelData; /// Information about all dimensions.
257 :
258 : ScViewData* mpViewData;
259 : ScDocument* mpDoc;
260 : formula::RefEdit* mpRefInputEdit;
261 :
262 : const rtl::OUString maStrUndefined;
263 : const rtl::OUString maStrNewTable;
264 :
265 : ScPivotFieldType meDnDFromType;
266 : size_t mnDnDFromIndex;
267 : bool mbIsDrag;
268 :
269 : Rectangle maRectPage;
270 : Rectangle maRectRow;
271 : Rectangle maRectCol;
272 : Rectangle maRectData;
273 : Rectangle maRectSelect;
274 : std::vector<FieldRect> maFieldRects;
275 :
276 : ScPivotFieldType meLastActiveType; /// Type of last active area.
277 : size_t mnOffset; /// Offset of first field in TYPE_SELECT area.
278 :
279 : ScDPFuncDataVec maSelectArr;
280 : ScDPFuncDataVec maPageArr;
281 : ScDPFuncDataVec maColArr;
282 : ScDPFuncDataVec maRowArr;
283 : ScDPFuncDataVec maDataArr;
284 :
285 : ScRange maOldRange;
286 : bool mbRefInputMode;
287 : };
288 :
289 :
290 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
291 :
292 : #endif
|