1 /* AbiWord 2 * Copyright (C) 1998 AbiSource, Inc. 3 * Copyright (C) 2002 Martin Sevior 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 * 02110-1301 USA. 19 * 20 * Code for allocation/requisition: 21 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 22 * 23 * This library is free software; you can redistribute it and/or 24 * modify it under the terms of the GNU Library General Public 25 * License as published by the Free Software Foundation; either 26 * version 2 of the License, or (at your option) any later version. 27 * 28 * This library is distributed in the hope that it will be useful, 29 * but WITHOUT ANY WARRANTY; without even the implied warranty of 30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31 * Library General Public License for more details. 32 * 33 * You should have received a copy of the GNU Library General Public 34 * License along with this library; if not, write to the 35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 36 * Boston, MA 02110-1301 USA. 37 */ 38 39 /* 40 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS 41 * file for a list of people on the GTK+ Team. See the ChangeLog 42 * files for a list of changes. These files are distributed with 43 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 44 */ 45 46 #ifndef CONTAINEROBJECT_H 47 #define CONTAINEROBJECT_H 48 49 #ifdef FMT_TEST 50 #include <stdio.h> 51 #endif 52 53 #include "ut_misc.h" 54 #include "ut_types.h" 55 #include "gr_Graphics.h" 56 #include "ut_vector.h" 57 #include "pt_Types.h" 58 #include "gr_Image.h" 59 #include "pp_PropertyMap.h" 60 61 class fp_ContainerObject; 62 63 typedef enum { 64 FG_FILL_TRANSPARENT, 65 FG_FILL_COLOR, 66 FG_FILL_IMAGE 67 } FG_Fill_Type; 68 69 #define INITIAL_OFFSET -99999999 70 71 typedef struct _fp_Requisition fp_Requisition; 72 typedef struct _fp_Allocation fp_Allocation; 73 74 /*! 75 * A requisition is a desired amount of space which a 76 * container may request. 77 */ 78 struct _fp_Requisition 79 { 80 UT_sint32 width; 81 UT_sint32 height; 82 }; 83 84 /*! 85 * An allocation is a size and position. Where a container 86 * can ask for a desired size, it is actually given 87 * this amount of space at the specified position. 88 */ 89 struct _fp_Allocation 90 { 91 UT_sint32 x; 92 UT_sint32 y; 93 UT_sint32 width; 94 UT_sint32 height; 95 }; 96 97 class GR_Graphics; 98 class FG_Graphic; 99 class fl_SectionLayout; 100 class fl_DocSectionLayout; 101 class FL_DocLayout; 102 class fp_Page; 103 class fp_Container; 104 struct dg_DrawArgs; 105 struct fp_Sliver; 106 struct dg_DrawArgs; 107 108 typedef enum { 109 FP_CONTAINER_RUN, //0 110 FP_CONTAINER_LINE, //1 111 FP_CONTAINER_VERTICAL, //2 112 FP_CONTAINER_ROW, //3 113 FP_CONTAINER_TABLE, // 4 114 FP_CONTAINER_CELL, // 5 115 FP_CONTAINER_COLUMN, // 6 116 FP_CONTAINER_HDRFTR, // 7 117 FP_CONTAINER_ENDNOTE, // 8 118 FP_CONTAINER_FOOTNOTE, // 9 119 FP_CONTAINER_COLUMN_POSITIONED, // 10 120 FP_CONTAINER_COLUMN_SHADOW, // 11 121 FP_CONTAINER_FRAME, // 12 122 FP_CONTAINER_TOC, // 13 123 FP_CONTAINER_ANNOTATION // 14 124 125 } FP_ContainerType; 126 127 class ABI_EXPORT fg_FillType 128 { 129 friend class fp_Run; 130 public: 131 fg_FillType(fg_FillType *pParent, fp_ContainerObject * pContainer, FG_Fill_Type iType); 132 virtual ~ fg_FillType(void); 133 void setParent(fg_FillType * pParent); 134 void setColor(UT_RGBColor & color); 135 void setColor(const char * pszColor); 136 void setTransColor(UT_RGBColor & color); 137 void setTransColor(const char * pszColor); 138 void setImage(FG_Graphic * pGraphic, GR_Image * pImage,GR_Graphics * pG, UT_sint32 width, UT_sint32 height); 139 void setTransparent(void); 140 void setWidthHeight(GR_Graphics * pG, UT_sint32 width, UT_sint32 height, bool doImage = false); 141 void setWidth(GR_Graphics * pG, UT_sint32 width); 142 void setHeight(GR_Graphics * pG, UT_sint32 height); 143 void setDocLayout(FL_DocLayout * pDocLayout); 144 void markTransparentForPrint(void); 145 void Fill(GR_Graphics * pG, UT_sint32 & srcX, UT_sint32 & srcY, UT_sint32 x, UT_sint32 y, UT_sint32 width, UT_sint32 height); 146 fg_FillType * getParent(void) const; 147 FG_Fill_Type getFillType(void) const; 148 const FL_DocLayout * getDocLayout(void) const; 149 const UT_RGBColor * getColor(void) const; 150 void setImagePointer(FG_Graphic ** pDocGraphic, GR_Image ** pDocImage); 151 void setIgnoreLineLevel(bool b); 152 private: 153 void _regenerateImage(GR_Graphics * pG); 154 fg_FillType * m_pParent; 155 fp_ContainerObject * m_pContainer; 156 FL_DocLayout * m_pDocLayout; 157 FG_Fill_Type m_FillType; 158 GR_Image * m_pImage; 159 FG_Graphic * m_pGraphic; 160 UT_uint32 m_iGraphicTick; 161 bool m_bTransparentForPrint; 162 UT_RGBColor m_color; 163 UT_RGBColor m_TransColor; 164 bool m_bTransColorSet; 165 bool m_bColorSet; 166 UT_sint32 m_iWidth; 167 UT_sint32 m_iHeight; 168 GR_Image ** m_pDocImage; 169 FG_Graphic ** m_pDocGraphic; 170 bool m_bIgnoreLineLevel; 171 }; 172 173 174 class ABI_EXPORT fp_ContainerObject 175 { 176 public: 177 fp_ContainerObject(FP_ContainerType iType, fl_SectionLayout* pSectionLayout); 178 virtual ~fp_ContainerObject(); 179 /*! 180 Return container type 181 \return Type 182 */ getContainerType(void)183 FP_ContainerType getContainerType(void) const { return m_iConType; } 184 bool isColumnType(void) const; 185 virtual void setWidth(UT_sint32) = 0; 186 virtual void setHeight(UT_sint32) = 0 ; 187 virtual void setX(UT_sint32, bool bDontClearIfNeeded = false) = 0; 188 virtual void setY(UT_sint32) = 0; 189 virtual UT_sint32 getWidth(void) const = 0; 190 191 // all containers that may wish to draw stuff outwith the normal 192 // drawing region, such as the pilcrow on a line, should overwrite this getDrawingWidth(void)193 virtual UT_sint32 getDrawingWidth(void) const {return getWidth();} 194 195 virtual UT_sint32 getX(void) const = 0; 196 virtual UT_sint32 getY(void) const = 0; getSectionLayout(void)197 fl_SectionLayout* getSectionLayout(void) const 198 { return m_pSectionLayout; } 199 fl_DocSectionLayout * getDocSectionLayout(void); setSectionLayout(fl_SectionLayout * pSL)200 void setSectionLayout(fl_SectionLayout * pSL) 201 { m_pSectionLayout = pSL; } getDirection(void)202 virtual inline UT_BidiCharType getDirection(void) const 203 { return m_iDirection;} setDirection(UT_BidiCharType c)204 virtual inline void setDirection(UT_BidiCharType c) {m_iDirection = c;} 205 virtual UT_sint32 getHeight(void) const = 0; 206 207 208 virtual void draw(dg_DrawArgs*) = 0; 209 virtual void draw(GR_Graphics*) = 0; 210 virtual void clearScreen(void) = 0; 211 GR_Graphics* getGraphics(void) const; 212 virtual fp_ContainerObject * getNext(void) const = 0; 213 virtual fp_ContainerObject * getPrev(void) const = 0; 214 virtual void setNext(fp_ContainerObject * pNext) = 0; 215 virtual void setPrev(fp_ContainerObject * pNext) = 0; 216 virtual bool isVBreakable(void) = 0; 217 virtual bool isHBreakable(void) = 0; 218 virtual UT_sint32 wantVBreakAt(UT_sint32) = 0; 219 virtual UT_sint32 wantHBreakAt(UT_sint32) = 0; 220 virtual fp_ContainerObject * VBreakAt(UT_sint32) =0; 221 virtual fp_ContainerObject * HBreakAt(UT_sint32) = 0; 222 virtual void mapXYToPosition(UT_sint32 xPos, UT_sint32 yPos, PT_DocPosition& pos, bool& bBOL, bool& bEOL, bool& isTOC) = 0; 223 virtual fp_Container * getNextContainerInSection(void) const = 0; 224 virtual fp_Container * getPrevContainerInSection(void) const = 0; 225 virtual UT_Rect * getScreenRect() = 0; 226 virtual void markDirtyOverlappingRuns(UT_Rect & recScreen) = 0; 227 const char * getContainerString(void); setAllowDelete(bool bDelete)228 void setAllowDelete(bool bDelete) 229 { m_bCanDelete = bDelete;} canDelete(void)230 bool canDelete(void) 231 { return m_bCanDelete;} getBreakTick(void)232 UT_sint32 getBreakTick(void) const 233 { return m_iBreakTick;} setBreakTick(UT_sint32 iTick)234 void setBreakTick(UT_sint32 iTick) 235 { m_iBreakTick = iTick;} ref(void)236 void ref(void) 237 { m_iRef++;} unref(void)238 void unref(void) 239 { m_iRef--;} getRefCount(void)240 UT_sint32 getRefCount(void) 241 { return m_iRef;} 242 private: 243 /*! 244 Container type 245 */ 246 FP_ContainerType m_iConType; 247 /*! 248 Section layout type used for this container 249 */ 250 fl_SectionLayout* m_pSectionLayout; 251 UT_BidiCharType m_iDirection; 252 UT_sint32 m_iBreakTick; 253 UT_sint32 m_iRef; 254 bool m_bCanDelete; 255 }; 256 257 258 class ABI_EXPORT fp_Container : public fp_ContainerObject 259 { 260 public: 261 fp_Container(FP_ContainerType iType, fl_SectionLayout* pSectionLayout); 262 virtual ~fp_Container(); 263 264 virtual void setContainer(fp_Container * pContainer); 265 fp_Container * getContainer(void) const; 266 fp_Container * getColumn(void) const; 267 fp_Page * getPage(void) const; 268 virtual UT_sint32 getMarginBefore(void) const =0; 269 virtual UT_sint32 getMarginAfter(void) const =0; getNext(void)270 virtual fp_ContainerObject * getNext(void) const {return m_pNext;} getPrev(void)271 virtual fp_ContainerObject * getPrev(void) const {return m_pPrev;} 272 virtual void setNext(fp_ContainerObject * pNext); 273 virtual void setPrev(fp_ContainerObject * pPrev); clearCons(void)274 void clearCons(void) 275 { m_vecContainers.clear();} 276 fp_ContainerObject * getNthCon(UT_sint32 i) const; 277 void addCon(fp_ContainerObject * pCon); 278 UT_sint32 countCons(void) const; 279 UT_sint32 findCon(fp_ContainerObject * pCon) const; 280 void justRemoveNthCon(UT_sint32 i); 281 void deleteNthCon(UT_sint32 i); 282 void insertConAt(fp_ContainerObject * pCon, UT_sint32 i); 283 bool isEmpty(void) const; 284 virtual UT_uint32 distanceFromPoint(UT_sint32 x, UT_sint32 y) =0; 285 virtual void recalcMaxWidth(bool bDontClearIfNeeded = false) = 0; 286 virtual void setAssignedScreenHeight(UT_sint32 iY) =0; 287 bool getPageRelativeOffsets(UT_Rect &r) const; 288 bool isOnScreen() const; 289 fp_Container * getMyBrokenContainer(void) const; 290 void setMyBrokenContainer(fp_Container * pMyBroken); 291 void clearBrokenContainers(void); 292 UT_uint32 binarysearchCons(const void* key,int (*compar)(const void *, 293 const void *)) const; getBrokenCount(void)294 UT_uint32 getBrokenCount(void) { return m_cBrokenContainers; } incBrokenCount(void)295 void incBrokenCount(void) { m_cBrokenContainers += 1; } decBrokenCount(void)296 void decBrokenCount(void) { if (m_cBrokenContainers > 0) { 297 m_cBrokenContainers -= 1; }} 298 299 fg_FillType & getFillType(void); 300 const fg_FillType & getFillType(void) const; 301 void drawLine(const PP_PropertyMap::Line & style, 302 UT_sint32 left, UT_sint32 top, 303 UT_sint32 right, UT_sint32 bot, 304 GR_Graphics * pGr); 305 306 private: 307 fp_Container* m_pContainer; 308 fp_ContainerObject * m_pNext; 309 fp_ContainerObject * m_pPrev; 310 UT_GenericVector<fp_ContainerObject *> m_vecContainers; 311 fp_Container * m_pMyBrokenContainer; 312 UT_uint32 m_cBrokenContainers; 313 fg_FillType m_FillType; 314 }; 315 316 317 #endif /* CONTAINEROBJECT_H */ 318 319 320 321 322 323 324