Commit 327d269c4fdbb6126a4b0b645ec43bdee91c93f4
1 parent
932d75df
Exists in
master
and in
5 other branches
Iniciando reimplementacao dos "keypads"
Showing
6 changed files
with
238 additions
and
17 deletions
Show diff stats
pw3270.nsi.in
| ... | ... | @@ -155,6 +155,7 @@ Section /o "Software Development Kit" SecSDK |
| 155 | 155 | file "/oname=$INSTDIR\sdk\include\lib3270.h" "src\include\lib3270.h" |
| 156 | 156 | file "/oname=$INSTDIR\sdk\include\pw3270.h" "src\include\pw3270.h" |
| 157 | 157 | file "/oname=$INSTDIR\sdk\include\pw3270\v3270.h" "src\include\pw3270\v3270.h" |
| 158 | + file "/oname=$INSTDIR\sdk\include\pw3270\hllapi.h" "src\include\pw3270\hllapi.h" | |
| 158 | 159 | |
| 159 | 160 | file "/oname=$INSTDIR\sdk\include\lib3270\config.h" "src\include\lib3270\config.h" |
| 160 | 161 | file "/oname=$INSTDIR\sdk\include\lib3270\rules.mak" "src\include\rules.mak" | ... | ... |
src/pw3270/uiparser/keypad.c
| ... | ... | @@ -30,16 +30,96 @@ |
| 30 | 30 | #include <gtk/gtk.h> |
| 31 | 31 | #include "private.h" |
| 32 | 32 | |
| 33 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 34 | + | |
| 35 | + struct row | |
| 36 | + { | |
| 37 | + unsigned short pos; | |
| 38 | + unsigned short num_cols; | |
| 39 | + GList * cols; | |
| 40 | + }; | |
| 41 | + | |
| 42 | + struct keypad | |
| 43 | + { | |
| 44 | + struct parser * parser; | |
| 45 | + unsigned short num_rows; | |
| 46 | + unsigned short num_cols; | |
| 47 | + unsigned short col; | |
| 48 | + struct row * row; | |
| 49 | + GtkWidget * box; | |
| 50 | + GtkWidget * handle; | |
| 51 | + GtkWidget * table; | |
| 52 | + UI_ATTR_DIRECTION pos; | |
| 53 | + GList * rows; | |
| 54 | + }; | |
| 55 | + | |
| 33 | 56 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 34 | 57 | |
| 35 | - static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, struct parser *info, GError **error) | |
| 58 | + static void row_start(struct keypad *keypad, const gchar **names,const gchar **values, GError **error) | |
| 59 | + { | |
| 60 | + keypad->row = g_malloc0(sizeof(struct row)); | |
| 61 | + | |
| 62 | + keypad->row->pos = ++keypad->num_rows; | |
| 63 | + keypad->col = 0; | |
| 64 | + | |
| 65 | + keypad->rows = g_list_append(keypad->rows,keypad->row); | |
| 66 | + } | |
| 67 | + | |
| 68 | + static void button_start(struct keypad *keypad, const gchar **names,const gchar **values, GError **error) | |
| 69 | + { | |
| 70 | + const gchar *label = ui_get_attribute("label", names, values); | |
| 71 | + const gchar *icon = ui_get_attribute("icon", names, values); | |
| 72 | + GtkWidget *widget = NULL; | |
| 73 | + | |
| 74 | + if(++keypad->col > keypad->num_cols) | |
| 75 | + keypad->num_cols = keypad->col; | |
| 76 | + | |
| 77 | + keypad->row->num_cols++; | |
| 78 | + | |
| 79 | + if(label) | |
| 80 | + { | |
| 81 | + widget = gtk_button_new_with_label(gettext(g_strcompress(label))); | |
| 82 | + } | |
| 83 | + else if(icon) | |
| 84 | + { | |
| 85 | + gchar *text = g_strconcat("gtk-",icon,NULL); | |
| 86 | + widget = gtk_button_new(); | |
| 87 | + gtk_container_add(GTK_CONTAINER(widget),gtk_image_new_from_stock(text,GTK_ICON_SIZE_SMALL_TOOLBAR)); | |
| 88 | + g_free(text); | |
| 89 | + } | |
| 90 | + | |
| 91 | + keypad->row->cols = g_list_append(keypad->row->cols,widget); | |
| 92 | + } | |
| 93 | + | |
| 94 | + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, struct keypad *keypad, GError **error) | |
| 36 | 95 | { |
| 37 | - trace("%s: %s",__FUNCTION__,element_name); | |
| 96 | + static const struct _cmd | |
| 97 | + { | |
| 98 | + const gchar *element_name; | |
| 99 | + void (*start)(struct keypad *, const gchar **, const gchar **, GError **); | |
| 100 | + } cmd[] = | |
| 101 | + { | |
| 102 | + { "row", row_start }, | |
| 103 | + { "button", button_start }, | |
| 104 | + }; | |
| 105 | + | |
| 106 | + int f; | |
| 107 | + | |
| 108 | + for(f = 0; f < G_N_ELEMENTS(cmd); f++) | |
| 109 | + { | |
| 110 | + if(!g_strcasecmp(cmd[f].element_name,element_name)) | |
| 111 | + { | |
| 112 | + cmd[f].start(keypad,names,values,error); | |
| 113 | + return; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + *error = g_error_new(ERROR_DOMAIN,EINVAL, _( "Unexpected element <%s>"), element_name); | |
| 38 | 118 | } |
| 39 | 119 | |
| 40 | - static void element_end(GMarkupParseContext *context, const gchar *element_name, struct parser *info, GError **error) | |
| 120 | + static void element_end(GMarkupParseContext *context, const gchar *element_name, struct keypad *keypad, GError **error) | |
| 41 | 121 | { |
| 42 | - trace("%s: %s",__FUNCTION__,element_name); | |
| 122 | +// trace("%s: %s",__FUNCTION__,element_name); | |
| 43 | 123 | } |
| 44 | 124 | |
| 45 | 125 | GObject * ui_create_keypad(GMarkupParseContext *context,GtkAction *action,struct parser *info,const gchar **names, const gchar **values, GError **error) |
| ... | ... | @@ -58,6 +138,11 @@ |
| 58 | 138 | |
| 59 | 139 | }; |
| 60 | 140 | |
| 141 | + const gchar *label = ui_get_attribute("label", names, values); | |
| 142 | + const gchar *name = ui_get_attribute("name", names, values); | |
| 143 | + | |
| 144 | + struct keypad *keypad; | |
| 145 | + | |
| 61 | 146 | if(info->element) |
| 62 | 147 | { |
| 63 | 148 | *error = g_error_new(ERROR_DOMAIN,EINVAL, _( "<%s> should be on toplevel"), "keypad"); |
| ... | ... | @@ -70,13 +155,107 @@ |
| 70 | 155 | return NULL; |
| 71 | 156 | } |
| 72 | 157 | |
| 73 | - g_markup_parse_context_push(context,(GMarkupParser *) &parser,info); | |
| 158 | + info->block_data = keypad = g_malloc0(sizeof(struct keypad)); | |
| 159 | + | |
| 160 | + keypad->parser = info; | |
| 161 | + keypad->handle = gtk_handle_box_new(); | |
| 162 | + keypad->pos = ui_get_dir_attribute(names,values); | |
| 74 | 163 | |
| 75 | - return NULL; | |
| 164 | + switch(keypad->pos) | |
| 165 | + { | |
| 166 | + case UI_ATTR_UP: | |
| 167 | + keypad->box = gtk_vbox_new(FALSE,0); | |
| 168 | + gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(keypad->handle),GTK_POS_BOTTOM); | |
| 169 | + break; | |
| 170 | + | |
| 171 | + case UI_ATTR_DOWN: | |
| 172 | + keypad->box = gtk_vbox_new(FALSE,0); | |
| 173 | + gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(keypad->handle),GTK_POS_TOP); | |
| 174 | + break; | |
| 175 | + | |
| 176 | + case UI_ATTR_LEFT: | |
| 177 | + keypad->box = gtk_hbox_new(FALSE,0); | |
| 178 | + gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(keypad->handle),GTK_POS_RIGHT); | |
| 179 | + break; | |
| 180 | + | |
| 181 | + default: | |
| 182 | + keypad->pos = UI_ATTR_RIGHT; | |
| 183 | + keypad->box = gtk_hbox_new(FALSE,0); | |
| 184 | + gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(keypad->handle),GTK_POS_LEFT); | |
| 185 | + | |
| 186 | + } | |
| 187 | + | |
| 188 | + if(name) | |
| 189 | + gtk_widget_set_name(keypad->handle,name); | |
| 190 | + | |
| 191 | + if(label) | |
| 192 | + g_object_set_data_full(G_OBJECT(keypad->handle),"keypad_label",g_strdup(label),g_free); | |
| 193 | + | |
| 194 | + gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(keypad->handle),GTK_SHADOW_ETCHED_IN); | |
| 195 | + gtk_container_add(GTK_CONTAINER(keypad->handle),keypad->box); | |
| 196 | + | |
| 197 | + g_markup_parse_context_push(context,(GMarkupParser *) &parser,keypad); | |
| 198 | + | |
| 199 | + return G_OBJECT(ui_insert_element(info, action, UI_ELEMENT_KEYPAD, names, values, G_OBJECT(keypad->handle), error)); | |
| 200 | + } | |
| 201 | + | |
| 202 | + static void create_col(GtkWidget *widget, struct keypad *keypad) | |
| 203 | + { | |
| 204 | + if(widget) | |
| 205 | + { | |
| 206 | + gtk_widget_show_all(widget); | |
| 207 | + gtk_table_attach( GTK_TABLE(keypad->table), | |
| 208 | + widget, | |
| 209 | + keypad->num_cols,keypad->num_cols+1, | |
| 210 | + keypad->num_rows,keypad->num_rows+1, | |
| 211 | + GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 ); | |
| 212 | + | |
| 213 | + } | |
| 214 | + keypad->num_cols++; | |
| 215 | + | |
| 216 | + } | |
| 217 | + | |
| 218 | + static void create_row(struct row *info, struct keypad *keypad) | |
| 219 | + { | |
| 220 | + if(info->cols) | |
| 221 | + { | |
| 222 | + keypad->num_cols = 0; | |
| 223 | + g_list_foreach(info->cols,(GFunc) create_col,keypad); | |
| 224 | + g_list_free(info->cols); | |
| 225 | + } | |
| 226 | + keypad->num_rows++; | |
| 76 | 227 | } |
| 77 | 228 | |
| 78 | 229 | void ui_end_keypad(GMarkupParseContext *context,GObject *widget,struct parser *info,GError **error) |
| 79 | 230 | { |
| 231 | + struct keypad *keypad = (struct keypad *) info->block_data; | |
| 232 | + info->block_data = NULL; | |
| 233 | + | |
| 234 | + keypad->num_cols *= 2; | |
| 235 | + | |
| 236 | + if(keypad->rows) | |
| 237 | + { | |
| 238 | + // Create Widgets & Release memory | |
| 239 | + keypad->table = gtk_table_new(keypad->num_rows,keypad->num_cols,FALSE); | |
| 240 | + | |
| 241 | +#if GTK_CHECK_VERSION(2,18,0) | |
| 242 | + gtk_widget_set_can_focus(keypad->table,FALSE); | |
| 243 | + gtk_widget_set_can_default(keypad->table,FALSE); | |
| 244 | +#else | |
| 245 | + GTK_WIDGET_UNSET_FLAGS(keypad->table,GTK_CAN_FOCUS); | |
| 246 | + GTK_WIDGET_UNSET_FLAGS(keypad->table,GTK_CAN_DEFAULT); | |
| 247 | +#endif // GTK(2,18) | |
| 248 | + | |
| 249 | + keypad->num_cols = keypad->num_rows = 0; | |
| 250 | + g_list_foreach(keypad->rows,(GFunc) create_row,keypad); | |
| 251 | + g_list_free_full(keypad->rows,g_free); | |
| 252 | + gtk_box_pack_start(GTK_BOX(keypad->box),keypad->table,FALSE,FALSE,0); | |
| 253 | + | |
| 254 | + gtk_widget_show_all(keypad->box); | |
| 255 | + gtk_widget_show_all(keypad->table); | |
| 256 | + gtk_widget_show_all(keypad->handle); | |
| 257 | + } | |
| 80 | 258 | |
| 259 | + g_free(keypad); | |
| 81 | 260 | g_markup_parse_context_pop(context); |
| 82 | 261 | } | ... | ... |
src/pw3270/uiparser/parser.c
| ... | ... | @@ -73,6 +73,22 @@ static void pack_start(gpointer key, GtkWidget *widget, struct parser *p) |
| 73 | 73 | gtk_box_pack_start(GTK_BOX(p->element),widget,FALSE,FALSE,0); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | +struct keypad | |
| 77 | +{ | |
| 78 | + GtkWidget * box; | |
| 79 | + GtkPositionType filter; | |
| 80 | + void (*pack)(GtkBox *,GtkWidget *, gboolean,gboolean,guint); | |
| 81 | +}; | |
| 82 | + | |
| 83 | +static void pack_keypad(gpointer key, GtkWidget *widget, struct keypad *k) | |
| 84 | +{ | |
| 85 | + if(gtk_handle_box_get_handle_position(GTK_HANDLE_BOX(widget)) != k->filter) | |
| 86 | + return; | |
| 87 | + | |
| 88 | + gtk_widget_show_all(widget); | |
| 89 | + k->pack(GTK_BOX(k->box),widget,FALSE,FALSE,0); | |
| 90 | +} | |
| 91 | + | |
| 76 | 92 | static void pack_view(gpointer key, GtkWidget *widget, GtkWidget *parent) |
| 77 | 93 | { |
| 78 | 94 | GObject *obj = g_object_get_data(G_OBJECT(widget),"view_action"); |
| ... | ... | @@ -116,7 +132,6 @@ struct action_info |
| 116 | 132 | GtkWidget * widget; |
| 117 | 133 | }; |
| 118 | 134 | |
| 119 | - | |
| 120 | 135 | static void action_group_setup(gpointer key, GtkAction *action, struct action_info *info) |
| 121 | 136 | { |
| 122 | 137 | int group_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action),"id_group")); |
| ... | ... | @@ -175,11 +190,14 @@ void parser_build(struct parser *p, GtkWidget *widget) |
| 175 | 190 | |
| 176 | 191 | #if GTK_CHECK_VERSION(3,0,0) |
| 177 | 192 | GtkWidget * vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); |
| 193 | + GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); | |
| 178 | 194 | #else |
| 179 | 195 | GtkWidget * vbox = gtk_vbox_new(FALSE,0); |
| 196 | + GtkWidget * hbox = gtk_hbox_new(FALSE,0); | |
| 180 | 197 | #endif // GTK(3,0,0) |
| 181 | 198 | |
| 182 | 199 | GtkWidget * parent; |
| 200 | + struct keypad keypad; | |
| 183 | 201 | int f; |
| 184 | 202 | |
| 185 | 203 | a_info.widget = widget; |
| ... | ... | @@ -211,20 +229,42 @@ void parser_build(struct parser *p, GtkWidget *widget) |
| 211 | 229 | // Pack top toolbars |
| 212 | 230 | g_hash_table_foreach(p->element_list[UI_ELEMENT_TOOLBAR],(GHFunc) pack_start, p); |
| 213 | 231 | |
| 232 | + // Pack top keypads | |
| 233 | + memset(&keypad,0,sizeof(keypad)); | |
| 234 | + keypad.box = vbox; | |
| 235 | + keypad.filter = GTK_POS_BOTTOM; | |
| 236 | + keypad.pack = gtk_box_pack_start; | |
| 237 | + g_hash_table_foreach(p->element_list[UI_ELEMENT_KEYPAD],(GHFunc) pack_keypad, &keypad); | |
| 238 | + | |
| 239 | + | |
| 240 | + // Pack left keypads | |
| 241 | + keypad.box = hbox; | |
| 242 | + keypad.filter = GTK_POS_RIGHT; | |
| 243 | + g_hash_table_foreach(p->element_list[UI_ELEMENT_KEYPAD],(GHFunc) pack_keypad, &keypad); | |
| 244 | + | |
| 214 | 245 | // Pack & configure center widget |
| 215 | 246 | if(widget) |
| 216 | 247 | { |
| 217 | 248 | ui_set_scroll_actions(widget,p->scroll_action); |
| 218 | - gtk_box_pack_start(GTK_BOX(vbox),widget,TRUE,TRUE,0); | |
| 249 | + gtk_box_pack_start(GTK_BOX(hbox),widget,TRUE,TRUE,0); | |
| 219 | 250 | gtk_widget_show(widget); |
| 220 | 251 | } |
| 221 | 252 | |
| 253 | + // Pack right keypads | |
| 254 | + keypad.filter = GTK_POS_LEFT; | |
| 255 | + keypad.pack = gtk_box_pack_end; | |
| 256 | + g_hash_table_foreach(p->element_list[UI_ELEMENT_KEYPAD],(GHFunc) pack_keypad, &keypad); | |
| 222 | 257 | |
| 223 | -// gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0); | |
| 258 | + // Pack bottom keypads | |
| 259 | + keypad.box = vbox; | |
| 260 | + keypad.filter = GTK_POS_TOP; | |
| 261 | + g_hash_table_foreach(p->element_list[UI_ELEMENT_KEYPAD],(GHFunc) pack_keypad, &keypad); | |
| 224 | 262 | |
| 263 | + // Finish building | |
| 264 | + gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0); | |
| 225 | 265 | gtk_container_add(GTK_CONTAINER(p->toplevel),vbox); |
| 226 | 266 | |
| 227 | -// gtk_widget_show(hbox); | |
| 267 | + gtk_widget_show(hbox); | |
| 228 | 268 | gtk_widget_show(vbox); |
| 229 | 269 | |
| 230 | 270 | gtk_window_add_accel_group(GTK_WINDOW(p->toplevel),a_info.accel_group); | ... | ... |
src/pw3270/uiparser/private.h
ui/00default.xml
| ... | ... | @@ -188,7 +188,7 @@ |
| 188 | 188 | <separator /> |
| 189 | 189 | <menuitem action='previousfield' label='Previous field' /> |
| 190 | 190 | <menuitem action='nextfield' label='Next field'/> |
| 191 | - <menuitem name="return" action='activate' label='Return' key='Return' /> | |
| 191 | + <menuitem name="return" action='activate' label='Return' /> | |
| 192 | 192 | |
| 193 | 193 | <separator /> |
| 194 | 194 | <menuitem action='Quit'/> |
| ... | ... | @@ -206,7 +206,7 @@ |
| 206 | 206 | |
| 207 | 207 | <accelerator action='firstfield' key='Home' group='online' /> |
| 208 | 208 | <accelerator action='kybdreset' key='<Shift><Ctrl>r' group='online' /> |
| 209 | - <accelerator name="return" action='activate' key='return' /> | |
| 209 | + <!-- accelerator name="return" action='activate' key='Enter' ---> | |
| 210 | 210 | <accelerator name="KP_enter" action='activate' key='KP_Enter' /> |
| 211 | 211 | <accelerator action='Break' key='Escape' group='online' /> |
| 212 | 212 | <accelerator action='Attn' key='<shift>Escape' group='online' /> | ... | ... |
ui/10keypad.xml
| ... | ... | @@ -54,17 +54,17 @@ |
| 54 | 54 | </row> |
| 55 | 55 | <row> |
| 56 | 56 | <button /> |
| 57 | - <button action="CursorUp" icon="go-up" /> | |
| 57 | + <button action='move' target='cursor' direction='up' icon="go-up" /> | |
| 58 | 58 | <button /> |
| 59 | 59 | </row> |
| 60 | 60 | <row> |
| 61 | - <button action="CursorLeft" icon="go-back" /> | |
| 62 | - <button action="Home" icon="goto-top" /> | |
| 63 | - <button action="CursorRight" icon="go-forward" /> | |
| 61 | + <button action='move' target='cursor' direction='left' icon="go-back" /> | |
| 62 | + <button action="firstfield" icon="goto-top" /> | |
| 63 | + <button action='move' target='cursor' direction='right' icon="go-forward" /> | |
| 64 | 64 | </row> |
| 65 | 65 | <row> |
| 66 | 66 | <button /> |
| 67 | - <button action="CursorDown" icon="go-down"/> | |
| 67 | + <button action='move' target='cursor' direction='down' icon="go-down"/> | |
| 68 | 68 | <button /> |
| 69 | 69 | </row> |
| 70 | 70 | <row> | ... | ... |