si_t save_as_button_callback(void* btn, void* msg) { union message* m = (union message*)msg; struct button* b = NULL; switch(m->base.type) { case MESSAGE_TYPE_MOUSE_SINGLE_CLICK: if(NULL == save_window) { save_window = window_init("save window"); /* 申请失败 */ if(NULL == main_window) { EGUI_PRINT_ERROR("failed to init save window"); application_exit(); return -1; } window_set_bounds(save_window, main_window->area.x + 30, main_window->area.y + 30, 300, 60); window_set_color(save_window, NULL, &barely_blue); save_text_line = text_line_init(FILE_MAX, 0); if(NULL == save_text_line) { EGUI_PRINT_ERROR("failed to init save_text_line on save window"); application_exit(); return -1; } text_line_set_bounds(save_text_line, 5, 5, 230, 50); text_line_set_placeholder(save_text_line, "input file name"); text_line_set_color(save_text_line, &dark_blue, NULL, &light_green); b = button_init("ok"); if(NULL == b) { EGUI_PRINT_ERROR("failed to init ok button on save window"); application_exit(); return -1; } button_set_bounds(b, 240, 10, 50, 40); button_set_color(b, &dark_blue, &light_green); button_set_font(b, FONT_MATRIX_12); b->callback = save_window_ok_button_callback; object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(b)); object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(save_text_line)); application_add_window(NULL, save_window); break; } else { EGUI_PRINT_ERROR("save window already open!"); } default: button_default_callback(btn, msg); } return 0; }
si_t pop_window() { switch(save_or_rename_flag) { case 0: save_window = window_init("save_directory_window"); break; case 1: save_window = window_init("save_file_window"); break; case 2: save_window = window_init("rename_window"); break; default: break; } if(NULL == save_window) { //EGUI_PRINT_ERROR("failed to init save window"); application_exit(); return -1; } window_set_bounds(save_window,200, 200, 300, 60); window_set_color(save_window, NULL, &ground_purple); save_text_line = text_line_init(100, 0); if(NULL == save_text_line) { //EGUI_PRINT_ERROR("failed to init save_text_line on save window"); application_exit(); return -1; } text_line_set_bounds(save_text_line, 5, 5, 230, 50); text_line_set_placeholder(save_text_line, "input file name"); text_line_set_color(save_text_line, &heavy_blue, NULL, &heavy_blue ); save_button = button_init("OK"); if(NULL == save_button) { //EGUI_PRINT_ERROR("failed to init ok button on save window"); application_exit(); return -1; } button_set_bounds(save_button, 240, 10, 50, 40); button_set_color(save_button, &ground_purple, &heavy_blue ); button_set_font(save_button, FONT_MATRIX_12); save_button->callback = rename_window_ok_button_callback; object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(save_button)); object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(save_text_line)); application_add_window(Desktop_w, save_window); return 0; }
si_t right_click_menu_init() { si_t i = 0; for(i=0;i<MENU_NUM;i++) menu_button[i]=NULL; //第一个邮件按钮(新建文件夹) menu_button[0] = button_init("NEW FOLDER"); /* 申请失败 */ if(menu_button[0] == NULL) { application_exit(); return -1; } menu_button[0]->callback = right_click_menu_NEW_FOLDER; //第二个邮件按钮(新建文件) menu_button[1] = button_init("NEW FILE"); /* 申请失败 */ if(menu_button[1] == NULL) { application_exit(); return -1; } menu_button[1]->callback = right_click_menu_NEW_FILE; //第三个邮件按钮(打开) menu_button[2] = button_init("open"); /* 申请失败 */ if(menu_button[2] == NULL) { application_exit(); return -1; } menu_button[2]->callback = right_click_menu_open; //第四个邮件按钮(重命名) menu_button[3] = button_init("rename"); /* 申请失败 */ if(menu_button[3] == NULL) { application_exit(); return -1; } menu_button[3]->callback = right_click_menu_rename; //第五个邮件按钮(删除) menu_button[4] = button_init("delete"); /* 申请失败 */ if(menu_button[4] == NULL) { application_exit(); return -1; } menu_button[4]->callback = right_click_menu_delete; //第六个邮件按钮(刷新) menu_button[5] = button_init("FLUSH"); /* 申请失败 */ if(menu_button[5] == NULL) { application_exit(); return -1; } menu_button[5]->callback = right_click_menu_FLUSH; //第七个邮件按钮(复制) menu_button[6] = button_init("coyp"); /* 申请失败 */ if(menu_button[6] == NULL) { application_exit(); return -1; } menu_button[6]->callback = right_click_menu_copy; //第八个邮件按钮(粘贴) menu_button[7] = button_init("paste"); /* 申请失败 */ if(menu_button[7] == NULL) { application_exit(); return -1; } menu_button[7]->callback = right_click_menu_paste; /* 添加button */ for(i=0;i<MENU_NUM;i++){ button_set_color(menu_button[i], &font_white, &ground_purple); button_set_bounds(menu_button[i], 0, -30, 0, 0); object_attach_child(OBJECT_POINTER(Desktop_im), OBJECT_POINTER(menu_button[i])); } /* 右键菜单不显示 */ menu_show = 0; }
int main(int argc, char* argv[]) { struct scroll_bar* s; struct button* b1 = NULL, *b2 = NULL; char msg[LABEL_MAX]; char file_msg[LABEL_MAX]; si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER; si_t app_type = APPLICATION_TYPE_NORMAL; char* file_name = NULL; si_t fonty = 0; /** * open with file **/ if(argc == 2) { struct stat st; if(stat(argv[1], &st) == -1) { EGUI_PRINT_ERROR("file %s does not exists", argv[1]); return -1; } if(!S_ISREG(st.st_mode) || access(argv[1], R_OK | W_OK) != 0) { EGUI_PRINT_ERROR("file %s cannot access!", argv[1]); return -1; } /** * file too large **/ if(st.st_size > FILE_MAX) { EGUI_PRINT_ERROR("file %s does not exists\n", argv[1]); return -1; } file_name = argv[1]; } else if(argc != 1) { EGUI_PRINT_ERROR("wrong parameter!\nusage: \nediterbasic\nor:\nediterbasic [filename]"); return -1; } /* 初始化用户应用程序 */ application_init(video_access_mode, app_type, "editerbasic"); /** * window **/ main_window = window_init("editer_basic"); /* 申请失败 */ if(main_window == NULL) { application_exit(); return -1; } window_set_bounds(main_window, 300, 100, 550, 300); window_set_color(main_window, NULL, &light_green); /** * label that show process **/ if(file_name) { sprintf(file_msg, "%s", file_name); } else { sprintf(file_msg, "new file"); } file_label = label_init(file_msg); if(file_label == NULL) { application_exit(); return -1; } label_set_bounds(file_label, 10, 10, 365, 20); label_set_color(file_label, &barely_blue, &light_blue); label_set_font(file_label, FONT_MATRIX_12); /** * save button **/ b1 = button_init("save"); if(b1 == NULL) { application_exit(); return -1; } button_set_bounds(b1, 380, 5, 60, 30); button_set_color(b1, &dark_blue, &barely_blue); button_set_font(b1, FONT_MATRIX_12); b1->callback = save_button_callback; b2 = button_init("save as"); if(b2 == NULL) { application_exit(); return -1; } button_set_bounds(b2, 445, 5, 100, 30); button_set_color(b2, &dark_blue, &barely_blue); button_set_font(b2, FONT_MATRIX_12); b2->callback = save_as_button_callback; /** * text_line that shows file context **/ file_context_text_line = text_line_init(FILE_MAX, 0); if(file_context_text_line == NULL) { application_exit(); return -1; } text_line_set_bounds(file_context_text_line, 5, 40, 520, 230); text_line_set_color(file_context_text_line, &dark_blue, NULL, NULL); text_line_set_multilines(file_context_text_line); fonty = get_font_height(file_context_text_line->gd); if(file_name) { if(load_file(file_name, text_line_get_buf(file_context_text_line)) < 0) { EGUI_PRINT_ERROR("failed to load file %s", file_name); application_exit(); return -1; } s = scroll_bar_init(1, fonty * text_line_get_max_line_shown(file_context_text_line), fonty); } else { s = scroll_bar_init(1, file_context_text_line->area.height, fonty); } if(s == NULL) { application_exit(); return -1; } scroll_bar_set_bounds(s, 525, 40, 20, 230); text_line_register_move_handler(file_context_text_line, WIDGET_POINTER(s), TEXT_LINE_EVENT_ALL, scrollbar_subscribe_text_line); scroll_bar_register_move_handler(s, WIDGET_POINTER(file_context_text_line), SCROLL_BAR_EVENT_ALL, text_line_subscribe_scrollbar); log_label = label_init(msg); if(log_label == NULL) { application_exit(); return -1; } label_set_bounds(log_label, 5, 275, 450, 20); label_set_color(log_label, NULL, &light_green); sprintf(msg, "open file successfully!"); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(file_label)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(file_context_text_line)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(log_label)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(b1)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(b2)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(s)); /* 添加顶层窗口 */ application_add_window(NULL, main_window); /* 设置主窗口 */ application_set_main_window(main_window); /* 运行 */ application_exec(); return 0; }