newt 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/examples/memory.rb +21 -0
  3. data/examples/test-j.rb +118 -0
  4. data/examples/test.rb +95 -0
  5. data/examples/test_method/Button_new.rb +22 -0
  6. data/examples/test_method/Checkbox_get.rb +25 -0
  7. data/examples/test_method/Checkbox_new.rb +22 -0
  8. data/examples/test_method/Checkbox_set.rb +28 -0
  9. data/examples/test_method/Checkbox_set_flags.rb +28 -0
  10. data/examples/test_method/CompactButton_new.rb +22 -0
  11. data/examples/test_method/Entry_get.rb +26 -0
  12. data/examples/test_method/Entry_new.rb +23 -0
  13. data/examples/test_method/Entry_set.rb +26 -0
  14. data/examples/test_method/Entry_set_flags.rb +31 -0
  15. data/examples/test_method/Form_destroy.rb +33 -0
  16. data/examples/test_method/Form_set_background.rb +23 -0
  17. data/examples/test_method/Form_set_height.rb +26 -0
  18. data/examples/test_method/Form_set_width.rb +26 -0
  19. data/examples/test_method/Grid_new.rb +26 -0
  20. data/examples/test_method/Label_new.rb +22 -0
  21. data/examples/test_method/Label_setText.rb +25 -0
  22. data/examples/test_method/Label_set_colors.rb +28 -0
  23. data/examples/test_method/Listbox_clear.rb +25 -0
  24. data/examples/test_method/Listbox_current_bykey.rb +29 -0
  25. data/examples/test_method/Listbox_delete.rb +27 -0
  26. data/examples/test_method/Listbox_get_current.rb +28 -0
  27. data/examples/test_method/Listbox_get_current_string.rb +28 -0
  28. data/examples/test_method/Listbox_insert.rb +24 -0
  29. data/examples/test_method/Listbox_new.rb +24 -0
  30. data/examples/test_method/Listbox_select.rb +27 -0
  31. data/examples/test_method/Listbox_set.rb +27 -0
  32. data/examples/test_method/Listbox_set_current.rb +26 -0
  33. data/examples/test_method/Listbox_set_width.rb +25 -0
  34. data/examples/test_method/Newt_FLAG_SCROLL.rb +21 -0
  35. data/examples/test_method/RadioButton_new.rb +22 -0
  36. data/examples/test_method/ReflowText.rb +27 -0
  37. data/examples/test_method/Scale_new.rb +22 -0
  38. data/examples/test_method/Scale_set.rb +22 -0
  39. data/examples/test_method/Screen_bell.rb +10 -0
  40. data/examples/test_method/Screen_cls.rb +12 -0
  41. data/examples/test_method/Screen_draw_roottext.rb +16 -0
  42. data/examples/test_method/Screen_init.rb +11 -0
  43. data/examples/test_method/Screen_pop_helpline.rb +18 -0
  44. data/examples/test_method/Screen_push_helpline.rb +16 -0
  45. data/examples/test_method/Screen_redraw_helpline.rb +18 -0
  46. data/examples/test_method/Screen_set_colors.rb +34 -0
  47. data/examples/test_method/Screen_size.rb +15 -0
  48. data/examples/test_method/Screen_win_menu.rb +19 -0
  49. data/examples/test_method/TextboxReflowed_new.rb +23 -0
  50. data/examples/test_method/Textbox_get_num_lines.rb +27 -0
  51. data/examples/test_method/Textbox_new.rb +22 -0
  52. data/examples/test_method/Textbox_set_colors.rb +27 -0
  53. data/examples/test_method/Textbox_set_height.rb +25 -0
  54. data/examples/testgrid-j.rb +85 -0
  55. data/examples/testgrid.rb +84 -0
  56. data/examples/testtree-j.rb +55 -0
  57. data/examples/testtree.rb +54 -0
  58. data/ext/ruby_newt/ruby_newt.c +185 -0
  59. data/lib/version.rb +1 -1
  60. metadata +60 -4
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # ?
4
+
5
+ require 'rubygems'
6
+ require "newt"
7
+
8
+ begin
9
+
10
+ Newt::Screen.new
11
+
12
+ t = Newt::Textbox.new(1, 1, 20, 10, Newt::FLAG_WRAP)
13
+ t.set_text("Line1\nLine2\nLine3")
14
+ line = t.get_num_lines
15
+
16
+ b = Newt::Button.new(1, 13, "Exit")
17
+
18
+ f = Newt::Form.new
19
+ f.add(t, b)
20
+
21
+ f.run()
22
+
23
+ ensure
24
+ Newt::Screen.finish
25
+ end
26
+
27
+ p line
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "newt"
5
+
6
+ begin
7
+
8
+ Newt::Screen.new
9
+
10
+ t = Newt::Textbox.new(1, 1, 20, 10, Newt::FLAG_WRAP)
11
+ t.set_text("Line1\nLine2\nLine3")
12
+
13
+ b = Newt::Button.new(1, 13, "Exit")
14
+
15
+ f = Newt::Form.new
16
+ f.add(t, b)
17
+
18
+ f.run()
19
+
20
+ ensure
21
+ Newt::Screen.finish
22
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "newt"
5
+
6
+ begin
7
+ TEXTBOX_NORMAL = Newt::COLORSET_CUSTOM 1
8
+ TEXTBOX_ACTIVE = Newt::COLORSET_CUSTOM 2
9
+
10
+ Newt::Screen.new
11
+ Newt::Screen.set_color(TEXTBOX_NORMAL, "black", "red")
12
+ Newt::Screen.set_color(TEXTBOX_ACTIVE, "white", "red")
13
+
14
+ t = Newt::Textbox.new(1, 1, 20, 10, Newt::FLAG_WRAP)
15
+ t.set_colors(TEXTBOX_NORMAL, TEXTBOX_ACTIVE)
16
+ t.set_text("Line1\nLine2\nLine3")
17
+
18
+ b = Newt::Button.new(1, 13, "Exit")
19
+
20
+ f = Newt::Form.new
21
+ f.add(t, b)
22
+
23
+ f.run()
24
+
25
+ ensure
26
+ Newt::Screen.finish
27
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # ?
4
+
5
+ require 'rubygems'
6
+ require "newt"
7
+
8
+ begin
9
+
10
+ Newt::Screen.new
11
+
12
+ t = Newt::Textbox.new(1, 1, 20, 10, Newt::FLAG_WRAP)
13
+ t.set_text("Line1\nLine2\nLine3")
14
+ t.set_height(5)
15
+
16
+ b = Newt::Button.new(1, 13, "Exit")
17
+
18
+ f = Newt::Form.new
19
+ f.add(t, b)
20
+
21
+ f.run()
22
+
23
+ ensure
24
+ Newt::Screen.finish
25
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "newt"
5
+
6
+ menuContents = ["°ì", "Æó", "»°", "»Í", "¸Þ"]
7
+ autoEntries = ["¥¨¥ó¥È¥ê", "Ê̤Υ¨¥ó¥È¥ê",
8
+ "»°ÈÖÌܤΥ¨¥ó¥È¥ê", "»ÍÈÖÌܤΥ¨¥ó¥È¥ê",]
9
+
10
+ begin
11
+ Newt::Screen.new
12
+
13
+ b1 = Newt::Checkbox.new(-1, -1, "¥Æ¥¹¥È¤Î¤¿¤á¤Î¤«¤Ê¤êŤ¤¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹", ' ', nil)
14
+ b2 = Newt::Button.new(-1, -1, "Ê̤Υܥ¿¥ó")
15
+ b3 = Newt::Button.new(-1, -1, "¤·¤«¤·¡¢¤·¤«¤·")
16
+ b4 = Newt::Button.new(-1, -1, "¤·¤«¤·²¿¤À¤í¤¦¡©")
17
+
18
+ f = Newt::Form.new
19
+
20
+ grid = Newt::Grid.new(2, 2)
21
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, b1, 0, 0, 0, 0,
22
+ Newt::ANCHOR_RIGHT, 0)
23
+ grid.set_field(0, 1, Newt::GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0)
24
+ grid.set_field(1, 0, Newt::GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0)
25
+ grid.set_field(1, 1, Newt::GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0)
26
+
27
+ f.add(b1, b2, b3, b4)
28
+
29
+ grid.wrapped_window("°ìÈÖÌܤΥ¦¥£¥ó¥É¥¦")
30
+
31
+ answer = f.run()
32
+
33
+ #f.destroy()
34
+ Newt::Screen.pop_window()
35
+
36
+ flowedText, textWidth, textHeight = Newt.reflow_text("¤³¤ì¤Ï¤«¤Ê¤ê¥Æ¥­¥¹¥È¤é¤·¤¤¤â¤Î¤Ç¤¹¡£40¥«¥é¥à" +
37
+ "¤ÎŤµ¤Ç¡¢¥é¥Ã¥Ô¥ó¥°¤¬¹Ô¤ï¤ì¤Þ¤¹¡£" +
38
+ "ÁÇÁᤤ¡¢Ãã¿§¤Î¸Ñ¤¬¤Î¤í¤Þ¤Ê¸¤¤òÈô¤Ó" +
39
+ "±Û¤¨¤¿¤Î¤òÃΤäƤ뤫¤¤?\n\n" +
40
+ "¾¤Ë¤ªÃΤ餻¤¹¤ë¤³¤È¤È¤·¤Æ¡¢Å¬Åö¤Ë²þ¹Ô¤ò¤¹¤ë" +
41
+ "¤³¤È¤¬½ÅÍפǤ¹¡£",
42
+ 40, 5, 5)
43
+ t = Newt::Textbox.new(-1, -1, textWidth, textHeight, Newt::FLAG_WRAP)
44
+ t.set_text(flowedText)
45
+
46
+ b1 = Newt::Button.new(-1, -1, "λ²ò")
47
+ b2 = Newt::Button.new(-1, -1, "¥­¥ã¥ó¥»¥ë")
48
+
49
+ grid = Newt::Grid.new(1, 2)
50
+ subgrid = Newt::Grid.new(2, 1)
51
+
52
+ subgrid.set_field(0, 0, Newt::GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0)
53
+ subgrid.set_field(1, 0, Newt::GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0)
54
+
55
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0)
56
+ grid.set_field(0, 1, Newt::GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
57
+ Newt::GRID_FLAG_GROWX)
58
+ grid.wrapped_window("Ê̤ÎÎã")
59
+
60
+ f = Newt::Form.new
61
+ f.add(b1, t, b2)
62
+ #f.add(b1, b2)
63
+ answer = f.run()
64
+
65
+ Newt::Screen.pop_window()
66
+ #f.destroy()
67
+
68
+ Newt::Screen.win_message("¥·¥ó¥×¥ë", "λ²ò", "¤³¤ì¤Ï¥·¥ó¥×¥ë¤Ê¥á¥Ã¥»¡¼¥¸¥¦¥£¥ó¥É¥¦¤Ç¤¹")
69
+ Newt::Screen.win_choice("¥·¥ó¥×¥ë", "λ²ò", "¥­¥ã¥ó¥»¥ë", "¤³¤ì¤Ï¥·¥ó¥×¥ë¤ÊÁªÂò¥¦¥£¥ó¥É¥¦¤Ç¤¹")
70
+
71
+ textWidth = Newt::Screen.win_menu("¥Æ¥¹¥È¥á¥Ë¥å¡¼", "¤³¤ì¤Ï newtWinMenu() ¥³¡¼¥ë¤Î¥µ¥ó¥×¥ë" +
72
+ "¤Ç¤¹¡£ ¥¹¥¯¥í¡¼¥ë¥Ð¡¼¤ÏɬÍפ˱þ¤¸¤Æ¤Ä¤¤¤¿¤ê¡¢ " +
73
+ "¤Ä¤«¤Ê¤«¤Ã¤¿¤ê¤·¤Þ¤¹¡£", 50, 5, 5, 3,
74
+ menuContents, "λ²ò", "¥­¥ã¥ó¥»¥ë")
75
+
76
+ v = Newt::Screen.win_entries("¥Æ¥­¥¹¥È newtWinEntries()", "¤³¤ì¤Ï newtWinEntries()" +
77
+ "¥³¡¼¥ë¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£¤¿¤¤¤Ø¤ó´Êñ¤Ë¤¿¤¯¤µ¤ó¤ÎÆþÎϤò" +
78
+ "°·¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£", 50, 5, 5, 20, autoEntries, "λ²ò", "¥­¥ã¥ó¥»¥ë")
79
+
80
+ ensure
81
+ Newt::Screen.finish
82
+
83
+ printf "item = %d\n", textWidth
84
+ p v
85
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "newt"
5
+
6
+ menuContents = ["One", "Two", "Three", "Four", "Five"]
7
+ autoEntries = ["An entry", "Another entry",
8
+ "Third entry", "Fourth entry"]
9
+
10
+ Newt::Screen.new
11
+
12
+ b1 = Newt::Checkbox.new(-1, -1, "An pretty long checkbox for testing", ' ', nil)
13
+ b2 = Newt::Button.new(-1, -1, "Another Button")
14
+ b3 = Newt::Button.new(-1, -1, "But, but")
15
+ b4 = Newt::Button.new(-1, -1, "But what?")
16
+
17
+ f = Newt::Form.new
18
+
19
+ grid = Newt::Grid.new(2, 2)
20
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, b1, 0, 0, 0, 0,
21
+ Newt::ANCHOR_RIGHT, 0)
22
+ grid.set_field(0, 1, Newt::GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0)
23
+ grid.set_field(1, 0, Newt::GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0)
24
+ grid.set_field(1, 1, Newt::GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0)
25
+
26
+ f.add(b1, b2, b3, b4)
27
+
28
+ grid.wrapped_window("first window")
29
+
30
+ answer = f.run()
31
+
32
+ #f.destroy()
33
+ Newt::Screen.pop_window()
34
+
35
+ flowedText, textWidth, textHeight = Newt.reflow_text("This is a quite a bit of text. It is 40 " +
36
+ "columns long, so some wrapping should be " +
37
+ "done. Did you know that the quick, brown " +
38
+ "fox jumped over the lazy dog?\n\n" +
39
+ "In other news, it's pretty important that we " +
40
+ "can properly force a line break.",
41
+ 40, 5, 5)
42
+ t = Newt::Textbox.new(-1, -1, textWidth, textHeight, Newt::FLAG_WRAP)
43
+ t.set_text(flowedText)
44
+
45
+
46
+ b1 = Newt::Button.new(-1, -1, "Okay")
47
+ b2 = Newt::Button.new(-1, -1, "Cancel")
48
+
49
+ grid = Newt::Grid.new(1, 2)
50
+ subgrid = Newt::Grid.new(2, 1)
51
+
52
+ subgrid.set_field(0, 0, Newt::GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0)
53
+ subgrid.set_field(1, 0, Newt::GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0)
54
+
55
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0)
56
+ grid.set_field(0, 1, Newt::GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
57
+ Newt::GRID_FLAG_GROWX)
58
+ grid.wrapped_window("another example")
59
+
60
+ f = Newt::Form.new
61
+ f.add(b1, t, b2)
62
+ #f.add(b1, b2)
63
+ answer = f.run()
64
+
65
+ Newt::Screen.pop_window()
66
+ #f.destroy()
67
+
68
+ Newt::Screen.win_message("Simple", "Ok", "This is a simple message window")
69
+ result = Newt::Screen.win_choice("Simple", "Ok", "Cancel", "This is a simple choice window")
70
+
71
+ textWidth = Newt::Screen.win_menu("Test Menu", "This is a sample invovation of the " +
72
+ "newtWinMenu() call. It may or may not have a scrollbar, " +
73
+ "depending on the need for one.", 50, 5, 5, 3,
74
+ menuContents, "Ok", "Cancel")
75
+
76
+ v = Newt::Screen.win_entries("Text newtWinEntries()", "This is a sample invovation of " +
77
+ "newtWinEntries() call. It lets you get a lot of input " +
78
+ "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", "Cancel")
79
+
80
+ Newt::Screen.finish
81
+
82
+ printf "item = %d\n", textWidth
83
+ p v
84
+ p result
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "newt"
5
+
6
+ Newt::Screen.new
7
+
8
+ checktree = Newt::CheckboxTreeMulti.new(-1, -1, 10, " ab", Newt::FLAG_SCROLL)
9
+ checktree.add("¥Ê¥ó¥Ð¡¼", 2, 0, Newt::ARG_APPEND)
10
+ checktree.add("ËÜÅö¤ËËÜÅö¤ËŤ¤¥â¥Î", 3, 0, Newt::ARG_APPEND)
11
+ checktree.add("¥Ê¥ó¥Ð¡¼£µ", 5, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
12
+ checktree.add("¥Ê¥ó¥Ð¡¼£¶", 6, 0, Newt::ARG_APPEND)
13
+ checktree.add("¥Ê¥ó¥Ð¡¼£·", 7, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
14
+ checktree.add("¥Ê¥ó¥Ð¡¼£¸", 8, 0, Newt::ARG_APPEND)
15
+ checktree.add("¥Ê¥ó¥Ð¡¼£¹", 9, 0, Newt::ARG_APPEND)
16
+ checktree.add("¥Ê¥ó¥Ð¡¼£±£°", 10, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
17
+ checktree.add("¥Ê¥ó¥Ð¡¼£±£±", 11, 0, Newt::ARG_APPEND)
18
+ checktree.add("¥Ê¥ó¥Ð¡¼£±£²", 12, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
19
+
20
+ checktree.add("¥«¥é¡¼", 1, 0, 0)
21
+ checktree.add("ÀÖ¿§", 100, 0, 0, Newt::ARG_APPEND)
22
+ checktree.add("Çò¿§", 101, 0, 0, Newt::ARG_APPEND)
23
+ checktree.add("ÀÄ¿§", 102, 0, 0, Newt::ARG_APPEND)
24
+
25
+ checktree.add("¥Ê¥ó¥Ð¡¼£´", 4, 0, 3)
26
+
27
+ checktree.add("°ì·å¤Î¿ô»ú", 200, 0, 1, Newt::ARG_APPEND)
28
+ checktree.add("°ì", 201, 0, 1, 0, Newt::ARG_APPEND)
29
+ checktree.add("Æó", 202, 0, 1, 0, Newt::ARG_APPEND)
30
+ checktree.add("»°", 203, 0, 1, 0, Newt::ARG_APPEND)
31
+ checktree.add("»Í", 204, 0, 1, 0, Newt::ARG_APPEND)
32
+
33
+ checktree.add("Æó·å¤Î¿ô»ú", 300, 0, 1, Newt::ARG_APPEND)
34
+ checktree.add("½½", 210, 0, 1, 1, Newt::ARG_APPEND)
35
+ checktree.add("½½°ì", 211, 0, 1, 1, Newt::ARG_APPEND)
36
+ checktree.add("½½Æó", 212, 0, 1, 1, Newt::ARG_APPEND)
37
+ checktree.add("½½»°", 213, 0, 1, 1, Newt::ARG_APPEND)
38
+
39
+ button = Newt::Button.new(-1, -1, "½ªÎ»")
40
+
41
+ grid = Newt::Grid.new(1, 2)
42
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, checktree, 0, 0, 0, 1,
43
+ Newt::ANCHOR_RIGHT, 0)
44
+ grid.set_field(0, 1, Newt::GRID_COMPONENT, button, 0, 0, 0, 0,
45
+ 0, 0)
46
+
47
+ grid.wrapped_window("¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¥Ä¥ê¡¼¥Æ¥¹¥È")
48
+
49
+ form = Newt::Form.new
50
+ form.add(checktree, button)
51
+
52
+ answer = form.run()
53
+
54
+ Newt::Screen.finish
55
+
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "newt"
5
+
6
+ Newt::Screen.new
7
+
8
+ checktree = Newt::CheckboxTreeMulti.new(-1, -1, 10, " ab", Newt::FLAG_SCROLL)
9
+ checktree.add("Numbers", 2, 0, Newt::ARG_APPEND)
10
+ checktree.add("Really really long thing", 3, 0, Newt::ARG_APPEND)
11
+ checktree.add("number 5", 5, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
12
+ checktree.add("number 6", 6, 0, Newt::ARG_APPEND)
13
+ checktree.add("number 7", 7, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
14
+ checktree.add("number 8", 8, 0, Newt::ARG_APPEND)
15
+ checktree.add("number 9", 9, 0, Newt::ARG_APPEND)
16
+ checktree.add("number 10", 10, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
17
+ checktree.add("number 11", 11, 0, Newt::ARG_APPEND)
18
+ checktree.add("number 12", 12, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
19
+
20
+ checktree.add("Colors", 1, 0, 0)
21
+ checktree.add("Red", 100, 0, 0, Newt::ARG_APPEND)
22
+ checktree.add("White", 101, 0, 0, Newt::ARG_APPEND)
23
+ checktree.add("Blue", 102, 0, 0, Newt::ARG_APPEND)
24
+
25
+ checktree.add("number 4", 4, 0, 3)
26
+
27
+ checktree.add("Single digit", 200, 0, 1, Newt::ARG_APPEND)
28
+ checktree.add("One", 201, 0, 1, 0, Newt::ARG_APPEND)
29
+ checktree.add("Two", 202, 0, 1, 0, Newt::ARG_APPEND)
30
+ checktree.add("Three", 203, 0, 1, 0, Newt::ARG_APPEND)
31
+ checktree.add("Four", 204, 0, 1, 0, Newt::ARG_APPEND)
32
+
33
+ checktree.add("Double digit", 300, 0, 1, Newt::ARG_APPEND)
34
+ checktree.add("Ten", 210, 0, 1, 1, Newt::ARG_APPEND)
35
+ checktree.add("Eleven", 211, 0, 1, 1, Newt::ARG_APPEND)
36
+ checktree.add("Twelve", 212, 0, 1, 1, Newt::ARG_APPEND)
37
+ checktree.add("Thirteen", 213, 0, 1, 1, Newt::ARG_APPEND)
38
+
39
+ button = Newt::Button.new(-1, -1, "Exit")
40
+
41
+ grid = Newt::Grid.new(1, 2)
42
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, checktree, 0, 0, 0, 1,
43
+ Newt::ANCHOR_RIGHT, 0)
44
+ grid.set_field(0, 1, Newt::GRID_COMPONENT, button, 0, 0, 0, 0,
45
+ 0, 0)
46
+
47
+ grid.wrapped_window("Checkbox Tree Test")
48
+
49
+ form = Newt::Form.new
50
+ form.add(checktree, button)
51
+
52
+ answer = form.run()
53
+
54
+ Newt::Screen.finish
@@ -6,6 +6,8 @@
6
6
  #include <rubyio.h>
7
7
  #include <newt.h>
8
8
 
9
+ #define SYMBOL(str) (ID2SYM(rb_intern(str)))
10
+
9
11
  static VALUE mNewt;
10
12
  static VALUE mScreen;
11
13
  static VALUE cWidget;
@@ -27,6 +29,7 @@ static VALUE cGrid;
27
29
 
28
30
  static ID rb_call_id;
29
31
  static VALUE rb_ext_Widget_CALLBACK_HASH;
32
+ static struct newtColors newtColors;
30
33
 
31
34
  typedef struct snackWidget_s snackWidget;
32
35
 
@@ -58,10 +61,16 @@ static VALUE rb_ext_ReflowText(VALUE self, VALUE text, VALUE width, VALUE flexDo
58
61
  return ary;
59
62
  }
60
63
 
64
+ static VALUE rb_ext_ColorSetCustom(VALUE self, VALUE id)
65
+ {
66
+ return INT2NUM(NEWT_COLORSET_CUSTOM(NUM2INT(id)));
67
+ }
68
+
61
69
  static VALUE rb_ext_Screen_new()
62
70
  {
63
71
  newtInit();
64
72
  newtCls();
73
+ memcpy(&newtColors, &newtDefaultColorPalette, sizeof(struct newtColors));
65
74
 
66
75
  return Qnil;
67
76
  }
@@ -69,6 +78,7 @@ static VALUE rb_ext_Screen_new()
69
78
  static VALUE rb_ext_Screen_Init()
70
79
  {
71
80
  newtInit();
81
+ memcpy(&newtColors, &newtDefaultColorPalette, sizeof(struct newtColors));
72
82
  return Qnil;
73
83
  }
74
84
 
@@ -117,6 +127,158 @@ static VALUE rb_ext_Screen_PopWindow(VALUE self)
117
127
  return Qnil;
118
128
  }
119
129
 
130
+ int rb_ext_Colors_callback_function(VALUE key, VALUE val, VALUE in)
131
+ {
132
+ struct newtColors *colors;
133
+
134
+ colors = (struct newtColors *) in;
135
+ Check_Type(key, T_SYMBOL);
136
+
137
+ if (key == SYMBOL("rootFg"))
138
+ colors->rootFg = StringValuePtr(val);
139
+
140
+ else if (key == SYMBOL("rootBg"))
141
+ colors->rootBg = StringValuePtr(val);
142
+
143
+ else if (key == SYMBOL("borderFg"))
144
+ colors->borderFg = StringValuePtr(val);
145
+
146
+ else if (key == SYMBOL("borderBg"))
147
+ colors->borderBg = StringValuePtr(val);
148
+
149
+ else if (key == SYMBOL("windowFg"))
150
+ colors->windowFg = StringValuePtr(val);
151
+
152
+ else if (key == SYMBOL("windowBg"))
153
+ colors->windowBg = StringValuePtr(val);
154
+
155
+ else if (key == SYMBOL("shadowFg"))
156
+ colors->shadowFg = StringValuePtr(val);
157
+
158
+ else if (key == SYMBOL("shadowBg"))
159
+ colors->shadowBg = StringValuePtr(val);
160
+
161
+ else if (key == SYMBOL("titleFg"))
162
+ colors->titleFg = StringValuePtr(val);
163
+
164
+ else if (key == SYMBOL("titleBg"))
165
+ colors->titleBg = StringValuePtr(val);
166
+
167
+ else if (key == SYMBOL("buttonFg"))
168
+ colors->buttonFg = StringValuePtr(val);
169
+
170
+ else if (key == SYMBOL("buttonBg"))
171
+ colors->buttonBg = StringValuePtr(val);
172
+
173
+ else if (key == SYMBOL("actButtonFg"))
174
+ colors->actButtonFg = StringValuePtr(val);
175
+
176
+ else if (key == SYMBOL("actButtonBg"))
177
+ colors->actButtonBg = StringValuePtr(val);
178
+
179
+ else if (key == SYMBOL("checkboxFg"))
180
+ colors->checkboxFg = StringValuePtr(val);
181
+
182
+ else if (key == SYMBOL("checkboxBg"))
183
+ colors->checkboxBg = StringValuePtr(val);
184
+
185
+ else if (key == SYMBOL("actCheckboxFg"))
186
+ colors->actCheckboxFg = StringValuePtr(val);
187
+
188
+ else if (key == SYMBOL("actCheckboxBg"))
189
+ colors->actCheckboxBg = StringValuePtr(val);
190
+
191
+ else if (key == SYMBOL("entryFg"))
192
+ colors->entryFg = StringValuePtr(val);
193
+
194
+ else if (key == SYMBOL("entryBg"))
195
+ colors->entryBg = StringValuePtr(val);
196
+
197
+ else if (key == SYMBOL("labelFg"))
198
+ colors->labelFg = StringValuePtr(val);
199
+
200
+ else if (key == SYMBOL("labelBg"))
201
+ colors->labelBg = StringValuePtr(val);
202
+
203
+ else if (key == SYMBOL("listboxFg"))
204
+ colors->listboxFg = StringValuePtr(val);
205
+
206
+ else if (key == SYMBOL("listboxBg"))
207
+ colors->listboxBg = StringValuePtr(val);
208
+
209
+ else if (key == SYMBOL("actListboxFg"))
210
+ colors->actListboxFg = StringValuePtr(val);
211
+
212
+ else if (key == SYMBOL("actListboxBg"))
213
+ colors->actListboxBg = StringValuePtr(val);
214
+
215
+ else if (key == SYMBOL("textboxFg"))
216
+ colors->textboxFg = StringValuePtr(val);
217
+
218
+ else if (key == SYMBOL("textboxBg"))
219
+ colors->textboxBg = StringValuePtr(val);
220
+
221
+ else if (key == SYMBOL("actTextboxFg"))
222
+ colors->actTextboxFg = StringValuePtr(val);
223
+
224
+ else if (key == SYMBOL("actTextboxBg"))
225
+ colors->actTextboxBg = StringValuePtr(val);
226
+
227
+ else if (key == SYMBOL("helpLineFg"))
228
+ colors->helpLineFg = StringValuePtr(val);
229
+
230
+ else if (key == SYMBOL("helpLineBg"))
231
+ colors->helpLineBg = StringValuePtr(val);
232
+
233
+ else if (key == SYMBOL("rootTextBg"))
234
+ colors->rootTextBg = StringValuePtr(val);
235
+
236
+ else if (key == SYMBOL("emptyScale"))
237
+ colors->emptyScale = StringValuePtr(val);
238
+
239
+ else if (key == SYMBOL("fullScale"))
240
+ colors->fullScale = StringValuePtr(val);
241
+
242
+ else if (key == SYMBOL("disabledEntryFg"))
243
+ colors->disabledEntryFg = StringValuePtr(val);
244
+
245
+ else if (key == SYMBOL("disabledEntryBg"))
246
+ colors->disabledEntryBg = StringValuePtr(val);
247
+
248
+ else if (key == SYMBOL("compactButtonFg"))
249
+ colors->compactButtonFg = StringValuePtr(val);
250
+
251
+ else if (key == SYMBOL("compactButtonBg"))
252
+ colors->compactButtonBg = StringValuePtr(val);
253
+
254
+ else if (key == SYMBOL("actSelListboxFg"))
255
+ colors->actSelListboxFg = StringValuePtr(val);
256
+
257
+ else if (key == SYMBOL("actSelListboxBg"))
258
+ colors->actSelListboxBg = StringValuePtr(val);
259
+
260
+ else if (key == SYMBOL("selListboxFg"))
261
+ colors->selListboxFg = StringValuePtr(val);
262
+
263
+ else if (key == SYMBOL("selListboxBg"))
264
+ colors->selListboxBg = StringValuePtr(val);
265
+
266
+ return ST_CONTINUE;
267
+ }
268
+
269
+ static VALUE rb_ext_Screen_SetColors(VALUE self, VALUE colors)
270
+ {
271
+ Check_Type(colors, T_HASH);
272
+ rb_hash_foreach(colors, rb_ext_Colors_callback_function, (VALUE) &newtColors);
273
+ newtSetColors(newtColors);
274
+ return Qnil;
275
+ }
276
+
277
+ static VALUE rb_ext_Screen_SetColor(VALUE self, VALUE colorset, VALUE fg, VALUE bg)
278
+ {
279
+ newtSetColor(NUM2INT(colorset), StringValuePtr(fg), StringValuePtr(bg));
280
+ return Qnil;
281
+ }
120
282
 
121
283
  static VALUE rb_ext_Screen_Resume()
122
284
  {
@@ -404,6 +566,15 @@ static VALUE rb_ext_Label_SetText(VALUE self, VALUE text)
404
566
  return Qnil;
405
567
  }
406
568
 
569
+ static VALUE rb_ext_Label_SetColors(VALUE self, VALUE colorset)
570
+ {
571
+ newtComponent co;
572
+
573
+ Data_Get_Struct(self, struct newtComponent_struct, co);
574
+ newtLabelSetColors(co, NUM2INT(colorset));
575
+ return Qnil;
576
+ }
577
+
407
578
  static VALUE rb_ext_CompactButton_new(VALUE self, VALUE left, VALUE top, VALUE text)
408
579
  {
409
580
  newtComponent co;
@@ -810,6 +981,15 @@ static VALUE rb_ext_Textbox_GetNumLines(VALUE self)
810
981
  return INT2NUM(newtTextboxGetNumLines(co));
811
982
  }
812
983
 
984
+ static VALUE rb_ext_Textbox_SetColors(VALUE self, VALUE normal, VALUE active)
985
+ {
986
+ newtComponent co;
987
+
988
+ Data_Get_Struct(self, struct newtComponent_struct, co);
989
+ newtTextboxSetColors(co, NUM2INT(normal), NUM2INT(active));
990
+ return Qnil;
991
+ }
992
+
813
993
  static VALUE rb_ext_TextboxReflowed_new(VALUE self, VALUE left, VALUE top, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp, VALUE flags)
814
994
  {
815
995
  newtComponent co;
@@ -1075,6 +1255,8 @@ void Init_ruby_newt(){
1075
1255
  rb_define_module_function(mScreen, "open_window", rb_ext_Screen_OpenWindow, 5);
1076
1256
  rb_define_module_function(mScreen, "centered_window", rb_ext_Screen_CenteredWindow, 3);
1077
1257
  rb_define_module_function(mScreen, "pop_window", rb_ext_Screen_PopWindow, 0);
1258
+ rb_define_module_function(mScreen, "set_colors", rb_ext_Screen_SetColors, 1);
1259
+ rb_define_module_function(mScreen, "set_color", rb_ext_Screen_SetColor, 3);
1078
1260
  rb_define_module_function(mScreen, "refresh", rb_ext_Screen_Refresh, 0);
1079
1261
  rb_define_module_function(mScreen, "suspend", rb_ext_Screen_Suspend, 0);
1080
1262
  rb_define_module_function(mScreen, "resume", rb_ext_Screen_Resume, 0);
@@ -1118,6 +1300,7 @@ void Init_ruby_newt(){
1118
1300
  cLabel = rb_define_class_under(mNewt, "Label", cWidget);
1119
1301
  rb_define_singleton_method(cLabel, "new", rb_ext_Label_new, 3);
1120
1302
  rb_define_method(cLabel, "set_text", rb_ext_Label_SetText, 1);
1303
+ rb_define_method(cLabel, "set_colors", rb_ext_Label_SetColors, 1);
1121
1304
 
1122
1305
  cListbox = rb_define_class_under(mNewt, "Listbox", cWidget);
1123
1306
  rb_define_singleton_method(cListbox, "new", rb_ext_Listbox_new, 4);
@@ -1149,6 +1332,7 @@ void Init_ruby_newt(){
1149
1332
  rb_define_method(cTextbox, "set_text", rb_ext_Textbox_SetText, 1);
1150
1333
  rb_define_method(cTextbox, "set_height", rb_ext_Textbox_SetHeight, 1);
1151
1334
  rb_define_method(cTextbox, "get_num_lines", rb_ext_Textbox_GetNumLines, 0);
1335
+ rb_define_method(cTextbox, "set_colors", rb_ext_Textbox_SetColors, 2);
1152
1336
 
1153
1337
  cTextboxReflowed = rb_define_class_under(mNewt, "TextboxReflowed", cWidget);
1154
1338
  rb_define_singleton_method(cTextboxReflowed, "new", rb_ext_TextboxReflowed_new, 7);
@@ -1207,6 +1391,7 @@ void Init_ruby_newt(){
1207
1391
  rb_define_const(mNewt, "COLORSET_COMPACTBUTTON", INT2FIX(NEWT_COLORSET_COMPACTBUTTON));
1208
1392
  rb_define_const(mNewt, "COLORSET_ACTSELLISTBOX", INT2FIX(NEWT_COLORSET_ACTSELLISTBOX));
1209
1393
  rb_define_const(mNewt, "COLORSET_SELLISTBOX", INT2FIX(NEWT_COLORSET_SELLISTBOX));
1394
+ rb_define_module_function(mNewt, "COLORSET_CUSTOM", rb_ext_ColorSetCustom, 1);
1210
1395
 
1211
1396
  rb_define_const(mNewt, "ARG_APPEND", INT2FIX(NEWT_ARG_APPEND));
1212
1397