wxruby 1.9.5-universal-darwin-9

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