📄 ctk.c
字号:
}*/ }}/*-----------------------------------------------------------------------------------*//** * Gets the width of the desktop. * * \param d The desktop. * \return The width of the desktop, in characters. * * \note The d parameter is currently unused and must be set to NULL. *//*-----------------------------------------------------------------------------------*/unsigned charctk_desktop_width(struct ctk_desktop *d){ return ctk_draw_width();}/*-----------------------------------------------------------------------------------*//** * Gets the height of the desktop. * * \param d The desktop. * \return The height of the desktop, in characters. * * \note The d parameter is currently unused and must be set to NULL. *//*-----------------------------------------------------------------------------------*/unsigned charctk_desktop_height(struct ctk_desktop *d){ return ctk_draw_height();}/*-----------------------------------------------------------------------------------*//** * \internal Selects a widget in the window of the widget. * * \param focus The widget to be focused. *//*-----------------------------------------------------------------------------------*/static void CC_FASTCALL select_widget(struct ctk_widget *focus){ struct ctk_window *window; window = focus->window; if(focus != window->focused) { window->focused = focus; /* The operation changed the focus, so we emit a "hover" signal for those widgets that support it. */ if(window->focused->type == CTK_WIDGET_HYPERLINK) { dispatcher_emit(ctk_signal_hyperlink_hover, window->focused, window->owner); } else if(window->focused->type == CTK_WIDGET_BUTTON) { dispatcher_emit(ctk_signal_button_hover, window->focused, window->owner); } add_redrawwidget(window->focused); dispatcher_emit(ctk_signal_widget_select, focus, focus->window->owner); }}/*-----------------------------------------------------------------------------------*/#define UP 0#define DOWN 1#define LEFT 2#define RIGHT 3static void CC_FASTCALL switch_focus_widget(unsigned char direction){ register struct ctk_window *window; register struct ctk_widget *focus; struct ctk_widget *widget; if(dialog != NULL) { window = dialog; } else { window = windows; } /* If there are no windows open, we move focus around between the icons on the root window instead. */ if(window == NULL) { window = &desktop_window; } focus = window->focused; if(focus == NULL) { focus = window->active; } add_redrawwidget(focus); if((direction & 1) == 0) { /* Move focus "up" */ focus = focus->next; } else { /* Move focus "down" */ for(widget = window->active; widget != NULL; widget = widget->next) { if(widget->next == focus) { break; } } focus = widget; if(focus == NULL) { if(window->active != NULL) { for(focus = window->active; focus->next != NULL; focus = focus->next); } } } if(focus == NULL) { focus = window->active; } select_widget(focus);}/*-----------------------------------------------------------------------------------*/#if CTK_CONF_MENUSstatic void switch_open_menu(unsigned char rightleft){ struct ctk_menu *menu; if(rightleft == 0) { /* Move right */ for(menu = menus.menus; menu != NULL; menu = menu->next) { if(menu->next == menus.open) { break; } } lastmenu = menus.open; menus.open = menu; if(menus.open == NULL) { for(menu = menus.menus; menu->next != NULL; menu = menu->next); menus.open = menu; } } else { /* Move to left */ lastmenu = menus.open; menus.open = menus.open->next; if(menus.open == NULL) { menus.open = menus.menus; } } menus.open->active = 0; /* if(menus.open->nitems > maxnitems) { maxnitems = menus.open->nitems; }*/ /* ctk_desktop_redraw();*/}/*-----------------------------------------------------------------------------------*/static void switch_menu_item(unsigned char updown){ register struct ctk_menu *m; m = menus.open; if(updown == 0) { /* Move up */ if(m->active == 0) { m->active = m->nitems - 1; } else { --m->active; if(m->items[m->active].title[0] == '-') { --m->active; } } } else { /* Move down */ if(m->active >= m->nitems - 1) { m->active = 0; } else { ++m->active; if(m->items[m->active].title[0] == '-') { ++m->active; } } } }#endif /* CTK_CONF_MENUS *//*-----------------------------------------------------------------------------------*/static unsigned char CC_FASTCALL activate(CC_REGISTER_ARG struct ctk_widget *w){ static unsigned char len; if(w->type == CTK_WIDGET_BUTTON) { if(w == (struct ctk_widget *)&windows->closebutton) {#if CTK_CONF_WINDOWCLOSE dispatcher_emit(ctk_signal_window_close, windows, w->window->owner); ctk_window_close(windows); return REDRAW_ALL;#endif /* CTK_CONF_WINDOWCLOSE */ } else if(w == (struct ctk_widget *)&windows->titlebutton) {#if CTK_CONF_WINDOWCLOSE mode = CTK_MODE_WINDOWMOVE;#endif /* CTK_CONF_WINDOWCLOSE */ } else { dispatcher_emit(ctk_signal_widget_activate, w, w->window->owner); }#if CTK_CONF_ICONS } else if(w->type == CTK_WIDGET_ICON) { dispatcher_emit(ctk_signal_widget_activate, w, w->widget.icon.owner);#endif /* CTK_CONF_ICONS */ } else if(w->type == CTK_WIDGET_HYPERLINK) { dispatcher_emit(ctk_signal_hyperlink_activate, w, DISPATCHER_BROADCAST); } else if(w->type == CTK_WIDGET_TEXTENTRY) { if(w->widget.textentry.state == CTK_TEXTENTRY_NORMAL) { w->widget.textentry.state = CTK_TEXTENTRY_EDIT; len = strlen(w->widget.textentry.text); if(w->widget.textentry.xpos > len) { w->widget.textentry.xpos = len; } } else if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT) { w->widget.textentry.state = CTK_TEXTENTRY_NORMAL; dispatcher_emit(ctk_signal_widget_activate, w, w->window->owner); } add_redrawwidget(w); return REDRAW_WIDGETS; } else { dispatcher_emit(ctk_signal_widget_activate, w, w->window->owner); } return REDRAW_NONE;}/*-----------------------------------------------------------------------------------*/static void CC_FASTCALL textentry_input(ctk_arch_key_t c, CC_REGISTER_ARG struct ctk_textentry *t){ register char *cptr, *cptr2; static unsigned char len, txpos, typos, tlen; txpos = t->xpos; typos = t->ypos; tlen = t->len; cptr = &t->text[txpos + typos * tlen]; switch(c) { case CH_CURS_LEFT: if(txpos > 0) { --txpos; } break; case CH_CURS_RIGHT: if(txpos < tlen && *cptr != 0) { ++txpos; } break; case CH_CURS_UP: txpos = 0; break; case CH_CURS_DOWN: txpos = strlen(t->text); break; case CH_ENTER: /* t->state = CTK_TEXTENTRY_NORMAL;*/ activate((struct ctk_widget *)t); switch_focus_widget(DOWN); break; case CTK_CONF_WIDGETDOWN_KEY: t->state = CTK_TEXTENTRY_NORMAL; switch_focus_widget(DOWN); break; case CTK_CONF_WIDGETUP_KEY: t->state = CTK_TEXTENTRY_NORMAL; switch_focus_widget(UP); break; default: len = tlen - txpos - 1; if(c == CH_DEL) { if(txpos > 0 && len > 0) { strncpy(cptr - 1, cptr, len); *(cptr + len - 1) = 0; --txpos; } } else { if(len > 0) { cptr2 = cptr + len - 1; while(cptr2 + 1 > cptr) { *(cptr2 + 1) = *cptr2; --cptr2; } *cptr = c; ++txpos; } } break; } t->xpos = txpos; t->ypos = typos;}/*-----------------------------------------------------------------------------------*/#if CTK_CONF_MENUSstatic unsigned char activate_menu(void){ struct ctk_window *w; lastmenu = menus.open; if(menus.open == &desktopmenu) { for(w = windows; w != NULL; w = w->next) { if(w->title == desktopmenu.items[desktopmenu.active].title) { ctk_window_open(w); menus.open = NULL; return REDRAW_ALL; } } } else { dispatcher_emit(ctk_signal_menu_activate, menus.open, DISPATCHER_BROADCAST); } menus.open = NULL; return REDRAW_MENUPART;}/*-----------------------------------------------------------------------------------*/static unsigned char menus_input(ctk_arch_key_t c){ if(menus.open->nitems > maxnitems) { maxnitems = menus.open->nitems; } switch(c) { case CH_CURS_RIGHT: switch_open_menu(1); return REDRAW_MENUPART; case CH_CURS_DOWN: switch_menu_item(1); return REDRAW_MENUS; case CH_CURS_LEFT: switch_open_menu(0); return REDRAW_MENUPART; case CH_CURS_UP: switch_menu_item(0); return REDRAW_MENUS; case CH_ENTER: return activate_menu(); case CTK_CONF_MENU_KEY: lastmenu = menus.open; menus.open = NULL; return REDRAW_MENUPART; } return REDRAW_NONE;}#endif /* CTK_CONF_MENUS *//*-----------------------------------------------------------------------------------*/static voidtimer(void){ if(mode == CTK_MODE_NORMAL) { ++screensaver_timer; if(screensaver_timer >= ctk_screensaver_timeout) {#if CTK_CONF_SCREENSAVER dispatcher_emit(ctk_signal_screensaver_start, NULL, DISPATCHER_BROADCAST);#ifdef CTK_SCREENSAVER_INIT CTK_SCREENSAVER_INIT();#endif /* CTK_SCREENSAVER_INIT */#endif /* CTK_CONF_SCREENSAVER */ screensaver_timer = 0; } } }/*-----------------------------------------------------------------------------------*/static voidunfocus_widget(CC_REGISTER_ARG struct ctk_widget *w){ if(w != NULL) { redraw |= REDRAW_WIDGETS; add_redrawwidget(w); if(CTK_WIDGET_TYPE(w) == CTK_WIDGET_TEXTENTRY) { ((struct ctk_textentry *)w)->state = CTK_TEXTENTRY_NORMAL; } w->window->focused = NULL; }}/*-----------------------------------------------------------------------------------*/static voidctk_idle(void) { static ctk_arch_key_t c; static unsigned char i; register struct ctk_window *window; register struct ctk_widget *widget; register struct ctk_widget **widgetptr;#if CTK_CONF_MOUSE_SUPPORT static unsigned char mxc, myc, mouse_button_changed, mouse_moved, mouse_clicked; static unsigned char menux; register struct ctk_menu *menu;#endif /* CTK_CONF_MOUSE_SUPPORT */ current = ek_clock(); if((current - start) >= CLK_TCK) { timer(); start = current; } #if CTK_CONF_MENUS if(menus.open != NULL) { maxnitems = menus.open->nitems; } else { maxnitems = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -