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 :
10 : #ifndef _VCLLAYOUT_HXX
11 : #define _VCLLAYOUT_HXX
12 :
13 : #include <vcl/dllapi.h>
14 : #include <vcl/button.hxx>
15 : #include <vcl/scrbar.hxx>
16 : #include <vcl/window.hxx>
17 : #include <boost/multi_array.hpp>
18 :
19 0 : class VCL_DLLPUBLIC VclContainer : public Window
20 : {
21 : public:
22 : VclContainer(Window *pParent, WinBits nStyle = WB_HIDE);
23 : virtual Size GetOptimalSize(WindowSizeType eType) const;
24 : virtual void SetPosSizePixel(const Point& rNewPos, const Size& rNewSize);
25 : virtual void SetPosPixel(const Point& rAllocPos);
26 : virtual void SetSizePixel(const Size& rAllocation);
27 :
28 0 : void markLayoutDirty()
29 : {
30 0 : m_bLayoutDirty = true;
31 0 : }
32 :
33 : //These take into account the external margins of the rWindow widget
34 : //while GetOptimalSize/get_preferred_size and SetPosSizePixel are
35 : //oblivious to them
36 : static Size getLayoutRequisition(const Window &rWindow);
37 : static void setLayoutPosSize(Window &rWindow, const Point &rPos, const Size &rSize);
38 :
39 : //applies the allocation pos and size onto rWindow via setLayoutPosSize taking into account
40 : //the rWindows alignment desires within that allocation
41 : static void setLayoutAllocation(Window &rWindow, const Point &rPos, const Size &rSize);
42 :
43 : protected:
44 : virtual Size calculateRequisition() const = 0;
45 : virtual void setAllocation(const Size &rAllocation) = 0;
46 : private:
47 : bool m_bLayoutDirty;
48 : };
49 :
50 0 : class VCL_DLLPUBLIC VclBox : public VclContainer
51 : {
52 : protected:
53 : bool m_bHomogeneous;
54 : int m_nSpacing;
55 : public:
56 0 : VclBox(Window *pParent, bool bHomogeneous, int nSpacing)
57 : : VclContainer(pParent)
58 : , m_bHomogeneous(bHomogeneous)
59 0 : , m_nSpacing(nSpacing)
60 : {
61 0 : }
62 0 : void set_spacing(int nSpacing)
63 : {
64 0 : m_nSpacing = nSpacing;
65 0 : }
66 : int get_spacing() const
67 : {
68 : return m_nSpacing;
69 : }
70 0 : void set_homogeneous(bool bHomogeneous)
71 : {
72 0 : m_bHomogeneous = bHomogeneous;
73 0 : }
74 : bool get_homogeneous() const
75 : {
76 : return m_bHomogeneous;
77 : }
78 : virtual bool set_property(const OString &rKey, const OString &rValue);
79 : protected:
80 : void accumulateMaxes(const Size &rChildSize, Size &rSize) const;
81 : Size finalizeMaxes(const Size &rSize, sal_uInt16 nVisibleChildren) const;
82 :
83 : virtual Size calculateRequisition() const;
84 : virtual void setAllocation(const Size &rAllocation);
85 :
86 : virtual long getPrimaryDimension(const Size &rSize) const = 0;
87 : virtual void setPrimaryDimension(Size &rSize, long) const = 0;
88 : virtual long getPrimaryCoordinate(const Point &rPos) const = 0;
89 : virtual void setPrimaryCoordinate(Point &rPos, long) const = 0;
90 : virtual long getSecondaryDimension(const Size &rSize) const = 0;
91 : virtual void setSecondaryDimension(Size &rSize, long) const = 0;
92 : virtual long getSecondaryCoordinate(const Point &rPos) const = 0;
93 : virtual void setSecondaryCoordinate(Point &rPos, long) const = 0;
94 :
95 : virtual bool getPrimaryDimensionChildExpand(const Window &rWindow) const = 0;
96 : };
97 :
98 0 : class VCL_DLLPUBLIC VclVBox : public VclBox
99 : {
100 : public:
101 0 : VclVBox(Window *pParent, bool bHomogeneous = false, int nSpacing = 0)
102 0 : : VclBox(pParent, bHomogeneous, nSpacing)
103 : {
104 0 : }
105 : protected:
106 0 : virtual long getPrimaryDimension(const Size &rSize) const
107 : {
108 0 : return rSize.getHeight();
109 : }
110 0 : virtual void setPrimaryDimension(Size &rSize, long nHeight) const
111 : {
112 0 : rSize.setHeight(nHeight);
113 0 : }
114 0 : virtual long getPrimaryCoordinate(const Point &rPos) const
115 : {
116 0 : return rPos.getY();
117 : }
118 0 : virtual void setPrimaryCoordinate(Point &rPos, long nPos) const
119 : {
120 0 : rPos.setY(nPos);
121 0 : }
122 0 : virtual long getSecondaryDimension(const Size &rSize) const
123 : {
124 0 : return rSize.getWidth();
125 : }
126 0 : virtual void setSecondaryDimension(Size &rSize, long nWidth) const
127 : {
128 0 : rSize.setWidth(nWidth);
129 0 : }
130 0 : virtual long getSecondaryCoordinate(const Point &rPos) const
131 : {
132 0 : return rPos.getX();
133 : }
134 0 : virtual void setSecondaryCoordinate(Point &rPos, long nPos) const
135 : {
136 0 : rPos.setX(nPos);
137 0 : }
138 0 : virtual bool getPrimaryDimensionChildExpand(const Window &rWindow) const
139 : {
140 0 : return rWindow.get_expand() || rWindow.get_vexpand();
141 : }
142 : };
143 :
144 0 : class VCL_DLLPUBLIC VclHBox : public VclBox
145 : {
146 : public:
147 0 : VclHBox(Window *pParent, bool bHomogeneous = false, int nSpacing = 0)
148 0 : : VclBox(pParent, bHomogeneous, nSpacing)
149 : {
150 0 : }
151 : protected:
152 0 : virtual long getPrimaryDimension(const Size &rSize) const
153 : {
154 0 : return rSize.getWidth();
155 : }
156 0 : virtual void setPrimaryDimension(Size &rSize, long nWidth) const
157 : {
158 0 : rSize.setWidth(nWidth);
159 0 : }
160 0 : virtual long getPrimaryCoordinate(const Point &rPos) const
161 : {
162 0 : return rPos.getX();
163 : }
164 0 : virtual void setPrimaryCoordinate(Point &rPos, long nPos) const
165 : {
166 0 : rPos.setX(nPos);
167 0 : }
168 0 : virtual long getSecondaryDimension(const Size &rSize) const
169 : {
170 0 : return rSize.getHeight();
171 : }
172 0 : virtual void setSecondaryDimension(Size &rSize, long nHeight) const
173 : {
174 0 : rSize.setHeight(nHeight);
175 0 : }
176 0 : virtual long getSecondaryCoordinate(const Point &rPos) const
177 : {
178 0 : return rPos.getY();
179 : }
180 0 : virtual void setSecondaryCoordinate(Point &rPos, long nPos) const
181 : {
182 0 : rPos.setY(nPos);
183 0 : }
184 0 : virtual bool getPrimaryDimensionChildExpand(const Window &rWindow) const
185 : {
186 0 : return rWindow.get_expand() || rWindow.get_hexpand();
187 : }
188 : };
189 :
190 : enum VclButtonBoxStyle
191 : {
192 : VCL_BUTTONBOX_DEFAULT_STYLE,
193 : VCL_BUTTONBOX_SPREAD,
194 : VCL_BUTTONBOX_EDGE,
195 : VCL_BUTTONBOX_START,
196 : VCL_BUTTONBOX_END,
197 : VCL_BUTTONBOX_CENTER
198 : };
199 :
200 0 : class VCL_DLLPUBLIC VclButtonBox : public VclBox
201 : {
202 : public:
203 0 : VclButtonBox(Window *pParent, int nSpacing)
204 : : VclBox(pParent, true, nSpacing)
205 : , m_eLayoutStyle(VCL_BUTTONBOX_DEFAULT_STYLE)
206 0 : , m_bHomogeneousGroups(false)
207 : {
208 0 : }
209 0 : void set_layout(VclButtonBoxStyle eStyle)
210 : {
211 0 : m_eLayoutStyle = eStyle;
212 0 : }
213 : VclButtonBoxStyle get_layout() const
214 : {
215 : return m_eLayoutStyle;
216 : }
217 : virtual bool set_property(const OString &rKey, const OString &rValue);
218 : protected:
219 : virtual Size calculateRequisition() const;
220 : virtual void setAllocation(const Size &rAllocation);
221 : private:
222 : VclButtonBoxStyle m_eLayoutStyle;
223 : bool m_bHomogeneousGroups;
224 : struct Requisition
225 : {
226 : sal_uInt16 m_nMainGroupChildren;
227 : sal_uInt16 m_nSubGroupChildren;
228 : Size m_aMainGroupSize;
229 : Size m_aSubGroupSize;
230 0 : Requisition()
231 : : m_nMainGroupChildren(0)
232 0 : , m_nSubGroupChildren(0)
233 : {
234 0 : }
235 : };
236 : Requisition calculatePrimarySecondaryRequisitions() const;
237 : Size addReqGroups(const VclButtonBox::Requisition &rReq) const;
238 : };
239 :
240 0 : class VCL_DLLPUBLIC VclVButtonBox : public VclButtonBox
241 : {
242 : public:
243 0 : VclVButtonBox(Window *pParent, int nSpacing = 0)
244 0 : : VclButtonBox(pParent, nSpacing)
245 : {
246 0 : }
247 : protected:
248 0 : virtual long getPrimaryDimension(const Size &rSize) const
249 : {
250 0 : return rSize.getHeight();
251 : }
252 0 : virtual void setPrimaryDimension(Size &rSize, long nHeight) const
253 : {
254 0 : rSize.setHeight(nHeight);
255 0 : }
256 0 : virtual long getPrimaryCoordinate(const Point &rPos) const
257 : {
258 0 : return rPos.getY();
259 : }
260 0 : virtual void setPrimaryCoordinate(Point &rPos, long nPos) const
261 : {
262 0 : rPos.setY(nPos);
263 0 : }
264 0 : virtual long getSecondaryDimension(const Size &rSize) const
265 : {
266 0 : return rSize.getWidth();
267 : }
268 0 : virtual void setSecondaryDimension(Size &rSize, long nWidth) const
269 : {
270 0 : rSize.setWidth(nWidth);
271 0 : }
272 0 : virtual long getSecondaryCoordinate(const Point &rPos) const
273 : {
274 0 : return rPos.getX();
275 : }
276 0 : virtual void setSecondaryCoordinate(Point &rPos, long nPos) const
277 : {
278 0 : rPos.setX(nPos);
279 0 : }
280 0 : virtual bool getPrimaryDimensionChildExpand(const Window &rWindow) const
281 : {
282 0 : return rWindow.get_expand() || rWindow.get_vexpand();
283 : }
284 : };
285 :
286 0 : class VCL_DLLPUBLIC VclHButtonBox : public VclButtonBox
287 : {
288 : public:
289 0 : VclHButtonBox(Window *pParent, int nSpacing = 0)
290 0 : : VclButtonBox(pParent, nSpacing)
291 : {
292 0 : }
293 : protected:
294 0 : virtual long getPrimaryDimension(const Size &rSize) const
295 : {
296 0 : return rSize.getWidth();
297 : }
298 0 : virtual void setPrimaryDimension(Size &rSize, long nWidth) const
299 : {
300 0 : rSize.setWidth(nWidth);
301 0 : }
302 0 : virtual long getPrimaryCoordinate(const Point &rPos) const
303 : {
304 0 : return rPos.getX();
305 : }
306 0 : virtual void setPrimaryCoordinate(Point &rPos, long nPos) const
307 : {
308 0 : rPos.setX(nPos);
309 0 : }
310 0 : virtual long getSecondaryDimension(const Size &rSize) const
311 : {
312 0 : return rSize.getHeight();
313 : }
314 0 : virtual void setSecondaryDimension(Size &rSize, long nHeight) const
315 : {
316 0 : rSize.setHeight(nHeight);
317 0 : }
318 0 : virtual long getSecondaryCoordinate(const Point &rPos) const
319 : {
320 0 : return rPos.getY();
321 : }
322 0 : virtual void setSecondaryCoordinate(Point &rPos, long nPos) const
323 : {
324 0 : rPos.setY(nPos);
325 0 : }
326 0 : virtual bool getPrimaryDimensionChildExpand(const Window &rWindow) const
327 : {
328 0 : return rWindow.get_expand() || rWindow.get_hexpand();
329 : }
330 : };
331 :
332 0 : class VCL_DLLPUBLIC VclGrid : public VclContainer
333 : {
334 : private:
335 : bool m_bRowHomogeneous;
336 : bool m_bColumnHomogeneous;
337 : int m_nRowSpacing;
338 : int m_nColumnSpacing;
339 :
340 : struct GridEntry
341 : {
342 : Window *pChild;
343 : sal_Int32 nSpanWidth;
344 : sal_Int32 nSpanHeight;
345 0 : GridEntry()
346 : : pChild(0)
347 : , nSpanWidth(0)
348 0 : , nSpanHeight(0)
349 : {
350 0 : }
351 : };
352 :
353 : typedef boost::multi_array<GridEntry, 2> array_type;
354 :
355 : struct ExtendedGridEntry : GridEntry
356 : {
357 : int x;
358 : int y;
359 0 : ExtendedGridEntry()
360 : : x(-1)
361 0 : , y(-1)
362 : {
363 0 : }
364 : };
365 :
366 : typedef boost::multi_array<ExtendedGridEntry, 2> ext_array_type;
367 :
368 : array_type assembleGrid() const;
369 : bool isNullGrid(const array_type& A) const;
370 : public:
371 : struct Value
372 : {
373 : long m_nValue;
374 : bool m_bExpand;
375 0 : Value() : m_nValue(0), m_bExpand(false) {}
376 : };
377 : private:
378 : void calcMaxs(const array_type &A, std::vector<Value> &rWidths, std::vector<Value> &rHeights) const;
379 :
380 : virtual Size calculateRequisition() const;
381 : virtual void setAllocation(const Size &rAllocation);
382 : public:
383 0 : VclGrid(Window *pParent)
384 : : VclContainer(pParent)
385 : , m_bRowHomogeneous(false), m_bColumnHomogeneous(false)
386 0 : , m_nRowSpacing(0), m_nColumnSpacing(0)
387 : {
388 0 : }
389 0 : void set_row_homogeneous(bool bHomogeneous)
390 : {
391 0 : m_bRowHomogeneous = bHomogeneous;
392 0 : }
393 0 : void set_column_homogeneous(bool bHomogeneous)
394 : {
395 0 : m_bColumnHomogeneous = bHomogeneous;
396 0 : }
397 0 : bool get_row_homogeneous() const
398 : {
399 0 : return m_bRowHomogeneous;
400 : }
401 0 : bool get_column_homogeneous() const
402 : {
403 0 : return m_bColumnHomogeneous;
404 : }
405 0 : void set_row_spacing(int nSpacing)
406 : {
407 0 : m_nRowSpacing = nSpacing;
408 0 : }
409 0 : void set_column_spacing(int nSpacing)
410 : {
411 0 : m_nColumnSpacing = nSpacing;
412 0 : }
413 0 : int get_row_spacing() const
414 : {
415 0 : return m_nRowSpacing;
416 : }
417 0 : int get_column_spacing() const
418 : {
419 0 : return m_nColumnSpacing;
420 : }
421 : virtual bool set_property(const OString &rKey, const OString &rValue);
422 : };
423 :
424 : VCL_DLLPUBLIC void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTop,
425 : sal_Int32 nWidth = 1, sal_Int32 nHeight = 1);
426 :
427 0 : class VCL_DLLPUBLIC VclBin : public VclContainer
428 : {
429 : public:
430 0 : VclBin(Window *pParent, WinBits nStyle = WB_HIDE)
431 0 : : VclContainer(pParent, nStyle)
432 : {
433 0 : }
434 : virtual Window *get_child();
435 : virtual const Window *get_child() const;
436 : virtual Size calculateRequisition() const;
437 : virtual void setAllocation(const Size &rAllocation);
438 : };
439 :
440 0 : class VCL_DLLPUBLIC VclFrame : public VclBin
441 : {
442 : public:
443 0 : VclFrame(Window *pParent) : VclBin(pParent) {}
444 : void set_label(const OUString &rLabel);
445 : Window *get_label_widget();
446 : const Window *get_label_widget() const;
447 : protected:
448 : virtual Size calculateRequisition() const;
449 : virtual void setAllocation(const Size &rAllocation);
450 : };
451 :
452 0 : class VCL_DLLPUBLIC VclAlignment : public VclBin
453 : {
454 : public:
455 0 : VclAlignment(Window *pParent)
456 : : VclBin(pParent)
457 : , m_nBottomPadding(0)
458 : , m_nLeftPadding(0)
459 : , m_nRightPadding(0)
460 : , m_nTopPadding(0)
461 : , m_fXAlign(0.0)
462 : , m_fXScale(1.0)
463 : , m_fYAlign(0.0)
464 0 : , m_fYScale(1.0)
465 : {
466 0 : }
467 : virtual bool set_property(const OString &rKey, const OString &rValue);
468 : protected:
469 : virtual Size calculateRequisition() const;
470 : virtual void setAllocation(const Size &rAllocation);
471 : private:
472 : sal_Int32 m_nBottomPadding;
473 : sal_Int32 m_nLeftPadding;
474 : sal_Int32 m_nRightPadding;
475 : sal_Int32 m_nTopPadding;
476 : float m_fXAlign;
477 : float m_fXScale;
478 : float m_fYAlign;
479 : float m_fYScale;
480 : };
481 :
482 0 : class VCL_DLLPUBLIC VclExpander : public VclBin
483 : {
484 : public:
485 0 : VclExpander(Window *pParent)
486 : : VclBin(pParent)
487 : , m_bResizeTopLevel(true)
488 0 : , m_aDisclosureButton(this)
489 : {
490 0 : m_aDisclosureButton.SetToggleHdl(LINK(this, VclExpander, ClickHdl));
491 0 : m_aDisclosureButton.Show();
492 0 : }
493 : virtual Window *get_child();
494 : virtual const Window *get_child() const;
495 : virtual bool set_property(const OString &rKey, const OString &rValue);
496 : protected:
497 : virtual Size calculateRequisition() const;
498 : virtual void setAllocation(const Size &rAllocation);
499 : private:
500 : bool m_bResizeTopLevel;
501 : DisclosureButton m_aDisclosureButton;
502 : DECL_DLLPRIVATE_LINK(ClickHdl, DisclosureButton* pBtn);
503 : };
504 :
505 : //This is a work in progress, so if you want to put something inside a
506 : //scrolled window that doesn't handle its own scrolling, then you may need to
507 : //implement this fully
508 0 : class VCL_DLLPUBLIC VclScrolledWindow : public VclBin
509 : {
510 : public:
511 0 : VclScrolledWindow(Window *pParent, WinBits nStyle = WB_HIDE | WB_AUTOHSCROLL | WB_AUTOVSCROLL)
512 : : VclBin(pParent, nStyle)
513 : , m_aVScroll(this, WB_HIDE | WB_VERT)
514 0 : , m_aHScroll(this, WB_HIDE | WB_HORZ)
515 : {
516 0 : SetType(WINDOW_SCROLLWINDOW);
517 0 : }
518 : virtual Window *get_child();
519 : virtual const Window *get_child() const;
520 : virtual bool set_property(const OString &rKey, const OString &rValue);
521 0 : ScrollBar& getVertScrollBar() { return m_aVScroll; }
522 : ScrollBar& getHorzScrollBar() { return m_aHScroll; }
523 : Size getVisibleChildSize() const;
524 : protected:
525 : virtual Size calculateRequisition() const;
526 : virtual void setAllocation(const Size &rAllocation);
527 : private:
528 : ScrollBar m_aVScroll;
529 : ScrollBar m_aHScroll;
530 : };
531 :
532 : // retro-fitting utilities //
533 :
534 : //Get a Size which is large enough to contain all children with
535 : //an equal amount of space at top left and bottom right
536 : Size getLegacyBestSizeForChildren(const Window &rWindow);
537 :
538 : //Get first parent which is not a layout widget
539 : Window* getNonLayoutParent(Window *pParent);
540 :
541 : //Get first real parent which is not a layout widget
542 : Window* getNonLayoutRealParent(Window *pParent);
543 :
544 : //return true if this window and its stack of containers are all shown
545 : bool isVisibleInLayout(const Window *pWindow);
546 :
547 : //return true if this window and its stack of containers are all enabled
548 : bool isEnabledInLayout(const Window *pWindow);
549 :
550 : //Get first window of a pTopLevel window as
551 : //if any intermediate layout widgets didn't exist
552 : //i.e. acts like pChild = pChild->GetWindow(WINDOW_FIRSTCHILD);
553 : //in a flat hierarchy where dialogs only have one layer
554 : //of children
555 : Window* firstLogicalChildOfParent(Window *pTopLevel);
556 :
557 : //Get next window after pChild of a pTopLevel window as
558 : //if any intermediate layout widgets didn't exist
559 : //i.e. acts like pChild = pChild->GetWindow(WINDOW_NEXT);
560 : //in a flat hierarchy where dialogs only have one layer
561 : //of children
562 : Window* nextLogicalChildOfParent(Window *pTopLevel, Window *pChild);
563 :
564 : //Get previous window before pChild of a pTopLevel window as
565 : //if any intermediate layout widgets didn't exist
566 : //i.e. acts like pChild = pChild->GetWindow(WINDOW_PREV);
567 : //in a flat hierarchy where dialogs only have one layer
568 : //of children
569 : Window* prevLogicalChildOfParent(Window *pTopLevel, Window *pChild);
570 :
571 44672 : inline bool isContainerWindow(const Window &rWindow)
572 : {
573 44672 : WindowType eType = rWindow.GetType();
574 44672 : return (eType == WINDOW_CONTAINER || eType == WINDOW_SCROLLWINDOW);
575 : }
576 :
577 : #endif
578 :
579 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|