//Opens a file void MenuOpen(list *FileBuffer, WINDOW *my_menu_win){ char str[MAXCHAR]; int i = 0, c; mvwprintw(my_menu_win, LINES - 3, 0 , "Enter the name of the file: "); int y = LINES - 2, x = 0; while((c = wgetch(my_menu_win)) != 10){ switch(c){ case KEY_BACKSPACE: case 8: if (x > 0){ x--; wmove(my_menu_win, y, x); i--; } mvwprintw(my_menu_win, y, x, " "); str[i] = ' '; break; default: str[i] = c; i++; mvwprintw(my_menu_win, y, x, "%c", c); x++; break; } } str[i] = '\0'; OpenFile(FileBuffer, str); MenuEdit(FileBuffer, my_menu_win); }
bool GraphicsWindow::KeyDown(int c) { if(c == '\b') { // Treat backspace identically to escape. MenuEdit(MNU_UNSELECT_ALL); return true; } return false; }
void GraphicsWindow::MouseRightUp(double x, double y) { SS.extraLine.draw = false; InvalidateGraphics(); // Don't show a context menu if the user is right-clicking the toolbar, // or if they are finishing a pan. if(ToolbarMouseMoved((int)x, (int)y)) return; if(orig.startedMoving) return; if(context.active) return; if(pending.operation == DRAGGING_NEW_LINE_POINT || pending.operation == DRAGGING_NEW_CUBIC_POINT) { // Special case; use a right click to stop drawing lines, since // a left click would draw another one. This is quicker and more // intuitive than hitting escape. Likewise for new cubic segments. ClearPending(); return; } context.active = true; if(!hover.IsEmpty()) { MakeSelected(&hover); SS.ScheduleShowTW(); } GroupSelection(); bool itemsSelected = (gs.n > 0 || gs.constraints > 0); if(itemsSelected) { if(gs.stylables > 0) { ContextMenuListStyles(); AddContextMenuItem("Assign to Style", CONTEXT_SUBMENU); } if(gs.n + gs.constraints == 1) { AddContextMenuItem("Group Info", CMNU_GROUP_INFO); } if(gs.n + gs.constraints == 1 && gs.stylables == 1) { AddContextMenuItem("Style Info", CMNU_STYLE_INFO); } if(gs.withEndpoints > 0) { AddContextMenuItem("Select Edge Chain", CMNU_SELECT_CHAIN); } if(gs.constraints == 1 && gs.n == 0) { Constraint *c = SK.GetConstraint(gs.constraint[0]); if(c->HasLabel() && c->type != Constraint::COMMENT) { AddContextMenuItem("Toggle Reference Dimension", CMNU_REFERENCE_DIM); } if(c->type == Constraint::ANGLE || c->type == Constraint::EQUAL_ANGLE) { AddContextMenuItem("Other Supplementary Angle", CMNU_OTHER_ANGLE); } } if(gs.comments > 0 || gs.points > 0) { AddContextMenuItem("Snap to Grid", CMNU_SNAP_TO_GRID); } if(gs.points == 1) { Entity *p = SK.GetEntity(gs.point[0]); Constraint *c; IdList<Constraint,hConstraint> *lc = &(SK.constraint); for(c = lc->First(); c; c = lc->NextAfter(c)) { if(c->type != Constraint::POINTS_COINCIDENT) continue; if(c->ptA.v == p->h.v || c->ptB.v == p->h.v) { break; } } if(c) { AddContextMenuItem("Delete Point-Coincident Constraint", CMNU_DEL_COINCIDENT); } } AddContextMenuItem(NULL, CONTEXT_SEPARATOR); if(LockedInWorkplane()) { AddContextMenuItem("Cut", CMNU_CUT_SEL); AddContextMenuItem("Copy", CMNU_COPY_SEL); } } if(SS.clipboard.r.n > 0 && LockedInWorkplane()) { AddContextMenuItem("Paste", CMNU_PASTE_SEL); } if(itemsSelected) { AddContextMenuItem("Delete", CMNU_DELETE_SEL); AddContextMenuItem(NULL, CONTEXT_SEPARATOR); AddContextMenuItem("Unselect All", CMNU_UNSELECT_ALL); } // If only one item is selected, then it must be the one that we just // selected from the hovered item; in which case unselect all and hovered // are equivalent. if(!hover.IsEmpty() && selection.n > 1) { AddContextMenuItem("Unselect Hovered", CMNU_UNSELECT_HOVERED); } int ret = ShowContextMenu(); switch(ret) { case CMNU_UNSELECT_ALL: MenuEdit(MNU_UNSELECT_ALL); break; case CMNU_UNSELECT_HOVERED: if(!hover.IsEmpty()) { MakeUnselected(&hover, true); } break; case CMNU_SELECT_CHAIN: MenuEdit(MNU_SELECT_CHAIN); break; case CMNU_CUT_SEL: MenuClipboard(MNU_CUT); break; case CMNU_COPY_SEL: MenuClipboard(MNU_COPY); break; case CMNU_PASTE_SEL: MenuClipboard(MNU_PASTE); break; case CMNU_DELETE_SEL: MenuClipboard(MNU_DELETE); break; case CMNU_REFERENCE_DIM: Constraint::MenuConstrain(MNU_REFERENCE); break; case CMNU_OTHER_ANGLE: Constraint::MenuConstrain(MNU_OTHER_ANGLE); break; case CMNU_DEL_COINCIDENT: { SS.UndoRemember(); if(!gs.point[0].v) break; Entity *p = SK.GetEntity(gs.point[0]); if(!p->IsPoint()) break; SK.constraint.ClearTags(); Constraint *c; for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) { if(c->type != Constraint::POINTS_COINCIDENT) continue; if(c->ptA.v == p->h.v || c->ptB.v == p->h.v) { c->tag = 1; } } SK.constraint.RemoveTagged(); ClearSelection(); break; } case CMNU_SNAP_TO_GRID: MenuEdit(MNU_SNAP_TO_GRID); break; case CMNU_GROUP_INFO: { hGroup hg; if(gs.entities == 1) { hg = SK.GetEntity(gs.entity[0])->group; } else if(gs.points == 1) { hg = SK.GetEntity(gs.point[0])->group; } else if(gs.constraints == 1) { hg = SK.GetConstraint(gs.constraint[0])->group; } else { break; } ClearSelection(); SS.TW.GoToScreen(TextWindow::SCREEN_GROUP_INFO); SS.TW.shown.group = hg; SS.ScheduleShowTW(); break; } case CMNU_STYLE_INFO: { hStyle hs; if(gs.entities == 1) { hs = Style::ForEntity(gs.entity[0]); } else if(gs.points == 1) { hs = Style::ForEntity(gs.point[0]); } else if(gs.constraints == 1) { hs = SK.GetConstraint(gs.constraint[0])->disp.style; if(!hs.v) hs.v = Style::CONSTRAINT; } else { break; } ClearSelection(); SS.TW.GoToScreen(TextWindow::SCREEN_STYLE_INFO); SS.TW.shown.style = hs; SS.ScheduleShowTW(); break; } case CMNU_NEW_CUSTOM_STYLE: { uint32_t v = Style::CreateCustomStyle(); Style::AssignSelectionToStyle(v); break; } case CMNU_NO_STYLE: Style::AssignSelectionToStyle(0); break; default: if(ret >= CMNU_FIRST_STYLE) { Style::AssignSelectionToStyle(ret - CMNU_FIRST_STYLE); } else { // otherwise it was cancelled, so do nothing contextMenuCancelTime = GetMilliseconds(); } break; } context.active = false; SS.ScheduleShowTW(); }
int main(){ WINDOW *my_win, *menu_win, *my_menu_win; ITEM **my_items; MENU *my_menu; list *FileBuffer; int height, width, startx, starty, exit = 0; int highlight = 1; int ch, c, choice = 0, i, j; char str[81]; FileBuffer = (list *)malloc(sizeof(list)); if (FileBuffer == NULL) return; InitialiseBuffer(FileBuffer); initscr(); clear(); noecho(); cbreak(); start_color(); /*Checking whether the terminal supports colors*/ if (has_colors() == FALSE){ endwin(); printf("Your terminal does not support colors\n"); } keypad(stdscr, TRUE); height = 3; width = 10; starty = (LINES - height)/2; startx = (COLS - width) / 2; refresh(); my_win = Create_NewWindow(height, width, starty, startx); mvwhline(my_win, 5, 1, ACS_HLINE, width - 1); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK); /* Create items */ my_items = (ITEM **)calloc(nchoices, sizeof(ITEM *)); for(i = 0; i < nchoices; ++i) my_items[i] = new_item(menu_options[i], menu_options[i]); /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Set menu option not to show the description */ menu_opts_off(my_menu, O_SHOWDESC); /* Create the window to be associated with the menu */ my_menu_win = newwin(0, 0, 0, 0); keypad(my_menu_win, TRUE); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 0, 0, 0, 0)); set_menu_format(my_menu, 1, 6); set_menu_mark(my_menu, " * "); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); i = 0; mvwhline(my_menu_win, 1, 0, ACS_HLINE, COLS); mvwprintw(my_menu_win, LINES - 1, 0, "Press F3 to go to the menu, F6 to exit", c); while(1){ choice = ToggleMenu(my_menu_win, my_menu, i); i = choice; switch(choice){ case 0: MenuOpen(FileBuffer, my_menu_win); break; case 1: MenuNew(FileBuffer, my_menu_win, my_menu); break; case 2: MenuSave(FileBuffer, my_menu_win); break; case 3: MenuSaveAs(FileBuffer, my_menu_win); break; case 4: MenuEdit(FileBuffer, my_menu_win); break; case 5: MenuExit(FileBuffer, my_menu_win); exit = 1; break; default: break; } if (exit) break; } /*Assertion: the user wants to exit the program*/ /* Unpost and free all the memory taken up */ unpost_menu(my_menu); free_menu(my_menu); for(j = 0; j < nchoices; ++j) free_item(my_items[j]); clrtoeol(); refresh(); /*Ending curses mode*/ endwin(); return 0; }