summaryrefslogtreecommitdiff
path: root/sw/inc/postit.hxx
blob: e5484741d908d87558f8e125e68968ad5908df4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _POSTIT_HXX
#define _POSTIT_HXX

#include <postithelper.hxx>

#include <vcl/window.hxx>
#include <swrect.hxx>
#include <svx/sdr/overlay/overlayobject.hxx>

#include <tools/datetime.hxx>
#include <tools/date.hxx>

#include <vcl/lineinfo.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <editeng/editstat.hxx>

class SwPostItMgr;
class SwPostItField;
class SwFmtFld;
class OutlinerView;
class Outliner;
class ScrollBar;
class SwEditWin;
class SwView;
class SwPostIt;
class Edit;
class MultiLineEdit;
class PopupMenu;
class SvxLanguageItem;
class SwRedline;
class OutlinerParaObject;

#define ANKORLINE_WIDTH			1

enum AnkorState {AS_ALL, AS_START, AS_END,AS_TRI};

class SwPostItAnkor: public sdr::overlay::OverlayObjectWithBasePosition
{
    protected:
        /*						  6------------7
             1					 /
            /4\ ---------------5
           2 - 3
        */

        basegfx::B2DPoint						maSecondPosition;
        basegfx::B2DPoint						maThirdPosition;
        basegfx::B2DPoint						maFourthPosition;
        basegfx::B2DPoint						maFifthPosition;
        basegfx::B2DPoint						maSixthPosition;
        basegfx::B2DPoint						maSeventhPosition;

        // helpers to fill and reset geometry
        void implEnsureGeometry();
        void implResetGeometry();

        // geometry creation for OverlayObject
        virtual drawinglayer::primitive2d::Primitive2DSequence createOverlayObjectPrimitive2DSequence();

    private:
        // object's geometry
        basegfx::B2DPolygon                     maTriangle;
        basegfx::B2DPolygon                     maLine;
        basegfx::B2DPolygon						maLineTop;
        unsigned long							mHeight;
        AnkorState								mAnkorState;

        // bitfield
        unsigned								mbShadowedEffect : 1;
        unsigned								mbLineSolid : 1;

    public:
        SwPostItAnkor(const basegfx::B2DPoint& rBasePos,
                        const basegfx::B2DPoint& rSecondPos,
                        const basegfx::B2DPoint& rThirdPos,
                        const basegfx::B2DPoint& rFourthPos,
                        const basegfx::B2DPoint& rFifthPos,
                        const basegfx::B2DPoint& rSixthPos,
                        const basegfx::B2DPoint& rSeventhPos,
                        Color aBaseColor,
                        bool bShadowedEffect,
                        bool bLineSolid);
        virtual ~SwPostItAnkor();

        const basegfx::B2DPoint& GetSecondPosition() const { return maSecondPosition; }
        const basegfx::B2DPoint& GetThirdPosition() const { return maThirdPosition; }
        const basegfx::B2DPoint& GetFourthPosition() const { return maFourthPosition; }
        const basegfx::B2DPoint& GetFifthPosition() const { return maFifthPosition; }
        const basegfx::B2DPoint& GetSixthPosition() const { return maSixthPosition; }
        const basegfx::B2DPoint& GetSeventhPosition() const { return maSeventhPosition; }

        void SetAllPosition(const basegfx::B2DPoint& rPoint1, const basegfx::B2DPoint& rPoint2, const basegfx::B2DPoint& rPoint3,
            const basegfx::B2DPoint& rPoint4, const basegfx::B2DPoint& rPoint5, const basegfx::B2DPoint& rPoint6, const basegfx::B2DPoint& rPoint7);
        void SetTriPosition(const basegfx::B2DPoint& rPoint1,const basegfx::B2DPoint& rPoint2,const basegfx::B2DPoint& rPoint3,
                                    const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5);
        void SetSixthPosition(const basegfx::B2DPoint& rNew);
        void SetSeventhPosition(const basegfx::B2DPoint& rNew);

        bool getLineSolid() const { return mbLineSolid; }
        void setLineSolid(bool bNew);

        void SetHeight(const unsigned long aHeight) {mHeight = aHeight;};

        bool getShadowedEffect() const { return mbShadowedEffect; }

        void SetAnkorState(AnkorState aState);
        AnkorState GetAnkorState() const {return mAnkorState;} 
};

enum ShadowState {SS_NORMAL, SS_VIEW, SS_EDIT};

class SwPostItShadow: public sdr::overlay::OverlayObjectWithBasePosition
{
    protected:
        // geometry creation for OverlayObject
        virtual drawinglayer::primitive2d::Primitive2DSequence createOverlayObjectPrimitive2DSequence();

    private:
        basegfx::B2DPoint						maSecondPosition;
        ShadowState mShadowState;

    public:
        SwPostItShadow(const basegfx::B2DPoint& rBasePos, const basegfx::B2DPoint& rSecondPosition, Color aBaseColor,ShadowState aState);
        virtual ~SwPostItShadow();

        void SetShadowState(ShadowState aState);
        ShadowState GetShadowState() {return mShadowState;}

        const basegfx::B2DPoint& GetSecondPosition() const { return maSecondPosition; }
        void SetSecondPosition(const basegfx::B2DPoint& rNew);
        void SetPosition(const basegfx::B2DPoint& rPoint1,const basegfx::B2DPoint& rPoint2);
};

class PostItTxt : public Window
{
    private:
        OutlinerView*	mpOutlinerView;
        SwMarginWin*	mpMarginWin;

        bool			mMouseOver;
        BOOL			mbShowPopup;

    protected:
        virtual void	Paint( const Rectangle& rRect);
        virtual void	KeyInput( const KeyEvent& rKeyEvt );
        virtual void	MouseMove( const MouseEvent& rMEvt );
        virtual void	MouseButtonDown( const MouseEvent& rMEvt );
        virtual void	MouseButtonUp( const MouseEvent& rMEvt );
        virtual void	Command( const CommandEvent& rCEvt );
        virtual void	DataChanged( const DataChangedEvent& aData);
        virtual void 	LoseFocus();
        virtual void	RequestHelp(const HelpEvent &rEvt);
        virtual XubString GetSurroundingText() const;
        virtual Selection GetSurroundingTextSelection() const;

        DECL_LINK( Select, Menu* );

    public:
            PostItTxt(Window* pParent, WinBits nBits);
            ~PostItTxt();

            virtual void 	GetFocus();
            void			SetTextView( OutlinerView* aEditView ) {	mpOutlinerView = aEditView;	}

            DECL_LINK( WindowEventListener, VclSimpleEvent* );
            DECL_LINK( OnlineSpellCallback, SpellCallbackInfo*);
};

typedef sal_Int64 SwPostItBits;

#define PB_Preview ((SwPostItBits)0x00000001)


class SwMarginWin : public Window
{
    private:
        ULONG			mnEventId;
        SwView*			mpView;
        sdr::overlay::OverlayManager* pOverlayManager;
        OutlinerView*	mpOutlinerView;
        Outliner*		mpOutliner;
        PostItTxt*		mpPostItTxt;
        MultiLineEdit*	mpMeta;
        ScrollBar*		mpVScrollbar;
        SwPostItAnkor*  mpAnkor;
        SwPostItShadow* mpShadow;
        SwPostItMgr*	mpMgr;
        bool			mbMeta;
        Color			mColorAnkor;
        Color			mColorDark;
        Color			mColorLight;
        basegfx::B2DPolygon aPopupTriangle;
        bool			mbMarginSide;
        Rectangle		mPosSize;
        SwRect			mAnkorRect;
        long			mPageBorder;
        SwPostItBits	nFlags;
        bool			mbMouseOverButton;

    protected:
        bool			mbReadonly;
        PopupMenu*		mpButtonPopup;
        bool			mbIsFollow;
        Rectangle		mRectMetaButton;
        virtual void	DataChanged( const DataChangedEvent& aEvent);
        virtual void 	LoseFocus();
        virtual void	MouseButtonDown( const MouseEvent& rMEvt );
        virtual void	MouseMove( const MouseEvent& rMEvt );
        virtual void	Paint( const Rectangle& rRect);
        virtual void 	GetFocus();
        
        void		SetSizePixel( const Size& rNewSize );
        SfxItemSet	DefaultItem();

        DECL_LINK(ModifyHdl, void*);
        DECL_LINK(ScrollHdl, ScrollBar*);
        DECL_LINK(DeleteHdl, void*);

    public:
        TYPEINFO();
        SwMarginWin( Window* pParent, WinBits nBits, SwPostItMgr* aMgr,SwPostItBits aBits);
        virtual ~SwMarginWin();

        void    SetSize( const Size& rNewSize );
            void    SetPosSizePixelRect( long nX, long nY,long nWidth, long nHeight,const SwRect &aRect,const long PageBorder);
        void            SetPosAndSize();
        void	TranslateTopPosition(const long aAmount);
        virtual void    CheckMetaText();
        
        PostItTxt*	    PostItText()	{ return mpPostItTxt;}
        ScrollBar*		Scrollbar()		{ return mpVScrollbar;}
        SwPostItAnkor*	Ankor()			{ return mpAnkor;}
        SwPostItShadow*	Shadow()		{ return mpShadow;}
        OutlinerView*	View()			{ return mpOutlinerView;}
        SwView*			DocView()		{ return mpView;}
        Outliner*		Engine()		{ return mpOutliner;}
        SwPostItMgr*	Mgr()			{ return mpMgr; }

        SwRect			GetAnkorRect()	{ return mAnkorRect; }
        SwEditWin*		EditWin();
        
        long            GetPostItTextHeight();

        void			SwitchToPostIt(USHORT aDirection);
        //void			SwitchToPostIt(bool aDirection);
        virtual void	SwitchToFieldPos();
        virtual sal_uInt32	MoveCaret() { return 0;};

        virtual void	UpdateData() = 0;
        virtual void	SetPostItText() = 0;
        virtual void	Delete();
        virtual void	GotoPos() = 0;
        virtual void	SetPopup() = 0;

        virtual String	GetAuthor();
        virtual Date	GetDate();
        virtual Time	GetTime();

        void			ExecuteCommand(USHORT nSlot);
        void			InitControls();
            void			HidePostIt();
        void            	DoResize();
        void			ResizeIfNeccessary(long aOldHeight, long aNewHeight);
        void			SetScrollbar();

        void			SetVirtualPosSize( const Point& aPoint, const Size& aSize);
        const Point		VirtualPos()	{ return mPosSize.TopLeft(); }
        const Size		VirtualSize()	{ return mPosSize.GetSize(); }

        void            ShowAnkorOnly(const Point &aPoint);
        void            ShowNote();
        void            HideNote();

        void			ResetAttributes();

        void			SetMarginSide(bool aMarginSide);
        void			SetReadonly(BOOL bSet);
        BOOL			IsReadOnly()		{ return mbReadonly;}
        bool			IsPreview()			{ return nFlags & PB_Preview;}

        void			SetLanguage(const SvxLanguageItem aNewItem);
        virtual SvxLanguageItem	GetLanguage(void);

        void			SetColor(Color aColorDark,Color aColorLight, Color aColorAnkor);
        Color			ColorDark() { return mColorDark; }
        Color			ColorLight() { return mColorLight; }
        void			Rescale();

        void			SetViewState(ShadowState bState);

        bool			IsFollow() { return mbIsFollow; }
        void			SetFollow( bool bIsFollow) { mbIsFollow = bIsFollow;};
        virtual bool	CalcFollow();

        SwMarginWin*	GetTopReplyNote();
        bool			IsAnyStackParentVisible();

        sal_Int32		GetMetaHeight();
        sal_Int32		GetMinimumSizeWithMeta();
        sal_Int32		GetMinimumSizeWithoutMeta();
        sal_Int32		GetMetaButtonAreaWidth();
        sal_Int32		GetScrollbarWidth();

        void			SetSpellChecking();

        void			ToggleInsMode();

        virtual	void	ActivatePostIt();
        virtual void	DeactivatePostIt();

        virtual			SwPostItHelper::SwLayoutStatus GetStatus() { return SwPostItHelper::NONE; }

        virtual bool	IsProtected() {return mbReadonly;};
};

// implementation for change tracking comments, fully functional, but not yet used
/*
class SwRedComment : public SwMarginWin
{
    private:
        SwRedline*		pRedline;

    protected:
        virtual void	MouseButtonDown( const MouseEvent& rMEvt );
    public:
        TYPEINFO();
        SwRedComment( Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits,SwRedline* pRed);
        virtual ~SwRedComment() {};

        virtual void	UpdateData();
        virtual void	SetPostItText();
        virtual void	Delete();
        virtual void	GotoPos();
        virtual void	SetPopup();
        virtual void	ActivatePostIt();
        virtual void	DeactivatePostIt();

        virtual String	GetAuthor();
        virtual Date	GetDate();
        virtual Time	GetTime();		

        virtual bool	IsProtected();
};
*/
class SwPostIt : public SwMarginWin
{
    private:
        SwFmtFld*		mpFmtFld;
        SwPostItField*  mpFld;
        SwPostItHelper::SwLayoutStatus mStatus;
        Color			mChangeColor;

    protected:
        virtual void	MouseButtonDown( const MouseEvent& rMEvt );

    public:
        TYPEINFO();
        SwPostIt( Window* pParent, WinBits nBits,SwFmtFld* aField,SwPostItMgr* aMgr,SwPostItBits aBits);
        virtual ~SwPostIt() {};

        virtual void	UpdateData();
        virtual void	SetPostItText();
        virtual void	Delete();
        virtual void	GotoPos();
        virtual void	SetPopup();

        virtual String	GetAuthor();
        virtual Date	GetDate();
        virtual Time	GetTime();

        virtual	sal_uInt32	MoveCaret();

        void			SetChangeTracking(SwPostItHelper::SwLayoutStatus& aStatus,Color aColor);
        virtual			SwPostItHelper::SwLayoutStatus GetStatus() { return mStatus; }
        Color			GetChangeColor() { return mChangeColor; }

        sal_uInt32		CountFollowing();
        virtual bool	CalcFollow();
        void			InitAnswer(OutlinerParaObject* pText);

        virtual SvxLanguageItem	GetLanguage(void);
        
        virtual bool	IsProtected();
};

#endif