textctrl.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: textctrl.h
  3. // Purpose: interface of wxTextAttr
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. wxTextCtrl style flags
  9. */
  10. #define wxTE_NO_VSCROLL 0x0002
  11. #define wxTE_READONLY 0x0010
  12. #define wxTE_MULTILINE 0x0020
  13. #define wxTE_PROCESS_TAB 0x0040
  14. // alignment flags
  15. #define wxTE_LEFT 0x0000 // 0x0000
  16. #define wxTE_CENTER wxALIGN_CENTER_HORIZONTAL // 0x0100
  17. #define wxTE_RIGHT wxALIGN_RIGHT // 0x0200
  18. #define wxTE_CENTRE wxTE_CENTER
  19. // this style means to use RICHEDIT control and does something only under wxMSW
  20. // and Win32 and is silently ignored under all other platforms
  21. #define wxTE_RICH 0x0080
  22. #define wxTE_PROCESS_ENTER 0x0400
  23. #define wxTE_PASSWORD 0x0800
  24. // automatically detect the URLs and generate the events when mouse is
  25. // moved/clicked over an URL
  26. //
  27. // this is for Win32 richedit and wxGTK2 multiline controls only so far
  28. #define wxTE_AUTO_URL 0x1000
  29. // by default, the Windows text control doesn't show the selection when it
  30. // doesn't have focus - use this style to force it to always show it
  31. #define wxTE_NOHIDESEL 0x2000
  32. // use wxHSCROLL to not wrap text at all, wxTE_CHARWRAP to wrap it at any
  33. // position and wxTE_WORDWRAP to wrap at words boundary
  34. //
  35. // if no wrapping style is given at all, the control wraps at word boundary
  36. #define wxTE_DONTWRAP wxHSCROLL
  37. #define wxTE_CHARWRAP 0x4000 // wrap at any position
  38. #define wxTE_WORDWRAP 0x0001 // wrap only at words boundaries
  39. #define wxTE_BESTWRAP 0x0000 // this is the default
  40. // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for
  41. // wxTE_RICH controls - can be used together with or instead of wxTE_RICH
  42. #define wxTE_RICH2 0x8000
  43. #define wxTEXT_TYPE_ANY 0
  44. /**
  45. wxTextCoord is a line or row number
  46. */
  47. typedef long wxTextCoord;
  48. /**
  49. One of the following values can be passed to wxTextAttr::SetAlignment to determine paragraph alignment.
  50. */
  51. enum wxTextAttrAlignment
  52. {
  53. wxTEXT_ALIGNMENT_DEFAULT,
  54. wxTEXT_ALIGNMENT_LEFT,
  55. wxTEXT_ALIGNMENT_CENTRE,
  56. wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
  57. wxTEXT_ALIGNMENT_RIGHT,
  58. /** wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented.
  59. In future justification may be supported when printing or previewing, only. */
  60. wxTEXT_ALIGNMENT_JUSTIFIED
  61. };
  62. /**
  63. The following values are passed in a bitlist to wxTextAttr::SetFlags() to
  64. determine what attributes will be considered when setting the attributes for a text control.
  65. */
  66. enum wxTextAttrFlags
  67. {
  68. wxTEXT_ATTR_TEXT_COLOUR = 0x00000001,
  69. wxTEXT_ATTR_BACKGROUND_COLOUR = 0x00000002,
  70. wxTEXT_ATTR_FONT_FACE = 0x00000004,
  71. wxTEXT_ATTR_FONT_POINT_SIZE = 0x00000008,
  72. wxTEXT_ATTR_FONT_PIXEL_SIZE = 0x10000000,
  73. wxTEXT_ATTR_FONT_WEIGHT = 0x00000010,
  74. wxTEXT_ATTR_FONT_ITALIC = 0x00000020,
  75. wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040,
  76. wxTEXT_ATTR_FONT_STRIKETHROUGH = 0x08000000,
  77. wxTEXT_ATTR_FONT_ENCODING = 0x02000000,
  78. wxTEXT_ATTR_FONT_FAMILY = 0x04000000,
  79. wxTEXT_ATTR_FONT_SIZE = \
  80. ( wxTEXT_ATTR_FONT_POINT_SIZE | wxTEXT_ATTR_FONT_PIXEL_SIZE ),
  81. /**
  82. Defined as the combination of all @c wxTEXT_ATTR_FONT_* values above.
  83. */
  84. wxTEXT_ATTR_FONT = \
  85. ( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \
  86. wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_STRIKETHROUGH | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ),
  87. wxTEXT_ATTR_ALIGNMENT = 0x00000080,
  88. wxTEXT_ATTR_LEFT_INDENT = 0x00000100,
  89. wxTEXT_ATTR_RIGHT_INDENT = 0x00000200,
  90. wxTEXT_ATTR_TABS = 0x00000400,
  91. wxTEXT_ATTR_PARA_SPACING_AFTER = 0x00000800,
  92. wxTEXT_ATTR_PARA_SPACING_BEFORE = 0x00001000,
  93. wxTEXT_ATTR_LINE_SPACING = 0x00002000,
  94. wxTEXT_ATTR_CHARACTER_STYLE_NAME = 0x00004000,
  95. wxTEXT_ATTR_PARAGRAPH_STYLE_NAME = 0x00008000,
  96. wxTEXT_ATTR_LIST_STYLE_NAME = 0x00010000,
  97. wxTEXT_ATTR_BULLET_STYLE = 0x00020000,
  98. wxTEXT_ATTR_BULLET_NUMBER = 0x00040000,
  99. wxTEXT_ATTR_BULLET_TEXT = 0x00080000,
  100. wxTEXT_ATTR_BULLET_NAME = 0x00100000,
  101. /**
  102. Defined as the combination of all @c wxTEXT_ATTR_BULLET_* values above.
  103. */
  104. wxTEXT_ATTR_BULLET = \
  105. ( wxTEXT_ATTR_BULLET_STYLE | wxTEXT_ATTR_BULLET_NUMBER | wxTEXT_ATTR_BULLET_TEXT | \
  106. wxTEXT_ATTR_BULLET_NAME ),
  107. wxTEXT_ATTR_URL = 0x00200000,
  108. wxTEXT_ATTR_PAGE_BREAK = 0x00400000,
  109. wxTEXT_ATTR_EFFECTS = 0x00800000,
  110. wxTEXT_ATTR_OUTLINE_LEVEL = 0x01000000,
  111. /**
  112. Combines the styles @c wxTEXT_ATTR_FONT, @c wxTEXT_ATTR_EFFECTS, @c wxTEXT_ATTR_BACKGROUND_COLOUR,
  113. @c wxTEXT_ATTR_TEXT_COLOUR, @c wxTEXT_ATTR_CHARACTER_STYLE_NAME, @c wxTEXT_ATTR_URL.
  114. */
  115. wxTEXT_ATTR_CHARACTER = \
  116. (wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS| \
  117. wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL),
  118. /**
  119. Combines all the styles regarding text paragraphs.
  120. */
  121. wxTEXT_ATTR_PARAGRAPH = \
  122. (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
  123. wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
  124. wxTEXT_ATTR_BULLET|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL),
  125. /**
  126. Combines all previous values.
  127. */
  128. wxTEXT_ATTR_ALL = (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
  129. };
  130. /**
  131. Styles for wxTextAttr::SetBulletStyle. They can be combined together as a bitlist.
  132. */
  133. enum wxTextAttrBulletStyle
  134. {
  135. wxTEXT_ATTR_BULLET_STYLE_NONE = 0x00000000,
  136. wxTEXT_ATTR_BULLET_STYLE_ARABIC = 0x00000001,
  137. wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER = 0x00000002,
  138. wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER = 0x00000004,
  139. wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER = 0x00000008,
  140. wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER = 0x00000010,
  141. wxTEXT_ATTR_BULLET_STYLE_SYMBOL = 0x00000020,
  142. /** wxTEXT_ATTR_BULLET_STYLE_BITMAP is unimplemented. */
  143. wxTEXT_ATTR_BULLET_STYLE_BITMAP = 0x00000040,
  144. wxTEXT_ATTR_BULLET_STYLE_PARENTHESES = 0x00000080,
  145. wxTEXT_ATTR_BULLET_STYLE_PERIOD = 0x00000100,
  146. wxTEXT_ATTR_BULLET_STYLE_STANDARD = 0x00000200,
  147. wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS = 0x00000400,
  148. wxTEXT_ATTR_BULLET_STYLE_OUTLINE = 0x00000800,
  149. wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT = 0x00000000,
  150. wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT = 0x00001000,
  151. wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE = 0x00002000,
  152. wxTEXT_ATTR_BULLET_STYLE_CONTINUATION = 0x00004000
  153. };
  154. /**
  155. Styles for wxTextAttr::SetTextEffects(). They can be combined together as a bitlist.
  156. Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
  157. wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
  158. */
  159. enum wxTextAttrEffects
  160. {
  161. wxTEXT_ATTR_EFFECT_NONE = 0x00000000,
  162. wxTEXT_ATTR_EFFECT_CAPITALS = 0x00000001,
  163. wxTEXT_ATTR_EFFECT_SMALL_CAPITALS = 0x00000002,
  164. wxTEXT_ATTR_EFFECT_STRIKETHROUGH = 0x00000004,
  165. wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH = 0x00000008,
  166. wxTEXT_ATTR_EFFECT_SHADOW = 0x00000010,
  167. wxTEXT_ATTR_EFFECT_EMBOSS = 0x00000020,
  168. wxTEXT_ATTR_EFFECT_OUTLINE = 0x00000040,
  169. wxTEXT_ATTR_EFFECT_ENGRAVE = 0x00000080,
  170. wxTEXT_ATTR_EFFECT_SUPERSCRIPT = 0x00000100,
  171. wxTEXT_ATTR_EFFECT_SUBSCRIPT = 0x00000200
  172. };
  173. /**
  174. Convenience line spacing values; see wxTextAttr::SetLineSpacing().
  175. */
  176. enum wxTextAttrLineSpacing
  177. {
  178. wxTEXT_ATTR_LINE_SPACING_NORMAL = 10,
  179. wxTEXT_ATTR_LINE_SPACING_HALF = 15,
  180. wxTEXT_ATTR_LINE_SPACING_TWICE = 20
  181. };
  182. /**
  183. Describes the possible return values of wxTextCtrl::HitTest().
  184. The element names correspond to the relationship between the point asked
  185. for and the character returned, e.g. @c wxTE_HT_BEFORE means that the point
  186. is before (leftward or upward) it and so on.
  187. */
  188. enum wxTextCtrlHitTestResult
  189. {
  190. /// Indicates that wxTextCtrl::HitTest() is not implemented on this
  191. /// platform.
  192. wxTE_HT_UNKNOWN = -2,
  193. /// The point is before the character returned.
  194. wxTE_HT_BEFORE,
  195. /// The point is directly on the character returned.
  196. wxTE_HT_ON_TEXT,
  197. /// The point is below the last line of the control.
  198. wxTE_HT_BELOW,
  199. /// The point is beyond the end of line containing the character returned.
  200. wxTE_HT_BEYOND
  201. };
  202. /**
  203. @class wxTextAttr
  204. wxTextAttr represents the character and paragraph attributes, or style,
  205. for a range of text in a wxTextCtrl or wxRichTextCtrl.
  206. When setting up a wxTextAttr object, pass a bitlist mask to
  207. wxTextAttr::SetFlags() to indicate which style elements should be changed.
  208. As a convenience, when you call a setter such as SetFont, the relevant bit
  209. will be set.
  210. @library{wxcore}
  211. @category{richtext}
  212. @see wxTextCtrl, wxRichTextCtrl
  213. */
  214. class wxTextAttr
  215. {
  216. public:
  217. //@{
  218. /**
  219. Constructors.
  220. */
  221. wxTextAttr();
  222. wxTextAttr(const wxColour& colText,
  223. const wxColour& colBack = wxNullColour,
  224. const wxFont& font = wxNullFont,
  225. wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
  226. wxTextAttr(const wxTextAttr& attr);
  227. //@}
  228. /**
  229. Applies the attributes in @a style to the original object, but not those
  230. attributes from @a style that are the same as those in @a compareWith (if passed).
  231. */
  232. bool Apply(const wxTextAttr& style,
  233. const wxTextAttr* compareWith = NULL);
  234. /**
  235. Copies all defined/valid properties from overlay to current object.
  236. */
  237. void Merge(const wxTextAttr& overlay);
  238. /**
  239. Creates a new @c wxTextAttr which is a merge of @a base and @a overlay.
  240. Properties defined in @a overlay take precedence over those in @a base.
  241. Properties undefined/invalid in both are undefined in the result.
  242. */
  243. static wxTextAttr Merge(const wxTextAttr& base,
  244. const wxTextAttr& overlay);
  245. /**
  246. Partial equality test. If @a weakTest is @true, attributes of this object do not
  247. have to be present if those attributes of @a attr are present. If @a weakTest is
  248. @false, the function will fail if an attribute is present in @a attr but not
  249. in this object.
  250. */
  251. bool EqPartial(const wxTextAttr& attr, bool weakTest = true) const;
  252. /**
  253. @name GetXXX functions
  254. */
  255. //@{
  256. /**
  257. Returns the alignment flags.
  258. See ::wxTextAttrAlignment for a list of available styles.
  259. */
  260. wxTextAttrAlignment GetAlignment() const;
  261. /**
  262. Returns the background colour.
  263. */
  264. const wxColour& GetBackgroundColour() const;
  265. /**
  266. Returns a string containing the name of the font associated with the bullet symbol.
  267. Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
  268. */
  269. const wxString& GetBulletFont() const;
  270. /**
  271. Returns the standard bullet name, applicable if the bullet style is
  272. wxTEXT_ATTR_BULLET_STYLE_STANDARD.
  273. Currently the following standard bullet names are supported:
  274. - @c standard/circle
  275. - @c standard/square
  276. - @c standard/diamond
  277. - @c standard/triangle
  278. @note
  279. For wxRichTextCtrl users only: if you wish your rich text controls to support
  280. further bullet graphics, you can derive a class from wxRichTextRenderer or
  281. wxRichTextStdRenderer, override @c DrawStandardBullet and @c EnumerateStandardBulletNames,
  282. and set an instance of the class using wxRichTextBuffer::SetRenderer.
  283. */
  284. const wxString& GetBulletName() const;
  285. /**
  286. Returns the bullet number.
  287. */
  288. int GetBulletNumber() const;
  289. /**
  290. Returns the bullet style.
  291. See ::wxTextAttrBulletStyle for a list of available styles.
  292. */
  293. int GetBulletStyle() const;
  294. /**
  295. Returns the bullet text, which could be a symbol, or (for example) cached
  296. outline text.
  297. */
  298. const wxString& GetBulletText() const;
  299. /**
  300. Returns the name of the character style.
  301. */
  302. const wxString& GetCharacterStyleName() const;
  303. /**
  304. Returns flags indicating which attributes are applicable.
  305. See SetFlags() for a list of available flags.
  306. */
  307. long GetFlags() const;
  308. /**
  309. Creates and returns a font specified by the font attributes in the wxTextAttr
  310. object. Note that wxTextAttr does not store a wxFont object, so this is only
  311. a temporary font.
  312. For greater efficiency, access the font attributes directly.
  313. */
  314. wxFont GetFont() const;
  315. /**
  316. Gets the font attributes from the given font, using only the attributes
  317. specified by @a flags.
  318. */
  319. bool GetFontAttributes(const wxFont& font,
  320. int flags = wxTEXT_ATTR_FONT);
  321. /**
  322. Returns the font encoding.
  323. */
  324. wxFontEncoding GetFontEncoding() const;
  325. /**
  326. Returns the font face name.
  327. */
  328. const wxString& GetFontFaceName() const;
  329. /**
  330. Returns the font family.
  331. */
  332. wxFontFamily GetFontFamily() const;
  333. /**
  334. Returns the font size in points.
  335. */
  336. int GetFontSize() const;
  337. /**
  338. Returns the font style.
  339. */
  340. wxFontStyle GetFontStyle() const;
  341. /**
  342. Returns @true if the font is underlined.
  343. */
  344. bool GetFontUnderlined() const;
  345. /**
  346. Returns the font weight.
  347. */
  348. wxFontWeight GetFontWeight() const;
  349. /**
  350. Returns the left indent in tenths of a millimetre.
  351. */
  352. long GetLeftIndent() const;
  353. /**
  354. Returns the left sub-indent in tenths of a millimetre.
  355. */
  356. long GetLeftSubIndent() const;
  357. /**
  358. Returns the line spacing value, one of ::wxTextAttrLineSpacing values.
  359. */
  360. int GetLineSpacing() const;
  361. /**
  362. Returns the name of the list style.
  363. */
  364. const wxString& GetListStyleName() const;
  365. /**
  366. Returns the outline level.
  367. */
  368. int GetOutlineLevel() const;
  369. /**
  370. Returns the space in tenths of a millimeter after the paragraph.
  371. */
  372. int GetParagraphSpacingAfter() const;
  373. /**
  374. Returns the space in tenths of a millimeter before the paragraph.
  375. */
  376. int GetParagraphSpacingBefore() const;
  377. /**
  378. Returns the name of the paragraph style.
  379. */
  380. const wxString& GetParagraphStyleName() const;
  381. /**
  382. Returns the right indent in tenths of a millimeter.
  383. */
  384. long GetRightIndent() const;
  385. /**
  386. Returns an array of tab stops, each expressed in tenths of a millimeter.
  387. Each stop is measured from the left margin and therefore each value must
  388. be larger than the last.
  389. */
  390. const wxArrayInt& GetTabs() const;
  391. /**
  392. Returns the text foreground colour.
  393. */
  394. const wxColour& GetTextColour() const;
  395. /**
  396. Returns the text effect bits of interest.
  397. See SetFlags() for further information.
  398. */
  399. int GetTextEffectFlags() const;
  400. /**
  401. Returns the text effects, a bit list of styles.
  402. See SetTextEffects() for details.
  403. */
  404. int GetTextEffects() const;
  405. /**
  406. Returns the URL for the content.
  407. Content with @a wxTEXT_ATTR_URL style causes wxRichTextCtrl to show a
  408. hand cursor over it, and wxRichTextCtrl generates a wxTextUrlEvent
  409. when the content is clicked.
  410. */
  411. const wxString& GetURL() const;
  412. //@}
  413. /**
  414. @name HasXXX and IsXXX functions
  415. */
  416. //@{
  417. /**
  418. Returns @true if the attribute object specifies alignment.
  419. */
  420. bool HasAlignment() const;
  421. /**
  422. Returns @true if the attribute object specifies a background colour.
  423. */
  424. bool HasBackgroundColour() const;
  425. /**
  426. Returns @true if the attribute object specifies a standard bullet name.
  427. */
  428. bool HasBulletName() const;
  429. /**
  430. Returns @true if the attribute object specifies a bullet number.
  431. */
  432. bool HasBulletNumber() const;
  433. /**
  434. Returns @true if the attribute object specifies a bullet style.
  435. */
  436. bool HasBulletStyle() const;
  437. /**
  438. Returns @true if the attribute object specifies bullet text (usually
  439. specifying a symbol).
  440. */
  441. bool HasBulletText() const;
  442. /**
  443. Returns @true if the attribute object specifies a character style name.
  444. */
  445. bool HasCharacterStyleName() const;
  446. /**
  447. Returns @true if the @a flag is present in the attribute object's flag
  448. bitlist.
  449. */
  450. bool HasFlag(long flag) const;
  451. /**
  452. Returns @true if the attribute object specifies any font attributes.
  453. */
  454. bool HasFont() const;
  455. /**
  456. Returns @true if the attribute object specifies an encoding.
  457. */
  458. bool HasFontEncoding() const;
  459. /**
  460. Returns @true if the attribute object specifies a font face name.
  461. */
  462. bool HasFontFaceName() const;
  463. /**
  464. Returns @true if the attribute object specifies a font family.
  465. */
  466. bool HasFontFamily() const;
  467. /**
  468. Returns @true if the attribute object specifies italic style.
  469. */
  470. bool HasFontItalic() const;
  471. /**
  472. Returns @true if the attribute object specifies a font point or pixel size.
  473. */
  474. bool HasFontSize() const;
  475. /**
  476. Returns @true if the attribute object specifies a font point size.
  477. */
  478. bool HasFontPointSize() const;
  479. /**
  480. Returns @true if the attribute object specifies a font pixel size.
  481. */
  482. bool HasFontPixelSize() const;
  483. /**
  484. Returns @true if the attribute object specifies either underlining or no
  485. underlining.
  486. */
  487. bool HasFontUnderlined() const;
  488. /**
  489. Returns @true if the attribute object specifies font weight (bold, light or
  490. normal).
  491. */
  492. bool HasFontWeight() const;
  493. /**
  494. Returns @true if the attribute object specifies a left indent.
  495. */
  496. bool HasLeftIndent() const;
  497. /**
  498. Returns @true if the attribute object specifies line spacing.
  499. */
  500. bool HasLineSpacing() const;
  501. /**
  502. Returns @true if the attribute object specifies a list style name.
  503. */
  504. bool HasListStyleName() const;
  505. /**
  506. Returns @true if the attribute object specifies an outline level.
  507. */
  508. bool HasOutlineLevel() const;
  509. /**
  510. Returns @true if the attribute object specifies a page break before this
  511. paragraph.
  512. */
  513. bool HasPageBreak() const;
  514. /**
  515. Returns @true if the attribute object specifies spacing after a paragraph.
  516. */
  517. bool HasParagraphSpacingAfter() const;
  518. /**
  519. Returns @true if the attribute object specifies spacing before a paragraph.
  520. */
  521. bool HasParagraphSpacingBefore() const;
  522. /**
  523. Returns @true if the attribute object specifies a paragraph style name.
  524. */
  525. bool HasParagraphStyleName() const;
  526. /**
  527. Returns @true if the attribute object specifies a right indent.
  528. */
  529. bool HasRightIndent() const;
  530. /**
  531. Returns @true if the attribute object specifies tab stops.
  532. */
  533. bool HasTabs() const;
  534. /**
  535. Returns @true if the attribute object specifies a text foreground colour.
  536. */
  537. bool HasTextColour() const;
  538. /**
  539. Returns @true if the attribute object specifies text effects.
  540. */
  541. bool HasTextEffects() const;
  542. /**
  543. Returns @true if the attribute object specifies a URL.
  544. */
  545. bool HasURL() const;
  546. /**
  547. Returns @true if the object represents a character style, that is,
  548. the flags specify a font or a text background or foreground colour.
  549. */
  550. bool IsCharacterStyle() const;
  551. /**
  552. Returns @false if we have any attributes set, @true otherwise.
  553. */
  554. bool IsDefault() const;
  555. /**
  556. Returns @true if the object represents a paragraph style, that is,
  557. the flags specify alignment, indentation, tabs, paragraph spacing, or
  558. bullet style.
  559. */
  560. bool IsParagraphStyle() const;
  561. //@}
  562. /**
  563. @name SetXXX functions
  564. */
  565. //@{
  566. /**
  567. Sets the paragraph alignment. See ::wxTextAttrAlignment enumeration values.
  568. Of these, wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented.
  569. In future justification may be supported when printing or previewing, only.
  570. */
  571. void SetAlignment(wxTextAttrAlignment alignment);
  572. /**
  573. Sets the background colour.
  574. */
  575. void SetBackgroundColour(const wxColour& colBack);
  576. /**
  577. Sets the name of the font associated with the bullet symbol.
  578. Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
  579. */
  580. void SetBulletFont(const wxString& font);
  581. /**
  582. Sets the standard bullet name, applicable if the bullet style is
  583. wxTEXT_ATTR_BULLET_STYLE_STANDARD.
  584. See GetBulletName() for a list of supported names, and how
  585. to expand the range of supported types.
  586. */
  587. void SetBulletName(const wxString& name);
  588. /**
  589. Sets the bullet number.
  590. */
  591. void SetBulletNumber(int n);
  592. /**
  593. Sets the bullet style.
  594. The ::wxTextAttrBulletStyle enumeration values are all supported,
  595. except for wxTEXT_ATTR_BULLET_STYLE_BITMAP.
  596. */
  597. void SetBulletStyle(int style);
  598. /**
  599. Sets the bullet text, which could be a symbol, or (for example) cached
  600. outline text.
  601. */
  602. void SetBulletText(const wxString& text);
  603. /**
  604. Sets the character style name.
  605. */
  606. void SetCharacterStyleName(const wxString& name);
  607. /**
  608. Sets the flags determining which styles are being specified.
  609. The ::wxTextAttrFlags values can be passed in a bitlist.
  610. */
  611. void SetFlags(long flags);
  612. /**
  613. Sets the attributes for the given font.
  614. Note that wxTextAttr does not store an actual wxFont object.
  615. */
  616. void SetFont(const wxFont& font, int flags = wxTEXT_ATTR_FONT & ~wxTEXT_ATTR_FONT_PIXEL_SIZE);
  617. /**
  618. Sets the font encoding.
  619. */
  620. void SetFontEncoding(wxFontEncoding encoding);
  621. /**
  622. Sets the font face name.
  623. */
  624. void SetFontFaceName(const wxString& faceName);
  625. /**
  626. Sets the font family.
  627. */
  628. void SetFontFamily(wxFontFamily family);
  629. /**
  630. Sets the font size in points.
  631. */
  632. void SetFontSize(int pointSize);
  633. /**
  634. Sets the font size in points.
  635. */
  636. void SetFontPointSize(int pointSize);
  637. /**
  638. Sets the font size in pixels.
  639. */
  640. void SetFontPixelSize(int pixelSize);
  641. /**
  642. Sets the font style (normal, italic or slanted).
  643. */
  644. void SetFontStyle(wxFontStyle fontStyle);
  645. /**
  646. Sets the font underlining.
  647. */
  648. void SetFontUnderlined(bool underlined);
  649. /**
  650. Sets the font weight.
  651. */
  652. void SetFontWeight(wxFontWeight fontWeight);
  653. /**
  654. Sets the left indent and left subindent in tenths of a millimetre.
  655. The sub-indent is an offset from the left of the paragraph, and is used for all
  656. but the first line in a paragraph.
  657. A positive value will cause the first line to appear to the left
  658. of the subsequent lines, and a negative value will cause the first line to be
  659. indented relative to the subsequent lines.
  660. wxRichTextBuffer uses indentation to render a bulleted item.
  661. The left indent is the distance between the margin and the bullet.
  662. The content of the paragraph, including the first line, starts
  663. at leftMargin + leftSubIndent.
  664. So the distance between the left edge of the bullet and the
  665. left of the actual paragraph is leftSubIndent.
  666. */
  667. void SetLeftIndent(int indent, int subIndent = 0);
  668. /**
  669. Sets the line spacing. @a spacing is a multiple, where 10 means single-spacing,
  670. 15 means 1.5 spacing, and 20 means double spacing.
  671. The ::wxTextAttrLineSpacing values are defined for convenience.
  672. */
  673. void SetLineSpacing(int spacing);
  674. /**
  675. Sets the list style name.
  676. */
  677. void SetListStyleName(const wxString& name);
  678. /**
  679. Specifies the outline level. Zero represents normal text.
  680. At present, the outline level is not used, but may be used in future for
  681. determining list levels and for applications that need to store document
  682. structure information.
  683. */
  684. void SetOutlineLevel(int level);
  685. /**
  686. Specifies a page break before this paragraph.
  687. */
  688. void SetPageBreak(bool pageBreak = true);
  689. /**
  690. Sets the spacing after a paragraph, in tenths of a millimetre.
  691. */
  692. void SetParagraphSpacingAfter(int spacing);
  693. /**
  694. Sets the spacing before a paragraph, in tenths of a millimetre.
  695. */
  696. void SetParagraphSpacingBefore(int spacing);
  697. /**
  698. Sets the name of the paragraph style.
  699. */
  700. void SetParagraphStyleName(const wxString& name);
  701. /**
  702. Sets the right indent in tenths of a millimetre.
  703. */
  704. void SetRightIndent(int indent);
  705. /**
  706. Sets the tab stops, expressed in tenths of a millimetre.
  707. Each stop is measured from the left margin and therefore each value must be
  708. larger than the last.
  709. */
  710. void SetTabs(const wxArrayInt& tabs);
  711. /**
  712. Sets the text foreground colour.
  713. */
  714. void SetTextColour(const wxColour& colText);
  715. /**
  716. Sets the text effect bits of interest.
  717. You should also pass wxTEXT_ATTR_EFFECTS to SetFlags().
  718. See SetFlags() for further information.
  719. */
  720. void SetTextEffectFlags(int flags);
  721. /**
  722. Sets the text effects, a bit list of styles.
  723. The ::wxTextAttrEffects enumeration values can be used.
  724. Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
  725. wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
  726. wxTEXT_ATTR_EFFECT_CAPITALS capitalises text when displayed (leaving the case
  727. of the actual buffer text unchanged), and wxTEXT_ATTR_EFFECT_STRIKETHROUGH draws
  728. a line through text.
  729. To set effects, you should also pass wxTEXT_ATTR_EFFECTS to SetFlags(), and call
  730. SetTextEffectFlags() with the styles (taken from the above set) that you
  731. are interested in setting.
  732. */
  733. void SetTextEffects(int effects);
  734. /**
  735. Sets the URL for the content. Sets the wxTEXT_ATTR_URL style; content with this
  736. style causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
  737. generates a wxTextUrlEvent when the content is clicked.
  738. */
  739. void SetURL(const wxString& url);
  740. //@}
  741. /**
  742. Assignment from a wxTextAttr object.
  743. */
  744. void operator=(const wxTextAttr& attr);
  745. };
  746. /**
  747. @class wxTextCtrl
  748. A text control allows text to be displayed and edited.
  749. It may be single line or multi-line. Notice that a lot of methods of the
  750. text controls are found in the base wxTextEntry class which is a common
  751. base class for wxTextCtrl and other controls using a single line text entry
  752. field (e.g. wxComboBox).
  753. @beginStyleTable
  754. @style{wxTE_PROCESS_ENTER}
  755. The control will generate the event @c wxEVT_TEXT_ENTER
  756. (otherwise pressing Enter key is either processed internally by the
  757. control or used for navigation between dialog controls).
  758. @style{wxTE_PROCESS_TAB}
  759. The control will receive @c wxEVT_CHAR events for TAB pressed -
  760. normally, TAB is used for passing to the next control in a dialog
  761. instead. For the control created with this style, you can still use
  762. Ctrl-Enter to pass to the next control from the keyboard.
  763. @style{wxTE_MULTILINE}
  764. The text control allows multiple lines. If this style is not
  765. specified, line break characters should not be used in the controls
  766. value.
  767. @style{wxTE_PASSWORD}
  768. The text will be echoed as asterisks.
  769. @style{wxTE_READONLY}
  770. The text will not be user-editable.
  771. @style{wxTE_RICH}
  772. Use rich text control under Win32, this allows to have more than
  773. 64KB of text in the control even under Win9x. This style is ignored
  774. under other platforms.
  775. @style{wxTE_RICH2}
  776. Use rich text control version 2.0 or 3.0 under Win32, this style is
  777. ignored under other platforms
  778. @style{wxTE_AUTO_URL}
  779. Highlight the URLs and generate the wxTextUrlEvents when mouse
  780. events occur over them. This style is only supported for wxTE_RICH
  781. Win32 and multi-line wxGTK2 text controls.
  782. @style{wxTE_NOHIDESEL}
  783. By default, the Windows text control doesn't show the selection
  784. when it doesn't have focus - use this style to force it to always
  785. show it. It doesn't do anything under other platforms.
  786. @style{wxHSCROLL}
  787. A horizontal scrollbar will be created and used, so that text won't
  788. be wrapped. No effect under wxGTK1.
  789. @style{wxTE_NO_VSCROLL}
  790. For multiline controls only: vertical scrollbar will never be
  791. created. This limits the amount of text which can be entered into
  792. the control to what can be displayed in it under MSW but not under
  793. GTK2. Currently not implemented for the other platforms.
  794. @style{wxTE_LEFT}
  795. The text in the control will be left-justified (default).
  796. @style{wxTE_CENTRE}
  797. The text in the control will be centered (currently wxMSW and
  798. wxGTK2 only).
  799. @style{wxTE_RIGHT}
  800. The text in the control will be right-justified (currently wxMSW
  801. and wxGTK2 only).
  802. @style{wxTE_DONTWRAP}
  803. Same as wxHSCROLL style: don't wrap at all, show horizontal
  804. scrollbar instead.
  805. @style{wxTE_CHARWRAP}
  806. Wrap the lines too long to be shown entirely at any position
  807. (wxUniv and wxGTK2 only).
  808. @style{wxTE_WORDWRAP}
  809. Wrap the lines too long to be shown entirely at word boundaries
  810. (wxUniv and wxGTK2 only).
  811. @style{wxTE_BESTWRAP}
  812. Wrap the lines at word boundaries or at any other character if
  813. there are words longer than the window width (this is the default).
  814. @style{wxTE_CAPITALIZE}
  815. On PocketPC and Smartphone, causes the first letter to be
  816. capitalized.
  817. @endStyleTable
  818. Note that alignment styles (wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT) can be
  819. changed dynamically after control creation on wxMSW and wxGTK. wxTE_READONLY,
  820. wxTE_PASSWORD and wrapping styles can be dynamically changed under wxGTK but
  821. not wxMSW. The other styles can be only set during control creation.
  822. @section textctrl_text_format wxTextCtrl Text Format
  823. The multiline text controls always store the text as a sequence of lines
  824. separated by @c '\\n' characters, i.e. in the Unix text format even on
  825. non-Unix platforms. This allows the user code to ignore the differences
  826. between the platforms but at a price: the indices in the control such as
  827. those returned by GetInsertionPoint() or GetSelection() can @b not be used
  828. as indices into the string returned by GetValue() as they're going to be
  829. slightly off for platforms using @c "\\r\\n" as separator (as Windows
  830. does).
  831. Instead, if you need to obtain a substring between the 2 indices obtained
  832. from the control with the help of the functions mentioned above, you should
  833. use GetRange(). And the indices themselves can only be passed to other
  834. methods, for example SetInsertionPoint() or SetSelection().
  835. To summarize: never use the indices returned by (multiline) wxTextCtrl as
  836. indices into the string it contains, but only as arguments to be passed
  837. back to the other wxTextCtrl methods. This problem doesn't arise for
  838. single-line platforms however where the indices in the control do
  839. correspond to the positions in the value string.
  840. @section textctrl_styles wxTextCtrl Styles.
  841. Multi-line text controls support styling, i.e. provide a possibility to set
  842. colours and font for individual characters in it (note that under Windows
  843. @c wxTE_RICH style is required for style support). To use the styles you
  844. can either call SetDefaultStyle() before inserting the text or call
  845. SetStyle() later to change the style of the text already in the control
  846. (the first solution is much more efficient).
  847. In either case, if the style doesn't specify some of the attributes (for
  848. example you only want to set the text colour but without changing the font
  849. nor the text background), the values of the default style will be used for
  850. them. If there is no default style, the attributes of the text control
  851. itself are used.
  852. So the following code correctly describes what it does: the second call to
  853. SetDefaultStyle() doesn't change the text foreground colour (which stays
  854. red) while the last one doesn't change the background colour (which stays
  855. grey):
  856. @code
  857. text->SetDefaultStyle(wxTextAttr(*wxRED));
  858. text->AppendText("Red text\n");
  859. text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
  860. text->AppendText("Red on grey text\n");
  861. text->SetDefaultStyle(wxTextAttr(*wxBLUE);
  862. text->AppendText("Blue on grey text\n");
  863. @endcode
  864. @section textctrl_cpp_streams wxTextCtrl and C++ Streams
  865. This class multiply-inherits from @c std::streambuf (except for some really
  866. old compilers using non-standard iostream library), allowing code such as
  867. the following:
  868. @code
  869. wxTextCtrl *control = new wxTextCtrl(...);
  870. ostream stream(control)
  871. stream << 123.456 << " some text\n";
  872. stream.flush();
  873. @endcode
  874. Note that even if your compiler doesn't support this (the symbol
  875. @c wxHAS_TEXT_WINDOW_STREAM has value of 0 then) you can still use
  876. wxTextCtrl itself in a stream-like manner:
  877. @code
  878. wxTextCtrl *control = new wxTextCtrl(...);
  879. *control << 123.456 << " some text\n";
  880. @endcode
  881. However the possibility to create an ostream associated with wxTextCtrl may
  882. be useful if you need to redirect the output of a function taking an
  883. ostream as parameter to a text control.
  884. Another commonly requested need is to redirect @c std::cout to the text
  885. control. This may be done in the following way:
  886. @code
  887. #include <iostream>
  888. wxTextCtrl *control = new wxTextCtrl(...);
  889. std::streambuf *sbOld = std::cout.rdbuf();
  890. std::cout.rdbuf(control);
  891. // use cout as usual, the output appears in the text control
  892. ...
  893. std::cout.rdbuf(sbOld);
  894. @endcode
  895. But wxWidgets provides a convenient class to make it even simpler so
  896. instead you may just do
  897. @code
  898. #include <iostream>
  899. wxTextCtrl *control = new wxTextCtrl(...);
  900. wxStreamToTextRedirector redirect(control);
  901. // all output to cout goes into the text control until the exit from
  902. // current scope
  903. @endcode
  904. See wxStreamToTextRedirector for more details.
  905. @section textctrl_event_handling Event Handling.
  906. The following commands are processed by default event handlers in
  907. wxTextCtrl: @c wxID_CUT, @c wxID_COPY, @c wxID_PASTE, @c wxID_UNDO, @c
  908. wxID_REDO. The associated UI update events are also processed
  909. automatically, when the control has the focus.
  910. @beginEventEmissionTable{wxCommandEvent}
  911. @event{EVT_TEXT(id, func)}
  912. Respond to a @c wxEVT_TEXT event, generated when the text
  913. changes. Notice that this event will be sent when the text controls
  914. contents changes -- whether this is due to user input or comes from the
  915. program itself (for example, if wxTextCtrl::SetValue() is called); see
  916. wxTextCtrl::ChangeValue() for a function which does not send this event.
  917. This event is however not sent during the control creation.
  918. @event{EVT_TEXT_ENTER(id, func)}
  919. Respond to a @c wxEVT_TEXT_ENTER event, generated when enter is
  920. pressed in a text control which must have wxTE_PROCESS_ENTER style for
  921. this event to be generated.
  922. @event{EVT_TEXT_URL(id, func)}
  923. A mouse event occurred over an URL in the text control (wxMSW and
  924. wxGTK2 only currently).
  925. @event{EVT_TEXT_MAXLEN(id, func)}
  926. This event is generated when the user tries to enter more text into the
  927. control than the limit set by wxTextCtrl::SetMaxLength(), see its description.
  928. @endEventTable
  929. @library{wxcore}
  930. @category{ctrl}
  931. @appearance{textctrl}
  932. @see wxTextCtrl::Create, wxValidator
  933. */
  934. class wxTextCtrl : public wxControl,
  935. public wxTextEntry
  936. {
  937. public:
  938. /**
  939. Default ctor.
  940. */
  941. wxTextCtrl();
  942. /**
  943. Constructor, creating and showing a text control.
  944. @param parent
  945. Parent window. Should not be @NULL.
  946. @param id
  947. Control identifier. A value of -1 denotes a default value.
  948. @param value
  949. Default text value.
  950. @param pos
  951. Text control position.
  952. @param size
  953. Text control size.
  954. @param style
  955. Window style. See wxTextCtrl.
  956. @param validator
  957. Window validator.
  958. @param name
  959. Window name.
  960. @remarks
  961. The horizontal scrollbar (wxHSCROLL style flag) will only be
  962. created for multi-line text controls. Without a horizontal
  963. scrollbar, text lines that don't fit in the control's size will be
  964. wrapped (but no newline character is inserted).
  965. Single line controls don't have a horizontal scrollbar, the text is
  966. automatically scrolled so that the insertion point is always visible.
  967. @see Create(), wxValidator
  968. */
  969. wxTextCtrl(wxWindow* parent, wxWindowID id,
  970. const wxString& value = wxEmptyString,
  971. const wxPoint& pos = wxDefaultPosition,
  972. const wxSize& size = wxDefaultSize,
  973. long style = 0,
  974. const wxValidator& validator = wxDefaultValidator,
  975. const wxString& name = wxTextCtrlNameStr);
  976. /**
  977. Destructor, destroying the text control.
  978. */
  979. virtual ~wxTextCtrl();
  980. /**
  981. Creates the text control for two-step construction.
  982. This method should be called if the default constructor was used for
  983. the control creation. Its parameters have the same meaning as for the
  984. non-default constructor.
  985. */
  986. bool Create(wxWindow* parent, wxWindowID id,
  987. const wxString& value = wxEmptyString,
  988. const wxPoint& pos = wxDefaultPosition,
  989. const wxSize& size = wxDefaultSize, long style = 0,
  990. const wxValidator& validator = wxDefaultValidator,
  991. const wxString& name = wxTextCtrlNameStr);
  992. /**
  993. Resets the internal modified flag as if the current changes had been
  994. saved.
  995. */
  996. virtual void DiscardEdits();
  997. /**
  998. This function inserts into the control the character which would have
  999. been inserted if the given key event had occurred in the text control.
  1000. The @a event object should be the same as the one passed to @c EVT_KEY_DOWN
  1001. handler previously by wxWidgets. Please note that this function doesn't
  1002. currently work correctly for all keys under any platform but MSW.
  1003. @return
  1004. @true if the event resulted in a change to the control, @false otherwise.
  1005. */
  1006. virtual bool EmulateKeyPress(const wxKeyEvent& event);
  1007. /**
  1008. Returns the style currently used for the new text.
  1009. @see SetDefaultStyle()
  1010. */
  1011. virtual const wxTextAttr& GetDefaultStyle() const;
  1012. /**
  1013. Gets the length of the specified line, not including any trailing
  1014. newline character(s).
  1015. @param lineNo
  1016. Line number (starting from zero).
  1017. @return
  1018. The length of the line, or -1 if @a lineNo was invalid.
  1019. */
  1020. virtual int GetLineLength(long lineNo) const;
  1021. /**
  1022. Returns the contents of a given line in the text control, not including
  1023. any trailing newline character(s).
  1024. @param lineNo
  1025. The line number, starting from zero.
  1026. @return
  1027. The contents of the line.
  1028. */
  1029. virtual wxString GetLineText(long lineNo) const;
  1030. /**
  1031. Returns the number of lines in the text control buffer.
  1032. The returned number is the number of logical lines, i.e. just the count
  1033. of the number of newline characters in the control + 1, for wxGTK and
  1034. wxOSX/Cocoa ports while it is the number of physical lines, i.e. the
  1035. count of lines actually shown in the control, in wxMSW and wxOSX/Carbon.
  1036. Because of this discrepancy, it is not recommended to use this function.
  1037. @remarks
  1038. Note that even empty text controls have one line (where the
  1039. insertion point is), so GetNumberOfLines() never returns 0.
  1040. */
  1041. virtual int GetNumberOfLines() const;
  1042. /**
  1043. Returns the style at this position in the text control.
  1044. Not all platforms support this function.
  1045. @return
  1046. @true on success, @false if an error occurred (this may also mean
  1047. that the styles are not supported under this platform).
  1048. @see SetStyle(), wxTextAttr
  1049. */
  1050. virtual bool GetStyle(long position, wxTextAttr& style);
  1051. /**
  1052. Finds the position of the character at the specified point.
  1053. If the return code is not @c wxTE_HT_UNKNOWN the row and column of the
  1054. character closest to this position are returned, otherwise the output
  1055. parameters are not modified.
  1056. Please note that this function is currently only implemented in wxUniv,
  1057. wxMSW and wxGTK2 ports and always returns @c wxTE_HT_UNKNOWN in the
  1058. other ports.
  1059. @beginWxPerlOnly
  1060. In wxPerl this function takes only the @a pt argument and
  1061. returns a 3-element list (result, col, row).
  1062. @endWxPerlOnly
  1063. @param pt
  1064. The position of the point to check, in window device coordinates.
  1065. @param pos
  1066. Receives the position of the character at the given position. May
  1067. be @NULL.
  1068. @see PositionToXY(), XYToPosition()
  1069. */
  1070. wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
  1071. /**
  1072. Finds the row and column of the character at the specified point.
  1073. If the return code is not @c wxTE_HT_UNKNOWN the row and column of the
  1074. character closest to this position are returned, otherwise the output
  1075. parameters are not modified.
  1076. Please note that this function is currently only implemented in wxUniv,
  1077. wxMSW and wxGTK2 ports and always returns @c wxTE_HT_UNKNOWN in the
  1078. other ports.
  1079. @beginWxPerlOnly
  1080. In wxPerl this function takes only the @a pt argument and
  1081. returns a 3-element list (result, col, row).
  1082. @endWxPerlOnly
  1083. @param pt
  1084. The position of the point to check, in window device coordinates.
  1085. @param col
  1086. Receives the column of the character at the given position. May be
  1087. @NULL.
  1088. @param row
  1089. Receives the row of the character at the given position. May be
  1090. @NULL.
  1091. @see PositionToXY(), XYToPosition()
  1092. */
  1093. wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
  1094. wxTextCoord *col,
  1095. wxTextCoord *row) const;
  1096. /**
  1097. Returns @true if the text has been modified by user.
  1098. Note that calling SetValue() doesn't make the control modified.
  1099. @see MarkDirty()
  1100. */
  1101. virtual bool IsModified() const;
  1102. /**
  1103. Returns @true if this is a multi line edit control and @false otherwise.
  1104. @see IsSingleLine()
  1105. */
  1106. bool IsMultiLine() const;
  1107. /**
  1108. Returns @true if this is a single line edit control and @false otherwise.
  1109. @see IsSingleLine(), IsMultiLine()
  1110. */
  1111. bool IsSingleLine() const;
  1112. /**
  1113. Loads and displays the named file, if it exists.
  1114. @param filename
  1115. The filename of the file to load.
  1116. @param fileType
  1117. The type of file to load. This is currently ignored in wxTextCtrl.
  1118. @return
  1119. @true if successful, @false otherwise.
  1120. */
  1121. bool LoadFile(const wxString& filename,
  1122. int fileType = wxTEXT_TYPE_ANY);
  1123. /**
  1124. Mark text as modified (dirty).
  1125. @see IsModified()
  1126. */
  1127. virtual void MarkDirty();
  1128. /**
  1129. This event handler function implements default drag and drop behaviour,
  1130. which is to load the first dropped file into the control.
  1131. @param event
  1132. The drop files event.
  1133. @remarks This is not implemented on non-Windows platforms.
  1134. @see wxDropFilesEvent
  1135. */
  1136. void OnDropFiles(wxDropFilesEvent& event);
  1137. /**
  1138. Converts given position to a zero-based column, line number pair.
  1139. @param pos
  1140. Position.
  1141. @param x
  1142. Receives zero based column number.
  1143. @param y
  1144. Receives zero based line number.
  1145. @return
  1146. @true on success, @false on failure (most likely due to a too large
  1147. position parameter).
  1148. @beginWxPerlOnly
  1149. In wxPerl this function takes only the @a pos argument and
  1150. returns a 2-element list (x, y).
  1151. @endWxPerlOnly
  1152. @see XYToPosition()
  1153. */
  1154. virtual bool PositionToXY(long pos, long* x, long* y) const;
  1155. /**
  1156. Converts given text position to client coordinates in pixels.
  1157. This function allows to find where is the character at the given
  1158. position displayed in the text control.
  1159. @onlyfor{wxmsw,wxgtk}. Additionally, wxGTK only implements this method
  1160. for multiline controls and ::wxDefaultPosition is always returned for
  1161. the single line ones.
  1162. @param pos
  1163. Text position in 0 to GetLastPosition() range (inclusive).
  1164. @return
  1165. On success returns a wxPoint which contains client coordinates for
  1166. the given position in pixels, otherwise returns ::wxDefaultPosition.
  1167. @since 2.9.3
  1168. @see XYToPosition(), PositionToXY()
  1169. */
  1170. wxPoint PositionToCoords(long pos) const;
  1171. /**
  1172. Saves the contents of the control in a text file.
  1173. @param filename
  1174. The name of the file in which to save the text.
  1175. @param fileType
  1176. The type of file to save. This is currently ignored in wxTextCtrl.
  1177. @return
  1178. @true if the operation was successful, @false otherwise.
  1179. */
  1180. bool SaveFile(const wxString& filename = wxEmptyString,
  1181. int fileType = wxTEXT_TYPE_ANY);
  1182. /**
  1183. Changes the default style to use for the new text which is going to be
  1184. added to the control using WriteText() or AppendText().
  1185. If either of the font, foreground, or background colour is not set in
  1186. @a style, the values of the previous default style are used for them.
  1187. If the previous default style didn't set them neither, the global font
  1188. or colours of the text control itself are used as fall back.
  1189. However if the @a style parameter is the default wxTextAttr, then the default
  1190. style is just reset (instead of being combined with the new style which
  1191. wouldn't change it at all).
  1192. @param style
  1193. The style for the new text.
  1194. @return
  1195. @true on success, @false if an error occurred (this may also mean
  1196. that the styles are not supported under this platform).
  1197. @see GetDefaultStyle()
  1198. */
  1199. virtual bool SetDefaultStyle(const wxTextAttr& style);
  1200. /**
  1201. Marks the control as being modified by the user or not.
  1202. @see MarkDirty(), DiscardEdits()
  1203. */
  1204. void SetModified(bool modified);
  1205. /**
  1206. Changes the style of the given range.
  1207. If any attribute within @a style is not set, the corresponding
  1208. attribute from GetDefaultStyle() is used.
  1209. @param start
  1210. The start of the range to change.
  1211. @param end
  1212. The end of the range to change.
  1213. @param style
  1214. The new style for the range.
  1215. @return
  1216. @true on success, @false if an error occurred (this may also mean
  1217. that the styles are not supported under this platform).
  1218. @see GetStyle(), wxTextAttr
  1219. */
  1220. virtual bool SetStyle(long start, long end, const wxTextAttr& style);
  1221. /**
  1222. Makes the line containing the given position visible.
  1223. @param pos
  1224. The position that should be visible.
  1225. */
  1226. virtual void ShowPosition(long pos);
  1227. /**
  1228. Converts the given zero based column and line number to a position.
  1229. @param x
  1230. The column number.
  1231. @param y
  1232. The line number.
  1233. @return
  1234. The position value, or -1 if x or y was invalid.
  1235. */
  1236. virtual long XYToPosition(long x, long y) const;
  1237. //@{
  1238. /**
  1239. Operator definitions for appending to a text control.
  1240. These operators can be used as with the standard C++ streams, for
  1241. example:
  1242. @code
  1243. wxTextCtrl *wnd = new wxTextCtrl(my_frame);
  1244. (*wnd) << "Welcome to text control number " << 1 << ".\n";
  1245. @endcode
  1246. */
  1247. wxTextCtrl& operator<<(const wxString& s);
  1248. wxTextCtrl& operator<<(int i);
  1249. wxTextCtrl& operator<<(long i);
  1250. wxTextCtrl& operator<<(float f);
  1251. wxTextCtrl& operator<<(double d);
  1252. wxTextCtrl& operator<<(char c);
  1253. wxTextCtrl& operator<<(wchar_t c);
  1254. //@}
  1255. };
  1256. wxEventType wxEVT_TEXT;
  1257. wxEventType wxEVT_TEXT_ENTER;
  1258. wxEventType wxEVT_TEXT_URL;
  1259. wxEventType wxEVT_TEXT_MAXLEN;
  1260. class wxTextUrlEvent : public wxCommandEvent
  1261. {
  1262. public:
  1263. wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
  1264. long start, long end);
  1265. wxTextUrlEvent(const wxTextUrlEvent& event);
  1266. // get the mouse event which happened over the URL
  1267. const wxMouseEvent& GetMouseEvent() const;
  1268. // get the start of the URL
  1269. long GetURLStart() const;
  1270. // get the end of the URL
  1271. long GetURLEnd() const;
  1272. virtual wxEvent *Clone() const;
  1273. };
  1274. /**
  1275. @class wxStreamToTextRedirector
  1276. This class can be used to (temporarily) redirect all output sent to a C++
  1277. ostream object to a wxTextCtrl instead.
  1278. @note
  1279. Some compilers and/or build configurations don't support multiply
  1280. inheriting wxTextCtrl from @c std::streambuf in which case this class is
  1281. not compiled in.
  1282. You also must have @c wxUSE_STD_IOSTREAM option on (i.e. set to 1) in your
  1283. @c setup.h to be able to use it. Under Unix, specify @c --enable-std_iostreams
  1284. switch when running configure for this.
  1285. Example of usage:
  1286. @code
  1287. using namespace std;
  1288. wxTextCtrl* text = new wxTextCtrl(...);
  1289. {
  1290. wxStreamToTextRedirector redirect(text);
  1291. // this goes to the text control
  1292. cout << "Hello, text!" << endl;
  1293. }
  1294. // this goes somewhere else, presumably to stdout
  1295. cout << "Hello, console!" << endl;
  1296. @endcode
  1297. @library{wxcore}
  1298. @category{logging}
  1299. @see wxTextCtrl
  1300. */
  1301. class wxStreamToTextRedirector
  1302. {
  1303. public:
  1304. /**
  1305. The constructor starts redirecting output sent to @a ostr or @a cout for
  1306. the default parameter value to the text control @a text.
  1307. @param text
  1308. The text control to append output too, must be non-@NULL
  1309. @param ostr
  1310. The C++ stream to redirect, cout is used if it is @NULL
  1311. */
  1312. wxStreamToTextRedirector(wxTextCtrl *text, ostream* ostr);
  1313. /**
  1314. When a wxStreamToTextRedirector object is destroyed, the redirection is ended
  1315. and any output sent to the C++ ostream which had been specified at the time of
  1316. the object construction will go to its original destination.
  1317. */
  1318. ~wxStreamToTextRedirector();
  1319. };