From: <enl...@li...> - 2004-01-06 21:13:14
|
Enlightenment CVS committal Author : handyande Project : misc Module : equate Dir : misc/equate/src Modified Files: gui.c Log Message: bound <esc> to c and <enter> and <return> to = cleaned up some source *now equate should be fit for anyone to use* (in basic mode at least...) =================================================================== RCS file: /cvsroot/enlightenment/misc/equate/src/gui.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -3 -r1.26 -r1.27 --- gui.c 6 Jan 2004 15:49:55 -0000 1.26 +++ gui.c 6 Jan 2004 21:13:13 -0000 1.27 @@ -20,16 +20,17 @@ } equate_button; void calc_append(Ewl_Widget * w, void *ev_data, void *user_data); -void calc_clear(Ewl_Widget * w, void *ev_data, void *user_data); +void calc_clear_cb(Ewl_Widget * w, void *ev_data, void *user_data); void calc_op(Ewl_Widget * w, void *ev_data, void *user_data); void calc_exec(void); +void calc_clear(void); static int basic_width = 98; static int basic_height = 138; static int basic_cols = 4; static int basic_rows = 6; static equate_button basic_buttons[] = { - {2, 1, 1, 1, "c", "c", (void *) calc_clear, NULL}, + {2, 1, 1, 1, "c", "c", (void *) calc_clear_cb, NULL}, {2, 2, 1, 1, "/", "/", (void *) calc_append, NULL}, {2, 3, 1, 1, "*", "*", (void *) calc_append, NULL}, {2, 4, 1, 1, "-", "-", (void *) calc_append, NULL}, @@ -46,7 +47,6 @@ {5, 3, 1, 1, "3", "3", (void *) calc_append, NULL}, {5, 4, 2, 1, "=", "=", (void *) calc_exec, NULL}, -/* {6, 1, 1, 1, "c", "c", (void *) calc_clear, NULL},*/ {6, 1, 1, 2, "0", "0", (void *) calc_append, NULL}, {6, 3, 1, 1, ".", ".", (void *) calc_append, NULL}, }; @@ -76,7 +76,7 @@ {6, 2, 1, 1, "2", "2", (void *) calc_append, NULL}, {6, 3, 1, 1, "3", "3", (void *) calc_append, NULL}, {6, 4, 2, 1, "=", "=", (void *) calc_exec, NULL}, - {7, 1, 1, 1, "c", "c", (void *) calc_clear, NULL}, + {7, 1, 1, 1, "c", "c", (void *) calc_clear_cb, NULL}, {7, 2, 1, 1, "0", "0", (void *) calc_append, NULL}, {7, 3, 1, 1, ".", ".", (void *) calc_append, NULL}, }; @@ -119,9 +119,10 @@ calc_exec(void) { char res[BUFLEN]; + int displen; if (calc_mode == SCI) { - int displen = strlen(disp); + displen = strlen(disp); if (displen > 0) { disp[displen] = '='; @@ -136,7 +137,13 @@ } void -calc_clear(Ewl_Widget * w, void *ev_data, void *user_data) +calc_clear_cb(Ewl_Widget * w, void *ev_data, void *user_data) +{ + calc_clear(); +} + +void +calc_clear(void) { equate_clear(); update_display("0"); @@ -163,44 +170,47 @@ if (ev->key_compose && !strcmp(ev->key_compose, "q")) equate_quit(); else - do_key(ev_data, EWL_CALLBACK_MOUSE_DOWN); + if ((!strcmp(ev->keyname, "Enter") || !strcmp(ev->keyname, "KP_Enter") || + !strcmp(ev->keyname, "Return") || !strcmp(ev->keyname, "KP_Return"))) + calc_exec(); + else if (!strcmp(ev->keyname, "Escape")) + calc_clear(); + else + do_key(ev->key_compose, EWL_CALLBACK_MOUSE_DOWN); } void key_un_press(Ewl_Widget * w, void *ev_data, void *user_data) { - do_key(ev_data, EWL_CALLBACK_MOUSE_UP); + Ecore_X_Event_Key_Up *ev; + + ev = ev_data; + do_key(ev->key_compose, EWL_CALLBACK_MOUSE_UP); } int -do_key(void *ev_data, int action) +do_key(char *data, int action) { - Ecore_X_Event_Key_Down *ev; - - ev = ev_data; - - if (ev->key_compose) - E(6, "Key pressed: %s\n", ev->key_compose); - int bc; + equate_button *but; + + if (!data) + return; + E(6, "Key pressed: %s\n", data); if (buttons == sci_buttons) bc = sizeof(sci_buttons); else bc = sizeof(basic_buttons); bc /= sizeof(equate_button); - - equate_button *but = buttons; + but = buttons; while (bc-- > 0) { - if (ev->key_compose) - if (!strcmp(ev->key_compose, but->cmd)) { - E(4, "Pressing button %s\n", but->text); - - ewl_callback_call(but->button, action); - - break; - } + if (!strcmp(data, but->cmd)) { + E(4, "Pressing button %s\n", but->text); + ewl_callback_call(but->button, action); + break; + } but++; } @@ -236,7 +246,7 @@ void draw_ewl(Mode draw_mode) { - int count; + int count, bc; int width, height, cols, rows; if (draw_mode == SCI) { @@ -256,14 +266,12 @@ } count /= sizeof(equate_button); - Ewl_Widget *table; Ewl_Widget *button[count]; Ewl_Widget *cell[count]; Ewl_Widget *displaycell; disp[0] = '\0'; - main_win = ewl_window_new(); ewl_window_set_title(EWL_WINDOW(main_win), "Equate"); ewl_window_set_name(EWL_WINDOW(main_win), "Equate"); @@ -271,43 +279,33 @@ ewl_object_set_minimum_size(EWL_OBJECT(main_win), width, height); ewl_callback_append(main_win, EWL_CALLBACK_DELETE_WINDOW, destroy_main_window, NULL); - ewl_callback_append(main_win, EWL_CALLBACK_KEY_DOWN, key_press, NULL); ewl_callback_append(main_win, EWL_CALLBACK_KEY_UP, key_un_press, NULL); - main_box = ewl_vbox_new(); ewl_container_append_child(EWL_CONTAINER(main_win), main_box); ewl_object_set_padding(EWL_OBJECT(main_box), 3, 3, 3, 3); - - /* main display element - needed for both modes */ ewl_object_set_fill_policy(EWL_OBJECT(main_box), EWL_FLAG_FILL_FILL); ewl_container_append_child(EWL_CONTAINER(main_win), main_box); - table = ewl_grid_new(cols, rows); ewl_container_append_child(EWL_CONTAINER(main_box), table); ewl_widget_show(table); - displaycell = ewl_cell_new(); display = ewl_text_new("0"); ewl_object_set_alignment(EWL_OBJECT(display), EWL_FLAG_ALIGN_RIGHT); - /* layout the display area, the table helps align the display even when in * basic mode */ Ewl_Widget *disp_table; Ewl_Widget *disp_cell[2]; - if (calc_mode == SCI) disp_table = ewl_grid_new(1, 2); else disp_table = ewl_grid_new(1, 1); disp_cell[1] = ewl_cell_new(); eqn_disp = ewl_text_new(""); - if (calc_mode == SCI) { ewl_object_set_alignment(EWL_OBJECT(eqn_disp), EWL_FLAG_ALIGN_LEFT); - ewl_container_append_child(EWL_CONTAINER(disp_cell[1]), eqn_disp); disp_cell[2] = ewl_cell_new(); ewl_container_append_child(EWL_CONTAINER(disp_cell[2]), display); @@ -315,9 +313,7 @@ } else ewl_container_append_child(EWL_CONTAINER(disp_cell[1]), display); ewl_widget_show(display); - ewl_container_append_child(EWL_CONTAINER(displaycell), disp_table); - ewl_widget_show(disp_cell[1]); ewl_grid_add(EWL_GRID(disp_table), disp_cell[1], 1, 1, 1, 1); if (calc_mode == SCI) { @@ -327,24 +323,17 @@ ewl_widget_configure(disp_table); ewl_widget_show(disp_table); /* end display layout */ - - ewl_grid_add(EWL_GRID(table), displaycell, 1, 4, 1, 1); - ewl_widget_show(displaycell); - - int bc = count; + bc = count; equate_button *but = buttons; while (bc-- > 0) { cell[bc] = ewl_cell_new(); button[bc] = ewl_button_new(but->text); but->button = button[bc]; - ewl_callback_append(button[bc], EWL_CALLBACK_MOUSE_DOWN, but->callback, but->cmd); - - ewl_container_append_child(EWL_CONTAINER(cell[bc]), button[bc]); ewl_box_set_homogeneous(EWL_BOX(button[bc]), TRUE); ewl_object_set_alignment(EWL_OBJECT @@ -355,17 +344,13 @@ but->row + but->width - 1); ewl_widget_show(button[bc]); ewl_widget_show(cell[bc]); - but++; } ewl_widget_configure(table); - ewl_widget_show(main_box); ewl_widget_show(main_win); - ewl_main(); - return; } |