Using wxCLIPS functions

wxCLIPS is really an interface to a C++ library, wxWindows. In wxWindows, each GUI entity is an object, with member functions associated with the object's class.

wxCLIPS has to use functions, so most functions take an integer identifier used as the handle of the object and returned from its creation function. Function names are comprised of the type of GUI element followed by the actual function name (corresponding to the C++ member function). Examples are check-box-set-value and frame-set-menu-bar. In C++, these are defined as wxCheckBox::SetValue and wxFrame::SetMenuBar respectively.

Creation functions are of the form 'GUI element'-create, and return the ID of the new object.

The following program shows off some of the wxCLIPS GUI capabilities, by create a frame with a panel and various panel items,

;;; Shows how a frame may be created, with a menu bar and
;;; panel, using low-level windows functions.
;;; Load using -clips  on the command line or using the Batch
;;; or Load commands from the CLIPS development window; type
;;; (app-on-init) to start.

;;; Sizing callback
(deffunction my-on-size (?id ?w ?h)
 (format t "Got an OnSize message for frame or dialog %d, size (%d, %d).%n" ?id ?w ?h)
)

(deffunction on-close (?frame)
 (format t "Closing frame.%n")
 1)

(deffunction on-menu-command (?frame ?id)
 (format t "Got menu command %d.%n" ?id)
 (if (eq ?id 200) 
  then (message-box "CLIPS for wxWindows Demo
by Julian Smart (c) 1993" "About wxWindows CLIPS Demo")
  else (if (eq ?id 3) then (window-delete ?frame)))
 )

;;; Button callback
(deffunction frame-button-proc (?id)
 (bind ?parent (window-get-parent ?id))
 (bind ?grandparent (window-get-parent ?parent))
 (format t "Pressed button %d%n" ?id)
 (window-show ?grandparent 0)
 (window-delete ?grandparent)
)

;;; Test program to create a frame
(deffunction app-on-init ()
  (bind ?frame (frame-create 0 "My frame" -1 -1 550 400))
;  (window-add-callback ?frame OnSize my-on-size)
  (window-add-callback ?frame OnClose on-close)
  (window-add-callback ?frame OnMenuCommand on-menu-command)

  ;;; Make a menu bar
  (bind ?file-menu (menu-create))
  (menu-append ?file-menu 1 "&Load file")

  (bind ?pull-right (menu-create))
  (menu-append ?pull-right 100 "&Twips")
  (menu-append ?pull-right 101 "&10th mm")

  (menu-append ?file-menu 2 "&Scale picture" ?pull-right)
  (menu-append-separator ?file-menu)
  (menu-append ?file-menu 3 "&Quit")

  (bind ?help-menu (menu-create))
  (menu-append ?help-menu 200 "&About")

  (bind ?menu-bar (menu-bar-create))
  (menu-bar-append ?menu-bar ?file-menu "&File")
  (menu-bar-append ?menu-bar ?help-menu "&Help")

  (frame-set-menu-bar ?frame ?menu-bar)

  ;;; Make a panel and panel items

  (bind ?panel (panel-create ?frame))

  (bind ?button (button-create ?panel frame-button-proc "A button"))
  (bind ?text (text-create ?panel "" "A text item" "Initial value" -1 -1 200))
  (bind ?check (check-box-create ?panel "" "A check box"))

  (panel-new-line ?panel)

  (bind ?choice (choice-create ?panel "" "A choice item"))
  (choice-append ?choice "One")
  (choice-append ?choice "Two")
  (choice-append ?choice "Three")
  (choice-append ?choice "Four")

  (message-create ?panel "Hello! A simple message")

  (bind ?list (list-box-create ?panel "" "A list" 0 -1 -1 100 100))
  (list-box-append ?list "Apple")
  (list-box-append ?list "Pear")
  (list-box-append ?list "Orange")
  (list-box-append ?list "Banana")
  (list-box-append ?list "Fruit")

  (panel-new-line ?panel)

  (bind ?slider (slider-create ?panel "" "A slider" 40 22 101 150))

  (bind ?multi (multi-text-create ?panel "" "Multiline text" "Some text"))

  (window-show ?frame 1)

  ?frame)