1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 2 3 /* AbiWord 4 * Copyright (C) 1998 AbiSource, Inc. 5 * Copyright (C) 2004 Hubert Figui�re 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 * 02110-1301 USA. 21 */ 22 23 #ifndef AP_LEFTRULER_H 24 #define AP_LEFTRULER_H 25 26 #include "xap_Features.h" 27 // Class for dealing with the horizontal ruler at the top of 28 // a document window. 29 30 #include "ut_types.h" 31 #include "ut_misc.h" 32 #include "ut_units.h" 33 #include "ut_hash.h" 34 #include "xav_Listener.h" 35 36 #include "gr_Graphics.h" 37 #include "ev_EditBits.h" 38 #include "pt_Types.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 GR_Graphics; 47 class ap_RulerTicks; 48 class fp_CellContainer; 49 class fp_TableContainer; 50 /*****************************************************************/ 51 52 53 /*****************************************************************/ 54 class ABI_EXPORT AP_LeftRulerTableInfo 55 { 56 public: 57 UT_sint32 m_iTopCellPos; 58 UT_sint32 m_iTopSpacing; 59 UT_sint32 m_iBotCellPos; 60 UT_sint32 m_iBotSpacing; 61 fp_CellContainer * m_pCell; 62 }; 63 64 /*****************************************************************/ 65 66 /*****************************************************************/ 67 68 class ABI_EXPORT AP_LeftRulerInfo 69 { 70 public: 71 typedef enum _mode { TRI_MODE_COLUMNS, 72 TRI_MODE_TABLE, 73 TRI_MODE_FRAME } Mode; 74 AP_LeftRulerInfo(void)75 AP_LeftRulerInfo(void) : m_mode(TRI_MODE_COLUMNS), 76 m_yPageStart(0), 77 m_yPageSize(0), 78 m_yPoint(0), 79 m_yTopMargin(0), 80 m_yBottomMargin(0), 81 m_iNumRows(0), 82 m_iCurrentRow(0), 83 m_iTablePadding(0), 84 m_vecTableRowInfo(NULL) 85 { 86 } ~AP_LeftRulerInfo(void)87 virtual ~AP_LeftRulerInfo(void) 88 { 89 if(m_vecTableRowInfo) 90 { 91 UT_sint32 count = m_vecTableRowInfo->getItemCount(); 92 UT_sint32 i =0; 93 for(i=0; i< count; i++) 94 { 95 delete m_vecTableRowInfo->getNthItem(i); 96 } 97 DELETEP(m_vecTableRowInfo); 98 } 99 } 100 101 Mode m_mode; 102 103 /* all values are in layout units */ 104 105 UT_uint32 m_yPageStart; /* absolute coord of start of page */ 106 UT_uint32 m_yPageSize; /* absolute page size for the current page */ 107 UT_uint32 m_yPoint; /* absolute coord of current insertion point */ 108 UT_sint32 m_yTopMargin; /* content start relative to top of page */ 109 UT_sint32 m_yBottomMargin; /* content end relative to top of page */ 110 111 // Things we need for Tables 112 113 UT_sint32 m_iNumRows; 114 UT_sint32 m_iCurrentRow; 115 UT_sint32 m_iTablePadding; 116 UT_GenericVector<AP_LeftRulerTableInfo *> * m_vecTableRowInfo; 117 }; 118 119 /*****************************************************************/ 120 121 class ABI_EXPORT AP_LeftRuler : public AV_Listener, public XAP_CustomWidgetLU 122 { 123 public: 124 AP_LeftRuler(XAP_Frame * pFrame); 125 virtual ~AP_LeftRuler(void); 126 127 virtual void setView(AV_View * pView); 128 void setView(AV_View* pView, UT_uint32 iZoom); 129 void setViewHidden(AV_View* pView); 130 void setZoom(UT_uint32 iZoom); isHidden(void)131 bool isHidden(void) const 132 { return m_bIsHidden;} getView(void)133 AV_View * getView(void) const 134 {return m_pView;} 135 void setHeight(UT_uint32 iHeight); 136 UT_uint32 getHeight(void) const; 137 void setWidth(UT_uint32 iWidth); 138 UT_uint32 getWidth(void) const; 139 void scrollRuler(UT_sint32 yoff, UT_sint32 ylimit); 140 141 void mouseMotion(EV_EditModifierState ems, UT_sint32 x, UT_sint32 y); 142 void mousePress(EV_EditModifierState ems, EV_EditMouseButton emb, UT_uint32 x, UT_uint32 y); 143 144 void mouseRelease(EV_EditModifierState ems, EV_EditMouseButton emb, UT_sint32 x, UT_sint32 y); 145 UT_sint32 setTableLineDrag(PT_DocPosition pos, UT_sint32 & iFixed, UT_sint32 y); 146 /* used with AV_Listener */ 147 virtual bool notify(AV_View * pView, const AV_ChangeMask mask); getType(void)148 virtual AV_ListenerType getType(void) { return AV_LISTENER_LEFTRULER;} 149 150 /* used with AV_ScrollObj */ 151 static void _scrollFuncX(void * pData, UT_sint32 xoff, UT_sint32 xlimit); 152 static void _scrollFuncY(void * pData, UT_sint32 yoff, UT_sint32 ylimit); 153 154 /* for use with the prefs listener top_ruler_prefs_listener */ getDimension()155 UT_Dimension getDimension() const { return m_dim; } 156 void setDimension( UT_Dimension newdim ); getGraphics(void)157 GR_Graphics * getGraphics(void) const { return m_pG;} 158 protected: 159 void _refreshView(void); 160 161 /* don't call this function directly, use XAP_CustomWidget::queueDraw() instead */ 162 virtual void drawLU(const UT_Rect *clip); 163 164 // void _draw3DFrame(const UT_Rect * pClipRect, AP_TopRulerInfo * pInfo, 165 // UT_sint32 x, UT_sint32 h); 166 167 // must be static so that I can pass as a functional arg - shack 168 static void _prefsListener( XAP_Prefs *pPrefs, UT_StringPtrMap *phChanges, void *data ); 169 170 XAP_Frame * m_pFrame; 171 GR_Graphics * m_pG; 172 173 // These are in device units. 174 /* static const*/ UT_uint32 s_iFixedHeight /* =32 */; /* size we draw stuff w/o regard to window size */ 175 /* static const*/ UT_uint32 s_iFixedWidth /* =32 */; /* minimum width of non-scrolling area on left */ 176 177 private: 178 UT_sint32 _snapPixelToGrid(UT_sint32 xDist, ap_RulerTicks & tick); 179 double _scalePixelDistanceToUnits(UT_sint32 yDist, ap_RulerTicks & tick); 180 void _ignoreEvent(bool bDone); 181 protected: 182 void _getMarginMarkerRects(const AP_LeftRulerInfo * pInfo, UT_Rect &rTop, UT_Rect &rBottom); 183 184 virtual void _drawMarginProperties(const UT_Rect * pClipRect, 185 const AP_LeftRulerInfo * pInfo, 186 GR_Graphics::GR_Color3D clr); 187 private: 188 189 void _getCellMarkerRects(const AP_LeftRulerInfo * pInfo, UT_sint32 iCell, UT_Rect &rCell, fp_TableContainer * pBroke=NULL); 190 void _drawCellProperties(const AP_LeftRulerInfo * pInfo); 191 protected: 192 virtual void _drawCellMark(UT_Rect *prDrag, bool bUp); 193 private: 194 void _xorGuide(bool bClear=false); 195 void _displayStatusMessage(XAP_String_Id messageID, const ap_RulerTicks &tick, double dValue); 196 197 AP_LeftRulerInfo * m_lfi; /* the values we last drew with */ 198 199 // scrolling objects 200 AV_ScrollObj * m_pScrollObj; 201 UT_sint32 m_yScrollOffset; 202 UT_sint32 m_yScrollLimit; 203 204 AV_ListenerId m_lidLeftRuler; 205 206 // misc info 207 208 AV_View * m_pView; 209 UT_Dimension m_dim; 210 UT_uint32 m_iHeight; /* size of window, in device units */ 211 UT_uint32 m_iWidth; /* size of window, in device units */ 212 213 AP_LeftRulerInfo m_infoCache; 214 UT_sint32 m_oldY; /* Only for dragging; used to see if object has moved */ 215 216 typedef enum _draggingWhat { DW_NOTHING, 217 DW_TOPMARGIN, 218 DW_BOTTOMMARGIN, 219 DW_CELLMARK 220 } DraggingWhat; 221 222 DraggingWhat m_draggingWhat; 223 UT_sint32 m_draggingCenter; /* center of primary thing being dragged */ 224 bool m_bBeforeFirstMotion; 225 UT_sint32 m_draggingCell; 226 bool m_bGuide; /* true ==> guide line XORed onscreen */ 227 UT_sint32 m_yGuide; /* valid iff m_bGuide */ 228 229 bool m_bValidMouseClick; 230 bool m_bEventIgnored; 231 UT_Rect m_draggingRect; 232 UT_sint32 m_minPageLength; 233 PT_DocPosition m_draggingDocPos; 234 bool m_bIsHidden; 235 #if XAP_DONTUSE_XOR 236 UT_Rect m_guideCacheRect; 237 GR_Image* m_guideCache; 238 #endif 239 }; 240 241 #endif /* AP_LEFTRULER_H */ 242