1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 35 //-------------------------------------------------------------------- 36 // 37 // Content.h 38 // 39 //-------------------------------------------------------------------- 40 41 #ifndef _CONTENT_H 42 #define _CONTENT_H 43 44 #include <FilePanel.h> 45 #include <FindDirectory.h> 46 #include <Font.h> 47 #include <fs_attr.h> 48 #include <Point.h> 49 #include <Rect.h> 50 #include <MessageFilter.h> 51 52 #include "KUndoBuffer.h" 53 54 #define MESSAGE_TEXT "Message:" 55 #define MESSAGE_TEXT_H 16 56 #define MESSAGE_TEXT_V 5 57 #define MESSAGE_FIELD_H 59 58 #define MESSAGE_FIELD_V 11 59 60 #define CONTENT_TYPE "content-type: " 61 #define CONTENT_ENCODING "content-transfer-encoding: " 62 #define CONTENT_DISPOSITION "Content-Disposition: " 63 #define MIME_TEXT "text/" 64 #define MIME_MULTIPART "multipart/" 65 66 class TMailWindow; 67 class TScrollView; 68 class TTextView; 69 class BFile; 70 class BList; 71 class BPopupMenu; 72 73 struct text_run_array; 74 75 typedef struct 76 { 77 bool header; 78 bool raw; 79 bool quote; 80 bool incoming; 81 bool close; 82 bool mime; 83 TTextView *view; 84 BEmailMessage *mail; 85 BList *enclosures; 86 sem_id *stop_sem; 87 } reader_info; 88 89 enum ENCLOSURE_TYPE 90 { 91 TYPE_ENCLOSURE = 100, 92 TYPE_BE_ENCLOSURE, 93 TYPE_URL, 94 TYPE_MAILTO 95 }; 96 97 struct hyper_text { 98 int32 type; 99 char *name; 100 char *content_type; 101 char *encoding; 102 int32 text_start; 103 int32 text_end; 104 BMailComponent *component; 105 bool saved; 106 bool have_ref; 107 entry_ref ref; 108 node_ref node; 109 }; 110 111 class TSavePanel; 112 113 114 //==================================================================== 115 116 class TContentView : public BView 117 { 118 public: 119 TContentView(BRect, bool incoming, BEmailMessage *mail, BFont *); 120 virtual void MessageReceived(BMessage *); 121 void FindString(const char *); 122 void Focus(bool); 123 void FrameResized(float, float); 124 125 TTextView *fTextView; 126 127 private: 128 bool fFocus; 129 bool fIncoming; 130 float fOffset; 131 }; 132 133 //==================================================================== 134 135 enum { 136 S_CLEAR_ERRORS = 1, 137 S_SHOW_ERRORS = 2 138 }; 139 140 class TTextView : public BTextView 141 { 142 public: 143 TTextView(BRect, BRect, bool incoming, BEmailMessage *mail, TContentView *,BFont *); 144 ~TTextView(); 145 146 virtual void AttachedToWindow(); 147 virtual void KeyDown(const char*, int32); 148 virtual void MakeFocus(bool); 149 virtual void MessageReceived(BMessage*); 150 virtual void MouseDown(BPoint); 151 virtual void MouseMoved(BPoint, uint32, const BMessage*); 152 virtual void InsertText(const char *text, int32 length, int32 offset, 153 const text_run_array *runs); 154 virtual void DeleteText(int32 start, int32 finish); 155 156 void ClearList(); 157 void LoadMessage(BEmailMessage *mail, bool quoteIt, const char *insertText); 158 void Open(hyper_text*); 159 status_t Save(BMessage *, bool makeNewFile = true); 160 void StopLoad(); 161 void AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding); 162 void CheckSpelling(int32 start, int32 end, 163 int32 flags = S_CLEAR_ERRORS | S_SHOW_ERRORS); 164 void FindSpellBoundry(int32 length, int32 offset, int32 *start, 165 int32 *end); 166 void EnableSpellCheck(bool enable); 167 168 void AddQuote(int32 start, int32 finish); 169 void RemoveQuote(int32 start, int32 finish); 170 171 void WindowActivated(bool flag); 172 void Undo(BClipboard *clipboard); 173 void Redo(); 174 175 const BFont *Font() const { return &fFont; } 176 177 bool fHeader; 178 bool fReady; 179 180 private: 181 struct { bool replaced, deleted; } fUndoState; 182 KUndoBuffer fUndoBuffer; 183 184 struct { bool active, replace; } fInputMethodUndoState; 185 KUndoBuffer fInputMethodUndoBuffer; 186 // For handling Input Method changes in undo. 187 188 struct spell_mark; 189 190 spell_mark *FindSpellMark(int32 start, int32 end, spell_mark **_previousMark = NULL); 191 void UpdateSpellMarks(int32 offset, int32 length); 192 status_t AddSpellMark(int32 start, int32 end); 193 bool RemoveSpellMark(int32 start, int32 end); 194 void RemoveSpellMarks(); 195 196 void ContentChanged(void); 197 198 class Reader; 199 friend class TTextView::Reader; 200 201 char *fYankBuffer; 202 int32 fLastPosition; 203 BFile *fFile; 204 BEmailMessage *fMail; 205 // for incoming/replied/forwarded mails only 206 BFont fFont; 207 TContentView *fParent; 208 sem_id fStopSem; 209 bool fStopLoading; 210 thread_id fThread; 211 BList *fEnclosures; 212 BPopUpMenu *fEnclosureMenu; 213 BPopUpMenu *fLinkMenu; 214 TSavePanel *fPanel; 215 bool fIncoming; 216 bool fSpellCheck; 217 bool fRaw; 218 bool fCursor; 219 220 struct spell_mark 221 { 222 spell_mark *next; 223 int32 start; 224 int32 end; 225 struct text_run_array *style; 226 }; 227 228 spell_mark *fFirstSpellMark; 229 230 class Reader 231 { 232 public: 233 Reader(bool header,bool raw,bool quote,bool incoming,bool stripHeaders,bool mime, 234 TTextView *view,BEmailMessage *mail,BList *list,sem_id sem); 235 236 static status_t Run(void *); 237 238 private: 239 bool ParseMail(BMailContainer *container,BTextMailComponent *ignore); 240 bool Process(const char *data, int32 len, bool isHeader = false); 241 bool Insert(const char *line, int32 count, bool isHyperLink, bool isHeader = false); 242 243 bool Lock(); 244 status_t Unlock(); 245 246 bool fHeader; 247 bool fRaw; 248 bool fQuote; 249 bool fIncoming; 250 bool fStripHeader; 251 bool fMime; 252 TTextView *fView; 253 BEmailMessage *fMail; 254 BList *fEnclosures; 255 sem_id fStopSem; 256 }; 257 }; 258 259 260 //==================================================================== 261 262 class TSavePanel : public BFilePanel { 263 public: 264 TSavePanel(hyper_text*, TTextView*); 265 virtual void SendMessage(const BMessenger*, BMessage*); 266 void SetEnclosure(hyper_text*); 267 268 private: 269 hyper_text *fEnclosure; 270 TTextView *fView; 271 }; 272 273 //==================================================================== 274 275 class TextRunArray { 276 public: 277 TextRunArray(size_t entries); 278 ~TextRunArray(); 279 280 text_run_array &Array() { return *fArray; } 281 size_t MaxEntries() const { return fNumEntries; } 282 283 private: 284 text_run_array *fArray; 285 size_t fNumEntries; 286 }; 287 288 extern void FillInQuoteTextRuns(BTextView *view, const char *line, int32 length, 289 const BFont &font, text_run_array *style, int32 maxStyles = 5); 290 291 #endif /* #ifndef _CONTENT_H */ 292