wxruby-ruby19 1.9.8-x86-linux → 1.9.10-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/LICENSE +53 -0
  2. data/README +297 -0
  3. data/lib/wx/accessors.rb +58 -0
  4. data/lib/wx/classes/acceleratortable.rb +28 -0
  5. data/lib/wx/classes/animation.rb +18 -0
  6. data/lib/wx/classes/app.rb +51 -0
  7. data/lib/wx/classes/artprovider.rb +31 -0
  8. data/lib/wx/classes/auinotebook.rb +9 -0
  9. data/lib/wx/classes/bitmap.rb +56 -0
  10. data/lib/wx/classes/busycursor.rb +12 -0
  11. data/lib/wx/classes/checklistbox.rb +45 -0
  12. data/lib/wx/classes/choice.rb +4 -0
  13. data/lib/wx/classes/clientdc.rb +13 -0
  14. data/lib/wx/classes/clipboard.rb +32 -0
  15. data/lib/wx/classes/colour.rb +49 -0
  16. data/lib/wx/classes/combobox.rb +4 -0
  17. data/lib/wx/classes/commandevent.rb +7 -0
  18. data/lib/wx/classes/controlwithitems.rb +10 -0
  19. data/lib/wx/classes/data_object.rb +14 -0
  20. data/lib/wx/classes/data_object_simple.rb +6 -0
  21. data/lib/wx/classes/dataformat.rb +23 -0
  22. data/lib/wx/classes/dc.rb +57 -0
  23. data/lib/wx/classes/event.rb +5 -0
  24. data/lib/wx/classes/evthandler.rb +1039 -0
  25. data/lib/wx/classes/font.rb +118 -0
  26. data/lib/wx/classes/functions.rb +44 -0
  27. data/lib/wx/classes/gauge.rb +12 -0
  28. data/lib/wx/classes/genericdirctrl.rb +36 -0
  29. data/lib/wx/classes/grid.rb +146 -0
  30. data/lib/wx/classes/hboxsizer.rb +6 -0
  31. data/lib/wx/classes/helpcontroller.rb +5 -0
  32. data/lib/wx/classes/helpcontrollerhelpprovider.rb +23 -0
  33. data/lib/wx/classes/helpprovider.rb +15 -0
  34. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  35. data/lib/wx/classes/htmlwindow.rb +14 -0
  36. data/lib/wx/classes/icon.rb +32 -0
  37. data/lib/wx/classes/iconbundle.rb +3 -0
  38. data/lib/wx/classes/image.rb +43 -0
  39. data/lib/wx/classes/imagelist.rb +3 -0
  40. data/lib/wx/classes/listbox.rb +4 -0
  41. data/lib/wx/classes/listctrl.rb +33 -0
  42. data/lib/wx/classes/locale.rb +28 -0
  43. data/lib/wx/classes/mediactrl.rb +48 -0
  44. data/lib/wx/classes/menu.rb +62 -0
  45. data/lib/wx/classes/menuitem.rb +7 -0
  46. data/lib/wx/classes/notebook.rb +9 -0
  47. data/lib/wx/classes/object.rb +14 -0
  48. data/lib/wx/classes/paintdc.rb +12 -0
  49. data/lib/wx/classes/point.rb +56 -0
  50. data/lib/wx/classes/previewframe.rb +13 -0
  51. data/lib/wx/classes/rect.rb +19 -0
  52. data/lib/wx/classes/richtextctrl.rb +63 -0
  53. data/lib/wx/classes/simplehelpprovider.rb +38 -0
  54. data/lib/wx/classes/size.rb +58 -0
  55. data/lib/wx/classes/sizer.rb +37 -0
  56. data/lib/wx/classes/sound.rb +23 -0
  57. data/lib/wx/classes/standardpaths.rb +9 -0
  58. data/lib/wx/classes/styledtextctrl.rb +92 -0
  59. data/lib/wx/classes/textctrl.rb +14 -0
  60. data/lib/wx/classes/texturlevent.rb +18 -0
  61. data/lib/wx/classes/timer.rb +94 -0
  62. data/lib/wx/classes/toolbar.rb +27 -0
  63. data/lib/wx/classes/toolbartool.rb +4 -0
  64. data/lib/wx/classes/treectrl.rb +44 -0
  65. data/lib/wx/classes/vboxsizer.rb +6 -0
  66. data/lib/wx/classes/window.rb +89 -0
  67. data/lib/wx/classes/xmlresource.rb +54 -0
  68. data/lib/wx/helpers.rb +45 -0
  69. data/lib/wx/keyword_ctors.rb +204 -0
  70. data/lib/wx/keyword_defs.rb +558 -0
  71. data/lib/wx/version.rb +3 -0
  72. data/lib/wx.rb +53 -0
  73. data/lib/wxruby2.so +0 -0
  74. data/samples/SAMPLES-LICENSE.TXT +18 -0
  75. data/samples/aui/aui.rb +1356 -0
  76. data/samples/bigdemo/About.rbw +39 -0
  77. data/samples/bigdemo/ColorPanel.rbw +23 -0
  78. data/samples/bigdemo/GridSimple.rbw +78 -0
  79. data/samples/bigdemo/MDIDemo.rbw +57 -0
  80. data/samples/bigdemo/PopupMenu.rbw +149 -0
  81. data/samples/bigdemo/ShapedWindow.rbw +131 -0
  82. data/samples/bigdemo/Sizers.rbw +543 -0
  83. data/samples/bigdemo/bigdemo.rb +823 -0
  84. data/samples/bigdemo/demoTemplate.rbw +33 -0
  85. data/samples/bigdemo/helpfile.htb +0 -0
  86. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  87. data/samples/bigdemo/icons/Test 015.png +0 -0
  88. data/samples/bigdemo/icons/choice.bmp +0 -0
  89. data/samples/bigdemo/icons/choice.xpm +27 -0
  90. data/samples/bigdemo/icons/combo.bmp +0 -0
  91. data/samples/bigdemo/icons/combo.xpm +27 -0
  92. data/samples/bigdemo/icons/copy.xpm +25 -0
  93. data/samples/bigdemo/icons/cut.xpm +24 -0
  94. data/samples/bigdemo/icons/gauge.bmp +0 -0
  95. data/samples/bigdemo/icons/gauge.xpm +27 -0
  96. data/samples/bigdemo/icons/help.xpm +25 -0
  97. data/samples/bigdemo/icons/list.bmp +0 -0
  98. data/samples/bigdemo/icons/list.xpm +27 -0
  99. data/samples/bigdemo/icons/mondrian.ico +0 -0
  100. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  101. data/samples/bigdemo/icons/new.xpm +24 -0
  102. data/samples/bigdemo/icons/ogl.ico +0 -0
  103. data/samples/bigdemo/icons/ogl.xpm +45 -0
  104. data/samples/bigdemo/icons/open.xpm +26 -0
  105. data/samples/bigdemo/icons/paste.bmp +0 -0
  106. data/samples/bigdemo/icons/paste.xpm +38 -0
  107. data/samples/bigdemo/icons/pointy.png +0 -0
  108. data/samples/bigdemo/icons/preview.xpm +26 -0
  109. data/samples/bigdemo/icons/print.xpm +26 -0
  110. data/samples/bigdemo/icons/radio.bmp +0 -0
  111. data/samples/bigdemo/icons/radio.xpm +27 -0
  112. data/samples/bigdemo/icons/robert.xpm +415 -0
  113. data/samples/bigdemo/icons/ruby.png +0 -0
  114. data/samples/bigdemo/icons/sashtest.ico +0 -0
  115. data/samples/bigdemo/icons/save.xpm +25 -0
  116. data/samples/bigdemo/icons/smiles.bmp +0 -0
  117. data/samples/bigdemo/icons/smiles.xpm +39 -0
  118. data/samples/bigdemo/icons/smiley.ico +0 -0
  119. data/samples/bigdemo/icons/smiley.xpm +42 -0
  120. data/samples/bigdemo/icons/stattext.xpm +24 -0
  121. data/samples/bigdemo/icons/test2.bmp +0 -0
  122. data/samples/bigdemo/icons/test2.png +0 -0
  123. data/samples/bigdemo/icons/test2.xpm +79 -0
  124. data/samples/bigdemo/icons/text.bmp +0 -0
  125. data/samples/bigdemo/icons/text.xpm +27 -0
  126. data/samples/bigdemo/icons/tog1.bmp +0 -0
  127. data/samples/bigdemo/icons/tog1.xpm +38 -0
  128. data/samples/bigdemo/icons/tog2.bmp +0 -0
  129. data/samples/bigdemo/icons/tog2.xpm +38 -0
  130. data/samples/bigdemo/icons/wxwin.ico +0 -0
  131. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  132. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  133. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  134. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  135. data/samples/bigdemo/run.rb +90 -0
  136. data/samples/bigdemo/tips.txt +7 -0
  137. data/samples/bigdemo/utils.rb +12 -0
  138. data/samples/bigdemo/wxArtProvider.rbw +281 -0
  139. data/samples/bigdemo/wxBitmapButton.rbw +65 -0
  140. data/samples/bigdemo/wxButton.rbw +64 -0
  141. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
  142. data/samples/bigdemo/wxCheckBox.rbw +50 -0
  143. data/samples/bigdemo/wxCheckListBox.rbw +65 -0
  144. data/samples/bigdemo/wxChoice.rbw +47 -0
  145. data/samples/bigdemo/wxChoicebook.rbw +78 -0
  146. data/samples/bigdemo/wxColourDialog.rbw +31 -0
  147. data/samples/bigdemo/wxComboBox.rbw +77 -0
  148. data/samples/bigdemo/wxCursor.rbw +136 -0
  149. data/samples/bigdemo/wxDialog.rbw +74 -0
  150. data/samples/bigdemo/wxDirDialog.rbw +29 -0
  151. data/samples/bigdemo/wxDragImage.rbw +70 -0
  152. data/samples/bigdemo/wxFileDialog.rbw +37 -0
  153. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
  154. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
  155. data/samples/bigdemo/wxFontDialog.rbw +173 -0
  156. data/samples/bigdemo/wxFrame.rbw +53 -0
  157. data/samples/bigdemo/wxGauge.rbw +71 -0
  158. data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
  159. data/samples/bigdemo/wxGrid.rbw +66 -0
  160. data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
  161. data/samples/bigdemo/wxListBox.rbw +140 -0
  162. data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -0
  163. data/samples/bigdemo/wxMDIWindows.rbw +50 -0
  164. data/samples/bigdemo/wxMenu.rbw +236 -0
  165. data/samples/bigdemo/wxMessageDialog.rbw +27 -0
  166. data/samples/bigdemo/wxMiniFrame.rbw +70 -0
  167. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
  168. data/samples/bigdemo/wxNotebook.rbw +136 -0
  169. data/samples/bigdemo/wxProgressDialog.rbw +43 -0
  170. data/samples/bigdemo/wxRadioBox.rbw +72 -0
  171. data/samples/bigdemo/wxRadioButton.rbw +125 -0
  172. data/samples/bigdemo/wxSashWindow.rbw +141 -0
  173. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
  174. data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
  175. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
  176. data/samples/bigdemo/wxSlider.rbw +42 -0
  177. data/samples/bigdemo/wxSpinButton.rbw +50 -0
  178. data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
  179. data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
  180. data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
  181. data/samples/bigdemo/wxStaticText.rbw +55 -0
  182. data/samples/bigdemo/wxStatusBar.rbw +126 -0
  183. data/samples/bigdemo/wxTextCtrl.rbw +149 -0
  184. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
  185. data/samples/bigdemo/wxToggleButton.rbw +49 -0
  186. data/samples/bigdemo/wxToolBar.rbw +131 -0
  187. data/samples/bigdemo/wxTreeCtrl.rbw +191 -0
  188. data/samples/calendar/calendar.rb +256 -0
  189. data/samples/caret/caret.rb +282 -0
  190. data/samples/caret/mondrian.xpm +44 -0
  191. data/samples/controls/controls.rb +1136 -0
  192. data/samples/controls/get_item_sample.rb +87 -0
  193. data/samples/controls/icons/choice.xpm +27 -0
  194. data/samples/controls/icons/combo.xpm +27 -0
  195. data/samples/controls/icons/gauge.xpm +27 -0
  196. data/samples/controls/icons/list.xpm +27 -0
  197. data/samples/controls/icons/radio.xpm +27 -0
  198. data/samples/controls/icons/stattext.xpm +24 -0
  199. data/samples/controls/icons/text.xpm +27 -0
  200. data/samples/controls/mondrian.ico +0 -0
  201. data/samples/controls/mondrian.xpm +44 -0
  202. data/samples/controls/test2.bmp +0 -0
  203. data/samples/dialogs/dialogs.rb +797 -0
  204. data/samples/dialogs/tips.txt +18 -0
  205. data/samples/dragdrop/dragdrop.rb +177 -0
  206. data/samples/drawing/graphics_drawing.rb +235 -0
  207. data/samples/drawing/images.rb +37 -0
  208. data/samples/drawing/paperclip.png +0 -0
  209. data/samples/etc/activation.rb +102 -0
  210. data/samples/etc/choice.rb +67 -0
  211. data/samples/etc/miniframe.rb +79 -0
  212. data/samples/etc/sash.rb +130 -0
  213. data/samples/etc/scrollwin.rb +110 -0
  214. data/samples/etc/system_settings.rb +252 -0
  215. data/samples/etc/threaded.rb +72 -0
  216. data/samples/etc/toolbar_sizer_additem.rb +55 -0
  217. data/samples/etc/wizard.rb +74 -0
  218. data/samples/event/event.rb +182 -0
  219. data/samples/event/update_ui_event.rb +70 -0
  220. data/samples/grid/grid.rb +198 -0
  221. data/samples/grid/gridtablebase.rb +148 -0
  222. data/samples/html/html.rb +262 -0
  223. data/samples/listbook/listbook.rb +174 -0
  224. data/samples/listbook/listbook.xrc +370 -0
  225. data/samples/mdi/mdi.rb +85 -0
  226. data/samples/media/mediactrl.rb +167 -0
  227. data/samples/minimal/minimal.rb +77 -0
  228. data/samples/minimal/mondrian.ico +0 -0
  229. data/samples/minimal/mondrian.png +0 -0
  230. data/samples/minimal/nothing.rb +16 -0
  231. data/samples/opengl/cube.rb +117 -0
  232. data/samples/printing/mondrian.ico +0 -0
  233. data/samples/printing/mondrian.xpm +44 -0
  234. data/samples/printing/printing.rb +487 -0
  235. data/samples/sockets/SocketPackets.rb +27 -0
  236. data/samples/sockets/res/message-new.png +0 -0
  237. data/samples/sockets/res/user.png +0 -0
  238. data/samples/sockets/wxClient.rb +395 -0
  239. data/samples/sockets/wxServer.rb +422 -0
  240. data/samples/sockets/wxSocketGUI.rb +97 -0
  241. data/samples/text/format-text-bold.png +0 -0
  242. data/samples/text/format-text-italic.png +0 -0
  243. data/samples/text/format-text-underline.png +0 -0
  244. data/samples/text/mondrian.ico +0 -0
  245. data/samples/text/mondrian.xpm +44 -0
  246. data/samples/text/rich_textctrl.rb +98 -0
  247. data/samples/text/scintilla.rb +169 -0
  248. data/samples/text/textctrl.rb +111 -0
  249. data/samples/text/unicode.rb +242 -0
  250. data/samples/text/utf8.txt +15 -0
  251. data/samples/treectrl/icon1.xpm +79 -0
  252. data/samples/treectrl/icon2.xpm +53 -0
  253. data/samples/treectrl/icon3.xpm +79 -0
  254. data/samples/treectrl/icon4.xpm +43 -0
  255. data/samples/treectrl/icon5.xpm +79 -0
  256. data/samples/treectrl/treectrl.rb +1166 -0
  257. data/samples/xrc/samples.xrc +46 -0
  258. data/samples/xrc/xrc_sample.rb +76 -0
  259. metadata +234 -220
@@ -0,0 +1,487 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+
10
+ WXPRINT_QUIT = Wx::ID_EXIT
11
+ WXPRINT_PRINT = Wx::ID_PRINT
12
+ WXPRINT_PAGE_SETUP = Wx::ID_PRINT_SETUP
13
+ WXPRINT_PREVIEW = Wx::ID_PREVIEW
14
+
15
+ WXPRINT_PRINT_PS = 105
16
+ WXPRINT_PAGE_SETUP_PS = 107
17
+ WXPRINT_PREVIEW_PS = 108
18
+
19
+ WXPRINT_ABOUT = Wx::ID_ABOUT
20
+
21
+ WXPRINT_ANGLEUP = 110
22
+ WXPRINT_ANGLEDOWN = 111
23
+
24
+ class MyFrame < Wx::Frame
25
+
26
+ attr_accessor :canvas
27
+
28
+ def initialize(parent,title,pos,size)
29
+ super(parent,-1,title,pos,size)
30
+ @canvas = nil
31
+ @bitmap = Wx::Bitmap.new
32
+ @angle = 30
33
+
34
+ # map events
35
+ evt_menu(WXPRINT_QUIT) {|e| on_exit(e)}
36
+ evt_menu(WXPRINT_PRINT) {|e| on_print(e)}
37
+ evt_menu(WXPRINT_PREVIEW) {|e| on_print_preview(e)}
38
+ evt_menu(WXPRINT_PAGE_SETUP) {|e| on_page_setup(e)}
39
+ evt_menu(WXPRINT_ABOUT) {|e| on_print_about(e)}
40
+ evt_menu(WXPRINT_ANGLEUP) {|e| on_angle_up(e)}
41
+ evt_menu(WXPRINT_ANGLEDOWN) {|e| on_angle_down(e)}
42
+ end
43
+
44
+ def draw(dc)
45
+ dc.set_background(Wx::WHITE_BRUSH)
46
+ dc.clear()
47
+ dc.set_font(Wx::get_app.test_font)
48
+
49
+ dc.set_background_mode(Wx::TRANSPARENT)
50
+
51
+ dc.set_brush(Wx::CYAN_BRUSH)
52
+ dc.set_pen(Wx::RED_PEN)
53
+
54
+ dc.draw_rounded_rectangle(0, 20, 200, 80, 20)
55
+
56
+ dc.draw_text( "Rectangle 200 by 80", 40, 40)
57
+
58
+ dc.set_pen( Wx::Pen.new(Wx::BLACK,0,Wx::DOT_DASH) )
59
+ dc.draw_ellipse(50, 140, 100, 50)
60
+ dc.set_pen(Wx::RED_PEN)
61
+
62
+ dc.draw_text( "Test message: this is in 10 point text", 10, 180)
63
+
64
+ test = "Hebrew שלום -- Japanese (日本語)"
65
+ dc.draw_text( test, 10, 200 )
66
+
67
+ points = []
68
+ points << Wx::Point.new(0,0)
69
+ points << Wx::Point.new(20,0)
70
+ points << Wx::Point.new(20,20)
71
+ points << Wx::Point.new(10,20)
72
+ points << Wx::Point.new(10,-20)
73
+
74
+ dc.draw_polygon( points, 20, 250, Wx::ODDEVEN_RULE )
75
+ dc.draw_polygon( points, 50, 250, Wx::WINDING_RULE )
76
+
77
+ dc.draw_elliptic_arc( 80, 250, 60, 30, 0.0, 270.0 )
78
+
79
+ points[0].x = 150
80
+ points[0].y = 250
81
+ points[1].x = 180
82
+ points[1].y = 250
83
+ points[2].x = 180
84
+ points[2].y = 220
85
+ points[3].x = 200
86
+ points[3].y = 220
87
+ points.pop
88
+ dc.draw_spline( points )
89
+
90
+ dc.draw_arc( 20,10, 10,10, 25,40 )
91
+
92
+ str = ""
93
+ i = 0
94
+ str = "---- Text at angle #{i} ----"
95
+ dc.draw_rotated_text( str, 100, 300, i )
96
+
97
+ i = @angle;
98
+ str = "---- Text at angle #{i} ----"
99
+ dc.draw_rotated_text( str, 100, 300, i )
100
+
101
+ dc.set_pen(Wx::BLACK_PEN)
102
+ dc.draw_line(0, 0, 200, 200)
103
+ dc.draw_line(200, 0, 0, 200)
104
+
105
+ # Load icon
106
+ if Wx::PLATFORM == "WXMSW"
107
+ icon_file = File.join(File.dirname(__FILE__), 'mondrian.ico')
108
+ my_icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_ICO)
109
+ else
110
+ icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
111
+ my_icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM)
112
+ end
113
+
114
+ dc.draw_icon( my_icon, 100, 100)
115
+
116
+ if @bitmap.is_ok
117
+ dc.draw_bitmap( @bitmap, 10, 10 )
118
+ end
119
+ end
120
+
121
+ def on_angle_up(event)
122
+ @angle += 5
123
+ canvas.refresh
124
+ end
125
+
126
+ def on_angle_down(event)
127
+ @angle -= 5
128
+ canvas.refresh
129
+ end
130
+
131
+ def on_size(event)
132
+ super(event)
133
+ end
134
+
135
+ def on_print(event)
136
+ print_dialog_data = Wx::PrintDialogData.new(Wx::get_app.print_data)
137
+
138
+ printer = Wx::Printer.new(print_dialog_data)
139
+ printout = MyPrintout.new("My printout")
140
+ if (!printer.print(self, printout, true))
141
+ if (Wx::Printer.get_last_error == Wx::PRINTER_ERROR)
142
+ Wx::message_box("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", Wx::OK)
143
+ else
144
+ Wx::message_box("You canceled printing", "Printing", Wx::OK)
145
+ end
146
+ else
147
+ Wx::get_app.print_data = printer.get_print_dialog_data.get_print_data
148
+ end
149
+ end
150
+
151
+ def on_print_preview(event)
152
+ # Pass two printout objects: for preview, and possible printing.
153
+ print_dialog_data = Wx::PrintDialogData.new(Wx::get_app.print_data)
154
+ preview = Wx::PrintPreview.new(MyPrintout.new, MyPrintout.new, print_dialog_data)
155
+ if not preview.is_ok
156
+ #delete preview;
157
+ Wx::message_box("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", Wx::OK)
158
+ return
159
+ end
160
+
161
+ prev_frame = Wx::PreviewFrame.new(preview, self, "Demo Print Preview", Wx::Point.new(100, 100), Wx::Size.new(600, 650))
162
+ prev_frame.centre(Wx::BOTH)
163
+ prev_frame.init
164
+ prev_frame.show
165
+ end
166
+
167
+ def on_page_setup(event)
168
+ Wx::get_app.page_setup_data = Wx::PageSetupDialogData.new(Wx::get_app.print_data)
169
+ page_setup_dialog = Wx::PageSetupDialog.new(self, Wx::get_app.page_setup_data)
170
+ page_setup_dialog.show_modal
171
+
172
+ Wx::get_app.print_data = page_setup_dialog.get_page_setup_data.get_print_data
173
+ Wx::get_app.page_setup_data = Wx::PageSetupDialogData.new(Wx::get_app.print_data)
174
+ end
175
+
176
+ def on_exit(event)
177
+ close(true)
178
+ end
179
+
180
+ def on_print_about(event)
181
+ Wx::message_box("wxWidgets printing demo\nAuthor: Julian Smart\nAdapted to wxRuby by Sean Long",
182
+ "About wxRuby printing demo", Wx::OK|Wx::CENTRE)
183
+ end
184
+
185
+ end
186
+
187
+ class MyCanvas < Wx::ScrolledWindow
188
+ #attr_accessor :frame
189
+
190
+ def initialize(parent,pos,size,style = Wx::RETAINED)
191
+ super(parent,-1,pos,size,style)
192
+ @frame = parent
193
+ set_background_colour(Wx::WHITE)
194
+ evt_mouse_events() {|e| on_event(e)}
195
+ end
196
+
197
+ def on_draw(dc)
198
+ @frame.draw(dc)
199
+ end
200
+
201
+ def on_event(event)
202
+ end
203
+ end
204
+
205
+ class MyPrintout < Wx::Printout
206
+ def initialize(title = "My printout")
207
+ super(title)
208
+ end
209
+
210
+ def on_print_page(page)
211
+ dc = get_dc
212
+ if dc
213
+ if page == 1
214
+ draw_page_one(dc)
215
+ elsif (page == 2)
216
+ draw_page_two(dc)
217
+ end
218
+ dc.set_device_origin(0, 0)
219
+ dc.set_user_scale(1.0, 1.0)
220
+
221
+ buf = "PAGE #{page}"
222
+ dc.draw_text(buf, 10, 10)
223
+
224
+ return true
225
+ else
226
+ return false
227
+ end
228
+ end
229
+
230
+ def on_begin_document(start_page,end_page)
231
+ go_ahead = super(start_page, end_page)
232
+ if (!go_ahead)
233
+ return false
234
+ end
235
+ return true
236
+ end
237
+
238
+ def has_page(page)
239
+ return (page == 1 || page == 2)
240
+ end
241
+
242
+ def get_page_info
243
+ min_page = 1
244
+ max_page = 2
245
+ sel_page_from = 1
246
+ sel_page_to = 2
247
+ [min_page,max_page,sel_page_from,sel_page_to]
248
+ end
249
+
250
+ def draw_page_one(dc)
251
+ # You might use THIS code if you were scaling
252
+ # graphics of known size to fit on the page.
253
+
254
+ # We know the graphic is 200x200. If we didn't know this,
255
+ # we'd need to calculate it.
256
+ max_x = 200
257
+ max_y = 200
258
+
259
+ # Let's have at least 50 device units margin
260
+ margin_x = 50
261
+ margin_y = 50
262
+
263
+ # Add the margin to the graphic size
264
+ max_x += (2*margin_x)
265
+ max_y += (2*margin_y)
266
+
267
+ # Get the size of the DC in pixels
268
+ size = dc.get_size
269
+ w = size.get_width
270
+ h = size.get_height
271
+
272
+ # Calculate a suitable scaling factor
273
+ scale_x=(w/max_x)
274
+ scale_y=(h/max_y)
275
+
276
+ # Use x or y scaling factor, whichever fits on the DC
277
+ #actualScale = Wx::min(scaleX,scaleY)
278
+ if scale_x < scale_y
279
+ actual_scale = scale_x
280
+ else
281
+ actual_scale = scale_y
282
+ end
283
+
284
+ # Calculate the position on the DC for centring the graphic
285
+ pos_x = ((w - (200*actual_scale))/2.0)
286
+ pos_y = ((h - (200*actual_scale))/2.0)
287
+
288
+ # Set the scale and origin
289
+ dc.set_user_scale(actual_scale, actual_scale)
290
+ dc.set_device_origin( pos_x.to_i, pos_y.to_i )
291
+
292
+ Wx::get_app.frame.draw(dc)
293
+ end
294
+
295
+ def draw_page_two(dc)
296
+ # You might use THIS code to set the printer DC to ROUGHLY reflect
297
+ # the screen text size. This page also draws lines of actual length
298
+ # 5cm on the page.
299
+
300
+ # Get the logical pixels per inch of screen and printer
301
+ ppi_screen_x, ppi_screen_y = get_ppi_screen
302
+ ppi_printer_x, ppi_printer_y = get_ppi_printer
303
+
304
+ # This scales the DC so that the printout roughly represents the
305
+ # the screen scaling. The text point size _should_ be the right size
306
+ # but in fact is too small for some reason. This is a detail that will
307
+ # need to be addressed at some point but can be fudged for the
308
+ # moment.
309
+ scale = ( ppi_printer_x.to_f / ppi_screen_x.to_f )
310
+
311
+ # Now we have to check in case our real page size is reduced
312
+ # (e.g. because we're drawing to a print preview memory DC)
313
+ page_width, page_height = get_page_size_pixels
314
+ size = dc.get_size
315
+ w = size.get_width
316
+ h = size.get_height
317
+
318
+ # If printer pageWidth == current DC width, then this doesn't
319
+ # change. But w might be the preview bitmap width, so scale down.
320
+ overall_scale = scale * (w/page_width)
321
+ dc.set_user_scale(overall_scale, overall_scale)
322
+
323
+ # Calculate conversion factor for converting millimetres into
324
+ # logical units.
325
+ # There are approx. 25.4 mm to the inch. There are ppi
326
+ # device units to the inch. Therefore 1 mm corresponds to
327
+ # ppi/25.4 device units. We also divide by the
328
+ # screen-to-printer scaling factor, because we need to
329
+ # unscale to pass logical units to DrawLine.
330
+
331
+ # Draw 50 mm by 50 mm L shape
332
+ log_units_factor = (ppi_printer_x/(scale*25.4))
333
+ log_units = (50*log_units_factor)
334
+ dc.set_pen(Wx::BLACK_PEN)
335
+ dc.draw_line(50, 250, (50.0 + log_units).to_i, 250)
336
+ dc.draw_line(50, 250, 50, (250.0 + log_units).to_i)
337
+
338
+ dc.set_background_mode(Wx::TRANSPARENT)
339
+ dc.set_brush(Wx::TRANSPARENT_BRUSH)
340
+
341
+ # GetTextExtent demo:
342
+ words = ["This ", "is ", "GetTextExtent ", "testing ", "string. ", "Enjoy ", "it!"]
343
+ w, h = 0,0
344
+ x = 200
345
+ y= 250
346
+ fnt = Wx::Font.new(15, Wx::SWISS, Wx::NORMAL, Wx::NORMAL)
347
+
348
+ dc.set_font(fnt)
349
+
350
+ words.each do |word|
351
+ w,h = dc.get_text_extent(word)
352
+ dc.draw_rectangle(x, y, w.to_i, h.to_i)
353
+ w,h = dc.get_text_extent(word)
354
+ dc.draw_text(word, x, y)
355
+ x += w
356
+ end
357
+
358
+ dc.set_font(Wx::get_app.test_font)
359
+
360
+ dc.draw_text("Some test text", 200, 300 )
361
+
362
+ left_margin = 20
363
+ right_margin = 20
364
+ top_margin = 20
365
+ bottom_margin = 20
366
+
367
+ page_width_mm, page_height_mm = get_page_size_mm
368
+
369
+ left_margin_logical = (log_units_factor*left_margin).to_i
370
+ top_margin_logical = (log_units_factor*top_margin).to_i
371
+ bottom_margin_logical = (log_units_factor*(page_height_mm - bottom_margin)).to_i
372
+ right_margin_logical = (log_units_factor*(page_width_mm - right_margin)).to_i
373
+
374
+ dc.set_pen(Wx::RED_PEN)
375
+ dc.draw_line( left_margin_logical, top_margin_logical,
376
+ right_margin_logical, top_margin_logical)
377
+ dc.draw_line( left_margin_logical, bottom_margin_logical,
378
+ right_margin_logical, bottom_margin_logical)
379
+
380
+ write_page_header(self, dc, "A header", log_units_factor)
381
+ end
382
+
383
+ # Writes a header on a page. Margin units are in millimetres.
384
+ def write_page_header(printout, dc, text, mm_to_logical)
385
+ page_width_mm, page_height_mm = printout.get_page_size_mm
386
+
387
+ left_margin = 10
388
+ top_margin = 10
389
+ right_margin = 10
390
+
391
+ left_margin_logical = (mm_to_logical*left_margin).to_i
392
+ top_margin_logical = (mm_to_logical*top_margin).to_i
393
+ right_margin_logical = (mm_to_logical*(page_width_mm - right_margin)).to_i
394
+
395
+ x_extent, y_extent= dc.get_text_extent(text)
396
+ x_pos = (((((page_width_mm - left_margin - right_margin)/2.0)+left_margin)*mm_to_logical) - (x_extent/2.0))
397
+ dc.draw_text(text, x_pos.to_i, top_margin_logical)
398
+
399
+ dc.set_pen(Wx::BLACK_PEN)
400
+ dc.draw_line( left_margin_logical, (top_margin_logical + y_extent).to_i,
401
+ right_margin_logical, (top_margin_logical + y_extent).to_i )
402
+
403
+ return true
404
+ end
405
+ end
406
+
407
+ class MyApp < Wx::App
408
+ attr_accessor :frame,:test_font,:print_data,:page_setup_data
409
+
410
+ def on_init
411
+ @test_font = Wx::Font.new(10, Wx::SWISS, Wx::NORMAL, Wx::NORMAL)
412
+
413
+ # Create the main frame window
414
+ @frame = MyFrame.new(nil, "wxRuby Printing Demo", Wx::Point.new(0, 0), Wx::Size.new(400, 400))
415
+
416
+ # Give it a status line
417
+ @frame.create_status_bar(2)
418
+
419
+
420
+ # Load icon and bitmap
421
+ if Wx::PLATFORM == "WXMSW"
422
+ icon_file = File.join(File.dirname(__FILE__), 'mondrian.ico')
423
+ @frame.set_icon( Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_ICO) )
424
+ else
425
+ icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
426
+ @frame.set_icon( Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM) )
427
+ end
428
+
429
+ # Make a menubar
430
+ file_menu = Wx::Menu.new
431
+
432
+ file_menu.append(WXPRINT_PRINT, "&Print...","Print")
433
+ file_menu.append(WXPRINT_PAGE_SETUP, "Page Set&up...","Page setup")
434
+ file_menu.append(WXPRINT_PREVIEW, "Print Pre&view","Preview")
435
+
436
+ =begin
437
+ # Accelerators
438
+ wxAcceleratorEntry entries[1];
439
+ entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW);
440
+ wxAcceleratorTable accel(1, entries);
441
+ frame->SetAcceleratorTable(accel);
442
+ =end
443
+
444
+ file_menu.append_separator()
445
+ file_menu.append(WXPRINT_ANGLEUP, "Angle up\tAlt-U","Raise rotated text angle")
446
+ file_menu.append(WXPRINT_ANGLEDOWN, "Angle down\tAlt-D","Lower rotated text angle")
447
+ file_menu.append_separator()
448
+ file_menu.append(WXPRINT_QUIT, "E&xit","Exit program")
449
+
450
+ help_menu = Wx::Menu.new
451
+ help_menu.append(WXPRINT_ABOUT, "&About","About this demo")
452
+
453
+ menu_bar = Wx::MenuBar.new
454
+
455
+ menu_bar.append(file_menu, "&File")
456
+ menu_bar.append(help_menu, "&Help")
457
+
458
+ # Associate the menu bar with the frame
459
+ @frame.set_menu_bar(menu_bar)
460
+
461
+ canvas = MyCanvas.new(@frame, Wx::Point.new(0, 0), Wx::Size.new(100, 100), Wx::RETAINED|Wx::HSCROLL|Wx::VSCROLL)
462
+
463
+ # Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
464
+ canvas.set_scrollbars(20, 20, 50, 50)
465
+
466
+ @frame.canvas = canvas
467
+
468
+ @frame.centre(Wx::BOTH)
469
+ @frame.show()
470
+
471
+ @frame.set_status_text("Printing demo")
472
+
473
+ set_top_window(@frame)
474
+
475
+ @print_data = Wx::PrintData.new
476
+ @page_setup_data = Wx::PageSetupDialogData.new
477
+
478
+ return true
479
+ end
480
+
481
+ def on_exit
482
+ return true
483
+ end
484
+ end
485
+
486
+
487
+ MyApp.new.main_loop()
@@ -0,0 +1,27 @@
1
+ # wxRuby2 Sample Code. Copyright (c) 2007-???? Mario J. Steele
2
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
3
+
4
+ class Socket
5
+ # Socket#recv_packet()
6
+ #
7
+ # This method retrives 1kb of data from the socket. It uses
8
+ # IO#readpartial due to the fact, that IO#read() uses buffered IO,
9
+ # which can cause errors. Where as the IO#readpartial() will read up
10
+ # to the maximum of 1024 bytes from the socket, and return what it
11
+ # retrives.
12
+ def recv_packet()
13
+ self.readpartial(1024)
14
+ end
15
+
16
+ # Socket#send_packet()
17
+ #
18
+ # This method will send the packet, and ensure that a LF (0x0A) is at
19
+ # the end of the data to be sent, as this is used as the determination
20
+ # of the end of a packet.
21
+ def send_packet(msg)
22
+ if !msg.index("\n")
23
+ msg += "\n"
24
+ end
25
+ self.write(msg)
26
+ end
27
+ end
Binary file
Binary file