Author Topic: Esc closes form  (Read 6603 times)

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Esc closes form
« on: September 08, 2006, 02:44:19 am »
I have a form with an Editor Control. The control seems to have successfully been put into Gnu emacs mode, wherein the escape key is used for things like Esc > (go to end of buffer). However, when editing in the editor control on my form, pressing Esc causes the form to close immediately (hilarity and data loss ensues).

I really want keystrokes like Esc and Tab to be given to an editor control when it has the input focus. I'm happy to use the mouse to move the focus elsewhere (come to think of it, I wouldn't mind making the C-X O other-window emacs command move the focus along). Alas, I'm finding it really difficult to piece together how all the event handling fits together in the SlickEdit environment.

Can someone point me down the right road to route those keystrokes where I want them to go?

hs2

  • Senior Community Member
  • Posts: 2740
  • Hero Points: 288
Re: Esc closes form
« Reply #1 on: September 08, 2006, 09:49:20 am »
Maybe you have to define your own event handlers for that form.
Check your form definition which default eventtabs are used (p_eventtab / p_eventtab2 properties)
Define your own p_eventtab handlers and let the p_eventtab2 do the rest:
Code: [Select]
defeventtab my_edit_form
void my_edit_form.on_close()
{
   _delete_window();
}
void my_edit_form.'ESC'()
{
   call_event(p_active_form,ON_CLOSE);
}
...

HS2

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Re: Esc closes form
« Reply #2 on: September 08, 2006, 06:51:16 pm »
Couldn't quite grok your explanation; it looked like you were demonstrating how to make the Escape key close the form, which is the default behavior I'm trying to overcome. I'm also having trouble finding any explanation of event inheritance and the difference between p_eventtab and p_eventtab2 in the documentation.

It's true that I can define a form event handler which gets invoked when the user presses the Escape key. However, I don't see how to get that key delivered to the editor control that currently has the input focus. I tried using call_event(WindowIdOfEditor,ESC), but that produced infinite recursion. Seems like that implies that the way the form manager picks off navigation events is by modifying their individual event tables (but I find all this pretty opaque, so I may be as clueless as I feel right now).

Defining an ESC event for the editor control doesn't seem to get invoked, which is analagous to the Windows dialog design, wherein the dialogbox manager picks off navigation events before the child controls get a chance to see them.

The need for an individual control to receive what are normally navigation keystrokes has a longstanding solution in Windows, so I guess I assume that there's one here, and I'm still hoping I don't have to manually code for every editor command that starts with an ESC key.

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Re: Esc closes form
« Reply #3 on: September 08, 2006, 10:21:07 pm »
Now I see that the regex evaluator form manages to give me
an editor control for which the Escape key goes to the control
and does not dismiss the form. Unfortunately, I haven't been
able to figure out how it does that. More unfortunately, it seems
I've patched an event table somewhere that is persistent and
have no clue how to get it unpatched :-).
 
Cool stuff!

Graeme

  • Senior Community Member
  • Posts: 2419
  • Hero Points: 320
Re: Esc closes form
« Reply #4 on: September 09, 2006, 07:24:04 am »

I tried this - using Windows XP, Slick 11.0.2

Start a new form; put an edit control on it.
Load and run -> pressing escape when the edit control has the focus does nothing.

Then add a handler for ESC

defeventtab form6;
void ctledit1.'ESC'()
{
   _insert_text('hello ');
}

and pressing escape when the edit control has the focus inserts 'hello ' into the edit control.

See also the "event names" topic in the help where it has the following

Code: [Select]
def "A-x"=safe_exit;  // Note that "A-a" is different than "A-A" which
                     // requires the Alt and Shift keys to be pressed.

def "A-?"=help;

def "C-X" "b"=list_buffers;

def \0 - \255= nothing;

ctlcombo1.on_change()
{
}
ctlcombo1."c-s-a"() // Define event handler for Ctrl+Shift+A
{
}
ctlcombo1."a"-"z", "A-"Z"( // Define event handler for characters A-Z
                           // upper and lowercase
{
}

Graeme


ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Re: Esc closes form
« Reply #5 on: September 10, 2006, 06:16:01 pm »
Thanks Graeme!

By gum, you are right! When I just plop an editor control on a blank
form and run it, the Esc key is delivered to the editor control when
it has the focus (I'm in Gnu Emacs mode so, for example Esc-> goes
to the end of the buffer). The Tab key is still picked off by somebody
for navigation purposes, but I can leave that battle for another day.

So apparently I did something to affect the behavior of the Esc key
in the editor control, even though I had not defined any Esc handler
at that point (had no interest in the Esc key until I found it terminated
the form).

Your experiment also showed me that another problem I saw must
just be a bug and not my fault. Just put an editor control and a text
control on an empty form, type some text into the editor control,
hit Tab twice (to cycle to the text control and back) all your text
disappears. Seems to be a redraw bug, as dragging some other window
over the form to force a redraw makes the text reappear.

Anyway, I can recreate my form from scratch, step by step and
see if I can figure out exactly at what point Esc started terminating
the form.

Thanks to everybody for their help!