Contents Up Previous Next

Grid overview

Function group/class: Grid

The grid class is a window designed for displaying data in tabular format. Possible uses include:

This manual currently describes the version of Grid that operates under Windows, implementing using mostly generic wxWindows code. It is intended to provide a similar API for Motif using the public domain Xbae matrix widget, included in the wxGrid distribution. Work needs to be done to wrap the Xbae functionality in a similar API.

The appearance and behaviour of a grid
Example


The appearance and behaviour of a grid

The following screenshot shows the initial appearance of the sample grid application.

The Grid class is a panel that provides a text editing area, and a grid with scrollbars. The grid has horizontal and vertical label areas whose colours may be changed independently from the cell area. The text editing area, and the label areas, may be switched off if desired.

The user navigates the grid using the mouse to click on cells and scroll around the virtual grid area (no keyboard navigation is possible as yet). If the edit control is enabled, it always has the focus for the currently selected cell and the user can type into it. The text in the edit control will be reflected in the currently selected cell.

If the row and column label areas are enabled, the user can drag on the label divisions to resize a row or column.

The sample application allows the user to change various aspects of the grid using the Grid API. These include:

There are various other aspects that can be controlled via the API, including changing individual cell font and colour properties.

You need to call grid-create-grid before there are any cells in the grid.

All row and column positions start from zero, and dimensions are in pixels.

If you make changes to row or column dimensions, call grid-update-dimensions and then grid-adjust-scrollbars. If you make changes to the grid appearance (such as a change of cell background colour or font), call window-refresh for the changes to be shown.


Example

The following is an example of using the grid functionality.

;;; grid.clp
;;; grid test
;;; Load using -clips <file> on the command line or using the Batch
;;; or Load commands from the CLIPS development window; type
;;; (app-on-init) to start.

(defglobal ?*main-frame* = 0)
(defglobal ?*grid* = 0)

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

(deffunction on-activate (?frame ?active)
  (if (> ?*grid* 0) then (grid-on-activate ?*grid* ?active))
)

(deffunction on-menu-command (?frame ?id)
 (switch ?id
  (case 200 then (message-box "CLIPS for wxWindows Demo
by Julian Smart (c) 1993" wxOK 1 0 "About wxWindows CLIPS Demo"))
  (case 3 then (if (on-close ?frame) then (window-delete ?frame)))
 )
)

;;; Test program to create a frame
(deffunction app-on-init ()
  (unwatch all)

  (bind ?*main-frame* (frame-create 0 "wxCLIPS Grid Test" -1 -1 400 300))

  (window-add-callback ?*main-frame* OnClose on-close)
  (window-add-callback ?*main-frame* OnMenuCommand on-menu-command)
  (window-add-callback ?*main-frame* OnActivate on-activate)

  ;;; Make a menu bar
  (bind ?file-menu (menu-create))
  (menu-append ?file-menu 3 "&Quit")

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

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

  ;;; Make a grid
  (bind ?*grid* (grid-create ?*main-frame* 0 0 400 300))
  (grid-create-grid ?*grid* 10 8)
  (grid-set-column-width ?*grid* 3 200)
  (grid-set-row-height ?*grid* 4 45)
  (grid-set-cell-value ?*grid* "First cell" 0 0)
  (grid-set-cell-value ?*grid* "Another cell" 1 1)
  (grid-set-cell-value ?*grid* "Yet another cell" 2 2)
  (grid-set-cell-text-font ?*grid* (font-create 12 wxROMAN wxITALIC wxNORMAL 0) 0 0)
  (bind ?red (colour-create RED))
  (grid-set-cell-text-colour ?*grid* ?red 1 1)
  (bind ?cyan (colour-create CYAN))
  (grid-set-cell-background-colour ?*grid* ?cyan 2 2)
  (grid-update-dimensions ?*grid*)

  (window-centre ?*main-frame* wxBOTH)

  (window-show ?*main-frame* 1)

  ?*main-frame*)