#endif #ifndef _NOSPLITWIN {'/', SPLIT_WINDOW, FNO_NONE}, {'^', NEXT_WINDOW, FNO_NONE}, #endif #ifndef _NOEXTRAWIN {'W', WIDEN_WINDOW, FNO_NONE}, {'N', NARROW_WINDOW, FNO_NONE}, {'K', KILL_WINDOW, FNO_NONE}, #endif {K_HOME, MARK_ALL, FNO_NONE}, {K_END, MARK_REVERSE, FNO_NONE}, {K_BEG, CUR_TOP, FNO_NONE}, {K_EOL, CUR_BOTTOM, FNO_NONE}, {K_HELP, HELP_MESSAGE, FNO_NONE}, {K_CTRL('@'), MARK_FILE3, FNO_NONE}, {K_CTRL('L'), REREAD_DIR, FNO_NONE}, {K_CTRL('R'), SEARCH_BACK, FNO_NONE}, {K_CTRL('S'), SEARCH_FORW, FNO_NONE}, {-1, NO_OPERATION, FNO_NONE} }; static int NEAR dochdir4(path, raw) CONST char *path; int raw; { if (chdir4(path, raw, archivefile) < 0) { warning(-1, path); return(FNC_CANCEL); }
int OpenMenu(Widget *w, wMENU *m, int xr, int xl, int minWidth, int y) { if (!w || !m) return MENU_QUIT; if (!m->nItems || !m->items) return MENU_QUIT; SDL_Surface *scr = w->construct->scr; wTHEME *t = w->construct->theme; ListArgs *args = w->args; wITEM *itm; wMENU *menu; int x, l; SDL_Rect area; SDL_Surface *saveImage; Uint32 c = Darker(t->color1, 60); Uint32 cs1 = Darker(t->menus_c1, 15); // color selection args->cMenu = m; args->yItem = 0; args->cItem = 0; int dItems = min(args->dItems, m->nItems); if (!dItems) dItems = m->nItems; SDL_Rect clip; SDL_GetClipRect(scr, &clip); int b; int ok = ACTION_CONTINUE; // calcul de la hauteur int h = 10*dItems+2; while (h > 234) h-=10, dItems-=1; if (y+h > scr->h) y = scr->h - h; // calcul de la largeur int wd = 0; for (x=0; x < m->nItems; x++) { itm = m->items[x]; l = nSDL_GetStringWidth(t->menus_font1, itm->str); if (l > wd) wd = l; l = nSDL_GetStringWidth(t->menus_font2, itm->str); if (l > wd) wd = l; } wd += 10; if (m->nItems > dItems) wd += 7; // pour les scrollbars if (wd < minWidth) wd = minWidth; if (wd > scr->w) wd = scr->w; if (xr+wd > scr->w) { if (xl-wd > 0) xr = xl - wd; else xr = scr->w - wd; } // sauvegarde de l'image area = (SDL_Rect) {xr, y, wd, h}; saveImage = SDL_CreateRGBSurface(SDL_SWSURFACE, wd, h, 16, 0, 0, 0, 0); DrawSurface(scr, &area, saveImage, NULL); if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) { SDL_FreeSurface(saveImage); return ok; } do { // dessin !!! SDL_SetClipRect(scr, &area); DrawFillRect(scr, &area, t->menus_c1); DrawRect(scr, &area, c); for (x=0; x < dItems; x++) { itm = m->items[x + args->yItem]; if (x == args->cItem) DrawFillRectXY(scr, xr+1, y+1+10*x, wd-2, 10, cs1); if (itm->magicNumber == 1) { menu = (wMENU *) itm; if (wMenu_HasSelectedItemOrMenu(menu)) DrawClippedStr(scr, t->menus_font2, xr+2, y+2+10*x, menu->title); else DrawClippedStr(scr, t->menus_font1, xr+2, y+2+10*x, menu->title); DrawSurface(t->menus_right,NULL,scr, &(SDL_Rect){xr+wd - (m->nItems > dItems? 17:8), y+2+10*x, 5, 7}); } else { if (itm->isSelected) DrawClippedStr(scr, t->menus_font2, xr+2, y+2+10*x, itm->str); else DrawClippedStr(scr, t->menus_font1, xr+2, y+2+10*x, itm->str); } } if (m->nItems > dItems) DrawVScrollBar(scr, t, &area, 10*m->nItems+2, 10*args->yItem); SDL_SetClipRect(scr, &clip); // activation !!! itm = m->items[args->cItem + args->yItem]; ACTIVATION: SDL_Flip(scr); while ((any_key_pressed() && !K_CTRL()) || K_CLICK()); while (!any_key_pressed()); if (K_CLICK() || K_ENTER()) { if (K_ENTER() && args->maxSelected != 1) { ok = wExecCallback(w, SIGNAL_CLICK); break; } if (itm->magicNumber == 1) goto NEWMENU; if (args->maxSelected == 1) { if (args->nSelected) wMenu_DeselectAll(args->menu); wMenu_SelectItem(m, args->yItem + args->cItem); args->nSelected = 1; DrawSurface(saveImage, NULL, scr, &area); SDL_FreeSurface(saveImage); saveImage = NULL; ok = wExecCallback(w, K_CLICK() || K_ENTER()? SIGNAL_CLICK : SIGNAL_ACTION); break; } else if (args->maxSelected >= 0) { b = wMenu_IsSelected(m, args->yItem + args->cItem); if (!b && args->nSelected) if (args->nSelected == args->maxSelected) goto ACTIVATION; wMenu_SelectItem(m, args->yItem + args->cItem); if (b) args->nSelected--; else args->nSelected++; } if ((ok=wExecCallback(w, SIGNAL_CLICK)) != ACTION_CONTINUE) break; } else if (K_UP()) { if (!args->yItem && !args->cItem) { if (K_CTRL()) goto ACTIVATION; args->cItem = dItems-1; args->yItem = m->nItems-dItems; } else { if (args->cItem) args->cItem--; else args->yItem--; } if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) break; } else if (K_DOWN()) { if (args->yItem + args->cItem >= m->nItems-1) { if (K_CTRL()) goto ACTIVATION; args->cItem = 0; args->yItem = 0; } else { if (args->cItem < dItems-1) args->cItem++; else args->yItem++; } if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) break; } else if (K_RIGHT() && itm->magicNumber == 1) { NEWMENU:; int yI = args->yItem, cI = args->cItem; ok = OpenMenu(w, (wMENU *) itm, xr+wd-3, xr, minWidth, y+10*args->cItem); args->cMenu = m; args->yItem = yI; args->cItem = cI; if (K_ESC() || K_ENTER() || (K_CLICK() && args->maxSelected == 1) || ok != ACTION_CONTINUE) break; if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) break; } else if (K_LEFT()) break; } while (!K_ESC()); if (saveImage) { DrawSurface(saveImage, NULL, scr, &area); SDL_FreeSurface(saveImage); } return ok; }