1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2 
3 /* AbiWord
4  * Copyright (C) 1998-2000 AbiSource, Inc.
5  * Copyright (C) 2001 Tomas Frydrych
6  * Copyright (C) 2004 Hubert Figui�re
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  */
23 
24 #ifndef AP_TOPRULER_H
25 #define AP_TOPRULER_H
26 
27 #include "xap_Features.h"
28 // Class for dealing with the horizontal ruler at the top of
29 // a document window.
30 
31 #include "ut_types.h"
32 #include "ut_misc.h"
33 #include "ut_units.h"
34 #include "xav_Listener.h"
35 #include "ap_Ruler.h"
36 #include "ev_EditBits.h"
37 #include "gr_Graphics.h"
38 #include "fl_BlockLayout.h"
39 #include "xap_Strings.h"
40 #include "xap_CustomWidget.h"
41 
42 class XAP_App;
43 class XAP_Frame;
44 class XAP_Prefs;
45 class AV_ScrollObj;
46 class UT_Timer;
47 class fp_CellContainer;
48 class  AP_TopRulerTableInfo;
49 /*****************************************************************/
50 
51 
52 
53 /*****************************************************************/
54 class ABI_EXPORT AP_TopRulerTableInfo
55 {
56 public:
57 	UT_sint32 m_iLeftCellPos;
58 	UT_sint32 m_iLeftSpacing;
59 	UT_sint32 m_iRightCellPos;
60 	UT_sint32 m_iRightSpacing;
61 	fp_CellContainer * m_pCell;
62 };
63 
64 /*****************************************************************/
65 
66 /*****************************************************************/
67 
68 class ABI_EXPORT AP_TopRulerInfo
69 {
70 public:
71 	typedef enum _mode { TRI_MODE_COLUMNS, TRI_MODE_TABLE, TRI_MODE_FRAME } Mode;
72 
AP_TopRulerInfo(void)73 	AP_TopRulerInfo(void) :
74 							m_mode(TRI_MODE_COLUMNS),
75 							m_xPaperSize(0),
76 							m_xPageViewMargin(0),
77 							m_xrPoint(0),
78 							m_xrLeftIndent(0),
79 							m_xrFirstLineIndent(0),
80 							m_xrRightIndent(0),
81 							m_xrTabStop(0),
82 							m_pfnEnumTabStops(NULL),
83 							m_pVoidEnumTabStopsData(NULL),
84 							m_iTabStops(0),
85 							m_iDefaultTabInterval(0),
86 							m_pszTabStops(NULL),
87 							m_iCurrentColumn(0),
88 							m_iNumColumns(0),
89 							m_vecTableColInfo (NULL),
90 							m_vecFullTable(NULL),
91 							m_iTablePadding(0),
92 							m_iCells(0),
93 							m_iCurCell(0)
94 		{
95 			xxx_UT_DEBUGMSG(("SEVIOR: Creating AP_TopRulerInfo %x \n",this));
96 
97 			u.c.m_xaLeftMargin  = 0;
98 			u.c.m_xaRightMargin = 0;
99 			u.c.m_xColumnGap    = 0;
100 			u.c.m_xColumnWidth  = 0;
101 		}
~AP_TopRulerInfo(void)102 	virtual ~AP_TopRulerInfo(void)
103 		{
104 			xxx_UT_DEBUGMSG(("SEVIOR: Deleting AP_TopRulerInfo %x \n",this));
105 			if(m_vecTableColInfo)
106 			{
107 				UT_sint32 count = m_vecTableColInfo->getItemCount();
108 				UT_sint32 i =0;
109 				for(i=0; i< count; i++)
110 				{
111 					delete m_vecTableColInfo->getNthItem(i);
112 				}
113 				delete m_vecTableColInfo;
114 			}
115 			if(m_vecFullTable)
116 			{
117 				UT_sint32 count = m_vecFullTable->getItemCount();
118 				UT_sint32 i =0;
119 				for(i=0; i< count; i++)
120 				{
121 					delete m_vecFullTable->getNthItem(i);
122 				}
123 				delete m_vecFullTable;
124 				m_vecFullTable = NULL;
125 			}
126 		}
127 
128 	Mode					m_mode;
129 	UT_uint32				m_xPaperSize;
130 	UT_uint32				m_xPageViewMargin;
131 
132 	// current caret position -- relative to the current column
133 
134 	UT_sint32				m_xrPoint;
135 	UT_sint32				m_xrLeftIndent;
136 	UT_sint32				m_xrFirstLineIndent;
137 	UT_sint32				m_xrRightIndent;
138 	UT_sint32				m_xrTabStop;
139 
140 	// tab stop information
141 
142 	bool					(*m_pfnEnumTabStops)(void * pData, UT_uint32 k, fl_TabStop *pTabInfo);
143 	void *					m_pVoidEnumTabStopsData;
144 	UT_sint32				m_iTabStops;
145 	UT_sint32				m_iDefaultTabInterval;
146 	const char *			m_pszTabStops;
147 
148 	// current column number and the number of columns
149 
150 	UT_uint32				m_iCurrentColumn;
151 	UT_uint32				m_iNumColumns;
152 
153 // Column information for current table
154 
155 	UT_GenericVector<AP_TopRulerTableInfo *> * m_vecTableColInfo;
156 	UT_GenericVector<AP_TopRulerTableInfo *> * m_vecFullTable;
157 	UT_sint32               m_iTablePadding;
158 	UT_sint32               m_iCells;
159 	UT_sint32               m_iCurCell;
160 	union _u {
161 
162 		struct _c {
163 
164 			// page absolute document margins
165 
166 			UT_sint32		m_xaLeftMargin;
167 			UT_sint32		m_xaRightMargin;
168 
169 			// column width and spacing -- currently we only support
170 			// uniform gaps and widths for columns
171 
172 			UT_uint32		m_xColumnGap;
173 			UT_uint32		m_xColumnWidth;
174 
175 		} c;									/* valid when column mode */
176 
177 		struct _t {
178 
179 			int foo;
180 
181 		} t;									/* valid when table mode */
182 
183 	} u;
184 };
185 
186 class ABI_EXPORT AP_TopRuler : public AV_Listener, virtual public XAP_CustomWidgetLU
187 {
188 public:
189 	AP_TopRuler(XAP_Frame * pFrame);
190 	virtual ~AP_TopRuler(void);
191 
192 	virtual void	setView(AV_View * pView);
193     void	        setViewHidden(AV_View * pView);
194 	void			setView(AV_View* pView, UT_uint32 iZoom);
getView(void)195 	AV_View *       getView(void) const { return m_pView;}
196 	void			setOffsetLeftRuler(UT_uint32 iLeftRulerWidth);
197 	void            setZoom(UT_uint32 iZoom);
198 	void			setHeight(UT_uint32 iHeight);
199 	UT_uint32		getHeight(void) const;
200 	void			setWidth(UT_uint32 iWidth);
201 	UT_uint32		getWidth(void) const;
getGraphics(void)202 	GR_Graphics *	getGraphics(void) const { return m_pG;}
isHidden(void)203 	bool            isHidden(void) const
204 		{ return m_bIsHidden;}
205 	void			scrollRuler(UT_sint32 xoff, UT_sint32 xlimit);
206 
207 	UT_sint32       setTableLineDrag(PT_DocPosition pos, UT_sint32 x, UT_sint32 & iFixed);
208 	void			mouseMotion(EV_EditModifierState ems, UT_sint32 x, UT_sint32 y);
209 	void			mousePress(EV_EditModifierState ems, EV_EditMouseButton emb, UT_uint32 x, UT_uint32 y);
210 	void			mouseRelease(EV_EditModifierState ems, EV_EditMouseButton emb, UT_sint32 x, UT_sint32 y);
211 
212 	bool            isMouseOverTab(UT_uint32 x, UT_uint32 y);
213 	/* used with AV_Listener */
214 	virtual bool	notify(AV_View * pView, const AV_ChangeMask mask);
getType(void)215     virtual  AV_ListenerType getType(void) { return AV_LISTENER_TOPRULER;}
216 
217 	/* used with AV_ScrollObj */
218 	static void		_scrollFuncX(void * pData, UT_sint32 xoff, UT_sint32 xlimit);
219 	static void		_scrollFuncY(void * pData, UT_sint32 yoff, UT_sint32 ylimit);
220 
221 	/* for use with the prefs listener top_ruler_prefs_listener */
getDimension()222 	UT_Dimension	getDimension() const { return m_dim; }
223 	void			setDimension( UT_Dimension newdim );
224 
225 	UT_uint32       getTabToggleAreaWidth() const;
226 
getFixedWidth()227 	static UT_uint32 getFixedWidth(){return s_iFixedWidth;}
228 
229 protected:
230 	/* implement XAP_CustomWidgetLU::drawLU */
231 	virtual void drawLU(const UT_Rect *clip);
232 
233 	void	_draw(const UT_Rect * pClipRect, AP_TopRulerInfo * pUseInfo);
234 	void	_drawBar(const UT_Rect * pClipRect, AP_TopRulerInfo * pInfo,
235 					 GR_Graphics::GR_Color3D clr3d, UT_sint32 x, UT_sint32 w);
236 	void	_drawTickMark(const UT_Rect * pClipRect,
237 						  AP_TopRulerInfo * pInfo, ap_RulerTicks &tick,
238 						  GR_Graphics::GR_Color3D clr3d, GR_Font * pFont,
239 						  UT_sint32 k, UT_sint32 xTick);
240 	void	_drawTicks(const UT_Rect * pClipRect,
241 					   AP_TopRulerInfo * pInfo, ap_RulerTicks &tick,
242 					   GR_Graphics::GR_Color3D clr3d, GR_Font * pFont,
243 					   UT_sint32 xOrigin, UT_sint32 xFrom, UT_sint32 xTo);
244 
245 	void	_getParagraphMarkerXCenters(AP_TopRulerInfo * pInfo,
246 										UT_sint32 * pLeft, UT_sint32 * pRight, UT_sint32 * pFirstLine);
247 	void	_getParagraphMarkerRects(AP_TopRulerInfo * pInfo,
248 									 UT_sint32 leftCenter, UT_sint32 rightCenter, UT_sint32 firstLineCenter,
249 									 UT_Rect * prLeftIndent, UT_Rect * prRightIndent, UT_Rect * prFirstLineIndent);
250 	void	_drawParagraphProperties(const UT_Rect * pClipRect,
251 									 AP_TopRulerInfo * pInfo,
252 									 bool bDrawAll = true);
253 
254 	void	_getTabToggleRect(UT_Rect * prToggle);
255 	void	_drawTabToggle(const UT_Rect * pClipRect, bool bErase);
256 
257 	void	_getTabStopXAnchor(AP_TopRulerInfo * pInfo, UT_sint32 k, UT_sint32 * pTab, eTabType & iType, eTabLeader & iLeader);
258 	void	_getTabStopRect(AP_TopRulerInfo * pInfo, UT_sint32 anchor, UT_Rect * pRect);
259 	void	_drawTabProperties(const UT_Rect * pClipRect,
260 								   AP_TopRulerInfo * pInfo,
261 								   bool bDrawAll = true);
262 
263 	UT_sint32		_findTabStop(AP_TopRulerInfo * pInfo, UT_uint32 x, UT_uint32 y, UT_sint32 & anchor, eTabType & iType, eTabLeader & iLeader);
264 	const char *	_getTabStopString(AP_TopRulerInfo * pInfo, UT_sint32 k);
265 	void			_getTabZoneRect(AP_TopRulerInfo * pInfo, UT_Rect &rZone);
266 	void			_setTabStops(ap_RulerTicks tick, UT_sint32 iTab, eTabLeader iLeader, bool bDelete);
267 
268 	UT_sint32	_getColumnMarkerXRightEnd(AP_TopRulerInfo * pInfo, UT_uint32 kCol);
269 	void		_getColumnMarkerRect(AP_TopRulerInfo * pInfo, UT_uint32 kCol, UT_sint32 xCenter,
270 									 UT_Rect * prCol);
271 	void		_drawColumnProperties(const UT_Rect * pClipRect,
272 									  AP_TopRulerInfo * pInfo,
273 									  UT_uint32 kCol);
274 	void		_getCellMarkerRect(AP_TopRulerInfo * pInfo, UT_sint32 kCell,
275 								   UT_Rect * prCell);
276 	void		_drawCellProperties(const UT_Rect * pClipRect,
277 									  AP_TopRulerInfo * pInfo,
278 									  UT_uint32 kCol, bool bDrawAll);
279 	void		_drawCellProperties(const UT_Rect * pClipRect,
280 									AP_TopRulerInfo * pInfo, bool bDrawAll);
281 	void        _drawCellGap( AP_TopRulerInfo * pInfo, UT_sint32 iCell);
282 
283 	virtual void	_drawCellMark(UT_Rect * prDrag, bool bUp);
284 
285 	void		_getMarginMarkerRects(AP_TopRulerInfo * pInfo, UT_Rect &rLeft, UT_Rect &rRight);
286 
287 	virtual void	_drawMarginProperties(const UT_Rect * pClipRect,
288 									  AP_TopRulerInfo * pInfo, GR_Graphics::GR_Color3D clr);
289 
290 	void		_xorGuide(bool bClear=false);
291 
292 	void		_ignoreEvent(bool bDone);
293 	double		_scalePixelDistanceToUnits(UT_sint32 xColRel, ap_RulerTicks & tick);
294 	double		_getUnitsFromRulerLeft(UT_sint32 xColRel, ap_RulerTicks & tick);
295 	UT_sint32	_getFirstPixelInColumn(AP_TopRulerInfo * pInfo, UT_uint32 kCol);
296 	UT_sint32	_snapPixelToGrid(UT_sint32 xDist, ap_RulerTicks & tick);
297 
298 	virtual void	_drawLeftIndentMarker(UT_Rect & r, bool bFilled);
299 	virtual void	_drawRightIndentMarker(UT_Rect & r, bool bFilled);
300 	virtual void	_drawFirstLineIndentMarker(UT_Rect & r, bool bFilled);
301 
302 	void		_drawTabStop(UT_Rect & r, eTabType iType, bool bFilled);
303 
304 	virtual void	_drawColumnGapMarker(UT_Rect & r);
305 
306 	bool		_isInBottomBoxOfLeftIndent(UT_uint32 y);
307 	void		_displayStatusMessage(XAP_String_Id messageID, const ap_RulerTicks &tick, double dValue);
308 	void		_displayStatusMessage(XAP_String_Id messageID, const ap_RulerTicks &tick, double dValue1, double dValue2);
309 	void		_displayStatusMessage(XAP_String_Id FormatMessageID, UT_sint32 iCol, const char * format);
310 	void		_displayStatusMessage(XAP_String_Id FormatMessageID);
311 
312 
313 	void        _refreshView(void);
314 
315 	// must be static so that I can pass as a functional arg - shack
316 	static void _prefsListener( XAP_Prefs *pPrefs, UT_StringPtrMap *phChanges, void *data );
317 
318 	// autoscroll stuff
319 	static void			_autoScroll(UT_Worker * pTimer);
320 
321 	XAP_Frame *			m_pFrame;
322 	GR_Graphics *		m_pG;
323 	UT_uint32			m_iLeftRulerWidth; // device
324 	UT_sint32			m_xScrollOffset;
325 	UT_sint32			m_xScrollLimit;
326 
327 	static UT_uint32	s_iFixedHeight /* =32 */;	/* size we draw stuff w/o regard to window size: device */
328 	static UT_uint32	s_iFixedWidth  /* =32 */;	/* minimum width of non-scrolling area on left: device */
329 
330 private:
331 	AV_ScrollObj *		m_pScrollObj;
332 protected:
333 	AV_View *			m_pView;
334 private:
335 	UT_Dimension		m_dim;
336 
337 	UT_uint32			m_iHeight;		/* size of window: device */
338 	UT_uint32			m_iWidth;		/* size of window: device */
339 
340 	UT_Timer *			m_pAutoScrollTimer;
341 	char				m_aScrollDirection; // 'L' == left   'R' == right
342 
343 	UT_sint32			m_minColumnWidth; // logical
344 
345 	UT_sint32			m_iMinCellPos;	/* cell marker left border while dragging: logical */
346 	UT_sint32			m_iMaxCellPos;  /* cell marker right border while dragging: logical */
347 
348 	AP_TopRulerInfo		m_infoCache;
349 	bool				m_bValidMouseClick;
350 	bool				m_bEventIgnored;
351 
352 	typedef enum _draggingWhat { DW_NOTHING,
353 								 DW_LEFTMARGIN,
354 								 DW_RIGHTMARGIN,
355 								 DW_COLUMNGAP,
356 								 DW_COLUMNGAPLEFTSIDE,
357 								 DW_LEFTINDENT,
358 								 DW_RIGHTINDENT,
359 								 DW_FIRSTLINEINDENT,
360 								 DW_LEFTINDENTWITHFIRST,
361 								 DW_TABSTOP,
362 								 DW_TABTOGGLE,
363 								 DW_CELLMARK
364 	} DraggingWhat;
365 
366 	DraggingWhat		m_draggingWhat;
367 	UT_sint32			m_draggingCenter; /* center of primary thing being dragged */
368 	UT_Rect				m_draggingRect;	/* rectangle of primary thing being dragged */
369 	UT_sint32			m_dragging2Center; /* center of drag-along */
370 	UT_Rect				m_dragging2Rect; /* rect of drag-along */
371 	UT_sint32			m_draggingTab;	/* index of tab being dragged */
372 	eTabType			m_draggingTabType;
373 	eTabLeader			m_draggingTabLeader;
374 	UT_sint32			m_dragStart;
375 	bool				m_bBeforeFirstMotion;
376 	UT_sint32			m_oldX; /* Only for dragging; used to see if object has moved */
377 
378 	eTabType			m_iDefaultTabType;
379 	UT_sint32           m_draggingCell; // index of cell being dragged
380 	bool				m_bGuide;	/* true ==> guide line XORed onscreen */
381 	UT_sint32			m_xGuide;	/* valid iff m_bGuide */
382 	UT_sint32			m_xOtherGuide;
383 
384 	AV_ListenerId		m_lidTopRuler;		/* need to save the view/listenerID so we can removeListener in destructor */
385 	UT_sint32           m_iCellContainerLeftPos; // position of the left side of the container
386                                                  // holding the cell
387 	bool                m_bIsHidden;
388 	UT_sint32           m_iOrigPosition;
389 #if XAP_DONTUSE_XOR
390 	UT_Rect				m_guideCacheRect;
391 	UT_Rect				m_otherGuideCacheRect;
392 	GR_Image*			m_guideCache;
393 	GR_Image*			m_otherGuideCache;
394 #endif
395 };
396 
397 #endif /* AP_TOPRULER_H */
398