📄 look-next.c
字号:
CLine (cache->cache, 1, y1, cache->width - 2, y1); if (pushed) CSetColor ((cache->hilited == cache->current) ? COLOR_FLAT : color_wdiget (15)); CLine (cache->cache, 0, y2, cache->width - 2, y2); CLine (cache->cache, cache->width - 2, y2, cache->width - 2, y1); }}static void hilite_filelist_line (FilelistCache * cache, int color, struct file_entry *directentry){ int y1, y2, x2; y1 = (cache->hilited - cache->firstline) * cache->rowheight; y2 = y1 + (cache->rowheight / 2 - 4); x2 = cache->width - NEXT_ARROW_FIELD + NEXT_ARROW_SIZE / 2; if (y1 >= 0 && y1 < cache->height - FONT_OVERHEAD) { CSetColor (color); CRectangle (cache->cache, 0, y1, cache->width - 1, cache->rowheight - 1); CSetColor (COLOR_BLACK); if (!(directentry[cache->hilited].options & FILELIST_LAST_ENTRY) && directentry[cache->hilited].name != NULL) { restrict_text_area (cache); CSetBackgroundColor (color); CImageString (cache->cache, FONT_OFFSET_X + 1, FONT_OFFSET_Y + y1, directentry[cache->hilited].name); XSetClipMask (CDisplay, CGC, None); if (is_directory (directentry, cache->hilited)) { CSetColor (COLOR_BLACK); CLine (cache->cache, x2, y2, x2 + 7, y2 + 4); CLine (cache->cache, x2, y2, x2, y2 + 8); CSetColor (COLOR_FLAT); CLine (cache->cache, x2, y2 + 8, x2 + 7, y2 + 4); } } }}static void scroll_cache (FilelistCache * cache, unsigned int new_first, int *start, int *end){ int good_start, good_end, scroll_to; if (cache->firstline > new_first) { /* scrolling up */ good_start = 0; scroll_to = (cache->firstline - new_first) * cache->rowheight; good_end = cache->height - scroll_to; } else { good_start = (new_first - cache->firstline) * cache->rowheight; good_end = cache->height; scroll_to = 0; } if (good_start < good_end) { XCopyArea (CDisplay, cache->cache, cache->cache, CGC, 0, good_start, cache->width, good_end, 0, scroll_to); if (cache->firstline > new_first) { /* scrolling up */ *start = 0; *end = scroll_to; } else { *start = (cache->height - good_start); *end = cache->height; } } else { *start = 0; *end = cache->height; } if (*start < *end) { CSetColor (COLOR_FLAT); CRectangle (cache->cache, 0, *start, cache->width, *end); } *start /= cache->rowheight; *end /= cache->rowheight;}static void check_filelist_cache (CWidget * wdt, unsigned int w, unsigned int h, FilelistCache * cache){ struct file_entry *directentry = (struct file_entry *) wdt->hook; int y, x, start_y; int i, start = 0, end = 0; if (cache->cache) { if (cache->width == w && cache->height == h) { if (cache->firstline == wdt->firstline && cache->hilited == wdt->cursor && cache->options == wdt->options) return; } else { XFreePixmap (CDisplay, cache->cache); cache->cache = None; } } if (cache->cache == None) { cache->cache = XCreatePixmap (CDisplay, wdt->winid, w, h, CDepth); cache->width = w; cache->height = h; CTextSize (NULL, (int *) &(cache->rowheight), "Ty~g$V|&^.,/_'I}[@"); if (cache->rowheight == 0) cache->rowheight = 1; cache->rowheight += FONT_OVERHEAD; CSetColor (COLOR_FLAT); CRectangle (cache->cache, 0, 0, w, h); end = h / cache->rowheight; } else { push_filelist_line (cache, False); if (cache->hilited != wdt->cursor) hilite_filelist_line (cache, COLOR_FLAT, directentry); if (cache->firstline != wdt->firstline) scroll_cache (cache, wdt->firstline, &start, &end); } cache->firstline = wdt->firstline; cache->hilited = wdt->cursor; hilite_filelist_line (cache, (wdt->options & BUTTON_HIGHLIGHT) ? COLOR_WHITE : color_widget (12), directentry); cache->current = wdt->current; push_filelist_line (cache, True); cache->options = wdt->options; start_y = start * cache->rowheight; y = start_y + FONT_OFFSET_Y; start += wdt->firstline; end += wdt->firstline; CSetColor (COLOR_BLACK); restrict_text_area (cache); for (i = start; i <= end && i < wdt->numlines && y < cache->height && !(directentry[i].options & FILELIST_LAST_ENTRY); i++) { if (directentry[i].name && i != cache->hilited) { CSetBackgroundColor (COLOR_FLAT); CImageString (cache->cache, FONT_OFFSET_X + 1, y, directentry[i].name); } y += cache->rowheight; } XSetClipMask (CDisplay, CGC, None); /* now drawing arrows */ y = start_y + (cache->rowheight / 2 - 4); x = cache->width - NEXT_ARROW_FIELD + NEXT_ARROW_SIZE / 2; for (i = start; i <= end && i < wdt->numlines && y < cache->height && !(directentry[i].options & FILELIST_LAST_ENTRY); i++) { if (is_directory (directentry, i)) { CSetColor (COLOR_BLACK); CLine (cache->cache, x, y, x + 7, y + 4); CLine (cache->cache, x, y, x, y + 8); CSetColor ((i == cache->hilited) ? COLOR_FLAT : COLOR_WHITE); CLine (cache->cache, x, y + 8, x + 7, y + 4); } y += cache->rowheight; }}static void render_NeXT_filelist (CWidget * wdt){ FilelistCache *cache; if (wdt->hook == NULL) { render_bevel (wdt->winid, 0, 0, wdt->width - 1, wdt->height - 1, 1, 3); return; } if (wdt->user == NULL) { wdt->user = calloc (sizeof (FilelistCache), 1); wdt->free_user = free_filelist_cache; } cache = (FilelistCache *) (wdt->user); CPushFont ("widget", 0); check_filelist_cache (wdt, wdt->width - 3, wdt->height - 3, cache); CPopFont (); render_bevel (wdt->winid, 0, 0, wdt->width - 1, wdt->height - 1, 1, 1); XCopyArea (CDisplay, cache->cache, wdt->winid, CGC, 0, 0, cache->width, cache->height, 2, 2);}static void link_scrollbar_to_NeXT_filelist (CWidget * scrollbar, CWidget * w, XEvent * xevent, CEvent * cwevent, int whichscrbutton){ /* fix me : add stuf */ int redrawtext = 0; int new_first = w->firstline; FilelistCache *cache; int box_size; if (w->user == NULL) return; cache = (FilelistCache *) (w->user); box_size = cache->height / cache->rowheight; if ((xevent->type == ButtonRelease || xevent->type == MotionNotify) && whichscrbutton == 3) { new_first = (double) scrollbar->firstline * w->numlines / 65535.0; } else if (xevent->type == ButtonPress && (cwevent->button == Button1 || cwevent->button == Button2)) { new_first = w->firstline; switch (whichscrbutton) { case 1: new_first -= box_size - 1; break; case 2: new_first--; break; case 5: new_first++; break; case 4: new_first += box_size - 1; break; } } if (new_first < 0) new_first = 0; else if (new_first > w->numlines - box_size) new_first = w->numlines - box_size; redrawtext = (new_first != w->firstline); w->firstline = new_first; if (xevent->type == ButtonRelease || (redrawtext && !CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0))) render_NeXT_filelist (w); scrollbar->firstline = (double) 65535.0 *w->firstline / (w->numlines ? w->numlines : 1); scrollbar->numlines = (double) 65535.0 *box_size / (w->numlines ? w->numlines : 1);}static int eh_NeXT_filelist (CWidget * w, XEvent * xevent, CEvent * cwevent);static CWidget *look_next_draw_file_list (const char *identifier, Window parent, int x, int y, int width, int height, int line, int column, struct file_entry *directentry, long options){ struct file_entry e; CWidget *w; int x_hint; int lines = 0; unsigned int prop; if (!directentry) { memset (&e, 0, sizeof (e)); e.options = FILELIST_LAST_ENTRY; directentry = &e; } else { while (!(directentry[lines].options & FILELIST_LAST_ENTRY)) lines++; } if (height == AUTO_HEIGHT) height = max (1, lines) * FONT_PIX_PER_LINE + 6; if (width == AUTO_WIDTH) width = (FONT_MEAN_WIDTH * 24 + 15); w = CSetupWidget (identifier, parent, x, y, width, height, C_TEXTBOX_WIDGET, INPUT_KEY, COLOR_FLAT, 1); x_hint = x + width + WIDGET_SPACING; prop = (double) 65535.0 *(height / FONT_PIX_PER_LINE) / (lines ? lines : 1); w->vert_scrollbar = CDrawVerticalScrollbar (catstrs (identifier, ".vsc", 0), parent, x_hint, y, height, AUTO_WIDTH, 0, prop); w->vert_scrollbar->position |= POSITION_HEIGHT; CSetScrollbarCallback (w->vert_scrollbar->ident, w->ident, link_scrollbar_to_NeXT_filelist); CGetHintPos (&x_hint, 0); set_hint_pos (x_hint, y + height + WIDGET_SPACING); w->eh = eh_NeXT_filelist; w->current = -1; w->cursor = -1; w->firstline = 0; w->numlines = lines; w->hook = directentry; return w;}CWidget *look_next_redraw_file_list (const char *identifier, struct file_entry * directentry, int preserve){ CWidget *w = CIdent (identifier); if (w) { w->hook = directentry; if (!directentry) w->numlines = 1; else { register int i = 0; while (!(directentry[i].options & FILELIST_LAST_ENTRY)) i++; w->numlines = i; } w->current = -1; w->cursor = -1; w->firstline = 0; free_filelist_cache (w->user); w->user = NULL; render_NeXT_filelist (w); if (w->user) { FilelistCache *cache; int box_size; cache = (FilelistCache *) (w->user); box_size = cache->height / cache->rowheight; w->vert_scrollbar->firstline = (double) 65535.0 *w->firstline / (w->numlines ? w->numlines : 1); w->vert_scrollbar->numlines = (double) 65535.0 *box_size / (w->numlines ? w->numlines : 1); render_scrollbar (w->vert_scrollbar); } } return w;}void CSetFilelistPosition (const char *identifier, long current, long cursor, long firstline){ CWidget *w = CIdent (identifier); if (w) { FilelistCache *cache; int redraw_scrollbar = 0; if (current >= w->numlines) current = w->numlines - 1; if (cursor >= w->numlines) cursor = w->numlines - 1; w->current = current; w->cursor = cursor; if (firstline >= 0 && (cache = (FilelistCache *) (w->user))) { long max_fline = w->numlines - cache->height / cache->rowheight; if (max_fline <= 0) if (firstline >= max_fline) firstline = max_fline - 1; /* if our window is larger then numlines : */ if (firstline < 0) firstline = 0; redraw_scrollbar = (w->firstline != firstline); w->firstline = firstline; } render_NeXT_filelist (w); if (redraw_scrollbar) { w->vert_scrollbar->firstline = (double) 65535.0 *w->firstline / (w->numlines ? w->numlines : 1); render_scrollbar (w->vert_scrollbar); } }}struct file_entry *look_next_get_file_list_line (CWidget * w, int line){ struct file_entry *e; static struct file_entry r; memset (&r, 0, sizeof (r)); e = (struct file_entry *) w->hook; if (e[line].options & FILELIST_LAST_ENTRY) r.options = FILELIST_LAST_ENTRY; else r = e[line]; return &r;}int filelist_handle_mouse (CWidget * wdt, FilelistCache * cache, int y){ int new_hilite; new_hilite = (int) (wdt->firstline) + y / (int) (cache->rowheight); if (y < 0) new_hilite--; /* we don't want to remove hilite even if user wants to go beyound the beginning */ if (new_hilite < 0) new_hilite = 0; return new_hilite;}int filelist_handle_keypress (CWidget * wdt, FilelistCache * cache, KeySym key){ int new_cursor = wdt->cursor;/* when text is highlighted, the cursor must be off */ switch ((int) key) { case CK_Up: new_cursor--; break; case CK_Down: new_cursor++; break; case CK_Page_Up: new_cursor -= cache->height / cache->rowheight - 1; break; case CK_Page_Down: new_cursor += cache->height / cache->rowheight - 1; break; case CK_Home: new_cursor = 0; break; case CK_End: new_cursor = wdt->numlines; break; default: return -1; } /* we don't want to remove hilite even if user wants to go beyound the beginning */ if (new_cursor < 0) new_cursor = 0; return new_cursor;}int change_hilite (CWidget * w, int new_hilite){ FilelistCache *cache = (FilelistCache *) (w->user); if (new_hilite >= w->numlines) new_hilite = w->numlines - 1; if (new_hilite != w->cursor) { int new_firstline = w->firstline;#if 0 struct file_entry *directentry = (struct file_entry *) w->hook;#endif if (new_hilite < w->firstline && new_hilite >= 0) new_firstline = new_hilite; if (new_hilite >= w->firstline + w->height / cache->rowheight) new_firstline = new_hilite - w->height / cache->rowheight + 1; if (new_firstline != w->firstline) { w->cursor = new_hilite; w->firstline = new_firstline; w->vert_scrollbar->firstline = (double) 65535.0 *w->firstline / (w->numlines ? w->numlines : 1); render_scrollbar (w->vert_scrollbar); } w->cursor = new_hilite; return 1; } return 0;}void selection_send (XSelectionRequestEvent * rq);int eh_NeXT_filelist (CWidget * w, XEvent * xevent, CEvent * cwevent){#if 0 int xevent_xbutton_y;#endif int need_redraw = 0; FilelistCache *cache = (FilelistCache *) (w->user); int handled = 0; if ((w == NULL || w->hook == NULL || cache == NULL) && xevent->type != Expose) return handled; switch (xevent->type) { case SelectionRequest:/* fixme: later { int type; if (selection.text) free (selection.text); selection.text = (unsigned char *) get_block (w, 0, 0, &type, &selection.len); selection_send (&(xevent->xselectionrequest)); } return 1; */ case Expose: handled = 1; break; case ButtonPress: resolve_button (xevent, cwevent); need_redraw = change_hilite (w, filelist_handle_mouse (w, cache, cwevent->y)); handled = 1; break; case ButtonRelease: resolve_button (xevent, cwevent); need_redraw = change_hilite (w, filelist_handle_mouse (w, cache, cwevent->y)); handled = 1; break; case MotionNotify: resolve_button (xevent, cwevent); if (cwevent->state & (Button1Mask | Button2Mask)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -