📄 ctk.c
字号:
#endif /* CTK_CONF_MENUS */#if CTK_CONF_MOUSE_SUPPORT mouse_button_changed = mouse_moved = mouse_clicked = 0; /* See if there is any change in the buttons. */ if(ctk_mouse_button() != mouse_button) { mouse_button = ctk_mouse_button(); mouse_button_changed = 1; if(mouse_button == 0) { mouse_clicked = 1; } } /* Check if the mouse pointer has moved. */ if(ctk_mouse_x() != mouse_x || ctk_mouse_y() != mouse_y) { mouse_x = ctk_mouse_x(); mouse_y = ctk_mouse_y(); mouse_moved = 1; } mxc = ctk_mouse_xtoc(mouse_x); myc = ctk_mouse_ytoc(mouse_y); #endif /* CTK_CONF_MOUSE_SUPPORT */#if CTK_CONF_SCREENSAVER if(mode == CTK_MODE_SCREENSAVER) { if(ctk_arch_keyavail()#if CTK_CONF_MOUSE_SUPPORT || mouse_moved || mouse_button_changed#endif /* CTK_CONF_MOUSE_SUPPORT */ ) { dispatcher_emit(ctk_signal_screensaver_stop, NULL, DISPATCHER_BROADCAST); mode = CTK_MODE_NORMAL; } } else#endif /* CTK_CONF_SCREENSAVER */ if(mode == CTK_MODE_NORMAL) {#if CTK_CONF_MOUSE_SUPPORT /* If there is any change in the mouse conditions, find out in which window the mouse pointer currently is in order to send the correct signals, or bring a window to focus. */ if(mouse_moved || mouse_button_changed) { ctk_mouse_show(); screensaver_timer = 0; if(myc == 0) { /* Here we should do whatever needs to be done when the mouse moves around and clicks in the menubar. */ if(mouse_clicked) { static unsigned char titlelen; /* Find out which menu that the mouse pointer is in. Start with the ->next menu after the desktop menu. We assume that the menus start one character from the left screen side and that the desktop menu is farthest to the right. */ menux = 1; for(menu = menus.menus->next; menu != NULL; menu = menu->next) { titlelen = menu->titlelen; if(mxc >= menux && mxc <= menux + titlelen) { break; } menux += titlelen; } /* Also check desktop menu. */ if(mxc >= width - 7 && mxc <= width - 1) { menu = &desktopmenu; } menus.open = menu; redraw |= REDRAW_MENUPART; } } else { --myc; if(menus.open != NULL) { static unsigned char nitems; /* Do whatever needs to be done when a menu is open. */ /* First check if the mouse pointer is in the currently open menu. */ if(menus.open == &desktopmenu) { menux = width - CTK_CONF_MENUWIDTH; } else { menux = 1; for(menu = menus.menus->next; menu != menus.open; menu = menu->next) { menux += menu->titlelen; } } nitems = menus.open->nitems; /* Find out which of the menu items the mouse is pointing to. */ if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH) { if(myc <= nitems) { menus.open->active = myc; } else { menus.open->active = nitems - 1; } } if(mouse_clicked) { if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH && myc <= nitems) { redraw |= activate_menu(); } else { lastmenu = menus.open; menus.open = NULL; redraw |= REDRAW_MENUPART; } } else { redraw |= REDRAW_MENUS; } } else { /* Walk through the windows from top to bottom to see in which window the mouse pointer is. */ if(dialog != NULL) { window = dialog; } else { for(window = windows; window != NULL; window = window->next) { /* Check if the mouse is within the window. */ if(mxc >= window->x && mxc <= window->x + window->w && myc >= window->y && myc <= window->y + window->h) { break; } } } /* If we didn't find any window, and there are no windows open, the mouse pointer will definately be within the background desktop window. */ if(window == NULL) { window = &desktop_window; } /* If the mouse pointer moves around outside of the currently focused window (or dialog), we should not have any focused widgets in the focused window so we make sure that there are none. */ if(windows != NULL && window != windows && windows->focused != NULL){ /*add_redrawwidget(windows->focused); windows->focused = NULL; redraw |= REDRAW_WIDGETS;*/ unfocus_widget(windows->focused); } if(window != NULL) { /* If the mouse was clicked outside of the current window, we bring the clicked window to front. */ if(dialog == NULL && window != &desktop_window && window != windows && mouse_clicked) { /* Bring window to front. */ ctk_window_open(window); redraw |= REDRAW_ALL; } else { /* Find out which widget currently is under the mouse pointer and give it focus, unless it already has focus. */ mxc = mxc - window->x - 1; myc = myc - window->y - 1; /* See if the mouse pointer is on a widget. If so, it should be selected and, if the button is clicked, activated. */ for(widget = window->active; widget != NULL; widget = widget->next) { if(mxc >= widget->x && mxc <= widget->x + widget->w && (myc == widget->y || ((widget->type == CTK_WIDGET_BITMAP || /*widget->type == CTK_WIDGET_TEXTMAP ||*/ widget->type == CTK_WIDGET_ICON) && (myc >= widget->y && myc <= widget->y + ((struct ctk_bitmap *)widget)->h)))) { break; } } /* if the mouse is moved in the focused window, we emit a ctk_signal_pointer_move signal to the owner of the window. */ if(mouse_moved && (window != &desktop_window || windows == NULL)) { dispatcher_emit(ctk_signal_pointer_move, NULL, window->owner); /* If there was a focused widget that is not below the mouse pointer, we remove focus from the widget and redraw it. */ if(window->focused != NULL && widget != window->focused) { /* add_redrawwidget(window->focused); if(CTK_WIDGET_TYPE(window->focused) == CTK_WIDGET_TEXTENTRY) { ((struct ctk_textentry *)(window->focused))->state = CTK_TEXTENTRY_NORMAL; } window->focused = NULL;*/ unfocus_widget(window->focused); } redraw |= REDRAW_WIDGETS; if(widget != NULL) { select_widget(widget); } } if(mouse_button_changed) { dispatcher_emit(ctk_signal_pointer_button, (ek_data_t)mouse_button, window->owner); if(mouse_clicked && widget != NULL) { select_widget(widget); redraw |= activate(widget); } } } } } } }#endif /* CTK_CONF_MOUSE_SUPPORT */ while(ctk_arch_keyavail()) { ctk_mouse_hide(); screensaver_timer = 0; c = ctk_arch_getkey(); if(dialog != NULL) { window = dialog; } else if(windows != NULL) { window = windows; } else { window = &desktop_window; } widget = window->focused; if(widget != NULL && widget->type == CTK_WIDGET_TEXTENTRY && widget->widget.textentry.state == CTK_TEXTENTRY_EDIT) { textentry_input(c, (struct ctk_textentry *)widget); add_redrawwidget(widget);#if CTK_CONF_MENUS } else if(menus.open != NULL) { redraw |= menus_input(c);#endif /* CTK_CONF_MENUS */ } else { switch(c) { case CTK_CONF_WIDGETDOWN_KEY: switch_focus_widget(DOWN); break; case CTK_CONF_WIDGETUP_KEY: switch_focus_widget(UP); break;#if CTK_CONF_MENUS case CTK_CONF_MENU_KEY: if(dialog == NULL) { if(lastmenu == NULL) { menus.open = menus.menus; } else { menus.open = lastmenu; } menus.open->active = 0; redraw |= REDRAW_MENUS; } break;#endif /* CTK_CONF_MENUS */ case CTK_CONF_WINDOWSWITCH_KEY: if(windows != NULL) { for(window = windows; window->next != NULL; window = window->next); ctk_window_open(window); } break; default: if(c == CH_ENTER && widget != NULL) { redraw |= activate(widget); } else { if(widget != NULL && widget->type == CTK_WIDGET_TEXTENTRY) { widget->widget.textentry.state = CTK_TEXTENTRY_EDIT; textentry_input(c, (struct ctk_textentry *)widget); add_redrawwidget(widget); } else { /* window->focused = NULL;*/ unfocus_widget(window->focused); dispatcher_fastemit(ctk_signal_keypress, (void *)c, window->owner); } } break; } }#if 0 if(redraw & REDRAW_WIDGETS) { widgetptr = redraw_widgets; for(i = 0; i < MAX_REDRAWWIDGETS; ++i) { widget_redraw(*widgetptr); *widgetptr = NULL; ++widgetptr; } redraw &= ~REDRAW_WIDGETS; redraw_widgetptr = 0; }#endif /* 0 */ }#if CTK_CONF_WINDOWMOVE } else if(mode == CTK_MODE_WINDOWMOVE) { redraw = 0; window = windows;#if CTK_CONF_MOUSE_SUPPORT /* If the mouse has moved, we move the window as well. */ if(mouse_moved) { if(window->w + mxc + 2 >= width) { window->x = width - 2 - window->w; } else { window->x = mxc; } if(window->h + myc + 2 >= height) { window->y = height - 2 - window->h; } else { window->y = myc; } if(window->y > 0) { --window->y; } redraw = REDRAW_ALL; } /* Check if the mouse has been clicked, and stop moving the window if so. */ if(mouse_button_changed && mouse_button == 0) { mode = CTK_MODE_NORMAL; redraw = REDRAW_ALL; }#endif /* CTK_CONF_MOUSE_SUPPORT */ while(mode == CTK_MODE_WINDOWMOVE && ctk_arch_keyavail()) { screensaver_timer = 0; c = ctk_arch_getkey(); switch(c) { case CH_CURS_RIGHT: ++window->x; if(window->x + window->w + 1 >= width) { --window->x; } redraw = REDRAW_ALL; break; case CH_CURS_LEFT: if(window->x > 0) { --window->x; } redraw = REDRAW_ALL; break; case CH_CURS_DOWN: ++window->y; if(window->y + window->h + 2 >= height) { --window->y; } redraw = REDRAW_ALL; break; case CH_CURS_UP: if(window->y > 0) { --window->y; } redraw = REDRAW_ALL; break; default: mode = CTK_MODE_NORMAL; redraw = REDRAW_ALL; break; } }#endif /* CTK_CONF_WINDOWMOVE */ } if(redraw & REDRAW_ALL) { do_redraw_all(1, height);#if CTK_CONF_MENUS } else if(redraw & REDRAW_MENUPART) { do_redraw_all(1, maxnitems + 1); } else if(redraw & REDRAW_MENUS) { ctk_draw_menus(&menus);#endif /* CTK_CONF_MENUS */ } else if(redraw & REDRAW_FOCUS) { if(dialog != NULL) { ctk_window_redraw(dialog); } else if(windows != NULL) { ctk_window_redraw(windows); } else { ctk_window_redraw(&desktop_window); } } else if(redraw & REDRAW_WIDGETS) { widgetptr = redraw_widgets; for(i = 0; i < MAX_REDRAWWIDGETS; ++i) { widget_redraw(*widgetptr); *widgetptr = NULL; ++widgetptr; } } redraw = 0; redraw_widgetptr = 0; }/*-----------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -