1 /* AbiSource Application Framework
2  * Copyright (C) 1998-2000 AbiSource, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA.
18  */
19 
20 
21 #ifndef AV_VIEW_H
22 #define AV_VIEW_H
23 
24 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
25  * so even if it's commented out in-file that's still a lot of work for
26  * the preprocessor to do...
27  */
28 #ifndef UT_TYPES_H
29 #include "ut_types.h"
30 #endif
31 #include "ut_misc.h"
32 #include "ut_vector.h"
33 #include "ut_debugmsg.h"
34 
35 #include "ev_EditBits.h"
36 
37 #include "xav_Listener.h"
38 
39 class GR_Graphics;
40 
41 class XAP_App;
42 
43 // TODO shouldn't these classes be xav_ prefixed ??
44 
45 enum AV_Focus
46 {
47 	AV_FOCUS_HERE,
48 	AV_FOCUS_NEARBY,
49 	AV_FOCUS_NONE,
50         AV_FOCUS_MODELESS
51 };
52 
53 typedef enum _AV_ScrollCmd
54 {
55 	AV_SCROLLCMD_PAGEUP,
56 	AV_SCROLLCMD_PAGEDOWN,
57 	AV_SCROLLCMD_LINEUP,
58 	AV_SCROLLCMD_LINEDOWN,
59 	AV_SCROLLCMD_PAGERIGHT,
60 	AV_SCROLLCMD_PAGELEFT,
61 	AV_SCROLLCMD_LINERIGHT,
62 	AV_SCROLLCMD_LINELEFT,
63 	AV_SCROLLCMD_TOTOP,
64 	AV_SCROLLCMD_TOBOTTOM,
65 	AV_SCROLLCMD_TOPOSITION
66 } AV_ScrollCmd;
67 
68 class ABI_EXPORT AV_ScrollObj
69 {
70  public:
AV_ScrollObj(void * pData,void (* pfnX)(void *,UT_sint32,UT_sint32),void (* pfnY)(void *,UT_sint32,UT_sint32))71 	AV_ScrollObj(void * pData,
72 				 void (*pfnX)(void *,UT_sint32,UT_sint32),
73 				 void (*pfnY)(void *,UT_sint32,UT_sint32))
74 			: m_pData(pData), m_pfnX(pfnX), m_pfnY(pfnY)
75 		{	};
76 
77 	void* m_pData;
78 	void (*m_pfnX)(void *, UT_sint32 xoff, UT_sint32 xlimit);
79 	void (*m_pfnY)(void *, UT_sint32 yoff, UT_sint32 ylimit);
80 };
81 
82 class ABI_EXPORT AV_View
83 {
84 public:
85 	AV_View(XAP_App * pApp, void*);
86 	virtual ~AV_View();
87 
88 	virtual void focusChange(AV_Focus focus)=0;
getFocus()89 	AV_Focus getFocus(){ return m_focus; }
setFocus(AV_Focus focus)90 	void setFocus(AV_Focus focus){ m_focus=focus; }
91 
92 	void*			getParentData() const;
93 
94 	void			setInsertMode(bool bInsert);
95 
96 	virtual void    setPoint(UT_uint32 pt) = 0;
97 
98 	/*! the parameters are in device units! */
99 	void			setWindowSize(UT_sint32, UT_sint32);
100 	virtual void	setXScrollOffset(UT_sint32) = 0;
101 	virtual void	setYScrollOffset(UT_sint32) = 0;
102 	UT_uint32               getTick(void) const;
103 	void                    incTick(void);
getApp(void)104 	inline XAP_App *	getApp(void) const { return m_pApp; };
105 	virtual void    setCursorToContext(void) =0;
106 
107 	/*! the return values of these functions are in logical units !!!*/
108 	UT_sint32		getWindowWidth(void) const;
109 	UT_sint32		getWindowHeight(void) const;
getXScrollOffset(void)110 	inline UT_sint32	getXScrollOffset(void) const { return m_xScrollOffset; }
getYScrollOffset(void)111 	inline UT_sint32	getYScrollOffset(void) const { return m_yScrollOffset; }
112 
113 	virtual void	      draw(const UT_Rect* pRect=static_cast<UT_Rect*>(NULL)) = 0;
114 	virtual void	      updateScreen(bool bDirtyRunsOnly=true) = 0;
115 	virtual GR_Graphics * getGraphics(void) const = 0;
116     virtual void          updateLayout(void) = 0;
117 	virtual void          rebuildLayout(void) = 0;
118 	virtual void          remeasureCharsWithoutRebuild() = 0;
119 	virtual void          fontMetricsChange() = 0;
120 
121 	virtual void	cmdScroll(AV_ScrollCmd cmd, UT_uint32 iPos = 0) = 0;
122 	void			addScrollListener(AV_ScrollObj*);
123 	void			removeScrollListener(AV_ScrollObj*);
124 	/*! input parameters of these functions are in logical units !!! */
125 	void			sendVerticalScrollEvent(UT_sint32 yoff, UT_sint32 ylimit = -1);
126 	void			sendHorizontalScrollEvent(UT_sint32 xoff, UT_sint32 xlimit = -1);
127 
couldBeActive(void)128 	bool                    couldBeActive(void) const
129 	{  return m_bCouldBeActive;}
130 	bool			addListener(AV_Listener * pListener, AV_ListenerId * pListenerId);
131 	bool			removeListener(AV_ListenerId listenerId);
132 
133 	//! returns true iff the current view is the active/focused window
134 	virtual bool		isActive(void) const = 0;
135         void                    setActivityMask(bool bActive);
136 	virtual bool	notifyListeners(const AV_ChangeMask hint, void * pPrivateData = NULL);
137 	virtual bool    isDocumentPresent(void) const = 0;
138 	virtual bool	canDo(bool bUndo) const = 0;
139 	virtual void	cmdUndo(UT_uint32 count) = 0;
140 	virtual void	cmdRedo(UT_uint32 count) = 0;
141 	virtual UT_Error	cmdSave(void) = 0;
142 	virtual UT_Error	cmdSaveAs(const char * szFilename, int ieft) = 0;
143 	virtual UT_Error        cmdSaveAs(const char * szFilename, int ieft, bool cpy) = 0;
144 
145 	virtual EV_EditMouseContext getMouseContext(UT_sint32 xPos, UT_sint32 yPos) = 0;
146 	virtual bool 	isSelectionEmpty(void) const = 0;
147 
148 	virtual void	cmdCopy(bool bToClipboard = true) = 0;
149 	virtual void	cmdCut(void) = 0;
150 	virtual void	cmdPaste(bool bHonorFormatting = true) = 0;
151 	virtual void	cmdPasteSelectionAt(UT_sint32 xPos, UT_sint32 yPos) = 0;
152 
153 	// For touch screen support
setVisualSelectionEnabled(bool bActive)154 	void	setVisualSelectionEnabled(bool bActive)
155 	{
156 		m_VisualSelectionActive = bActive;
157 	}
getVisualSelectionEnabled(void)158 	bool	getVisualSelectionEnabled(void) const
159 	{
160 		return m_VisualSelectionActive;
161 	}
162 
163 //
164 // Let subclasses override but this is here to avoid a crash on frame closing.
165 // With a selection in place. (Rather than pure virtual.)
cmdUnselectSelection(void)166 	virtual void		cmdUnselectSelection(void) {UT_DEBUGMSG(("Just saved a segfault! \n"));}
167 
168 	virtual UT_uint32   calculateZoomPercentForPageWidth() const = 0;
169 	virtual UT_uint32   calculateZoomPercentForPageHeight() const = 0;
170 	virtual UT_uint32   calculateZoomPercentForWholePage() const = 0;
setLayoutIsFilling(bool bFill)171 	void   setLayoutIsFilling(bool bFill) { m_bIsLayoutFilling = bFill;}
isLayoutFilling(void)172 	bool   isLayoutFilling(void)  const {return  m_bIsLayoutFilling;}
173 	virtual UT_uint32	  getPoint(void) const =0;
174 	virtual void setCursorWait(void) = 0;
175 	virtual void clearCursorWait(void) = 0;
isConfigureChanged(void)176 	bool   isConfigureChanged(void)
177 	{ return m_bConfigureChanged;}
setConfigure(bool b)178 	void   setConfigure(bool b)
179 	{ m_bConfigureChanged = b;}
180 
181 protected:
182 	XAP_App *			m_pApp;
183 	void*				m_pParentData;
184 
185 	UT_sint32			m_xScrollOffset;
186 	UT_sint32			m_yScrollOffset;
187 	AV_Focus			m_focus;
188 	UT_uint32                       m_iTick; // Count changes
189 	bool				m_bInsertMode;
190 	bool				m_VisualSelectionActive;
191 
192 	UT_GenericVector<AV_ScrollObj*>	m_scrollListeners;
193 	UT_GenericVector<AV_Listener*>	m_vecListeners;
194 
195 private:
196 	AV_View(const AV_View&);	// no impl.
197 	void operator=(AV_View&);	// no impl.
198 	bool m_bIsLayoutFilling;
199 
200 	UT_sint32			m_iWindowHeight;
201 	UT_sint32			m_iWindowWidth;
202 	double				m_dOneTDU;
203 	bool                            m_bCouldBeActive;
204 	bool                            m_bConfigureChanged;
205 };
206 
207 #endif /* AV_VIEW_H */
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223