From: Guy Hall
Subject: Attn: Interleaf Lisp Hackers - Navigating Tables
Date: 
Message-ID: <3491324E.6EC7@gecm.com.no.spam>
Seasons Greetings fellow hackers,

I've got a function that clears the fill colour/pattern from
table cells using :fill-visible nil. The user is prompted to
select one of the following options from a stickup:

  Current Only   Row   Column   Table  ALL Tables   Cancel

The function itself is implemented as a callback and added to
the Tables "popup" menu.  It works fine except I have a major
problem...

How can you determine the position in terms of row and column
of the caret over the table.  To be able to process the cell,
row or column you need to know the position of the caret then
use row and column as parameters of (tell table mid:get-cell)
in order to obtain the object of table-cell class and set the
:fill-visible property to nil.

Any ideas anyone.

I know this is not going to be particularly easy, for example
to navigate from a component in a cell to the cell object you
have to do 5 nested (tell object mid:get-parent)'s !

I'm running Ileaf 6.3.0-003 under Windows NT 4.0.

The following is the routine itself.  Currently it will only
clear the top left cell, left column or first row due to the
described problem.  Apolgoies for some of the line lengths.

<lisp>

;; Routine to add a Clear Cell(s) function
;; to the table editor popup menu.
;;
;; G. R. Hall
;;
;; 11/12/97

(lisp-set-implementation "Interleaf Lisp" "2.0")

(require "cbdef")
(require "latemenu")

(defactioncb (doc-clear-table-cells-pu-cb)
  (let (get-cell table cell rows cols range r c x y)
    (defun get-cell (cmpn)
      (tell (tell (tell (tell (tell cmpn mid:get-parent) mid:get-parent)
mid:get-parent) mid:get-parent) mid:get-parent))
    (unless (equal 5 (setq range (stk-open "Select range of cells to
clear:" :buttons '("Current Only" "Row" "Column" "Table" "ALL Tables"
"Cancel"))))
      (setq table (tell (doc-point-cmpn) mid:get-parent))
      (setq rows (tell table mid:get-props :number-of-rows))
      (setq cols (tell table mid:get-props :number-of-columns))
      (inc rows)
      (inc cols)

      ;; need to know what cell we're at and translate to row and colunm

;;      (setq r 1)
;;      (while (not (equal r rows))
;;        (setq c 1)
;;        (while (not (equal c cols))
;;          (when (equal (tell table mid:get-cell r c)
*the-cell-the-carets-over*)
;;            (setq x c)
;;            (setq y r))
;;          (inc c))
;;        (inc r))

      (cond
        ((equal 0 range)
          (setq r 1)
          (setq c 1)
          (tell (get-cell (tell table mid:get-cell r c)) mid:set-props
:fill-visible nil))
        ((equal 1 range)
          (setq r 1)
          (setq c 1)
          (while (not (equal c cols))
            (tell (get-cell (tell table mid:get-cell r c)) mid:set-props
:fill-visible nil)
            (inc c)))
        ((equal 2 range)
          (setq r 1)
          (setq c 1)
          (while (not (equal r rows))
            (tell (get-cell (tell table mid:get-cell r c)) mid:set-props
:fill-visible nil)
            (inc r)))
        ((equal 3 range)
          (setq r 1)
          (while (not (equal r rows))
            (setq c 1)
            (while (not (equal c cols))
              (tell (get-cell (tell table mid:get-cell r c))
mid:set-props :fill-visible nil)
              (inc c))
            (inc r)))
        ((equal 4 range)
          (setq cell (tell-class doc-table-cell-class mid:get-first))
          (while cell
            (tell cell mid:set-props :fill-visible nil)
            (setq cell (tell cell mid:get-next)))))
      (tell *doc-editor* mid:set-props :modify 1))))

(doc-menu-add
  (:popup "Tables"
    ("Clear Cell(s)" #'doc-clear-table-cells-pu-cb)))

</lisp>

Shukas,
 SpLiT.

O--------------------------------O----------------------------------O
| Guy Hall (SpLiT)               | email: ········@gecm.com.no.spam |
| Mission Avionics Division      | phone: (+44) 01634 844400 x5009  |
| GEC-Marconi Avionics Limited   | tlink: ······@··@csd06v (GMAv)   |
| Remove no.spam to return email | g-net: 791-5009 (GMAv)           |
O--------------------------------O----------------------------------O
| Did you know when you're not looking, mushrooms go Ftang, Ftang ? |
O--------------------------------O----------------------------------O
From: Guy Hall
Subject: Re: Attn: Interleaf Lisp Hackers - Navigating Tables - ** SOLVED **
Date: 
Message-ID: <34916752.705A@gecm.com.no.spam>
This is a multi-part message in MIME format.

--------------6165337651A4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Well, it couldn't be more simple.   It seems those lovely
people at Interleaf have provided some new methods to the
doc-table-editor-class (among others):

  mid:get-row-number
  mid:get-column-number

I found this out by doing the following in a Read-Eval:

 (tell-class doc-table-editor-class mid:get-methods)

which revealed all the new methods not documented in the
LRM for version 5.

This tempts me to perform this action on all classes such
that I've got a complete list of all the latest methods !

I've attached the complete function for those who wish to
use it.  Simply select and Load it.  A new option will be
added to the Tables popup menu called Clear Cell(s).

Obviously it will only work on version 6.*. 

Shukas,
 SpLiT.

O--------------------------------O----------------------------------O
| Guy Hall (SpLiT)               | email: ········@gecm.com.no.spam |
| Mission Avionics Division      | phone: (+44) 01634 844400 x5009  |
| GEC-Marconi Avionics Limited   | tlink: ······@··@csd06v (GMAv)   |
| Remove no.spam to return email | g-net: 791-5009 (GMAv)           |
O--------------------------------O----------------------------------O
| Did you know when you're not looking, mushrooms go Ftang, Ftang ? |
O--------------------------------O----------------------------------O

--------------6165337651A4
Content-Type: text/plain; charset=us-ascii; name="clearcell.lsp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="clearcell.lsp"

;; Routine to add a Clear Cell(s) function
;; to the table editor popup menu.
;;
;; G. R. Hall
;;
;; 11/12/97

(lisp-set-implementation "Interleaf Lisp" "2.0")

(require "cbdef")
(require "latemenu")

(defactioncb (doc-clear-table-cells-pu-cb)
  (let (get-cell table cell rows cols range r c)
    (defun get-cell (cmpn)
      (tell (tell (tell (tell (tell cmpn mid:get-parent) mid:get-parent) mid:get-parent) mid:get-parent) mid:get-parent))
    (unless (equal 5 (setq range (stk-open "Select range of cells to clear:" :buttons '("Current Only" "Row" "Column" "Table" "ALL Tables" "Cancel"))))
      (setq table (tell (doc-point-cmpn) mid:get-parent))
      (setq rows (tell table mid:get-props :number-of-rows))
      (setq cols (tell table mid:get-props :number-of-columns))
      (inc rows)
      (inc cols)
      (setq r (tell *table-editor* mid:get-row-number))
      (setq c (tell *table-editor* mid:get-column-number))
      (cond
        ((equal 0 range)
          (tell (get-cell (tell table mid:get-cell r c)) mid:set-props :fill-visible nil))
        ((equal 1 range)
          (setq c 1)
          (while (not (equal c cols))
            (tell (get-cell (tell table mid:get-cell r c)) mid:set-props :fill-visible nil)
            (inc c)))
        ((equal 2 range)
          (setq r 1)
          (while (not (equal r rows))
            (tell (get-cell (tell table mid:get-cell r c)) mid:set-props :fill-visible nil)
            (inc r)))
        ((equal 3 range)
          (setq r 1)
          (while (not (equal r rows))
            (setq c 1)
            (while (not (equal c cols))
              (tell (get-cell (tell table mid:get-cell r c)) mid:set-props :fill-visible nil)
              (inc c))
            (inc r)))
        ((equal 4 range)
          (setq cell (tell-class doc-table-cell-class mid:get-first))
          (while cell
            (tell cell mid:set-props :fill-visible nil)
            (setq cell (tell cell mid:get-next)))))
      (tell *doc-editor* mid:set-props :modify 1))))

(doc-menu-add
  (:popup "Tables"
    ("Clear Cell(s)" #'doc-clear-table-cells-pu-cb)))
--------------6165337651A4--