📄 ctk.c
字号:
#if CTK_CONF_WINDOWCLOSE CTK_BUTTON_NEW(&window->closebutton, window->w - 3, -1, 1, "x");#else CTK_LABEL_NEW(&window->closebutton, window->w - 4, -1, 3, 1, " ");#endif /* CTK_CONF_WINDOWCLOSE */ CTK_WIDGET_ADD(window, &window->closebutton);}/*-----------------------------------------------------------------------------------*//** * Remove all widgets from a window. * * \param w The window to be cleared. *//*-----------------------------------------------------------------------------------*/voidctk_window_clear(struct ctk_window *w){ w->active = w->inactive = w->focused = NULL; make_windowbuttons(w);}/*-----------------------------------------------------------------------------------*//** * Add a menu to the menu bar. * * \param menu The menu to be added. * * \note Do not call this function multiple times for the same menu, * as no check is made to see if the menu already is in the menu bar. *//*-----------------------------------------------------------------------------------*/voidctk_menu_add(struct ctk_menu *menu){#if CTK_CONF_MENUS struct ctk_menu *m; if(lastmenu == NULL) { lastmenu = menu; } for(m = menus.menus; m->next != NULL; m = m->next) { if(m == menu) { return; } } m->next = menu; menu->next = NULL; redraw |= REDRAW_MENUPART;#endif /* CTK_CONF_MENUS */}/*-----------------------------------------------------------------------------------*//** * Remove a menu from the menu bar. * * \param menu The menu to be removed. *//*-----------------------------------------------------------------------------------*/voidctk_menu_remove(struct ctk_menu *menu){#if CTK_CONF_MENUS struct ctk_menu *m; for(m = menus.menus; m->next != NULL; m = m->next) { if(m->next == menu) { m->next = menu->next; if(menu == lastmenu) { lastmenu = NULL; } redraw |= REDRAW_MENUPART; return; } }#endif /* CTK_CONF_MENUS */}/*-----------------------------------------------------------------------------------*//** * \internal Redraws everything on the screen within the clip * interval. * * \param clipy1 The upper bound of the clip interval * \param clipy2 The lower bound of the clip interval *//*-----------------------------------------------------------------------------------*/static void CC_FASTCALL do_redraw_all(unsigned char clipy1, unsigned char clipy2){ struct ctk_window *w; static struct ctk_widget *widget; if(mode != CTK_MODE_NORMAL && mode != CTK_MODE_WINDOWMOVE) { return; } ctk_draw_clear(clipy1, clipy2); /* Draw widgets in root window */ for(widget = desktop_window.active; widget != NULL; widget = widget->next) { ctk_draw_widget(widget, CTK_FOCUS_WINDOW, clipy1, clipy2); } /* Draw windows */ if(windows != NULL) { /* Find the last window.*/ for(w = windows; w->next != NULL; w = w->next); /* Draw the windows from back to front. */ for(; w != windows; w = w->prev) { ctk_draw_clear_window(w, 0, clipy1, clipy2); ctk_draw_window(w, 0, clipy1, clipy2); } /* Draw focused window */ ctk_draw_clear_window(windows, CTK_FOCUS_WINDOW, clipy1, clipy2); ctk_draw_window(windows, CTK_FOCUS_WINDOW, clipy1, clipy2); } /* Draw dialog (if any) */ if(dialog != NULL) { ctk_draw_dialog(dialog); }#if CTK_CONF_MENUS ctk_draw_menus(&menus);#endif /* CTK_CONF_MENUS */}/*-----------------------------------------------------------------------------------*//** * Redraw the entire desktop. * * \param d The desktop to be redrawn. * * \note Currently the parameter d is not used, but must be set to * NULL. *//*-----------------------------------------------------------------------------------*/voidctk_desktop_redraw(struct ctk_desktop *d){ if(DISPATCHER_CURRENT() == ctkid) { if(mode == CTK_MODE_NORMAL || mode == CTK_MODE_WINDOWMOVE) { do_redraw_all(1, height); } } else { redraw |= REDRAW_ALL; }}/*-----------------------------------------------------------------------------------*//** * Redraw a window. * * This function redraws the window, but only if it is the foremost * one on the desktop. * * \param w The window to be redrawn. *//*-----------------------------------------------------------------------------------*/void ctk_window_redraw(struct ctk_window *w){ /* Only redraw the window if it is a dialog or if it is the foremost window. */ if(mode != CTK_MODE_NORMAL) { return; } if(w == dialog) { ctk_draw_dialog(w); } else if(dialog == NULL &&#if CTK_CONF_MENUS menus.open == NULL &&#endif /* CTK_CONF_MENUS */ windows == w) { ctk_draw_window(w, CTK_FOCUS_WINDOW, 0, height); } }/*-----------------------------------------------------------------------------------*//** * \internal Creates a new window. * * \param window The window to be created. * \param w The width of the window. * \param h The height of the window. * \param title The title of the window. *//*-----------------------------------------------------------------------------------*/static void window_new(CC_REGISTER_ARG struct ctk_window *window, unsigned char w, unsigned char h, char *title){ if(w >= width - 2) { window->x = 0; } else { window->x = (width - w - 2) / 2; } if(h >= height - 3) { window->y = 0; } else { window->y = (height - h - 1) / 2; } window->w = w; window->h = h; window->title = title; if(title != NULL) { window->titlelen = strlen(title); } else { window->titlelen = 0; } window->next = window->prev = NULL; window->owner = DISPATCHER_CURRENT(); window->active = window->inactive = window->focused = NULL;}/*-----------------------------------------------------------------------------------*//** * Create a new window. * * Creates a new window. The memory for the window structure must * already be allocated by the caller, and is usually done with a * static declaration. * * This function sets up the internal structure of the ctk_window * struct and creates the move and close buttons, but it does not open * the window. The window must be explicitly opened by calling the * ctk_window_open() function. * * \param window The window to be created. * \param w The width of the new window. * \param h The height of the new window. * \param title The title of the new window. *//*-----------------------------------------------------------------------------------*/voidctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title){ window_new(window, w, h, title); make_windowbuttons(window); }/*-----------------------------------------------------------------------------------*//** * Creates a new dialog. * * This function only sets up the internal structure of the ctk_window * struct but does not open the dialog. The dialog must be explicitly * opened by calling the ctk_dialog_open() function. * * \param dialog The dialog to be created. * \param w The width of the dialog. * \param h The height of the dialog. *//*-----------------------------------------------------------------------------------*/voidctk_dialog_new(CC_REGISTER_ARG struct ctk_window *dialog, unsigned char w, unsigned char h){ window_new(dialog, w, h, NULL);}/*-----------------------------------------------------------------------------------*//** * Creates a new menu. * * This function sets up the internal structure of the menu, but does * not add it to the menubar. Use the function ctk_menu_add() for that * purpose. * * \param menu The menu to be created. * \param title The title of the menu. *//*-----------------------------------------------------------------------------------*/void ctk_menu_new(CC_REGISTER_ARG struct ctk_menu *menu, char *title){#if CTK_CONF_MENUS menu->next = NULL; menu->title = title; menu->titlelen = strlen(title); menu->active = 0; menu->nitems = 0;#endif /* CTK_CONF_MENUS */}/*-----------------------------------------------------------------------------------*//** * Adds a menu item to a menu. * * In CTK, each menu item is identified by a number which is unique * within each menu. When a menu item is selected, a * ctk_menuitem_activated signal is emitted and the menu item number * is passed as signal data with the signal. * * \param menu The menu to which the menu item should be added. * \param name The name of the menu item. * \return The number of the menu item. *//*-----------------------------------------------------------------------------------*/unsigned charctk_menuitem_add(CC_REGISTER_ARG struct ctk_menu *menu, char *name){#if CTK_CONF_MENUS if(menu->nitems == CTK_CONF_MAXMENUITEMS) { return 0; } menu->items[menu->nitems].title = name; menu->items[menu->nitems].titlelen = strlen(name); return menu->nitems++;#else return 0;#endif /* CTK_CONF_MENUS */}/*-----------------------------------------------------------------------------------*//** * \internal Adds a widget to the list of widgets that should be * redrawn. * * \param w The widget that should be redrawn. *//*-----------------------------------------------------------------------------------*/static void CC_FASTCALL add_redrawwidget(struct ctk_widget *w){ static unsigned char i; if(redraw_widgetptr == MAX_REDRAWWIDGETS) { redraw |= REDRAW_FOCUS; } else { redraw |= REDRAW_WIDGETS; /* Check if it is in the queue already. If so, we don't add it again. */ for(i = 0; i < redraw_widgetptr; ++i) { if(redraw_widgets[i] == w) { return; } } redraw_widgets[redraw_widgetptr++] = w; }}/*-----------------------------------------------------------------------------------*//** * \internal Checks if a widget redrawn and adds it to the list of * widgets to be redrawn. * * A widget can be redrawn only if the current CTK mode is * CTK_MODE_NORMAL, if no menu is open, and the widget is in the * foremost window. * * \param widget The widget that should be redrawn. *//*-----------------------------------------------------------------------------------*/static voidwidget_redraw(struct ctk_widget *widget){ struct ctk_window *window; if(mode != CTK_MODE_NORMAL || widget == NULL) { return; } /* Only redraw widgets that are in the foremost window. If we would allow redrawing widgets in non-focused windows, we would have to redraw all the windows that cover the non-focused window as well, which would lead to flickering. Also, we avoid drawing any widgets when the menus are active. */ #if CTK_CONF_MENUS if(menus.open == NULL)#endif /* CTK_CONF_MENUS */ { window = widget->window; if(window == dialog) { ctk_draw_widget(widget, CTK_FOCUS_DIALOG, 0, height); } else if(dialog == NULL && (window == windows || window == &desktop_window)) { ctk_draw_widget(widget, CTK_FOCUS_WINDOW, 0, height); } }}/*-----------------------------------------------------------------------------------*//** * Redraws a widget. * * This function will set a flag which causes the widget to be redrawn * next time the CTK process is scheduled. * * \param widget The widget that is to be redrawn. * * \note This function should usually not be called directly since it * requires typecasting of the widget parameter. The wrapper macro * CTK_WIDGET_REDRAW() does the required typecast and should be used * instead. *//*-----------------------------------------------------------------------------------*/void ctk_widget_redraw(struct ctk_widget *widget){ struct ctk_window *window; if(mode != CTK_MODE_NORMAL || widget == NULL) { return; } /* Since this function isn't called by CTK itself, we only queue the redraw request. */ add_redrawwidget(widget);}/*-----------------------------------------------------------------------------------*//** * Adds a widget to a window. * * This function adds a widget to a window. The order of which the * widgets are added is important, as it sets the order to which * widgets are cycled with the widget selection keys. * * \param window The window to which the widhet should be added. * \param widget The widget to be added. *//*-----------------------------------------------------------------------------------*/void CC_FASTCALLctk_widget_add(CC_REGISTER_ARG struct ctk_window *window, CC_REGISTER_ARG struct ctk_widget *widget){ if(widget->type == CTK_WIDGET_LABEL || widget->type == CTK_WIDGET_SEPARATOR) { widget->next = window->inactive; window->inactive = widget; widget->window = window; } else { widget->next = window->active; window->active = widget; widget->window = window; /* if(window->focused == NULL) { window->focused = widget;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -