Skip to content

Commit

Permalink
To recognize the :enter key pressed in the edit_line area, improved t…
Browse files Browse the repository at this point in the history
…he code of windows.c with the subclassing technique. Now when you press the :enter key in the edit_line area, Shoes.hook method will be launched. You can overwite the method as you like in your Shoes app.

A sample snippet is here:

def Shoes.hook
  $app.instance_eval{alert @msg.text}
end

$app = Shoes.app :width => 400, :height => 150 do
  edit_line{|el| @msg.text = el.text}
  @msg = para
end

Reference to http://www.arcpit.co.jp/winapi/api_02/ap020108.htm
(in Japanese)
  • Loading branch information
ashbb committed Dec 12, 2009
1 parent 2032db6 commit d01565f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions shoes/native/windows.c
Expand Up @@ -18,9 +18,12 @@
#define IDC_HAND MAKEINTRESOURCE(32649)
#endif

static WNDPROC shoes_original_edit_line_proc = NULL;

shoes_code shoes_classex_init();
LRESULT CALLBACK shoes_app_win32proc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK shoes_slot_win32proc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK shoes_edit_line_win32proc(HWND, UINT, WPARAM, LPARAM);

static WCHAR *
shoes_wchar(char *utf8)
Expand Down Expand Up @@ -1398,13 +1401,23 @@ shoes_native_edit_line(VALUE self, shoes_canvas *canvas, shoes_place *place, VAL
canvas->slot->window, (HMENU)cid,
(HINSTANCE)GetWindowLong(canvas->slot->window, GWL_HINSTANCE),
NULL);

shoes_original_edit_line_proc = (WNDPROC)GetWindowLong(ref, GWL_WNDPROC);
SetWindowLong(ref, GWL_WNDPROC, (LONG)shoes_edit_line_win32proc);

SetWindowPos(ref, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW);
shoes_win32_control_font(cid, canvas->slot->window);
shoes_native_edit_line_set_text(ref, msg);
rb_ary_push(canvas->slot->controls, self);
return ref;
}

LRESULT CALLBACK shoes_edit_line_win32proc(HWND win, UINT msg, WPARAM w, LPARAM l)
{
if (msg == WM_KEYDOWN && w == VK_RETURN) rb_eval_string("Shoes.hook");
return CallWindowProc(shoes_original_edit_line_proc, win, msg, w, l);
}

VALUE
shoes_native_edit_line_get_text(SHOES_CONTROL_REF ref)
{
Expand Down

0 comments on commit d01565f

Please sign in to comment.