xref: /trunk/main/svtools/source/inc/svimpicn.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #ifndef _SVIMPICN_HXX
28 #define _SVIMPICN_HXX
29 
30 #ifndef _VIRDEV_HXX
31 #include <vcl/virdev.hxx>
32 #endif
33 
34 #ifndef _SCRBAR_HXX
35 #include <vcl/scrbar.hxx>
36 #endif
37 #include <limits.h>
38 
39 class SvLBoxEntry;
40 class SvLBoxTreeList;
41 class SvImpIconView;
42 class ImpIcnCursor;
43 class SvPtrarr;
44 
45 #define PAINTFLAG_HOR_CENTERED  0x0001
46 #define PAINTFLAG_VER_CENTERED  0x0002
47 
48 #define SELRECT_BORDER_OFFS -7
49 // Flags
50 #define F_VER_SBARSIZE_WITH_HBAR        0x00000001
51 #define F_HOR_SBARSIZE_WITH_VBAR        0x00000002
52 #define F_IGNORE_NEXT_MOUSEMOVE         0x00000004  // OS/2 only
53 #define F_ENTRY_REMOVED                 0x00000008
54 // ist gesetzt, wenn nach Clear oder Ctor mind. einmal gepaintet wurde
55 #define F_PAINTED                       0x00000010
56 #define F_ADD_MODE                      0x00000020
57 #define F_MOVING_SIBLING                0x00000040
58 #define F_SELRECT_VISIBLE               0x00000080
59 #define F_CMD_ARRIVED                   0x00000100
60 #define F_DRAG_SOURCE                   0x00000200
61 #define F_GRIDMODE                      0x00000400
62 // beim Einfuegen eines Eintrags ergibt sich dessen Position
63 // durch simples Addieren auf die Position des zuletzt eingefuegten Eintrags
64 #define F_GRID_INSERT                   0x00000800
65 #define F_DOWN_CTRL                     0x00001000
66 #define F_DOWN_DESELECT                 0x00002000
67 // Hack fuer D&D: Hintergrund des Entries nicht painten
68 #define F_NO_EMPHASIS                   0x00004000
69 // Selektion per Gummiband
70 #define F_RUBBERING                     0x00008000
71 #define F_START_EDITTIMER_IN_MOUSEUP    0x00010000
72 
73 class SvImpIconView
74 {
75     friend class ImpIcnCursor;
76     ScrollBar       aVerSBar;
77     ScrollBar       aHorSBar;
78     Rectangle       aCurSelectionRect;
79     SvPtrarr        aSelectedRectList;
80     MouseEvent      aMouseMoveEvent;
81     Timer           aEditTimer;  // fuer Inplace-Editieren
82     Timer           aMouseMoveTimer; // generiert MouseMoves bei Gummibandselektion
83     // Boundrect des zuletzt eingefuegten Entries
84     Rectangle       aPrevBoundRect;
85     Size            aOutputSize;        // Pixel
86     Size            aVirtOutputSize;    // expandiert automatisch
87     Point           aDDLastEntryPos;
88     Point           aDDLastRectPos;
89 
90     SvLBoxTreeList* pModel;
91     SvIconView*     pView;
92     ImpIcnCursor*   pImpCursor;
93     long            nMaxVirtWidth;      // max.breite aVirtOutputSize
94     SvPtrarr*       pZOrderList;
95     long            nGridDX,
96                     nGridDY;
97     long            nHorSBarHeight,
98                     nVerSBarWidth;
99     int             nViewMode;
100     long            nHorDist;
101     long            nVerDist;
102     long            nMaxBmpWidth;
103     long            nMaxBmpHeight;
104     long            nMaxTextWidth;
105     long            nMaxBoundHeight; // Hoehe des hoechsten BoundRects
106     sal_uLong           nFlags;
107     sal_uLong           nCurUserEvent;
108     SvLBoxEntry*    pCurParent;
109     SvLBoxEntry*    pCursor;
110     SvLBoxEntry*    pNextCursor; // wird in MovingEntry gesetzt und ist
111                                  // nur in EntryMoved gueltig!
112     SvLBoxEntry*    pDDRefEntry;
113     VirtualDevice*  pDDDev;
114     VirtualDevice*  pDDBufDev;
115     VirtualDevice*  pDDTempDev;
116 
117     SvIconViewTextMode eTextMode;
118     sal_Bool            bMustRecalcBoundingRects;
119 
120     void            CheckAllSizes();
121     void            CheckSizes( SvLBoxEntry* pEntry,
122                         const SvIcnVwDataEntry* pViewData = 0  );
123     void            ShowCursor( sal_Bool bShow );
124 
125     void            SetNextEntryPos(const Point& rPos);
126     Point           FindNextEntryPos( const Size& rBoundSize );
127     void            ImpArrange();
128     void            AdjustVirtSize( const Rectangle& );
129     void            ResetVirtSize();
130     void            CheckScrollBars();
131 
132                     DECL_LINK( ScrollUpDownHdl, ScrollBar * );
133                     DECL_LINK( ScrollLeftRightHdl, ScrollBar * );
134                     DECL_LINK( MouseMoveTimeoutHdl, Timer* );
135                     DECL_LINK( EditTimeoutHdl, Timer* );
136                     DECL_LINK( UserEventHdl, void* );
137     void            AdjustScrollBars();
138     void            PositionScrollBars( long nRealWidth, long nRealHeight );
139     void            CalcDocPos( Point& aMousePos );
140     sal_Bool            GetResizeRect( Rectangle& );
141     void            PaintResizeRect( const Rectangle& );
142     SvLBoxEntry*    GetNewCursor();
143     void            ToggleSelection( SvLBoxEntry* );
144     void            DeselectAllBut( SvLBoxEntry* );
145     void            Center( SvLBoxEntry* pEntry, SvIcnVwDataEntry* ) const;
146     void            StopEditTimer() { aEditTimer.Stop(); }
147     void            StartEditTimer() { aEditTimer.Start(); }
148     void            ImpHideDDIcon();
149     void            ImpDrawXORRect( const Rectangle& rRect );
150     void            AddSelectedRect( const Rectangle&, short nOffset = SELRECT_BORDER_OFFS );
151     void            ClearSelectedRectList();
152     Rectangle       CalcMaxTextRect( const SvLBoxEntry* pEntry,
153                                     const SvIcnVwDataEntry* pViewData ) const;
154 
155     void            ClipAtVirtOutRect( Rectangle& rRect ) const;
156     void            AdjustAtGrid( const SvPtrarr& rRow, SvLBoxEntry* pStart=0 );
157     Point           AdjustAtGrid(
158                         const Rectangle& rCenterRect, // "Schwerpunkt" des Objekts (typ. Bmp-Rect)
159                         const Rectangle& rBoundRect ) const;
160     SvIconViewTextMode GetEntryTextModeSmart( const SvLBoxEntry* pEntry,
161                         const SvIcnVwDataEntry* pViewData ) const;
162 
163     sal_Bool            CheckVerScrollBar();
164     sal_Bool            CheckHorScrollBar();
165     void            CancelUserEvent();
166 
167 public:
168 
169                     SvImpIconView( SvIconView* pView, SvLBoxTreeList*, WinBits nWinStyle );
170                     ~SvImpIconView();
171 
172     void            Clear( sal_Bool bInCtor = sal_False );
173     void            SetStyle( const WinBits i_nWinStyle );
174     void            SetModel( SvLBoxTreeList* pTree, SvLBoxEntry* pParent )
175                         { pModel = pTree; SetCurParent(pParent); }
176     void            EntryInserted( SvLBoxEntry*);
177     void            RemovingEntry( SvLBoxEntry* pEntry );
178     void            EntryRemoved();
179     void            MovingEntry( SvLBoxEntry* pEntry );
180     void            EntryMoved( SvLBoxEntry* pEntry );
181     void            TreeInserted( SvLBoxEntry* pEntry );
182     void            ChangedFont();
183     void            ModelHasEntryInvalidated( SvListEntry* );
184     void            EntryExpanded( SvLBoxEntry* pEntry );
185     void            EntryCollapsed( SvLBoxEntry* pEntry );
186     void            CollapsingEntry( SvLBoxEntry* pEntry );
187     void            EntrySelected( SvLBoxEntry*, sal_Bool bSelect );
188 
189     void            Paint( const Rectangle& rRect );
190     void            RepaintSelectionItems();
191     void            MouseButtonDown( const MouseEvent& );
192     void            MouseButtonUp( const MouseEvent& );
193     void            MouseMove( const MouseEvent&);
194     sal_Bool            KeyInput( const KeyEvent& );
195     void            Resize();
196     void            GetFocus();
197     void            LoseFocus();
198     void            UpdateAll();
199     void            PaintEntry( SvLBoxEntry* pEntry,
200                         SvIcnVwDataEntry* pViewData = 0 );
201     void            PaintEntry( SvLBoxEntry*, const Point&,
202                         SvIcnVwDataEntry* pViewData = 0, OutputDevice* pOut = 0);
203     void            SetEntryPosition( SvLBoxEntry* pEntry, const Point& rPos,
204                                       sal_Bool bAdjustRow = sal_False,
205                                       sal_Bool bCheckScrollBars = sal_False );
206     void            InvalidateEntry( SvLBoxEntry* );
207     void            ViewDataInitialized( SvLBoxEntry* pEntry );
208     SvLBoxItem*     GetItem( SvLBoxEntry*, const Point& rAbsPos );
209 
210     void            SetNoSelection();
211     void            SetDragDropMode( DragDropMode eDDMode );
212     void            SetSelectionMode( SelectionMode eSelMode  );
213 
214     void            SttDrag( const Point& rPos );
215     void            EndDrag();
216 
217     SvLBoxEntry*    GetCurEntry() const { return pCursor; }
218     void            SetCursor( SvLBoxEntry* );
219 
220     sal_Bool            IsEntryInView( SvLBoxEntry* );
221     SvLBoxEntry*    GetEntry( const Point& rDocPos );
222     SvLBoxEntry*    GetNextEntry( const Point& rDocPos, SvLBoxEntry* pCurEntry );
223     SvLBoxEntry*    GetPrevEntry( const Point& rDocPos, SvLBoxEntry* pCurEntry  );
224 
225     Point           GetEntryPosition( SvLBoxEntry* );
226     void            MakeVisible( SvLBoxEntry* pEntry );
227 
228     void            Arrange();
229 
230     void            SetSpaceBetweenEntries( long nHor, long Ver );
231     long            GetHorSpaceBetweenEntries() const { return nHorDist; }
232     long            GetVerSpaceBetweenEntries() const { return nVerDist; }
233 
234     Rectangle       CalcFocusRect( SvLBoxEntry* );
235 
236     Rectangle       CalcBmpRect( SvLBoxEntry*, const Point* pPos = 0,
237                         SvIcnVwDataEntry* pViewData=0 );
238     Rectangle       CalcTextRect( SvLBoxEntry*, SvLBoxString* pItem = 0,
239                                   const Point* pPos = 0,
240                                   sal_Bool bForInplaceEdit = sal_False,
241                                   SvIcnVwDataEntry* pViewData = 0 );
242 
243     long            CalcBoundingWidth( SvLBoxEntry*, const SvIcnVwDataEntry* pViewData = 0) const;
244     long            CalcBoundingHeight( SvLBoxEntry*, const SvIcnVwDataEntry* pViewData= 0 ) const;
245     Size            CalcBoundingSize( SvLBoxEntry*,
246                         SvIcnVwDataEntry* pViewData = 0 ) const;
247     void            FindBoundingRect( SvLBoxEntry* pEntry,
248                         SvIcnVwDataEntry* pViewData = 0 );
249     // berechnet alle BoundRects neu
250     void            RecalcAllBoundingRects();
251     // berechnet alle ungueltigen BoundRects neu
252     void            RecalcAllBoundingRectsSmart();
253     const Rectangle&  GetBoundingRect( SvLBoxEntry*,
254                         SvIcnVwDataEntry* pViewData=0);
255     void            InvalidateBoundingRect( SvLBoxEntry* );
256     void            InvalidateBoundingRect( Rectangle& rRect ) { rRect.Right() = LONG_MAX; }
257     sal_Bool            IsBoundingRectValid( const Rectangle& rRect ) const { return (sal_Bool)( rRect.Right() != LONG_MAX ); }
258 
259     void            PaintEmphasis( const Rectangle&, sal_Bool bSelected,
260                                    sal_Bool bCursored, OutputDevice* pOut = 0 );
261     void            PaintItem( const Rectangle& rRect, SvLBoxItem* pItem,
262                         SvLBoxEntry* pEntry, sal_uInt16 nPaintFlags, OutputDevice* pOut = 0 );
263     // berechnet alle BoundingRects neu, wenn bMustRecalcBoundingRects == sal_True
264     void            CheckBoundingRects() { if (bMustRecalcBoundingRects) RecalcAllBoundingRects(); }
265     // berechnet alle invalidierten BoundingRects neu
266     void            UpdateBoundingRects();
267     void            ShowTargetEmphasis( SvLBoxEntry* pEntry, sal_Bool bShow );
268     SvLBoxEntry*    GetDropTarget( const Point& rPosPixel );
269     sal_Bool            NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
270                         SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos );
271     sal_Bool            NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
272                         SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos );
273 
274     void            WriteDragServerInfo( const Point&, SvLBoxDDInfo* );
275     void            ReadDragServerInfo( const Point&, SvLBoxDDInfo* );
276     void            ToTop( SvLBoxEntry* );
277 
278     void            SetCurParent( SvLBoxEntry* pNewParent );
279     SvLBoxEntry*    GetCurParent() const { return pCurParent; }
280     sal_uInt16          GetSelectionCount() const;
281     void            SetGrid( long nDX, long nDY );
282     void            Scroll( long nDeltaX, long nDeltaY, sal_Bool bScrollBar = sal_False );
283     const Size&     GetItemSize( SvIconView* pView, SvLBoxEntry*, SvLBoxItem*,
284                         const SvIcnVwDataEntry* pViewData = 0 ) const;
285     void            PrepareCommandEvent( const Point& rPt );
286 
287     void            HideDDIcon();
288     void            ShowDDIcon( SvLBoxEntry* pRefEntry, const Point& rPos );
289     void            HideShowDDIcon( SvLBoxEntry* pRefEntry, const Point& rPos );
290 
291     SvLBoxEntry*    mpViewData;
292 
293     sal_Bool            IsOver( SvPtrarr* pSelectedRectList, const Rectangle& rEntryBoundRect ) const;
294     void            SelectRect( const Rectangle&, sal_Bool bAdd = sal_True,
295                         SvPtrarr* pOtherRects = 0,
296                         short nOffs = SELRECT_BORDER_OFFS );
297     void            DrawSelectionRect( const Rectangle& );
298     void            HideSelectionRect();
299     void            CalcScrollOffsets( const Point& rRefPosPixel,
300                         long& rX, long& rY, sal_Bool bDragDrop = sal_False,
301                         sal_uInt16 nBorderWidth = 10 );
302     void            EndTracking();
303     sal_Bool            IsTextHit( SvLBoxEntry* pEntry, const Point& rDocPos );
304     void            MakeVisible( const Rectangle& rDocPos,sal_Bool bInScrollBarEvent=sal_False);
305     void            AdjustAtGrid( SvLBoxEntry* pStart = 0 );
306     void            SetTextMode( SvIconViewTextMode, SvLBoxEntry* pEntry = 0 );
307     SvIconViewTextMode GetTextMode( const SvLBoxEntry* pEntry = 0,
308                     const SvIcnVwDataEntry* pViewData = 0 ) const;
309     void            ShowFocusRect( const SvLBoxEntry* pEntry );
310 };
311 
312 inline void SvImpIconView::MakeVisible( SvLBoxEntry* pEntry )
313 {
314     const Rectangle& rRect = GetBoundingRect( pEntry );
315     MakeVisible( rRect );
316 }
317 
318 #endif // #ifndef _SVIMPICN_HXX
319 
320 
321