code.c
来自「超强的嵌入式GUI系统」· C语言 代码 · 共 574 行 · 第 1/2 页
C
574 行
/*************************************************************************** begin : Wed Dec 20 2006 copyright : (C) 2006 - 2007 by Alper Akcan email : distchx@yahoo.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of the * * License, or (at your option) any later version. * * * ***************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "list.h"#include "xml.h"#include "code.h"static char *g_name;static FILE *g_source;void code_generate_style (s_xml_node_t *node, s_xml_node_t *parent, char *prefix){ s_xml_node_t *shape = s_xml_node_get_path(node, "shape"); s_xml_node_t *shadow = s_xml_node_get_path(node, "shadow"); s_xml_node_attr_t *id = s_xml_node_get_attr(parent, "id"); s_xml_node_attr_t *type = s_xml_node_get_attr(parent, "type"); fprintf(g_source, "w_%s_set_%sstyle(%s->object, %s, %s);\n", type->value, (prefix) ? prefix : "", id->value, (shape) ? shape->value : "0", (shadow) ? shadow->value : "0"); if (shape) shape->dontparse = 1; if (shadow) shadow->dontparse = 1;}void code_generate_image (s_xml_node_t *node, s_xml_node_t *parent, char *prefix){ int i; int count; char *pid; char *ptype; char *shape; char *shadow; char *rotate; char *cntstr; char *imgvar; s_xml_node_t *tmp; cntstr = (char *) malloc(sizeof(char *) * 255); imgvar = (char *) malloc(sizeof(char *) * 255); sprintf(imgvar, "__imgvar__%u", rand()); shape = s_xml_node_get_path_value(node, "style/shape"); shadow = s_xml_node_get_path_value(node, "style/shadow"); rotate = s_xml_node_get_path_value(node, "rotate"); count = atoi(s_xml_node_get_path_value(node, "count")); pid = s_xml_node_get_attr_value(parent, "id"); ptype = s_xml_node_get_attr_value(parent, "type"); fprintf(g_source, "{\n"); fprintf(g_source, " char *%s[%d] = {\n", imgvar, count); for (i = 0; i < count; i++) { sprintf(cntstr, "image%d", i); fprintf(g_source, " \"%s\",\n", s_xml_node_get_path_value(node, cntstr)); tmp = s_xml_node_get_path(node, cntstr); tmp->dontparse = 1; } fprintf(g_source, " };\n"); fprintf(g_source, " w_%s_set_%simage(%s->object, %s | %s, %s, %d, %s);\n", ptype, (prefix) ? prefix : "", pid, (shape) ? shape : "0", (shadow) ? shadow : "0", (rotate) ? rotate : "0", count, imgvar); fprintf(g_source, "}\n"); if ((tmp = s_xml_node_get_path(node, "style")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "style/shape")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "style/shadow")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "count")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "rotate")) != NULL) { tmp->dontparse = 1; } free(cntstr); free(imgvar);}void code_generate_move (s_xml_node_t *node){ s_xml_node_t *tmp; char *x = s_xml_node_get_path_value(node, "x"); char *y = s_xml_node_get_path_value(node, "y"); char *w = s_xml_node_get_path_value(node, "w"); char *h = s_xml_node_get_path_value(node, "h"); char *pid = s_xml_node_get_attr_value(node->parent, "id"); if (strcmp(node->parent->name, "window") == 0) { fprintf(g_source, "w_window_set_coor(%s, %s, %s, %s, %s);\n", pid, (x) ? x : "0", (y) ? y : "0", (w) ? w : "w", (h) ? h : "0"); } else if (strcmp(node->parent->name, "object") == 0) { fprintf(g_source, "w_object_move(%s->object, %s, %s, %s, %s);\n", pid, (x) ? x : "0", (y) ? y : "0", (w) ? w : "w", (h) ? h : "0"); } node->dontparse = 1; if ((tmp = s_xml_node_get_path(node, "x")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "y")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "w")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "h")) != NULL) { tmp->dontparse = 1; }}void code_generate_window (s_xml_node_t *node){ s_xml_node_t *tmp; char *nid = s_xml_node_get_attr_value(node, "id"); char *ntype = s_xml_node_get_attr_value(node, "type"); fprintf(g_source, "w_window_init(&%s, %s, NULL);\n", nid, ntype); fprintf(g_source, "s_setlocale(%s->window, 0, \"\");\n" "s_bindtextdomain(%s->window, \"%s\", \"/usr/local/share/xynth/messages/\");\n" "s_textdomain(%s->window, \"%s\");\n", nid, nid, g_name, nid, g_name); if ((tmp = s_xml_node_get_path(node, "language")) != NULL) { fprintf(g_source, "s_setlocale(%s->window, 0, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "title")) != NULL) { fprintf(g_source, "s_window_set_title(%s->window, \"%s\");\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "move")) != NULL) { code_generate_move(tmp); tmp->dontparse = 1; }}void code_generate_object_frame (s_xml_node_t *node){ s_xml_node_t *tmp; char *nid = s_xml_node_get_attr_value(node, "id"); char *pid = s_xml_node_get_attr_value(node->parent, "id"); char *wid = s_xml_node_get_attr_value(s_xml_node_get_parent(node, "window"), "id"); fprintf(g_source, "w_frame_init(%s, &%s, %s, %s->object);\n", wid, nid, "0", pid); while ((tmp = s_xml_node_get_path(node, "style")) != NULL) { code_generate_style(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "image")) != NULL) { code_generate_image(tmp, node, NULL); tmp->dontparse = 1; }}void code_generate_object_button (s_xml_node_t *node){ s_xml_node_t *tmp; char *nid = s_xml_node_get_attr_value(node, "id"); char *pid = s_xml_node_get_attr_value(node->parent, "id"); char *wid = s_xml_node_get_attr_value(s_xml_node_get_parent(node, "window"), "id"); fprintf(g_source, "w_button_init(%s, &%s, %s->object);\n", wid, nid, pid); while ((tmp = s_xml_node_get_path(node, "style")) != NULL) { code_generate_style(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "image")) != NULL) { code_generate_image(tmp, node, NULL); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "pressed")) != NULL) { fprintf(g_source, "w_button_set_pressed(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "released")) != NULL) { fprintf(g_source, "w_button_set_released(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "clicked")) != NULL) { fprintf(g_source, "w_button_set_clicked(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; }}void code_generate_object_textbox (s_xml_node_t *node){ s_xml_node_t *tmp; char *nid = s_xml_node_get_attr_value(node, "id"); char *pid = s_xml_node_get_attr_value(node->parent, "id"); char *wid = s_xml_node_get_attr_value(s_xml_node_get_parent(node, "window"), "id"); fprintf(g_source, "w_textbox_init(%s, &%s, %s->object);\n", wid, nid, pid); while ((tmp = s_xml_node_get_path(node, "style")) != NULL) { code_generate_style(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "image")) != NULL) { code_generate_image(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "properties")) != NULL) { fprintf(g_source, "w_textbox_set_properties(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "size")) != NULL) { fprintf(g_source, "w_textbox_set_size(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color")) != NULL) { fprintf(g_source, "w_textbox_set_rgb(%s->object, %s, %s, %s);\n", nid, s_xml_node_get_path_value(tmp, "red"), s_xml_node_get_path_value(tmp, "green"), s_xml_node_get_path_value(tmp, "blue")); if ((tmp = s_xml_node_get_path(node, "color/red")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color/green")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color/blue")) != NULL) { tmp->dontparse = 1; } tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "string")) != NULL) { fprintf(g_source, "w_textbox_set_str(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; }}void code_generate_object_editbox (s_xml_node_t *node){ s_xml_node_t *tmp; char *nid = s_xml_node_get_attr_value(node, "id"); char *pid = s_xml_node_get_attr_value(node->parent, "id"); char *wid = s_xml_node_get_attr_value(s_xml_node_get_parent(node, "window"), "id"); fprintf(g_source, "w_editbox_init(%s, &%s, %s->object);\n", wid, nid, pid); while ((tmp = s_xml_node_get_path(node, "style")) != NULL) { code_generate_style(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "image")) != NULL) { code_generate_image(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "properties")) != NULL) { fprintf(g_source, "w_editbox_set_properties(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "size")) != NULL) { fprintf(g_source, "w_editbox_set_size(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color")) != NULL) { fprintf(g_source, "w_editbox_set_rgb(%s->object, %s, %s, %s);\n", nid, s_xml_node_get_path_value(tmp, "red"), s_xml_node_get_path_value(tmp, "green"), s_xml_node_get_path_value(tmp, "blue")); if ((tmp = s_xml_node_get_path(node, "color/red")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color/green")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color/blue")) != NULL) { tmp->dontparse = 1; } tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "string")) != NULL) { fprintf(g_source, "w_editbox_set_str(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; }}void code_generate_object_checkbox (s_xml_node_t *node){ s_xml_node_t *tmp; char *nid = s_xml_node_get_attr_value(node, "id"); char *pid = s_xml_node_get_attr_value(node->parent, "id"); char *wid = s_xml_node_get_attr_value(s_xml_node_get_parent(node, "window"), "id"); fprintf(g_source, "w_checkbox_init(%s, &%s, %s->object);\n", wid, nid, pid); while ((tmp = s_xml_node_get_path(node, "style")) != NULL) { code_generate_style(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "boxstyle")) != NULL) { code_generate_style(tmp, node, "box"); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "properties")) != NULL) { fprintf(g_source, "w_checkbox_set_properties(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "size")) != NULL) { fprintf(g_source, "w_checkbox_set_size(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color")) != NULL) { fprintf(g_source, "w_checkbox_set_rgb(%s->object, %s, %s, %s);\n", nid, s_xml_node_get_path_value(tmp, "red"), s_xml_node_get_path_value(tmp, "green"), s_xml_node_get_path_value(tmp, "blue")); if ((tmp = s_xml_node_get_path(node, "color/red")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color/green")) != NULL) { tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "color/blue")) != NULL) { tmp->dontparse = 1; } tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "image")) != NULL) { code_generate_image(tmp, node, NULL); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "boximage")) != NULL) { code_generate_image(tmp, node, "box"); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "changed")) != NULL) { fprintf(g_source, "w_checkbox_set_changed(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } if ((tmp = s_xml_node_get_path(node, "string")) != NULL) { fprintf(g_source, "w_checkbox_set_str(%s->object, %s);\n", nid, tmp->value); tmp->dontparse = 1; } while ((tmp = s_xml_node_get_path(node, "state")) != NULL) { fprintf(g_source, "w_checkbox_state(%s->object, %s);\n", nid, tmp->value);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?