00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00033 #ifndef PG_RICHEDIT_H
00034 #define PG_RICHEDIT_H
00035
00036 #include "paragui.h"
00037 #include "pgscrollwidget.h"
00038 #include <map>
00039
00047 class DECLSPEC PG_RichEdit : public PG_ScrollWidget {
00048 public:
00049
00053 PG_RichEdit(PG_Widget* parent, const PG_Rect& r = PG_Rect::null, bool autoVerticalResize = false, Uint32 linewidth = 0, Uint32 tabSize = 30, Uint32 childsborderwidth = 8, const std::string& style="WidgetList");
00054
00059 void SetText(const std::string &text);
00060
00065 void AddChild(PG_Widget* child);
00066
00072 bool RemoveChild(PG_Widget* child);
00073
00075
00080 bool LoadText(const std::string& textfile);
00081
00087 void SetAutoResize(bool bHorizontal = true, bool bVertical = true);
00088
00092 void SetAlignment(Uint8 align);
00093
00097 void SetTabSize(Uint16 tabSize);
00098
00102 void SetLineWidth(Uint16 lineWidth);
00103
00104 protected:
00105
00106 void eventBlit(SDL_Surface* surface, const PG_Rect& src, const PG_Rect& dst);
00107 void eventSizeWidget(Uint16 w, Uint16 h);
00108
00109
00110
00111 bool my_AutoVerticalResize;
00112 bool my_AutoHorizontalResize;
00113
00114 struct RichWordDescription {
00115 PG_String my_Word;
00116 Uint32 my_Width;
00117 Uint32 my_EndSpaceWidth;
00118 Uint32 my_WidthAfterFormating;
00119 Uint32 my_Height;
00120 Uint32 my_BaseLine;
00121 Uint32 my_LineSkip;
00122 Uint32 my_EndMark;
00123 };
00124
00125 typedef std::vector<RichWordDescription> RichWordDescriptionArray;
00126
00127 RichWordDescriptionArray my_ParsedWords;
00128
00129 typedef std::vector<size_t> Size_tArray;
00130
00131 struct RichLinePart {
00132 Uint32 my_Left;
00133 Size_tArray my_WordIndexes;
00134 Sint32 my_WidthMax;
00135
00136 RichLinePart(Uint32 left, Sint32 widthMax) {
00137 my_Left = left;
00138 my_WidthMax = widthMax;
00139 }
00140
00141 Uint32 Width(RichWordDescriptionArray &parsedWords) {
00142 Size_tArray::iterator word;
00143 Uint32 width= 0;
00144
00145 for (word = my_WordIndexes.begin(); word < my_WordIndexes.end(); word++) {
00146 width += parsedWords[*word].my_WidthAfterFormating;
00147 }
00148
00149 return width;
00150 }
00151 };
00152
00153 typedef std::vector<RichLinePart> RichLinePartArray;
00154
00155 struct RichLine {
00156 Uint32 my_BaseLine;
00157 Uint32 my_LineSpace;
00158 RichLinePartArray my_LineParts;
00159
00160 RichLine(Uint32 baseLine) {
00161 my_BaseLine = baseLine;
00162 }
00163 };
00164
00165 typedef std::vector<RichLine> RichLineArray;
00166
00167 RichLineArray my_RichText;
00168
00169 Uint32 my_ChildsBorderWidth;
00170
00171 Uint16 my_TabSize;
00172 Uint16 my_LineWidth;
00173
00174 private:
00175
00176 bool handleScrollTrack();
00177
00178 enum { MARK_SPACE, MARK_NONBREAKABLE_SPACE, MARK_ENTER, MARK_TAB,
00179 MARK_TEXT_LEFT, MARK_TEXT_CENTER, MARK_TEXT_RIGHT, MARK_TEXT_BLOCK,
00180 MARK_ALL_LEFT, MARK_ALL_CENTER, MARK_ALL_RIGHT,
00181 MARKS_COUNT };
00182
00183 static const Uint32 my_Marks[MARKS_COUNT];
00184
00185 static const Uint32 my_FontBeginMark;
00186
00187 Uint32 my_Align;
00188
00189 std::string my_ActualFontName;
00190
00191 typedef std::map<Sint32, PG_Widget*> WidgetMap;
00192
00193 DLLLOCAL Sint32 CompleteLines();
00194
00195 DLLLOCAL size_t CompleteLine(RichLineArray::iterator actualLine, Sint32 &lineTop, size_t searchFrom, Uint32 &lineSpace, Uint32 &lineAscent, bool changeAlign);
00196
00197 DLLLOCAL Sint32 CompleteLinePart(size_t searchFrom, Sint32 lineTop, Uint32 &lineSpace, RichLineArray::iterator actualLine, RichLinePartArray::iterator actualLinePart, bool &breakLine, Uint32 &lineAscent, bool changeAlign);
00198
00199 DLLLOCAL void GetWidgetsOnLine(Sint32 lineTop, Uint32 lineHeight, WidgetMap &widgetsOnLine, bool clear);
00200
00201 DLLLOCAL bool ProcessLongLine(PG_String &word, size_t &searchFrom, Uint32 oldFind, Sint32 lineTop, Uint32 &lineSpace, bool normalLine, RichLineArray::iterator actualLine, RichLinePartArray::iterator actualLinePart, Uint32 &lineAscent);
00202
00203 DLLLOCAL size_t GetWord(size_t searchFrom, PG_String *word, Uint32 *endMark);
00204
00205 DLLLOCAL void AlignLinePart(RichLinePartArray::iterator actualLinePart, Uint32 align, bool breakLine);
00206
00207 DLLLOCAL void AlignLine(RichLineArray::iterator actualLine, WidgetMap &widgetsOnLine, Uint32 align);
00208
00209 DLLLOCAL void ParseWords();
00210
00211 public:
00212
00213 enum {
00214 PG_TEXT_LEFT = MARK_TEXT_LEFT,
00215 PG_TEXT_CENTER = MARK_TEXT_CENTER,
00216 PG_TEXT_RIGHT = MARK_TEXT_RIGHT,
00217 PG_TEXT_BLOCK = MARK_TEXT_BLOCK,
00218 PG_ALL_LEFT = MARK_ALL_LEFT,
00219 PG_ALL_CENTER = MARK_ALL_CENTER,
00220 PG_ALL_RIGHT = MARK_ALL_RIGHT
00221 };
00222
00223 private:
00224 void* my_internaldata;
00225 };
00226
00227
00228
00229 #endif