Line data Source code
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 SC_FIELDWND_HXX
21 : #define SC_FIELDWND_HXX
22 :
23 : #include <vector>
24 :
25 : #include <vcl/ctrl.hxx>
26 : #include <vcl/fixed.hxx>
27 : #include <vcl/scrbar.hxx>
28 :
29 : #include "address.hxx"
30 : #include "pivot.hxx"
31 :
32 : class ScPivotLayoutDlg;
33 : class ScAccessibleDataPilotControl;
34 :
35 : extern const size_t PIVOTFIELD_INVALID;
36 :
37 : /** Type of the pivot table field window. */
38 : enum ScPivotFieldType
39 : {
40 : PIVOTFIELDTYPE_PAGE = 0, /// Window for all page fields.
41 : PIVOTFIELDTYPE_COL, /// Window for all column fields.
42 : PIVOTFIELDTYPE_ROW, /// Window for all row fields.
43 : PIVOTFIELDTYPE_DATA, /// Window for all data fields.
44 : PIVOTFIELDTYPE_SELECT, /// Selection window with all fields.
45 : PIVOTFIELDTYPE_UNKNOWN
46 : };
47 :
48 : /**
49 : * Represents a field area in the DataPilot layout dialog. This base class
50 : * handles storage of field names and the accessibility object.
51 : */
52 : class ScDPFieldControlBase : public Control
53 : {
54 : protected:
55 0 : struct FieldName
56 : {
57 : rtl::OUString maText;
58 : bool mbFits;
59 : sal_uInt8 mnDupCount;
60 : FieldName(const rtl::OUString& rText, bool bFits, sal_uInt8 nDupCount = 0);
61 : FieldName(const FieldName& r);
62 :
63 : rtl::OUString getDisplayedText() const;
64 : };
65 : typedef ::std::vector<FieldName> FieldNames;
66 :
67 : public:
68 :
69 : /**
70 : * Custom scroll bar to pass the command event to its parent window.
71 : * We need this to pass the mouse wheel events to its parent field
72 : * control to have mouse wheel events appaer to be properly handled by the
73 : * scroll bar.
74 : */
75 0 : class ScrollBar : public ::ScrollBar
76 : {
77 : public:
78 : ScrollBar(Window* pParent, WinBits nStyle);
79 : virtual void Command( const CommandEvent& rCEvt );
80 : private:
81 : Window* mpParent;
82 : };
83 :
84 : ScDPFieldControlBase(
85 : ScPivotLayoutDlg* pParent, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
86 : virtual ~ScDPFieldControlBase();
87 :
88 : virtual void CalcSize() = 0;
89 :
90 : virtual bool IsValidIndex( size_t nIndex ) const = 0;
91 : /** @return The pixel position of a field (without bound check). */
92 : virtual Point GetFieldPosition( size_t nIndex ) = 0;
93 : /** Calculates the field index at a specific pixel position. */
94 : virtual size_t GetFieldIndex( const Point& rPos ) = 0;
95 : /** @return The pixel size of a field. */
96 : virtual Size GetFieldSize() const = 0;
97 :
98 : /** @return The description of the control which is used for the accessibility objects. */
99 : virtual String GetDescription() const = 0;
100 : /** @return The type of the FieldWindow. */
101 : virtual ScPivotFieldType GetFieldType() const = 0;
102 : virtual void ScrollToShowSelection() = 0;
103 : virtual void ScrollToEnd() = 0;
104 : virtual void ResetScrollBar() = 0;
105 : virtual void HandleWheelScroll(long nNotch) = 0;
106 :
107 : /** @return The name of the control without shortcut. */
108 : ::rtl::OUString GetName() const;
109 : void SetName(const ::rtl::OUString& rName);
110 :
111 : /** @return TRUE, if the field with the given index exists. */
112 : bool IsExistingIndex( size_t nIndex ) const;
113 :
114 : /** Inserts a field to the specified index. */
115 : void AddField( const rtl::OUString& rText, size_t nNewIndex );
116 :
117 : /** Inserts a field using the specified pixel position.
118 : @param rPos The coordinates to insert the field.
119 : @param rnIndex The new index of the field is returned here.
120 : @return true, if the field has been created. */
121 : bool AddField(const rtl::OUString& rText, const Point& rPos, size_t& rnIndex, sal_uInt8& rnDupCount);
122 :
123 : bool MoveField(size_t nCurPos, const Point& rPos, size_t& rnIndex);
124 :
125 : bool AppendField(const rtl::OUString& rText, size_t& rnIndex);
126 :
127 : /** Removes a field from the specified index. */
128 : void DelField( size_t nDelIndex );
129 :
130 : /** Returns the number of existing fields. */
131 : size_t GetFieldCount() const;
132 :
133 : bool IsEmpty() const;
134 :
135 : /** Removes all fields. */
136 : void ClearFields();
137 : /** Changes the text on an existing field. */
138 : void SetFieldText(const rtl::OUString& rText, size_t nIndex, sal_uInt8 nDupCount);
139 : /** Returns the text of an existing field. */
140 : rtl::OUString GetFieldText( size_t nIndex ) const;
141 :
142 : /** Calculates a field index at a specific pixel position. Returns in every
143 : case the index of an existing field.
144 : @param rnIndex The index of the field is returned here.
145 : @return TRUE, if the index value is valid. */
146 : void GetExistingIndex( const Point& rPos, size_t& rnIndex );
147 :
148 : size_t GetSelectedField() const;
149 :
150 : /** Selects the next field. Called i.e. after moving a field from SELECT area. */
151 : void SelectNext();
152 : /** Grabs focus and sets new selection. */
153 : void GrabFocusAndSelect( size_t nIndex );
154 :
155 : virtual void Paint( const Rectangle& rRect );
156 :
157 : protected:
158 : virtual void StateChanged( StateChangedType nStateChange );
159 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
160 : virtual void KeyInput( const KeyEvent& rKEvt );
161 : virtual void Command( const CommandEvent& rCEvt );
162 : virtual void MouseButtonDown( const MouseEvent& rMEvt );
163 : virtual void MouseButtonUp( const MouseEvent& rMEvt );
164 : virtual void MouseMove( const MouseEvent& rMEvt );
165 : virtual void GetFocus();
166 : virtual void LoseFocus();
167 :
168 : protected:
169 : FieldNames& GetFieldNames();
170 : const FieldNames& GetFieldNames() const;
171 :
172 : virtual ::com::sun::star::uno::Reference<
173 : ::com::sun::star::accessibility::XAccessible > CreateAccessible();
174 :
175 : void FieldFocusChanged(size_t nOldSelected, size_t nFieldSelected);
176 :
177 : /** Updates the tab stop style bits. */
178 : void UpdateStyle();
179 :
180 : /** Draw background color for the whole control area. */
181 : void DrawBackground( OutputDevice& rDev );
182 :
183 : /** Draw a single field button. */
184 : void DrawField( OutputDevice& rDev, const Rectangle& rRect,
185 : FieldName& rText, bool bFocus );
186 :
187 : void AppendPaintable(Window* p);
188 : void DrawPaintables();
189 : void DrawInvertSelection();
190 : Size GetStdFieldBtnSize() const;
191 :
192 : /** @return The new selection index after moving to the given direction. */
193 : virtual size_t CalcNewFieldIndex( SCsCOL nDX, SCsROW nDY ) const = 0;
194 :
195 : /**
196 : * @param nIndex logical index of a field name, independent of scroll
197 : * offsets.
198 : * @return Display position of the button. The first displayed button is
199 : * always 0 no matter what the current scroll offset is. In case
200 : * the field specified by the index is outside the visible range,
201 : * <code>INVALID_INDEX</code> is returned.
202 : */
203 : virtual size_t GetDisplayPosition(size_t nIndex) const = 0;
204 :
205 : /** Draws the complete control. */
206 : virtual void Redraw() = 0;
207 :
208 : private:
209 : /** Moves the selected field to nDestIndex. */
210 : void MoveField( size_t nDestIndex );
211 : /** Moves the selected field to the given direction. */
212 : void MoveFieldRel( SCsCOL nDX, SCsROW nDY );
213 :
214 : /** Selects a field and adjusts scrolling position to make the field visible. */
215 : void MoveSelection( size_t nSelectedIndex );
216 : /** Selects a field at a new position relative to the current. */
217 : void MoveSelection( SCsCOL nDX, SCsROW nDY );
218 :
219 : sal_uInt8 GetNextDupCount(const rtl::OUString& rFieldText) const;
220 :
221 : private:
222 : typedef ::std::vector<Window*> Paintables;
223 : Paintables maPaintables;
224 :
225 : FieldNames maFieldNames; /// String array of the field names and flags, if text fits into button.
226 : ScPivotLayoutDlg* mpDlg;
227 : FixedText* mpCaption; /// FixedText containing the name of the control.
228 : ::rtl::OUString maName;
229 :
230 : size_t mnFieldSelected; /// Currently selected field.
231 :
232 : // Hold a helpful reference while we work with our weakref.
233 0 : class AccessRef
234 : {
235 : com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > mxRef;
236 : public:
237 : AccessRef( const com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > & rAccessible );
238 : ScAccessibleDataPilotControl *operator -> () const;
239 0 : bool is() { return mxRef.is(); }
240 : };
241 :
242 : com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > mxAccessible;
243 : };
244 :
245 : // ============================================================================
246 :
247 : /**
248 : * Base class for field control with a horizontal scroll bar at the bottom.
249 : * Page, column, data and select fields are derived from this class.
250 : */
251 : class ScDPHorFieldControl : public ScDPFieldControlBase
252 : {
253 : protected:
254 : virtual size_t CalcNewFieldIndex(SCsCOL nDX, SCsROW nDY) const;
255 : virtual size_t GetDisplayPosition(size_t nIndex) const;
256 : virtual void Redraw();
257 :
258 : public:
259 : ScDPHorFieldControl(
260 : ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
261 :
262 : virtual ~ScDPHorFieldControl();
263 :
264 : virtual void CalcSize();
265 : virtual bool IsValidIndex( size_t nIndex ) const;
266 : virtual Point GetFieldPosition(size_t nIndex);
267 : virtual Size GetFieldSize() const;
268 : virtual size_t GetFieldIndex( const Point& rPos );
269 : virtual String GetDescription() const;
270 :
271 : virtual void ScrollToEnd();
272 : virtual void ScrollToShowSelection();
273 : virtual void ResetScrollBar();
274 : virtual void HandleWheelScroll(long nNotch);
275 :
276 : private:
277 : bool GetFieldBtnPosSize(size_t nPos, Point& rPos, Size& rSize);
278 : void HandleScroll();
279 :
280 : DECL_LINK(ScrollHdl, void*);
281 : DECL_LINK(EndScrollHdl, void*);
282 :
283 : private:
284 :
285 : ScrollBar maScroll;
286 :
287 : size_t mnFieldBtnRowCount;
288 : size_t mnFieldBtnColCount;
289 : };
290 :
291 : // ============================================================================
292 :
293 : class ScDPPageFieldControl : public ScDPHorFieldControl
294 : {
295 : public:
296 : ScDPPageFieldControl(
297 : ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
298 : virtual ~ScDPPageFieldControl();
299 :
300 : virtual ScPivotFieldType GetFieldType() const;
301 : virtual String GetDescription() const;
302 : };
303 :
304 : // ============================================================================
305 :
306 : class ScDPColFieldControl : public ScDPHorFieldControl
307 : {
308 : public:
309 : ScDPColFieldControl(
310 : ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
311 : virtual ~ScDPColFieldControl();
312 :
313 : virtual ScPivotFieldType GetFieldType() const;
314 : virtual String GetDescription() const;
315 : };
316 :
317 : // ============================================================================
318 :
319 : /**
320 : * Row field control with a vertical scroll bar.
321 : */
322 : class ScDPRowFieldControl : public ScDPFieldControlBase
323 : {
324 : public:
325 : ScDPRowFieldControl(
326 : ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
327 :
328 : virtual ~ScDPRowFieldControl();
329 :
330 : virtual void CalcSize();
331 : virtual bool IsValidIndex( size_t nIndex ) const;
332 : virtual Point GetFieldPosition( size_t nIndex );
333 : virtual Size GetFieldSize() const;
334 : virtual size_t GetFieldIndex( const Point& rPos );
335 : virtual String GetDescription() const;
336 : virtual ScPivotFieldType GetFieldType() const;
337 :
338 : virtual void ScrollToEnd();
339 : virtual void ScrollToShowSelection();
340 : virtual void ResetScrollBar();
341 : virtual void HandleWheelScroll(long nNotch);
342 :
343 : protected:
344 : virtual size_t CalcNewFieldIndex( SCsCOL nDX, SCsROW nDY ) const;
345 : virtual size_t GetDisplayPosition(size_t nIndex) const;
346 : virtual void Redraw();
347 :
348 : private:
349 : bool GetFieldBtnPosSize(size_t nPos, Point& rPos, Size& rSize);
350 : void HandleScroll();
351 :
352 : DECL_LINK(ScrollHdl, void*);
353 : DECL_LINK(EndScrollHdl, void*);
354 :
355 : private:
356 :
357 : ScDPFieldControlBase::ScrollBar maScroll;
358 : size_t mnColumnBtnCount;
359 : };
360 :
361 : // ============================================================================
362 :
363 : class ScDPSelectFieldControl : public ScDPHorFieldControl
364 : {
365 : public:
366 : ScDPSelectFieldControl(
367 : ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
368 : virtual ~ScDPSelectFieldControl();
369 :
370 : virtual ScPivotFieldType GetFieldType() const;
371 : virtual String GetDescription() const;
372 : };
373 :
374 : // ============================================================================
375 :
376 : class ScDPDataFieldControl : public ScDPHorFieldControl
377 : {
378 : public:
379 : ScDPDataFieldControl(
380 : ScPivotLayoutDlg* pParent, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
381 : virtual ~ScDPDataFieldControl();
382 :
383 : virtual ScPivotFieldType GetFieldType() const;
384 : virtual Size GetFieldSize() const;
385 : virtual String GetDescription() const;
386 : };
387 :
388 : #endif
389 :
390 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|