/src/wrappers/gtk/examples/gtk-demo/textview.e

http://github.com/tybor/Liberty · Specman e · 766 lines · 219 code · 133 blank · 414 comment · 5 complexity · 0695f9a0d20efe13da41602e3692f12b MD5 · raw file

  1. indexing
  2. description: "Text Widget/Multiple Views"
  3. long_description: "[
  4. The GtkTextView widget displays a GtkTextBuffer. One GtkTextBuffer
  5. can be displayed by multiple GtkTextViews. This demo has two views
  6. displaying a single buffer, and shows off the widget's text
  7. formatting features.
  8. ]"
  9. copyright: "[
  10. Copyright (C) 2006 Paolo Redaelli, GTK+ team
  11. This library is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU Lesser General Public License
  13. as published by the Free Software Foundation; either version 2.1 of
  14. the License, or (at your option) any later version.
  15. This library is distributed in the hope that it will be useful, but
  16. WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Lesser General Public License for more details.
  19. You should have received a copy of the GNU Lesser General Public
  20. License along with this library; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. 02110-1301 USA
  23. ]"
  24. class TEXTVIEW
  25. insert
  26. GTK
  27. PANGO_CONSTANTS
  28. PANGO_SCALES
  29. PANGO_WEIGHT
  30. PANGO_STYLE
  31. creation make
  32. feature -- Widgets
  33. buffer: GTK_TEXT_BUFFER
  34. feature
  35. make is
  36. do
  37. gtk.initialize_gtk
  38. create buffer.make
  39. end
  40. feature -- Callbacks
  41. -- easter_egg_callback (GtkWidget *button, Gpointer data);
  42. feature -- constants
  43. gray50_width: INTEGER is 2
  44. gray50_height: INTEGER is 2
  45. -- static char gray50_bits[] = {0x02, 0x01}; ???
  46. feature -- tags
  47. heading: GTK_TEXT_TAG is
  48. once
  49. create Result.with_name("heading")
  50. Result.set_weight (pango_weight_bold)
  51. Result.set_size (15 * pango_scale)
  52. end
  53. italic: GTK_TEXT_TAG is
  54. once
  55. create Result.with_name("italic")
  56. Result.set_style (pango_style_italic)
  57. end
  58. bold: GTK_TEXT_TAG is
  59. once
  60. create Result.with_name("bold")
  61. Result.set_weight ( pango_weight_bold )
  62. end
  63. big: GTK_TEXT_TAG is
  64. once
  65. create Result.with_name("big")
  66. Result.set_size (20* 1024 -- i.e.: pango_scale ... TODO:
  67. )
  68. end
  69. xx_small: GTK_TEXT_TAG is
  70. once
  71. create Result.with_name("xx_small")
  72. Result.set_scale ( pango_scale_xx_small )
  73. end
  74. x_large: GTK_TEXT_TAG is
  75. once
  76. create Result.with_name("x_large")
  77. -- "Extra-large", buffer.create_tag ("x-large", -- << [ "scale",
  78. -- PANGO_SCALE_X_LARGE ] >> );
  79. end
  80. monospace: GTK_TEXT_TAG is
  81. once
  82. create Result.with_name("monospace")
  83. -- gtk_text_buffer_create_tag (buffer, "monospace",
  84. -- "family", "monospace", NULL);
  85. end
  86. blue_foreground: GTK_TEXT_TAG is
  87. once
  88. create Result.with_name("blue_foreground")
  89. -- gtk_text_buffer_create_tag (buffer, "blue_foreground",
  90. -- "foreground", "blue", NULL);
  91. end
  92. red_background: GTK_TEXT_TAG is
  93. once
  94. create Result.with_name("red_background")
  95. -- gtk_text_buffer_create_tag (buffer, "red_background",
  96. -- "background", "red", NULL);
  97. end
  98. background_stipple: GTK_TEXT_TAG is
  99. once
  100. create Result.with_name("background_stipple")
  101. -- stipple = gdk_bitmap_create_from_data (NULL,
  102. -- gray50_bits, gray50_width,
  103. -- gray50_height);
  104. -- gtk_text_buffer_create_tag (buffer, "background_stipple",
  105. -- "background_stipple", stipple, NULL);
  106. end
  107. foreground_stipple: GTK_TEXT_TAG is
  108. once
  109. create Result.with_name("foreground_stipple")
  110. -- gtk_text_buffer_create_tag (buffer, "foreground_stipple",
  111. -- "foreground_stipple", stipple, NULL);
  112. -- g_object_unref (stipple);
  113. -- gtk_text_buffer_create_tag (buffer, "big_gap_before_line",
  114. end
  115. big_gap_before_line: GTK_TEXT_TAG is
  116. once
  117. create Result.with_name("big_gap_before_line")
  118. -- gtk_text_buffer_create_tag (buffer, "big_gap_before_line",
  119. -- "pixels_above_lines", 30, NULL);
  120. end
  121. big_gap_after_line: GTK_TEXT_TAG is
  122. once
  123. create Result.with_name("big_gap_after_line")
  124. -- gtk_text_buffer_create_tag (buffer, "big_gap_after_line",
  125. -- "pixels_below_lines", 30, NULL);
  126. end
  127. double_spaced_line: GTK_TEXT_TAG is
  128. once
  129. create Result.with_name("double_spaced_line")
  130. -- gtk_text_buffer_create_tag (buffer, "double_spaced_line",
  131. -- "pixels_inside_wrap", 10, NULL);
  132. end
  133. not_editable: GTK_TEXT_TAG is
  134. once
  135. create Result.with_name("not_editable")
  136. -- gtk_text_buffer_create_tag (buffer, "not_editable",
  137. -- "editable", FALSE, NULL);
  138. end
  139. word_wrap: GTK_TEXT_TAG is
  140. once
  141. create Result.with_name("word_wrap")
  142. -- gtk_text_buffer_create_tag (buffer, "word_wrap",
  143. -- "wrap_mode", GTK_WRAP_WORD, NULL);
  144. end
  145. char_wrap: GTK_TEXT_TAG is
  146. once
  147. create Result.with_name("char_wrap")
  148. -- gtk_text_buffer_create_tag (buffer, "char_wrap",
  149. -- "wrap_mode", GTK_WRAP_CHAR, NULL);
  150. end
  151. no_wrap: GTK_TEXT_TAG is
  152. once
  153. create Result.with_name("no_wrap")
  154. -- gtk_text_buffer_create_tag (buffer, "no_wrap",
  155. -- "wrap_mode", GTK_WRAP_NONE, NULL);
  156. end
  157. center: GTK_TEXT_TAG is
  158. once
  159. create Result.with_name("center")
  160. -- gtk_text_buffer_create_tag (buffer, "center",
  161. -- "justification", GTK_JUSTIFY_CENTER, NULL);
  162. end
  163. right_justify: GTK_TEXT_TAG is
  164. once
  165. create Result.with_name("right_justify")
  166. -- gtk_text_buffer_create_tag (buffer, "right_justify",
  167. -- "justification", GTK_JUSTIFY_RIGHT, NULL);
  168. end
  169. wide_margins: GTK_TEXT_TAG is
  170. once
  171. create Result.with_name("wide_margins")
  172. -- gtk_text_buffer_create_tag (buffer, "wide_margins",
  173. -- "left_margin", 50, "right_margin", 50,
  174. -- NULL);
  175. end
  176. strikethrough: GTK_TEXT_TAG is
  177. once
  178. create Result.with_name("strikethrough")
  179. -- gtk_text_buffer_create_tag (buffer, "strikethrough",
  180. -- "strikethrough", TRUE, NULL);
  181. end
  182. underline: GTK_TEXT_TAG is
  183. once
  184. create Result.with_name("underline")
  185. -- gtk_text_buffer_create_tag (buffer, "underline",
  186. -- "underline", PANGO_UNDERLINE_SINGLE, NULL);
  187. end
  188. double_underline: GTK_TEXT_TAG is
  189. once
  190. create Result.with_name("double_underline")
  191. -- gtk_text_buffer_create_tag (buffer, "double_underline",
  192. -- "underline", PANGO_UNDERLINE_DOUBLE, NULL); end
  193. end
  194. superscript: GTK_TEXT_TAG is
  195. once
  196. create Result.with_name("superscript")
  197. -- gtk_text_buffer_create_tag (buffer, "superscript",
  198. -- "rise", 10 * PANGO_SCALE, /* 10 pixels */
  199. -- "size", 8 * PANGO_SCALE, /* 8 points */
  200. -- NULL);
  201. end
  202. subscript: GTK_TEXT_TAG is
  203. once
  204. create Result.with_name("subscript")
  205. -- gtk_text_buffer_create_tag (buffer, "subscript",
  206. -- "rise", -10 * PANGO_SCALE, /* 10 pixels */
  207. -- "size", 8 * PANGO_SCALE, /* 8 points */
  208. -- NULL);
  209. end
  210. rtl_quote: GTK_TEXT_TAG is
  211. once
  212. create Result.with_name("rtl_quote")
  213. -- gtk_text_buffer_create_tag (buffer, "rtl_quote",
  214. -- gtk_text_buffer_create_tag (buffer, "rtl_quote",
  215. -- "wrap_mode", GTK_WRAP_WORD,
  216. -- "direction", GTK_TEXT_DIR_RTL,
  217. -- "indent", 30,
  218. -- "left_margin", 20,
  219. -- "right_margin", 20,
  220. -- NULL);
  221. -- }
  222. end
  223. tags: GTK_TEXT_TAG_TABLE is
  224. -- A bunch of tags. Note that it's also possible to create
  225. -- tags with `GTK_TEXT_TAG.make' then add them to the tag
  226. -- table for the buffer, `GTK_TEXT_BUFFER.create_tag' is just
  227. -- a convenience function. Also note that you don't have to
  228. -- give tags a name; pass Void for the name to create an
  229. -- anonymous tag.
  230. --In any real app, another useful optimization would be to
  231. --create a GtkTextTagTable in advance, and reuse the same tag
  232. --table for all the buffers with the same tag set, instead of
  233. --creating new copies of the same tags for every buffer.
  234. -- Tags are assigned default priorities in order of addition
  235. -- to the tag table. That is, tags created later that affect
  236. -- the same text property affected by an earlier tag will
  237. -- override the earlier tag. You can modify tag priorities
  238. -- with gtk_text_tag_set_priority().
  239. local stipple: GDK_BITMAP;
  240. do
  241. create Result.make
  242. Result.add (heading)
  243. Result.add (italic)
  244. Result.add (bold)
  245. Result.add (big)
  246. Result.add (xx_small)
  247. Result.add (x_large)
  248. Result.add (monospace)
  249. Result.add (blue_foreground)
  250. Result.add (red_background)
  251. Result.add (background_stipple)
  252. Result.add (foreground_stipple)
  253. Result.add (big_gap_before_line)
  254. Result.add (big_gap_after_line)
  255. Result.add (double_spaced_line)
  256. Result.add (not_editable)
  257. Result.add (word_wrap)
  258. Result.add (char_wrap)
  259. Result.add (no_wrap)
  260. Result.add (center)
  261. Result.add (right_justify)
  262. Result.add (wide_margins)
  263. Result.add (strikethrough)
  264. Result.add (underline)
  265. Result.add (double_underline)
  266. Result.add (superscript)
  267. Result.add (subscript)
  268. Result.add (rtl_quote)
  269. end
  270. pixbuf: GDK_PIXBUF is
  271. local
  272. filename: STRING
  273. do
  274. -- `demo_find_file' looks in the the current directory first,
  275. -- so you can run gtk-demo without installing GTK, then looks
  276. -- in the location where the file is installed.
  277. filename := "gtk-logo-rgb.gif" -- demo_find_file ("gtk-logo-rgb.gif", Void)
  278. if filename /= Void then
  279. create Result.from_file (filename)
  280. if Result /= Void then
  281. -- g_printerr ("Failed to load image file gtk-logo-rgb.gif\n")
  282. -- exit (1)
  283. else
  284. -- scaled: GDK_PIXBUF;
  285. -- TODO: scaled := pixbuf.scale_simple (32, 32, gdk_interp_bilinear)
  286. -- pixbuf.unref
  287. -- TODO: check if the previous command is unnecessary,
  288. -- since the following instruction will make former pixbuf
  289. -- unreachable, disposable and collectable by the garbage
  290. -- collector. Paolo 2006-07-05
  291. -- pixbuf := scaled
  292. end
  293. end
  294. end
  295. insert_text is
  296. local
  297. iter, start, end_iter: GTK_TEXT_ITER;
  298. anchor: GTK_TEXT_CHILD_ANCHOR;
  299. do
  300. -- get start of buffer; each insertion will revalidate the
  301. -- iterator to point to just after the inserted text.
  302. iter := buffer.iter_at_offset(0)
  303. buffer.insert_at (iter, "The text widget can display text with all %
  304. %kinds of nifty attributes. It also supports %
  305. %multiple views of the same buffer; this demo %
  306. %is showing the same buffer in two places.\n\n")
  307. buffer.insert_with_tags (iter, "Font styles. ", <<heading>>)
  308. buffer.insert_at (iter, "For example, you can have ")
  309. buffer.insert_with_tags_by_name (iter, "italic", <<"italic">>)
  310. buffer.insert_at (iter, ", ")
  311. --buffer.insert_with_tags_by_name (iter, "bold", <<"bold">>)
  312. -- gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
  313. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  314. -- "monospace (typewriter)", -1,
  315. -- "monospace", NULL);
  316. -- gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
  317. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  318. -- "big", -1,
  319. -- "big", NULL);
  320. -- gtk_text_buffer_insert (buffer, &iter, " text. ", -1);
  321. -- gtk_text_buffer_insert (buffer, &iter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ", -1);
  322. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  323. -- "xx-small", -1,
  324. -- "xx-small", NULL);
  325. -- gtk_text_buffer_insert (buffer, &iter, " or ", -1);
  326. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  327. -- "x-large", -1,
  328. -- "x-large", NULL);
  329. -- gtk_text_buffer_insert (buffer, &iter, " to ensure that your program properly adapts if the user changes the default font size.\n\n", -1);
  330. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1,
  331. -- "heading", NULL);
  332. -- gtk_text_buffer_insert (buffer, &iter, "Colors such as ", -1);
  333. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  334. -- "a blue foreground", -1,
  335. -- "blue_foreground", NULL);
  336. -- gtk_text_buffer_insert (buffer, &iter, " or ", -1);
  337. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  338. -- "a red background", -1,
  339. -- "red_background", NULL);
  340. -- gtk_text_buffer_insert (buffer, &iter, " or even ", -1);
  341. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  342. -- "a stippled red background", -1,
  343. -- "red_background",
  344. -- "background_stipple",
  345. -- NULL);
  346. -- gtk_text_buffer_insert (buffer, &iter, " or ", -1);
  347. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  348. -- "a stippled blue foreground on solid red background", -1,
  349. -- "blue_foreground",
  350. -- "red_background",
  351. -- "foreground_stipple",
  352. -- NULL);
  353. -- gtk_text_buffer_insert (buffer, &iter, " (select that to read it) can be used.\n\n", -1);
  354. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Underline, strikethrough, and rise. ", -1,
  355. -- "heading", NULL);
  356. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  357. -- "Strikethrough", -1,
  358. -- "strikethrough", NULL);
  359. -- gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  360. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  361. -- "underline", -1,
  362. -- "underline", NULL);
  363. -- gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  364. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  365. -- "double underline", -1,
  366. -- "double_underline", NULL);
  367. -- gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  368. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  369. -- "superscript", -1,
  370. -- "superscript", NULL);
  371. -- gtk_text_buffer_insert (buffer, &iter, ", and ", -1);
  372. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  373. -- "subscript", -1,
  374. -- "subscript", NULL);
  375. -- gtk_text_buffer_insert (buffer, &iter, " are all supported.\n\n", -1);
  376. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Images. ", -1,
  377. -- "heading", NULL);
  378. -- gtk_text_buffer_insert (buffer, &iter, "The buffer can have images in it: ", -1);
  379. -- gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  380. -- gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  381. -- gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  382. -- gtk_text_buffer_insert (buffer, &iter, " for example.\n\n", -1);
  383. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Spacing. ", -1,
  384. -- "heading", NULL);
  385. -- gtk_text_buffer_insert (buffer, &iter, "You can adjust the amount of space before each line.\n", -1);
  386. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  387. -- "This line has a whole lot of space before it.\n", -1,
  388. -- "big_gap_before_line", "wide_margins", NULL);
  389. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  390. -- "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", -1,
  391. -- "big_gap_after_line", "wide_margins", NULL);
  392. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  393. -- "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", -1,
  394. -- "double_spaced_line", "wide_margins", NULL);
  395. -- gtk_text_buffer_insert (buffer, &iter, "Also note that those lines have extra-wide margins.\n\n", -1);
  396. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Editability. ", -1,
  397. -- "heading", NULL);
  398. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  399. -- "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", -1,
  400. -- "not_editable", NULL);
  401. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Wrapping. ", -1,
  402. -- "heading", NULL);
  403. -- gtk_text_buffer_insert (buffer, &iter,
  404. -- "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1);
  405. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  406. -- "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1,
  407. -- "char_wrap", NULL);
  408. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  409. -- "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", -1,
  410. -- "no_wrap", NULL);
  411. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Justification. ", -1,
  412. -- "heading", NULL);
  413. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  414. -- "\nThis line has center justification.\n", -1,
  415. -- "center", NULL);
  416. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  417. -- "This line has right justification.\n", -1,
  418. -- "right_justify", NULL);
  419. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  420. -- "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", -1,
  421. -- "wide_margins", NULL);
  422. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Internationalization. ", -1,
  423. -- "heading", NULL);
  424. -- gtk_text_buffer_insert (buffer, &iter,
  425. -- "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\303\274d) Gr\303\274\303\237 Gott\nGreek (\316\225\316\273\316\273\316\267\316\275\316\271\316\272\316\254) \316\223\316\265\316\271\316\254 \317\203\316\261\317\202\nHebrew \327\251\327\234\327\225\327\235\nJapanese (\346\227\245\346\234\254\350\252\236)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n", -1);
  426. -- gtk_text_buffer_insert (buffer, &iter, "Here's a word-wrapped quote in a right-to-left language:\n", -1);
  427. -- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\331\210\331\202\330\257 \330\250\330\257\330\243 \330\253\331\204\330\247\330\253 \331\205\331\206 \330\243\331\203\330\253\330\261 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \330\252\331\202\330\257\331\205\330\247 \331\201\331\212 \330\264\330\250\331\203\330\251 \330\247\331\203\330\263\331\212\331\210\331\206 \330\250\330\261\330\247\331\205\330\254\331\207\330\247 \331\203\331\205\331\206\330\270\331\205\330\247\330\252 \331\204\330\247 \330\252\330\263\330\271\331\211 \331\204\331\204\330\261\330\250\330\255\330\214 \330\253\331\205 \330\252\330\255\331\210\331\204\330\252 \331\201\331\212 \330\247\331\204\330\263\331\206\331\210\330\247\330\252 \330\247\331\204\330\256\331\205\330\263 \330\247\331\204\331\205\330\247\330\266\331\212\330\251 \330\245\331\204\331\211 \331\205\330\244\330\263\330\263\330\247\330\252 \331\205\330\247\331\204\331\212\330\251 \331\205\331\206\330\270\331\205\330\251\330\214 \331\210\330\250\330\247\330\252\330\252 \330\254\330\262\330\241\330\247 \331\205\331\206 \330\247\331\204\331\206\330\270\330\247\331\205 \330\247\331\204\331\205\330\247\331\204\331\212 \331\201\331\212 \330\250\331\204\330\257\330\247\331\206\331\207\330\247\330\214 \331\210\331\204\331\203\331\206\331\207\330\247 \330\252\330\252\330\256\330\265\330\265 \331\201\331\212 \330\256\330\257\331\205\330\251 \331\202\330\267\330\247\330\271 \330\247\331\204\331\205\330\264\330\261\331\210\330\271\330\247\330\252 \330\247\331\204\330\265\330\272\331\212\330\261\330\251. \331\210\330\243\330\255\330\257 \330\243\331\203\330\253\330\261 \331\207\330\260\331\207 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \331\206\330\254\330\247\330\255\330\247 \331\207\331\210 \302\273\330\250\330\247\331\206\331\203\331\210\330\263\331\210\331\204\302\253 \331\201\331\212 \330\250\331\210\331\204\331\212\331\201\331\212\330\247.\n\n", -1,
  428. -- "rtl_quote", NULL);
  429. -- gtk_text_buffer_insert (buffer, &iter, "You can put widgets in the buffer: Here's a button: ", -1);
  430. -- anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  431. -- gtk_text_buffer_insert (buffer, &iter, " and a menu: ", -1);
  432. -- anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  433. -- gtk_text_buffer_insert (buffer, &iter, " and a scale: ", -1);
  434. -- anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  435. -- gtk_text_buffer_insert (buffer, &iter, " and an animation: ", -1);
  436. -- anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  437. -- gtk_text_buffer_insert (buffer, &iter, " finally a text entry: ", -1);
  438. -- anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  439. -- gtk_text_buffer_insert (buffer, &iter, ".\n", -1);
  440. -- gtk_text_buffer_insert (buffer, &iter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...", -1);
  441. -- /* Apply word_wrap tag to whole buffer */
  442. -- gtk_text_buffer_get_bounds (buffer, &start, &end);
  443. -- gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
  444. -- g_object_unref (pixbuf);
  445. -- }
  446. -- static gboolean
  447. -- find_anchor (GtkTextIter *iter)
  448. -- {
  449. -- while (gtk_text_iter_forward_char (iter))
  450. -- {
  451. -- if (gtk_text_iter_get_child_anchor (iter))
  452. -- return TRUE;
  453. -- }
  454. -- return FALSE;
  455. -- }
  456. -- static void
  457. -- attach_widgets (GtkTextView *text_view)
  458. -- {
  459. -- GtkTextIter iter;
  460. -- GtkTextBuffer *buffer;
  461. -- int i;
  462. -- buffer = gtk_text_view_get_buffer (text_view);
  463. -- gtk_text_buffer_get_start_iter (buffer, &iter);
  464. -- i = 0;
  465. -- while (find_anchor (&iter))
  466. -- {
  467. -- GtkTextChildAnchor *anchor;
  468. -- GtkWidget *widget;
  469. -- anchor = gtk_text_iter_get_child_anchor (&iter);
  470. -- if (i == 0)
  471. -- {
  472. -- widget = gtk_button_new_with_label ("Click Me");
  473. -- g_signal_connect (widget, "clicked",
  474. -- G_CALLBACK (easter_egg_callback),
  475. -- NULL);
  476. -- }
  477. -- else if (i == 1)
  478. -- {
  479. -- widget = gtk_combo_box_new_text ();
  480. -- gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Option 1");
  481. -- gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Option 2");
  482. -- gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Option 3");
  483. -- }
  484. -- else if (i == 2)
  485. -- {
  486. -- widget = gtk_hscale_new (NULL);
  487. -- gtk_range_set_range (GTK_RANGE (widget), 0, 100);
  488. -- gtk_widget_set_size_request (widget, 70, -1);
  489. -- }
  490. -- else if (i == 3)
  491. -- {
  492. -- gchar *filename = demo_find_file ("floppybuddy.gif", NULL);
  493. -- widget = gtk_image_new_from_file (filename);
  494. -- g_free (filename);
  495. -- }
  496. -- else if (i == 4)
  497. -- {
  498. -- widget = gtk_entry_new ();
  499. -- }
  500. -- else
  501. -- {
  502. -- widget = NULL; /* avoids a compiler warning */
  503. -- g_assert_not_reached ();
  504. -- }
  505. -- gtk_text_view_add_child_at_anchor (text_view,
  506. -- widget,
  507. -- anchor);
  508. -- gtk_widget_show_all (widget);
  509. -- ++i;
  510. -- }
  511. -- }
  512. -- GtkWidget *
  513. -- do_textview (GtkWidget *do_widget)
  514. -- {
  515. -- static GtkWidget *window = NULL;
  516. -- if (!window)
  517. -- {
  518. -- GtkWidget *vpaned;
  519. -- GtkWidget *view1;
  520. -- GtkWidget *view2;
  521. -- GtkWidget *sw;
  522. -- GtkTextBuffer *buffer;
  523. -- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  524. -- gtk_window_set_screen (GTK_WINDOW (window),
  525. -- gtk_widget_get_screen (do_widget));
  526. -- gtk_window_set_default_size (GTK_WINDOW (window),
  527. -- 450, 450);
  528. -- g_signal_connect (window, "destroy",
  529. -- G_CALLBACK (gtk_widget_destroyed), &window);
  530. -- gtk_window_set_title (GTK_WINDOW (window), "TextView");
  531. -- gtk_container_set_border_width (GTK_CONTAINER (window), 0);
  532. -- vpaned = gtk_vpaned_new ();
  533. -- gtk_container_set_border_width (GTK_CONTAINER(vpaned), 5);
  534. -- gtk_container_add (GTK_CONTAINER (window), vpaned);
  535. -- /* For convenience, we just use the autocreated buffer from
  536. -- * the first text view; you could also create the buffer
  537. -- * by itself with gtk_text_buffer_new(), then later create
  538. -- * a view widget.
  539. -- */
  540. -- view1 = gtk_text_view_new ();
  541. -- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));
  542. -- view2 = gtk_text_view_new_with_buffer (buffer);
  543. -- sw = gtk_scrolled_window_new (NULL, NULL);
  544. -- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
  545. -- GTK_POLICY_AUTOMATIC,
  546. -- GTK_POLICY_AUTOMATIC);
  547. -- gtk_paned_add1 (GTK_PANED (vpaned), sw);
  548. -- gtk_container_add (GTK_CONTAINER (sw), view1);
  549. -- sw = gtk_scrolled_window_new (NULL, NULL);
  550. -- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
  551. -- GTK_POLICY_AUTOMATIC,
  552. -- GTK_POLICY_AUTOMATIC);
  553. -- gtk_paned_add2 (GTK_PANED (vpaned), sw);
  554. -- gtk_container_add (GTK_CONTAINER (sw), view2);
  555. -- create_tags (buffer);
  556. -- insert_text (buffer);
  557. -- attach_widgets (GTK_TEXT_VIEW (view1));
  558. -- attach_widgets (GTK_TEXT_VIEW (view2));
  559. -- gtk_widget_show_all (vpaned);
  560. -- }
  561. -- if (!GTK_WIDGET_VISIBLE (window))
  562. -- {
  563. -- gtk_widget_show (window);
  564. -- }
  565. -- else
  566. -- {
  567. -- gtk_widget_destroy (window);
  568. -- window = NULL;
  569. -- }
  570. -- return window;
  571. -- }
  572. -- static void
  573. -- recursive_attach_view (int depth,
  574. -- GtkTextView *view,
  575. -- GtkTextChildAnchor *anchor)
  576. -- {
  577. -- GtkWidget *child_view;
  578. -- GtkWidget *event_box;
  579. -- GdkColor color;
  580. -- GtkWidget *align;
  581. -- if (depth > 4)
  582. -- return;
  583. -- child_view = gtk_text_view_new_with_buffer (gtk_text_view_get_buffer (view));
  584. -- /* Event box is to add a black border around each child view */
  585. -- event_box = gtk_event_box_new ();
  586. -- gdk_color_parse ("black", &color);
  587. -- gtk_widget_modify_bg (event_box, GTK_STATE_NORMAL, &color);
  588. -- align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
  589. -- gtk_container_set_border_width (GTK_CONTAINER (align), 1);
  590. -- gtk_container_add (GTK_CONTAINER (event_box), align);
  591. -- gtk_container_add (GTK_CONTAINER (align), child_view);
  592. -- gtk_text_view_add_child_at_anchor (view, event_box, anchor);
  593. -- recursive_attach_view (depth + 1, GTK_TEXT_VIEW (child_view), anchor);
  594. -- }
  595. -- static void
  596. -- easter_egg_callback (GtkWidget *button,
  597. -- gpointer data)
  598. -- {
  599. -- static GtkWidget *window = NULL;
  600. -- GtkTextBuffer *buffer;
  601. -- GtkWidget *view;
  602. -- GtkTextIter iter;
  603. -- GtkTextChildAnchor *anchor;
  604. -- GtkWidget *sw;
  605. -- if (window)
  606. -- {
  607. -- gtk_window_present (GTK_WINDOW (window));
  608. -- return;
  609. -- }
  610. -- buffer = gtk_text_buffer_new (NULL);
  611. -- gtk_text_buffer_get_start_iter (buffer, &iter);
  612. -- gtk_text_buffer_insert (buffer, &iter,
  613. -- "This buffer is shared by a set of nested text views.\n Nested view:\n", -1);
  614. -- anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  615. -- gtk_text_buffer_insert (buffer, &iter,
  616. -- "\nDon't do this in real applications, please.\n", -1);
  617. -- view = gtk_text_view_new_with_buffer (buffer);
  618. -- recursive_attach_view (0, GTK_TEXT_VIEW (view), anchor);
  619. -- g_object_unref (buffer);
  620. -- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  621. -- sw = gtk_scrolled_window_new (NULL, NULL);
  622. -- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
  623. -- GTK_POLICY_AUTOMATIC,
  624. -- GTK_POLICY_AUTOMATIC);
  625. -- gtk_container_add (GTK_CONTAINER (window), sw);
  626. -- gtk_container_add (GTK_CONTAINER (sw), view);
  627. -- g_object_add_weak_pointer (G_OBJECT (window),
  628. -- (gpointer *) &window);
  629. -- gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
  630. -- gtk_widget_show_all (window);
  631. -- }
  632. end
  633. end