Lisp HUG Maillist Archive

CAPI: text-input-pane-selection and more

Hi!

I'm currently trying to write an application where I have two
(multi-line) text-input-panes (or maybe editor-panes, I'm not sure
about that yet) that interact with each other. There are mainly two
things I want to achieve:

1. If the user makes a selection in one of the panes the selection in
   the other pane should be changed by the program according to the
   user's action.

2. I want to control how the extension is extended if the user
   double-clicks or triple-clicks in one of the panes.

As you might have guessed the reason for my email is that I don't know
how to do this... :)

For the first point I think this has to be done by change-callbacks
for both panes but I couldn't find anything in the docs about the
current selection. Fiddling around with APROPOS revealed
CAPI:TEXT-INPUT-PANE-SELECTION which seems to yield the values that I
want. This function also seems to be SETFable but I can't find out how
to use it.

For the second point I currently have no idea at all... :(

BTW, this is only my second CAPI application (and the first one was
rather simple) so I might have missed a few points. However, it looks
to me as if I've bought a really nice product which is extremely
lacking as far as the quality of the documentation is concerned. A few
examples:

1. APROPOS reveals a lot of exported symbols that I couldn't find in
   the docs, including but not limited to

     CAPI:TEXT-INPUT-PANE-SELECTION
     CAPI:TEXT-INPUT-PANE-SELECTED-TEXT
     CAPI:TEXT-INPUT-PANE-BEFORE-CHANGE-CALLBACK
     CAPI:SET-TEXT-INPUT-PANE-SPINBOX-RANGE

   My apologies if they are in the docs somewhere but if they are then
   they're hidden very well.

2. LW comes with a full-blown rich-text editor in the examples/capi
   folder which is quite amazing given the length of the
   code. However, most of the functions used in this program aren't
   documented either although the example seems to be six years old
   and is still working.

If a new release of LispWorks is scheduled I'd rather like to have
better documentation than more features (if the wish list is still
open).

I'm using LW pro 4.2.7 on Windows and Linux, doing most of the CAPI
development with WinXP pro.

Thanks,
Edi.

PS: I've also had a couple of issues with the Interface Builder. I'd
    be happy to send separate bug reports if you're interested.


Re: CAPI: text-input-pane-selection and more

Unable to parse email body. Email id is 859

Re: CAPI: text-input-pane-selection and more

Edi Weitz <edi@agharta.de> writes:

> 2. I want to control how the extension is extended if the user
>    double-clicks or triple-clicks in one of the panes.

Sorry, a typo. I wanted to say "how the SELECTION is extended..."


Re: CAPI: text-input-pane-selection and more

Nick Levine <ndl@ravenbrook.com> writes:

Thanks for the quick reply!!

>    1. If the user makes a selection in one of the panes the selection
>       in the other pane should be changed by the program according to
>       the user's action.
> 
> Something like (untested):
> 
> (let ((text-input-one (make-instance 'capi:text-input-pane
>                                      :change-callback-type :none))
>       (text-input-two (make-instance 'capi:text-input-pane
>                                      :change-callback-type :none)))
>   (capi:contain (make-instance 'capi:column-layout
>                                :description (list text-input-one
>                                                   text-input-two)))
>   (setf (capi:text-input-pane-change-callback text-input-one)
>         (lambda ()
>           (setf (capi:text-input-pane-text text-input-one)
>                 (do-whatever-with 
>                  (capi:text-input-pane-text text-input-two))))
>         (capi:text-input-pane-change-callback text-input-two)
>         (lambda ()
>           (setf (capi:text-input-pane-text text-input-two)
>                 (do-whatever-with 
>                  (capi:text-input-pane-text text-input-one))))))

Hmm, but this doesn't address my main concern - how to get and set the
selection (the selected text) in the text-input-pane. Or at least I
don't see it.
 
>    2. I want to control how the extension is extended if the user
>       double-clicks or triple-clicks in one of the panes.
> 
> The choices that support double click are controlled by the
> :interaction keyword when initializing a capi:choice.

This is a mis-understanding due to my typo. I was interested in
extending the selection, meaning the selected text in the
text-input-pane.

> I don't imagine you'll ever get your hands on a triple-click,
> certainly not on Windows.

But other apps (even Emacs on Windows which is not a typical Windows
app I think) can do that. Does this mean I have to resort to the WIN32
API?

>    PS: I've also had a couple of issues with the Interface Builder. I'd
>        be happy to send separate bug reports if you're interested.
> 
> Not I. I have never imagined that Interface Builders are ever going to
> be capable of doing anything particularly useful.  :-)

I've found myself building the actual interface manually but I think
the IB is quite convenient for finding out what's there and trying out
things.

Thanks again,
Edi.


Re: CAPI: text-input-pane-selection and more

Unable to parse email body. Email id is 863

Re: CAPI: text-input-pane-selection and more

----- Original Message -----
From: "David Fox" <davef@xanalys.com>
Subject: Re: CAPI: text-input-pane-selection and more


> :confirm-change-function
> A function called to validate a change. Note: Implemented for
Motif/Lesstif only, >not MSWindows or MacOS. (<------ What a treat!)



Re: CAPI: text-input-pane-selection and more

David Fox <davef@xanalys.com> writes:

> Here's an example which I think does what you're after for 1, though
> I don't think we can rely on the change-callback on Motif since
> there is no callback on selection in this widget. My example
> interface feels pretty wierd (i.e. do a select gesture in pane1, see
> a selection in pane2) so I'm wondering why you want to do this at
> all.

Thanks, the example code was very helpful. What I have in mind isn't
as weird as you might think... :)

I'll probably release it publicly once it's done.

> As Nick pointed out triple-click is non-standard and the CAPI does
> not support it, while double-click has a standard action.

Does that mean I can react to double clicks in an editor pane? How do
I do that? I see there's ACTION-CALLBACK for some other kinds of panes
but not for text panes.

> Yes we will indeed be addressing many of the documentation gaps,
> especially for the CAPI, FLI and EDITOR packages. These are the
> areas which the 'wish list' feedback on this mailing list last year
> identified as most in need of better documentation.

That's good to hear! Thanks.

> If you think they're of general interest do post, though it sounds
> like a bug report (standard format please) to
> lisp-support@xanalys.com might be more appropriate.

OK, I'll send bug reports if I find some time.

One other thing: About this rich-text-pane (or what's it called) - it
looks like the symbols are exported to the Linux version but it's only
really available in the Windows version. I guess this is part of the
WIN32 API because the interface (from what I see in the example code)
doesn't "feel" like the rest of CAPI. Is that right?

Anyway - I might want to visually emphasize parts of the text in an
editor-pane (or text-input-pane or something similar), be it by the
use of different foreground colors, different background colors, bold
face, or whatever. Is that possible without a rich-text-pane?

Thanks again,
Edi.


Re: CAPI: text-input-pane-selection and more

Unable to parse email body. Email id is 867

Re: CAPI: text-input-pane-selection and more

David Fox <davef@xanalys.com> writes:

> What you need to do is subclass CAPI:EDITOR-PANE and specify your
> own input model by the :INPUT-MODEL initarg. Inspect the INPUT-MODEL
> slot after (MAKE-INSTANCE 'CAPI:EDITOR-PANE) and you will see which
> gestures need a modified action.

Thanks, that did help very much! I also noticed (after reading your
mail) that the INPUT-MODEL stuff is actually mentioned in the
docs. Shame on me... :(

> Yes. You can use editor functions to set colors in the text of an
> CAPI:EDITOR-PANE, using the Face mechanism that implements the
> syntax coloring. I think that's the portable solution you're
> after. Here's some code that should help.
> 
> (defvar *red-yellow*
>   (editor:make-face 'ry
>                     :foreground :red 
>                     :background :yellow))
> 
> (defvar *buffer* (editor:buffer-from-name "foo.txt"))
> (defvar *s* (editor:buffers-start *buffer*))
> (defvar *e* (editor:buffers-end *buffer*))
> (editor::push-region-face *red-yellow* *s* *e*)

OK, another one that helped me get further. However, this also results
in three new questions:

1. It looks like the arguments to EDITOR::PUSH-REGION-FACE have to be
   of type EDITOR::POINT or EDITOR::I-POINT (which also means the
   buffer is encoded therein), so in order to color an arbitrary part
   of my buffer I have to create an EDITOR::POINT, right?

   I found the function EDITOR::MAKE-I-POINT (IIRC) but couldn't get
   it to work. What I'm currently doing is this:

     (defun make-point (buffer offset)
       (let ((point (editor:copy-point (editor:buffers-start buffer))))
         (setf (slot-value point 'editor::offset) offset)
         point))

   And then, to color, say, position 3 to 7 of a certain editor-pane
   of my interface I do something like this:

     (editor::push-region-face *red-yellow*
                               (make-point (editor-pane-buffer (target-pane my-interface)) 3)
                               (make-point (editor-pane-buffer (target-pane my-interface)) 7)))

   Is this completely stupid or am I close to how it should be done?

2. I haven't yet found out how to reset the whole pane to a
   "non-colored" state. I though this one should work...

      (defparameter *normal*
        (editor:make-face 'bw
                          :foreground :black
                          :background :white))

      (defun reset-target-region ()
        (editor::push-region-face *normal*
                                  (editor:buffers-start (editor-pane-buffer (target-pane my-interface)))
                                  (editor:buffers-end (editor-pane-buffer (target-pane my-interface)))))

   ...but it doesn't. Every other combination of foreground and
   background colors seems to work but black-and-white doesn't,
   i.e. the *red-yellow* parts stay as they are . Why?

3. If I'm implementing my own callback for, say, (:BUTTON-1
   :SECOND-PRESS), I use CAPI::MOUSE-EDITOR-CALL which gives me "raw"
   x and y coordinates. I then use EDITOR::MOUSE-SET-POINT to
   translate these to a point. Is that the right way to do it?

> In LispWorks4.3 (tentatively scheduled for the end of June) we will
> be including editor source code allowing you to find this
> undocumented functionality for yourself.

That's great! I'm glad to hear this. I remember being one of those to
recommend this (pointing to Digitool doing this with the source code
to Fred) and I'm happy to see that Xanalys is listening to their
customers... :)

Thanks,
Edi.


Updated at: 2020-12-10 09:00 UTC