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