home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / layout / editor.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  157.0 KB  |  4,312 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. //
  21. // Editor save stuff. LWT 06/01/95
  22. //
  23.  
  24. #ifdef EDITOR
  25.  
  26. #ifndef _EDITOR_H
  27. #define _EDITOR_H
  28. #include "edttypep.h"       // include first so types are mapped.
  29.  
  30. // 
  31. // Turn on new DT mapping code
  32. //
  33. #define EDT_DDT 1
  34.  
  35. #if defined(JAVA)
  36. #define EDITOR_JAVA
  37. #endif
  38.  
  39. //
  40. //    Many of the system header files have C++ specific stuff in
  41. //    them. If we just widely extern "C" {} the lot, we will lose.
  42. //    So.. pre-include some that must be seen by C++.
  43. //
  44. #if defined(HPUX) || defined(SCO_SV)
  45. #include "math.h"
  46. #endif /*HPUX losing headers */
  47.  
  48. extern "C" {
  49. #include "net.h"
  50. //#include "glhist.h"
  51. //#include "shist.h"
  52. #include "merrors.h"
  53. #include "xp.h"
  54. #include "pa_parse.h"
  55. #include "layout.h"
  56. #include "edt.h"
  57. #include "pa_tags.h"
  58. #include "xpassert.h"
  59. #include "xp_file.h"
  60. #include "libmocha.h"
  61. #include "libi18n.h"
  62. }
  63.  
  64. #include "bits.h"
  65. #include "garray.h"
  66. #include "streams.h"
  67.  
  68.  
  69. #include "gui.h"
  70.  
  71. // For textFE test, hardts
  72. #include "xlate.h"
  73.  
  74. #include "fsfile.h"
  75. #include "shist.h"
  76.  
  77. #ifdef XP_WIN32
  78. #include    <crtdbg.h>
  79. #endif
  80.  
  81. // XP Strings
  82. extern "C" {
  83. #include "xpgetstr.h"
  84. #define WANT_ENUM_STRING_IDS
  85. #include "allxpstr.h"
  86. #undef WANT_ENUM_STRING_IDS
  87. }
  88.  
  89. // Defining DEBUG_AUTO_SAVE will make the document AutoSave every six seconds.
  90. //#define DEBUG_AUTO_SAVE
  91.  
  92. // Test if ele
  93. #ifdef USE_SCRIPT
  94. #define  ED_IS_NOT_SCRIPT(pEle) (0 == (pEle->Text()->m_tf & (TF_SERVER | TF_SCRIPT | TF_STYLE)))
  95. #else
  96. #define ED_IS_NOT_SCRIPT(pEle) (TRUE)
  97. #endif
  98.  
  99. #define EDT_SELECTION_START_COMMENT "selection start"
  100. #define EDT_SELECTION_END_COMMENT "selection end"
  101.  
  102. // TRY / CATCH / RETHROW macros for minimal error recovery on macs
  103. #if defined(XP_MAC)
  104. #define EDT_TRY try
  105. #define EDT_CATCH_ALL catch(...)
  106. #define EDT_RETHROW throw
  107. #else
  108. #define EDT_TRY if(1)
  109. #define EDT_CATCH_ALL else
  110. #define EDT_RETHROW
  111.  
  112. #endif
  113.  
  114. #ifdef XP_MAC
  115. // taken from pa_amp.h
  116. #define NON_BREAKING_SPACE  ((char)007)
  117. #define NON_BREAKING_SPACE_STRING   "\07"
  118. #else
  119. #define NON_BREAKING_SPACE  ((char)160)
  120. #define NON_BREAKING_SPACE_STRING   "\xa0"
  121. #endif
  122.  
  123. #define DEF_FONTSIZE    3
  124. #define MAX_FONTSIZE    7
  125. #define DEFAULT_HR_THICKNESS    2
  126.  
  127. #define EDT_IS_LIVEWIRE_MACRO(s) ( (s) && (s)[0] == '`' )
  128.  
  129.  
  130. // Macros for the public entry points.
  131. // usage:
  132. // GET_EDIT_BUF_OR_RETURN(pContext, pEditBuffer) ; // For no return value
  133. // GET_EDIT_BUF_OR_RETURN(pContext, pEditBuffer) return-value; // to return a return value
  134.  
  135. #define GET_WRITABLE_EDIT_BUF_OR_RETURN(CONTEXT, BUFFER) CEditBuffer* BUFFER = LO_GetEDBuffer( CONTEXT );\
  136.     if (!CEditBuffer::IsAlive(BUFFER) || !BUFFER->IsReady() || !BUFFER->IsWritable() ) return
  137.  
  138. #define GET_EDIT_BUF_OR_RETURN(CONTEXT, BUFFER) CEditBuffer* BUFFER = LO_GetEDBuffer( CONTEXT );\
  139.     if (!CEditBuffer::IsAlive(BUFFER) || !BUFFER->IsReady() ) return
  140.  
  141. #define GET_EDIT_BUF_OR_RETURN_READY_OR_NOT(CONTEXT, BUFFER) CEditBuffer* BUFFER = LO_GetEDBuffer( CONTEXT );\
  142.     if (!CEditBuffer::IsAlive(BUFFER) ) return
  143.  
  144. #define GET_WRITABLE_EDIT_BUF_OR_RETURN_READY_OR_NOT(CONTEXT, BUFFER) CEditBuffer* BUFFER = LO_GetEDBuffer( CONTEXT );\
  145.     if (!CEditBuffer::IsAlive(BUFFER) || !BUFFER->IsWritable() ) return
  146.  
  147.  
  148. //-----------------------------------------------------------------------------
  149. // Edit Classes
  150. //-----------------------------------------------------------------------------
  151. class CEditElement;
  152. class CEditLeafElement;
  153. class CEditSubDocElement;
  154. class CEditTableElement;
  155. class CEditTableRowElement;
  156. class CEditCaptionElement;
  157. class CEditTableCellElement;
  158. class CEditRootDocElement;
  159. class CEditContainerElement;
  160. class CEditListElement;
  161. class CEditTextElement;
  162. class CEditImageElement;
  163. class CEditHorizRuleElement;
  164. class CEditIconElement;
  165. class CEditEndElement;
  166. class CEditBreakElement;
  167. class CEditTargetElement;
  168. class CEditLayerElement;
  169. class CEditDivisionElement;
  170. class CParseState;
  171. class CPrintState;
  172. class CEditImageLoader;
  173. class CEditSaveObject;
  174. class CFileSaveObject;
  175. struct ED_Link;
  176. class CEditCommand;
  177. class CEditCommandGroup;
  178.  
  179. class CEditSaveData;
  180. class CEditSaveToTempData;
  181.  
  182. #ifdef DEBUG
  183. class CEditTestManager;
  184. #endif
  185. #ifdef EDITOR_JAVA
  186. // Opaque interface to Editor Plugin support classes.
  187. // (It's too expensive to pull jri in in this header file.
  188. // If we do, bsdi runs out of VM while compiling.
  189.  
  190. typedef void* EditorPluginManager;
  191. EditorPluginManager EditorPluginManager_new(MWContext* pContext);
  192. void EditorPluginManager_delete(EditorPluginManager a);
  193. XP_Bool EditorPluginManager_IsPluginActive(EditorPluginManager a);
  194. XP_Bool EditorPluginManager_PluginsExist();
  195. class CEditorPluginInterface;
  196. #endif
  197.  
  198. // Originally this was a sugared int32, but we ran into
  199. // trouble working with big-endian architectures, like the
  200. // Macintosh. So rather than being even cleverer with
  201. // macros, I decided to make it a regular class.
  202. // If this turns out to be a performance bottleneck
  203. // we can always inline it.... jhp
  204. class ED_Color {
  205. public:
  206.     ED_Color();
  207.     ED_Color(LO_Color& pLoColor);
  208.     ED_Color(int32 rgb);
  209.     ED_Color(int r, int g, int b);
  210.     ED_Color(LO_Color* pLoColor);
  211.     XP_Bool IsDefined();
  212.     XP_Bool operator==(const ED_Color& other) const;
  213.     XP_Bool operator!=(const ED_Color& other) const;
  214.     int Red();
  215.     int Green();
  216.     int Blue();
  217.     LO_Color GetLOColor();
  218.     long GetAsLong(); // 0xRRGGBB
  219.     void SetUndefined();
  220.     static ED_Color GetUndefined();
  221. private:
  222.     LO_Color m_color;
  223.     XP_Bool m_bDefined;
  224. };
  225.  
  226. // Copies the argument into a static buffer, and then upper-cases the
  227. // buffer, and returns a pointer to the buffer. You don't own the
  228. // result pointer, and you can't call twice in same line of code.
  229.  
  230. char* EDT_UpperCase(char*);
  231.  
  232. // Returns a string for the given alignment. Uses a static buffer, so
  233. // don't call twice in the same line of code.
  234.  
  235. char* EDT_AlignString(ED_Alignment align);
  236.  
  237. // Backwards-compatable macros. Should clean this up some day.
  238.  
  239. #define EDT_COLOR_DEFAULT    (ED_Color())
  240. #define EDT_RED(x)      ((x).Red())
  241. #define EDT_GREEN(x)    ((x).Green())
  242. #define EDT_BLUE(x)     ((x).Blue())
  243. #define EDT_RGB(r,g,b)  (ED_Color(r,g,b))
  244. #define EDT_LO_COLOR(pLoColor)  ED_Color(pLoColor)
  245.  
  246.  
  247. // Editor selections
  248.  
  249. // template declarations
  250. Declare_GrowableArray(int32,int32)                      // TXP_GrowableArray_int32
  251. Declare_GrowableArray(ED_Link,ED_Link*)                 // TXP_GrowableArray_ED_Link
  252. Declare_GrowableArray(EDT_MetaData,EDT_MetaData*)       // TXP_GrowableArray_EDT_MetaData
  253. Declare_GrowableArray(pChar,char*)                      // TXP_GrowableArray_pChar
  254. Declare_GrowableArray(CEditCommand,CEditCommand*)       // TXP_GrowableArray_CEditCommand
  255. #ifdef EDITOR_JAVA
  256. Declare_GrowableArray(CEditorPluginInterface,CEditorPluginInterface*)       // TXP_GrowableArray_CEditorPluginInterface
  257. #endif
  258. //cmanske - store lists of selected cell elements
  259. Declare_GrowableArray(CEditTableCellElement,CEditTableCellElement*)  // TXP_GrowableArray_CEditTableCellElement
  260. Declare_GrowableArray(LO_CellStruct,LO_CellStruct*)                  // TXP_GrowableArray_LO_CellStruct
  261. //List of tables encountered during Relayout()
  262. Declare_GrowableArray(LO_TableStruct,LO_TableStruct*)                // TXP_GrowableArray_LO_TableStruct
  263.  
  264. Declare_PtrStack(ED_Alignment,ED_Alignment)             // TXP_PtrStack_ED_Alignment
  265. Declare_PtrStack(TagType,TagType)                       // TXP_PtrStack_TagType
  266. Declare_PtrStack(CEditTextElement,CEditTextElement*)    // TXP_PtrStack_CEditTextElement
  267. Declare_PtrStack(ED_TextFormat,int32)                   // TXP_PtrStack_ED_TextFormat
  268. Declare_PtrStack(CEditCommandGroup,CEditCommandGroup*)  // TXP_PtrStack_CEditCommandGroup
  269. Declare_PtrStack(CParseState,CParseState*)              // TXP_PtrStack_CParseState
  270.  
  271. #ifdef DEBUG
  272.     #define DEBUG_EDIT_LAYOUT
  273. #endif
  274.  
  275. typedef int32 DocumentVersion;
  276.  
  277. typedef int32 ElementIndex; // For persistent insert points, a position from the start of the document.
  278. typedef int32 ElementOffset; // Within one element, an offset into an element. Is 0 or 1, except for text.
  279.  
  280. class CEditInsertPoint
  281. {
  282. public:
  283.     CEditInsertPoint();
  284.     CEditInsertPoint(CEditElement* pElement, ElementOffset iPos);
  285.     CEditInsertPoint(CEditLeafElement* pElement, ElementOffset iPos);
  286.     CEditInsertPoint(CEditElement* pElement, ElementOffset iPos, XP_Bool bStickyAfter);
  287.  
  288.     XP_Bool IsStartOfElement();
  289.     XP_Bool IsEndOfElement();
  290.     XP_Bool IsStartOfContainer();
  291.     XP_Bool IsEndOfContainer();
  292.     XP_Bool IsStartOfDocument();
  293.     XP_Bool IsEndOfDocument();
  294.  
  295.     XP_Bool GapWithBothSidesAllowed();
  296.     XP_Bool IsLineBreak();
  297.     XP_Bool IsSoftLineBreak();
  298.     XP_Bool IsHardLineBreak();
  299.     XP_Bool IsSpace(); // After insert point
  300.     XP_Bool IsSpaceBeforeOrAfter(); // Before or after insert point
  301.  
  302.     // Move forward and backward. Returns FALSE if can't move
  303.     CEditInsertPoint NextPosition();
  304.     CEditInsertPoint PreviousPosition();
  305.  
  306.     XP_Bool operator==(const CEditInsertPoint& other );
  307.     XP_Bool operator!=(const CEditInsertPoint& other );
  308.     XP_Bool operator<(const CEditInsertPoint& other );
  309.     XP_Bool operator<=(const CEditInsertPoint& other );
  310.     XP_Bool operator>=(const CEditInsertPoint& other );
  311.     XP_Bool operator>(const CEditInsertPoint& other );
  312.     XP_Bool IsDenormalizedVersionOf(const CEditInsertPoint& other);
  313.     intn Compare(const CEditInsertPoint& other );
  314.  
  315. #ifdef DEBUG
  316.     void Print(IStreamOut& stream);
  317. #endif
  318.  
  319.     CEditLeafElement* m_pElement;
  320.     ElementOffset m_iPos;
  321.     XP_Bool m_bStickyAfter;
  322.  
  323. private:
  324.     CEditElement* FindNonEmptyElement( CEditElement *pStartElement );
  325. };
  326.  
  327.  
  328. class CEditSelection
  329. {
  330. public:
  331.     CEditSelection();
  332.     CEditSelection(CEditElement* pStart, intn iStartPos, CEditElement* pEnd, intn iEndPos, XP_Bool fromStart = FALSE);
  333.     CEditSelection(const CEditInsertPoint& start, const CEditInsertPoint& end, XP_Bool fromStart = FALSE);
  334.  
  335.     XP_Bool operator==(const CEditSelection& other );
  336.     XP_Bool operator!=(const CEditSelection& other );
  337.     XP_Bool IsInsertPoint();
  338.     CEditInsertPoint* GetActiveEdge();
  339.     CEditInsertPoint* GetAnchorEdge();
  340.     CEditInsertPoint* GetEdge(XP_Bool bEnd);
  341.  
  342.     // Like ==, except ignores bFromStart.
  343.     XP_Bool EqualRange(CEditSelection& other);
  344.     XP_Bool Intersects(CEditSelection& other); // Just a test; doesn't change this.
  345.     XP_Bool Contains(CEditInsertPoint& point);
  346.     XP_Bool Contains(CEditSelection& other);
  347.     XP_Bool ContainsStart(CEditSelection& other);
  348.     XP_Bool ContainsEnd(CEditSelection& other);
  349.     XP_Bool ContainsEdge(CEditSelection& other, XP_Bool bEnd);
  350.     XP_Bool CrossesOver(CEditSelection& other);
  351.  
  352.     XP_Bool ClipTo(CEditSelection& other); // True if the result is defined. No change to this if it isn't
  353.  
  354.     CEditElement* GetCommonAncestor();
  355.     XP_Bool CrossesSubDocBoundary();
  356.     CEditSubDocElement* GetEffectiveSubDoc(XP_Bool bEnd);
  357.  
  358.     XP_Bool ExpandToNotCrossStructures(); // TRUE if this was changed
  359.     void ExpandToBeCutable();
  360.     void ExpandToIncludeFragileSpaces();
  361.     void ExpandToEncloseWholeContainers();
  362.     XP_Bool EndsAtStartOfContainer();
  363.     XP_Bool StartsAtEndOfContainer();
  364.     XP_Bool AnyLeavesSelected(); // FALSE if insert point or container end.
  365.     XP_Bool IsContainerEnd(); // TRUE if just contains the end of a container.
  366.     // Useful for cut & delete, where you don't replace the final container mark
  367.     XP_Bool ContainsLastDocumentContainerEnd();
  368.     void ExcludeLastDocumentContainerEnd();
  369.  
  370.     CEditContainerElement* GetStartContainer();
  371.     CEditContainerElement* GetClosedEndContainer(); // Not 1/2 open!
  372.  
  373. #ifdef DEBUG
  374.     void Print(IStreamOut& stream);
  375. #endif
  376.  
  377.     CEditInsertPoint m_start;
  378.     CEditInsertPoint m_end;
  379.     XP_Bool m_bFromStart;
  380.     
  381.     //cmanske: Needed to differentiate between an empty selection 
  382.     //  (indicating we should get the current selection)
  383.     //  and a selection obtained from a table cell
  384.     XP_Bool IsEmpty() { return (m_start.m_pElement == 0); }
  385. };
  386.  
  387.  
  388. class CPersistentEditInsertPoint
  389. {
  390. public:
  391.     // m_bStickyAfter defaults to TRUE
  392.     CPersistentEditInsertPoint();
  393.     CPersistentEditInsertPoint(ElementIndex index);
  394.     CPersistentEditInsertPoint(ElementIndex index, XP_Bool bStickyAfter);
  395. #ifdef DEBUG
  396.     void Print(IStreamOut& stream);
  397. #endif
  398.     XP_Bool operator==(const CPersistentEditInsertPoint& other );
  399.     XP_Bool operator!=(const CPersistentEditInsertPoint& other );
  400.     XP_Bool operator<(const CPersistentEditInsertPoint& other );
  401.     XP_Bool operator<=(const CPersistentEditInsertPoint& other );
  402.     XP_Bool operator>=(const CPersistentEditInsertPoint& other );
  403.     XP_Bool operator>(const CPersistentEditInsertPoint& other );
  404.  
  405.     XP_Bool IsEqualUI(const CPersistentEditInsertPoint& other );
  406.  
  407.     // Used for undo
  408.     // delta = this - other;
  409.     void ComputeDifference(CPersistentEditInsertPoint& other, CPersistentEditInsertPoint& delta);
  410.     // result = this + delta;
  411.     void AddRelative(CPersistentEditInsertPoint& delta, CPersistentEditInsertPoint& result);
  412.  
  413.     ElementIndex m_index;
  414.     // If this insert point falls between two elements, and
  415.     // m_bStickyAfter is TRUE, then this insert point is attached
  416.     // to the start of the second element. If m_bStickyAfter
  417.     // is false, then this insert point is attached to the end of
  418.     // the first element. It is FALSE by default. It is ignored
  419.     // by all of the comparison operators except IsEqualUI. It
  420.     // is ignored by ComputeDifference and AddRelative
  421.  
  422.      XP_Bool m_bStickyAfter;
  423. };
  424.  
  425. #ifdef DEBUG
  426.     #define DUMP_PERSISTENT_EDIT_INSERT_POINT(s, pt) { XP_TRACE(("%s %d", s, pt.m_index));}
  427. #else
  428.     #define DUMP_PERSISTENT_EDIT_INSERT_POINT(s, pt) {}
  429. #endif
  430.  
  431. class CPersistentEditSelection
  432. {
  433. public:
  434.     CPersistentEditSelection();
  435.     CPersistentEditSelection(const CPersistentEditInsertPoint& start, const CPersistentEditInsertPoint& end);
  436. #ifdef DEBUG
  437.     void Print(IStreamOut& stream);
  438. #endif
  439.     XP_Bool operator==(const CPersistentEditSelection& other );
  440.     XP_Bool operator!=(const CPersistentEditSelection& other );
  441.     XP_Bool SelectedRangeEqual(const CPersistentEditSelection& other ); // Ignores m_bFromStart
  442.  
  443.     ElementIndex GetCount();
  444.     XP_Bool IsInsertPoint();
  445.     CPersistentEditInsertPoint* GetEdge(XP_Bool bEnd);
  446.  
  447.     // Used for undo
  448.     // change this by the same way that original was changed into modified.
  449.     void Map(CPersistentEditSelection& original, CPersistentEditSelection& modified);
  450.  
  451.     CPersistentEditInsertPoint m_start;
  452.     CPersistentEditInsertPoint m_end;
  453.     XP_Bool m_bFromStart;
  454. };
  455.  
  456. #ifdef DEBUG
  457.     #define DUMP_PERSISTENT_EDIT_SELECTION(s, sel) { XP_TRACE(("%s %d-%d %d", s,\
  458.         sel.m_start.m_index,\
  459.         sel.m_end.m_index,\
  460.         sel.m_bFromStart));}
  461. #else
  462.     #define DUMP_PERSISTENT_EDIT_SELECTION(s, sel) {}
  463. #endif
  464.  
  465. #ifdef DEBUG
  466. void TraceLargeString(char* b);
  467. #endif
  468.  
  469. //
  470. // Element type used during stream constructor
  471. //
  472. enum EEditElementType {
  473.     eElementNone,
  474.     eElement,
  475.     eTextElement,
  476.     eImageElement,
  477.     eHorizRuleElement,
  478.     eBreakElement,
  479.     eContainerElement,
  480.     eIconElement,
  481.     eTargetElement,
  482.     eListElement,
  483.     eEndElement,
  484.     eTableElement,
  485.     eTableRowElement,
  486.     eTableCellElement,
  487.     eCaptionElement,
  488.     eLayerElement,
  489.     eDivisionElement,
  490.     eInternalAnchorElement
  491. };
  492.  
  493. //
  494. // Copy type written to stream
  495. //    Used to decide how to paste into existing table
  496. //
  497. enum EEditCopyType {
  498.     eCopyNormal,        // Default = 0. Normal HTML copying, not a table
  499.     eCopyTable,         // Entire table - paste normally or embeded into existing table
  500.     eCopyRows,          // Entire rows - inserts/overlays into existing table
  501.     eCopyColumns,       // Entire columns   "
  502.     eCopyCells          // Arbitrary cells - overlay selected target cells in table
  503. };
  504.  
  505. //
  506. // CEditElement
  507. //
  508. class CEditElement {
  509. private:
  510.     TagType m_tagType;
  511.     CEditElement* m_pParent;
  512.     CEditElement* m_pNext;
  513.     CEditElement* m_pChild;
  514.     char *m_pTagData;               // hack! remainder of tag data for regen.
  515.  
  516. protected:
  517.     char* GetTagData(){ return m_pTagData; };
  518.     void SetTagData(char* tagData);
  519.  
  520. public:
  521.  
  522.     // ctor, dtor
  523.     CEditElement(CEditElement *pParent, TagType tagType, char* pData = NULL);
  524.     CEditElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  525.     CEditElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  526.     virtual ~CEditElement();
  527.  
  528.     static CEditElement* StreamCtor( IStreamIn *pIn, CEditBuffer *pBuffer );
  529.     static CEditElement* StreamCtorNoChildren( IStreamIn *pIn, CEditBuffer *pBuffer );
  530.     virtual void StreamInChildren(IStreamIn* pIn, CEditBuffer* pBuffer);
  531.  
  532.     //
  533.     // Accessor functions
  534.     //
  535.     CEditElement* GetParent(){ return m_pParent; }
  536.     CEditElement* GetNextSibling(){ return m_pNext; }
  537.     CEditElement* GetPreviousSibling();
  538.     CEditElement* GetChild(){ return m_pChild; }
  539.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild);
  540.     void SetParent(CEditElement* pParent){m_pParent = pParent;}
  541.     void SetChild(CEditElement *pChild);
  542.     void SetNextSibling(CEditElement* pNext);
  543.  
  544.     CEditElement* GetLastChild();
  545.     CEditElement* GetLastMostChild();
  546.     CEditElement* GetFirstMostChild();
  547.  
  548.     CEditCaptionElement* GetCaption(); // Returns containing cell, or NULL if none.
  549.     CEditCaptionElement* GetCaptionIgnoreSubdoc(); // Returns containing cell, or NULL if none.
  550.     CEditTableCellElement* GetTableCell(); // Returns containing cell, or NULL if none.
  551.     CEditTableCellElement* GetTableCellIgnoreSubdoc(); // Returns containing cell, or NULL if none.
  552.     CEditTableRowElement* GetTableRow(); // Returns containing row, or NULL if none.
  553.     CEditTableRowElement* GetTableRowIgnoreSubdoc(); // Returns containing row, or NULL if none.
  554.     CEditTableElement* GetTable(); // Returns containing table, or NULL if none.
  555.     CEditTableElement* GetTableIgnoreSubdoc(); // Returns containing table, or NULL if none.
  556.     CEditLayerElement* GetLayer(); // Returns containing Layer, or NULL if none.
  557.     CEditLayerElement* GetLayerIgnoreSubdoc(); // Returns containing Layer, or NULL if none.
  558.     CEditSubDocElement* GetSubDoc(); // Returns containing sub-doc, or NULL if none.
  559.     CEditSubDocElement* GetSubDocSkipRoot(); // Returns containing sub-doc, or NULL if none.
  560.     CEditRootDocElement* GetRootDoc(); // Returns containing root, or NULL if none.
  561.     XP_Bool InMungableMailQuote(); // Returns true if this element is within a mungable mail quote.
  562.     XP_Bool InMailQuote(); // Returns true if this element is within a mail quote.
  563.     CEditListElement* GetMailQuote(); // Returns containing mail quote or NULL.
  564.  
  565.     //cmanske A bit more readable
  566.     XP_Bool IsInTableCell() { return NULL != GetTableCellIgnoreSubdoc(); }
  567.     XP_Bool IsInTable() { return NULL != GetTableIgnoreSubdoc(); }
  568.  
  569.     CEditElement* GetTopmostTableOrLayer(); // Returns topmost containing table or Layer, or NULL if none.
  570.     CEditElement* GetTableOrLayerIgnoreSubdoc(); // Returns containing table or Layer, or NULL if none.
  571.     CEditElement* GetSubDocOrLayerSkipRoot();
  572.  
  573.     CEditBuffer* GetEditBuffer(); // returns the edit buffer if the element is in one.
  574.  
  575.     virtual ED_Alignment GetDefaultAlignment();
  576.     virtual ED_Alignment GetDefaultVAlignment();
  577.  
  578.     TagType GetType(){ return m_tagType; }
  579.     void SetType( TagType t ){ m_tagType = t; }
  580.  
  581.     // Returns TRUE only if tag has WIDTH or HEIGHT already defined
  582.     // Use NULL for params if you don't need those values
  583.     XP_Bool GetWidth(XP_Bool * pPercent = NULL, int32 * pWidth = NULL);
  584.     XP_Bool GetHeight(XP_Bool * pPercent = NULL, int32 * pHeight = NULL);
  585.     
  586.     virtual void SetSize(XP_Bool bWidthPercent, int32 iWidth,
  587.                          XP_Bool bHeightPercent, int32 iHeight);
  588.     
  589.     virtual XP_Bool CanReflow();
  590.     
  591.     //
  592.     // Cast routines.
  593.     //
  594.     CEditTextElement* Text();
  595.  
  596.     virtual XP_Bool IsLeaf();
  597.     CEditLeafElement* Leaf();
  598.  
  599.     virtual XP_Bool IsRoot();
  600.     CEditRootDocElement* Root();
  601.  
  602.     virtual XP_Bool IsContainer();
  603.     CEditContainerElement* Container();
  604.  
  605.     //get previous non empty container to querry for preopen conditions ect
  606.     CEditContainerElement*  GetPreviousNonEmptyContainer();
  607.     //get next non empty container to querry for preclose conditions ect
  608.     CEditContainerElement*  GetNextNonEmptyContainer();
  609.  
  610.     virtual XP_Bool IsList();
  611.     CEditListElement* List();
  612.  
  613.     virtual XP_Bool IsBreak();
  614.     CEditBreakElement* Break();
  615.  
  616.     virtual XP_Bool CausesBreakBefore();
  617.     virtual XP_Bool CausesBreakAfter();
  618.     virtual XP_Bool AllowBothSidesOfGap();
  619.  
  620.     virtual XP_Bool IsImage();
  621.     CEditImageElement* Image();
  622.     virtual XP_Bool IsIcon();
  623.     CEditIconElement* Icon();
  624.  
  625.     CEditTargetElement* Target();
  626.  
  627.     CEditHorizRuleElement* HorizRule();
  628.     virtual XP_Bool IsRootDoc();
  629.     CEditRootDocElement* RootDoc();
  630.     virtual XP_Bool IsSubDoc();
  631.     CEditSubDocElement* SubDoc();
  632.     virtual XP_Bool IsTable();
  633.     CEditTableElement* Table();
  634.     virtual XP_Bool IsTableRow();
  635.     CEditTableRowElement* TableRow();
  636.     virtual XP_Bool IsTableCell();
  637.     CEditTableCellElement* TableCell();
  638.     virtual XP_Bool IsCaption();
  639.     CEditCaptionElement* Caption();
  640.     virtual XP_Bool IsText();
  641.     virtual XP_Bool IsLayer();
  642.     CEditLayerElement* Layer();
  643.     virtual XP_Bool IsDivision();
  644.     CEditDivisionElement* Division();
  645.  
  646.     XP_Bool IsEndOfDocument();
  647.     virtual XP_Bool IsEndContainer();
  648.  
  649.     // Can this element contain a paragraph?
  650.     virtual XP_Bool IsContainerContainer();
  651.  
  652.     XP_Bool IsA( int tagType ){ return m_tagType == tagType; }
  653.     XP_Bool Within( int tagType );
  654.     XP_Bool InFormattedText();
  655.     CEditContainerElement* FindContainer(); // Returns this if this is a container.
  656.     CEditContainerElement* FindEnclosingContainer(); // Starts search with parent of this.
  657.     CEditElement* FindList();
  658.     void FindList( CEditContainerElement*& pContainer, CEditListElement*& pList );
  659.     CEditElement* FindContainerContainer();
  660.  
  661.     //
  662.     // Tag Generation functions
  663.     //
  664.     virtual PA_Tag* TagOpen( int iEditOffset );
  665.     virtual PA_Tag* TagEnd( );
  666.     void SetTagData( PA_Tag* pTag, char* pTagData);
  667.  
  668.     //
  669.     // Output routines.
  670.     //
  671.     virtual void PrintOpen( CPrintState *pPrintState );
  672.     void InternalPrintOpen( CPrintState *pPrintState, char* pTagData );
  673.     virtual void PrintEnd( CPrintState *pPrintState );
  674.     virtual void StreamOut( IStreamOut *pOut );
  675.     virtual void PartialStreamOut( IStreamOut *pOut, CEditSelection& selection );
  676.     virtual XP_Bool ShouldStreamSelf( CEditSelection& local, CEditSelection& selection);
  677.     virtual void StreamToPositionalText( IStreamOut * /*pOut*/, XP_Bool /*bEnd*/ ){}
  678.  
  679.  
  680.     virtual EEditElementType GetElementType();
  681.  
  682.     // Get parent table of any element
  683.     CEditTableElement* GetParentTable();
  684.  
  685.     virtual XP_Bool Reduce( CEditBuffer *pBuffer );
  686.  
  687.     // Selection utilities
  688.     XP_Bool ClipToMe(CEditSelection& selection, CEditSelection& local); // Returns TRUE if selection intersects with "this".
  689.     virtual void GetAll(CEditSelection& selection); // Get selection that selects all of this.
  690.     
  691.     //cmanske: Used only by CEditTableElement and CEditTableCellElement
  692.     virtual XP_Bool IsSelected() {return FALSE; }
  693.  
  694.     // iterators
  695.     typedef XP_Bool (CEditElement::*PMF_EditElementTest)(void*);
  696.  
  697.     CEditElement* FindNextElement( PMF_EditElementTest pmf, void *pData );
  698.     CEditElement* UpRight( PMF_EditElementTest pmf, void *pTestData );
  699.     CEditElement* DownRight( PMF_EditElementTest pmf,void *pTestData,
  700.             XP_Bool bIgnoreThis = FALSE );
  701.  
  702.     CEditElement* FindPreviousElement( PMF_EditElementTest pmf, void *pTestData );
  703.     CEditElement* UpLeft( PMF_EditElementTest pmf, void *pTestData );
  704.     CEditElement* DownLeft( PMF_EditElementTest pmf, void *pTestData,
  705.             XP_Bool bIgnoreThis = FALSE );
  706.  
  707.     XP_Bool TestIsTrue( PMF_EditElementTest pmf, void *pTestData ){
  708.                 return (this->*pmf)(pTestData); }
  709.  
  710.     //
  711.     // Search routines to be applied FindNextElement and FindPreviousElement
  712.     //
  713.     XP_Bool FindText( void* /*pVoid*/ );
  714.     XP_Bool FindTextAll( void* /*pVoid*/ );
  715.     XP_Bool FindLeaf( void* /*pVoid*/ );
  716.     XP_Bool FindLeafAll( void* /*pVoid*/ );
  717.     XP_Bool FindImage( void* /*pvoid*/ );
  718.     XP_Bool FindTarget( void* /*pvoid*/ );
  719.     XP_Bool FindUnknownHTML( void* /*pvoid*/ );
  720.     XP_Bool SplitContainerTest( void* /*pVoid*/ );
  721.     XP_Bool SplitFormattingTest( void* pVoid );
  722.     XP_Bool FindTable( void* /*pvoid*/ );
  723.     XP_Bool FindTableRow( void* /*pvoid*/ );
  724.     XP_Bool FindTableCell( void* /*pvoid*/ );
  725.     
  726.  
  727.     XP_Bool FindContainer( void* /*pVoid*/ );
  728.  
  729.     //
  730.     // Split the tree.  You can stop when pmf returns true.
  731.     //
  732.     virtual CEditElement* Split(CEditElement *pLastChild,
  733.                                 CEditElement* pCloneTree,
  734.                                 PMF_EditElementTest pmf,
  735.                                 void *pData);
  736.  
  737.     virtual CEditElement* Clone( CEditElement *pParent = 0 );
  738.     CEditElement* CloneFormatting( TagType endType );
  739.     virtual void Unlink();
  740.     virtual void Merge( CEditElement *pAppendBlock, XP_Bool bCopyAppendAttributes = TRUE );
  741.  
  742.  
  743. #ifdef DEBUG
  744.     virtual void ValidateTree();
  745. #endif
  746.     CEditElement* InsertAfter( CEditElement *pPrev );
  747.     CEditElement* InsertBefore( CEditElement *pNext );
  748.     void InsertAsFirstChild( CEditElement *pParent );
  749.     void InsertAsLastChild( CEditElement *pParent );
  750.  
  751.     virtual XP_Bool IsFirstInContainer();
  752.     CEditTextElement* TextInContainerAfter();
  753.     CEditTextElement* PreviousTextInContainer();
  754.     virtual CEditElement* Divide(int iOffset);
  755.  
  756.     CEditLeafElement* PreviousLeafInContainer();
  757.     CEditLeafElement* LeafInContainerAfter();
  758.  
  759.     CEditLeafElement* PreviousLeaf() { return (CEditLeafElement*) FindPreviousElement( &CEditElement::FindLeaf, 0 ); }
  760.     CEditLeafElement* NextLeaf() { return (CEditLeafElement*) FindNextElement( &CEditElement::FindLeaf, 0 ); }
  761.     CEditLeafElement* NextLeafAll() { return (CEditLeafElement*) FindNextElement( &CEditElement::FindLeafAll, 0 ); }
  762.     CEditLeafElement* NextLeafAll(XP_Bool bForward);
  763.     CEditContainerElement* NextContainer() { return (CEditContainerElement*) FindNextElement( &CEditElement::FindContainer, 0 ); }
  764.     CEditContainerElement* PreviousContainer() { return (CEditContainerElement*) FindPreviousElement( &CEditElement::FindContainer, 0 ); }
  765.  
  766.     CEditElement* GetRoot();
  767.     CEditElement* GetCommonAncestor(CEditElement* pOther); // NULL if not in same tree
  768.     CEditElement* GetChildContaining(CEditElement* pDescendant); // NULL if not a descendant
  769.  
  770.     XP_Bool DeleteElement( CEditElement *pTellIfKilled );
  771.     void DeleteChildren();
  772.  
  773.     // should be in Container class
  774.     int GetDefaultFontSize();
  775.  
  776.     // To and from persistent insert points
  777.     virtual CEditInsertPoint IndexToInsertPoint(ElementIndex index, XP_Bool bStickyAfter);
  778.     virtual CPersistentEditInsertPoint GetPersistentInsertPoint(ElementOffset offset);
  779.     virtual ElementIndex GetElementIndexOf(CEditElement* child); // asserts if argument is not a child.
  780.     virtual ElementIndex GetPersistentCount();
  781.     ElementIndex GetElementIndex();
  782.  
  783.     virtual void FinishedLoad( CEditBuffer* pBuffer );
  784.     virtual void AdjustContainers( CEditBuffer* pBuffer );
  785.  
  786.     int16 GetWinCSID(); // International Character set ID
  787.  
  788. protected:
  789.     virtual void Finalize();
  790.     void EnsureSelectableSiblings(CEditBuffer* pBuffer);
  791.  
  792. private:
  793.     void CommonConstructor();
  794.     // For CEditElement constructor, where the vtable isn't
  795.     // set up enough to check if the item is acceptable.
  796.     void RawSetNextSibling(CEditElement* pNext) {m_pNext = pNext; }
  797.     void RawSetChild(CEditElement* pChild) {m_pChild = pChild; }
  798. };
  799.  
  800.  
  801. //
  802. // CEditSubDocElement - base class for the root, captions, and table data cells
  803. //
  804. class CEditSubDocElement: public CEditElement {
  805. public:
  806.     CEditSubDocElement(CEditElement *pParent, int tagType, char* pData = NULL);
  807.     CEditSubDocElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  808.     CEditSubDocElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  809.  
  810.     virtual XP_Bool IsSubDoc() { return TRUE; }
  811.     static CEditSubDocElement* Cast(CEditElement* pElement) {
  812.         return pElement && pElement->IsSubDoc() ? (CEditSubDocElement*) pElement : 0; }
  813.  
  814.     virtual XP_Bool Reduce( CEditBuffer *pBuffer );
  815.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild){
  816.             return ! pChild.IsLeaf();
  817.         }
  818.     virtual void FinishedLoad( CEditBuffer* pBuffer );
  819. };
  820.  
  821. class CEditTableElement: public CEditElement {
  822. public:
  823.     CEditTableElement(intn columns, intn rows);
  824.     CEditTableElement(CEditElement *pParent, PA_Tag *pTag, int16 csid, ED_Alignment align);
  825.     CEditTableElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  826.     virtual ~CEditTableElement();
  827.  
  828.     virtual XP_Bool IsTable() { return TRUE; }
  829.     static CEditTableElement* Cast(CEditElement* pElement) {
  830.         return pElement && pElement->IsTable() ? (CEditTableElement*) pElement : 0; }
  831.     virtual EEditElementType GetElementType() { return eTableElement; }
  832.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild){
  833.             return pChild.IsTableRow() || pChild.IsCaption();
  834.         }
  835.     virtual void FinishedLoad( CEditBuffer* pBuffer );
  836.     void AdjustCaption();
  837.     virtual PA_Tag* TagOpen(int iEditOffset);
  838.     PA_Tag* InternalTagOpen(int iEditOffset, XP_Bool bPrinting);
  839.     virtual PA_Tag* TagEnd();
  840.  
  841.     void InsertRows(int32 Y, int32 newY, intn number, CEditTableElement* pSource = NULL);
  842.     void InsertColumns(int32 X, int32 newX, intn number, CEditTableElement* pSource = NULL);
  843.     void DeleteRows(int32 Y, intn number, CEditTableElement* pUndoContainer = NULL);
  844.     void DeleteColumns(int32 X, intn number, CEditTableElement* pUndoContainer = NULL);
  845.     
  846.     // Not used much - index based
  847.     CEditTableRowElement* FindRow(intn number);
  848.  
  849.     // Find first row containing a cell that has Y as its top
  850.     // Optionally return the "logical" row index
  851.     CEditTableRowElement* GetRow(int32 Y, intn *pRow = NULL);
  852.  
  853.     // Find first geometric cell that is at or spans given Y value
  854.     // The logical row is written to m_iGetRow
  855.     CEditTableCellElement* GetFirstCellInRow(int32 Y, XP_Bool bSpan = FALSE);
  856.     CEditTableCellElement* GetFirstCellInRow(CEditTableCellElement *pCell, XP_Bool bSpan = FALSE);
  857.     // Find next cell using the supplied cell's Y value 
  858.     //  (bSpan is FALSE, so Y must match exactly)
  859.     // If pCell is NULL, use the same Y and bSpan as used for GetFirstCellInRow()
  860.     // The logical row is written to the element's m_iGetRow
  861.     CEditTableCellElement* GetNextCellInRow(CEditTableCellElement *pCell = NULL);
  862.     
  863.     // Find previous and cell using supplied cell's Y value 
  864.     //  (does not depend on data from GetFirstCellInRow)
  865.     CEditTableCellElement* GetPreviousCellInRow(CEditTableCellElement *pCell);
  866.     CEditTableCellElement* GetLastCellInRow(CEditTableCellElement *pCell);
  867.  
  868.     // Same as above, but finds columns
  869.     CEditTableCellElement* GetFirstCellInColumn(int32 X, XP_Bool bSpan = FALSE);
  870.     CEditTableCellElement* GetFirstCellInColumn(CEditTableCellElement *pCell, XP_Bool bSpan = FALSE);
  871.     CEditTableCellElement* GetNextCellInColumn(CEditTableCellElement *pCell = NULL);
  872.     
  873.     // Find previous and last cell using supplied cell's X value 
  874.     //  (does not depend on data from GetFirstCellInRow)
  875.     CEditTableCellElement* GetPreviousCellInColumn(CEditTableCellElement *pCell);
  876.     CEditTableCellElement* GetLastCellInColumn(CEditTableCellElement *pCell);
  877.  
  878.     CEditCaptionElement* GetCaption();
  879.     void SetCaption(CEditCaptionElement*);
  880.     void DeleteCaption();
  881.  
  882.     void SetData( EDT_TableData *pData );
  883.     EDT_TableData* GetData();
  884.     EDT_TableData* ParseParams( PA_Tag *pTag, int16 csid );
  885.     static EDT_TableData* NewData();
  886.     static void FreeData( EDT_TableData *pData );
  887.  
  888.     void SetBackgroundColor( ED_Color iColor );
  889.     ED_Color GetBackgroundColor();
  890.     void SetBackgroundImage( char* pImage );
  891.     char* GetBackgroundImage();
  892.  
  893.     // Override printing and taging, since we don't allow ALIGN tag when editing.
  894.     virtual void PrintOpen( CPrintState *pPrintState );
  895.     virtual void PrintEnd( CPrintState *pPrintState );
  896.     char* CreateTagData(EDT_TableData *pData, XP_Bool bPrinting);
  897.  
  898.     virtual void StreamOut( IStreamOut *pOut);
  899.  
  900.     //cmanske:
  901.     // Get corresponding Layout table element
  902.     LO_TableStruct* GetLoTable();
  903.  
  904.     // Get width of window view or parent cell of a table
  905.     // Supply pLoTable if known, else find it
  906.     void GetParentSize(MWContext *pContext, int32 *pWidth, int32 *pHeight = NULL, LO_TableStruct *pLoTable = NULL);
  907.  
  908.     // See edttypes.h for dConvert table and all rows and cells to Percent mode or not
  909.     void SetTableMode(MWContext *pContext, int iTableMode);
  910.     int32 GetInterCellSpace() {return m_iInterCellSpace; }
  911.     int32 GetWidth() {return m_iWidthPixels; }
  912.     int32 GetHeight() {return m_iHeightPixels; }
  913.     int32 GetWidthOrPercent() { return m_iWidth; }
  914.     int32 GetHeightOrPercent() { return m_iHeight; }
  915.  
  916.     // Get first cell in table. 
  917.     //  Use GetNextCellInTable() or resulting pCell->GetNextCellInTable() 
  918.     //     to walk through the table, wrapping around rows,
  919.     //  or resultCell->pGetNextCellInLogicalRow() to walk through cells in the row
  920.     CEditTableCellElement* GetFirstCell();
  921.  
  922.     // Result from above is stored in m_pCurrentCell    
  923.     CEditTableCellElement* GetNextCellInTable(intn *pRowCounter = NULL);
  924.  
  925.     // Analogous routine for rows
  926.     CEditTableRowElement* GetFirstRow();
  927.     
  928.     // This just counts rows - return m_iRows if it is set
  929.     intn GetRows();
  930.     
  931.     // Max of number of columns in all rows
  932.     intn GetColumns();
  933.     // See comment below for m_iMaxColumns
  934.     intn GetMaxColumns() {return m_iMaxColumns; }
  935.  
  936.     // Get number of columns between given values    
  937.     intn GetColumnsSpanned(int32 iStartX, int32 iEndX);
  938.  
  939.     // Also figure these out during FixupTableData
  940.     // Used to tell when we are in first row or column of table
  941.     int32 GetFirstColumnX() {return m_iFirstColumnX;}
  942.     void SetFirstColumnX(int32 X) {m_iFirstColumnX = X;}
  943.     int32 GetFirstRowY() {return m_iFirstRowY;}
  944.     void SetFirstRowY(int32 Y) { m_iFirstRowY = Y;}
  945.  
  946. private:
  947.     ED_Color m_backgroundColor;
  948.     char* m_pBackgroundImage;
  949.     ED_Alignment m_align;
  950.     ED_Alignment m_malign;
  951.  
  952.     //Actual width, as determined from layout
  953.     // See comments for similar params in CEditTableCellElement
  954.     int32   m_iWidthPixels;       
  955.     // This is % of parent (when bWidthPercent = TRUE) or absolute (in pixels)
  956.     XP_Bool m_iWidth;
  957.     XP_Bool m_bWidthPercent;       
  958.  
  959.     int32   m_iHeightPixels;       
  960.     int32   m_iHeight;
  961.     XP_Bool m_bHeightPercent;       
  962.  
  963.     // Pixels between cells
  964.     int32   m_iInterCellSpace;
  965.  
  966.     int32   m_iFirstColumnX;
  967.     int32   m_iFirstRowY;
  968.  
  969.     // Total number in table
  970.     // Columns are tricky - max number of possible columns,
  971.     //    which is sensitive to ROWSPAN and COLSPAN
  972.     //    calculated in CEditBuffer::FixupTableData()
  973.     // Thus, this may be more than GetColumns(), which doesn't include RowSpan effect
  974.     int32   m_iMaxColumns;
  975.     
  976.     // Rows are straight forward. This should == result of GetRows();
  977.     int32   m_iRows;
  978.  
  979.     // Used by GetFirstCell() and GetNextCellInTable()
  980.     CEditTableCellElement *m_pCurrentCell;
  981.  
  982.     // For use with GetFirstCellInRow/Column and GetNextCellInRow/Column
  983.     CEditTableCellElement *m_pFirstCellInColumnOrRow;
  984.     CEditTableCellElement *m_pNextCellInColumnOrRow;
  985.     int32                  m_iColX;
  986.     int32                  m_iRowY;
  987.     XP_Bool                m_bSpan;
  988.     intn                   m_iGetRow;
  989.  
  990. public:
  991.     intn m_iBackgroundSaveIndex;
  992.  
  993. };
  994.  
  995. class CEditTableRowElement: public CEditElement {
  996. public:
  997.     CEditTableRowElement();
  998.     CEditTableRowElement(intn cells);
  999.     CEditTableRowElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  1000.     CEditTableRowElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1001.     virtual ~CEditTableRowElement();
  1002.  
  1003.     virtual XP_Bool IsTableRow() { return TRUE; }
  1004.     static CEditTableRowElement* Cast(CEditElement* pElement) {
  1005.         return pElement && pElement->IsTableRow() ? (CEditTableRowElement*) pElement : 0; }
  1006.     virtual EEditElementType GetElementType() { return eTableRowElement; }
  1007.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild){
  1008.             return pChild.IsTableCell();
  1009.         }
  1010.     virtual void FinishedLoad( CEditBuffer* pBuffer );
  1011.  
  1012.     intn GetCells();
  1013.     // Use actual cell X and Y for Insert and Delete logic
  1014.     void InsertCells(int32 X, int32 newX, intn number, CEditTableRowElement* pSource = NULL);
  1015.     // Append (move) cells in supplied row to this row and delete supplied row if requested
  1016.     // (Note: Unlike most other "insert" methods, "this" is the existing row, not row to be inserted)
  1017.     // Returns the number of cells "positions" appended (sum of COLSPAN of appended cells)
  1018.     intn AppendRow( CEditTableRowElement *pAppendRow, XP_Bool bDeleteRow = TRUE );
  1019.     // Add extra empty cells to fill out a row to specified amount
  1020.     //   or use current table's max columns if iColumns is 0
  1021.     void PadRowWithEmptyCells(intn iColumns = 0);
  1022.  
  1023.     void DeleteCells(int32 X, intn number, CEditTableRowElement* pUndoContainer = NULL);
  1024.     // Find cell at specific location in column
  1025.     CEditTableCellElement* FindCell(int32 X, XP_Bool bIncludeRightEdge = FALSE);
  1026.  
  1027.     void SetData( EDT_TableRowData *pData );
  1028.     EDT_TableRowData* GetData( );
  1029.     static EDT_TableRowData* ParseParams( PA_Tag *pTag, int16 csid );
  1030.     static EDT_TableRowData* NewData();
  1031.     static void FreeData( EDT_TableRowData *pData );
  1032.     void SetBackgroundColor( ED_Color iColor );
  1033.     ED_Color GetBackgroundColor();
  1034.     void SetBackgroundImage( char* pImage );
  1035.     char* GetBackgroundImage();
  1036.     // Not sure if we need this, but it will be useful
  1037.     //   for padding tables with ragged right edges
  1038.     intn GetColumns() {return m_iColumns; }
  1039.     void SetColumns(intn iColumns) {m_iColumns = iColumns; }
  1040.  
  1041.     CEditTableRowElement *GetNextRow();
  1042.     // Use resultCell->pGetNextCellInLogicalRow() to walk through cells in row
  1043.     CEditTableCellElement *GetFirstCell();
  1044.  
  1045. private:
  1046.     ED_Color m_backgroundColor;
  1047.     char* m_pBackgroundImage;
  1048.     // Total number of "physical" columns in row
  1049.     //  (i.e., includes effect of COLSPAN and ROWSPAN)
  1050.     intn m_iColumns;
  1051.  
  1052. public:
  1053.     intn m_iBackgroundSaveIndex;
  1054.  
  1055. };
  1056.  
  1057. class CEditCaptionElement: public CEditSubDocElement {
  1058. public:
  1059.     CEditCaptionElement();
  1060.     CEditCaptionElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  1061.     CEditCaptionElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1062.  
  1063.     virtual XP_Bool IsCaption() { return TRUE; }
  1064.     static CEditCaptionElement* Cast(CEditElement* pElement) {
  1065.         return pElement && pElement->IsCaption() ? (CEditCaptionElement*) pElement : 0; }
  1066.     virtual EEditElementType GetElementType() { return eCaptionElement; }
  1067.  
  1068.     void SetData( EDT_TableCaptionData *pData );
  1069.     EDT_TableCaptionData* GetData( );
  1070.     EDT_TableCaptionData* GetData( int16 csid );
  1071.     static EDT_TableCaptionData* ParseParams( PA_Tag *pTag, int16 csid );
  1072.     static EDT_TableCaptionData* NewData();
  1073.     static void FreeData( EDT_TableCaptionData *pData );
  1074. };
  1075.  
  1076. // Table data and Table header
  1077.  
  1078. class CEditTableCellElement: public CEditSubDocElement {
  1079. public:
  1080.     CEditTableCellElement();
  1081.     CEditTableCellElement(XP_Bool bIsHeader);
  1082.     CEditTableCellElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  1083.     CEditTableCellElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1084.     virtual ~CEditTableCellElement();
  1085.  
  1086.     virtual XP_Bool IsTableCell();
  1087.     static CEditTableCellElement* Cast(CEditElement* pElement) {
  1088.         return pElement && pElement->IsTableCell() ? (CEditTableCellElement*) pElement : 0; }
  1089.     virtual EEditElementType GetElementType();
  1090.     virtual ED_Alignment GetDefaultAlignment();
  1091.  
  1092.     XP_Bool IsTableData();
  1093.  
  1094.     void SetData( EDT_TableCellData *pData );
  1095.     // Supply the csid if getting data for table not
  1096.     //  yet part of doc, as when pasting from stream
  1097.     EDT_TableCellData* GetData(int16 csid = 0);
  1098.  
  1099.     // Clear mask bits for attributes different from supplied data
  1100.     void MaskData( EDT_TableCellData *pData );
  1101.     
  1102.     EDT_TableCellData* ParseParams( PA_Tag *pTag, int16 csid );
  1103.     static EDT_TableCellData* NewData();
  1104.     static void FreeData( EDT_TableCellData *pData );
  1105.     void SetBackgroundColor( ED_Color iColor );
  1106.     ED_Color GetBackgroundColor();
  1107.     void SetBackgroundImage( char* pImage );
  1108.     char* GetBackgroundImage();
  1109.  
  1110.     //cmanske:
  1111.     // Get corresponding Layout struct
  1112.     LO_CellStruct* GetLoCell();
  1113.  
  1114.     // Next cell in table - wraps around end of each
  1115.     //  row until end of table is found (returns null)
  1116.     // If pRowCount is supplied, value it is incremented
  1117.     //   when cell returned is 1st one in a next row
  1118.     CEditTableCellElement* GetNextCellInTable(intn *pRowCounter = NULL);
  1119.     // Similar to above, but finds previous cell until beginning is found (returns null)
  1120.     // If pRowCount is supplied, value it is decremented
  1121.     //   when cell returned is 1st one in a previous row
  1122.     CEditTableCellElement* GetPreviousCellInTable(intn *pRowCounter = NULL);
  1123.     
  1124.     // This gets next cell in the same logical row
  1125.     CEditTableCellElement* GetNextCellInLogicalRow();
  1126.  
  1127.     // Find first geometric cell that is at 
  1128.     //  given X (for column) or Y (for row)value
  1129.     // GetNext... continue using same X or Y
  1130.     // (These just call same functions in CEditTableElement)
  1131.     CEditTableCellElement* GetFirstCellInRow(int32 Y, XP_Bool bSpan = FALSE);
  1132.     CEditTableCellElement* GetFirstCellInColumn(int32 X, XP_Bool bSpan = FALSE);
  1133.     CEditTableCellElement* GetNextCellInRow();
  1134.     CEditTableCellElement* GetNextCellInColumn();
  1135.  
  1136.     // Test if cell contains only 1 container with 
  1137.     //  just the empty text field every new cell has
  1138.     XP_Bool IsEmpty();
  1139.  
  1140.     // Move contents of supplied cell into this cell
  1141.     void MergeCells(CEditTableCellElement* pCell);
  1142.  
  1143.     // Delete all contents, leaving just the minimum empty text element
  1144.     void DeleteContents();
  1145.  
  1146.     // Get all text from a cell. If bJoinParagrphs is FALSE,
  1147.     //  appropriate CR/LF is added between containers,
  1148.     //  else they are appended without CR/LF so cell contents
  1149.     //  can be pasted into Excell spreadsheet
  1150.     char * GetText(XP_Bool bJoinParagraphs = FALSE);
  1151.  
  1152.     // Returns sum of widths of all cells in first row in table
  1153.     int32 GetParentWidth();
  1154.     // Sum of heights of all cells in first column of table
  1155.     int32 GetParentHeight();
  1156.  
  1157.     int32 GetX() { return m_X; }
  1158.     int32 GetY() { return m_Y; }
  1159.     intn  GetRow() { return m_iRow; }
  1160.     int32 GetWidth() { return m_iWidthPixels; }
  1161.     int32 GetHeight() { return m_iHeightPixels; }
  1162.     int32 GetWidthOrPercent() { return m_iWidth; }
  1163.     int32 GetHeightOrPercent() { return m_iHeight; }
  1164.     int32 GetColSpan() { return m_iColSpan; }
  1165.     int32 GetRowSpan() { return m_iRowSpan; }
  1166.     XP_Bool GetWidthPercent() { return m_bWidthPercent; }
  1167.     XP_Bool GetHeightPercent() { return m_bHeightPercent; }
  1168.  
  1169.     // These will do appropriate action using SetData
  1170.     void IncreaseColSpan(int32 iIncrease);
  1171.     void IncreaseRowSpan(int32 iIncrease);
  1172.     void DecreaseColSpan(int32 iDecrease);
  1173.     void DecreaseRowSpan(int32 iDecrease);
  1174.  
  1175.     // Insert as last child of supplied parent 
  1176.     //   but first save current parent and next pointers
  1177.     void SwitchLinkage(CEditTableRowElement *pParentRow);
  1178.     // This switches parent and next pointers
  1179.     //   to those saved during SwitchLinkage
  1180.     void RestoreLinkage();
  1181.  
  1182. private:
  1183.     ED_Color m_backgroundColor;
  1184.     char* m_pBackgroundImage;
  1185.  
  1186.     // Cache this for efficiency
  1187.     XP_Bool m_bWidthPercent;       
  1188.     XP_Bool m_bHeightPercent;
  1189.     int32   m_iColSpan;
  1190.     int32   m_iRowSpan;
  1191.  
  1192.     // These are set only by FixupTableData(),
  1193.     //FIGURING OUT INDEXES IS TOO COMPLICATED!
  1194.     //  USE REAL LOCATIONS INSTEAD
  1195.     int32 m_X;
  1196.     int32 m_Y;
  1197.     intn m_iRow;    // Current logical and actual row index
  1198.  
  1199.     //Actual width, as determined from layout
  1200.     //Set by CEditBuffer::FixupTableData() after a table is layed out
  1201.     // We need this because tag data is not recorded
  1202.     // if m_bWidthDefined is FALSE, but we want to be able
  1203.     // to have the actual width available as default when
  1204.     // user edits the table or cell data
  1205.     int32   m_iWidthPixels;       
  1206.     int32   m_iHeightPixels;       
  1207.  
  1208.     // This is actual width or height in pixels, or Percent if b[Width|Height]Percent = TRUE;
  1209.     int32   m_iWidth;       
  1210.     int32   m_iHeight;       
  1211.  
  1212.     // This is used to temporarily switch cell to 
  1213.     //  a table created for copying contents
  1214.     // These are used by SwitchLinkage() and RestoreLinkage()
  1215.     CEditElement *m_pSaveParent;
  1216.     CEditElement *m_pSaveNext;
  1217.  
  1218. public:
  1219.  
  1220.     intn m_iBackgroundSaveIndex;
  1221. };
  1222.  
  1223. class CEditLayerElement: public CEditElement {
  1224. public:
  1225.     CEditLayerElement();
  1226.     CEditLayerElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  1227.     CEditLayerElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1228.  
  1229.     virtual XP_Bool IsLayer() { return TRUE; }
  1230.     static CEditLayerElement* Cast(CEditElement* pElement) {
  1231.         return pElement && pElement->IsLayer() ? (CEditLayerElement*) pElement : 0; }
  1232.     virtual EEditElementType GetElementType() { return eLayerElement; }
  1233.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild){
  1234.             return pChild.IsContainer();
  1235.         }
  1236.     virtual void FinishedLoad( CEditBuffer* pBuffer );
  1237.  
  1238.     void SetData( EDT_LayerData *pData );
  1239.     EDT_LayerData* GetData( );
  1240.     static EDT_LayerData* ParseParams( PA_Tag *pTag, int16 csid );
  1241.     static EDT_LayerData* NewData();
  1242.     static void FreeData( EDT_LayerData *pData );
  1243.  
  1244.     // Temporary methods. Remove when we can display layers.
  1245.     virtual void PrintOpen( CPrintState *pPrintState );
  1246.     virtual void PrintEnd( CPrintState *pPrintState );
  1247.  
  1248.  
  1249. private:
  1250. };
  1251.  
  1252. class CEditDivisionElement: public CEditElement {
  1253. public:
  1254.     CEditDivisionElement();
  1255.     CEditDivisionElement(CEditElement *pParent, PA_Tag *pTag, int16 csid);
  1256.     CEditDivisionElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1257.  
  1258.     virtual XP_Bool IsDivision();
  1259.     static CEditDivisionElement* Cast(CEditElement* pElement);
  1260.     virtual EEditElementType GetElementType();
  1261.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild);
  1262.  
  1263.     ED_Alignment GetAlignment();
  1264.     void ClearAlignment();
  1265.     XP_Bool HasData();
  1266.  
  1267.     void SetData( EDT_DivisionData *pData );
  1268.     EDT_DivisionData* GetData( );
  1269.     static EDT_DivisionData* ParseParams( PA_Tag *pTag, int16 csid );
  1270.     static EDT_DivisionData* NewData();
  1271.     static void FreeData( EDT_DivisionData *pData );
  1272.  
  1273.     virtual void PrintOpen( CPrintState *pPrintState );
  1274.     virtual void PrintEnd( CPrintState *pPrintState );
  1275.  
  1276. private:
  1277. };
  1278.  
  1279. //
  1280. // CEditRootDocElement - Top most element in the tree, tag HTML
  1281. //
  1282. class CEditRootDocElement: public CEditSubDocElement {
  1283. private:
  1284.     CEditBuffer* m_pBuffer;
  1285. public:
  1286.     CEditRootDocElement( CEditBuffer* pBuffer ):
  1287.             CEditSubDocElement(0, P_MAX), m_pBuffer( pBuffer ){}
  1288.     virtual XP_Bool Reduce( CEditBuffer * /*pBuffer */ ){ return FALSE; }
  1289.     virtual XP_Bool ShouldStreamSelf( CEditSelection& /*local*/, CEditSelection& /*selection*/ ) { return FALSE; }
  1290.  
  1291.     virtual void FinishedLoad( CEditBuffer *pBuffer );
  1292.  
  1293.     virtual void PrintOpen( CPrintState *pPrintState );
  1294.     virtual void PrintEnd( CPrintState *pPrintState );
  1295.  
  1296.     virtual XP_Bool IsRoot() { return TRUE; }
  1297.     static CEditRootDocElement* Cast(CEditElement* pElement) {
  1298.         return pElement && pElement->IsRoot() ? (CEditRootDocElement*) pElement : 0; }
  1299.     CEditBuffer* GetBuffer(){ return m_pBuffer; }
  1300. #ifdef DEBUG
  1301.     virtual void ValidateTree();
  1302. #endif
  1303. };
  1304.  
  1305. class CEditLeafElement: public CEditElement {
  1306. private:
  1307.     ElementOffset m_iSize;        // fake size.
  1308. public:
  1309.     // pass through constructors.
  1310.     CEditLeafElement(CEditElement *pParent, int tagType):
  1311.             CEditElement(pParent,tagType),m_iSize(1){}
  1312.  
  1313.     CEditLeafElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer):
  1314.             CEditElement(pStreamIn,pBuffer),m_iSize(1){}
  1315.  
  1316.     //
  1317.     // CEditElement Stuff
  1318.     //
  1319.     virtual XP_Bool IsLeaf() { return TRUE; }
  1320.     static CEditLeafElement* Cast(CEditElement* pElement) {
  1321.         return pElement && pElement->IsLeaf() ? (CEditLeafElement*) pElement : 0; }
  1322.     virtual PA_Tag* TagOpen( int iEditOffset );
  1323.  
  1324.     virtual void GetAll(CEditSelection& selection);
  1325.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild );
  1326.     virtual ElementIndex GetPersistentCount();
  1327.     virtual void StreamToPositionalText( IStreamOut *pOut, XP_Bool bEnd );
  1328.  
  1329.     virtual XP_Bool IsContainerContainer();
  1330.     virtual XP_Bool IsFirstInContainer();
  1331.  
  1332.     //
  1333.     // Stuff created at this level (Leaf)
  1334.     //
  1335.     virtual void SetLayoutElement( intn iEditOffset, intn lo_type,
  1336.                 LO_Element* pLoElement )=0;
  1337.     virtual void ResetLayoutElement( intn iEditOffset,
  1338.                 LO_Element* pLoElement )=0;
  1339.     virtual LO_Element* GetLayoutElement()=0;
  1340.  
  1341.     virtual XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool bEditStickyAfter,
  1342.                 LO_Element*& pRetElement,
  1343.                 int& pLayoutOffset )=0;       // if appropriate
  1344.     virtual ElementOffset GetLen(){ return m_iSize; }
  1345.     virtual void DeleteChar( MWContext * /*pContext*/, int /*iOffset*/ ){ m_iSize = 0; }
  1346.     virtual CEditElement* Divide(int iOffset);
  1347.     virtual CEditTextElement* CopyEmptyText(CEditElement *pParent = 0);
  1348.  
  1349.     // HREF management...
  1350.     virtual void SetHREF( ED_LinkId ){}
  1351.     virtual ED_LinkId GetHREF(){ return ED_LINK_ID_NONE; }
  1352.  
  1353.     //
  1354.     // Leaf manipulation functions..
  1355.     //
  1356.     XP_Bool NextPosition(ElementOffset iOffset, CEditLeafElement*& pNew, ElementOffset& iNewOffset );
  1357.     XP_Bool PrevPosition(ElementOffset iOffset, CEditLeafElement*& pNew, ElementOffset& iNewOffset );
  1358.  
  1359.     virtual CPersistentEditInsertPoint GetPersistentInsertPoint(ElementOffset offset);
  1360.  
  1361.     // True if this is a bucket for totally unknown html
  1362.     virtual XP_Bool IsUnknownHTML();
  1363.     // True if this element is an HTML comment
  1364.     virtual XP_Bool IsComment();
  1365.     // True if this element is an HTML comment that matches a given prefix.
  1366.     // IsComment("FOO") will match "<!-- FOOBAR -->"
  1367.     virtual XP_Bool IsComment(char* pPrefix);
  1368.  
  1369.     XP_Bool IsMisspelled();
  1370.  
  1371. #ifdef DEBUG
  1372.     virtual void ValidateTree();
  1373. #endif
  1374. protected:
  1375.     void DisconnectLayoutElements(LO_Element* pElement);
  1376.     void SetLayoutElementHelper( intn desiredType, LO_Element** pElementHolder,
  1377.           intn iEditOffset, intn lo_type,
  1378.           LO_Element* pLoElement);
  1379.     void ResetLayoutElementHelper( LO_Element** pElementHolder, intn iEditOffset,
  1380.             LO_Element* pLoElement );
  1381. };
  1382.  
  1383. class CEditContainerElement: public CEditElement {
  1384. private:
  1385.     ED_Alignment m_align;
  1386.     ED_Alignment m_defaultAlign;
  1387.     XP_Bool m_hackPreformat;
  1388. public:
  1389.     XP_Bool m_bHasEndTag; // Only important for parsing.
  1390.  
  1391.     static CEditContainerElement* NewDefaultContainer( CEditElement *pParent,
  1392.             ED_Alignment align );
  1393.     CEditContainerElement(CEditElement *pParent, PA_Tag *pTag, int16 csid,
  1394.             ED_Alignment eAlign);
  1395.     CEditContainerElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1396.     virtual void StreamInChildren(IStreamIn* pIn, CEditBuffer* pBuffer);
  1397.  
  1398.     virtual void StreamOut( IStreamOut *pOut);
  1399.     virtual XP_Bool ShouldStreamSelf( CEditSelection& /*local*/, CEditSelection& /*selection*/ ) { return TRUE; }
  1400.     virtual XP_Bool IsContainer() { return TRUE; }
  1401.     static CEditContainerElement* Cast(CEditElement* pElement) {
  1402.         return pElement && pElement->IsContainer() ? (CEditContainerElement*) pElement : 0; }
  1403.     virtual XP_Bool IsContainerContainer() { return FALSE; }
  1404.  
  1405.     virtual ElementIndex GetPersistentCount();
  1406.     virtual void FinishedLoad( CEditBuffer *pBuffer );
  1407.     virtual void AdjustContainers( CEditBuffer *pBuffer );
  1408.  
  1409.     virtual PA_Tag* TagOpen( int iEditOffset );
  1410.     virtual PA_Tag* TagEnd( );
  1411.     virtual EEditElementType GetElementType();
  1412.     virtual void PrintOpen( CPrintState *pPrintState );
  1413.     virtual void PrintEnd( CPrintState *pPrintState );
  1414.  
  1415.     virtual CEditElement* Clone( CEditElement *pParent = 0);
  1416.     virtual void StreamToPositionalText( IStreamOut *pOut, XP_Bool bEnd );
  1417.  
  1418.     static EDT_ContainerData* NewData();
  1419.     static void FreeData( EDT_ContainerData *pData );
  1420.  
  1421.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild) {return pChild.IsLeaf();}
  1422.  
  1423.     //
  1424.     // Implementation
  1425.     //
  1426.     void SetData( EDT_ContainerData *pData );
  1427.     EDT_ContainerData* GetData( );
  1428.     EDT_ContainerData* ParseParams( PA_Tag *pTag, int16 csid );
  1429.  
  1430.     void SetAlignment( ED_Alignment eAlign );
  1431.     ED_Alignment GetAlignment( ){ return m_align; }
  1432.     void CopyAttributes( CEditContainerElement *pContainer );
  1433.     XP_Bool IsEmpty();
  1434.  
  1435.     XP_Bool ShouldSkipTags();
  1436.     XP_Bool IsImplicitBreak();
  1437.     // 0..2, where 0 = not in pseudo paragraph.
  1438.     // 1 = first container of pseudo paragraph.
  1439.     // 2 = second container of pseudo paragraph.
  1440.     int16 GetPseudoParagraphState(); 
  1441.     XP_Bool ForcesDoubleSpacedNextLine();
  1442.  
  1443.     //cmanske: Get single string with all of container's text (no embeded CR/LF)
  1444.     // Caller must XP_FREE the result
  1445.     char *GetText();
  1446.  
  1447. #ifdef DEBUG
  1448.     virtual void ValidateTree();
  1449. #endif
  1450.  
  1451.     XP_Bool IsPlainFirstContainer();
  1452.     XP_Bool IsFirstContainer();
  1453.     XP_Bool SupportsAlign();
  1454.     void AlignIfEmpty( ED_Alignment eAlign );
  1455.     XP_Bool HasExtraData();
  1456. };
  1457.  
  1458. class CEditListElement: public CEditElement {
  1459. private:
  1460.     char *m_pBaseURL; /* If an ED_LIST_TYPE_CITE, this is the URL from the enclosing <BASE> tag. */
  1461.  
  1462. public:
  1463.     CEditListElement( CEditElement *pParent, PA_Tag *pTag, int16 csid );
  1464.     CEditListElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1465.     virtual ~CEditListElement();
  1466.  
  1467.     XP_Bool IsList(){ return TRUE; }
  1468.     static CEditListElement* Cast(CEditElement* pElement) {
  1469.         return pElement && pElement->IsList() ? (CEditListElement*) pElement : 0; }
  1470.  
  1471.     virtual PA_Tag* TagOpen( int iEditOffset );
  1472.     virtual CEditElement* Clone( CEditElement *pParent = 0);
  1473.  
  1474.     static EDT_ListData* NewData();
  1475.     static void FreeData( EDT_ListData *pData );
  1476.  
  1477.     // Streaming
  1478.     virtual EEditElementType GetElementType();
  1479.  
  1480.     //
  1481.     // Implementation
  1482.     //
  1483.     void SetData( EDT_ListData *pData );
  1484.     EDT_ListData* GetData( );
  1485.     static EDT_ListData* ParseParams( PA_Tag *pTag, int16 csid );
  1486.  
  1487.     void CopyData(CEditListElement* pOther);
  1488.  
  1489.     XP_Bool IsMailQuote();
  1490. #ifdef DEBUG
  1491.     virtual void ValidateTree();
  1492. #endif
  1493.  
  1494. };
  1495.  
  1496. //
  1497. // CEditTextElement
  1498. //
  1499.  
  1500. class CEditTextElement: public CEditLeafElement {
  1501. public:
  1502.     char* m_pText;                          // pointer to actual string.
  1503.     int m_textSize;                         // number of bytes allocated
  1504.     LO_Element* m_pFirstLayoutElement;
  1505.     LO_TextBlock* m_pTextBlock;
  1506.     ED_TextFormat m_tf;
  1507.     intn m_iFontSize;
  1508.     ED_Color m_color;
  1509.     ED_LinkId m_href;
  1510.     char* m_pFace;
  1511.     int16  m_iWeight;                 /* font weight range = 100-900, 400=Normal, 700=Bold*/
  1512.     int16  m_iPointSize;              /* not sure what default is! Use 0 to mean "default" */
  1513.     char* m_pScriptExtra;   // <SCRIPT> tag parameters
  1514.  
  1515. public:
  1516.     CEditTextElement(CEditElement *pParent, char *pText);
  1517.     CEditTextElement(IStreamIn *pStreamIn, CEditBuffer* pBuffer);
  1518.     virtual ~CEditTextElement();
  1519.  
  1520.     virtual XP_Bool IsText() { return TRUE; }
  1521.     static CEditTextElement* Cast(CEditElement* pElement) {
  1522.         return pElement && pElement->IsText() ? (CEditTextElement*) pElement : 0; }
  1523.  
  1524.     // accessor functions
  1525.     char* GetText(){ return m_pText; }
  1526.     char* GetTextWithConvertedSpaces();
  1527.     // If bConvertSpaces is FALSE, then csid is not used.
  1528.     void SetText(char* pText, XP_Bool bConvertSpaces=FALSE, int16 csid=0 );
  1529.     int GetSize(){ return m_textSize; }
  1530.     ElementOffset GetLen(){ return m_pText ? XP_STRLEN( m_pText ) : 0 ; }
  1531.     LO_Element* GetLayoutElement();
  1532.     virtual void SetLayoutElement( intn iEditOffset, intn lo_type,
  1533.                 LO_Element* pLoElement );
  1534.     virtual void ResetLayoutElement( intn iEditOffset,
  1535.                 LO_Element* pLoElement );
  1536.  
  1537.     void SetColor( ED_Color iColor );
  1538.     ED_Color GetColor(){ return m_color; }
  1539.     void SetFontSize( int iSize );
  1540.     int GetFontSize();
  1541.     void SetFontFace(char* face);
  1542.     char* GetFontFace();
  1543.     void SetFontWeight(int16 weight);
  1544.     int16 GetFontWeight();
  1545.     void SetFontPointSize(int16 pointSize);
  1546.     int16 GetFontPointSize();
  1547.     void SetScriptExtra(char* );
  1548.     char* GetScriptExtra();
  1549.     void SetHREF( ED_LinkId );
  1550.     ED_LinkId GetHREF(){ return m_href; }
  1551.     void ClearFormatting();
  1552.  
  1553.     void SetData( EDT_CharacterData *pData );
  1554.     EDT_CharacterData *GetData();
  1555.     void MaskData( EDT_CharacterData*& ppData );
  1556.  
  1557.     //
  1558.     // utility functions
  1559.     //
  1560.     XP_Bool InsertChar( int iOffset, int newChar );
  1561.     // returns number of bytes inserted.
  1562.     int32 InsertChars( int iOffset, char* pNewChars );
  1563.     XP_Bool GetLOTextAndOffset( ElementOffset iEditOffset, XP_Bool bEditStickyAfter, LO_TextStruct*& pRetText,
  1564.         int& pLayoutOffset );
  1565.  
  1566.     // for leaf implementation.
  1567.     void DeleteChar( MWContext *pContext, int iOffset );
  1568.     XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool bEditStickyAfter,
  1569.                 LO_Element*& pRetText,
  1570.                 int& pLayoutOffset );
  1571.  
  1572.     LO_TextStruct* GetLOText( int iEditOffset );
  1573.     LO_TextBlock* GetTextBlock();
  1574.     
  1575.     virtual XP_Bool CanReflow();
  1576.  
  1577.     virtual PA_Tag* TagOpen( int iEditOffset );
  1578.  
  1579.     // output funcitons
  1580.     virtual void PrintOpen( CPrintState *ps );
  1581.     virtual void PrintWithEscapes( CPrintState *ps, XP_Bool bTrimTrailingSpaces );
  1582.     virtual void PrintLiteral( CPrintState *ps );
  1583.     virtual void StreamOut( IStreamOut *pOut );
  1584.     // Why is "selection" param commented out?
  1585.     virtual void PartialStreamOut( IStreamOut *pOut, CEditSelection& /*selection*/ );
  1586.     virtual EEditElementType GetElementType();
  1587.     virtual XP_Bool Reduce( CEditBuffer *pBuffer );
  1588.     virtual void StreamToPositionalText( IStreamOut *pOut, XP_Bool bEnd );
  1589.  
  1590.     CEditElement* SplitText( int iOffset );
  1591.     void DeleteText();
  1592.     XP_Bool IsOffsetEnd( int iOffset ){
  1593.         ElementOffset iLen = GetLen();
  1594.         return ( iOffset == iLen
  1595.                   || ( iOffset == iLen-1
  1596.                         && m_pText[iLen-1] == ' ')
  1597.                 );
  1598.     }
  1599.     CEditTextElement* CopyEmptyText( CEditElement *pParent = 0);
  1600.     void FormatOpenTags(PA_Tag*& pStartList, PA_Tag*& pEndList);
  1601.     void FormatTransitionTags(CEditTextElement *pNext,
  1602.             PA_Tag*& pStart, PA_Tag*& pEndList);
  1603.     void FormatCloseTags(PA_Tag*& pStartList, PA_Tag*& pEndList);
  1604.     char* DebugFormat();
  1605.  
  1606.     void PrintTagOpen( CPrintState *pPrintState, TagType t, ED_TextFormat tf, char* pExtra=0 );
  1607.     void PrintFormatDifference( CPrintState *ps, ED_TextFormat bitsDifferent );
  1608.     void PrintFormat( CPrintState *ps, CEditTextElement *pFirst, ED_TextFormat mask );
  1609.     void PrintTagClose( CPrintState *ps, TagType t );
  1610.     void PrintPopFormat( CPrintState *ps, int iStackTop );
  1611.     ED_TextFormat PrintFormatClose( CPrintState *ps );
  1612.  
  1613.     XP_Bool SameAttributes(CEditTextElement *pCompare);
  1614.     void ComputeDifference(CEditTextElement *pFirst,
  1615.         ED_TextFormat mask, ED_TextFormat& bitsCommon, ED_TextFormat& bitsDifferent);
  1616.  
  1617. #ifdef DEBUG
  1618.     virtual void ValidateTree();
  1619. #endif
  1620.  
  1621. private:
  1622.     void PrintRange(CPrintState *ps, int32 start, int32 end);
  1623.     void PrintOpen2(CPrintState* ps, XP_Bool bTrimTrailingSpaces);
  1624. };
  1625.  
  1626. //-----------------------------------------------------------------------------
  1627. //  CEditImageElement
  1628. //-----------------------------------------------------------------------------
  1629.  
  1630. class CEditImageElement: public CEditLeafElement {
  1631.     LO_ImageStruct *m_pLoImage;
  1632.     ED_Alignment m_align;
  1633.     char *m_pParams;            // partial parameter string
  1634.  
  1635.     //EDT_ImageData *pData;
  1636.     int32 m_iHeight;
  1637.     int32 m_iWidth;
  1638.     ED_LinkId m_href;
  1639.     XP_Bool m_bSizeWasGiven;
  1640.     XP_Bool m_bSizeIsBogus;
  1641.     XP_Bool m_bWidthPercent;
  1642.     XP_Bool m_bHeightPercent;
  1643. public:
  1644.     intn m_iSaveIndex;
  1645.     intn m_iSaveLowIndex;
  1646.  
  1647. public:
  1648.     // pass through constructors.
  1649.     CEditImageElement(CEditElement *pParent, PA_Tag* pTag = 0, int16 csid = 0,
  1650.             ED_LinkId href = ED_LINK_ID_NONE );
  1651.     CEditImageElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1652.     virtual ~CEditImageElement();
  1653.  
  1654.     LO_Element* GetLayoutElement();
  1655.     virtual void SetLayoutElement( intn iEditOffset, intn lo_type,
  1656.                 LO_Element* pLoElement );
  1657.     virtual void ResetLayoutElement( intn iEditOffset,
  1658.                 LO_Element* pLoElement );
  1659.  
  1660.     void StreamOut( IStreamOut *pOut );
  1661.     virtual EEditElementType GetElementType();
  1662.  
  1663.  
  1664.     //
  1665.     // CEditElement implementation
  1666.     //
  1667.     PA_Tag* TagOpen( int iEditOffset );
  1668.     void PrintOpen( CPrintState *pPrintState );
  1669.  
  1670.     //
  1671.     // CEditLeafElement Implementation
  1672.     //
  1673.     XP_Bool IsImage() { return TRUE; }
  1674.     static CEditImageElement* Cast(CEditElement* pElement) {
  1675.         return pElement && pElement->IsImage() ? (CEditImageElement*) pElement : 0; }
  1676.     void FinishedLoad( CEditBuffer *pBuffer );
  1677.     LO_ImageStruct* GetLayoutImage(){ return m_pLoImage; }
  1678.  
  1679.     XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool /*bEditStickyAfter*/ ,
  1680.                 LO_Element*& pRetElement,
  1681.                 int& pLayoutOffset );
  1682.  
  1683.     int32 GetDefaultBorder();
  1684.     void SetHREF( ED_LinkId );
  1685.     ED_LinkId GetHREF(){ return m_href; }
  1686.  
  1687.     //
  1688.     // Implementation
  1689.     //
  1690.     void SetImageData( EDT_ImageData *pData );
  1691.     EDT_ImageData* GetImageData( );
  1692.     EDT_ImageData* ParseParams( PA_Tag *pTag, int16 csid );
  1693.     char* FormatParams(EDT_ImageData* pData, XP_Bool bForPrinting);
  1694.  
  1695.     XP_Bool SizeIsKnown();
  1696.  
  1697.     //CLM: Since HREF is a "character" attribute,
  1698.     //  we look at images for this as well
  1699.     void MaskData( EDT_CharacterData*& pData );
  1700.     EDT_CharacterData* GetCharacterData();
  1701. };
  1702.  
  1703.  
  1704. //-----------------------------------------------------------------------------
  1705. //  CEditHRuleElement
  1706. //-----------------------------------------------------------------------------
  1707.  
  1708. class CEditHorizRuleElement: public CEditLeafElement {
  1709.     LO_HorizRuleStruct *m_pLoHorizRule;
  1710. public:
  1711.     // pass through constructors.
  1712.     CEditHorizRuleElement(CEditElement *pParent, PA_Tag* pTag = 0, int16 csid = 0 );
  1713.     CEditHorizRuleElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1714.     virtual ~CEditHorizRuleElement();
  1715.  
  1716.     void StreamOut( IStreamOut *pOut);
  1717.     virtual EEditElementType GetElementType();
  1718.  
  1719.     //
  1720.     // CEditLeafElement Implementation
  1721.     //
  1722.     virtual XP_Bool CausesBreakBefore() { return TRUE;}
  1723.     virtual XP_Bool CausesBreakAfter() { return TRUE;}
  1724.     virtual XP_Bool AllowBothSidesOfGap() { return TRUE; }
  1725.  
  1726.     virtual void SetLayoutElement( intn iEditOffset, intn lo_type,
  1727.                 LO_Element* pLoElement );
  1728.     virtual void ResetLayoutElement( intn iEditOffset,
  1729.                 LO_Element* pLoElement );
  1730.  
  1731.     LO_Element* GetLayoutElement();
  1732.     LO_HorizRuleStruct* GetLayoutHorizRule(){ return m_pLoHorizRule; }
  1733.  
  1734.     XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool /* bEditStickyAfter */,
  1735.                 LO_Element*& pRetElement,
  1736.                 int& pLayoutOffset );
  1737.  
  1738.     static EDT_HorizRuleData* NewData();
  1739.     static void FreeData( EDT_HorizRuleData *pData );
  1740.  
  1741.     //
  1742.     // Implementation
  1743.     //
  1744.     void SetData( EDT_HorizRuleData *pData );
  1745.     EDT_HorizRuleData* GetData( );
  1746.     static EDT_HorizRuleData* ParseParams( PA_Tag *pTag, int16 csid );
  1747. };
  1748.  
  1749. //-----------------------------------------------------------------------------
  1750. //  CEditIconElement
  1751. //-----------------------------------------------------------------------------
  1752.  
  1753. #define EDT_ICON_NAMED_ANCHOR           0
  1754. #define EDT_ICON_FORM_ELEMENT           1
  1755. #define EDT_ICON_UNSUPPORTED_TAG        2
  1756. #define EDT_ICON_UNSUPPORTED_END_TAG    3
  1757. #define EDT_ICON_JAVA                   4
  1758. #define EDT_ICON_PLUGIN                 5
  1759. #define EDT_ICON_OBJECT                 6
  1760. #define EDT_ICON_LAYER                  7
  1761.  
  1762. class CEditIconElement: public CEditLeafElement {
  1763. private:
  1764.     // States for parsing LOCALDATA tag, see ParseLocalData().
  1765.     enum {BeforeMIME,InMIME,BeforeURL,InURL,AfterURL};
  1766.  
  1767.     // States for ReplaceParamValue().
  1768.     enum {OutsideValue,BeforeValue,InsideValue,InsideValueQuote};
  1769.  
  1770. protected:
  1771.     LO_ImageStruct *m_pLoIcon;
  1772.     TagType m_originalTagType;
  1773.     int32 m_iconTag;
  1774.     XP_Bool m_bEndTag;
  1775.     char *m_pSpoofData;
  1776.  
  1777. public:
  1778.     // pass through constructors.
  1779.     CEditIconElement(CEditElement *pParent, int32 iconTag, PA_Tag* pTag = 0, int16 csid = 0 );
  1780.     CEditIconElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1781.     ~CEditIconElement();
  1782.  
  1783.     void StreamOut( IStreamOut *pOut);
  1784.     virtual EEditElementType GetElementType(){ return eIconElement; }
  1785.  
  1786.     static ED_TagValidateResult ValidateTag(  char *Data, XP_Bool bNoBrackets );
  1787.  
  1788.     //
  1789.     // CEditLeafElement Implementation
  1790.     //
  1791.     XP_Bool IsIcon() { return TRUE; }
  1792.     static CEditIconElement* Cast(CEditElement* pElement) {
  1793.         return pElement && pElement->IsIcon() ? (CEditIconElement*) pElement : 0; }
  1794.  
  1795.     virtual void SetLayoutElement( intn iEditOffset, intn lo_type,
  1796.                 LO_Element* pLoElement );
  1797.     virtual void ResetLayoutElement( intn iEditOffset,
  1798.                 LO_Element* pLoElement );
  1799.  
  1800.     LO_Element* GetLayoutElement(){ return (LO_Element*)m_pLoIcon; }
  1801.     LO_ImageStruct* GetLayoutIcon(){ return m_pLoIcon; }
  1802.  
  1803.     XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool /* bEditStickyAfter */,
  1804.                 LO_Element*& pRetElement,
  1805.                 int& pLayoutOffset );
  1806.  
  1807.     PA_Tag* TagOpen( int iEditOffset );
  1808.     void PrintOpen( CPrintState *pPrintState );
  1809.     void PrintEnd( CPrintState *pPrintState );
  1810.  
  1811.     char* GetData();
  1812.  
  1813.     // Creates list of the mimeType/URL pairs from the LOCALDATA parameter.
  1814.     // List of Strings.
  1815.     // mimeTypes and URLs must be freed with FreeLocalDataLists() when done.
  1816.     // Returns the length of the lists.
  1817.     int ParseLocalData(char ***mimeTypes,char ***urls);
  1818.     static void FreeLocalDataLists(char **mimeTypes,char **urls,int count);
  1819.  
  1820.     // Replace all occurances of pOld in parameter values with pNew.
  1821.     // Used by LOCALDATA to update tags when saved/published/mailed.
  1822.     void ReplaceParamValues(char *pOld,char *pNew);
  1823.  
  1824.     // Call this to set both Width and Height at same time,
  1825.     //  to avoid relayout twice if Width and Height are set separetely
  1826.     // Set either value to 0 to ignore 
  1827.     //  Do we ever need to set to 0? (change to -1 to "ignore" if we need 0)
  1828.     void SetSize(XP_Bool bWidthPercent, int32 iWidth,
  1829.                  XP_Bool bHeightPercent, int32 iHeight);
  1830.  
  1831.     // Not currently implemented.
  1832.     void SetData( char* );
  1833.  
  1834.     void MorphTag( PA_Tag *pTag );
  1835.     void SetSpoofData( PA_Tag* pTag );
  1836.     void SetSpoofData( char* pData );
  1837.  
  1838.     virtual XP_Bool IsUnknownHTML();
  1839.     virtual XP_Bool IsComment();
  1840.     virtual XP_Bool IsComment(char* pPrefix);
  1841.  
  1842. public:
  1843.     // Used by CEditSaveObject.
  1844.     intn *m_piSaveIndices;
  1845. };
  1846.  
  1847. //-----------------------------------------------------------------------------
  1848. //  CEditTargetElement
  1849. //-----------------------------------------------------------------------------
  1850. class CEditTargetElement: public CEditIconElement {
  1851. private:
  1852. public:
  1853.     CEditTargetElement(CEditElement *pParent, PA_Tag* pTag = 0, int16 csid = 0 );
  1854.     CEditTargetElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1855.     void StreamOut( IStreamOut *pOut);
  1856.     EEditElementType GetElementType(){ return eTargetElement; }
  1857.  
  1858.     PA_Tag* TagOpen( int iEditOffset );
  1859.  
  1860.     char *GetName();
  1861.     void SetName( char* pName, int16 csid );
  1862.  
  1863.     void SetData( EDT_TargetData *pData );
  1864.     EDT_TargetData* GetData();
  1865.     EDT_TargetData* GetData(int16 csid);
  1866.     static EDT_TargetData* ParseParams( PA_Tag *pTag, int16 csid );
  1867.     static EDT_TargetData* NewTargetData();
  1868.     static void FreeTargetData(EDT_TargetData* pData);
  1869. };
  1870.  
  1871.  
  1872. //-----------------------------------------------------------------------------
  1873. //  CEditBreakElement
  1874. //-----------------------------------------------------------------------------
  1875.  
  1876. class CEditBreakElement: public CEditLeafElement {
  1877.     LO_LinefeedStruct *m_pLoLinefeed;
  1878. public:
  1879.     // pass through constructors.
  1880.     CEditBreakElement(CEditElement *pParent, PA_Tag* pTag = 0, int16 csid = 0 );
  1881.     CEditBreakElement(IStreamIn *pStreamIn, CEditBuffer *pBuffer);
  1882.     virtual ~CEditBreakElement();
  1883.  
  1884.     void StreamOut( IStreamOut *pOut );
  1885.     virtual EEditElementType GetElementType();
  1886.  
  1887.     void PrintOpen( CPrintState *ps );
  1888.  
  1889.     virtual XP_Bool IsBreak() { return TRUE; }
  1890.     virtual XP_Bool CausesBreakAfter() { return TRUE;}
  1891.     static CEditBreakElement* Cast(CEditElement* pElement) {
  1892.         return pElement && pElement->IsBreak() ? (CEditBreakElement*) pElement : 0; }
  1893.     //
  1894.     // CEditLeafElement Implementation
  1895.     //
  1896.     void SetLayoutElement( intn iEditOffset, intn lo_type,
  1897.                 LO_Element* pLoElement );
  1898.     virtual void ResetLayoutElement( intn iEditOffset,
  1899.                 LO_Element* pLoElement );
  1900.  
  1901.     LO_Element* GetLayoutElement();
  1902.  
  1903.     XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool bEditStickyAfter,
  1904.                 LO_Element*& pRetElement,
  1905.                 int& pLayoutOffset );
  1906. };
  1907.  
  1908. class CEditEndElement: public CEditHorizRuleElement {
  1909. public:
  1910.     CEditEndElement(CEditElement *pParent):
  1911.             CEditHorizRuleElement(pParent){
  1912.             EDT_HorizRuleData ourParams;
  1913.             ourParams.align = ED_ALIGN_LEFT;
  1914.             ourParams.size = DEFAULT_HR_THICKNESS;
  1915.             ourParams.bNoShade = FALSE;
  1916.             ourParams.iWidth = 64;
  1917.             ourParams.bWidthPercent = FALSE;
  1918.             ourParams.pExtra = 0;
  1919.             SetData(&ourParams);
  1920.             }
  1921.  
  1922.     virtual XP_Bool ShouldStreamSelf( CEditSelection& /* local */, CEditSelection& /* selection */ ) { return FALSE; }
  1923.     virtual void StreamOut( IStreamOut * /* pOut */) { XP_ASSERT(FALSE); }
  1924.  
  1925.     void SetLayoutElement( intn /* iEditOffset */ , intn lo_type,
  1926.                 LO_Element* pLoElement ){
  1927.         CEditHorizRuleElement::SetLayoutElement(-1, lo_type, pLoElement);
  1928.     }
  1929.  
  1930.     virtual EEditElementType GetElementType() { return eEndElement; }
  1931.     virtual void PrintOpen( CPrintState * /*pPrintState*/ ) {}
  1932.     virtual void PrintEnd( CPrintState * /*pPrintState*/ ) {}
  1933. };
  1934.  
  1935. class CEditEndContainerElement: public CEditContainerElement {
  1936. public:
  1937.     CEditEndContainerElement(CEditElement *pParent);
  1938.     virtual void StreamOut( IStreamOut * pOut);
  1939.     virtual XP_Bool ShouldStreamSelf( CEditSelection& local, CEditSelection& selection );
  1940.     virtual XP_Bool IsAcceptableChild(CEditElement& pChild);
  1941.     virtual void PrintOpen( CPrintState * pPrintState );
  1942.     virtual void PrintEnd( CPrintState * pPrintState );
  1943.     virtual XP_Bool IsEndContainer();
  1944.     virtual void AdjustContainers( CEditBuffer* pBuffer );
  1945. };
  1946.  
  1947. class CEditInternalAnchorElement: public CEditLeafElement {
  1948. public:
  1949.     CEditInternalAnchorElement(CEditElement *pParent);
  1950.     virtual ~CEditInternalAnchorElement();
  1951.     virtual XP_Bool Reduce( CEditBuffer* );
  1952.  
  1953.     virtual XP_Bool ShouldStreamSelf( CEditSelection& local, CEditSelection& selection);
  1954.     virtual void StreamOut( IStreamOut *pOut);
  1955.  
  1956.     virtual void SetLayoutElement( intn iEditOffset, intn lo_type,
  1957.                 LO_Element* pLoElement );
  1958.     virtual void ResetLayoutElement( intn iEditOffset,
  1959.                 LO_Element* pLoElement );
  1960.     virtual LO_Element* GetLayoutElement();
  1961.  
  1962.     virtual XP_Bool GetLOElementAndOffset( ElementOffset iEditOffset, XP_Bool bEditStickyAfter,
  1963.                 LO_Element*& pRetElement,
  1964.                 int& pLayoutOffset );
  1965.  
  1966.     virtual EEditElementType GetElementType();
  1967.     virtual void PrintOpen( CPrintState *pPrintState );
  1968.     virtual void PrintEnd( CPrintState *pPrintState );
  1969. };
  1970.  
  1971.  
  1972. //
  1973. // Macro to compute the next size of an TextBuffer.
  1974. //
  1975. #define GROW_TEXT(x)    ((x+0x20) & ~0x1f)   // grow buffer by 32 bytes
  1976.  
  1977. //-----------------------------------------------------------------------------
  1978. // CEditPosition
  1979. //-----------------------------------------------------------------------------
  1980.  
  1981. class CEditPosition {
  1982. private:
  1983.     CEditElement* m_pElement;
  1984.     int m_iOffset;
  1985. public:
  1986.     CEditPosition( CEditElement* pElement, int iOffset = 0 ):
  1987.             m_pElement(pElement), m_iOffset( iOffset ){}
  1988.  
  1989.     int Offset() { return m_iOffset; }
  1990.     CEditElement* Element() { return m_pElement; }
  1991.     IsPositioned(){ return m_pElement != 0; }
  1992. };
  1993.  
  1994.  
  1995. class CEditPositionComparable: public CEditPosition {
  1996. private:
  1997.     TXP_GrowableArray_int32 m_Array;
  1998.     void CalcPosition( TXP_GrowableArray_int32* pA, CEditPosition *pPos );
  1999. public:
  2000.     CEditPositionComparable( CEditElement* pElement, int iOffset = 0 ):
  2001.             CEditPosition( pElement, iOffset )
  2002.     {
  2003.         CalcPosition( &m_Array, this );
  2004.     }
  2005.  
  2006.     // return -1 if passed pos is before
  2007.     // return 0 if pos is the same
  2008.     // return 1 if pos is greater
  2009.     int Compare( CEditPosition *pPos );
  2010. };
  2011.  
  2012. //-----------------------------------------------------------------------------
  2013. // CEditBuffer (and others)..
  2014. //-----------------------------------------------------------------------------
  2015.  
  2016. class CParseState {
  2017. public:
  2018.     XP_Bool bLastWasSpace;
  2019.     XP_Bool m_bInTitle;
  2020. private:
  2021.     int m_iDocPart;
  2022. public:
  2023.     XP_Bool InBody();
  2024.     void StartBody();
  2025.     void EndBody();
  2026.  
  2027.     TagType m_inJavaScript; // 0 when not in any script, otherwise the tag of the kind of script
  2028.     int m_baseFontSize;
  2029.     TXP_PtrStack_ED_Alignment m_formatAlignStack;
  2030.     TXP_PtrStack_TagType m_formatTypeStack;
  2031.     TXP_PtrStack_CEditTextElement m_formatTextStack;
  2032.     CEditTextElement *m_pNextText;
  2033.     CStreamOutMemory *m_pJavaScript;
  2034.     CStreamOutMemory* m_pPostBody;
  2035.     CStreamOutMemory* GetStream(); // Gets either m_pJavaScript or m_postBody, depending upon m_iDocPart
  2036.  
  2037. public:
  2038.     void Reset();
  2039.     CParseState();
  2040.     ~CParseState();
  2041. private:
  2042.     void Free(CStreamOutMemory*& pStream);
  2043. };
  2044.  
  2045. class CPrintState {
  2046. public:
  2047.     int m_iLevel;
  2048.     int m_iCharPos;
  2049.     XP_Bool m_bTextLast;
  2050.     IStreamOut* m_pOut;
  2051.     TXP_PtrStack_ED_TextFormat m_formatStack;
  2052.     TXP_PtrStack_CEditTextElement m_elementStack;
  2053.     CEditBuffer *m_pBuffer;
  2054.     XP_Bool m_bEncodeSelectionAsComment;
  2055.     CEditSelection m_selection;
  2056. public:
  2057.     void Reset( IStreamOut *pStream, CEditBuffer *pBuffer );
  2058.     XP_Bool ShouldPrintSelectionComments(CEditLeafElement* pElement);
  2059.     XP_Bool ShouldPrintSelectionComment(CEditLeafElement* pElement, XP_Bool bEnd);
  2060.     void PrintSelectionComment(XP_Bool bEnd, XP_Bool bStickyAfter);
  2061. };
  2062.  
  2063.  
  2064. //
  2065. // This is a structure, not a class.  It cannot be instanciated with NEW and
  2066. //  should never be derived from.
  2067. //
  2068. class CEditLinkManager;
  2069.  
  2070. struct ED_Link {
  2071. private:
  2072.     // Should never create on of these with a constructor!  Must
  2073.     //  create it only through CEditLinkManager::Add
  2074.     ED_Link(){}
  2075. public:
  2076.     void AddRef(){ iRefCount++; }
  2077.  
  2078.     void Release() {} 
  2079.     // A bug, probably should call pLinkManager::Free(), not worth the work to fix 
  2080.     // it and make sure ref counting works all the time.  hardts
  2081.  
  2082.     EDT_HREFData* GetData();
  2083.     intn iRefCount;
  2084.     CEditLinkManager* pLinkManager;
  2085.     int linkOffset;
  2086.     char *hrefStr;
  2087.     char *pExtra;
  2088.     XP_Bool bAdjusted;
  2089. };
  2090.  
  2091.  
  2092. typedef TXP_GrowableArray_pChar ED_HREFList;
  2093. class CEditLinkManager {
  2094. private:
  2095.     TXP_GrowableArray_ED_Link m_links;
  2096.  
  2097. public:
  2098.     CEditLinkManager();
  2099.     ED_Link* MakeLink( char* pStr, char* pExtra, intn iRefCount = 1 );
  2100.     ED_LinkId Add( char *pHREF, char *pExtra );
  2101.     char* GetHREF( ED_LinkId id ){ return id->hrefStr; }
  2102.     int GetHREFLen( ED_LinkId id ){ return XP_STRLEN( id->hrefStr ); }
  2103.     EDT_HREFData* GetHREFData( ED_LinkId id){ return id->GetData(); }
  2104.     void Free( ED_LinkId id );
  2105.     void AdjustAllLinks( char *pOldURL, char* pNewURL, ED_HREFList *badLinks );
  2106.  
  2107.     // Wrapper for other AdjustLink function.
  2108.     void AdjustLink( ED_LinkId id, char *pOldURL, char* pNewURL, ED_HREFList *badLinks ) {
  2109.       if (id && id->hrefStr) AdjustLink(&id->hrefStr,pOldURL,pNewURL,badLinks);
  2110.     }
  2111.  
  2112.     // Used for adjusting links, images, etc.
  2113.     static void AdjustLink(char **pURL,char *pOldBase, char *pNewBase, ED_HREFList *badLinks);
  2114.  
  2115.     static void AddHREFUnique(ED_HREFList *badLinks,char *pURL);
  2116.  
  2117.     // Since we don't trust the reference counting, CEditSaveObject::FixupLinks() marks each link
  2118.     // as it adjusts it, so it doesn't adjust links twice.  HARDTS
  2119.     static void SetAdjusted(ED_LinkId id,XP_Bool bVal) { if (id) id->bAdjusted = bVal;}
  2120.     static XP_Bool GetAdjusted(ED_LinkId id) { if (id) return id->bAdjusted; else return TRUE;}
  2121. };
  2122.  
  2123. // Relayout Flags
  2124. #define RELAYOUT_NOCARET        1       // after relaying out, don't show the caret
  2125.  
  2126.  
  2127. // Commands
  2128.  
  2129. class CEditBuffer;
  2130.  
  2131. class CEditCommand {
  2132. public:
  2133.     CEditCommand(CEditBuffer*, intn id);
  2134.     virtual ~CEditCommand();
  2135.     virtual void Do();
  2136.     virtual void Undo();
  2137.     virtual void Redo();
  2138.     intn GetID();
  2139. #ifdef DEBUG
  2140.     virtual void Print(IStreamOut& stream);
  2141. #endif
  2142. protected:
  2143.     CEditBuffer* GetEditBuffer() { return m_editBuffer; };
  2144. private:
  2145.     CEditBuffer* m_editBuffer;
  2146.     intn m_id;
  2147. };
  2148.  
  2149. // CEditCommandGroup
  2150.  
  2151. class CEditCommandGroup : public CEditCommand {
  2152. public:
  2153.     CEditCommandGroup(CEditBuffer*, int id);
  2154.     virtual ~CEditCommandGroup();
  2155.     void AdoptAndDo(CEditCommand* pCommand);
  2156.     virtual void Undo();
  2157.     virtual void Redo();
  2158. #ifdef DEBUG
  2159.     virtual void Print(IStreamOut& stream);
  2160. #endif
  2161.     intn GetNumberOfCommands();
  2162. private:
  2163.     TXP_GrowableArray_CEditCommand m_commands;
  2164. };
  2165.  
  2166. /* Default */
  2167. #define EDT_CMD_LOG_MAXHISTORY 1
  2168.  
  2169. class CEditCommandLog;
  2170.  
  2171. class CGlobalHistoryGroup {
  2172. public:
  2173.     static CGlobalHistoryGroup* GetGlobalHistoryGroup();
  2174.     CGlobalHistoryGroup();
  2175.     ~CGlobalHistoryGroup();
  2176.     XP_Bool IsReload(CEditBuffer* pContext);
  2177.     void ReloadFinished(CEditBuffer* pContext);
  2178.     CEditCommandLog* CreateLog(CEditBuffer* pContext);
  2179.     CEditCommandLog* GetLog(CEditBuffer* pContext);
  2180.     void DeleteLog(CEditBuffer* pContext);
  2181.     void IgnoreNextDeleteOf(CEditBuffer* pContext);
  2182.  
  2183. private:
  2184.     CEditCommandLog* m_pHead; // First log
  2185.     static CGlobalHistoryGroup* g_pGlobalHistoryGroup;
  2186. };
  2187.  
  2188. //
  2189. // CEditDocState
  2190. //
  2191. class CEditDocState {
  2192. public:
  2193.   // Only created by CEditBuffer::RecordState().
  2194.   friend class CEditBuffer;
  2195.   virtual ~CEditDocState();
  2196.  
  2197. #ifdef DEBUG
  2198.     void Print(IStreamOut& stream);
  2199. #endif
  2200.  
  2201. private:
  2202.   CEditDocState();
  2203.  
  2204.   XP_HUGE_CHAR_PTR m_pBuffer;
  2205.   DocumentVersion m_version;
  2206. };
  2207.  
  2208.  
  2209. class CCommandState {
  2210. public:
  2211.     CCommandState();
  2212.     ~CCommandState();
  2213.     void SetID(intn commandID);
  2214.     intn GetID();
  2215.     void Record(CEditBuffer* pBufferToRecord);
  2216.     void Restore(CEditBuffer* pBufferToRestore);
  2217. #ifdef DEBUG
  2218.     void Print(IStreamOut& stream);
  2219. #endif
  2220.  
  2221. private:
  2222.     void Flush();
  2223.  
  2224.     intn m_commandID;
  2225.     CEditDocState *m_pState;
  2226. };
  2227.  
  2228. class CEditCommandLog {
  2229. public:
  2230.     void StartTyping(intn typing);
  2231.     void EndTyping();
  2232.     void AdoptAndDo(CEditCommand*);
  2233.     void Undo();
  2234.     void Redo();
  2235.     void Trim();    // Trims undo and redo command lists.
  2236.     XP_Bool InReload();
  2237.     void SetInReload(XP_Bool bInReload);
  2238.     DocumentVersion GetVersion();
  2239.     void SetVersion(DocumentVersion); // For CEditBuffer::RestoreState().
  2240.     DocumentVersion GetStoredVersion();
  2241.     void DocumentStored();
  2242.     XP_Bool IsDirty();
  2243.  
  2244.     intn GetCommandHistoryLimit();
  2245.     void SetCommandHistoryLimit(intn newLimit);
  2246.  
  2247.     intn GetNumberOfCommandsToUndo();
  2248.     intn GetNumberOfCommandsToRedo();
  2249.  
  2250.     // Returns kNullCommandID if out of range
  2251.     intn GetUndoCommand(intn index);
  2252.     intn GetRedoCommand(intn index);
  2253.  
  2254.     void BeginBatchChanges(intn batchID);
  2255.     void EndBatchChanges();
  2256.  
  2257. #ifdef DEBUG
  2258.     void Print(IStreamOut& stream);
  2259. #endif
  2260.  
  2261. #ifdef EDITOR_JAVA
  2262.     EditorPluginManager GetPlugins();
  2263. #endif
  2264.  
  2265.     // Temporary directory specific to the edit buffer.  In xpURL format.
  2266.     char *GetDocTempDir();
  2267.     char *CreateDocTempFilename(char *pPrefix,char *pExtension);
  2268.  
  2269. protected:
  2270.     // Use the global history to get the command log for a given context.
  2271.     CEditCommandLog();
  2272.     ~CEditCommandLog();
  2273.  
  2274. private:
  2275.     void FinishBatchCommands();
  2276.     void InternalAdoptAndDo(CEditCommand*);
  2277.     void InternalDo(intn id);
  2278.     void Trim(intn start, intn end);
  2279.     static char *GetAppTempDir();
  2280.  
  2281.     CEditBuffer* m_pBuffer;
  2282.     CCommandState* m_pUndo;
  2283.     CCommandState* m_pRedo;
  2284.     int32 m_iBatchLevel;
  2285.     int16 m_state;
  2286.  
  2287. #ifdef DEBUG
  2288.     friend class CEditCommandLogRecursionCheckEntry;
  2289.     XP_Bool m_bBusy;
  2290. #endif
  2291.  
  2292.     friend CGlobalHistoryGroup;
  2293.     CEditCommandLog* m_pNext;
  2294.     MWContext* m_pContext;
  2295.     XP_Bool m_bIgnoreDelete;
  2296.  
  2297.     DocumentVersion m_version;
  2298.     DocumentVersion m_storedVersion;
  2299.     DocumentVersion m_highestVersion;
  2300.  
  2301. #ifdef EDITOR_JAVA
  2302.     EditorPluginManager m_pPlugins;
  2303. #endif
  2304.  
  2305.  
  2306.     ///// All the temp directory variables are stored in CEditCommandLog
  2307.     ///// because they must persist when the CEditBuffer is deleted 
  2308.     ///// during undo/redo.    
  2309.     // The temp directory for this document.
  2310.     char *m_pDocTempDir; 
  2311.     // Used to create unique filenames in the temp directory.
  2312.     int m_iDocTempFilenameNonce;
  2313.     // used to create unique temp dir filenames.
  2314.     static int32 m_iDocTempDirNonce; 
  2315. };
  2316.  
  2317. // The commands
  2318.  
  2319. #define kNullCommandID 0
  2320. #define kTypingCommandID 1
  2321. #define kAddTextCommandID 2
  2322. #define kDeleteTextCommandID 3
  2323. #define kCutCommandID 4
  2324. #define kPasteTextCommandID 5
  2325. #define kPasteHTMLCommandID 6
  2326. #define kPasteHREFCommandID 7
  2327. #define kChangeAttributesCommandID 8
  2328. #define kIndentCommandID 9
  2329. #define kParagraphAlignCommandID 10
  2330. #define kMorphContainerCommandID 11
  2331. #define kInsertHorizRuleCommandID 12
  2332. #define kSetHorizRuleDataCommandID 13
  2333. #define kInsertImageCommandID 14
  2334. #define kSetImageDataCommandID 15
  2335. #define kInsertBreakCommandID 16
  2336. #define kChangePageDataCommandID 17
  2337. #define kSetMetaDataCommandID 18
  2338. #define kDeleteMetaDataCommandID 19
  2339. #define kInsertTargetCommandID 20
  2340. #define kSetTargetDataCommandID 21
  2341. #define kInsertUnknownTagCommandID 22
  2342. #define kSetUnknownTagDataCommandID 23
  2343. #define kGroupOfChangesCommandID 24
  2344. #define kSetListDataCommandID 25
  2345.  
  2346. #define kInsertTableCommandID 26
  2347. #define kDeleteTableCommandID 27
  2348. #define kSetTableDataCommandID 28
  2349.  
  2350. #define kInsertTableCaptionCommandID 29
  2351. #define kSetTableCaptionDataCommandID 30
  2352. #define kDeleteTableCaptionCommandID 31
  2353.  
  2354. #define kInsertTableRowCommandID 32
  2355. #define kSetTableRowDataCommandID 33
  2356. #define kDeleteTableRowCommandID 34
  2357.  
  2358. #define kInsertTableColumnCommandID 35
  2359. #define kSetTableCellDataCommandID 36
  2360. #define kDeleteTableColumnCommandID 37
  2361.  
  2362. #define kInsertTableCellCommandID 38
  2363. #define kDeleteTableCellCommandID 39
  2364.  
  2365. #define kInsertLayerCommandID 40
  2366. #define kDeleteLayerCommandID 41
  2367. #define kSetLayerDataCommandID 42
  2368.  
  2369. #define kSetSelectionCommandID 43
  2370.  
  2371. #define kPerformPluginCommandID 44
  2372.  
  2373. #define kCommandIDMax 44
  2374.  
  2375. // This class holds a chunk of html text.
  2376.  
  2377. class CEditText
  2378. {
  2379. public:
  2380.     CEditText();
  2381.     ~CEditText();
  2382.  
  2383.     void Clear();
  2384.  
  2385.     // The length is the number of chars
  2386.     char* GetChars();
  2387.     int32 Length();
  2388.     char** GetPChars();
  2389.     int32* GetPLength();
  2390. private:
  2391.     char* m_pChars;
  2392.     int32 m_iLength;
  2393.     ElementIndex m_iCount;
  2394. };
  2395.  
  2396. // Can save and restore a region of the document. Also saves and restores current
  2397. // selection
  2398.  
  2399. class CEditDataSaver {
  2400. public:
  2401.     CEditDataSaver(CEditBuffer* pBuffer);
  2402.     ~CEditDataSaver();
  2403.     void DoBegin(CPersistentEditSelection& original);
  2404.     void DoEnd(CPersistentEditSelection& modified);
  2405.     void Undo();
  2406.     void Redo();
  2407.  
  2408.     CPersistentEditSelection* GetOriginalDocumentSelection() { return &m_originalDocument; }
  2409. private:
  2410.     CEditBuffer* m_pEditBuffer;
  2411.     CPersistentEditSelection m_originalDocument;
  2412.     CPersistentEditSelection m_modifiedDocument;
  2413.     CPersistentEditSelection m_original;
  2414.     CPersistentEditSelection m_expandedOriginal;
  2415.     CPersistentEditSelection m_expandedModified;
  2416.     CEditText m_originalText;
  2417.     CEditText m_modifiedText;
  2418.     XP_Bool m_bModifiedTextHasBeenSaved;
  2419. #ifdef DEBUG
  2420.     int m_bDoState;
  2421. #endif
  2422. };
  2423.  
  2424. class CDeleteTableCommand
  2425.     : public CEditCommand
  2426. {
  2427. public:
  2428.     CDeleteTableCommand(CEditBuffer* buffer, intn id = kDeleteTableCommandID);
  2429.     virtual ~CDeleteTableCommand();
  2430.     virtual void Do();
  2431. //    virtual void Undo();
  2432. //    virtual void Redo();
  2433. private:
  2434.     CEditTableElement* m_pTable;
  2435.     CPersistentEditInsertPoint m_replacePoint;
  2436.     CPersistentEditSelection m_originalSelection;
  2437. };
  2438.  
  2439. class CInsertTableCaptionCommand
  2440.     : public CEditCommand
  2441. {
  2442. public:
  2443.     CInsertTableCaptionCommand(CEditBuffer* buffer, EDT_TableCaptionData *pData, intn id = kInsertTableCaptionCommandID);
  2444.     virtual ~CInsertTableCaptionCommand();
  2445.     virtual void Do();
  2446. //    virtual void Undo();
  2447. //    virtual void Redo();
  2448. private:
  2449.     CEditCaptionElement* m_pOldCaption;
  2450.     CPersistentEditSelection m_originalSelection;
  2451.     CPersistentEditSelection m_changedSelection;
  2452. };
  2453.  
  2454. class CDeleteTableCaptionCommand
  2455.     : public CEditCommand
  2456. {
  2457. public:
  2458.     CDeleteTableCaptionCommand(CEditBuffer* buffer, intn id = kDeleteTableCaptionCommandID);
  2459.     virtual ~CDeleteTableCaptionCommand();
  2460.     virtual void Do();
  2461. //    virtual void Undo();
  2462. //    virtual void Redo();
  2463. private:
  2464.     CEditCaptionElement* m_pOldCaption;
  2465.     CPersistentEditSelection m_originalSelection;
  2466.     CPersistentEditSelection m_changedSelection;
  2467. };
  2468. class CInsertTableRowCommand
  2469.     : public CEditCommand
  2470. {
  2471. public:
  2472.     CInsertTableRowCommand(CEditBuffer* buffer, EDT_TableRowData *pData, XP_Bool bAfterCurrentRow, intn number, intn id = kInsertTableRowCommandID);
  2473.     virtual ~CInsertTableRowCommand();
  2474.     virtual void Do();
  2475. //    virtual void Undo();
  2476. //    virtual void Redo();
  2477. private:
  2478.     intn m_row;
  2479.     intn m_number;
  2480.     intn m_new_row;
  2481.     CPersistentEditSelection m_originalSelection;
  2482.     CPersistentEditSelection m_changedSelection;
  2483. };
  2484.  
  2485. class CDeleteTableRowCommand
  2486.     : public CEditCommand
  2487. {
  2488. public:
  2489.     CDeleteTableRowCommand(CEditBuffer* buffer, intn rows, intn id = kDeleteTableRowCommandID);
  2490.     virtual ~CDeleteTableRowCommand();
  2491.     virtual void Do();
  2492. //    virtual void Undo();
  2493. //    virtual void Redo();
  2494. private:
  2495.     XP_Bool m_bDeletedWholeTable;
  2496.     intn m_row;
  2497.     intn m_rows;
  2498.     CEditTableElement m_table;    // Holds deleted rows
  2499.     CPersistentEditSelection m_originalSelection;
  2500.     CPersistentEditSelection m_changedSelection;
  2501. };
  2502.  
  2503. class CInsertTableColumnCommand
  2504.     : public CEditCommand
  2505. {
  2506. public:
  2507.     CInsertTableColumnCommand(CEditBuffer* buffer, EDT_TableCellData *pData, XP_Bool bAfterCurrentCell, intn number, intn id = kInsertTableColumnCommandID);
  2508.     virtual ~CInsertTableColumnCommand();
  2509.     virtual void Do();
  2510. //    virtual void Undo();
  2511. //    virtual void Redo();
  2512. private:
  2513.     intn m_number;
  2514.     //cmanske: Changed to retain actual column and new insert column
  2515.     // This is needed for proper insert given COLSPAN effects
  2516.     intn m_column;
  2517.     intn m_new_column;
  2518.     CPersistentEditSelection m_originalSelection;
  2519.     CPersistentEditSelection m_changedSelection;
  2520. };
  2521.  
  2522. class CDeleteTableColumnCommand
  2523.     : public CEditCommand
  2524. {
  2525. public:
  2526.     CDeleteTableColumnCommand(CEditBuffer* buffer, intn rows, intn id = kDeleteTableColumnCommandID);
  2527.     virtual ~CDeleteTableColumnCommand();
  2528.     virtual void Do();
  2529. //    virtual void Undo();
  2530. //    virtual void Redo();
  2531. private:
  2532.     XP_Bool m_bDeletedWholeTable;
  2533.     intn m_column;
  2534.     intn m_columns;
  2535.     CEditTableElement m_table;    // Holds deleted columns
  2536.     CPersistentEditSelection m_originalSelection;
  2537.     CPersistentEditSelection m_changedSelection;
  2538. };
  2539.  
  2540. class CInsertTableCellCommand
  2541.     : public CEditCommand
  2542. {
  2543. public:
  2544.     CInsertTableCellCommand(CEditBuffer* buffer, XP_Bool bAfterCurrentCell, intn number, intn id = kInsertTableCellCommandID);
  2545.     virtual ~CInsertTableCellCommand();
  2546.     virtual void Do();
  2547. //    virtual void Undo();
  2548. //    virtual void Redo();
  2549. private:
  2550.     intn m_column;
  2551.     intn m_new_column;
  2552.     intn m_number;
  2553.     CPersistentEditSelection m_originalSelection;
  2554.     CPersistentEditSelection m_changedSelection;
  2555. };
  2556.  
  2557. class CDeleteTableCellCommand
  2558.     : public CEditCommand
  2559. {
  2560. public:
  2561.     CDeleteTableCellCommand(CEditBuffer* buffer, intn rows, intn id = kDeleteTableCellCommandID);
  2562.     virtual ~CDeleteTableCellCommand();
  2563.     virtual void Do();
  2564. //    virtual void Undo();
  2565. //    virtual void Redo();
  2566. private:
  2567.     XP_Bool m_bDeletedWholeTable;
  2568.     intn m_column;
  2569.     intn m_columns;
  2570.     CEditTableRowElement m_tableRow;    // Holds deleted cells
  2571.     CPersistentEditSelection m_originalSelection;
  2572.     CPersistentEditSelection m_changedSelection;
  2573. };
  2574.  
  2575. class CSetListDataCommand
  2576.     : public CEditCommand
  2577. {
  2578. public:
  2579.     CSetListDataCommand(CEditBuffer*, EDT_ListData& listData, intn id = kSetListDataCommandID);
  2580.     virtual ~CSetListDataCommand();
  2581.     virtual void Do();
  2582.     virtual void Undo();
  2583.     virtual void Redo();
  2584.  
  2585. private:
  2586.     EDT_ListData m_newData;
  2587.     EDT_ListData* m_pOldData;
  2588. };
  2589.  
  2590. // CChangePageDataCommand - for commands that change the document's page data
  2591.  
  2592. class CChangePageDataCommand
  2593.     : public CEditCommand
  2594. {
  2595. public:
  2596.     CChangePageDataCommand(CEditBuffer*, intn id = kChangePageDataCommandID);
  2597.     virtual ~CChangePageDataCommand();
  2598.     virtual void Undo();
  2599.     virtual void Redo();
  2600.  
  2601. private:
  2602.     EDT_PageData* m_oldData;
  2603.     EDT_PageData* m_newData;
  2604. };
  2605.  
  2606. // CSetMetaDataCommand - for changes to the document's meta data
  2607.  
  2608. class CSetMetaDataCommand
  2609.     : public CEditCommand
  2610. {
  2611. public:
  2612.     // Note: Simply creating this command does the action -- this is so we don't have to explicitly copy the
  2613.     // meta data that's passed in.
  2614.     CSetMetaDataCommand(CEditBuffer*, EDT_MetaData *pMetaData, XP_Bool bDelete, intn id = kSetMetaDataCommandID);
  2615.     virtual ~CSetMetaDataCommand();
  2616.     virtual void Undo();
  2617.     virtual void Redo();
  2618.  
  2619. private:
  2620.     XP_Bool m_bNewItem;    // This command creates an item.
  2621.     XP_Bool m_bDelete;     // This command deletes an item.
  2622.     EDT_MetaData* m_pOldData;
  2623.     EDT_MetaData* m_pNewData;
  2624. };
  2625.  
  2626. class CSetTableDataCommand
  2627.     : public CEditCommand
  2628. {
  2629. public:
  2630.     // Note: Simply creating this command does the action -- this is so we don't have to explicitly copy the
  2631.     // data that's passed in.
  2632.     CSetTableDataCommand(CEditBuffer*, EDT_TableData *pMetaData, intn id = kSetTableDataCommandID);
  2633.     virtual ~CSetTableDataCommand();
  2634.     virtual void Undo();
  2635.     virtual void Redo();
  2636.  
  2637. private:
  2638.     EDT_TableData* m_pOldData;
  2639.     EDT_TableData* m_pNewData;
  2640. };
  2641.  
  2642. class CSetTableCaptionDataCommand
  2643.     : public CEditCommand
  2644. {
  2645. public:
  2646.     // Note: Simply creating this command does the action -- this is so we don't have to explicitly copy the
  2647.     // data that's passed in.
  2648.     CSetTableCaptionDataCommand(CEditBuffer*, EDT_TableCaptionData *pMetaData, intn id = kSetTableCaptionDataCommandID);
  2649.     virtual ~CSetTableCaptionDataCommand();
  2650.     virtual void Undo();
  2651.     virtual void Redo();
  2652.  
  2653. private:
  2654.     EDT_TableCaptionData* m_pOldData;
  2655.     EDT_TableCaptionData* m_pNewData;
  2656. };
  2657.  
  2658. class CSetTableRowDataCommand
  2659.     : public CEditCommand
  2660. {
  2661. public:
  2662.     // Note: Simply creating this command does the action -- this is so we don't have to explicitly copy the
  2663.     // data that's passed in.
  2664.     CSetTableRowDataCommand(CEditBuffer*, EDT_TableRowData *pMetaData, intn id = kSetTableRowDataCommandID);
  2665.     virtual ~CSetTableRowDataCommand();
  2666.     virtual void Undo();
  2667.     virtual void Redo();
  2668.  
  2669. private:
  2670.     EDT_TableRowData* m_pOldData;
  2671.     EDT_TableRowData* m_pNewData;
  2672. };
  2673.  
  2674. class CSetTableCellDataCommand
  2675.     : public CEditCommand
  2676. {
  2677. public:
  2678.     // Note: Simply creating this command does the action -- this is so we don't have to explicitly copy the
  2679.     // data that's passed in.
  2680.     CSetTableCellDataCommand(CEditBuffer*, EDT_TableCellData *pMetaData, intn id = kSetTableCellDataCommandID);
  2681.     virtual ~CSetTableCellDataCommand();
  2682.     virtual void Undo();
  2683.     virtual void Redo();
  2684.  
  2685. private:
  2686.     EDT_TableCellData* m_pOldData;
  2687.     EDT_TableCellData* m_pNewData;
  2688. };
  2689.  
  2690. class CSetSelectionCommand
  2691.     : public CEditCommand
  2692. {
  2693. public:
  2694.     CSetSelectionCommand(CEditBuffer*, CEditSelection& selection, intn id = kSetSelectionCommandID);
  2695.     virtual ~CSetSelectionCommand();
  2696.     virtual void Do();
  2697.     virtual void Undo();
  2698.     virtual void Redo();
  2699.  
  2700. private:
  2701.     CPersistentEditSelection m_OldSelection;
  2702.     CPersistentEditSelection m_NewSelection;
  2703. };
  2704.  
  2705. // Generic timer callback
  2706.  
  2707. extern "C" {
  2708. void CEditTimerCallback (void * closure);
  2709. }
  2710.  
  2711. class CEditTimer {
  2712. public:
  2713.     CEditTimer();
  2714.     virtual ~CEditTimer();
  2715. protected:
  2716.     void SetTimeout(uint32 msecs);
  2717.     void Callback();
  2718.     void Cancel();
  2719.     XP_Bool IsTimeoutEnabled() { return m_timeoutEnabled; }
  2720.     virtual void OnCallback();
  2721. private:
  2722.     friend void CEditTimerCallback (void * closure);
  2723.     XP_Bool m_timeoutEnabled;
  2724.     void*   m_timerID;
  2725. };
  2726.  
  2727. class CFinishLoadTimer : public CEditTimer {
  2728. public:
  2729.     CFinishLoadTimer();
  2730.     void FinishedLoad(CEditBuffer* pBuffer);
  2731. protected:
  2732.     virtual void OnCallback();
  2733. private:
  2734.     CEditBuffer* m_pBuffer;
  2735. };
  2736.  
  2737. class CRelayoutTimer : public CEditTimer {
  2738. public:
  2739.     CRelayoutTimer();
  2740.     void SetEditBuffer(CEditBuffer* pBuffer);
  2741.     void Relayout(CEditElement *pStartElement, int iOffset);
  2742.     void Flush();
  2743. protected:
  2744.     virtual void OnCallback();
  2745. private:
  2746.     CEditBuffer* m_pBuffer;
  2747.     CEditElement* m_pStartElement;
  2748.     int m_iOffset;
  2749. };
  2750.  
  2751. class CAutoSaveTimer : public CEditTimer {
  2752. public:
  2753.     CAutoSaveTimer();
  2754.     void SetEditBuffer(CEditBuffer* pBuffer);
  2755.     void SetPeriod(int32 minutes);
  2756.     int32 GetPeriod();
  2757.     void Restart();
  2758.  
  2759.     //CLM: Call before and after operations
  2760.     //     that are upset by autosave relayout
  2761.     void Suspend();
  2762.     void Resume();
  2763.  
  2764. protected:
  2765.     virtual void OnCallback();
  2766. private:
  2767.     CEditBuffer* m_pBuffer;
  2768.     int32 m_iMinutes;
  2769.     XP_Bool m_bSuspended;
  2770.     XP_Bool m_bCalledWhileSuspended;
  2771. };
  2772.  
  2773.  
  2774. //
  2775. // CSizingObject
  2776. //
  2777.  
  2778. class CSizingObject {
  2779. public:
  2780.     CSizingObject();
  2781.     ~CSizingObject();
  2782.     XP_Bool Create(CEditBuffer *pBuffer,
  2783.                    LO_Element *pLoElement,
  2784.                    int iSizingStyle,
  2785.                    int32 xVal, int32 yVal,
  2786.                    XP_Bool bLockAspect, XP_Rect *pRect);
  2787.  
  2788.  
  2789.     XP_Bool GetSizingRect(int32 xVal, int32 yVal, XP_Bool bLockAspect, XP_Rect *pRect);
  2790.     void ResizeObject();
  2791.     void EraseAddRowsOrCols();
  2792.  
  2793. private:
  2794.     CEditBuffer   *m_pBuffer;
  2795.     LO_Element    *m_pLoElement;
  2796.     XP_Rect        m_Rect;
  2797.     int            m_iStyle;
  2798.     int32          m_iXOrigin;
  2799.     int32          m_iYOrigin;
  2800.     int32          m_iStartWidth;
  2801.     int32          m_iStartHeight;
  2802.     int32          m_iParentWidth;
  2803.     int32          m_iViewWidth;
  2804.     int32          m_iViewHeight;
  2805.     int32          m_iAddCols;
  2806.     int32          m_iAddRows;
  2807.     XP_Bool        m_bWidthPercent;
  2808.     XP_Bool        m_bHeightPercent;
  2809.     XP_Bool        m_bPercentOriginal;
  2810.     int            m_iWidthMsgID;
  2811. };
  2812.  
  2813.  
  2814.  
  2815. //
  2816. // CEditBuffer
  2817. //
  2818.  
  2819. // Matches LO_NA constants, plus up/down
  2820.  
  2821. #define EDT_NA_CHARACTER 0
  2822. #define EDT_NA_WORD 1
  2823. #define EDT_NA_LINEEDGE 2
  2824. #define EDT_NA_DOCUMENT 3
  2825. #define EDT_NA_UPDOWN 4
  2826. #define EDT_NA_COUNT 5
  2827.  
  2828. class CEditBuffer {
  2829. public:
  2830.     long m_lifeFlag; /* Used to detect accesses to deleted buffer. */
  2831.     MWContext *m_pContext;
  2832.     CEditRootDocElement *m_pRoot;
  2833.     // To do: replace m_pCurrent et. al. with a CEditInsertPoint
  2834.     CEditLeafElement *m_pCurrent;
  2835.     ElementOffset m_iCurrentOffset;
  2836.     XP_Bool m_bCurrentStickyAfter;
  2837.  
  2838.     CEditElement* m_pCreationCursor;
  2839.  
  2840.     ED_Color m_colorText;
  2841.     ED_Color m_colorBackground;
  2842.     ED_Color m_colorLink;
  2843.     ED_Color m_colorFollowedLink;
  2844.     ED_Color m_colorActiveLink;
  2845.     char *m_pTitle;
  2846.     char *m_pBackgroundImage;
  2847.     XP_Bool m_bBackgroundNoSave;
  2848.     char *m_pFontDefURL;
  2849.     XP_Bool m_bFontDefNoSave;
  2850.     char *m_pBaseTarget;
  2851.     char *m_pBodyExtra;
  2852.     CEditImageLoader *m_pLoadingImage;
  2853.     CFileSaveObject *m_pSaveObject;
  2854.     XP_Bool m_bMultiSpaceMode;
  2855.     
  2856.     // Save copied style here
  2857.     // By making it static, we can paste attributes
  2858.     //   into a different window
  2859.     static EDT_CharacterData *m_pCopyStyleCharacterData;
  2860.  
  2861.     int m_hackFontSize;             // not a real implementation, just for testing
  2862.  
  2863.     int32 m_iDesiredX;
  2864.     int32 m_lastTopY;
  2865.     XP_Bool m_inScroll;
  2866.     XP_Bool m_bBlocked;                // we are doing the initial layout so we
  2867.                                     //  are blocked.
  2868.     XP_Bool m_bSelecting;
  2869.     XP_Bool m_bNoRelayout;               // maybe should be a counter
  2870.  
  2871.     CEditElement *m_pSelectStart;
  2872.     int m_iSelectOffset;
  2873.  
  2874.     int m_preformatLinePos;
  2875.     XP_Bool m_bInPreformat;             // semaphore to keep us from reentering
  2876.                                     //  NormalizePreformat
  2877.     TagType m_iLastTagType; // The previous tag's type, comments are ignored.
  2878.     XP_Bool m_bLastTagIsEnd; // The previous tag's open vs. close state, comments are ignored.
  2879.  
  2880.  
  2881.     CPrintState printState;
  2882.     CEditLinkManager linkManager;
  2883.     TXP_GrowableArray_EDT_MetaData m_metaData;
  2884.     
  2885.     // Get time and save in m_FileSaveTime
  2886.     // Public so CEditFileSave can call it
  2887.     void  GetFileWriteTime();
  2888.  
  2889.     // Used only by CEditBuffer::Relayout()
  2890.     TXP_GrowableArray_LO_TableStruct m_RelayoutTables;
  2891.  
  2892.     PRBool m_bEncrypt;
  2893.  
  2894. private:
  2895.     CParseState*    GetParseState();
  2896.     void            PushParseState();
  2897.     void            PopParseState();
  2898.     void            ResetParseStateStack();
  2899.     TXP_PtrStack_CParseState    m_parseStateStack;
  2900.  
  2901.     // CFileFileSaveObject->m_status copied here
  2902.     //  to return a result even if save object is deleted
  2903.     ED_FileError m_status;
  2904.  
  2905.     XP_Bool IsSelectionComment(PA_Tag* pTag);
  2906.     XP_Bool HandleSelectionComment(PA_Tag* pTag, CEditElement*& pElement, intn& retVal);
  2907.     CEditCommandLog* GetCommandLog(){ XP_ASSERT(m_pCommandLog); return m_pCommandLog; };
  2908.     CEditCommandLog* m_pCommandLog;
  2909.     XP_Bool m_bTyping;
  2910.     CEditInternalAnchorElement* m_pStartSelectionAnchor;
  2911.     CEditInternalAnchorElement* m_pEndSelectionAnchor;
  2912.     XP_Bool m_bStartSelectionStickyAfter;
  2913.     XP_Bool m_bEndSelectionStickyAfter;
  2914.  
  2915.     XP_Bool m_bLayoutBackpointersDirty;
  2916.     //CLM: Save the current file time to
  2917.     //     check if an outside editor changed our source
  2918.     int32 m_iFileWriteTime;
  2919.  
  2920.     // For maintaining the selected Table, row, columns, or individual cell
  2921.     // Only 1 table can be selected, but multiple cells are selected for rows, columns
  2922.     // Array of SelectedCell structs matches LO_Elements to CEditElements
  2923.     TXP_GrowableArray_CEditTableCellElement m_SelectedEdCells;
  2924.     TXP_GrowableArray_LO_CellStruct         m_SelectedLoCells;
  2925.     CEditTableElement                      *m_pSelectedEdTable;
  2926.     LO_TableStruct                         *m_pSelectedLoTable;
  2927.     
  2928.     // Index to the next selected cell from the m_SelectedEdCells list.
  2929.     // This and m_CurrentInsertPoint are used by GetFirstCellSelection() and SelectNextSelectedCell()
  2930.     intn m_iNextSelectedCell;
  2931.  
  2932.     // Save the current insert point before mucking with selected cells
  2933.     // Don't need this as long as we suppress relayout for individual
  2934.     //   cell selection format changes. Just relayout entire table when done
  2935. //    CEditInsertPoint m_CurrentInsertPoint;
  2936.  
  2937.     // This is either m_pSelectedLoTable or last selected cell 
  2938.     //   (which will be a member of m_SelectedLoCells list)
  2939.     LO_Element     *m_pSelectedTableElement;
  2940.     ED_HitType      m_TableHitType;
  2941.  
  2942.     // Used with ExtentTableCellSelection:
  2943.     //  save previous cell we used to extend selection so we change
  2944.     //  selection only when we move into a different cell
  2945.     LO_Element     *m_pPrevExtendSelectionCell;
  2946.  
  2947. #ifdef DEBUG
  2948.     friend CEditTestManager;
  2949.     CEditTestManager* m_pTestManager;
  2950.     int16 m_iSuppressPhantomInsertPointCheck;
  2951.     XP_Bool m_bSkipValidation;
  2952. #endif
  2953.  
  2954. public:
  2955.     CEditBuffer( MWContext* pContext );
  2956.     ~CEditBuffer();
  2957.     CEditElement* CreateElement(PA_Tag* pTag, CEditElement *pParent);
  2958.     CEditElement* CreateFontElement(PA_Tag* pTag, CEditElement *pParent);
  2959.     intn ParseTag(pa_DocData *data_doc, PA_Tag* pTag, intn status);
  2960.  
  2961. private:
  2962.     XP_Bool ShouldAutoStartBody(PA_Tag* pTag, int16 csid);
  2963.     intn ParseOpenTag(pa_DocData *data_doc, PA_Tag* pTag, intn status);
  2964.     void ParseUnsupportedTag(PA_Tag* pTag, CEditElement*& pElement, intn& retVal);
  2965.     void ParseLink(PA_Tag* pTag, CEditElement*& pElement, intn& retVal);
  2966.     void ParseLinkFontDef(PA_Tag* pTag, CEditElement*& pElement, intn& retVal);
  2967.     intn ParseEndTag(PA_Tag* pTag);
  2968.     void WriteClosingScriptTag();
  2969. public:
  2970.     void FinishedLoad();
  2971.     void FinishedLoad2();
  2972.     void DummyCharacterAddedDuringLoad();
  2973.  
  2974.     XP_Bool IsComposeWindow(){ return m_pContext->bIsComposeWindow; }
  2975.  
  2976.     void PrintTree( CEditElement* m_pRoot );
  2977.     void DebugPrintTree( CEditElement* m_pRoot );
  2978.     XP_HUGE_CHAR_PTR GetPositionalText();
  2979.     void StreamToPositionalText( CEditElement* pElement, IStreamOut* pOut );
  2980.  
  2981.     void PrintDocumentHead( CPrintState *pPrintState );
  2982.     void PrintDocumentEnd( CPrintState *pPrintState );
  2983.     XP_Bool IsBodyTagRequired();
  2984.     static void Write(CStreamOutMemory *pSource, IStreamOut* pDest);
  2985.     void AppendTitle( char* pTitleString );
  2986.  
  2987.     void RepairAndSet(CEditSelection& selection);
  2988.     XP_Bool Reduce( CEditElement* pRoot );
  2989.     void NormalizeTree( );
  2990.     
  2991.     // Change Table and alls cell width data to match
  2992.     //  sizes calculated by Layout. Must do for all tables during Relayout()
  2993.     //  else generated HTML is very misleading!
  2994.     void FixupTableData();
  2995.     CEditElement* FindRelayoutStart( CEditElement *pStartElement );
  2996.     void Relayout( CEditElement *pStartElement, int iOffset,
  2997.             CEditElement *pEndElement = 0, intn relayoutFlags = 0 );
  2998.  
  2999.     void Reflow( CEditElement *pStartElement, int iOffset,
  3000.             CEditElement *pEndElement = 0, intn relayoutFlags = 0 );
  3001.             
  3002.     // Relayout current selected table (or parent of selected cells)
  3003.     void RelayoutSelectedTable();
  3004.  
  3005.     void SetCaret();
  3006.     void InternalSetCaret(XP_Bool bRevealPosition);
  3007.     LO_Position GetEffectiveCaretLOPosition(CEditElement* pElement, intn iOffset, XP_Bool bStickyAfter);
  3008.     void RevealPosition(CEditElement* pElement, int iOffset, XP_Bool bStickyAfter);
  3009.     void RevealSelection();
  3010.     XP_Bool GetLOCaretPosition(CEditElement* pElement, int iOffset, XP_Bool bStickyAfter,
  3011.         int32& targetX, int32& targetYLow, int32& targetYHigh);
  3012.     void WindowScrolled();
  3013.     void NavigateDocument(XP_Bool bSelect, XP_Bool bForward );
  3014.     /* Begin of document check preference and if move curosr is enabled, 
  3015.         we will move the cursor if not, we leave the cursor alone.
  3016.         REQUIRES: (Boolean to select or not), Valid editbuffer
  3017.         RETURNS: Nothing
  3018.         NOTE: uses
  3019.         NavigateChunk( bSelect, LO_NA_DOCUMENT, FALSE ); 
  3020.             if we move the cursor.
  3021.         and
  3022.         FE_ScrollDocTo (MWContext *context, int iLocation, int32 x,int32 y);
  3023.             if we do not
  3024.     */
  3025.     void PageUpDown(XP_Bool select, XP_Bool pagedown);
  3026.     /*PageUpDown requires:  Boolean to select the scrolled text if cursor should move
  3027.                             Boolean , true if page down, false if page up.
  3028.                   effects:  moves cursor or not depending on preferences.*/
  3029.  
  3030.     ED_ElementType GetCurrentElementType(); /* CM: "Current" is superfluous! */
  3031.  
  3032.     //
  3033.     // Doesn't allocate.  Returns the base URL of the document if it has been
  3034.     //  saved.  NULL if it hasn't.
  3035.     //
  3036.     char* GetBaseURL(){ return LO_GetBaseURL( m_pContext); }
  3037.  
  3038.     // editor buffer commands
  3039.     EDT_ClipboardResult InsertChar( int newChar, XP_Bool bTyping );
  3040.     EDT_ClipboardResult InsertChars( char* pNewChars, XP_Bool bTyping , XP_Bool bReduce);
  3041.     EDT_ClipboardResult DeletePreviousChar();
  3042.     EDT_ClipboardResult DeleteNextChar();
  3043.     EDT_ClipboardResult DeleteChar(XP_Bool bForward, XP_Bool bTyping = TRUE);
  3044.  
  3045.     // Delete key clears contents, but doesn't delete cells
  3046.     EDT_ClipboardResult ClearSelectedCells();
  3047.  
  3048.     CPersistentEditSelection GetEffectiveDeleteSelection();
  3049.  
  3050.     XP_Bool PreviousChar( XP_Bool bSelect );
  3051.     XP_Bool PrevPosition(CEditLeafElement *pEle, ElementOffset iOffset, CEditLeafElement*& pNew,
  3052.             ElementOffset& iNewOffset );
  3053.     XP_Bool NextPosition(CEditLeafElement *pEle, ElementOffset iOffset, CEditLeafElement*& pNew,
  3054.             ElementOffset& iNewOffset );
  3055.     void SelectNextChar( );
  3056.     void SelectPreviousChar( );
  3057.     void NextChar( XP_Bool bSelect );
  3058.     // Return FALSE if at the 1st or last cell
  3059.     // Option pRowCounter: if supplied, it is incremented when we move to a new row
  3060.     XP_Bool NextTableCell( XP_Bool bSelect, XP_Bool bForward, intn* pRowCounter = NULL );
  3061.     void UpDown( XP_Bool bSelect, XP_Bool bForward );
  3062.     void NavigateChunk( XP_Bool bSelect, intn chunkType, XP_Bool bForward );
  3063.     void EndOfLine( XP_Bool bSelect );
  3064.     //void BeginOfDocument( XP_Bool bSelect );
  3065.     //void EndOfDocument( XP_Bool bSelect );
  3066.     void ClearMailQuote();
  3067.     EDT_ClipboardResult ReturnKey(XP_Bool bTyping);
  3068.     EDT_ClipboardResult TabKey(XP_Bool bForward, XP_Bool bForceTabChar);
  3069.     EDT_ClipboardResult InternalReturnKey(XP_Bool bRelayout);
  3070.     void Indent();
  3071.     void IndentSelection(CEditSelection& selection);
  3072.     void IndentContainer( CEditContainerElement *pContainer,
  3073.             CEditListElement *pList );
  3074.     XP_Bool Outdent(); /* Returns TRUE if Outdent succeeded */
  3075.     XP_Bool OutdentSelection(CEditSelection& selection);
  3076.     void OutdentContainer( CEditContainerElement *pContainer,
  3077.             CEditListElement *pList );
  3078.     void MorphContainer( TagType t );
  3079.     void MorphListContainer( TagType t );
  3080.  
  3081.     // Added to use for selected regions and table cells
  3082.     void MorphContainerSelection( TagType t, CEditSelection& selection  );
  3083.     void MorphListContainer2( TagType t, CEditSelection& selection );
  3084.     void ToggleList(intn iTagType);
  3085.     void ToggleList2(intn iTagType, CEditSelection& selection);
  3086.  
  3087.     void SetParagraphAlign( ED_Alignment eAlign );
  3088.     void SetTableAlign( ED_Alignment eAlign );
  3089.     ED_Alignment GetParagraphAlign();
  3090.     void FormatCharacter( ED_TextFormat tf );
  3091.  
  3092.     // Format Character was modified to handle selected cells
  3093.     enum {
  3094.         ED_GET_FORMAT,
  3095.         ED_SET_FORMAT,
  3096.         ED_CLEAR_FORMAT
  3097.     };
  3098.     // This does similar scan of elements in selection, but only to find out if we should set
  3099.     //   or clear an attribute. Call this for a set of non-contiguous selected cells,
  3100.     //   then use result to set the iSetState for FormatCharacterSelection
  3101.     XP_Bool GetSetStateForCharacterSelection( ED_TextFormat tf, CEditSelection& selection );
  3102.  
  3103.     // iSetState default will get the set state in one pass,
  3104.     //   else it will use supplied state
  3105.     void FormatCharacterSelection( ED_TextFormat tf, CEditSelection& selection, XP_Bool bRelayout, intn iSetState = 0 );
  3106.  
  3107.     void SetCharacterData( EDT_CharacterData *pData );
  3108.     void SetCharacterDataSelection( EDT_CharacterData *pData, CEditSelection& selection, XP_Bool bRelayout );
  3109.     void SetCharacterDataAtOffset( EDT_CharacterData *pData,
  3110.             ED_BufferOffset iBufOffset, int32 iLen );
  3111.  
  3112.     EDT_CharacterData* GetCharacterData();
  3113.     // Pass in existing data to combine with previous data,
  3114.     //   used primarily for selected table cells
  3115.     EDT_CharacterData* GetCharacterDataSelection(EDT_CharacterData *pData, CEditSelection& selection);
  3116.  
  3117.     // Format all text contents into tab-delimeted cells,
  3118.     //  with CR/LF (or appropriate end-line for platform) at end of each row.
  3119.     // Use result to paste into spreadsheets like Excel
  3120.     char *GetTabDelimitedTextFromSelectedCells();
  3121.  
  3122.     // Convert Selected text into a table (put each paragraph in separate cell)
  3123.     // Number of rows is automatic - creates as many as needed
  3124.     void ConvertTextToTable(intn iColumns);
  3125.  
  3126.     // Convert the table into text - unravel existing paragraphs in cells
  3127.     void ConvertTableToText();
  3128.  
  3129.     // Save the character and paragraph style of selection or at caret
  3130.     void CopyStyle();
  3131.     
  3132.     // This is TRUE after EDT_CopyStyle is called, until the next left mouse up call
  3133.     XP_Bool CanPasteStyle() { return (m_pCopyStyleCharacterData != NULL); }
  3134.  
  3135.     // Apply the style to selection or at caret. Use bApplyStyle = FALSE to cancel
  3136.     void PasteStyle(XP_Bool bApplyStyle);
  3137.  
  3138.     // Get the index of the current font (at caret or selection)
  3139.     // Returns 0 (ED_FONT_VARIABLE), 1 (ED_FONT_FIXED), or 2 (ED_FONT_LOCAL)
  3140.     int GetFontFaceIndex();
  3141.     
  3142.     // Get the current font face for current selection or insert point
  3143.     // If the current font matches an XP font 'group',
  3144.     //    else it is the font face string from EDT_CharacterData.
  3145.     //    Use this to search your local font list
  3146.     //    in menu or listbox. DO NOT FREE RETURN VALUE (its a static string)
  3147.     char * GetFontFace();
  3148.  
  3149.     void ReplaceTextAtOffset( char *pText, EDT_CharacterData *pData,
  3150.             ED_BufferOffset iBufOffset, int32 iLen );
  3151.  
  3152.     void SetRefresh( XP_Bool bRefreshOn );
  3153.  
  3154.     void SetDisplayParagraphMarks(XP_Bool bDisplay);
  3155.     XP_Bool GetDisplayParagraphMarks();
  3156.  
  3157.     void SetDisplayTables(XP_Bool bDisplay);
  3158.     XP_Bool GetDisplayTables();
  3159.  
  3160.     ED_TextFormat GetCharacterFormatting();
  3161.     TagType GetParagraphFormatting();
  3162.     TagType GetParagraphFormattingSelection(CEditSelection& selection);
  3163.     int GetFontSize();
  3164.     void SetFontSize(int n);
  3165.     void SetFontSizeSelection(int n, CEditSelection& selection, XP_Bool bRelayout);
  3166.     int GetFontPointSize();
  3167.     void SetFontPointSize(int pointSize);
  3168.     ED_Color GetFontColor();
  3169.     void SetFontColor(ED_Color n);
  3170.     void SetFontColorSelection(ED_Color n, CEditSelection& selection, XP_Bool bRelayout);
  3171.     void InsertLeaf(CEditLeafElement *pLeaf);
  3172.     void InsertNonLeaf( CEditElement* pNonLeaf);
  3173.     EDT_ImageData* GetImageData();
  3174.     void SetImageData( EDT_ImageData* pData, XP_Bool bKeepImagesWithDoc );
  3175.     void InsertImage( EDT_ImageData* pData );
  3176.     int32 GetDefaultBorderWidth();
  3177.     void LoadImage( EDT_ImageData* pData, XP_Bool bKeepImagesWithDoc, XP_Bool bReplaceImage );
  3178.  
  3179.     // Tables
  3180.  
  3181.     // Like GetInsertPoint, but handles the right edge of the
  3182.     // selection differently: If the right edge of a non-empty
  3183.     // selection is at the edge of the table cell, the insert point
  3184.     // is moved inside the table cell. This gives the
  3185.     // correct behavior for table operations.
  3186.     void GetTableInsertPoint(CEditInsertPoint& ip);
  3187.     
  3188.     // Set insert point to beginning or end of cell contents
  3189.     // Returns TRUE if we found an appropriate 
  3190.     //   paragraph + text element inside cell
  3191.     XP_Bool SetTableInsertPoint(CEditTableCellElement *pCell, XP_Bool bStartOfCell = FALSE);
  3192.  
  3193.     XP_Bool IsInsertPointInTable();
  3194.     XP_Bool IsInsertPointInNestedTable();
  3195.     EDT_TableData* GetTableData();
  3196.     void SetTableData(EDT_TableData *pData);
  3197.     void InsertTable(EDT_TableData *pData);
  3198.     void DeleteTable();
  3199.  
  3200.     //cmanske: new:
  3201.     ED_MergeType GetMergeTableCellsType();
  3202.     XP_Bool CanSplitTableCell();
  3203.     void MergeTableCells();
  3204.     void SplitTableCell();
  3205.  
  3206.     XP_Bool IsInsertPointInTableCaption();
  3207.     EDT_TableCaptionData* GetTableCaptionData();
  3208.     void SetTableCaptionData(EDT_TableCaptionData *pData);
  3209.     void InsertTableCaption(EDT_TableCaptionData *pData);
  3210.     void DeleteTableCaption();
  3211.  
  3212.     XP_Bool IsInsertPointInTableRow();
  3213.     EDT_TableRowData* GetTableRowData();
  3214.     void SetTableRowData(EDT_TableRowData *pData);
  3215.     void InsertTableRows(EDT_TableRowData *pData, XP_Bool bAfterCurrentRow, intn number);
  3216.     void DeleteTableRows(intn number);
  3217.  
  3218.     XP_Bool IsInsertPointInTableCell();
  3219.     EDT_TableCellData* GetTableCellData();
  3220.  
  3221.     void ChangeTableSelection(ED_HitType iHitType, ED_MoveSelType iMoveType, EDT_TableCellData *pData = NULL);
  3222.  
  3223.     void SelectAndMoveToNextTableCell(XP_Bool bForward, EDT_TableCellData *pData = NULL);
  3224.     void SetTableCellData(EDT_TableCellData *pData);
  3225.     void InsertTableCells(EDT_TableCellData *pData, XP_Bool bAfterCurrentCell, intn number);
  3226.     void DeleteTableCells(intn number);
  3227.     void InsertTableColumns(EDT_TableCellData *pData, XP_Bool bAfterCurrentColumn, intn number);
  3228.     void DeleteTableColumns(intn number);
  3229.  
  3230.     XP_Bool IsInsertPointInLayer();
  3231.     EDT_LayerData* GetLayerData();
  3232.     void SetLayerData(EDT_LayerData *pData);
  3233.     void InsertLayer(EDT_LayerData *pData);
  3234.     void DeleteLayer();
  3235.  
  3236.     EDT_PageData* GetPageData();
  3237.     void SetPageData( EDT_PageData* pData );
  3238.     static void FreePageData( EDT_PageData* pData );
  3239.     void SetImageAsBackground();
  3240.     
  3241.     intn MetaDataCount( );
  3242.     intn FindMetaData( EDT_MetaData *pMetaData );
  3243.     intn FindMetaData( XP_Bool bHttpEquiv, char* pName );
  3244.     intn FindMetaDataIndex( EDT_MetaData *pMetaData );
  3245.     EDT_MetaData* MakeMetaData( XP_Bool bHttpEquiv, char *pName, char*pContent );
  3246.     EDT_MetaData* GetMetaData( intn n );
  3247.     void SetMetaData( EDT_MetaData *pMetaData );
  3248.     void DeleteMetaData( EDT_MetaData *pMetaData );
  3249.     static void FreeMetaData( EDT_MetaData *pMetaData );
  3250.     void ParseMetaTag( PA_Tag *pTag );
  3251.     void PrintMetaData( CPrintState *pPrintState );
  3252.     void PrintMetaData( CPrintState *pPrintState, int index );
  3253.  
  3254.     EDT_HorizRuleData* GetHorizRuleData();
  3255.     void SetHorizRuleData( EDT_HorizRuleData* pData );
  3256.     void InsertHorizRule( EDT_HorizRuleData* pData );
  3257.  
  3258.     char* GetTargetData();
  3259.     void SetTargetData( char* pData );
  3260.     void InsertTarget( char* pData );
  3261.     char* GetAllDocumentTargets();
  3262.     char* GetAllDocumentTargetsInFile(char *pHref);  //CLM
  3263.     char* GetAllDocumentFiles(XP_Bool **, XP_Bool);
  3264.  
  3265.     char* GetUnknownTagData();
  3266.     void SetUnknownTagData( char* pData );
  3267.     void InsertUnknownTag( char* pData );
  3268.  
  3269.     EDT_ListData* GetListData();
  3270.     void SetListData( EDT_ListData* pData );
  3271.  
  3272.     void InsertBreak( ED_BreakType eBreak, XP_Bool bTyping = TRUE );
  3273.  
  3274.     void SetInsertPoint( CEditLeafElement* pElement, int iOffset, XP_Bool bStickyAfter );
  3275.     void FixupInsertPoint();
  3276.     void FixupInsertPoint(CEditInsertPoint& ip);
  3277.     EDT_ClipboardResult DeleteSelection(XP_Bool bCopyAppendAttributes = TRUE);
  3278.     EDT_ClipboardResult DeleteSelection(CEditSelection& selection, XP_Bool bCopyAppendAttributes = TRUE);
  3279.     void DeleteBetweenPoints( CEditLeafElement* pBegin, CEditLeafElement* pEnd, XP_Bool bCopyAppendAttributes = TRUE );
  3280.     void PositionCaret( int32 x, int32 y);
  3281.  
  3282.     // Show where we can drop during  dragNdrop. Handles tables as well
  3283.     XP_Bool PositionDropCaret(int32 x, int32 y);
  3284.     void DeleteSelectionAndPositionCaret(int32 x, int32 y);
  3285.  
  3286.     // Data for table currently being dragged.  Accessible to all edit windows
  3287.     static EDT_DragTableData* m_pDragTableData;
  3288.  
  3289.     // Setup data for dragging table cells
  3290.     XP_Bool StartDragTable(int32 x, int32 y);
  3291.     static XP_Bool IsDraggingTable() { return m_pDragTableData != NULL; }
  3292.     static void StopDragTable();
  3293.  
  3294.     /*StartSelection:
  3295.         used when mouse is clicked or double clicked.  calls clearmove then done typing before 
  3296.         going on to LO_Click/LO_DoubleClick.
  3297.     */
  3298.     void StartSelection( int32 x, int32 y , XP_Bool doubleClick = FALSE);
  3299.     void MoveAndHideCaretInTable(LO_Element *pLoElement); //cmanske: Move caret without scrolling or showing caret
  3300.     // Moves caret to an existing cell -- use after deleting a cell or row, but before Relayout();
  3301.     void MoveToExistingCell(CEditTableElement *pTable, int32 X, int32 Y);
  3302.  
  3303.     void SelectObject( int32 x, int32 y);
  3304.     void ExtendSelection( int32 x, int32 y );
  3305.     void ExtendSelectionElement( CEditLeafElement *pElement, int iOffset, XP_Bool bStickyAfter );
  3306.     void EndSelection(int32 x, int32 y);
  3307.     void EndSelection();
  3308.     void SelectAll();
  3309.     void SelectTable();         //See below for new overloaded version
  3310.  
  3311.     void SelectTableCell();     //Now selects the cell border, not contents
  3312.     // Similar to the old version of SelectTableCell: selects a cells contents
  3313.     void SelectCellContents(CEditTableCellElement *pCell);
  3314.  
  3315.     // Very important for new Table/Cell selection strategy:
  3316.     // 1. Check if IsTableOrCellSelected() is TRUE,
  3317.     // 2. Call GetFirstCellSelection to contents of
  3318.     //     the "selected" table cell (from m_pSelectedEdTable or m_SelectedEdCells)
  3319.     // 3. Do whatever formating on returned selection data
  3320.     // 4. Call GetNextCellSelection() and repeat formatting
  3321.     //     until return value is FALSE.
  3322.     XP_Bool GetFirstCellSelection(CEditSelection& selection);
  3323.     XP_Bool GetNextCellSelection(CEditSelection& selection);
  3324.  
  3325.     // Similar to above, but just returns the cell pointer
  3326.     CEditTableCellElement *GetFirstSelectedCell();
  3327.     // *pRowCounter is incremented when 1st cell of next row is returned
  3328.     // Use these to build a selected table for cut/copy/paste of cells
  3329.     CEditTableCellElement *GetNextSelectedCell(intn *pRowCounter = NULL);
  3330.  
  3331.  
  3332.     void SelectRegion(CEditLeafElement *pBegin, intn iBeginPos,
  3333.             CEditLeafElement* pEnd, intn iEndPos, XP_Bool bFromStart = FALSE,
  3334.             XP_Bool bForward = FALSE );
  3335.     void SetSelection(CEditSelection& selection);
  3336.     void SetInsertPoint(CEditInsertPoint& insertPoint);
  3337.     void SetInsertPoint(CPersistentEditInsertPoint& insertPoint);
  3338.  
  3339.     void GetInsertPoint( CEditLeafElement** ppLeaf, ElementOffset *pOffset, XP_Bool * pbStickyAfter);
  3340.     XP_Bool GetPropertyPoint( CEditLeafElement** ppLeaf, ElementOffset *pOffset);
  3341.     CEditElement *GetSelectedElement();
  3342.     void SelectCurrentElement();
  3343.     void ClearSelection( XP_Bool bResyncInsertPoint = TRUE, XP_Bool bKeepLeft = FALSE );
  3344.     void BeginSelection( XP_Bool bExtend = FALSE, XP_Bool bFromStart = FALSE );
  3345.     void MakeSelectionEndPoints( CEditLeafElement*& pBegin, CEditLeafElement*& pEnd );
  3346.     void MakeSelectionEndPoints( CEditSelection& selection, CEditLeafElement*& pBegin, CEditLeafElement*& pEnd );
  3347.     
  3348.     void GetSelection( CEditLeafElement*& pStartElement, ElementOffset& iStartOffset,
  3349.                 CEditLeafElement*& pEndElement, ElementOffset& iEndOffset, XP_Bool& bFromStart );
  3350.     
  3351.     // Use data from supplied selection, or get from current selection if supplied is empty
  3352.     // Used were above used to be used -- allows using "selected" cell data
  3353.     void GetSelection( CEditSelection& selection, CEditLeafElement*& pStartElement, ElementOffset& iStartOffset,
  3354.                 CEditLeafElement*& pEndElement, ElementOffset& iEndOffset, XP_Bool& bFromStart );
  3355.  
  3356.     int Compare( CEditElement *p1, int i1Offset, CEditElement *p2, int i2Offset );
  3357.  
  3358.     void FileFetchComplete(ED_FileError m_status = ED_ERROR_NONE);
  3359.  
  3360.     void AutoSaveCallback();
  3361.     void SetAutoSavePeriod(int32 minutes);
  3362.     int32 GetAutoSavePeriod();
  3363.     void SuspendAutoSave(); //CLM
  3364.     void ResumeAutoSave();
  3365.  
  3366.     void ClearMove(XP_Bool bFlushRelayout = TRUE);
  3367.     XP_Bool IsSelected(){ return LO_IsSelected( m_pContext ); }
  3368.     XP_Bool IsSelecting(){ return m_bSelecting; }
  3369.     XP_Bool IsBlocked(){ return this == 0 || m_bBlocked; }
  3370.     XP_Bool IsPhantomInsertPoint();
  3371.     XP_Bool IsPhantomInsertPoint(CEditInsertPoint& ip);
  3372.     void ClearPhantomInsertPoint();
  3373.     XP_Bool GetDirtyFlag();
  3374.     void DocumentStored();
  3375.  
  3376.     EDT_ClipboardResult CanCut(XP_Bool bStrictChecking);
  3377.     EDT_ClipboardResult CanCut(CEditSelection& selection, XP_Bool bStrictChecking);
  3378.     EDT_ClipboardResult CanCopy(XP_Bool bStrictChecking);
  3379.     EDT_ClipboardResult CanCopy(CEditSelection& selection, XP_Bool bStrictChecking);
  3380.     EDT_ClipboardResult CanPaste(XP_Bool bStrictChecking);
  3381.     EDT_ClipboardResult CanPaste(CEditSelection& selection, XP_Bool bStrictChecking);
  3382.  
  3383.     XP_Bool CanSetHREF();
  3384.     char *GetHREF();
  3385.     ED_LinkId GetHREFLinkID();
  3386.     char *GetHREFText();
  3387.     void GetHREFData( EDT_HREFData *pData );
  3388.     void SetHREFData( EDT_HREFData *pData );
  3389.     void SetHREF( char *pHREF, char *pExtra );
  3390.     void SetHREFSelection( ED_LinkId eId );
  3391.  
  3392.     // Accessor functions
  3393.  
  3394.     ED_FileError SaveFile( ED_SaveFinishedOption finishedOpt,
  3395.                             char * pSourceURL, // used to resolve links in editor document.
  3396.                             ITapeFileSystem *tapeFS,  /* char *pDestURL, */
  3397.                             XP_Bool   bSaveAs,
  3398.                             XP_Bool   bKeepImagesWithDoc,
  3399.                             XP_Bool   bAutoAdjustLinks,
  3400.                             XP_Bool   bAutoSave,
  3401.                             char **ppIncludedFiles,
  3402.                             CEditSaveToTempData *pData = NULL);
  3403.     // Does actual save, from plugin callback.
  3404.     void SaveFileReal( CEditSaveData *pData);
  3405.  
  3406.     // Returns the desired on-disk, published output character set.
  3407.     int16 GetDocCharSetID();
  3408.  
  3409.     // Returns the current in-memory character set ID.
  3410.     // Will be the same as the wincsid, except without the AUTODETECT bits,
  3411.     // and except when the user has just changed the view encoding.
  3412.     int16 GetRAMCharSetID();
  3413.  
  3414.     void ForceDocCharSetID(int16 csid);
  3415.  
  3416.     ED_FileError PublishFile( ED_SaveFinishedOption finishedOpt,
  3417.                            char *pSourceURL,
  3418.                            char **ppIncludedFiles,
  3419.                            char *pDestURL, /* Must have trailing slash, ie after HEAD call */
  3420.                            char *pUsername,
  3421.                            char *pPassword,
  3422.                            XP_Bool   bKeepImagesWithDoc,
  3423.                            XP_Bool   bAutoAdjustLinks );
  3424.  
  3425. ////    ED_FileError WriteBufferToFile( char* pFileName );
  3426.  
  3427.     //CLM: Get current time and return TRUE if it changed
  3428.     XP_Bool IsFileModified();
  3429.  
  3430.     // saves the edit buffer to a file.
  3431.     //CM: was char *pFileName, added return value 0 for success, -1 if fail
  3432.     int  WriteToFile( XP_File hFile );
  3433.     // returns length of pBuffer. (You can't use XP_STRLEN on a XP_HUGE_CHAR_PTR.)
  3434.     int32 WriteToBuffer( XP_HUGE_CHAR_PTR* pBuffer, XP_Bool bEncodeSelectionAsComment );
  3435.  
  3436.     // Warning! This will delete the CEditBuffer.
  3437.     void ReadFromBuffer(XP_HUGE_CHAR_PTR pBuffer);
  3438.  
  3439.     void WriteToStream( IStreamOut *stream );
  3440.  
  3441.     // Delegates to WriteToBuffer() and ReadFromBuffer().
  3442.     CEditDocState *RecordState();
  3443.     void RestoreState(CEditDocState *);
  3444.  
  3445. #ifdef DEBUG
  3446.     void DebugPrintState(IStreamOut& stream);
  3447.     void ValidateTree();
  3448.     void SuppressPhantomInsertPointCheck(XP_Bool bSuppress);
  3449. #endif
  3450.     void DisplaySource();
  3451.     void InitEscapes();
  3452.     char* NormalizeText( char* pSrc );
  3453.     intn NormalizePreformatText( pa_DocData *pData, PA_Tag *pTag, intn status );
  3454.     MWContext *GetContext(){ return m_pContext; }
  3455.     EDT_ClipboardResult PasteQuoteBegin(XP_Bool bHTML);
  3456.     EDT_ClipboardResult PasteQuote(char *pText);
  3457.     EDT_ClipboardResult PasteQuoteINTL(char *pText, int16 csid);
  3458.     EDT_ClipboardResult PasteQuoteEnd();
  3459.     void PasteHTMLHook(CPrintState* pPrintState); // For CPrintState.
  3460.  
  3461.     EDT_ClipboardResult PasteText(char *pText, XP_Bool bMailQuote, XP_Bool bIsContinueTyping, XP_Bool bRelayout, XP_Bool bReduce); /* Deprecated. */
  3462.     EDT_ClipboardResult PasteText(char *pText, XP_Bool bMailQuote, XP_Bool bIsContinueTyping, int16 csid,  XP_Bool bRelayout, XP_Bool bReduce);
  3463.     EDT_ClipboardResult PasteHTML(char *pText, XP_Bool bUndoRedo);
  3464.     EDT_ClipboardResult PasteHTML(IStreamIn& stream, XP_Bool bUndoRedo);
  3465.     EDT_ClipboardResult PasteCellsIntoTable(IStreamIn& stream, EEditCopyType iCopyType);
  3466.     EDT_ClipboardResult PasteHREF( char **ppHref, char **ppTitle, int iCount);
  3467.     EDT_ClipboardResult CopySelection( char **ppText, int32* pTextLen,
  3468.             char **ppHtml, int32* pHtmlLen);
  3469.  
  3470.     XP_Bool CopyBetweenPoints( CEditElement *pBegin,
  3471.                     CEditElement *pEnd, char **ppText, int32* pTextLen,
  3472.                     char **ppHtml, int32* pHtmlLen );
  3473.     XP_Bool CopySelectionContents( CEditSelection& selection,
  3474.                     char **ppHtml, int32* pHtmlLen, EEditCopyType iCopyType = eCopyNormal );
  3475.     //cmanske: Added flags param to pass info about copied table elements
  3476.     XP_Bool CopySelectionContents( CEditSelection& selection,
  3477.                     IStreamOut& stream, EEditCopyType iCopyType = eCopyNormal );
  3478.     int32 GetClipboardSignature();
  3479.     int32 GetClipboardVersion();
  3480.     EDT_ClipboardResult CutSelection( char **ppText, int32* pTextLen,
  3481.             char **ppHtml, int32* pHtmlLen);
  3482.     XP_Bool CutSelectionContents( CEditSelection& selection,
  3483.                     char **ppHtml, int32* pHtmlLen );
  3484.  
  3485.     // cmanske: New Table-related cut/paste functions
  3486.     // Returns FALSE if number of cells in each row are not all the same
  3487.     XP_Bool CountRowsAndColsInPasteText(char *pText, intn* pRows, intn* pCols);
  3488.     // Supply Rows, Cols if known, else they will be calculated from text 
  3489.     EDT_ClipboardResult PasteTextAsNewTable(char *pText, intn iRows = 0, intn iCols = 0);
  3490.     EDT_ClipboardResult PasteTextIntoTable(char *pText, XP_Bool bReplace = FALSE, intn iRows = 0, intn iCols = 0);
  3491.  
  3492.     void RefreshLayout();
  3493.     void FixupSpace( XP_Bool bTyping = FALSE);
  3494.     ED_Alignment GetCurrentAlignment();
  3495.     int32 GetDesiredX(CEditLeafElement* pEle, intn iOffset, XP_Bool bStickyAfter);
  3496.  
  3497.     // Selection utility methods
  3498.     void GetInsertPoint(CEditInsertPoint& insertPoint);
  3499.     void GetInsertPoint(CPersistentEditInsertPoint& insertPoint);
  3500.     void GetSelection(CEditSelection& selection);
  3501.     void GetSelection(CPersistentEditSelection& persistentSelection);
  3502.     void SetSelection(CPersistentEditSelection& persistentSelection);
  3503.  
  3504.     // Navigation
  3505.     XP_Bool Move(CEditInsertPoint& pt, XP_Bool forward);
  3506.     XP_Bool Move(CPersistentEditInsertPoint& pt, XP_Bool forward);
  3507.     XP_Bool CanMove(CEditInsertPoint& pt, XP_Bool forward);
  3508.     XP_Bool CanMove(CPersistentEditInsertPoint& pt, XP_Bool forward);
  3509.  
  3510.     void CopyEditText(CPersistentEditSelection& selection, CEditText& text);
  3511.     void CopyEditText(CEditText& text);
  3512.     void CutEditText(CEditText& text);
  3513.     void PasteEditText(CEditText& text);
  3514.  
  3515.     // Persistent to regular selection conversion routines
  3516.     CEditInsertPoint PersistentToEphemeral(CPersistentEditInsertPoint& persistentInsertPoint);
  3517.     CPersistentEditInsertPoint EphemeralToPersistent(CEditInsertPoint& insertPoint);
  3518.     CEditSelection PersistentToEphemeral(CPersistentEditSelection& persistentInsertPoint);
  3519.     CPersistentEditSelection EphemeralToPersistent(CEditSelection& insertPoint);
  3520.  
  3521.     // Command methods
  3522.     void AdoptAndDo(CEditCommand*);
  3523.     void Undo();
  3524.     void Redo();
  3525.     void Trim();
  3526.  
  3527.     // History limits
  3528.     intn GetCommandHistoryLimit();
  3529.     void SetCommandHistoryLimit(intn newLimit);
  3530.  
  3531.     // Returns NULL if out of range
  3532.     intn GetUndoCommand(intn);
  3533.     intn GetRedoCommand(intn);
  3534.     void BeginBatchChanges(intn commandID);
  3535.     void EndBatchChanges();
  3536.  
  3537.     XP_Bool IsWritable(); // FALSE while a plugin is executing.
  3538.  
  3539.     // Typing command methods.
  3540.     void DoneTyping();
  3541.     void StartTyping(XP_Bool bTyping);
  3542.  
  3543. //cmanske - no longer using column/row indexes
  3544. //    void SyncCursor(CEditTableElement* pTable, intn iColumn, intn iRow);
  3545. //    CEditSelection ComputeCursor(CEditTableElement* pTable, intn iColumn, intn iRow);
  3546.     void SyncCursor(CEditLayerElement* pLayer);
  3547.  
  3548.     void ReplaceText( char *pReplaceText, XP_Bool bReplaceAll,
  3549.                       char *pTextToLookFor, XP_Bool bCaseless, XP_Bool bBackward, XP_Bool bDoWrap );
  3550.  
  3551.     /* function for finding and replacing text once */
  3552.     XP_Bool ReplaceOnce(char *pReplaceText, XP_Bool bRelayout, XP_Bool bReduce);
  3553.  
  3554.     void ReplaceLoop(char *pReplaceText, XP_Bool bReplaceAll,
  3555.                          char *pTextToLookFor, XP_Bool bCaseless,
  3556.                          XP_Bool bBackward, XP_Bool bDoWrap );
  3557.  
  3558. #ifdef FIND_REPLACE
  3559.     XP_Bool FindAndReplace( EDT_FindAndReplaceData *pData );
  3560. #endif
  3561.  
  3562.     XP_Bool IsMultiSpaceMode(){ return m_bMultiSpaceMode; }
  3563.  
  3564. private:
  3565.     // CLM: Dynamic object sizing
  3566.     CSizingObject *m_pSizingObject;
  3567.     
  3568. public:
  3569.     // Table sizing, selection, add row or col interface
  3570.     
  3571.     // Get the hit type from current mouse location in the doc
  3572.     //  (See ED_HitType enum in include/edttypes.h)
  3573.     // Optional: Returns the table or cell element clicked on
  3574.     // bModifierKeyPressed is applicable if selecting table (upper left corner),
  3575.     //  or moving mouse over cell to extend selection.
  3576.     //  If TRUE, returns ED_HIT_SEL_ALL_CELLS instead of ED_HIT_SEL_TABLE
  3577.     ED_HitType GetTableHitRegion(int32 xVal, int32 yVal, LO_Element **ppElement, XP_Bool bModifierKeyPressed = FALSE);
  3578.  
  3579.     // Get the corresponding CEditTableElement if LoElementType == LO_TABLE,
  3580.     //   or CEditTableCellElement if LoElementType = LO_CELL
  3581.     CEditElement* GetTableElementFromLO_Element(LO_Element *pLoElement, int16 LoElementType);
  3582.  
  3583.     // Tells us where to insert or replace cell (cell we are over is in *ppElement)
  3584.     ED_DropType GetTableDropRegion(int32 *pX, int32 *pY, int32 *pWidth, int32 *pHeight, LO_Element **ppElement);
  3585.  
  3586.     // Used withing editor - use supplied cell's X and Y and get LO_CellStruct from it
  3587.     //   to pass to following version.
  3588.     // iHitType can be set to just 1 cell, or entire row or column
  3589.     XP_Bool SelectTableElement(CEditTableCellElement *pCell, ED_HitType iHitType);
  3590.  
  3591.     // This is only table select function exposed to FEs via EDT_SelectTableElement
  3592.     // Select a table, cell, row, or column and redraw table to show new selection
  3593.     // If selecting cells and bAppendSelection is TRUE, then current selected items will not be cleared
  3594.     //  (ignored if selecting a table - cell selection will be cleared)
  3595.     // All uses ignore x and y except when ED_HitType = ED_HIT_SEL_COL or ED_HIT_SEL_ROW,
  3596.     //   which need those coordinates to find the REAL column or row 
  3597.     //   when ROWSPAN or COLSPAN is used.
  3598.     // If pLoElement == NULL, then the current caret location is used
  3599.     //   to locate element by calling GetCurrentLoTableElement
  3600.     XP_Bool SelectTableElement(int32, int32 y, LO_Element *pLoElement, ED_HitType iHitType, 
  3601.                                XP_Bool bModifierKeyPressed = FALSE,
  3602.                                XP_Bool bExtendSelection = FALSE );
  3603.  
  3604.     // Helper for SelectTableElement - find appropriate element at current caret location
  3605.     LO_Element* GetCurrentLoTableElement(ED_HitType iHitType, int32 *pX, int32 *pY);
  3606.  
  3607.        
  3608.     // Called on mouse-move message after selection was started
  3609.     // on a row, column, or cell element
  3610.     // Returns the hit type: ED_HIT_SEL_ROW, ED_HIT_SEL_COL, ED_HIT_SEL_CELL, or ED_HIT_NONE
  3611.     //   reflecting what type of block we are extended,
  3612.     //     or ED_HIT_NONE if mouse is outside of the table
  3613.     //   Use this to set the type of cursor by the FEs
  3614.     ED_HitType ExtendTableCellSelection(int32 x, int32 y);
  3615.  
  3616.     // Used by ExtendTableCellSelection
  3617.     //  and SelectTableElement when bExtendSelection is TRUE,
  3618.     // Select all cells whose top and left are within a rect formed by
  3619.     //   left and top last selected cell (m_pSelectedTableElement) and pLastCell
  3620.     void SelectBlockOfCells(LO_CellStruct *pLastCell);
  3621.  
  3622.     // Get corresponding layout cell struct containing the given edit element
  3623.     // Null if not in a table, of course
  3624.     LO_CellStruct* GetLoCell(CEditElement *pEdElement);
  3625.  
  3626.     // Set or clear the two table pointers (m_pSelectedEdTable, m_pSelectedLoTable)
  3627.     // pLoTable must be supplied if bSelect is TRUE. 
  3628.     //   If FALSE, existing selected table is unselected
  3629.     // Table selection is redisplayed if changed from existing state
  3630.     //   pEdTable is optional - it will be found from pLoTable if pEdTable = NULL
  3631.     //   and returned
  3632.     CEditTableElement* SelectTable(XP_Bool bSelect, LO_TableStruct *pLoTable = NULL, CEditTableElement *pEdTable = NULL);
  3633.  
  3634.     // Helper to select a single cell - both Lo and Edit arrays updated
  3635.     //   and cells are redisplayed. pLoCell must be supplied, but
  3636.     //   pEdCell is optional - it will be found from pLoCell if pEdCell = NULL
  3637.     //   and returned
  3638.     CEditTableCellElement* SelectCell(XP_Bool bSelect, LO_CellStruct *pLoCell, CEditTableCellElement *pEdCell = NULL);
  3639.     
  3640.     // Set the special selection attribute used for all currently-selected cells,
  3641.     //  except for the supplied "focus" cell.
  3642.     // Front ends should always display the "special" attribute
  3643.     //  if that bit (LO_ELE_SELECTED_SPECIAL) even if LO_ELE_SELECTED ) is also set
  3644.     void DisplaySpecialCellSelection( CEditTableCellElement *pFocusCell = NULL,  EDT_TableCellData *pCellData = NULL );
  3645.     
  3646.     // Select current cell and change other currently-selected cells
  3647.     //  to LO_ELE_SELECTED_SPECIAL so user can tell difference between
  3648.     //  the "focus" cell (current, where caret is) and other selected cells
  3649.     //  Call just before Table Cell properties dialog is created
  3650.     // Supply pCellData to update iSelectionType and iSelectedCount values
  3651.     void StartSpecialCellSelection( EDT_TableCellData *pCellData = NULL );
  3652.  
  3653.     // Remove LO_ELE_SELECTED_SPECIAL from all currently-selected cells
  3654.     // Call after closing the Table Cell properties dialog
  3655.     void ClearSpecialCellSelection();
  3656.  
  3657.     // Rearrange order of cells in selected cell lists as they
  3658.     //   appear from upper left to lower right (rows first) 
  3659.     void SortSelectedCells();
  3660.     
  3661.     // Remove selection from all tables and cells (both Editor and LO_Element elements affected)
  3662.     void ClearTableAndCellSelection();
  3663.     
  3664.     // Clear any existing cells selected if current edit element is not inside selection
  3665.     void ClearCellSelectionIfNotInside();
  3666.  
  3667.     // If the supplied element is in our Table or Selection list,
  3668.     //  clear the selection. Call when deleting an element
  3669.     void ClearTableIfContainsElement(CEditElement *pElement);
  3670.     
  3671.     // Called from front ends before during redrawing of screen
  3672.     void ClearLastTableSelection();
  3673.  
  3674.     XP_Bool IsTableSelected() {return m_pSelectedEdTable != NULL; }
  3675.     XP_Bool IsTableOrCellSelected() { return (XP_Bool)(m_pSelectedEdTable ? TRUE : m_SelectedEdCells.Size()); }
  3676.     int     GetSelectedCellCount() { return m_SelectedEdCells.Size(); }
  3677.  
  3678.  
  3679.     // For special cell highlighting during drag and drop
  3680.     // pLoElement can be the table or any cell that is starting cell,
  3681.     //  all cells from starting cell will have attribute removed
  3682.     void ClearCellAttrmask(LO_Element *pLoElement, uint16 attrmask );
  3683.  
  3684.     // Start Column or Row search from current element
  3685.     // This works on geometric location data, not "logical" row or column
  3686.     CEditTableCellElement* GetFirstCellInCurrentColumn();
  3687.     CEditTableCellElement* GetFirstCellInCurrentRow();
  3688.  
  3689.     intn GetNumberOfSelectedColumns();
  3690.     intn GetNumberOfSelectedRows();
  3691.     void MoveToFirstSelectedCell();
  3692.     void MoveToLastSelectedCell();
  3693.  
  3694.     // Dynamic object sizing interface
  3695.     XP_Bool       IsSizing() { return (m_pSizingObject != 0); }
  3696.     ED_SizeStyle  CanSizeObject(LO_Element *pLoElement, int32 xVal, int32 yVal);
  3697.     ED_SizeStyle  StartSizing(LO_Element *pLoElement, int32 xVal, int32 yVal, XP_Bool bLockAspect, XP_Rect *pRect);
  3698.     XP_Bool       GetSizingRect(int32 xVal, int32 yVal, XP_Bool bLockAspect, XP_Rect *pRect);
  3699.     void          EndSizing();
  3700.     void          CancelSizing();
  3701.     
  3702.     XP_Bool       IsReady();
  3703.  
  3704.     // Spellcheck api
  3705.     XP_Bool FindNextMisspelledWord( XP_Bool bFirst, XP_Bool bSelect,
  3706.             CEditLeafElement **ppWordStart );
  3707.  
  3708.     // Iterate over mispelled words, replace or ignore them.
  3709.     enum EMSW_FUNC { EMSW_IGNORE, EMSW_REPLACE };
  3710.     void IterateMisspelledWords( EMSW_FUNC eFunc, char* pOldWord, char* 
  3711.             pNewWord, XP_Bool bAll );
  3712.  
  3713.     LO_Element* FirstElementOnLine(LO_Element* pTarget, int32* pLineNum);
  3714.  
  3715.     void ChangeEncoding(int16 csid);
  3716.     void SetEncoding(int16 csid);
  3717.     XP_Bool HasEncoding();
  3718.  
  3719.     // Used for QA only - Ctrl+Alt+Shift+N accelerator for automated testing
  3720.     void SelectNextNonTextObject();
  3721.     CEditTableElement *m_pNonTextSelectedTable;
  3722.  
  3723. #ifdef EDITOR_JAVA
  3724.     EditorPluginManager GetPlugins();
  3725. #endif
  3726.  
  3727. public:
  3728.     static XP_Bool IsAlive(CEditBuffer* pBuffer); // Tells you if the pointer is valid.
  3729.  
  3730. private:
  3731.     void CheckAndPrintComment(CEditLeafElement* pElement, CEditSelection& selection, XP_Bool bEnd);
  3732.     void CheckAndPrintComment2(const CEditInsertPoint& where, CEditSelection& selection, XP_Bool bEnd);
  3733.  
  3734.     void SetSelectionInNewDocument();
  3735.     void ParseBodyTag(PA_Tag *pTag);
  3736.     void RecordTag(PA_Tag* pTag, XP_Bool bWithLinefeed);
  3737.     void RecordJavaScriptAsUnknownTag(CStreamOutMemory* pOut);
  3738.  
  3739.     void SetBaseTarget(char* pTarget);
  3740.     char* GetBaseTarget(); /* NULL if no BASE TARGET */
  3741.  
  3742.     CFinishLoadTimer m_finishLoadTimer;
  3743.     CRelayoutTimer m_relayoutTimer;
  3744.     CAutoSaveTimer m_autoSaveTimer;
  3745.     XP_Bool m_bDisplayTables;
  3746.     XP_Bool m_bDummyCharacterAddedDuringLoad;
  3747.     static XP_Bool m_bAutoSaving;
  3748.     XP_Bool m_bReady;
  3749.     XP_Bool m_bPasteQuoteMode;
  3750.     XP_Bool m_bPasteHTML;
  3751.     XP_Bool m_bPasteHTMLWhenSavingDocument;
  3752.     CStreamOutMemory* m_pPasteHTMLModeText;
  3753.     CConvertCSIDStreamOut* m_pPasteTranscoder;
  3754.     XP_Bool m_bAbortPasteQuote;
  3755.     // In case the user sets the encoding
  3756.     int16 m_originalWinCSID;
  3757.     XP_Bool m_bForceDocCSID;
  3758.     int16 m_forceDocCSID;
  3759.  
  3760. //preference information
  3761.     static XP_Bool m_bMoveCursor; //true = move cursor when pageup/down false, just move scrollbar
  3762.     static XP_Bool m_bEdtBufPrefInitialized; //are the preferences initialized
  3763.     static int PrefCallback(const char *,void *);//callback for preferences
  3764.     static void InitializePrefs();//call this function to force initialization of preferences
  3765. };
  3766.  
  3767.  
  3768. //
  3769. // CEditTagCursor -
  3770. //
  3771. class CEditTagCursor {
  3772. private: // types
  3773.     enum TagPosition { tagOpen, tagEnd };
  3774.  
  3775. private: // data
  3776.  
  3777.     CEditBuffer *m_pEditBuffer;
  3778.     CEditElement *m_pCurrentElement;
  3779.     CEditPositionComparable m_endPos;
  3780.     TagPosition m_tagPosition;
  3781.     int m_stateDepth;
  3782.     int m_currentStateDepth;
  3783.     int m_iEditOffset;
  3784.     XP_Bool m_bClearRelayoutState;
  3785.     MWContext *m_pContext;
  3786.     PA_Tag* m_pStateTags;
  3787.  
  3788.  
  3789. public:  // routines
  3790.     CEditTagCursor( CEditBuffer* pEditBuffer, CEditElement *pElement,
  3791.             int iEditOffset, CEditElement* pEndElement );
  3792.     ~CEditTagCursor();
  3793.  
  3794.     PA_Tag* GetNextTag();
  3795.     PA_Tag* GetNextTagState();
  3796.     XP_Bool AtBreak(XP_Bool* pEndTag);
  3797.     int32 CurrentLine();
  3798.     XP_Bool ClearRelayoutState() { return m_bClearRelayoutState; }
  3799.     CEditTagCursor* Clone();
  3800. };
  3801.  
  3802. //-----------------------------------------------------------------------------
  3803. //  CEditImageLoader
  3804. //-----------------------------------------------------------------------------
  3805. class CEditImageLoader {
  3806. private:
  3807.     CEditBuffer *m_pBuffer;
  3808.     EDT_ImageData *m_pImageData;
  3809.     LO_ImageStruct *m_pLoImage;
  3810.     XP_Bool m_bReplaceImage;
  3811.  
  3812. public:
  3813.     CEditImageLoader( CEditBuffer *pBuffer, EDT_ImageData *pImageData,
  3814.             XP_Bool bReplaceImage );
  3815.     ~CEditImageLoader();
  3816.  
  3817.     void LoadImage();
  3818.     void SetImageInfo(int32 ele_id, int32 width, int32 height);
  3819. };
  3820.  
  3821. //-----------------------------------------------------------------------------
  3822. // CEditSaveToTempData: used to call back to FE after saving document to temp
  3823. // file.  Could be expanded to be a general callback mechanism for reporting
  3824. // when saving is complete.
  3825. //-----------------------------------------------------------------------------
  3826. class CEditSaveToTempData {
  3827. public:
  3828.   CEditSaveToTempData() : doneFn(NULL), hook(NULL), pFileURL(NULL) {}
  3829.   ~CEditSaveToTempData() {XP_FREEIF(pFileURL);}
  3830.  
  3831.   EDT_SaveToTempCallbackFn doneFn;
  3832.   void *hook;
  3833.   char *pFileURL;
  3834. };
  3835.  
  3836. //-----------------------------------------------------------------------------
  3837. //  CFileSaveObject
  3838. //-----------------------------------------------------------------------------
  3839. // Takes care of FE interaction, does not know that there is anything
  3840. // special about the first file (the root HTML document for CEditSaveObject).
  3841. class CFileSaveObject {
  3842.     friend void edt_CFileSaveObjectDone(XP_Bool,void *); // A callback.
  3843.  
  3844. private:
  3845.     XP_Bool m_bOverwriteAll;
  3846.     XP_Bool m_bDontOverwriteAll;
  3847.     XP_Bool m_bDontOverwrite;
  3848.     int m_iCurFile; // 1-based
  3849.     IStreamOut *m_pOutStream;
  3850.     XP_Bool m_bOpenOutputHandledError;
  3851.     CEditSaveToTempData *m_pSaveToTempData;
  3852.  
  3853. protected:
  3854.     // Override this if the child of CFileSaveObject needs to do anything special to save the
  3855.     // first file.  O.w. it will just be copied from source to dest like everything else.
  3856.     // Return TRUE if the child took care of saving the first file.
  3857.     virtual XP_Bool SaveFirstFile() {return FALSE;}
  3858.  
  3859.     // can be a full file path.  Grabs the path part automatically.
  3860.     // Return the path part of pFileURL, alloced with XP_STRDUP.
  3861.     char *GetPathURL( char* pFileURL );
  3862.  
  3863.     // Check to see if we should call FE_FinishedSave() to tell
  3864.     // the front end that a new file has been created.
  3865.     void CheckFinishedSave(intn iFileIndex,ED_FileError iError);
  3866.  
  3867.     MWContext *m_pContext;
  3868.     ITapeFileSystem *m_tapeFS;
  3869.     ED_FileError m_status;
  3870.     XP_Bool m_bFromAutoSave; // This save was initiated from the auto save callback.
  3871.  
  3872. public:
  3873.     //
  3874.     // inherited interface.
  3875.     //
  3876.     CFileSaveObject( MWContext *pContext, char *pSrcURL, ITapeFileSystem *tapeFS, XP_Bool bAutoSave,
  3877.                      CEditSaveToTempData * ) ;
  3878.     virtual ~CFileSaveObject();
  3879.  
  3880.     // Return values like ITapeFileSystem::AddFile().
  3881.     intn AddFile( char *pSrcURL, char *pMIMEType, int16 iDocCharSetID );
  3882.  
  3883.     ED_FileError SaveFiles();
  3884.  
  3885.     char *GetDestName( intn index );
  3886.     char *GetDestAbsoluteURL( intn index );
  3887.     char *GetSrcName( intn index );
  3888.     // Return newly allocated string.
  3889.  
  3890.     // Inherit from CFileSaveObject and implement FileFetchComplete.
  3891.     //
  3892.     virtual ED_FileError FileFetchComplete();
  3893.  
  3894.     void Cancel();
  3895.  
  3896.     // Communicate content type and other information to the tape file system.
  3897.     // This function is called from edt_MakeFileSaveStream 
  3898.     // after OpenOutputFile() and before FileFetchComplete().
  3899.     // Necessary so that libmime can convey the mime type of an inferior URL
  3900.     // that represents, for example, part of a mail or news message.
  3901.     void CopyURLInfo(const URL_Struct *pURL);
  3902.     
  3903. private:
  3904.     ED_FileError FetchNextFile();
  3905. /*    intn OpenOutputFile( int iFile ); */
  3906.  
  3907.     // Report error given by iError on the current file being processed.
  3908.     // Return whether we sould continue.  
  3909.     // Replaces FE_SaveErrorContinueDialog().
  3910.     XP_Bool SaveErrorContinueDialog(ED_FileError iError);
  3911.  
  3912. // Netlib interface
  3913. public:
  3914.     // Made Public so we can access from file save stream
  3915.     //  (We don't open file until
  3916.     //   libnet succeeds in finding source data)
  3917.     intn OpenOutputFile(/*int iFile*/);
  3918.     // Net Callbacks
  3919.     int NetStreamWrite( const char *block, int32 length );
  3920.     void NetFetchDone( URL_Struct *pUrl, int status, MWContext *pContext );
  3921.  
  3922. };
  3923.  
  3924.  
  3925. //-----------------------------------------------------------------------------
  3926. //  CEditSaveObject
  3927. //-----------------------------------------------------------------------------
  3928. class CEditSaveObject: public CFileSaveObject{
  3929. private:
  3930.     enum {IgnoreImage = -1, AttemptAdjust = -2};
  3931.  
  3932.     // Can return IgnoreImage or AttemptAdjust
  3933.     // If ppIncludedFiles is non-NULL, image will only be added if it is in
  3934.     // the list.
  3935.     // If ppIncludeFiles is NULL, use bNoSave to decide whether to add it.
  3936.     intn CheckAddFile( char *pSrc, char *pMIMEType, char **ppIncludedFiles, XP_Bool bNoSave );
  3937.  
  3938.     ////XP_Bool IsSameURL( char* pSrcURL, char *pLocalName );
  3939.  
  3940.    // ppList is a NULL-terminated list of absolute URLs.
  3941.    XP_Bool URLInList (char **ppList, char *pURL);
  3942.  
  3943.     // helper for FixupLinks().
  3944.     void FixupLink(intn iIndex, // index to tape file system
  3945.                    char **ppImageURL,   // Value to fixup.
  3946.                    char *pDestPathURL,
  3947.                    ED_HREFList *badLinks);
  3948.  
  3949.     char *FixupLinks();
  3950.  
  3951.     CEditBuffer *m_pBuffer;
  3952.     CEditDocState *m_pDocStateSave; // Backup of m_pBuffer before doing anything.
  3953.     char *m_pSrcURL;
  3954.     //XP_Bool m_bSaveAs;
  3955.     ED_SaveFinishedOption m_finishedOpt; // Should we be editing the newly saved doc after saving is done.
  3956.     XP_Bool m_bKeepImagesWithDoc;
  3957.     XP_Bool m_bAutoAdjustLinks;
  3958.     intn m_backgroundIndex;
  3959.     intn m_fontDefIndex;
  3960.  
  3961. public:
  3962.     CEditSaveObject( CEditBuffer *pBuffer, 
  3963.                             ED_SaveFinishedOption finishedOpt, char *pSrcURL, ITapeFileSystem *tapeFS,
  3964.                             XP_Bool bSaveAs,
  3965.                             XP_Bool bKeepImagesWithDoc, 
  3966.                             XP_Bool bAutoAdjustLinks,
  3967.                             XP_Bool bAutoSave,
  3968.                             CEditSaveToTempData *pSaveToTempData ); 
  3969.     ~CEditSaveObject();
  3970.  
  3971.     // Add HTML document, then find and add all images in document.
  3972.     // Returns success or not.
  3973.     // If pIncludedFiles in non-NULL, it is a NULL-terminated list of absolute
  3974.     // URLs telling which images may be published..  
  3975.     // Free all memory pointed to by ppIncludedFiles when done.
  3976.     XP_Bool AddAllFiles(char **ppIncludedFiles);
  3977.  
  3978.     virtual ED_FileError FileFetchComplete();
  3979.  
  3980.     // If list is non-null, free it element-wise, then free the list itself.
  3981.     // list is NULL-terminated if it exists.
  3982.     static void FreeList( char **list );
  3983.  
  3984.     // Save the source URL when we fail to publish
  3985.     // Used by EDT_GetDefaultPublishUrl to return the previous failed destination
  3986.     static char * m_pFailedPublishUrl;
  3987.  
  3988. protected:
  3989.     virtual XP_Bool SaveFirstFile();
  3990. };
  3991.  
  3992.  
  3993. #if 0 //// Now obsolete
  3994. //-----------------------------------------------------------------------------
  3995. //  CEditImageSaveObject
  3996. //-----------------------------------------------------------------------------
  3997. class CEditImageSaveObject: public CFileSaveObject{
  3998. private:
  3999.     CEditBuffer *m_pBuffer;
  4000.     EDT_ImageData *m_pData;
  4001.     XP_Bool m_bReplaceImage;
  4002.  
  4003. public:
  4004.     intn m_srcIndex;
  4005.     intn m_lowSrcIndex;
  4006.  
  4007.     CEditImageSaveObject( CEditBuffer *pBuffer, EDT_ImageData *pData,
  4008.                         XP_Bool bReplaceImage );
  4009.     ~CEditImageSaveObject();
  4010.  
  4011.     virtual ED_FileError FileFetchComplete();
  4012. };
  4013. #endif
  4014.  
  4015. #if 0
  4016. //-----------------------------------------------------------------------------
  4017. //  CEditBackgroundImageSaveObject
  4018. //-----------------------------------------------------------------------------
  4019. class CEditBackgroundImageSaveObject: public CFileSaveObject{
  4020. private:
  4021.     CEditBuffer *m_pBuffer;
  4022.  
  4023. public:
  4024.     CEditBackgroundImageSaveObject( CEditBuffer *pBuffer );
  4025.     ~CEditBackgroundImageSaveObject();
  4026.  
  4027.     virtual ED_FileError FileFetchComplete();
  4028. };
  4029. #endif
  4030.  
  4031. extern CBitArray *edt_setNoEndTag;
  4032. extern CBitArray *edt_setWriteEndTag;
  4033. extern CBitArray *edt_setHeadTags;
  4034. extern CBitArray *edt_setSoloTags;
  4035. extern CBitArray *edt_setBlockFormat;
  4036. extern CBitArray *edt_setCharFormat;
  4037. extern CBitArray *edt_setList;
  4038. extern CBitArray *edt_setUnsupported;
  4039. extern CBitArray *edt_setAutoStartBody;
  4040. extern CBitArray *edt_setTextContainer;
  4041. extern CBitArray *edt_setListContainer;
  4042. extern CBitArray *edt_setParagraphBreak;
  4043. extern CBitArray *edt_setFormattedText;
  4044. extern CBitArray *edt_setContainerSupportsAlign;
  4045. extern CBitArray *edt_setIgnoreWhiteSpace;
  4046. extern CBitArray *edt_setSuppressNewlineBefore;
  4047. extern CBitArray *edt_setRequireNewlineAfter;
  4048. extern CBitArray *edt_setContainerBreakConvert;
  4049. extern CBitArray *edt_setContainerHasLineAfter;
  4050. extern CBitArray *edt_setIgnoreBreakAfterClose;
  4051.  
  4052. inline XP_Bool BitSet( CBitArray* pBitArray, int i ){ if ( i < 0 ) return FALSE;
  4053.     else return (*pBitArray)[i]; }
  4054.  
  4055. inline int IsListContainer( TagType i ){ return BitSet( edt_setListContainer, i ); }
  4056.  
  4057. inline int TagHasClose( TagType i ){ return !BitSet( edt_setNoEndTag, i ); }
  4058. inline int WriteTagClose( TagType i ){ return (BitSet( edt_setWriteEndTag, i ) ||
  4059.                 TagHasClose(i)); }
  4060.  
  4061. //
  4062. // Utility functions.
  4063. //
  4064. char *EDT_TagString(int32 tagType);
  4065. ED_TextFormat edt_TagType2TextFormat( TagType t );
  4066. char *edt_WorkBuf( int iSize );
  4067. char *edt_QuoteString( char* pString );
  4068. char *edt_MakeParamString( char* pString );
  4069.  
  4070. char *edt_FetchParamString( PA_Tag *pTag, char* param, int16 win_csid );
  4071. XP_Bool edt_FetchParamBoolExist( PA_Tag *pTag, char* param, int16 win_csid );
  4072. XP_Bool edt_FetchDimension( PA_Tag *pTag, char* param,
  4073.                          int32 *pValue, XP_Bool *pPercent,
  4074.                          int32 nDefaultValue, XP_Bool bDefaultPercent, int16 win_csid );
  4075. // Old defaults: ED_ALIGN_BASELINE, FALSE
  4076. ED_Alignment edt_FetchParamAlignment( PA_Tag* pTag,
  4077.                 ED_Alignment eDefault, XP_Bool bVAlign, int16 win_csid );
  4078. int32 edt_FetchParamInt( PA_Tag *pTag, char* param, int32 defValue, int16 win_csid );
  4079. int32 edt_FetchParamInt( PA_Tag *pTag, char* param, int32 defValue, int32 defValueIfParamButNoValue, int16 win_csid );
  4080. ED_Color edt_FetchParamColor( PA_Tag *pTag, char* param, int16 win_csid );
  4081.  
  4082. // Preserves the old value of data if there's no parameter.
  4083. void edt_FetchParamString2(PA_Tag* pTag, char* param, char*& data, int16 win_csid);
  4084. void edt_FetchParamColor2( PA_Tag *pTag, char* param, ED_Color& data, int16 win_csid );
  4085.  
  4086. // Concatenates onto the old value
  4087. void edt_FetchParamExtras2( PA_Tag *pTag, char**ppKnownParams, char*& data, int16 win_csid );
  4088.  
  4089. LO_Color* edt_MakeLoColor( ED_Color c );
  4090. void edt_SetLoColor( ED_Color c, LO_Color *pColor );
  4091.  
  4092. void edt_InitEscapes(int16 csid, XP_Bool bQuoteHiBits);
  4093. void edt_PrintWithEscapes( CPrintState *ps, char *p, XP_Bool bBreakLines);
  4094. char *edt_LocalName( char *pURL );
  4095. PA_Block PA_strdup( char* s );
  4096.  
  4097. inline char *edt_StrDup( char *pStr );
  4098. EDT_ImageData* edt_NewImageData();
  4099. EDT_ImageData* edt_DupImageData( EDT_ImageData *pOldData );
  4100. void edt_FreeImageData( EDT_ImageData *pData );
  4101.  
  4102. void edt_SetTagData( PA_Tag* pTag, char* pTagData);
  4103. void edt_AddTag( PA_Tag*& pStart, PA_Tag*& pEnd, TagType t, XP_Bool bIsEnd,
  4104.         char *pTagData = 0 );
  4105.  
  4106. void edt_InitBitArrays();
  4107.  
  4108. // Given an absolute URL, return the path portion of it, allocated with XP_STRDUP.
  4109. char *edt_GetPathURL(char *);
  4110.  
  4111. //
  4112. // Convert NBSPs into spaces.
  4113. //
  4114. void edt_RemoveNBSP( int16 csid, char *pString );
  4115.  
  4116. //
  4117. // Retreive extra parameters and return them in the form:
  4118. //
  4119. //  ' foo=bar zoo mombo="fds ifds ifds">'
  4120. //
  4121. char* edt_FetchParamExtras( PA_Tag *pTag, char**ppKnownParams, int16 win_csid );
  4122.  
  4123. // Replace the Value of a Param, rebuilding the Tag data within given tag
  4124. // Returns TRUE if param NAME was already in the list. If it wasn't,
  4125. //   it is added to end of tag data. If pValue is NULL, pName is removed from tag
  4126. XP_Bool edt_ReplaceParamValue( PA_Tag *pTag, char * pName, char * pValue, int16 csid );
  4127.  
  4128. // Copies text out of a Huge pointer. Truncates it if it's too large for the platform.
  4129. // Returns a copy of the text. Caller owns the copy.
  4130. // csid is the character set id of the text. Used to make sure truncation occurs on a
  4131. // character boundary.
  4132. // pOutLength is the output length in bytes. Pass NULL if you don't care about the new length.
  4133. // The result is always zero terminated, so that if the input does not contain nulls,
  4134. // XP_STRLEN(result) == *pOutLenth.
  4135.  
  4136. char* edt_CopyFromHuge(int16 csid, XP_HUGE_CHAR_PTR text, int32 length, int32* pOutLength);
  4137.  
  4138.  
  4139. // Return dup'd string that is the same as pUrl except that any username/password info is removed.
  4140. char *edt_StripUsernamePassword(char *pUrl);
  4141.  
  4142. // Terminate string in place at "#" or "?"
  4143. void edt_StripAtHashOrQuestionMark(char *pUrl);
  4144.  
  4145. // Kills directory pName and, recursively, everything under it.
  4146. // pName is in xpURL format.
  4147. void edt_RemoveDirectoryR(char *pName);
  4148.  
  4149. // Just wrappers around the XP_* functions.  The only difference is that
  4150. // these functions will work if the directory ends in a trailing slash,
  4151. // avoiding obscure bugs on Win16.
  4152. XP_Dir edt_OpenDir(const char * name, XP_FileType type);
  4153. int edt_MakeDirectory(const char* name, XP_FileType type);
  4154. int edt_RemoveDirectory(const char *name, XP_FileType type);
  4155.  
  4156. // Returns the URL that should be used as the base for relative URLs in 
  4157. // the document.  Similar to just calling LO_GetBaseURL(), except returns
  4158. // the document temp directory for untitled documents.
  4159. // Must free returned memory.
  4160. char *edt_GetDocRelativeBaseURL(MWContext *pContext);
  4161.  
  4162. // Platform-specific end-of-line character(s) added to string,
  4163. //  returning in possibly-reallocated buffer that caller must free
  4164. char *edt_AppendEndOfLine(char *pText);
  4165. //
  4166. // Parse return values.
  4167. //
  4168. #define OK_IGNORE       2
  4169. #define OK_CONTINUE     1
  4170. #define OK_STOP         0
  4171. #define NOT_OK          -1
  4172.  
  4173. // Inline function implementations
  4174.  
  4175. inline char *edt_StrDup( char *pStr ){
  4176.     if( pStr ){ 
  4177.         return XP_STRDUP( pStr );
  4178.     }
  4179.     else {
  4180.         return 0;
  4181.     }
  4182. }
  4183.  
  4184. #ifdef DEBUG
  4185.  
  4186. class CEditTestManager {
  4187. public:
  4188.     CEditTestManager(CEditBuffer* pBuffer);
  4189.     XP_Bool Key(char key);
  4190.     XP_Bool Backspace();
  4191.     XP_Bool ReturnKey();
  4192.  
  4193. protected:
  4194.  
  4195.     void PowerOnTest();
  4196.  
  4197.     void DumpLoElements();
  4198.     void VerifyLoElements();
  4199.     void DumpDocumentContents();
  4200.  
  4201.     void PasteINTL();
  4202.     void PasteINTLText();
  4203.  
  4204.     void CopyBufferToDocument();
  4205.     void CopyDocumentToBuffer();
  4206.  
  4207.     XP_Bool ArrowTest();
  4208.     XP_Bool LArrowTest(XP_Bool bSelect);
  4209.     XP_Bool RArrowTest(XP_Bool bSelect);
  4210.     XP_Bool UArrowTest(XP_Bool bSelect);
  4211.     XP_Bool DArrowTest(XP_Bool bSelect);
  4212.     XP_Bool EveryNavigationKeyEverywhereTest();
  4213.     XP_Bool NavigateChunkCrashTest();
  4214.     XP_Bool NavChunkCrashTest(XP_Bool bSelect, int chunk, XP_Bool bDirection);
  4215.     XP_Bool DeleteKeyTest();
  4216.     XP_Bool BackspaceKeyTest();
  4217.     XP_Bool ZeroDocumentCursorTest();
  4218.     XP_Bool OneCharDocumentCursorTest();
  4219.     XP_Bool OneDayTest(int32 rounds);
  4220.     XP_Bool BoldTest(int32 rounds);
  4221.     XP_Bool TextFETest(); // Not really a test.
  4222.  
  4223.     void GetWholeDocumentSelection(CPersistentEditSelection& selection);
  4224.     void    DumpMemoryDelta();
  4225. #ifdef EDITOR_JAVA
  4226.     void DumpPlugins();
  4227.     void PerformFirstPlugin();
  4228.     void PerformPluginByName();
  4229.     void PerformFirstEncoder();
  4230.     void PerformPreOpen();
  4231. #endif
  4232.     void TestHTMLPaste();
  4233.     void SaveToTempFile();
  4234.     static void SaveToTempFileCB(char *pFileURL,void *hook);
  4235.     void RemoveTempFile();
  4236.     // Create the document-specific temporary directory.
  4237.     void GetDocTempDir();
  4238. private:
  4239.     CEditBuffer* m_pBuffer;
  4240.     XP_Bool m_bTesting;
  4241.     int m_iTriggerIndex;
  4242.     static const char* m_kTrigger;
  4243.  
  4244.     XP_HUGE_CHAR_PTR m_pSaveBuffer;
  4245.  
  4246. #ifdef XP_WIN32
  4247.     _CrtMemState m_state;
  4248. #endif
  4249.     char *m_pTempFileURL; // for SaveToTempFile() and RemoveTempFile().
  4250. };
  4251.  
  4252. #endif  //DEBUG
  4253.  
  4254. // Semantic sugar for debugging. Validates the tree on construction and
  4255. // destruction. Place in every method that munges the tree.
  4256. //
  4257. // VALIDATE_TREE(this);
  4258.  
  4259. #ifdef DEBUG
  4260. class CTreeValidater {
  4261.     CEditBuffer* m_pBuffer;
  4262. public:
  4263.     CTreeValidater(CEditBuffer* pBuffer)
  4264.      : m_pBuffer(pBuffer)
  4265.     {
  4266.         m_pBuffer->ValidateTree();
  4267.     }
  4268.     ~CTreeValidater() {
  4269.         m_pBuffer->ValidateTree();
  4270.     }
  4271. };
  4272.  
  4273. class CSuppressPhantomInsertPointCheck {
  4274.     CEditBuffer* m_pBuffer;
  4275. public:
  4276.     CSuppressPhantomInsertPointCheck(CEditBuffer* pBuffer)
  4277.      : m_pBuffer(pBuffer)
  4278.     {
  4279.         m_pBuffer->SuppressPhantomInsertPointCheck(TRUE);
  4280.     }
  4281.     ~CSuppressPhantomInsertPointCheck() {
  4282.         m_pBuffer->SuppressPhantomInsertPointCheck(FALSE);
  4283.     }
  4284. };
  4285.  
  4286. // The local variable names will cause problems if you try to
  4287. // use these macros twice in the same scope. However,
  4288. // they are nescessary to ensure that some compilers (MS VC 2.2)
  4289. // keep the object alive for the duration of the scope, instead
  4290. // of constructing and destructing it at the point of declaration.
  4291. // I think this may be a bug in the compiler -- but I'd have
  4292. // to check the ANSI standard to make sure.
  4293.  
  4294. #define VALIDATE_TREE(BUFFER) CTreeValidater CTreeValidater_x_zzx1(BUFFER)
  4295. #define SUPPRESS_PHANTOMINSERTPOINTCHECK(BUFFER) \
  4296.     CSuppressPhantomInsertPointCheck CSuppressPhantomInsertPointCheck_x_zzx2(BUFFER)
  4297. #else
  4298.  
  4299. #define VALIDATE_TREE(BUFFER)
  4300. #define SUPPRESS_PHANTOMINSERTPOINTCHECK(BUFFER)
  4301.  
  4302. #endif
  4303.  
  4304. // Find the current context's URL in the cached history data and update the
  4305. //   corresponding Title. Used by CEditBuffer::SetPageData()
  4306. void edt_UpdateEditHistoryTitle(MWContext * pMWContext, char * pTitle);
  4307.  
  4308. #endif  // _EDITOR_H
  4309. #endif  // EDITOR
  4310.  
  4311.  
  4312.