1 ;; @module guiserver.lsp
2 ;; @description Functions for programming GUIs and 2D graphics.
4 ;; @author Lutz Mueller, December 2007
6 ;; This module has been tested on MacOS X 10.8 and Windows XP, both with the
7 ;; Standard SUN Java RE v.1.5 (runtime environment) which came pre-installed on
10 ;; <h2>What is newLISP-GS</h2>
11 ;; <tt>guiserver.lsp</tt> is a module for interfacing to <tt>guiserver.jar</tt>
12 ;; a Java server application for generating GUIs (graphical user interfaces)
13 ;; and 2D graphics for newLISP applications. The <tt>guiserver.lsp</tt> module
14 ;; implements a newLISP API much smaller and more abstract than the APIs of the
15 ;; Java Swing libraries which it interfaces with. Because of this, GUI applications
16 ;; can be built much faster than when using the original Java APIs.
18 ;; <h2>Requirements</h2>
19 ;; At the beginning of the program file, include a 'load' statement for the module:
21 ;; (load "/usr/share/newlisp/guiserver.lsp")
25 ;; (load "c:/Program Files/newlisp/guiserver.lsp")
28 ;; <tt>guiserver.lsp</tt> expects the server <tt>guiserver.jar</tt> to be
29 ;; installed in <tt>/usr/share/newlisp</tt> on MacOS X and Unix OSs, and
30 ;; in <tt>C:\Program Files\newlisp</tt> on MS Windows systems. On Win32 the
31 ;; standard environment variable <tt>PROGRAMFILES</tt> is used to find the exact location
32 ;; of non-English installations of Windows.. Both, the <tt>guiserver.lsp</tt> and
33 ;; <tt>guiserver.jar</tt> are installed by default when installing newLISP with one of
34 ;; the binary installers available.
36 ;; <h3>Architecture of a newLISP GUI application</h3>
37 ;; A GUI application in newLISP is composed of four parts:
40 ;; <em>initialization</em> - this means starting the newLISP-GS 'guiserver.jar' and initializing
41 ;; communications with it. Only one function call is required to do this.
43 ;; <em>building widgets</em> - in this step windows, buttons, text fields etc., and
44 ;; all visual aspects of the GUI are described. newLISP newLISP-GS offers a wide range
45 ;; of different control widgets.
47 ;; <em>defining event actions</em> - in this step all the functions are defined to
48 ;; react to events coming from the GUI as a consequence of button pushes, keystrokes,
49 ;; mouse-movements etc.. These event actions send many commands back to the GUI
50 ;; to change information for the user, popup dialogs etc..
52 ;; <em>listening for events</em> - the newLISP program sits in a loop waiting for
53 ;; events and dispatching them to the defined event actions. Only one function call
54 ;; is required for this step.
58 ;; The following example application shows all the essential elements of a newLISP GUI
62 ;; ; button-demo.lsp - demonstrate the button control
64 ;; ;;;; initialization
65 ;; (load (append (env "NEWLISPDIR") "/guiserver.lsp"))
69 ;; ;;;; describe the GUI
70 ;; (gs:frame 'ButtonDemo 100 100 400 300 "Button demo")
71 ;; (gs:set-resizable 'ButtonDemo nil)
72 ;; (gs:panel 'ColorPanel 360 200)
73 ;; (gs:set-color 'ColorPanel (random) (random) (random))
74 ;; (gs:button 'aButton 'abutton-action "color")
75 ;; (gs:set-flow-layout 'ButtonDemo "center" 2 15)
76 ;; (gs:add-to 'ButtonDemo 'ColorPanel 'aButton)
77 ;; (gs:set-visible 'ButtonDemo true)
79 ;; ;;;; define actions
80 ;; (define (abutton-action id)
81 ;; (gs:set-color 'ColorPanel (random) (random) (random)))
83 ;; ;;;; listen for incoming action requests and dispatch
87 ;; </pre></blockquote>
89 ;; <h3>Application start</h3>
91 ;; ./button-demo ; on MacOS X and Unix
93 ;; newlisp button-demo ; on Win32
95 ;; By default guiserver.jar uses the ports 47011 and 47012, but this setting can be overwritten
96 ;; either by supplying a port number parameter to the 'gs:init' function or by overwriting the
97 ;; port number from the command-line. newLISP-GS will then use the port number supplied and the number
100 ;; ./button-demo 10001 ; on MacOS X and Unix
102 ;; newlisp button-demo 10001 ; on Win32
104 ;; newLISP-GS 'guiserver.jsr' will now use the ports '10001' and '10002'.
105 ;; Ports under <tt>1024</tt> should not be used, as many of them are already in use by other
106 ;; OS services and need administrator privileges to use them.
108 ;; A second method to start a newLISP-GS application starts the 'guiserver.jar' first, which then
109 ;; starts the newLISP application:
111 ;; Java -jar /usr/share/newlisp/guiserver.jar 47011 /usr/home/aUser/MyApplication.lsp
113 ;; A different port number can be used. Port numbers below 1024 need administrator
114 ;; permissions. Optionally a splash screen can be specified as the last parameter:
116 ;; Java -jar /usr/share/newlisp/guiserver.jar 47011 /home/apps/myapp.lsp /local/newLISP128.png
118 ;; The example specifies an image inside 'guiserver.jar'. Any other image path on the local file system
121 ;; On Win32 similar methods can be used replacing the appropriate file paths, but on Win32 Java jar files
122 ;; can also be treated as executables and executed directly without calling Java explicitly. By default
123 ;; 'guiserver.jar' and 'guiserver.lsp' are installed in 'c:\Program Files\newlisp\' or any other
124 ;; directory configured on a Win32 platform using the 'PROGRAMFILES' environment variable:
126 ;; "c:\Program Files\newlisp\guiserver.jar" 47011 c:\myprogs\MyApplication.lsp
128 ;; Quotes are necessary when spaces are present in the argument string. The example also assumes that
129 ;; 'newlisp.exe' is in the path for executables.
132 ;; <h2>Debugging</h2>
133 ;; <b>Tracing commands to newLISP-GS</b><br><br>
134 ;; For debugging purpose put the following directive at the beginning of your application
135 ;; or at the place from where to start tracing.
137 ;; (gs:set-trace true)
139 ;; Then start the application from a terminal or command shell window. Now newLISP-GS
140 ;; will output startup, version and connection messages and a trace for each 'gs:xxs' directive
141 ;; as it is received by the newLISP-GS dispatcher:
145 ;; listening on 47011
146 ;; accepted from 0.0.0.0
147 ;; connecting to 0.0.0.0 47012
148 ;; retrying to connect
150 ;; -> frame MAIN:ButtonDemo 100 100 400 300 QnV0dG9uIGRlbW8= nil
151 ;; -> set-resizable MAIN:ButtonDemo nil
152 ;; -> panel MAIN:ColorPanel 360 200
153 ;; -> set-color MAIN:ColorPanel 0 1 0 0.2
154 ;; -> button MAIN:aButton MAIN:abutton-action Y29sb3I=
155 ;; -> set-flow-layout MAIN:ButtonDemo center 2 15
156 ;; -> add-to MAIN:ButtonDemo MAIN:ColorPanel MAIN:aButton
157 ;; -> set-visible MAIN:ButtonDemo true
158 ;; -> set-color MAIN:ColorPanel 0.8401877172 0.3943829268 0.7830992238
160 ;; </blockquote></pre>
162 ;; Text strings for button names, icon paths and other texts are encode in
163 ;; Base64 strings as the first trace line for MAIN:ButtonDemo shows. To switch
164 ;; off tracing mode use:
166 ;; (gs:set-trace nil)
168 ;; Even if trace mode is switched off, wrong or missing parameters are still messaged
169 ;; by newLISP-GS in a small message box. After such an error the application and guiserver
170 ;; will exit. Unknown commands will be ignored. Functions which are not applicable to
171 ;; certain widgets will also pop up an error message box. In certain situations a
172 ;; function will have no effect, e.g. 'gs:set-size' or 'gs:set-color' sometimes do not
173 ;; have an effect, depending on how a widget is configured or depending on the layout
174 ;; which hosts the widget. Sometimes the platform look-and-feel overwrites colors.
177 ;; <b>Event handlers</b><br><br>
178 ;; For most widgets, event handlers must be defined. Sometimes an event handler is
179 ;; not required. In this case specify <tt>'gs:no-action</tt> as the event handler
180 ;; symbol. When developing programs it is useful to watch the event handler first
181 ;; before coding for it. This can be done easily by printing out event parameters:
184 ;; (gs:button 'aButton 'abutton-handler "press")
186 ;; (define (abutton-handler id)
188 ;; </pre></blockquote>
190 ;; Sometimes the same event handler function is attached to several widgets' keyboard
191 ;; or mouse events. Some of these events receive a greater number of parameters. There
192 ;; are two easy ways to discover the nature of an event:
195 ;; (define (the-handler)
197 ;; (println "->" p)))
198 ;; </pre></blockquote>
200 ;; The other method looks at the source of the event as it was transmitted by the newLISP-GS.
201 ;; This is useful to recognize the data types used in the event:
204 ;; (define (the-handler)
205 ;; (println gs:event))
206 ;; </pre></blockquote>
208 ;; All text from text fields are received as base64-encoded strings. E.g. the text:
209 ;; '"Hello World"' would be received as: '"SGVsbG8gV29ybGQ="':
212 ;; (gs:text-field 'TextField 'textfield-handler)
214 ;; (define (textfield-handler id text)
215 ;; (printnl id ": " (base64-dec text)))
216 ;; </pre></blockquote>
218 ;; When the text "Hello World" is entered in the text field, the following output
219 ;; would be generated:
222 ;; TextField: "Hello World"
223 ;; </pre></blockquote>
225 ;; In case the ESC key is pressed in the text field, the event handler would
226 ;; report 'nil' for the text field. A handler should therefore always check text
227 ;; for string contents before trying to apply the 'base64-dec' function on it.
230 ;; <h3>Coding considerations</h3>
231 ;; <b>mapping or applying 'gs:xxx' functions</b><br><br>
232 ;; Like any newLISP functions, 'gs:xxx' functions can be mapped or applied to lists of
233 ;; parameters using the newLISP 'map' and 'apply' functions. When doing this, make sure to
234 ;; map or apply the quoted <tt>'gs:xxx symbol</tt>, so the <tt>gs:xx</tt> functions
235 ;; get executed under the <tt>gs</tt> context, prefixing symbols in parameter lists
236 ;; correctly with the context prefix of their origin.
239 ;; (map 'gs:panel '(first second third fourth)) ; note quoted gs: function
240 ;; </blockquote></pre>
243 ;; <h2>Some shortcuts when writing 'gs:xxx' functions</h2>
244 ;; Due to the nature of transfer between newLISP and the guiserver as text, the following
245 ;; convenient shortcuts can be taken when writing functions:
249 ;; <li>Symbol ids of components can be expressed as strings.</li>
250 ;; <li>Number values can be expressed as strings.</li>
251 ;; <li>Numbers can be expressed as floats or integers.</li>
252 ;; <li>String constants for type and orientation constants can be given as symbols.</li>
256 ;; Here are some examples:
258 ;; (gs:panel 'ColorPanel 360 200)
260 ;; (gs:panel "ColorPanel" 360 200)
262 ;; (gs:panel "ColorPanel" "360" "200")
264 ;; (gs:panel "ColorPanel" 360.0 "200.00")
266 ;; (gs:set-flow-layout 'ButtonDemo "center" 2 15)
268 ;; (gs:set-flow-layout 'ButtonDemo 'center 2 15)
270 ;; Although the first form is preferred for clarity and readability, in some cases coding
271 ;; may be more efficient using the other forms.
273 ;; Except for the symbols used for action handlers, all symbols are used only by their
274 ;; face (name) value. This means that reserved symbols of the newLISP programming
275 ;; language can be used freely in symbol ids for all components, e.g:
277 ;; (gs:label 'name "Input here")
279 ;; The usage of the reserved symbol 'name' will not pose a problem.
281 ;; <h2>Return values</h2>
282 ;; The return value of all functions is usually the number of characters
283 ;; sent to newLISP-GS. In general, return values of 'gs:xxx' functions do not have
284 ;; any specific meaning and can be discarded. Only the functions 'gs:get-version',
285 ;; 'gs:get-screen' and 'gs:get-fonts' return their respective data and copy them
286 ;; also to the variables 'gs:version', 'gs:screen' and 'gs:fonts' for later access.
289 ;; <h2>Function overview</h2>
291 ;; <li><b>Initialization and application setup</b><br>
293 ;; (gs:init [<server-port>])
295 ;; The initialization function starts <tt>guiserver.jar</tt> which will listen to the <i>server-port</i>
296 ;; and initiate another connection on <tt>server-port + 1</tt> back to newLISP. If a <server-port>
297 ;; is not supplied <tt>guiserver</tt> will assume <tt>47011</tt> and <tt>47012</tt>.
299 ;; As the last statement in the application put:
303 ;; This function listens on <tt>47012</tt> (by default) for event messages from newLISP-GS
304 ;; and dispatches them to the user-defined action handlers. To avoid newLISP shutting down
305 ;; when the guiserver shuts down, use:
311 ;; Sometimes it is necessary to run other tasks while listening for events. In this case use
312 ;; 'gs:check-event', which will wait for certain amount of microseconds for an event
313 ;; to be executed. After the wait-time, it returns. The function is typically used in a loop:
316 ;; (while (gs:check-event 10000) ; check for 10 milli seconds
323 ;; The loop will exit when 'gs:check-event' returns 'nil' on communications errors, e.g.
324 ;; when the window's close button was clicked.
326 ;; <li><b>Containers</b><br>
327 ;; A <em>container</em> can contain any other container or control widget. Except for the
328 ;; <tt>menu-bar</tt> and the <tt>split-pane</tt>, containers can have a special layout-manager set
329 ;; with one of the three layout-manager function commands. By default containers have a flow layout. By
330 ;; nesting different containers and using different layout-manager settings, complex layouts
331 ;; can be configured. The function/command <tt>add-to</tt> is used to add components to containers.
334 ;; (gs:dialog <sym-id> <sym-parent-frame> <str-message> <int-width> <int-height> [<boolean-visible> [<boolean-modal>]])
335 ;; (gs:frame <sym-id> <int-x> <int-y> <int-width> <int-height> [<str-title> <boolean-visible>])
336 ;; (gs:menu-bar <sym-frame> [<sym-menu-1> ...])
337 ;; (gs:panel <sym-id> [<int-width> <int-height>])
338 ;; (gs:scroll-pane <sym-id> <sym-widget> [<int-width> <int-height>])
339 ;; (gs:split-pane <sym-id> <str-orientation> [<float-weight> [<float-location> [int-divider-size>]]])
340 ;; (gs:tabbed-pane <sym-id> <sym-action> <str-orientation> [<sym-widget> <sym-tab-title> ...])
341 ;; (gs:tool-bar <sym-frame> [<bool-floatable> <int-hgap> <int-vgap>])
342 ;; (gs:canvas <sym-id>)
343 ;; (gs:window <sym-id> <int-x> <int-y> <int-width> <int-height>)
346 ;; <li><b>Labels</b><br>
347 ;; Labels can have text or an image or both. A normal text <tt>label</tt> can have an icon
348 ;; added to it and a <tt>image-label</tt> can have text added to it. Labels don't initiate
349 ;; actions and can be placed in any container like all button-type widgets - buttons, checkboxes
350 ;; and menu items. A basic set of icon images is built into <tt>guiserver.jar</tt>,
351 ;; but user-supplied images and icons in <tt>.jpg</tt>, <tt>.png</tt> and <tt>.gif</tt> formats
354 ;; (gs:label <sym-id> <str-text> [<str-align> [<int-width> <int-height>]])
355 ;; (gs:image-label <sym-id> <str-icon-path> [<str-align>])
358 ;; <li><b>Control widgets</b><br>
359 ;; Except for the passive progress bar, all control widgets fire action requests to
360 ;; the newLISP program. These requests must be served to avoid error messages but can
361 ;; be defined as empty functions, if an action is not required:
363 ;; ; empty action definition
364 ;; (define (my-button-action) )
366 ;; ; action handler printing the name of the button pressed
367 ;; (define (my-button-action id) (println id " has been pressed"))
369 ;; All action events calls carry information about the widget, that initiated that the event,
370 ;; and event parameters like keystrokes, slider positions etc..
372 ;; (gs:button <sym-id> <sym-action> [<str-text> [<int-width> <int-height>]])
373 ;; (gs:check-box <sym-id> <sym-action> [<str-text> [<bool-selected>]])
374 ;; (gs:combo-box <sym-id> <sym-action> [<str-item-1> ...])
375 ;; (gs:combo-box <sym-id> <sym-action> [<list-str-items>])
376 ;; (gs:image-button <sym-id> <sym-action> <str-icon-path> [<str-down-icon-path> [<int-width> <int-height>]])
377 ;; (gs:list-box <sym-id> <sym-action> [<str-item-1> ...])
378 ;; (gs:list-box <sym-id> <sym-action> [<list-str-items>])
379 ;; (gs:menu <sym-id> <str-text>)
380 ;; (gs:menu-popup <sym-id> <str-text>)
381 ;; (gs:menu-item <sym-id> <sym-action> <str-text>)
382 ;; (gs:menu-item-check <sym-id> <sym-action> <str-text> [<bool-selected>])
383 ;; (gs:progress-bar <sym-id> <int-min> <in-max> <int-initial-value>)
384 ;; (gs:radio-button <sym-id> <sym-action> [<str-text> [<bool-selected>]])
385 ;; (gs:slider <sym-id> <sym-action> <str-orientation> <int-min> <int-max> <int-initial-value>)
386 ;; (gs:text-area <sym-id> <sym-action> [<int-width> <int-height>])
387 ;; (gs:text-field <sym-id> <sym-action> <int-columns>)
388 ;; (gs:text-pane <sym-id> <sym-action> <str-style> [<int-width> <int-height>])
389 ;; (gs:toggle-button <sym-id> <sym-action> [<str-text> <bool-selected>])
391 ;; For all button widgets, and the check box and menu-item widgets, icons can be set using
392 ;; the 'gs:set-icon' and 'gs:set-pressed-icon' functions.
395 ;; <li><b>Placing components in containers</b><br>
396 ;; For the flow and grid layouts the components are added in the sequence they are listed.
397 ;; The grid-layout fills the grid row by row starting with the left most column.
399 ;; (gs:add-to <sym-container> <sym-component> [<sym-component ...])
401 ;; For the border layout an orientation parameter is specified as either <tt>"north"</tt>,
402 ;; <tt>"west"</tt>, <tt>"center"</tt>, <tt>"east"</tt> or <tt>"south"</tt>.
404 ;; (gs:add-to <sym-container> [<sym-component> <str-orientation> ...])
408 ;; <li><b>Summary of commands</b><br>
409 ;; Most of the commands set special attributes of containers or control widgets.
410 ;; Not all functions can be applied to all containers and control widgets. A wrong
411 ;; application will either pop up an error message box or do nothing.
413 ;; Some functions will work on certain widgets only in certain situations. For example
414 ;; <tt>set-size</tt> will work not on components in a grid layout but on components
415 ;; in a flow layout. Some widgets have a preset background color which cannot be changed
416 ;; or is overwritten by the current 'gs:look-and-feel' settings.
419 ;; (gs:add-list-item <sym-list-combo> <str-text> [<str-text> ...])
420 ;; (gs:add-separator <sym-menu-tool-bar>)
421 ;; (gs:add-to <sym-container> <sym-component> [<sym-component ...])
422 ;; (gs:add-to <sym-container> <sym-component> <str-orientation> [<sym-component> <str-orientation> ...])
423 ;; (gs:append-text <sym-id> <str-text>)
424 ;; (gs:check-event <int-microseconds>)
425 ;; (gs:clear-list <sym-id>)
426 ;; (gs:clear-text <sym-id>)
427 ;; (gs:copy-text <sym-id>)
428 ;; (gs:cut-text <sym-id>)
429 ;; (gs:destroy-shell <sym-text-area>)
430 ;; (gs:disable <sym-id-1> [<sym-id-2> ...])
431 ;; (gs:dispose <sym-id>)
432 ;; (gs:dispose-splash)
433 ;; (gs:enable <sym-id-1> [<sym-id-2> ...])
434 ;; (gs:eval-shell <sym-text-area> <str-commmand>)
435 ;; (gs:find-text <sym-id> <str-text> <sym-action> [<str-direction>]])
436 ;; (gs:frame-closed <sym-id> <sym-action>)
438 ;; (gs:get-bounds <sym-id>)
439 ;; (gs:get-font-metrics <sym-id> <str-text>)
441 ;; (gs:get-selected-text <sym-id> <sym-action>)
442 ;; (gs:get-text <sym-id> [<sym-action>])
443 ;; (gs:get-text-position <sym-id>)
445 ;; (gs:goto-text <sym-id> <sym-row> <sym-column>)
446 ;; (gs:insert-list-item <sym-list-combo> <str-text> <int-index> [<str-text> <int-index>])
447 ;; (gs:insert-tab <sym-tabbed-pane> <sym-component> [<str-text> [<int-index> [<str-icon-path>]])
448 ;; (gs:insert-text <sym-id> <str-text> <int-pos>)
449 ;; (gs:layout <sym-container>)
450 ;; (gs:load-text <sym-id> <str-path>)
452 ;; (gs:paste-text <sym-id> [<str-text>])
453 ;; (gs:redo-text <sym-id>)
454 ;; (gs:remove-from <sym-container> <sym-component> [<sym-component> ...])
455 ;; (gs:remove-list-item <sym-list-combo> <int-index> [<int-index> ...])
456 ;; (gs:remove-tab <sym-tabbed-pane> <int-index>)
457 ;; (gs:request-focus <sym-id>)
458 ;; (gs:run-shell <sym-text-area> <str-commmand>)
459 ;; (gs:select-list-item <sym-id> <str-item> [<boolean-flag>])
460 ;; (gs:select-text <sym-id> <int-from> [<int-to>])
461 ;; (gs:set-accelerator <sym-menu-item> <str-keystroke>)
462 ;; (gs:set-background <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
463 ;; (gs:set-background <sym-id> <list-rgb> [<float-alpha>])
464 ;; (gs:set-bevel-border <sym-panel> <str-type>)
465 ;; (gs:set-border-layout <sym-container> [<int-hgap> <int-vgap>])
466 ;; (gs:set-caret <sym-id> <int-offset>)
467 ;; (gs:set-caret-color <sym-id> <list-rgb>)
468 ;; (gs:set-caret-color <sym-id> <float-red> <float-green> <float-blue>)
469 ;; (gs:set-color <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
470 ;; (gs:set-color <sym-id> <list-rgb> [<float-alpha>])
471 ;; (gs:set-cursor <sym-id> <str-shape>)
472 ;; (gs:set-editable <sym-id> <boolean-flag>)
473 ;; (gs:set-flow-layout <sym-container> [<str-alignment> [<int-hgap> <int-vgap>]])
474 ;; (gs:set-font <sym-id> <str-family> <int-size> <str-type>)
475 ;; (gs:set-foreground <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
476 ;; (gs:set-foreground <sym-id> <list-rgb> [<float-alpha>])
477 ;; (gs:set-grid-layout <sym-container> <int-columns> <int-rows> [<int-hgap> <int-vgap>])
478 ;; (gs:set-icon <sym-id> <str-icon-path> [<int-index>])
479 ;; (gs:set-look-and-feel <str-look>)
480 ;; (gs:set-resizable <sym-frame> <boolean-flag>)
481 ;; (gs:set-pressed-icon <sym-id> <str-icon-path>)
482 ;; (gs:set-selected <sym-id> <boolean-flag>)
483 ;; (gs:set-size <sym-id> <int-width> <int-height>)
484 ;; (gs:set-selection-color <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
485 ;; (gs:set-syntax <sym-id> <str-type>)
486 ;; (gs:set-syntax-colors <list-rgb-comments> <list-rgb-keywords> <list-rgb-string> <list-rgb-number> <list-rgb-quoted> <list-rgb-prantheses>)
487 ;; (gs:set-tab-size <sym-id> <int-size>)
488 ;; (gs:set-text <sym-id> <str-text> [<int-index>])
489 ;; (gs:set-titled-border <sym-component> <str-title>)
490 ;; (gs:set-tool-tip <sym-id> <str-text>)
491 ;; (gs:set-trace <boolean-flag>)
492 ;; (gs:set-utf8 <boolean-flag>)
493 ;; (gs:set-value <sym-id> <int-value>)
494 ;; (gs:set-visible <sym-id> <boolean-visible>)
495 ;; (gs:undo-text <sym-id>)
496 ;; (gs:undo-enable <sym-id> <boolean-enabled>)
499 ;; <li><b>Special dialogs</b><br>
500 ;; These are standard dialogs for opening and saving files and for choosing colors.
501 ;; Each dialog when closed fires an event for which a handler function must be
502 ;; defined by the newLISP program.
504 ;; (gs:color-dialog <sym-parent-frame> <sym-action> <str-title> <float-red> <float-green> <float-blue>)
505 ;; (gs:message-dialog <sym-parent-frame> <str-title> <str-message> [<str-type> [<str-icon-path>]])
506 ;; (gs:confirm-dialog <sym-parent-frame> <sym-action> <str-title> <str-message> [<str-type>])
507 ;; (gs:open-file-dialog <sym-parent-frame> <sym-action> [<str-directory> [<str-mask> <str-description>]])
508 ;; (gs:save-file-dialog <sym-parent-frame> <sym-action> [<str-directory> [<str-initial-file> [<str-mask> <str-description>]]])
511 ;; <li><b>2D Graphics functions</b><br>
512 ;; Every call to a 'gs:draw-xxx' or 'gs:fill-xxx' function will create a new graphics object, which
513 ;; will persist until destroyed by a call to 'gs:delete-tag'. Graphics objects are animated
514 ;; using the tag operations 'gs:move-tag', 'gs:rotate-tag', 'gs:scale-tag' and
515 ;; 'gs:shear-tag' or using 'gs:hide-tag' and 'gs:show-tag'.
517 ;; Any 'gs:draw-xxx' or 'gs:fill-xxx' will create graphics objects but not force a screen update.
518 ;; The canvas is automatically redrawn when made visible for the first time using 'gs:set-visible' or
519 ;; after a call to 'gs:update'. Redrawing is also forced when resizing the window which hosts the canvas
520 ;; or any action covering and uncovering the canvas.
522 ;; After all tag operations redrawing is initiated by default, but it can be forced off by spcifying
523 ;; 'nil' as the last parameter in a 'gs:xxx-tag' command. Suppressing immediate redraw is useful to avoid
524 ;; flicker when a batch of tag operations is performed.
526 ;; Every graphics object (line, shape, text, or image) carries a group tag. Objects are deleted
527 ;; using 'gs:delete-tag' and will disappear immediately from the canvas. Using 'gs:move-tag'
528 ;; lines, shapes, text and images can be moved to a different position.
531 ;; (gs:color-tag <sym-tag> <list-rgb> [<boolean-repaint>])
532 ;; (gs:delete-tag <sym-tag>[<boolean-repaint>])
533 ;; (gs:draw-arc <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-start> <int-angle> [<list-rgb>])
534 ;; (gs:draw-circle <sym-tag> <int-x> <int-y> <int-radius> [<list-rgb>])
535 ;; (gs:draw-ellipse <sym-tag> <int-x> <int-y> <int-radius-x> <int-radius-y> [<list-rgb>])
536 ;; (gs:draw-image <sym-tag> <str-path> <int-x> <int-y> [<int-width> <int-height>])
537 ;; (gs:draw-line <sym-tag> <int-x1> <int-y1> <int-x2> <int-y2> [<list-rgb>])
538 ;; (gs:draw-path <sym-tag> <list-points> [<list-rgb>])
539 ;; (gs:draw-polygon <sym-tag> <list-points> [<list-rgb>])
540 ;; (gs:draw-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> [<list-rgb>])
541 ;; (gs:draw-round-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-arc-width> <int-arc-height> [<list-rgb>])
542 ;; (gs:g <sym-tag> <str-text> <int-x> <int-y> [<list-rgb> [<float-angle>]])
543 ;; (gs:export <str-path-file> [<int-width> <int-height>])
544 ;; (gs:fill-arc <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-start> <int-angle> [<list-rgb>])
545 ;; (gs:fill-circle <sym-tag> <int-x> <int-y> <int-radius> [<list-rgb>])
546 ;; (gs:fill-ellipse <sym-tag> <int-x> <int-y> <int-radius-x> <int-radius-y> [<list-rgb>])
547 ;; (gs:fill-polygon <sym-tag> <list-points> [<list-rgb>])
548 ;; (gs:fill-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> [<list-rgb>])
549 ;; (gs:fill-round-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-arc-width> <int-arc-height> [<list-rgb>])
550 ;; (gs:hide-tag <sym-tag> [<boolean-repaint>])
551 ;; (gs:move-tag <sym-tag> <int-dx> <int-dy> [<boolean-repaint>])
552 ;; (gs:reorder-tags <list-tags>)
553 ;; (gs:rotate-tag <sym-tag> <float theta> <int-x> <int-y> [<boolean-repaint>])
554 ;; (gs:save-text <sym-id> <str-path>)
555 ;; (gs:scale-tag <sym-tag> <float-x> <float-y> [<boolean-repaint>])
556 ;; (gs:shear-tag <sym-tag> <float-x> <float-y> [<boolean-repaint>])
557 ;; (gs:show-popup <sym-tag> <sym-host> <int-x> <int-y>)
558 ;; (gs:show-tag <sym-tag> [<boolean-repaint>])
559 ;; (gs:set-canvas <sym-tag>)
560 ;; (gs:set-paint <list-rgb>)
561 ;; (gs:set-rotation <float-angle>)
562 ;; (gs:set-scale <int-x> <int-y>)
563 ;; (gs:set-stroke <float-width> [<str-cap> [<str-join> [<float-miterlimit>]]])
564 ;; (gs:set-translation <int-x> <int-y>)
565 ;; (gs:set-anti-aliasing <boolean-flag>)
566 ;; (gs:translate-tag <sym-tag> <int-x> <int-y> [<boolean-repaint>])
571 ;; <li><b>Events</b><br>
572 ;; Additionally to the event actions registered when creating a widget,
573 ;; the canvas, windows and dialogs can fire events as a result of key or mouse
574 ;; actions or when the position or size of a windows or dialog has changed.
577 ;; (gs:key-event <sym-id> <sym-action>)
578 ;; (gs:mouse-clicked <sym-canvas> <sym-action> [<boolean-tags>])
579 ;; (gs:mouse-dragged <sym-canvas> <sym-action>)
580 ;; (gs:mouse-event <sym-id> <sym-action>)
581 ;; (gs:mouse-moved <sym-canvas> <sym-action> [<boolean-tags>])
582 ;; (gs:mouse-pressed <sym-canvas> <sym-action> [<boolean-tags>])
583 ;; (gs:mouse-released <sym-canvas> <sym-action> [<boolean-tags>])
584 ;; (gs:mouse-wheel <sym-canvas> <sym-action>)
585 ;; (gs:window-closed <sym-id> <sym-action>)
586 ;; (gs:window-moved <sym-id> <sym-action>)
587 ;; (gs:window-resized <sym-id> <sym-action>)
591 ;; <li><b>Built-in icons and images</b><br>
592 ;; The 'guiserver.jar' file has the following icons and images built in. Each of
593 ;; them is prefixed with the path '/local/'. For example '/local/newLISP128.png'
594 ;; addresses the newLISP logo of size 128x128. To address images outside of
595 ;; 'guiserver.jar', use a normal file path suitable to your platform. On Win32
596 ;; use forward slashes instead of backslashes.
617 ;; folder-closed-down32.png
618 ;; folder-closed32.png
619 ;; folder-opened-down32.png
620 ;; folder-opened32.png
621 ;; font-book-down32.png
628 ;; newLISP-down32.png
634 ;; newLISPsplashWin.png
637 ;; pressedbutton32.png
639 ;; restart-down32.png
650 ;; <li><b>Predefined colors</b><br>
651 ;; The following colors are predefined:
653 ;; Name rgb components
654 ;; ---- --------------
655 ;; gs:black (0.0 0.0 0.0)
656 ;; gs:blue (0.0 0.0 1.0)
657 ;; gs:cyan (0.0 1.0 1.0)
658 ;; gs:darkGray (0.2509804 0.2509804 0.2509804)
659 ;; gs:gray (0.5019608 0.5019608 0.5019608)
660 ;; gs:green (0.0 1.0 0.0)
661 ;; gs:lightGray (0.7529412 0.7529412 0.7529412)
662 ;; gs:magenta (1.0 0.0 1.0)
663 ;; gs:orange (1.0 0.78431374 0.0)
664 ;; gs:pink (1.0 0.6862745 0.6862745)
665 ;; gs:red (1.0 0.0 0.0)
666 ;; gs:white (1.0 1.0 1.0)
667 ;; gs:yellow (1.0 1.0 0.0)
670 ;; Colors in newLISP-GS can be specified as three (four with alpha component) single
671 ;; numbers or as a list of the three RGB values followed by the alpha channel number.
673 ;; (gs:set-background 'aPanel gs:magenta
674 ;; (gs:set-background 'aPanel 1.0 0 1
675 ;; (gs:set-background 'aPanel '(1 0 1)
677 ;; All of the above statements will produce the same background color on the <tt>aPanel</tt>.
678 ;; <li><b>Sound API</b><br>
680 ;; (gs:play-sound <str-file-path>)
684 (set 'gs
:black
'(0.0
0.0 0.0))
685 (set 'gs
:blue
'(0.0
0.0 1.0))
686 (set 'gs
:cyan
'(0.0
1.0 1.0))
687 (set 'gs
:darkGray
'(0.2509804
0.2509804 0.2509804))
688 (set 'gs
:gray
'(0.5019608
0.5019608 0.5019608))
689 (set 'gs
:green
'(0.0
1.0 0.0))
690 (set 'gs
:lightGray
'(0.7529412
0.7529412 0.7529412))
691 (set 'gs
:magenta
'(1.0
0.0 1.0))
692 (set 'gs
:orange
'(1.0
0.78431374 0.0))
693 (set 'gs
:pink
'(1.0
0.6862745 0.6862745))
694 (set 'gs
:red
'(1.0
0.0 0.0))
695 (set 'gs
:white
'(1.0
1.0 1.0))
696 (set 'gs
:yellow
'(1.0
1.0 0.0))
699 (if (= ostype
"Win32")
700 ; on some Win32 systems the jar -> javaw.exe association my be missing, the use the following:
701 ;(set 'server-path (string "javaw.exe -jar " "'\"" (env "PROGRAMFILES") "/newlisp/guiserver.jar\"'"))
702 (set 'server-path
(string "'\"" (env "PROGRAMFILES") "/newlisp/guiserver.jar\"'"))
703 (set 'server-path
"/usr/share/newlisp/guiserver.jar"))
707 ;; @syntax (gs:add-list-item <sym-list-combo> <str-text> [<str-text> ...])
708 ;; @param <sym-list-combo> The name of the combo box or list box to which text entries are added.
709 ;; @param <str-text> The text of the entry to be added.
711 ;; Items are added in the same sequence as they appear in the 'gs:add-list' command and added to the
712 ;; end of the existing list of items.
714 (define (add-list-item comp
)
715 (let (s (string "add-list-item " comp
" "))
717 (write-buffer s
(string (base64-enc item
) " ")))
718 (write-buffer s
"\n")
722 ;; @syntax (gs:add-separator <sym-menu-tool-bar>)
723 ;; @param <sym-menu-tool-bar> The name of the tool bar or menu bar to which a spacer entry is added.
725 ;; Depending on the OS platform the separator may not be visible and only occupy space before the next
726 ;; component added to the tool or menu bar.
728 (define (add-separator bar
)
729 (net-send out
(string "add-separator " bar
"\n"))
732 ;; @syntax (gs:add-to <sym-container> <sym-component> [<sym-componentl> ...])
733 ;; @param <sym-container> The name of the container to which components are added.
734 ;; @param <sym-component> One or more symbols of the components to add.
737 ;; @syntax (gs:add-to <sym-container> <sym-component> <str-orientation> [<sym-component> <str-orientation> ...])
738 ;; @param <sym-container> The name of the container to which components are added.
739 ;; @param <sym-component> The name of a component to add.
740 ;; @param <str-orientation> The orientation of a component to add in border layout, '"north"', '"west"', '"center"', '"east"' or '"south"'.
743 (let (s (string "add-to " id
" "))
745 (write-buffer s
(string item
" ")))
746 (write-buffer s
"\n")
751 ;; @syntax (gs:append-text <sym-id> <str-text>)
752 ;; @param <sym-id> The name of the text field or text area to which text is appended.
753 ;; @param <str-text> The text to be appended.
755 (define (append-text id text
)
756 (net-send out
(string "append-text " id
" " (base64-enc text
) "\n"))
759 ;; @syntax (gs:button <sym-id> <sym-action> [<str-text> [<int-width> <int-height>]])
760 ;; @param <sym-id> The name of the button.
761 ;; @param <sym-action> The name of the event handler.
762 ;; @param <str-icon-path> An optional text for the button.
763 ;; @param <int-width> The optional width of the button.
764 ;; @param <int-height> The optional height of the button.
766 (define (button id action text x y
)
769 (net-send out
(string "button " id
" " action
" " (base64-enc text
) " " x
" " y
"\n"))
770 (net-send out
(string "button " id
" " action
" " (base64-enc text
) "\n")))
771 (net-send out
(string "button " id
" " action
"\n"))
775 ;; @syntax (gs:canvas <sym-id>)
776 ;; @param <sym-id> The name of the canvas.
778 ;; A canvas is a pane for drawing and receiving mouse input events. For most
779 ;; applications a background color should be specified for the canvas using
780 ;; 'gs:set-background' or 'gs:set-color' which call the same function internally. The
781 ;; background forces the canvas to be cleared before redrawing components
782 ;; which have been moved, rotated, scaled or deleted. In applications where
783 ;; this is not desired but a background color is still required, the background
784 ;; color can be specified for the container hosting the canvas. The canvas
785 ;; background will then appear in the color of the container, but erasing
786 ;; the canvas before repainting is not enforced.
788 ;; A canvas can also be used to host widgets like buttons etc.. In this case
789 ;; the canvas is treated like a 'gs:pane', with a flow layout by default.
790 ;; Similar to a panel created with 'gs:pane' other layouts can be set.
792 ;; When widgets are present on a canvas they appear to be floating over
793 ;; the drawing. See the file 'textrot-demo.lsp' for an example.
795 (define (canvas id parent
)
796 (set 'gs
:currentCanvas id
)
797 (net-send out
(string "canvas " id
"\n"))
800 ;; @syntax (gs:check-box <sym-id> <sym-action> [<str-text> [<bool-selected>]])
801 ;; @param <sym-id> The name of the check box.
802 ;; @param <sym-action> The name of the event handler.
803 ;; @param <str-text> The text of the check box.
804 ;; @param <bool-selected> An optional flag indicating the selection state 'true' or 'nil' (default).
807 (define (check-box id action text selected
)
809 (net-send out
(string "check-box " id
" " action
" " (base64-enc text
) " " selected
"\n"))
810 (net-send out
(string "check-box " id
" " action
"\n")))
813 ;; @syntax (gs:check-event <int-microseconds>)
814 ;; @param <int-microseconds> Wait for for an event a maximum of <int-microseconds> and execute it.
816 ;; The function 'gs:check-event' is used as an alternative to 'gs:listen' when the application
817 ;; is performing some activity while waiting for user input from the GUI. Typically
818 ;; 'gs:check-event' is used in a loop, which performs some other task and at the same time
819 ;; checks for events from the GUI part of the application. Like 'gs:listen' the function will
820 ;; force an exit of the application when communication between the newLISP-GS and the newLISP
821 ;; application process fails.
824 ;; (while (gs:check-event 10000) ; check for 10 milliseconds
829 (define (check-event us
)
830 (if (net-select in
"read" us
)
831 (if (net-receive in
'event
1000000000 "\n")
837 ;; @syntax (gs:clear-list <sym-id>)
838 ;; @param <sum-id> The name of the list component in which to clear all entries.
840 (define (clear-list id
)
841 (net-send out
(string "clear-list " id
"\n"))
844 ;; @syntax (gs:clear-text <sym-id>)
845 ;; @param <sum-id> The name of the component in which to clear the text.
847 (define (clear-text id
)
848 (net-send out
(string "clear-text " id
"\n"))
851 ;; @syntax (gs:copy-text <sym-id>)
852 ;; @param <sum-id> The name of the text component from which to copy the selection to the clipboard.
854 (define (copy-text id
)
855 (net-send out
(string "copy-text " id
"\n"))
858 ;; @syntax (gs:cut-text <sym-id>)
859 ;; @param <sym-id-text> The name of the text component from which to cut selected text and place it on the clipboard..
861 (define (cut-text id
)
862 (net-send out
(string "cut-text " id
"\n"))
866 ;; @syntax (gs:color-dialog <sym-parent-frame> <sym-action> <str-title> <float-red> <float-green> <float-blue>)
867 ;; @param <sym-parent-frame> The name symbol of the parent frame.
868 ;; @param <sym-action> The symbol of the handler to call when leaving the dialog
869 ;; @param <str-title> The title of the color dialog.
870 ;; @param <float-red> The initial red color component.
871 ;; @param <float-green> The initial green color component.
872 ;; @param <float-blue The initial blue color component.
874 (define (color-dialog parent action title red green blue
)
875 (net-send out
(string "color-dialog " parent
" " action
" " (base64-enc title
) " " red
" " green
" " blue
"\n"))
879 ;; @syntax (gs:color-tag <sym-tag> <list-color> [<boolean-update>])
880 ;; @param <sym-tag> The name tage of the shape(s) to set a new color.
881 ;; @param <list-color> The new color as a list of 3 numbers for the rgb components.
882 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
884 (define (color-tag tag color
(update true
))
885 (net-send out
(string "color-tag " gs
:currentCanvas
" " tag
" "
886 (color 0) " " (color 1) " " (color 2) " " update
"\n"))
889 ;; @syntax (gs:combo-box <sym-id> <sym-action> [<str-item-1> ...])
890 ;; @param <sym-id> The name of the combo box.
891 ;; @param <sym-action> The name of the event handler.
892 ;; @param <str-item> Zero, one or more text entries in the combo box.
893 ;; @syntax (gs:combo-box <sym-id> <sym-action> [<list-str-items>])
894 ;; @param <sym-id> The name of the combo box.
895 ;; @param <sym-action> The name of the event handler.
896 ;; @param <list-str-items> Zero, one or more text entries in a list.
898 (define (combo-box id action
)
899 (let ( s
(string "combo-box " id
" " action
" ")
900 entries
(if (list?
(args 0)) (args 0) (args)) )
901 (dolist (item entries
)
902 (write-buffer s
(string (base64-enc item
) " ")))
903 (write-buffer s
"\n")
907 ;; @syntax (gs:confirm-dialog <sym-parent-frame> <sym-action> <str-title> <str-message> [<str-type>])
908 ;; @param <sym-parent-frame> The symbol name of the parent frame.
909 ;; @param <sym-action> The action to perform when the diaog is closed.
910 ;; @param <str-title> The title of the message box.
911 ;; @param <str-message> The message in the message box.
912 ;; @param <str-type> The type of the message box.
914 ;; The type of the message box can be one of: '"yes-no"', '"yes-no-cancel"'
915 ;; On return of the message box <sym-action> carries one of the responses <tt>0</tt> for the yes-,
916 ;; <tt>1</tt> for the no- or <tt>3</tt> for the cancel-button.
918 (define (confirm-dialog parent action title message
(type plain
))
919 (net-send out
(string "confirm-dialog " parent
" " action
" "
920 (base64-enc title
) " " (base64-enc message
) " " type
"\n"))
923 ;; @syntax (gs:delete-tag <sym-tag> [<boolean-repaint>])
924 ;; @param <sym-tag> The tag group to be deleted.
925 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
927 ;; Deletes all 2D objects (lines, shapes, text, images) tagged with <sym-tag>.
929 ;; Each time a 'gs:draw-xxx' or 'gs:fill-xxx' function is called a graphical
930 ;; object is created. The tag used during creation is a way to address one
931 ;; or more of these objects. See the file 'mouse-demo.lsp' for an example.
933 (define (delete-tag tag
(repaint true
))
934 (net-send out
(string "delete-tag " gs
:currentCanvas
" " tag
" " repaint
"\n"))
937 ;; @syntax (gs:destroy-shell <sym-text-area>)
938 ;; @param <sym-text-area> The name of the text component for which the shell process is destroyed.
940 (define (destroy-shell id
)
941 (net-send out
(string "destroy-shell " id
"\n"))
944 ;; @syntax (gs:dialog <sym-id> <sym-parent> <str-title> <int-width> <int-height> [<boolean-visible> [<boolean-modal>]])
945 ;; @param <sym-id> The name of the dialog
946 ;; @param <sym-parent> The name of the parent frame.
947 ;; @param <str-title> The title string of the dialog frame.
948 ;; @param <int-width> The width of the dialog frame.
949 ;; @param <int-height> The height of the dialog frame.
950 ;; @param <boolean-visible> The optional flag with a value of 'true' or 'nil' for visibility of the dialog.
951 ;; @param <boolean-modal> The optional flag with a value of 'true' or 'nil' for modality of the dialog.
953 ;; Initially the dialog should not be visible until all widgets are added to it.
954 ;; When no flags for visibility and modality are specified, 'nil' is assumed. A modal dialog will
955 ;; prevent input in the parent window. Components can be added to a dialog using 'gs:add-to'.
956 ;; Use the 'gs:set-border-layout', 'ga:set-flow-layout' or 'gs:set-grid-layout' to set a specific
959 (define (dialog id parent title width height visible modal
)
960 (net-send out
(string "dialog " id
" " parent
" " (base64-enc title
) " " width
" " height
" " visible
" " modal
"\n"))
963 ;; @syntax (gs:disable <sym-id-1> [sym-id-2 ...])
964 ;; @param <sym-id> The name of the component to disable.
966 ;; Disabled components are grayed and do not accept input.
971 (write-buffer s
(string item
" ")))
972 (write-buffer s
"\n")
977 ;; @syntax (gs:dispose <sym-id>)
978 ;; @param <sym-id> The name of the component to dispose of.
981 (net-send out
(string "dispose " id
"\n"))
984 ;; @syntax (gs:dispose-splash)
986 ;; A splash screen can be specified when starting the newLISP-GS process before newLISP.
987 ;; The function 'gs:dispose-splash' is used to turn off the splash image after
988 ;; the newLISP GUI application has started.
991 ;; java -jar /usr/share/newlisp/guiserver.jar 4711 program.lsp /local/newLISP128.png
993 ;; java -jar "c:\Program Files\newlisp\guiserver.jar" 4711 "newlisp program.lsp" /local/newLISPsplashWin.png
995 ;; The example starts newLISP-GS with an application 'program.lsp' and a splash
996 ;; screen showing the built-in newLISP logos and using port 4711. Instead, the full pathname
997 ;; of a different image file can be specified. Inside 'program.lsp' the function
998 ;; 'gs:dispose-splash' or a mouse click on the image will turn off the splash screen.
999 ;; For 'program.lsp' the full pathname may be necessary. On Win32 quotes are necessary to bracket
1000 ;; arguments to 'guiserver.jar' which contain spaces.
1002 (define (dispose-splash)
1003 (net-send out
"dispose-splash System\n")
1006 ;; @syntax (gs:draw-arc <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-start> <int-angle> [<list-rgb>])
1007 ;; @param <sym-tag> The tag group of the arc.
1008 ;; @param <int-x> The X position of the arc.
1009 ;; @param <int-y> The Y position of the arc.
1010 ;; @param <int-width> The width of the arc.
1011 ;; @param <int-height> The height of the arc.
1012 ;; @param <int-start-angle> The start angle of the arc in 0 to 360 degrees.
1013 ;; @param <int-arc-angle> The opening angle of the arc in 0 to 360 degrees.
1014 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components
1016 ;; The resulting arc begins at <int-start-angle> and extends for <int-arc-angle degrees>,
1017 ;; using the current color. Angles are interpreted such that 0 degrees is at the 3 o'clock
1018 ;; position. A positive value indicates a counter-clockwise rotation while a negative value
1019 ;; indicates a clockwise rotation.
1021 ;; The center of the arc is the center of the rectangle whose origin is (x, y) and whose size
1022 ;; is specified by the width and height arguments.
1024 ;; The resulting arc covers an area <int-width> pixels wide by <int-height> pixels tall.
1026 (define (draw-arc id x y width height start angle color
)
1028 (net-send out
(string "draw-arc " gs
:currentCanvas
" " id
" " x
" " y
" "
1029 width
" " height
" " start
" " angle
" "
1030 (color 0) " " (color 1) " " (color 2) "\n"))
1031 (net-send out
(string "draw-arc " gs
:currentCanvas
" " id
" " x
" " y
" "
1032 width
" " height
" " start
" " angle
"\n"))
1037 ;; @syntax (gs:draw-circle <sym-tag> <int-x> <int-y> <int-radius> [<list-rgb>])
1038 ;; @param <sym-tag> The tag group of the circle.
1039 ;; @param <int-x> The X position of the circle center.
1040 ;; @param <int-y> The Y position of the circle center.
1041 ;; @param <int-radius> The radius of the circle.
1042 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components
1044 ;; Creates the outline of a circle. The color numbers must be entered in list form.
1045 ;; If no <list-rgb> is used the current paint specified with 'gs:set-paint' is used.
1047 (define (draw-circle tag x y radius color
)
1049 (net-send out
(string "draw-circle " gs
:currentCanvas
" "
1050 tag
" " x
" " y
" " radius
" " (color 0) " " (color 1) " " (color 2) "\n"))
1051 (net-send out
(string "draw-circle " gs
:currentCanvas
" "
1052 tag
" " x
" " y
" " radius
"\n"))
1056 ;; @syntax (gs:draw-ellipse <sym-tag> <int-x> <int-y> <int-radius-x> <int-radius-y> [<list-rgb>])
1057 ;; @param <sym-tag> The tag group of the ellipse.
1058 ;; @param <int-x> The X position of the ellipse center.
1059 ;; @param <int-y> The Y position of the ellipse center.
1060 ;; @param <int-radius-x> The radius of the ellipse.
1061 ;; @param <int-radius-y> The radius of the ellipse.
1062 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components
1064 ;; Creates the outline of an ellipse. The color numbers must be enterd in list form.
1065 ;; If no <list-rgb> is used the current paint specified with 'gs:set-paint' is used.
1067 (define (draw-ellipse tag x y radius-x radius-y color
)
1069 (net-send out
(string "draw-ellipse " gs
:currentCanvas
" "
1070 tag
" " x
" " y
" " radius-x
" " radius-y
" " (color 0) " " (color 1) " " (color 2) "\n"))
1071 (net-send out
(string "draw-ellipse " gs
:currentCanvas
" "
1072 tag
" " x
" " y
" " radius-x
" " radius-y
"\n"))
1076 ;; @syntax (gs:draw-image <sym-tag> <str-path> <int-x> <int-y> [<int-width> <int-height>])
1077 ;; @param <sym-tag> The tag group of the image.
1078 ;; @param <int-x> The X position of the image top left corner.
1079 ;; @param <int-y> The Y position of the image top left corner.
1080 ;; @param <int-width> The optional width in which to draw the image.
1081 ;; @param <int-height> The optional height in which to draw the image.
1083 ;; When <int-width> and <int-height> parameters are specified and they are not
1084 ;; equal to the original size of the image (measured in pixels) the image will
1085 ;; be displayed in either compressed or zoomed form.
1087 (define (draw-image tag path x y width height
)
1088 (if (and width height
)
1089 (net-send out
(string "draw-image " gs
:currentCanvas
" " tag
" "
1090 (base64-enc path
) " " x
" " y
" " width
" " height
"\n"))
1091 (net-send out
(string "draw-image " gs
:currentCanvas
" " tag
" "
1092 (base64-enc path
) " " x
" " y
"\n"))
1096 ;; @syntax (gs:draw-line <sym-tag> <int-x1> <int-y1> <int-x2> <int-y2> [<list-rgb>])
1097 ;; @param <sym-tag> The tage of the line.
1098 ;; @param <int-x1> The X position of the first point.
1099 ;; @param <int-y1> The Y position of the first point.
1100 ;; @param <int-x2> The X position of the second point.
1101 ;; @param <int-y2> The Y position of the second point.
1103 ;; Draws a line. The color numbers must be entered in list form.
1104 ;; If no <list-rgb> is used the current paint specified with 'gs:set-paint' is used.
1106 (define (draw-line tag x1 y1 x2 y2 color
)
1108 (net-send out
(string "draw-line " gs
:currentCanvas
" " tag
" "
1109 x1
" " y1
" " x2
" " y2
" " (color 0) " " (color 1) " " (color 2) "\n"))
1113 ;; @syntax (gs:draw-path <sym-tag> <list-points> [<list-rgb>])
1114 ;; @param <sym-tag> The tage group of the path.
1115 ;; @param <list-points> The list of x and y coordinates of the points.
1117 ;; Draws a path with the points found in <list-points>.
1120 ;; (gs:draw-path 'P '(1 0 2 2 3 0))
1122 ;; The example will draw an upwards-pointing triangle without base at the
1123 ;; points '1,0', '2,2' and '3,0'
1125 (define (draw-path tag points color
)
1127 (let (s (string "draw-path " gs
:currentCanvas
" " tag
" " (/ (length points
) 2) " "))
1129 (write-buffer s
(string p
" ")))
1130 (write-buffer s
(string (color 0) " " (color 1) " " (color 2) "\n"))
1133 (let (s (string "draw-path " gs
:currentCanvas
" " tag
" " (/ (length points
) 2) " "))
1135 (write-buffer s
(string p
" ")))
1136 (write-buffer s
"\n")
1142 ;; @syntax (gs:draw-polygon <sym-tag> <list-points> [<list-rgb>])
1143 ;; @param <sym-tag> The tag group of the polygon.
1144 ;; @param <list-points> The list of x and y coordinates of the points.
1146 ;; Draws a polygon with the points found in <list-points>.
1149 ;; (gs:draw-polygon 'P '(1 0 2 2 3 0))
1151 ;; The example will draw an upwards-pointing triangle with the points '1,0', '2,2'
1154 (define (draw-polygon tag points color
)
1156 (let (s (string "draw-polygon " gs
:currentCanvas
" " tag
" " (/ (length points
) 2) " "))
1158 (write-buffer s
(string p
" ")))
1159 (write-buffer s
(string (color 0) " " (color 1) " " (color 2) "\n"))
1162 (let (s (string "draw-polygon " gs
:currentCanvas
" " tag
" " (/ (length points
) 2) " "))
1164 (write-buffer s
(string p
" ")))
1165 (write-buffer s
"\n")
1172 ;; @syntax (gs:draw-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> [<list-rgb>])
1173 ;; @param <sym-tag> The tag group of the rectangle.
1174 ;; @param <int-x> The X position of the top left corner.
1175 ;; @param <int-y> The Y position of the top left corner.
1176 ;; @param <int-width> The width of the rectangle.
1177 ;; @param <int-height> The height of the rectangle..
1178 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components
1180 ;; Creates the outline of a rectangle. The color numbers must be entered in list form.
1181 ;; If no <list-rgb> is used the current paint specified with 'gs:set-paint' is used.
1183 (define (draw-rect tag x y width height color
)
1185 (net-send out
(string "draw-rect " gs
:currentCanvas
" "
1186 tag
" " x
" " y
" " width
" " height
" " (color 0) " " (color 1) " " (color 2) "\n"))
1187 (net-send out
(string "draw-rect " gs
:currentCanvas
" "
1188 tag
" " x
" " y
" " width
" " height
"\n"))
1193 ;; @syntax (gs:draw-round-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-arc-width> <int-arc-height> [<list-rgb>])
1194 ;; @param <sym-tag> The tag group of the round rectangle.
1195 ;; @param <int-x> The X position of the top left corner.
1196 ;; @param <int-y> The Y position of the top left corner.
1197 ;; @param <int-width> The width of the rectangle.
1198 ;; @param <int-height> The height of the rectangle..
1199 ;; @param <int-arc-width> The width of the corner rectangle.
1200 ;; @param <int-arc-height> The height of the corner rectangle..
1201 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components
1203 ;; Draws a rectangle shape with round corners. The rounding is defined by the rectangle enclosing
1204 ;; the rounding arc.
1206 (define (draw-round-rect tag x y width height arcw arch color
)
1208 (net-send out
(string "draw-round-rect " gs
:currentCanvas
" "
1209 tag
" " x
" " y
" " width
" " height
" " arcw
" " arch
" "
1210 (color 0) " " (color 1) " " (color 2) "\n"))
1211 (net-send out
(string "draw-round-rect " gs
:currentCanvas
" "
1212 tag
" " x
" " y
" " width
" " height
" " arcw
" " arch
"\n"))
1217 ;; @syntax (gs:draw-text <sym-tag> <str-text> <int-x> <int-y> [<list-rgb> [<float-angle>])
1218 ;; @param <sym-tag> The tag group of the text.
1219 ;; @param <str-text> The text to be drawn.
1220 ;; @param <int-x> The X position of the text.
1221 ;; @param <int-y> The Y position of the text.
1222 ;; @param <list-rgb> The optonal color for the text.
1223 ;; @param <float-angle> The optional angle for text in degrees
1225 ;; If no <list-rgb> is used, the current paint specified with 'gs:set-paint' is used.
1226 ;; The optional angle is <tt>0</tt> by default for horizontal text. A value of <tt>90</tt>
1227 ;; will rotate the text around the <tt>x</tt>, <tt>y</tt> position downwards clockwise.
1229 (define (draw-text tag text x y color angle
)
1232 (net-send out
(string "draw-text " gs
:currentCanvas
" "
1233 tag
" " (base64-enc text
) " " x
" " y
" "
1234 (color 0) " " (color 1) " " (color 2) " " angle
"\n"))
1235 (net-send out
(string "draw-text " gs
:currentCanvas
" "
1236 tag
" " (base64-enc text
) " " x
" " y
" "
1237 (color 0) " " (color 1) " " (color 2) "\n"))
1239 (net-send out
(string "draw-text " gs
:currentCanvas
" "
1240 tag
" " (base64-enc text
) " " x
" " y
"\n"))
1247 ;; @syntax (gs:enable <sym-id-1> [sym-id-2 ...])
1248 ;; @param <sym-id> The name of a component to enable.
1250 ;; Components are enabled by default.
1253 (let (s (string "enable "))
1255 (write-buffer s
(string item
" ")))
1256 (write-buffer s
"\n")
1261 ;; @syntax (gs:eva-shell <sym-id-text-area> <str-command>)
1262 ;; @param <sym-id-text-area> The name of the text are in which to evaluate text.
1263 ;; @param <str-command> The text to evaluate in the shell.
1265 (define (eval-shell id command
)
1266 (net-send out
(string "eval-shell " id
" " (base64-enc command
) "\n"))
1269 ;; @syntax (gs:export <str-path-file> [<int-width> <int-height>])
1270 ;; @param <str-path-file> The path and file name of the image file to write to.
1271 ;; @param <int-width> The optional width of the image in pixels.
1272 ;; @param <int-height> The optional height of the image in pixels.
1274 ;; If no width and height are specified, the current size of the canvas is assumed.
1278 ;; (gs:export "/usr/home/pictures/mypic.png")
1280 ;; This will generate a '.png' file exactly as the image seen on the screen.
1281 ;; The color format is RGBA with 8 bit per color and an alpha channel. When
1282 ;; no background color is defined for the canvas, the background will be
1285 ;; When specifying width and height, a smaller or bigger portion of the canvas
1286 ;; than seen on the screen is printed to the image.
1288 (define (export path width height
)
1289 (if (and width height
)
1290 (net-send out
(string "export " gs
:currentCanvas
" " (base64-enc path
) " " width
" " height
"\n"))
1291 (net-send out
(string "export " gs
:currentCanvas
" " (base64-enc path
) "\n"))
1296 ;; @syntax (gs:fill-arc <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-start> <int-angle> [<list-rgb>])
1297 ;; @param <sym-tag> The tag group of the arc.
1298 ;; @param <int-x> The X position of the arc.
1299 ;; @param <int-y> The Y position of the arc.
1300 ;; @param <int-width> The width of the arc.
1301 ;; @param <int-height> The height of the arc.
1302 ;; @param <int-start-angle> The start angle of the arc in 0 to 360 degrees.
1303 ;; @param <int-arc-angle> The opening angle of the arc in 0 to 360 degrees.
1304 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components.
1306 ;; The resulting arc begins at <int-start-angle> and extends for <int-arc-angle degrees>,
1307 ;; using the current color. Angles are interpreted such that 0 degrees is at the 3 o'clock
1308 ;; position. A positive value indicates a counter-clockwise rotation while a negative value
1309 ;; indicates a clockwise rotation.
1311 ;; The center of the arc is the center of the rectangle whose origin is (x, y) and whose size
1312 ;; is specified by the width and height arguments.
1314 ;; The resulting arc covers an area <int-width> pixels wide by <int-height> pixels tall.
1316 (define (fill-arc id x y width height start angle color
)
1318 (net-send out
(string "fill-arc " gs
:currentCanvas
" " id
" " x
" " y
" "
1319 width
" " height
" " start
" " angle
" "
1320 (color 0) " " (color 1) " " (color 2) "\n"))
1321 (net-send out
(string "fill-arc " gs
:currentCanvas
" " id
" " x
" " y
" "
1322 width
" " height
" " start
" " angle
"\n"))
1326 ;; @syntax (gs:fill-circle <sym-tag> <int-x> <int-y> <int-radius> [<list-rgb>])
1327 ;; @param <sym-tag> The tag group of the circle.
1328 ;; @param <int-x> The X position of the circle center.
1329 ;; @param <int-y> The Y position of the circle center.
1330 ;; @param <int-radius> The radius of the circle.
1331 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components.
1333 ;; Creates a filled circle. The color numbers must be entered in list form.
1334 ;; If no <list-rgb> is used, the current paint specified with 'gs:set-paint' is used.
1336 (define (fill-circle tag x y radius color
)
1338 (net-send out
(string "fill-circle " gs
:currentCanvas
" "
1339 tag
" " x
" " y
" " radius
" " (color 0) " " (color 1) " " (color 2) "\n"))
1340 (net-send out
(string "fill-circle " gs
:currentCanvas
" "
1341 tag
" " x
" " y
" " radius
"\n"))
1345 ;; @syntax (gs:fill-ellipse <sym-tag> <int-x> <int-y> <int-radius-x> <int-radius-y> [<list-rgb>])
1346 ;; @param <sym-tag> The tag group of the ellipse.
1347 ;; @param <int-x> The X position of the ellipse center.
1348 ;; @param <int-y> The Y position of the ellipse center.
1349 ;; @param <int-radius-x> The radius of the ellipse.
1350 ;; @param <int-radius-y> The radius of the ellipse.
1351 ;; @param <list-rgb> The fill color as a list of 3 numbers for the rgb components.
1353 ;; Creates a filled ellipse. The color numbers must be entered in list form.
1354 ;; If no <list-rgb> is used, the current paint specified with 'gs:set-paint' is used.
1356 (define (fill-ellipse tag x y radius-x radius-y color
)
1358 (net-send out
(string "fill-ellipse " gs
:currentCanvas
" "
1359 tag
" " x
" " y
" " radius-x
" " radius-y
" "
1360 (color 0) " " (color 1) " " (color 2) "\n"))
1361 (net-send out
(string "fill-ellipse " gs
:currentCanvas
" "
1362 tag
" " x
" " y
" " radius-x
" " radius-y
"\n"))
1366 ;; @syntax (gs:fill-polygon <sym-tag> <list-points> [<list-color>])
1367 ;; @param <sym-tag> The tag group of the polygon.
1368 ;; @param <list-points> The list of x and y coordinates of the points.
1370 ;; Draws a polygon with the points found in <list-points> and fills it with
1371 ;; the current color set with 'gs:set-paint' or the optional color
1372 ;; given in <list-color>.
1375 ;; (gs:fill-polygon 'P '(1 0 2 2 3 0))
1377 ;; (gs:fill-polygon 'P '(1 0 2 2 3 0) gs:gray)
1379 ;; The example will fill an upwards pointing triangle with the points '1,0', '2,2'
1380 ;; and '3,0' and fill it with the current color set with 'gs:set-paint'. The second
1381 ;; example paints a gray triangle regardless of the current color set with
1384 (define (fill-polygon tag points color
)
1386 (let (s (string "fill-polygon " gs
:currentCanvas
" " tag
" " (/ (length points
) 2) " "))
1388 (write-buffer s
(string p
" ")))
1389 (write-buffer s
(string (color 0) " " (color 1) " " (color 2) "\n"))
1392 (let (s (string "fill-polygon " gs
:currentCanvas
" " tag
" " (/ (length points
) 2) " "))
1394 (write-buffer s
(string p
" ")))
1395 (write-buffer s
"\n")
1401 ;; @syntax (gs:fill-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> [<list-rgb>])
1402 ;; @param <sym-tag> The tag group of the rectangle.
1403 ;; @param <int-x> The X position of the top left corner.
1404 ;; @param <int-y> The Y position of the top left corner.
1405 ;; @param <int-width> The width of the rectangle.
1406 ;; @param <int-height> The height of the rectangle.
1407 ;; @param <list-rgb> The fill color as a list of 3 numbers for the rgb components.
1409 ;; Creates a filled rectangle. The color numbers must be entered in list form.
1410 ;; If no <list-rgb> is used, the current paint specified with 'gs:set-paint' is used.
1412 (define (fill-rect tag x y width height color
)
1414 (net-send out
(string "fill-rect " gs
:currentCanvas
" "
1415 tag
" " x
" " y
" " width
" " height
" " (color 0) " " (color 1) " " (color 2) "\n"))
1416 (net-send out
(string "fill-rect " gs
:currentCanvas
" "
1417 tag
" " x
" " y
" " width
" " height
"\n"))
1421 ;; @syntax (gs:fill-round-rect <sym-tag> <int-x> <int-y> <int-width> <int-height> <int-arc-width> <int-arc-height> [<list-rgb>])
1422 ;; @param <sym-tag> The tag group of the round rectangle.
1423 ;; @param <int-x> The X position of the top left corner.
1424 ;; @param <int-y> The Y position of the top left corner.
1425 ;; @param <int-width> The width of the rectangle.
1426 ;; @param <int-height> The height of the rectangle..
1427 ;; @param <int-arc-width> The width of the corner rectangle.
1428 ;; @param <int-arc-height> The height of the corner rectangle.
1429 ;; @param <list-rgb> The outline color as a list of 3 numbers for the rgb components.
1431 ;; Paints a rectangle shape with round corners. The rounding is defined by the rectangle enclosing
1432 ;; the rounding arc.
1434 (define (fill-round-rect tag x y width height arcw arch color
)
1436 (net-send out
(string "fill-round-rect " gs
:currentCanvas
" "
1437 tag
" " x
" " y
" " width
" " height
" " arcw
" " arch
" "
1438 (color 0) " " (color 1) " " (color 2) "\n"))
1439 (net-send out
(string "fill-round-rect " gs
:currentCanvas
" "
1440 tag
" " x
" " y
" " width
" " height
" " arcw
" " arch
"\n"))
1444 ;; @syntax (gs:find-text <sym-id> <str-text> <sym-action> [<str-direction>])
1445 ;; @param <sym-id> The name of the textr area or text pane.
1446 ;; @param <boolean-next> The optional direction string '"next"' (default) or '"previous"'.
1447 ;; @param <sym-action> A optional action to peform after find-text.
1449 ;; The text area or text pane will be searched starting at the current caret position
1450 ;; forward or backwards depending on the optional direction field. After the search
1451 ;; the found text is highlighted. If the optional <sym-action> is specified an event
1452 ;; containing the id of the text area or pane and found position or '-1' will be fired.
1454 (define (find-text id text action
(direction "next"))
1455 (net-send out
(string "find-text " id
" " (base64-enc text
) " " action
" " direction
"\n"))
1460 ;; @syntax (gs:frame <sym-id> <int-x> <int-y> <int-width> <int-height> [<str-title> <boolean-visible>])
1461 ;; @param <sym-id> The name of the frame window.
1462 ;; @param <int-x> The X position of the top left window corner.
1463 ;; @param <int-y> The Y position of the top left windows corner.
1464 ;; @param <int-width> The width of the window frame.
1465 ;; @param <int-height> The height of the windows frame.
1466 ;; @param <str-title> The optional title of the window.
1467 ;; @param <boolean-visible> The optional flag with a value of 'true' or 'nil' for the visibility of the window.
1469 ;; Initially the frame should not be visible until all widgets are added to it.
1470 ;; When no flag for visibility is specified 'nil' is assumed. The default layout of a frame behaves
1471 ;; like a grid layout with one cell. Use the 'set-flow-layout', 'set-border-layout' and
1472 ;; 'set-grid-layout' to change the layout.
1475 (define (frame id x y width height text visible
)
1477 (net-send out
(string "frame " id
" " x
" " y
" " width
" " height
" " (base64-enc text
) " " visible
"\n"))
1478 (net-send out
(string "frame " id
" " x
" " y
" " width
" " height
"\n"))
1482 ;; @syntax (gs:get-bounds <sym-id>)
1483 ;; @param <sym-id> The id of the component for which to get the list of bounding values.
1484 ;; @return The bounding list '(<x> <y> <width> <height>)'
1486 (define (get-bounds id
)
1487 (set 'gs
:bounds nil
)
1488 (net-send out
(string "get-bounds " id
"\n"))
1489 (while (not gs
:bounds
) (check-event 10000))
1493 ;; @syntax (gs:get-fonts)
1494 ;; @return A list of family names for fonts on the current system.
1496 ;; The function should be called only once because it may take considerable
1497 ;; time in a system loaded with many fonts. The variable 'gs:fonts' contains
1498 ;; the same list of fonts originally returned by a call to 'gs:get-fonts'.
1503 (net-send out
(string "get-fonts System\n"))
1504 (while (not gs
:fonts
) (check-event 10000))
1505 (set 'gs
:fonts
(map base64-dec gs
:fonts
))
1510 ;; @syntax (gs:get-font-metrics <sym-id> <str-text>)
1511 ;; @return A list of the two values for width and height in pixels.
1513 ;; The font metrics for the currently set font in <sym-id> are returned as a list
1514 ;; of width and height in pixels when displaying the string in <str-text>.
1515 ;; After the function call the variable 'gs:font-metrics' contains the same list
1516 ;; of values as originally returned by the call to 'gs:get-font-metrics'.
1518 (define (get-font-metrics id text
)
1519 (set 'gs
:font-metrics nil
)
1520 (net-send out
(string "get-font-metrics " id
" " (base64-enc text
) "\n"))
1521 (while (not gs
:font-metrics
) (check-event 10000))
1526 ;; @syntax (gs:get-screen)
1527 ;; @return A list of screen width, height and resolution of the main computer screen.
1529 ;; After calling the 'gs:get-screen' once the screen parameters are also available
1530 ;; in the variable 'gs:screen'.
1532 (define (get-screen)
1533 (net-send out
(string "get-screen System\n"))
1534 (while (not gs
:screen
) (check-event 10000))
1539 ;; @syntax (gs:get-selected-text <sym-id> <sym-action>)
1540 ;; @param <sym-id> The name of the component from which to get the selected text.
1541 ;; @param <sym-action> The symbol of the event handler which will receive the selected text.
1543 (define (get-selected-text id action
)
1544 (net-send out
(string "get-selected-text " id
" " action
"\n"))
1549 ;; @syntax (gs:get-text <sym-id> [<sym-action>])
1550 ;; @param <sym-id> The name of the component from which to get the text.
1551 ;; @param <sym-action> The optional symbol of the event handler which will receive the text.
1553 ;; If no <sym-action> is specified the function will block until the text is returned.
1554 ;; After return the text is also available in the variable 'gs:text'.
1555 ;; If <sym-action> is specified the function will return immediately and a <sym-action> event
1556 ;; is fired containing the text.
1558 (define (get-text id action
)
1560 (net-send out
(string "get-text " id
" " action
"\n"))
1563 (net-send out
(string "get-text " id
"\n"))
1564 (while (not gs
:text
) (check-event 10000))
1570 ;; @syntax (gs:get-text-position <sym-id>)
1571 ;; @param <sym-id> The name of the text component for which the line and column position is returned.
1572 ;; @return A list of line and column position of the text caret.
1575 (define (get-text-position id
)
1576 (set 'gs
:text-position nil
)
1577 (net-send out
(string "get-text-position " id
"\n"))
1578 (while (not gs
:text-position
) (check-event 10000))
1582 ;; @syntax (gs:get-version)
1583 ;; @return The version string of newLISP-GS running.
1585 ;; After calling the 'gs:get-version' once the version number is also
1586 ;; available in 'gs:version'.
1588 (define (get-version)
1589 (net-send out
(string "get-version System\n"))
1590 (while (not gs
:version
) (check-event 10000))
1594 ;; @syntax (gs:goto-text <sym-id> <int-row> <int-column>)
1595 ;; @param <sym-id> The name of the text widget.
1596 ;; @param <int-row> The row number where to place the cursor.
1597 ;; @param <int-column> The column number where to place the cursor.
1599 (define (goto-text id row col
)
1600 (net-send out
(string "goto-text " id
" " row
" " col
"\n"))
1605 ;; @syntax (gs:hide-tag <sym-tag> [<boolean-repaint>])
1606 ;; @param <sym-tag> The tag of the group to hide.
1607 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
1610 (define (hide-tag tag
(repaint true
))
1611 (net-send out
(string "hide-tag " gs
:currentCanvas
" " tag
" " repaint
"\n"))
1615 ;; @syntax (gs:image-button <sym-id> <sym-action> <str-icon-path> [<str-down-icon-path> [<int-width> <int-height>]])
1616 ;; @param <sym-id> The name of the image button.
1617 ;; @param <sym-action> The name of the event handler.
1618 ;; @param <str-icon-path> The path for an image icon.
1619 ;; @param <str-down-con-path> The path for a pressed down image icon.
1620 ;; @param <int-width> The optional width of the image button.
1621 ;; @param <int-height> The optional height of the image button.
1623 (define (image-button id action icon down-icon x y
)
1626 (net-send out
(string "image-button " id
" " action
" " (base64-enc icon
) " " (base64-enc down-icon
) " " x
" " y
"\n"))
1627 (net-send out
(string "image-button " id
" " action
" " (base64-enc icon
) " " (base64-enc down-icon
) "\n"))
1629 (net-send out
(string "image-button " id
" " action
" " (base64-enc icon
) "\n"))
1633 ;; @syntax (gs:image-label <sym-id> <str-icon-path> [<str-align>])
1634 ;; @param <sym-id> The name of the label.
1635 ;; @param <str-ucon-path> A string with the icon file path.
1636 ;; @param <str-align> An optional alignment '"left"', '"center"' or '"right"', '"leading"', '"trailing"', '"bottom"' or '"top"'.
1638 (define (image-label id icon align
)
1640 (net-send out
(string "image-label " id
" " (base64-enc icon
) " " align
"\n"))
1641 (net-send out
(string "image-label " id
" " (base64-enc icon
) "\n")))
1645 ;; @syntax (gs:init [<int-port> <str-host>])
1646 ;; @param <int-port> The optional guiserver server port.
1647 ;; @param <str-host> The optional remote host of the guiserver.
1649 (define (init (portIn 47011) (host "127.0.0.1"))
1650 ; check for server portIn and if this was started by java
1651 (if (main-args 2) (set 'portIn
(int (main-args 2) portIn
)))
1652 (if (not (= (main-args 3) "javastart"))
1653 (if (= ostype
"Win32")
1654 (process (string "cmd /c " server-path
" " portIn
))
1657 (process (string "/usr/bin/java -jar " server-path
" " portIn
))
1660 (process (string (env "JAVA_HOME") "/bin/java -jar " server-path
" " portIn
))
1662 (process (string "/usr/bin/java -jar " server-path
" " portIn
))
1667 (set 'portOut
(+ portIn
1))
1671 (if (> retry
300) ; try for 30 seconds
1673 (println "Could not connect to guiserver")
1676 (set 'out
(net-connect host portIn
))
1679 (set 'listenSock
(net-listen portOut
))
1680 (set 'in
(net-accept listenSock
))
1681 (net-close listenSock
)
1682 (gs:set-utf8
(primitive? MAIN
:utf8
))
1686 ;; @syntax (gs:insert-list-item <sym-list-combo> <str-text> <int-index> [<str-text> <int-index>])
1687 ;; @param <sym-list-combo> The name of the combo box or list box from which entries are removed.
1688 ;; @param <str-text> The text of the list or combo box item to insert.
1689 ;; @param <int-index> The index of an entry to add to the list or combo box.
1691 ;; When specifying an index of <tt>0</tt> the first item gets inserted at the beginning.
1692 ;; When specifying an index equal or greater to the number of items in the list, the item
1693 ;; is added at the end.
1695 (define (insert-list-item comp
)
1696 (let ( s
(string "insert-list-item " comp
" ")
1699 (write-buffer s
(string (base64-enc (pop p
)) " " (pop p
) " ")))
1701 (write-buffer s
"\n")
1705 ;; @syntax (gs:insert-tab <sym-tabbed-pane> <sym-component> [<str-text> [<int-index> [<str-icon-path>]]])
1706 ;; @param <sym-tabbed-pane> The name of the tabbed pane.
1707 ;; @param <sym-component> The name of the component to insert as a tab.
1708 ;; @param <str-text> The optional text on the tab.
1709 ;; @param <int-index> The optional index where to insert the new tab.
1710 ;; @param <str-icon-path> The file path to an optional icon.
1712 (define (insert-tab pane comp text idx icon
)
1716 (net-send out
(string "insert-tab " pane
" " comp
" " (base64-enc text
) " " idx
" " (base64-enc icon
) "\n"))
1717 (net-send out
(string "insert-tab " pane
" " comp
" " (base64-enc text
) " " idx
"\n")))
1718 (net-send out
(string "insert-tab " pane
" " comp
" " (base64-enc text
) "\n")))
1719 (net-send out
(string "insert-tab " pane
" " comp
"\n")))
1722 ;; @syntax (gs:insert-text <sym-id> <str-text> <int-position>)
1723 ;; @param <sym-id> The name of the text component.
1724 ;; @param <str-text> The text to insert.
1725 ;; @param <int-position> The offset position where to insert the text.
1727 (define (insert-text id text position
)
1728 (replace "\r" text
"")
1729 (net-send out
(string "insert-text " id
" " (base64-enc text
) " " position
"\n"))
1732 ;; @syntax (gs:key-event <sym-id> <sym-action>)
1733 ;; @param <sym-canvas> The id of the component to register the action handler.
1734 ;; @param <sym-action> The symbol of the action handler.
1736 ;; 'gs:key-event' can be used to register a general unspecific key event handler
1737 ;; for any component in the system. Since version 1.05 of newLISP-GS this also
1738 ;; includes text widgets, which alrady handle key events using their normal event
1739 ;; handler function. With 'gs:key-event' a second handler function can be registered
1740 ;; for text widgets. Both functions will fire on their respective events.
1742 ;; Components respond to the following key event types: '"pressed"', '"released"', '"typed"'.
1746 ;; (define (key-action id type code modifiers)
1747 ;; (println "id:" id " type:" type " key code:" code " modifiers:" modifiers)
1750 ;; The example shows a handler which prints all key event parameters to the terminal/shell
1751 ;; window where the applicaton was started.
1753 ;; In order for key events to work, the component for which a key action handler
1754 ;; is registered must have the input focus. Use '"gs:request-focus"' to set the
1755 ;; input focus for the component.
1758 (define (gs:key-event id action
)
1759 (net-send out
(string "key-event " id
" " action
"\n"))
1762 ;; @syntax (gs:label <sym-id> <str-text> [<str-align> [<int-width> <int-height>]])
1763 ;; @param <sym-id> The name of the label.
1764 ;; @param <str-text> The text to appear on the label.
1765 ;; @param <str-align> The optional alignment of the text.
1766 ;; @param <int-width> The optional width of the label.
1767 ;; @param <int-height> The optional height of the label.
1769 ;; The following alignment constants can be supplied: '"left"', '"center"', '"right"",
1770 ;; '"leading"', '"trailing"', '"bottom"' and "'top'". By default each label text is
1771 ;; '"center"' aligned.
1773 (define (label id text align width height
)
1775 (if (and width height
)
1776 (net-send out
(string "label " id
" " (base64-enc text
) " " align
" " width
" " height
"\n"))
1777 (net-send out
(string "label " id
" " (base64-enc text
) " " align
"\n")))
1778 (net-send out
(string "label " id
" " (base64-enc text
) "\n")))
1782 ;; @syntax (gs:layout <sym-container>)
1783 ;; @param <sym-container> The id of the container to lay out.
1785 ;; Forces the container to lay out its components again, e.g. after a 'gs:add-to' or 'gs:remove-from'
1786 ;; when the container was already visible.
1789 (net-send out
(string "layout " id
"\n"))
1792 ;; @syntax (gs:load-text <sym-id> <str-path>)
1793 ;; @param <sym-id> The id of the 'gs:text-pane'.
1794 ;; @param <str-path> The full path name of the file to load.
1796 ;; 'gs:load-text' will load text into a 'gs:text-pane' directly by specifying
1797 ;; the path name. During loading, CR-LF line terminators are automatically
1798 ;; translated to LF-only line terminators by stripping all CRs from the file. All internal
1799 ;; operations of guiserver on text assume LF as a line terminator.
1801 (define (load-text id path
)
1802 (net-send out
(string "load-text " id
" " (base64-enc path
) "\n"))
1805 ;; @syntax (gs:listen [<boolean-flag>])
1806 ;; @param <boolean-flag> Prevent exit on loss of communication.
1807 ;; @return Never returns. Exits the application when the guiserver exits, except when <boolean-flag> is 'true'.
1809 (define (listen flag
)
1810 (while (net-receive in
'event
1000000000 "\n")
1811 (eval-string event
))
1812 (println "server shut down")
1813 (if (not flag
) (exit))
1816 ;; @syntax (gs:list-box <sym-id> <sym-action> [<str-item-1> ...])
1817 ;; @param <sym-id> The name of the list box.
1818 ;; @param <sym-action> The name of the event handler.
1819 ;; @param <str-item> Zero, one or more text entries in the list box.
1820 ;; @syntax (gs:list-box <sym-id> <sym-action> [<list-str-items>])
1821 ;; @param <sym-id> The name of the list box.
1822 ;; @param <sym-action> The name of the event handler.
1823 ;; @param <str-item> Zero, one or more text entries in the list box.
1825 ;; The listbox when clicked with the mouse, or when the [enter] key is
1826 ;; presses, will pass the following parameters to the event handler:
1828 ;; <id> - the id string of the list box<br>
1829 ;; <index> - the zero offset index of the highlighted listbox entry<br>
1830 ;; <item> - the string of the highlighted listbox entry<br>
1831 ;; <click-count> - the number of times the mouse has been clicked<br>
1834 (define (list-box id action
)
1835 (let ( s
(string "list-box " id
" " action
" ")
1836 entries
(if (list?
(args 0)) (args 0) (args)) )
1837 (dolist (item entries
)
1838 (write-buffer s
(string (base64-enc item
) " ")))
1839 (write-buffer s
"\n")
1844 ;; @syntax (gs:message-dialog <sym-parent-frame> <str-title> <str-message> [<str-type> [<str-icon-path>]])
1845 ;; @param <sym-parent-frame> The symbol name of the parent frame.
1846 ;; @param <str-title> The title of the message box.
1847 ;; @param <str-message> The message in the message box.
1848 ;; @param <str-type> The type of the message box.
1849 ;; @param <str-icon-path> The optional path for an icon.
1851 ;; The type of the message box can be one of: '"error"', '"information"', '"warning"', '"question"', '"plain"'.
1852 ;; The function initiating the message-dialog will return when the dialog is closed.
1854 (define (message-dialog parent title message
(type "plain") icon
)
1856 (net-send out
(string "message-dialog " parent
" "
1857 (base64-enc title
) " " (base64-enc message
) " " type
" " (base64-enc icon
) "\n"))
1858 (net-send out
(string "message-dialog " parent
" "
1859 (base64-enc title
) " " (base64-enc message
) " " type
"\n"))
1863 ;; @syntax (gs:menu <sym-id> <str-text>)
1864 ;; @param <sym-id> The name of the menu.
1865 ;; @param <str-text> The title string of the menu.
1867 (define (menu id text
)
1868 (net-send out
(string "menu " id
" " (base64-enc text
) "\n"))
1871 ;; @syntax (gs:menu-popup <sym-id> <str-text>)
1872 ;; @param <sym-id> The name of the menu.
1873 ;; @param <str-text> The title string of the menu.
1875 (define (menu-popup id text
)
1876 (net-send out
(string "menu-popup " id
" " (base64-enc text
) "\n"))
1879 ;; @syntax (gs:menu-bar <sym-frame> [<sym-menu-1> ...])
1880 ;; @param <sym-frame> The name of the frame hosting the menu bar.
1881 ;; @param <sym-menu> Zero or more symbol names of menus to be positioned on the menu bar.
1883 (define (menu-bar aframe
)
1884 (let (s (string "menu-bar " aframe
" "))
1886 (write-buffer s
(string item
" ")))
1887 (write-buffer s
"\n")
1891 ;; @syntax (gs:menu-item <sym-id> <sym-action> <str-text>)
1892 ;; @param <sym-id> The name of the menu item.
1893 ;; @param <sym-action> The name of the event handler.
1894 ;; @param <str-text> The text to appear for the menu item.
1896 (define (menu-item id action text
)
1897 (net-send out
(string "menu-item " id
" " action
" " (base64-enc text
) "\n"))
1900 ;; @syntax (gs:menu-item-check <sym-id> <sym-action> <str-text> [<bool-selected>])
1901 ;; @param <sym-id> The name of the menu item.
1902 ;; @param <sym-action> The name of the event handler.
1903 ;; @param <str-text> The text to appear for the menu item.
1904 ;; @param <bool-selected> An optional flag indicating the selection state 'true' or 'nil' (default).
1906 (define (menu-item-check id action text selected
)
1907 (net-send out
(string "menu-item-check " id
" " action
" " (base64-enc text
) " " selected
"\n"))
1910 ;; @syntax (gs:mouse-clicked <sym-canvas> <sym-action> [<boolean-tags>])
1911 ;; @param <sym-canvas> The id of the canvas to register the action handler.
1912 ;; @param <sym-action> The symbol of the action handler.
1913 ;; @param <boolean-tags> A 'true' to indicate checking for tags.
1915 ;; If <boolean-tags> is 'true', the action event will carry a list of
1916 ;; all tags which contained the X,Y coordinates of the mouse.
1918 (define (mouse-clicked cnvs action flag
)
1919 (net-send out
(string "mouse-clicked " cnvs
" " action
" " flag
"\n"))
1922 ;; @syntax (gs:mouse-dragged <sym-canvas> <sym-action>)
1923 ;; @param <sym-canvas> The id of the canvas to register the action handler.
1924 ;; @param <sym-action> The symbol of the action handler.
1926 (define (gs:mouse-dragged cnvs action
)
1927 (net-send out
(string "mouse-dragged " cnvs
" " action
"\n"))
1930 ;; @syntax (gs:mouse-event <sym-id> <sym-action>)
1931 ;; @param <sym-canvas> The id of the component to register the action handler.
1932 ;; @param <sym-action> The symbol of the action handler.
1934 ;; 'gs:mouse-event' can be used to register a general unspecific mouse event handler
1935 ;; for any component in the system. Components respond to the following types:
1936 ;; '"pressed"', '"released"', '"clicked"',
1940 ;; (define (mouse-action id type x y button cnt mods)
1941 ;; (println "id:" id " type:" type " x:" x " y:" y " button:" button " count:" cnt " mods:" mods)
1944 ;; The example shows a handler which prints all mouse event parameters to the terminal/shell
1945 ;; window where the applicaton was started.
1948 (define (gs:mouse-event id action
)
1949 (net-send out
(string "mouse-event " id
" " action
"\n"))
1952 ;; @syntax (gs:mouse-moved <sym-canvas> <sym-action>)
1953 ;; @param <sym-canvas> The id of the canvas to register the action handler.
1954 ;; @param <sym-action> The symbol of the action handler.
1955 ;; @param <boolean-tags> A 'true' to indicate checking for tags.
1957 ;; If <boolean-tags> is 'true', the action event will carry a list of
1958 ;; all tags which contained the X,Y coordinates of the mouse.
1960 (define (gs:mouse-moved cnvs action flag
)
1961 (net-send out
(string "mouse-moved " cnvs
" " action
" " flag
"\n"))
1964 ;; @syntax (gs:mouse-pressed <sym-canvas> <sym-action> [<boolean-tags>])
1965 ;; @param <sym-canvas> The id of the canvas to register the action handler.
1966 ;; @param <sym-action> The symbol of the action handler.
1967 ;; @param <boolean-tags> A 'true' to indicate checking for tags.
1969 ;; If <boolean-tags> is 'true', the action event will carry a list of
1970 ;; all tags which contained the X,Y coordinates of the mouse.
1972 (define (gs:mouse-pressed cnvs action flag
)
1973 (net-send out
(string "mouse-pressed " cnvs
" " action
" " flag
"\n"))
1976 ;; @syntax (gs:mouse-released <sym-canvas> <sym-action> [<boolean-tags>])
1977 ;; @param <sym-canvas> The id of the canvas to register the action handler.
1978 ;; @param <sym-action> The symbol of the action handler.
1979 ;; @param <boolean-tags> A 'true' to indicate checking for tags.
1981 ;; If <boolean-tags> is 'true', the the action event will carry a list of
1982 ;; all tags which contained the X,Y coordinates of the mouse.
1984 (define (gs:mouse-released cnvs action flag
)
1985 (net-send out
(string "mouse-released " cnvs
" " action
" " flag
"\n"))
1988 ;; @syntax (gs:mouse-wheel <sym-canvas> <sym-action>)
1989 ;; @param <sym-canvas> The id of the canvas to register the action handler.
1990 ;; @param <sym-action> The symbol of the action handler.
1992 (define (gs:mouse-wheel cnvs action
)
1993 (net-send out
(string "mouse-wheel " cnvs
" " action
"\n"))
1996 ;; @syntax (gs:move-tag <sym-tag> <int-dx> <int-dy> [<boolean-repaint>])
1997 ;; @param <sym-tag> The tag of the group of objects to move.
1998 ;; @param <int-dx> The distance to move on the X-axis.
1999 ;; @param <int-dy> The distance to move on the Y-axis.
2000 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
2002 ;; 'gs:move-tag' is the only tag operation which actually changes the
2003 ;; internal data of a drawn object. All other tag operations like
2004 ;; 'gs:translate-tag', 'gs:scale-tag', 'gs:rotate-tag' and 'gs:shear-tag'
2005 ;; will transform object coordinates only for drawing.
2007 (define (gs:move-tag tag dx dy
(repaint true
))
2008 (net-send out
(string "move-tag " gs
:currentCanvas
" " tag
" "
2009 dx
" " dy
" " repaint
"\n"))
2012 ;; @syntax (gs:no-action)
2014 ;; Specify as <sym-action> for widgets where no action handler is defined.
2016 (define (no-action))
2018 ;; @syntax (gs:open-file-dialog <sym-parent-frame> <sym-action> [<str-directory> [<str-mask> <str-description>]])
2019 ;; @param <sym-parent-frame> The parent frame of the file dialog.
2020 ;; @param <sym-action> The handler function symbol.
2021 ;; @param <str-directory> The initial directory to show.
2022 ;; @param <str-mask> An optonal string mask.
2023 ;; @param Mstr-description> An optional mask description.
2025 (define (open-file-dialog parent action dir mask desc
)
2028 (net-send out
(string "open-file-dialog " parent
" " action
" " (base64-enc dir
) " "
2029 (base64-enc mask
) " " (base64-enc desc
) "\n"))
2030 (net-send out
(string "open-file-dialog " parent
" " action
" " (base64-enc dir
) "\n")))
2031 (net-send out
(string "open-file-dialog " parent
" " action
"\n")))
2034 ;; @syntax (gs:panel <sym-id> [<int-width> <int-height>])
2035 ;; @param <sym-id> The name of the panel.
2036 ;; @param <int-width> The optional width of the panel.
2037 ;; @param <int-height> The optional height of the panel.
2039 ;; Panels have a flow layout by default. In a flow layout an unsized button will
2040 ;; assume the natural size necessary to display the text on it.
2041 ;; To change the layout use the 'set-flow-layout' or 'set-grid-layout' functions.
2043 (define (panel id width height
)
2044 (if (and width height
)
2045 (net-send out
(string "panel " id
" " width
" " height
"\n"))
2046 (net-send out
(string "panel " id
"\n"))
2049 ;; @syntax (gs:paste-text <sym-id> [<str-text>])
2050 ;; @param <sym-id> The name of the text component in which to paste text.
2051 ;; @param <str-text> An optional text string to paste instead of the clipboard contents.
2053 ;; If the <sym-id> contains selected text, this text gets replaced,
2054 ;; otherwise the text is inserted at the current caret position.
2055 ;; If no text is given in <str-text>, the text is taken from the clipboard.
2057 (define (paste-text id text
)
2059 (net-send out
(string "paste-text " id
" " (base64-enc text
) "\n"))
2060 (net-send out
(string "paste-text " id
"\n")))
2063 ;; @syntax (gs:play-sound <str-file-path>)
2064 ;; @param <str-file-path> The path and file name of the sound file.
2066 ;; On most OS platforms '.au' and '.wav' sound file formats are supported.
2068 (define (play-sound file-name
)
2069 (net-send out
(string "play-sound System " (base64-enc file-name
) "\n"))
2072 ;; @syntax (gs:progress-bar <sym-id> <int-min> <in-max> <int-initial-value>)
2073 ;; @param <sym-id> The symbols of the progress bar.
2074 ;; @param <int-min> The minimum value of the slider.
2075 ;; @param <int-max> The maximum value of the slider.
2076 ;; @param <int-initial-value> The initial value of the slider.
2078 (define (progress-bar id posmin posmax posinit
)
2079 (net-send out
(string "progress-bar " id
" " posmin
" " posmax
" " posinit
"\n"))
2082 ;; @syntax (gs:radio-button <sym-id> <sym-action> [<str-text> [<bool-selected>]])
2083 ;; @param <sym-id> The name of the radio button.
2084 ;; @param <sym-action> The name of the event handler.
2085 ;; @param <str-text> The optional text of the radio button.
2086 ;; @param <bool-seected> An optional flag 'true' or 'nil' (default) indicating the initial state of the radio button.
2088 (define (radio-button id action text selected
)
2090 (net-send out
(string "radio-button " id
" " action
" " (base64-enc text
) " " selected
"\n"))
2091 (net-send out
(string "radio-button " id
" " action
"\n")))
2094 ;; @syntax (gs:redo-text <sym-id>)
2095 ;; @param <sym-id> The id of the 'gs:text-pane' where to perform a redo operation.
2097 (define (redo-text id
)
2098 (net-send out
(string "redo-text " id
"\n"))
2101 ;; @syntax (gs:remove-from <sym-container> <sym-component> [<sym-component> ...])
2102 ;; @param <sym-container> The container from which to remove a component.
2103 ;; @param <sym-component> One or more optional components to remove.
2106 (define (remove-from id
)
2107 (let (s (string "remove-from " id
" "))
2109 (write-buffer s
(string item
" ")))
2110 (write-buffer s
"\n")
2114 ;; @syntax (gs:remove-list-item <sym-list-combo> <int-index> [<int-index> ...])
2115 ;; @param <sym-list-combo> The name of the combo box or list box from which entries are removed.
2116 ;; @param <int-index> The index of an entry to remove from the list or combo box.
2118 ;; When specifying an index of <tt>0</tt>, the first item gets removed. When specifying an
2119 ;; index equal or greater to the number of items in the list, the item is added at the end.
2121 (define (remove-list-item comp
)
2122 (let (s (string "remove-list-item " comp
" "))
2124 (write-buffer s
(string item
" ")))
2125 (write-buffer s
"\n")
2129 ;; @syntax (gs:remove-tab <sym-tabbed-pane> [<int-index>])
2130 ;; @param <sym-tabbed-pane> The name of the tabbed pane.
2131 ;; @param <int-index> The optional index of the tab to remove. The default is <tt>0</tt> for the first tab.
2133 (define (remove-tab pane idx
)
2135 (net-send out
(string "remove-tab " pane
" " idx
"\n"))
2136 (net-send out
(string "remove-tab " pane
"\n")))
2139 ;; @syntax (gs:request-focus <sym-id> [<int-tab-index>])
2140 ;; @param <sym-id> The name of the component for which to request focus.
2141 ;; @param <int-tab-index> The index of a tab for which focus is requested.
2143 (define (request-focus id idx
)
2145 (net-send out
(string "request-focus " id
" " idx
"\n"))
2146 (net-send out
(string "request-focus " id
"\n")))
2149 ;; @syntax (gs:reorder-tags <list-tags>)
2150 ;; @param <list-tags> The list of tag symbols or tag string names in the new order of display.
2152 ;; The re-ordering itself will not repaint the canvas use 'gs:update' to repaint the current
2153 ;; canvas after using 'gs:reorder-tags'. The list of tags can be given as either a list of
2154 ;; tags symbols or name strings. Tags not appearing in <list-tags> will be deleted.
2156 (define (reorder-tags tags
)
2157 (let (s (string "reorder-tags " gs
:currentCanvas
" "))
2159 (write-buffer s
(string tag
" ")))
2160 (write-buffer s
"\n")
2165 ;; @syntax (gs:rotate-tag <sym-tag> <float theta> <int-x> <int-y> [<boolean-repaint>])
2166 ;; @param <sym-tag> The tag group to rotate.
2167 ;; @param <float-theta> The rotation angle in degrees (0 - 360).
2168 ;; @param <int-x> The X-coordinate of the rotation center.
2169 ;; @param <int-y> The Y-coordinate of the rotation center.
2170 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
2172 ;; Like all tag operations, multiple 'gs:rotate-tag' operations are cumulative.
2174 (define (rotate-tag tag angle x y
(repaint true
))
2175 (net-send out
(string "rotate-tag " gs
:currentCanvas
" " tag
" " angle
" "
2176 x
" " y
" " repaint
"\n"))
2179 ;; @syntax (gs:run-shell <id-text-area> <str-command>)
2180 ;; @param <idx-text-area> The id of the text area to wich a shell process will be attached.
2181 ;; @param <str-command> The command string to start the shell process.
2183 (define (run-shell id command
)
2184 (net-send out
(string "run-shell " id
" " (base64-enc command
) "\n"))
2187 ;; @syntax (gs:save-file-dialog <sym-parent-frame> <sym-action> [<str-directory> [<str-initial-file> [<str-mask> <str-description>]]])
2188 ;; @param <sym-parent-frame> The parent frame of the file dialog.
2189 ;; @param <sym-action> The handler function symbol.
2190 ;; @param <str-directory> The initial directory to show.
2191 ;; @param <str-file> The initial file name.
2192 ;; @param <str-mask> An optional string mask.
2193 ;; @param <str-description> An optional mask description.
2195 (define (save-file-dialog parent action dir file mask desc
)
2199 (net-send out
(string "save-file-dialog " parent
" " action
" " (base64-enc dir
) " " (base64-enc file
)
2200 " " (base64-enc mask
) " " (base64-enc desc
) "\n"))
2201 (net-send out
(string "save-file-dialog " parent
" " action
" " (base64-enc dir
) " " (base64-enc file
) "\n")))
2202 (net-send out
(string "save-file-dialog " parent
" " action
" " (base64-enc dir
) "\n")))
2203 (net-send out
(string "save-file-dialog " parent
" " action
"\n")))
2206 ;; @syntax (gs:save-text <sym-id> <str-path>)
2207 ;; @param <sym-id> The id of the 'gs:text-pane'.
2208 ;; @param <str-path> The full path name of the file to save.
2210 ;; This function will write text back from a 'gs:text-pane' directly
2211 ;; by specifying a path name only. Line feed characters (ASCII 10)
2212 ;; are used as line terminators. If this behavior is not desired,
2213 ;; as is the case with Windows text files, then 'gs:get-text' should
2214 ;; be used instead. A program can then add CR characters using a
2215 ;; newLISP 'replace', i.e. '(replace "\n" text "\r\n")' before
2216 ;; saving the text to a file.
2218 (define (save-text id path
)
2219 (net-send out
(string "save-text " id
" " (base64-enc path
) "\n"))
2223 ;; @syntax (gs:scale-tag <sym-tag> <float-x> <float-y> [<boolean-repaint>])
2224 ;; @param <sym-tag> The tag group to scale.
2225 ;; @param <float-x> The X scaling factor.
2226 ;; @param <float-y> The Y scaling factor.
2227 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
2229 ;; 'gs:scale' scales the object to draw relative to the '0,0' point of
2230 ;; the coordinate system. This means if a object is not at the center it
2231 ;; will not only change in size when scaled but also change the distance
2232 ;; to the center point of the coordinate system, moving away when scaling
2233 ;; up with scale factor bigger '1.0' and moving closer to the center
2234 ;; when scaling down using factors smaller than '1.0'.
2236 ;; This means that objects which will be scaled should be defined in
2237 ;; coordinates relative to their center point. Then a 'gs:translate-tag'
2238 ;; command should be used to place the object to correct place:
2241 ;; (gs:circle 'C 0 0 50)
2242 ;; (gs:gs:translate-tag 'C 200 100)
2244 ;; (gs:scale-tag 'C 1.1 1.1)
2246 ;; In the example the circle, although defined for '0,0', will be displayed
2247 ;; at the '200,200' position because of the 'gs:translate-tag' statement. When
2248 ;; later scaling the circle will get bigger but stay in place.
2249 ;; Like all tag operations, multiple 'gs:scale-tag' operations are cumulative.
2251 (define (scale-tag tag sx sy
(repaint true
))
2252 (net-send out
(string "scale-tag " gs
:currentCanvas
" " tag
" "
2253 sx
" " sy
" " repaint
"\n"))
2256 ;; @syntax (gs:select-list-item <sym-id> <str-item> [<boolean-flag>])
2257 ;; @param <sym-id> The name of the list or combo box.
2258 ;; @param <str-item> The item to select.
2259 ;; @param <boolean-flag> An optional flag only for list boxes to force scrolling to the selected entry.
2261 ;; On combo boxes the optional <boolean-flag> has no effect. The selected entry will always
2262 ;; appear as the visible text of the combo box. The flag has either the value 'true' or 'nil'.
2264 (define (select-list-item id item flag
)
2265 (net-send out
(string "select-list-item " id
" " (base64-enc item
) " " flag
"\n")))
2268 ;; @syntax (gs:select-text <sym-id> <int-from> [<int-to>])
2269 ;; @param <sym-id> The ame of the text component.
2270 ;; @param <int-from> Start offset of selection.
2271 ;; @param <int-to> Optional end offset of selection.
2273 ;; If no <int-to> end offset is given, 'gs:select-text' will
2274 ;; select to the end of the text.
2276 (define (select-text id from to
)
2278 (net-send out
(string "select-text " id
" " from
" " to
"\n"))
2279 (net-send out
(string "select-text " id
" " from
"\n")))
2282 ;; @syntax (gs:scroll-pane <sym-id> <sym-widget> [<int-width> <int-height>])
2283 ;; @param <sym-id> The name of the scroll pane.
2284 ;; @param <sym-widget> The component in the scroll pane to be scrolled.
2285 ;; @param <int-width> The optional width of the scroll pane.
2286 ;; @param <int-height> The optional height of the scroll pane.
2288 (define (scroll-pane id widget width height
)
2289 (if (and width height
)
2290 (net-send out
(string "scroll-pane " id
" " widget
" " width
" " height
"\n"))
2291 (net-send out
(string "scroll-pane " id
" " widget
"\n")))
2294 ;; @syntax (gs:set-accelerator <sym-menu-item> <str-keystroke>)
2295 ;; @param <sym-menu-item> The name of the menu item for which an accelerator key is set.
2296 ;; @param <str-keystroke> A text string identifying the keystroke.
2298 ;; The following rules are used to create keystroke strings:
2301 ;; <blockquote><pre>
2302 ;; modifiers* (typedID | pressedReleasedID)
2303 ;; modifiers := shift | control | ctrl | meta | alt | button1 | button2 | button3
2304 ;; typedID := typed typedKey
2305 ;; typedKey := string of length 1 giving Unicode character.
2306 ;; pressedReleasedID := (pressed | released) key
2307 ;; key := KeyEvent key code name, i.e. the name following "VK_".
2308 ;; </pre></blockquote>
2310 ;; <blockquote><pre>
2314 ;; "alt shift released X"
2316 ;; </pre></blockquote>
2317 ;; Note that the <i>apple</i> key on MacOS X is the 'meta' key.
2318 ;; The 'alt' on MacOS X is the <i>option</i> key.
2319 ;; For letters use uppercase.
2320 ;; Keys are added to the menu item display automatically on all platforms.
2322 (define (set-accelerator item key
)
2323 (net-send out
(string "set-accelerator " item
" " (base64-enc key
) "\n"))
2326 ;; @syntax (gs:set-anti-aliasing <boolean-flag>)
2327 ;; @param <boolean-flag> The anti aliasing setting for the current canvas 'true' or 'nil'.
2329 ;; The default setting is 'true'.
2331 (define (gs:set-anti-aliasing flag
)
2332 (net-send out
(string "set-anti-aliasing " gs
:currentCanvas
" " flag
"\n"))
2335 ;; @syntax (gs:set-background <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
2336 ;; @param <sym-id> The name of the component for which to set the color.
2337 ;; @param <float-red> The red color component expressed as a number between 0.0 and 1.0.
2338 ;; @param <float-green> The green color component expressed as a number between 0.0 and 1.0.
2339 ;; @param <float-blue> The blue color component expressed as a number between 0.0 and 1.0.
2340 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2342 ;; @syntax (gs:set-background <sym-id> <list-rgb> [<float-alpha>])
2343 ;; @param <sym-id> The name of the component for which to set the color.
2344 ;; @param <list-rgb> The rgb color can be given as a list of three numbers.
2345 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2347 ;; Note 'set-background' is the same as 'set-color'.
2349 (define (set-background id red green blue alpha
)
2352 (set 'alpha
(or green
1.0))
2353 (map set
'(red green blue
) red
))
2354 (set 'alpha
(or alpha
1.0)))
2355 (net-send out
(string "set-color " id
" " red
" " green
" " blue
" " alpha
"\n"))
2358 ;; @syntax (gs:set-bevel-border <sym-id> <str-type>)
2359 ;; @param <sym-id> The name of the component.
2360 ;; @param <str-type> The type of the bevel '"raised"' or '"lowered"'.
2362 (define (set-bevel-border id type
)
2363 (net-send out
(string "set-bevel-border " id
" " type
"\n"))
2366 ;; @syntax (gs:set-border-layout <sym-container> [<int-hgap> <int-vgap>])
2367 ;; @param <sym-container> The name of the container for which border layout is set.
2368 ;; @param <int-hgap> The horizontal gap between components in the border layout.
2369 ;; @param <int-vgap> The vertical gap between components in the border layout.
2371 ;; Border layout divides the layout into 5 zones labeled '"north"', '"west"',
2372 ;; '"center"', '"east"' and '"south"'. These string constants are used in
2373 ;; the 'gs:add-to' command when adding components to a border layout.
2375 ;; In a border layout each component will take the maximum size if components
2376 ;; are not sized. If components are sized only some dimensions will be honored.
2377 ;; The '"north"' and '"south"' components will stretch to maximum width and
2378 ;; assume the height given in a size parameter of the component. The '"east"'
2379 ;; and '"west"' components will stretch to the maximum height available assuming
2380 ;; their width specified earlier. The '"center"' component will take the left over
2383 (define (set-border-layout container hgap vgap
)
2385 (net-send out
(string "set-border-layout " container
" " hgap
" " vgap
"\n"))
2386 (net-send out
(string "set-border-layout " container
"\n")))
2389 ;; @syntax (gs:set-canvas <sym-id>)
2390 ;; @param <sym-id> The id of the canvas to switch to.
2392 ;; The canvas in <sym-id> must have been created earlier with a 'gs:canvas'
2393 ;; statement. All graphics operations which do not take a canvas as argument
2394 ;; will automatically refer to this current canvas. If no 'gs:set-canvas' is
2395 ;; used, the current canvas is assumed to be the last one created.
2397 (define (gs:set-canvas id
)
2398 (net-send out
(string "set-canvas " id
"\n"))
2402 ;; @syntax (gs:set-caret <sym-id> <int-offset>)
2403 ;; @param <sym-id> The name of the component for which to set the cursor caret.
2405 ;; The functions has the same effect as calling 'gs:select-text' with the same
2406 ;; offset for the dot and mark position.
2408 (define (gs:set-caret id offset
)
2409 (net-send out
(string "set-caret " id
" " offset
"\n"))
2412 ;; @syntax (gs:set-caret-color <sym-id> <float-red> <float-green> <float-blue>)
2413 ;; @param <sym-id> The name of the component for which to set the color.
2414 ;; @param <float-red> The red color component expressed as a number between 0.0 and 1.0.
2415 ;; @param <float-green> The green color component expressed as a number between 0.0 and 1.0.
2416 ;; @param <float-blue> The blue color component expressed as a number between 0.0 and 1.0.
2417 ;; @syntax (gs:set-caret-color <sym-id> <list-rgb> [<float-alpha>])
2418 ;; @param <sym-id> The name of the component for which to set the color.
2419 ;; @param <list-rgb> The rgb color can be given as a list of three numbers.
2421 (define (set-caret-color id red green blue
)
2423 (map set
'(red green blue
) red
))
2424 (net-send out
(string "set-caret-color " id
" " red
" " green
" " blue
"\n"))
2427 ;; @syntax (gs:set-color <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
2428 ;; @param <sym-id> The name of the component for which to set the color.
2429 ;; @param <float-red> The red color component expressed as a number between 0.0 and 1.0.
2430 ;; @param <float-green> The green color component expressed as a number between 0.0 and 1.0.
2431 ;; @param <float-blue> The blue color component expressed as a number between 0.0 and 1.0.
2432 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2434 ;; @syntax (gs:set-color <sym-id> <list-rgb> [<float-alpha>])
2435 ;; @param <sym-id> The name of the component for which to set the color.
2436 ;; @param <list-rgb> The rgb color can be given as a list of three numbers.
2437 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2439 ;; Note that 'set-color' is the same as 'set-background'.
2441 (define set-color set-background
)
2443 ;; @syntax (gs:set-cursor <sym-id> <str-shape>)
2444 ;; @param <sym-id> The name of the frame, dialog or window.
2445 ;; @param <str-shape> The string describing the cursor shape.
2447 ;; The cursor shape can be one of the following:
2465 (define (set-cursor id shape
)
2466 (net-send out
(string "set-cursor " id
" " shape
"\n"))
2469 ;; @syntax (gs:set-editable <sym-id> <boolean-editable>)
2470 ;; @param <sym-id> The name of the text widget.
2471 ;; @param <boolean-editable> The flag 'true' or 'nil' to indicate if this text widget can be edited.
2473 (define (set-editable id flag
)
2474 (net-send out
(string "set-editable " id
" " flag
"\n"))
2477 ;; @syntax (gs:set-flow-layout <sym-container> [<str-alignment> [<int-hgap> <int-vgap>]])
2478 ;; @param <sym-container> The name of the container for which flow layout is set.
2479 ;; @param <sym-alignment> The alignment of the flow layout '"left"', '"center"' or '"right"'.
2480 ;; @param <int-hgap> The horizontal gap between components in the flow layout.
2481 ;; @param <int-vgap> The vertical gap between components in the flow layout.
2483 ;; The flow layout lets components appear in their natural or preferred size. The preferred
2484 ;; size of a component is set using the function 'gs:set-size'. Button-type widgets and
2485 ;; combo boxes will take as much space as necessary to show the included text.
2487 (define (set-flow-layout id
(direction "left") hGap vGap
)
2489 (net-send out
(string "set-flow-layout " id
" " direction
" " hGap
" " vGap
"\n"))
2490 (net-send out
(string "set-flow-layout " id
" " direction
"\n"))
2494 ;; @syntax (gs:set-font <sym-id> <str-family> <int-size> <str-type>)
2495 ;; @param <sym-id> The name of the component for which to set the text font.
2496 ;; @param <str-familiy> The family of the font, e.g.: '"Monospaced"', '"Serif"', '"Sans Serif"'.
2497 ;; @param <int-size> The font size in points.
2498 ;; @param <str-type> The type of the font, one or more of '"plain"', '"bold"', '"italic"'.
2500 ;; More than the above noted families are available depending on the platform.
2502 (define (set-font id family size type
)
2503 (net-send out
(string "set-font " id
" " (base64-enc family
) " " size
" " type
"\n"))
2506 ;; @syntax (gs:set-foreground <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
2507 ;; @param <sym-id> The name of the component for which to set the color.
2508 ;; @param <float-red> The red color component expressed as a number between 0.0 and 1.0.
2509 ;; @param <float-green> The green color component expressed as a number between 0.0 and 1.0.
2510 ;; @param <float-blue> The blue color component expressed as a number between 0.0 and 1.0.
2511 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2513 ;; @syntax (gs:set-foreground <sym-id> <list-rgb> [<float-alpha>])
2514 ;; @param <sym-id> The name of the component for which to set the color.
2515 ;; @param <list-rgb> The rgb color can be given as a list of three numbers.
2516 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2518 ;; The foreground color is the color of the text in a component.
2520 (define (set-foreground id red green blue alpha
)
2523 (set 'alpha
(or green
1.0))
2524 (map set
'(red green blue
) red
))
2525 (set 'alpha
(or alpha
1.0)))
2526 (net-send out
(string "set-foreground " id
" " red
" " green
" " blue
" " alpha
"\n"))
2530 ;; @syntax (gs:set-grid-layout <sym-container> <int-rows> <int-columns> [<int-hgap> <int-vgap>])
2531 ;; @param <sym-container> The name of the container for which grid layout is set.
2532 ;; @param <int-rows> The number of rows in the layout grid.
2533 ;; @param <int-columns> The number of columns in the layout grid.
2534 ;; @param <int-hgap> The horizontal gap between components in the grid layout.
2535 ;; @param <int-vgap> The vertical gap between components in the grid layout.
2537 ;; In a grid layout each component will assume the maximum size the grid cell allows
2538 ;; regardless of sizes preset using 'gs:set-size' Because of this grid layout cells are
2539 ;; frequently filled with panels using 'gs:panel' which have flow layout by default
2540 ;; and allow deliberate sizing of components using 'gs:set-size'.
2542 (define (set-grid-layout container rows cols hgap vgap
)
2544 (net-send out
(string "set-grid-layout " container
" " rows
" " cols
" " hgap
" " vgap
"\n"))
2545 (net-send out
(string "set-grid-layout " container
" " rows
" " cols
"\n")))
2548 ;; @syntax (gs:set-icon <sym-id> <str-icon-path> [<int-index>])
2549 ;; @param <sym-id> The name of a button or label or menu-item for which to set an icon.
2550 ;; @param <str-icon-path> The file path of the icon to be set.
2551 ;; @param <int-index> If <sym-id> is a tabbed pane <int-index> is the index of the tab.
2553 (define (set-icon comp text idx
)
2555 (net-send out
(string "set-icon " comp
" " (base64-enc text
) " " idx
"\n"))
2556 (net-send out
(string "set-icon " comp
" " (base64-enc text
) "\n"))
2560 ;; @syntax (gs:set-look-and-feel <str-look>)
2561 ;; @param <str-look> The class description string for the look and feel of the application.
2563 ;; The following strings can be tried in <str-look>, but not all will work on a specific
2564 ;; platform. On the Mac the default look-and-feel is built-in to the JVM as the default
2565 ;; style. The '"MacLookAndFeel"' is not available as an explicit flavor here, but may be
2566 ;; on other platforms.
2568 ;; '"com.sun.java.swing.plaf.motif.MotifLookAndFeel"'<br>
2569 ;; '"javax.swing.plaf.metal.MetalLookAndFeel"'<br>
2570 ;; '"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"'<br>
2571 ;; '"javax.swing.plaf.mac.MacLookAndFeel"'<br>
2572 ;; '"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"'
2575 (define (set-look-and-feel look
)
2576 (net-send out
(string "set-look-and-feel System " look
"\n"))
2579 ;; @syntax (gs:set-paint <list-rgb>)
2580 ;; @param <list-rgb> The current paint used for outlines, text and fill color.
2582 (define (gs:set-paint color
)
2583 (net-send out
(string "set-paint " gs
:currentCanvas
" " (color 0) " " (color 1) " " (color 2) "\n"))
2586 ;; @syntax (gs:set-pressed-icon <sym-id> <str-icon-path>)
2587 ;; @param <sym-id> The name of the button, image button or toggle button.
2588 ;; @param <str-icon-path> The file path of the icon or image to be set to the button in pressed state.
2590 ;; By default a small grey dot is shown on image buttons when in a pressed state.
2592 (define (set-pressed-icon comp text
)
2593 (net-send out
(string "set-pressed-icon " comp
" " (base64-enc text
) "\n"))
2596 ;; @syntax (gs:set-resizable <sym-frame> <boolean-resizable>)
2597 ;; @param <sym-frame> The name of the frame window.
2598 ;; @param <bbolean-resizable> The flag 'true' or 'nil' to indicate if a frame can be resized by the user.
2600 (define (set-resizable id flag
)
2601 (net-send out
(string "set-resizable " id
" " flag
"\n"))
2605 ;; @syntax (gs:set-rotation <float-angle>)
2606 ;; @param <float-angle> The angle in degrees (0 - 360) of the canvas rotation.
2608 ;; Unlike the 'gs:rotate-tag' operation which is cumulative, 'gs:set-rotation'
2609 ;; will set an absolute rotation value each time it is called.
2611 (define (gs:set-rotation angle
)
2612 (net-send out
(string "set-rotation " gs
:currentCanvas
" " angle
"\n"))
2615 ;; @syntax (gs:set-scale <int-x> <int-y>)
2616 ;; @param <int-x> The X-scale value of the current canvas.
2617 ;; @param <int-y> The Y-scale value of the current canvas.
2619 ;; Unlike the 'gs:scale-tag' operation which is cumulative, 'gs:set-scale'
2620 ;; will set an absolute scale value each time it is called.
2622 (define (gs:set-scale x y
)
2623 (net-send out
(string "set-scale " gs
:currentCanvas
" " x
" " y
"\n"))
2626 ;; @syntax (gs:set-selected <sym-id> <boolean-selected> [<sym-id> <boolean-selected>])
2627 ;; @param <sym-id> The name of the toggle or radio button or check box or menu item.
2628 ;; @param <boolean-selected> A flag of 'true' or 'nil' to indicated the selection state.
2630 ;; More then one toggle control may be set selected or unselected.
2632 (define (set-selected id flag
)
2633 (let (s (string "set-selected " id
" " flag
" "))
2635 (write-buffer s
(string item
" ")))
2636 (write-buffer s
"\n")
2641 ;; @syntax (gs:set-selection-color <sym-id> <float-red> <float-green> <float-blue> [<float-alpha>])
2642 ;; @param <sym-id> The name of the component for which to set the text selection color.
2643 ;; @param <float-red> The red color component expressed as a number between 0.0 and 1.0.
2644 ;; @param <float-green> The green color component expressed as a number between 0.0 and 1.0.
2645 ;; @param <float-blue> The blue color component expressed as a number between 0.0 and 1.0.
2646 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2648 ;; @syntax (gs:set-selection-color <sym-id> <list-rgb> [<float-alpha>])
2649 ;; @param <sym-id> The name of the component for which to set the text selection color.
2650 ;; @param <list-rgb> The rgb color can be given as a list of three numbers.
2651 ;; @param <float-alpha> The transparency of the color expressed as a number between 0.0 (fully transparent)and 1.0 (completely opaque).
2653 ;; Note 'set-background' is the same as 'set-color'.
2655 (define (set-selection-color id red green blue alpha
)
2658 (set 'alpha
(or green
1.0))
2659 (map set
'(red green blue
) red
))
2660 (set 'alpha
(or alpha
1.0)))
2661 (net-send out
(string "set-selection-color " id
" " red
" " green
" " blue
" " alpha
"\n"))
2665 ;; @syntax (gs:set-size <sym-id> <int-width> <int-height>)
2666 ;; @param <sym-id> The name of the component of which a preferred size is set.
2667 ;; @param <int-width> The preferred width of the component.
2668 ;; @param <int-height> The preferred height of the component.
2670 ;; Note that not all layouts allow setting the size of a component. The grid and
2671 ;; border layouts will size the component to its maximum possible in the layout.
2673 (define (set-size id width height
)
2674 (net-send out
(string "set-size " id
" " width
" " height
"\n"))
2677 ;; @syntax (gs:set-stroke <float-width> [<str-cap> [<str-join> [<float-miterlimit>]]])
2678 ;; @param <float-width> The width for drawing lines and outlines in shapes.
2679 ;; @param <str-cap> One of optional '"butt"' (default), '"round"' or '"sqare"'.
2680 ;; @param <str-join> One of optional '"miter"' (default), '"bevel"' or '"round"'
2682 ;; For a <float-width> 0f 0.0 the thinnest possible line width be be chosen.
2683 ;; Join is the decoration applied at the intersection of two path segments and at the
2684 ;; intersection of the endpoints.
2685 ;; Cap is the decoration applied to the ends of unclosed subpaths and dash segments.
2686 ;; The <float-miterlimit> should be greater or equal 1.0.
2688 (define (gs:set-stroke width cap jn limit
)
2692 (net-send out
(string "set-stroke " gs
:currentCanvas
" " width
" " cap
" " jn
" " limit
"\n"))
2693 (net-send out
(string "set-stroke " gs
:currentCanvas
" " width
" " cap
" " jn
"\n"))
2695 (net-send out
(string "set-stroke " gs
:currentCanvas
" " width
" " cap
"\n"))
2697 (net-send out
(string "set-stroke " gs
:currentCanvas
" " width
"\n"))
2701 ;; @syntax (gs:set-syntax <sym-id> <str-type>)
2702 ;; @param <sym-id> The name of the text pane for syntax coloring is enabled or disabled.
2703 ;; @param <str-type> A string '"lsp"', '"c"', '"cpp"', '"java"' or '"php"' to indicate the
2704 ;; syntax desired, or 'nil' to switch off syntax highlighting.
2706 ;; Colors for syntax highlighting are preselected for a white background, but can be changed using
2707 ;; the following functions: 'gs:set-background', 'gs:set-foreground', 'gs:set-caret', 'gs:set-selection-color'
2708 ;; and 'gs:set-syntax-colors'.
2710 (define (set-syntax id type
)
2711 (net-send out
(string "set-syntax " id
" " type
"\n"))
2714 ;; @syntax (gs:set-syntax-colors <list-rgb-comment> <list-rgb-keyword> <list-rgb-string> <list-rgb-number> <list-rgb-quoted> <list-rgb-parentheses>)
2715 ;; @param <list-rgb-comment> The color for comments.
2716 ;; @param <list-rgb-keyword> The color for reserved keywords.
2717 ;; @param <list-rgb-string> The color for strings.
2718 ;; @param <list-rgb-number> The color for numbers.
2719 ;; @param <list-rgb-quoted> The color for the quote and quoted symbols.
2720 ;; @param <list-rgb-parentheses> The color for parenthesis.
2722 ;; Syntax highlighting colors are given as lists of red, green and blue values between 0.0 and 1.0.
2723 ;; Depending on the syntax colors and the foreground and background colors set for the text pane,
2724 ;; the caret color and color for selected text should also be changed. Only text widgets created
2725 ;; using 'gs:text-pane' feature syntax highlighting.
2727 (define (set-syntax-colors comment keyword text number quoted parentheses
)
2728 (let ( components
(append comment keyword text number quoted parentheses
)
2729 str
"set-syntax-colors System ")
2730 (dolist (c components
)
2731 (write-buffer str
(string c
" ")))
2732 (write-buffer str
"\n")
2736 ;; @syntax (gs:set-tab-size <sym-id> <int-size>)
2737 ;; @param <sym-id> The name of the text area component.
2738 ;; @param <int-size> The tabulator size.
2740 ;; Note that 'gs:set-tab-size' will only work with fixed spaced fonts.
2742 (define (set-tab-size id size
)
2743 (net-send out
(string "set-tab-size " id
" " size
"\n"))
2746 ;; @syntax (gs:set-text <sym-id> <str-text> [<int-index>])
2747 ;; @param <sym-id> The name of the component for which text is set.
2748 ;; @param <str-text> The text to be set in the component.
2749 ;; @param <int-index> The index for a tab if the <sym-id> is a tabbed pane.
2751 (define (set-text id text idx
)
2752 (replace "\r" text
"")
2754 (net-send out
(string "set-text " id
" " (base64-enc text
) " " idx
"\n"))
2755 (net-send out
(string "set-text " id
" " (base64-enc text
) "\n"))
2759 ;; @syntax (gs:set-titled-border <sym-component> <str-title>)
2760 ;; @param <sym-component> The name of the component.
2761 ;; @param <str-title> The text in the titled border around the component.
2763 ;; The component is usually a 'panel'.
2765 (define (set-titled-border id text
)
2766 (net-send out
(string "set-titled-border " id
" " (base64-enc text
) "\n"))
2769 ;; @syntax (gs:set-tool-tip <sym-id> <str-text>)
2770 ;; @param <sym-id> The name of the widget for which to supply a tool tip.
2771 ;; @param <str-text> The text of the tool tip.
2773 ;; The tool tip text is shown when leaving the mouse over the widget for certain
2776 (define (set-tool-tip id text
)
2777 (net-send out
(string "set-tool-tip " id
" " (base64-enc text
) "\n"))
2780 ;; @syntax (gs:set-trace <boolean-flag>)
2781 ;; @param <boolean-flag> The flag 'true' or 'nil'.
2783 (define (set-trace flag
)
2784 (net-send out
(string "set-trace System " flag
"\n"))
2787 ;; @syntax (gs:set-translation <int-x> <int-y>)
2788 ;; @param <int-x> The X-translation value of the current canvas.
2789 ;; @param <int-y> The Y-translation value of the current canvas.
2791 ;; Translates the current origin of the current canvas to the point in <int-x> <int-y>.
2792 ;; Unlike the 'gs:translate-tag' operation which is cumulative, 'gs:set-translation'
2793 ;; will set an absolute translation value each time it is called.
2795 (define (gs:set-translation x y
)
2796 (net-send out
(string "set-translation " gs
:currentCanvas
" " x
" " y
"\n"))
2799 ;; @syntax (gs:set-utf8 <boolean-flag>)
2800 ;; @param <boolean> The flag 'true' or 'nil' to indicate if in UTF-8 mode.
2802 ;; When set in UTF-8 mode, guiserver will convert files to UTF-8 encoding
2803 ;; when loading and saving files. On Mac OX X UTF-8 mode is by default enabled.
2804 ;; On startup guiserver.lsp will detect if newLISP is UTF-8 enabled and
2805 ;; switch the mode in Guiserver accordingly using 'gs:set-utf8'.
2807 (define (gs:set-utf8 flag
)
2808 (net-send out
(string "set-utf8 System " flag
"\n"))
2811 ;; @syntax (gs:set-value <sym-id> <int-value>)
2812 ;; @param <sym-id> The name of a slider or progress bar for which to set the value.
2813 ;; @param <int-value> The integer value of the name to be set.
2815 ;; The value should not be bigger or smaller than the minimum or maximum values set
2816 ;; when creating the slider or progress bar, otherwise the setting will default to either
2817 ;; the minimum or maximum preset value.
2819 (define (set-value id value
)
2820 (net-send out
(string "set-value " id
" " value
"\n"))
2823 ;; @syntax (gs:set-visible <sym-id> <boolean-visible>)
2824 ;; @param <sym-id> The component which is hidden or made visible.
2825 ;; @param <boolean-visible> A flag indicating if the component is visible '"true"', '"nil"'.
2827 ;; Except for frames and dialog windows, components are visible by default. Normally
2828 ;; frames and dialogs are not set visible before all other components are placed inside.
2830 (define (set-visible id flag
)
2831 (net-send out
(string "set-visible " id
" " flag
"\n"))
2834 ;; @syntax (gs:shear-tag <sym-tag> <int-x> <int-y> [<boolean-repaint>])
2835 ;; @param <sym-tag> The tag group to shear.
2836 ;; @param <float-x> The X shearing factor.
2837 ;; @param <float-y> The Y shearing factor.
2838 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
2840 (define (shear-tag tag sx sy
(repaint true
))
2841 (net-send out
(string "shear-tag " gs
:currentCanvas
" " tag
" "
2842 sx
" " sy
" " repaint
"\n"))
2845 ;; @syntax (gs:show-popup <sym-tag> <sym-host> <int-x> <int-y>)
2846 ;; @param <sym-tag> The id of the popup menu.
2847 ;; @param <sym-host> The host container where to pop up the menu.
2848 ;; @param <int-x> The X coordinate of the menu popup position.
2849 ;; @param <int-y> The Y coordinate of the menu popup position.
2851 (define (gs:show-popup id host x y
)
2852 (net-send out
(string "show-popup " id
" " host
" " x
" " y
"\n"))
2855 ;; @syntax (gs:show-tag <sym-tag> [<boolean-repaint>])
2856 ;; @param <sym-tag> The tag of the group to show.
2857 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
2860 (define (show-tag tag
(repaint true
))
2861 (net-send out
(string "show-tag " gs
:currentCanvas
" " tag
" " repaint
"\n"))
2864 ;; @syntax (gs:slider <sym-id> <sym-action> <str-orientation> <int-min> <int-max> <int-initial-value>)
2865 ;; @param <sym-id> The name of the slider.
2866 ;; @param <sym-action> The name of the event handler.
2867 ;; @param <str-orientation> The orientation of the slider '"horizontal"' or '"vertical"'
2868 ;; @param <int-min> The minimum value of the slider.
2869 ;; @param <int-max> The maximum value of the slider.
2870 ;; @param <int-initial-value> The initial value of the slider.
2872 (define (slider id action orient posmin posmax posinit
)
2873 (net-send out
(string "slider " id
" " action
" " orient
" " posmin
" " posmax
" " posinit
"\n"))
2876 ;; @syntax (gs:split-pane <sym-id> <str-orientation> [<float-weight> [<float-location> [<int-divider-size>]]])
2877 ;; @param <sym-id> The name of the split-pane.
2878 ;; @param <str-orientation> The orientation '"horizontal"' or '"vertical"'.
2879 ;; @param <float-weight> The optional weight distribution between '0.0' and '1.0' when re-sizing the window. The default is '0.0'.
2880 ;; @param <float-location> The optional initial divider location between '0.0' and '1.0'.
2881 ;; @param <int-divider-size) The optional size of the draggable divider in pixels.
2883 (define (split-pane id orient
(weight 0.0) (pos 0.5) (dvdr 5))
2884 (net-send out
(string "split-pane " id
" " orient
" " weight
" " pos
" " dvdr
"\n"))
2887 ;; @syntax (gs:tabbed-pane <sym-id> <sym-action> <str-orientation> [<sym-tab> <sym-tab-title> ...])
2888 ;; @param <sym-id> The name of the tabbed pane.
2889 ;; @param <str-orientation> The position of the tabs; either '"top"' (default), '"bottom"','"left"' or '"right"'.
2890 ;; @param <sym-tab> The id symbol name of a tab
2891 ;; @param <str-title> The title of the tab.
2893 (define (tabbed-pane id action orient
)
2894 (let (s (string "tabbed-pane " id
" " action
" " orient
" ")
2897 (write-buffer s
(string (pop t
) " " (base64-enc (pop t
)) " "))
2899 (write-buffer s
"\n")
2903 ;; @syntax (gs:text-area <sym-id> <sym-action> <int-width> <int-height>)
2904 ;; @param <symid> The name of the text area.
2905 ;; @param <sym-action> The name of the event handler.
2906 ;; @param <int-width> The optional width of the text area..
2907 ;; @param <int-height> The optional height of the text area.
2909 ;; (gs:text-area 'TheText 'textarea-event 10 8)
2911 ;; (define (textarea-event id code dot mark) ...)
2913 ;; 'gs:text-area' transmits the following parameters in its event:
2915 ;; id - name of the widget
2916 ;; code - key code equals ASCII code. Only for text keys
2917 ;; dot - position of text caret in the text
2918 ;; mark - extended (selection) position of caret
2922 (define (text-area id action width height
)
2923 (if (and width height
)
2924 (net-send out
(string "text-area " id
" " action
" " width
" " height
"\n"))
2925 (net-send out
(string "text-area " id
" " action
"\n")))
2928 ;; @syntax (gs:text-field <sym-id> <sym-action> <int-columns>)
2929 ;; @param <sym-id> The name of the text field.
2930 ;; @param <sym-action> The name of the event handler.
2931 ;; @param <int-columns> The number of columns in the text field.
2933 ;; (gs:text-field 'TheText 'textfield-event)
2935 ;; The 'textfield-event' is fired when the enter key is pressed in the
2938 (define (text-field id action columns
)
2939 (net-send out
(string "text-field " id
" " action
" " columns
"\n"))
2942 ;; @syntax (gs:text-pane <sym-id> <sym-action> <str-style> [<int-width> <int-height>])
2943 ;; @param <sym-id> The name of the text pane.
2944 ;; @param <sym-action> The key action handler for the html pane.
2945 ;; @param <sym-style> The content type of the text pane.
2946 ;; @param <int-width> The optional width of the pane.
2947 ;; @param <int-height> The optional height of the pane.
2949 ;; The 'gs:text-pane' is used similar to 'gs:text-area. The following styles
2950 ;; are supported in <sym-style>:
2956 ;; The 'gs:text-pane' widget will automatically display scroll bars when
2957 ;; text does not fit in the visible space of the pane. When entering parentheses
2958 ;; they are automatically matched with their opening or closing counterparts, if they exist.
2959 ;; If this is undesired behavior, the simpler 'gs:text-area' control should
2962 ;; On each change of the caret or selection in the text pane
2963 ;; an event is fired containing several parameters about the caret and selection
2964 ;; positions, the last character typed, and the modifier keys used. See the
2965 ;; the file 'newlisp-edit.lsp' for a complex application using all features
2966 ;; available in this widget.
2968 ;; To make hyperlinks in 'HTML' formatted text clickable, editing must
2969 ;; be disabled using the 'gs:set-editable' function. The functions 'gs:set-font'
2970 ;; and 'gs:append-text' will work only on the 'text/plain' content style.
2972 ;; (gs:text-pane 'TheTextPane 'textpane-event "text/plain")
2974 ;; (define (textpane-event id code mods dot mark len undo redo) ...)
2976 ;; 'gs:text-pane' transmits the following parameters in its event:
2978 ;; id - name of the widget
2979 ;; code - key code equals ASCII code. Only for text keys
2980 ;; mods - keys pressed together with the previous, like shift, ctrl etc.
2981 ;; dot - position of the text caret in the text
2982 ;; mark - extended (selection) position of the caret
2983 ;; len - length of the text in the textarea
2984 ;; undo - undo enabled/disabled
2985 ;; redo - redo enabled/disabled
2988 (define (text-pane id action style width height
)
2989 (if (and width height
)
2990 (net-send out
(string "text-pane " id
" " action
" " style
" " width
" " height
"\n"))
2991 (net-send out
(string "text-pane " id
" " action
" " style
"\n"))
2995 ;; @syntax (gs:toggle-button <sym-id> <sym-action> <str-text> [<bool-selected>])
2996 ;; @param <sym-id> The name of the toggle button.
2997 ;; @param <sym-action> The name of the event handler.
2998 ;; @param <str-text> The optional text of the toggle button.
2999 ;; @param <bool-selected> An optional flag 'true' or 'nil' (default) indicating the initial state of the toggle button.
3001 (define (toggle-button id action text selected
)
3003 (net-send out
(string "toggle-button " id
" " action
" " (base64-enc text
) " " selected
"\n"))
3004 (net-send out
(string "toggle-button " id
" " action
"\n")))
3007 ;; @syntax (gs:tool-bar <sym-frame> [<bool-floatable> <int-hgap> <int-vgap>])
3008 ;; @param <sym-frame> The name of the frame hosting the toolbar.
3009 ;; @param <bool-floatable> The optional flag 'true' or 'nil' to indicate if the toolbar can be detached.
3010 ;; @param <int-hgap> The horizontal gap between components on the toolbar.
3011 ;; @param <int-vgap> The vertical gap between the components on the toolbar.
3013 (define (tool-bar aframe floatable width height
)
3014 (if (and width height
)
3015 (net-send out
(string "tool-bar " aframe
" " floatable
" " width
" " height
"\n"))
3016 (net-send out
(string "tool-bar " aframe
" " floatable
"\n")))
3019 ;; @syntax (gs:translate-tag <sym-tag> <int-x> <int-y> [<boolean-repaint>])
3020 ;; @param <sym-tag> The name tag of the group to translate.
3021 ;; @param <int-x> The X-coordinate translation value.
3022 ;; @param <int-y> The Y-coordinate translation value.
3023 ;; @param <boolean-repaint> An optional flag to indicate if repainting is required (default is 'true').
3025 ;; Moves the origin of the coordinate system of all objects tagged with <sym-tag>.
3026 ;; Like all tag operations multiple 'gs:translate-tag' operations are cumulative.
3028 (define (translate-tag tag x y
(repaint true
))
3029 (net-send out
(string "translate-tag " gs
:currentCanvas
" " tag
" " x
" " y
" " repaint
"\n"))
3032 ;; @syntax (gs:undo-text <sym-id>)
3033 ;; @param <sym-id> The id of the 'gs:text-pane' where to perform an undo operation.
3035 (define (undo-text id
)
3036 (net-send out
(string "undo-text " id
"\n"))
3039 ;; @syntax (gs:undo-enable <sym-id> <boolean-enabled)
3040 ;; @param <sym-id> The id of the 'gs:text-pane' for which to enabe/disable undo.
3042 (define (undo-enable id enabled
)
3043 (net-send out
(string "undo-enable " id
" " enabled
"\n"))
3047 ;; @syntax (gs:update)
3049 ;; Forces a repaint of the current canvas, e.g. after changing the scale or translation of a visible
3050 ;; canvas. This function is rarely used, as most screen updates are performed automatically.
3051 ;; All tag operations can carry an additional parameter to force update after they have been
3055 (net-send out
(string "update " gs
:currentCanvas
"\n"))
3058 ;; @syntax (gs:window <sym-id> <int-x> <int-y> <int-width> <int-height>)
3059 ;; @param <sym-id> The name of the invisible window.
3060 ;; @param <int-x> The x-coordinate of the screen position.
3061 ;; @param <int-y> The y-coordinate of the screen position.
3062 ;; @param <int-width> The width of the window.
3063 ;; @param <int-height> The height of the window.
3065 ;; Creates a borderless window. Note that a borderless window may treat
3066 ;; some hosted components differently from normal frames and dialogs.
3068 (define (window id x y width height
)
3069 (net-send out
(string "window " id
" " x
" " y
" " width
" " height
"\n"))
3072 ;; @syntax (gs:window-closed <sym-id> <sym-action>)
3073 ;; @param <sym-id> The name of the frame or dialog.
3074 ;; @param <sym-action> The action to perform when the frame or dialog closes.
3076 ;; A window or dialog window can be closed using the system close button in
3077 ;; one of the corners of the window. In this case it is useful to specify
3078 ;; a handler function which is called upon closing.
3080 (define (frame-closed id action
)
3081 (net-send out
(string "frame-closed " id
" " action
"\n"))
3084 (define (window-closed id action
)
3085 (net-send out
(string "frame-closed " id
" " action
"\n"))
3089 ;; @syntax (gs:window-moved <sym-id> <sym-action>)
3090 ;; @param <sym-id> The name of the frame or dialog.
3091 ;; @param <sym-action> The action to perform when the frame or dialog moves.
3093 ;; The event will carry the <sym-id> of the window or dialog and current <tt>X</tt> and <tt>Y</tt>
3094 ;; coordinates on the screen.
3097 (define (frame-moved id action
)
3098 (net-send out
(string "frame-moved " id
" " action
"\n"))
3101 (define (window-moved id action
)
3102 (net-send out
(string "frame-moved " id
" " action
"\n"))
3106 ;; @syntax (gs:window-resized <sym-id> <sym-action>)
3107 ;; @param <sym-id> The name of the frame or dialog.
3108 ;; @param <sym-action> The action to perform when the frame or dialog is resized.
3110 ;; The event will carry the <sym-id> of the window or dialog and current width and
3113 (define (frame-resized id action
)
3114 (net-send out
(string "frame-resized " id
" " action
"\n"))
3117 (define (window-resized id action
)
3118 (net-send out
(string "frame-resized " id
" " action
"\n"))