static gboolean remove_toaster(GntToast *toast) { GList *iter; int h; int col; int nwin[MAX_COLS]; gnt_widget_get_size(toast->window, NULL, &h); gpsy[toast->column] -= h; col = toast->column; memset(&nwin, 0, sizeof(nwin)); destroy_toaster(toast); for (iter = toasters; iter; iter = iter->next) { int x, y; toast = iter->data; nwin[toast->column]++; if (toast->column != col) continue; gnt_widget_get_position(toast->window, &x, &y); y += h; gnt_screen_move_widget(toast->window, x, y); } if (nwin[col] == 0) gpsw[col] = 0; return FALSE; }
static void s_new_window(GntWM *wm, GntWidget *win) { int x, y, w, h; int maxx, maxy; const char *name; gboolean blist = FALSE; if (!GNT_IS_MENU(win)) { getmaxyx(stdscr, maxy, maxx); gnt_widget_get_position(win, &x, &y); gnt_widget_get_size(win, &w, &h); name = gnt_widget_get_name(win); if (name && strcmp(name, "buddylist") == 0) { /* The buddylist doesn't have no border nor nothing! */ x = 0; y = 0; h = maxy - 1; blist = TRUE; gnt_box_set_toplevel(GNT_BOX(win), FALSE); GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_CAN_TAKE_FOCUS); gnt_widget_set_position(win, x, y); mvwin(win->window, y, x); gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */ } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) { const char *title = GNT_BOX(win)->title; if (title == NULL || !g_hash_table_lookup(wm->positions, title)) { /* In the middle of the screen */ x = (maxx - w) / 2; y = (maxy - h) / 2; gnt_widget_set_position(win, x, y); mvwin(win->window, y, x); } } } org_new_window(wm, win); if (blist) gnt_wm_raise_window(wm, win); }
static gboolean gnt_box_clicked(GntWidget *widget, GntMouseEvent event, int cx, int cy) { GList *iter; for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { int x, y, w, h; GntWidget *wid = iter->data; gnt_widget_get_position(wid, &x, &y); gnt_widget_get_size(wid, &w, &h); if (cx >= x && cx < x + w && cy >= y && cy < y + h) { if (event <= GNT_MIDDLE_MOUSE_DOWN && GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_CAN_TAKE_FOCUS)) { while (widget->parent) widget = widget->parent; gnt_box_give_focus_to_child(GNT_BOX(widget), wid); } return gnt_widget_clicked(wid, event, cx, cy); } } return FALSE; }
static gboolean s_mouse_clicked(GntWM *wm, GntMouseEvent event, int cx, int cy, GntWidget *widget) { int x, y, w, h; if (!widget) return FALSE; /* This might be a place to bring up a context menu */ if (event != GNT_LEFT_MOUSE_DOWN || GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) return FALSE; gnt_widget_get_position(widget, &x, &y); gnt_widget_get_size(widget, &w, &h); if (cy == y && cx == x + w - 3) { gnt_widget_destroy(widget); return TRUE; } return FALSE; }
static gboolean show_suggest_dropdown(GntEntry *entry) { char *suggest = NULL; int len; int offset = 0, x, y; int count = 0; GList *iter; const char *text = NULL; const char *sgst = NULL; int max = -1; if (entry->word) { char *s = get_beginning_of_word(entry); suggest = g_strndup(s, entry->cursor - s); if (entry->scroll < s) offset = gnt_util_onscreen_width(entry->scroll, s); } else suggest = g_strdup(entry->start); len = strlen(suggest); /* Don't need to use the utf8-function here */ if (entry->ddown == NULL) { GntWidget *box = gnt_vbox_new(FALSE); entry->ddown = gnt_tree_new(); gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate); gnt_box_add_widget(GNT_BOX(box), entry->ddown); GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT); gnt_widget_get_position(GNT_WIDGET(entry), &x, &y); x += offset; y++; if (y + 10 >= getmaxy(stdscr)) y -= 11; gnt_widget_set_position(box, x, y); } else gnt_tree_remove_all(GNT_TREE(entry->ddown)); for (count = 0, iter = entry->suggests; iter; iter = iter->next) { text = iter->data; if (g_ascii_strncasecmp(suggest, text, len) == 0 && strlen(text) >= len) { gnt_tree_add_row_after(GNT_TREE(entry->ddown), (gpointer)text, gnt_tree_create_row(GNT_TREE(entry->ddown), text), NULL, NULL); count++; if (max == -1) max = strlen(text) - len; else if (max) max = MIN(max, max_common_prefix(sgst + len, text + len)); sgst = text; } } g_free(suggest); if (count == 0) { destroy_suggest(entry); return FALSE; } else if (count == 1) { char *store = g_strndup(entry->start, entry->end - entry->start); gboolean ret; destroy_suggest(entry); complete_suggest(entry, sgst); ret = (strncmp(store, entry->start, entry->end - entry->start) != 0); g_free(store); return ret; } else { if (max > 0) { GntWidget *ddown = entry->ddown; char *match = g_strndup(sgst + len, max); entry->ddown = NULL; gnt_entry_key_pressed(GNT_WIDGET(entry), match); g_free(match); if (entry->ddown) gnt_widget_destroy(ddown); else entry->ddown = ddown; } gnt_widget_draw(entry->ddown->parent); } return TRUE; }