void System::completeKeyword(int index) { if (get_focus_edit() && isEditing()) { const char *help = get_focus_edit()->completeKeyword(index); if (help) { runtime->getOutput()->setStatus(help); runtime->getOutput()->redraw(); } } }
void System::handleEvent(MAEvent &event) { switch (event.type) { case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED: if (_systemMenu != NULL) { handleMenu(event); } else if (isRunning()) { if (!form_ui::optionSelected(event.optionsBoxButtonIndex)) { dev_clrkb(); dev_pushkey(event.optionsBoxButtonIndex); } } break; case EVENT_TYPE_SCREEN_CHANGED: resize(); break; case EVENT_TYPE_POINTER_PRESSED: _touchX = _touchCurX = event.point.x; _touchY = _touchCurY = event.point.y; if (_output->overMenu(_touchX, _touchY)) { showMenu(); } else { dev_pushkey(SB_KEY_MK_PUSH); _buttonPressed = _output->pointerTouchEvent(event); showCursor(get_focus_edit() != NULL ? kIBeam : kHand); } break; case EVENT_TYPE_POINTER_DRAGGED: _touchCurX = event.point.x; _touchCurY = event.point.y; _output->pointerMoveEvent(event); if (_output->hasHover() || _output->overMenu(_touchCurX, _touchCurY)) { showCursor(kHand); } else if (_output->hasMenu()) { showCursor(kArrow); } else if (get_focus_edit()) { showCursor(kIBeam); } else { showCursor(kArrow); } break; case EVENT_TYPE_POINTER_RELEASED: _buttonPressed = false; _touchX = _touchY = _touchCurX = _touchCurY = -1; _output->pointerReleaseEvent(event); showCursor(get_focus_edit() != NULL ? kIBeam : kArrow); break; default: // no event _output->flush(false); break; } }
void System::showMenu() { logEntered(); if (!_menuActive) { _menuActive = true; char buffer[64]; if (_systemMenu != NULL) { delete [] _systemMenu; } StringList *items = new StringList(); int completions = 0; if (get_focus_edit() && isEditing()) { completions = get_focus_edit()->getCompletions(items, MAX_COMPLETIONS); } _systemMenu = new int[MENU_SIZE + completions]; int index = 0; if (get_focus_edit() != NULL) { if (isEditing()) { items->add(new String("Undo")); items->add(new String("Redo")); items->add(new String("Cut")); items->add(new String("Copy")); items->add(new String("Paste")); items->add(new String("Select All")); items->add(new String("Save")); items->add(new String("Run")); #if defined(_SDL) items->add(new String("Debug")); items->add(new String("Show Output")); #endif items->add(new String("Help")); for (int i = 0; i < completions; i++) { _systemMenu[index++] = MENU_COMPLETION_0 + i; } _systemMenu[index++] = MENU_UNDO; _systemMenu[index++] = MENU_REDO; _systemMenu[index++] = MENU_CUT; _systemMenu[index++] = MENU_COPY; _systemMenu[index++] = MENU_PASTE; _systemMenu[index++] = MENU_SELECT_ALL; _systemMenu[index++] = MENU_SAVE; _systemMenu[index++] = MENU_RUN; #if defined(_SDL) _systemMenu[index++] = MENU_DEBUG; _systemMenu[index++] = MENU_OUTPUT; #endif _systemMenu[index++] = MENU_HELP; } else if (isRunning()) { items->add(new String("Cut")); items->add(new String("Copy")); items->add(new String("Paste")); items->add(new String("Select All")); _systemMenu[index++] = MENU_CUT; _systemMenu[index++] = MENU_COPY; _systemMenu[index++] = MENU_PASTE; _systemMenu[index++] = MENU_SELECT_ALL; } #if defined(_SDL) items->add(new String("Back")); _systemMenu[index++] = MENU_BACK; #else items->add(new String("Show keypad")); _systemMenu[index++] = MENU_KEYPAD; if (!isEditing()) { bool controlMode = get_focus_edit()->getControlMode(); sprintf(buffer, "Control Mode [%s]", (controlMode ? "ON" : "OFF")); items->add(new String(buffer)); _systemMenu[index++] = MENU_CTRL_MODE; } #endif } else { items->add(new String("Console")); items->add(new String("View source")); _systemMenu[index++] = MENU_CONSOLE; _systemMenu[index++] = MENU_SOURCE; if (!isEditing()) { items->add(new String("Restart")); _systemMenu[index++] = MENU_RESTART; } #if !defined(_SDL) items->add(new String("Show keypad")); _systemMenu[index++] = MENU_KEYPAD; #endif items->add(new String("Screenshot")); _systemMenu[index++] = MENU_SCREENSHOT; if (_mainBas) { sprintf(buffer, "Font Size %d%%", _fontScale - FONT_SCALE_INTERVAL); items->add(new String(buffer)); sprintf(buffer, "Font Size %d%%", _fontScale + FONT_SCALE_INTERVAL); items->add(new String(buffer)); _systemMenu[index++] = MENU_ZOOM_UP; _systemMenu[index++] = MENU_ZOOM_DN; sprintf(buffer, "Editor [%s]", opt_ide == IDE_NONE ? "OFF" : "ON"); items->add(new String(buffer)); _systemMenu[index++] = MENU_EDITMODE; } #if !defined(_SDL) if (!_mainBas && !_activeFile.empty()) { items->add(new String("Desktop Shortcut")); items->add(new String("Share")); _systemMenu[index++] = MENU_SHORTCUT; _systemMenu[index++] = MENU_SHARE; } #endif sprintf(buffer, "Audio [%s]", (opt_mute_audio ? "OFF" : "ON")); items->add(new String(buffer)); _systemMenu[index++] = MENU_AUDIO; #if defined(_SDL) items->add(new String("Back")); _systemMenu[index++] = MENU_BACK; #endif } optionsBox(items); delete items; _menuActive = false; } }
void System::handleMenu(MAEvent &event) { int menuId = event.optionsBoxButtonIndex; int fontSize = _output->getFontSize(); int menuItem = _systemMenu[menuId]; delete [] _systemMenu; _systemMenu = NULL; switch (menuItem) { case MENU_SOURCE: showSystemScreen(true); break; case MENU_CONSOLE: showSystemScreen(false); break; case MENU_KEYPAD: maShowVirtualKeyboard(); break; case MENU_RESTART: setRestart(); break; case MENU_BACK: setBack(); break; case MENU_ZOOM_UP: if (_fontScale > FONT_MIN) { _fontScale -= FONT_SCALE_INTERVAL; fontSize = (_initialFontSize * _fontScale / 100); } break; case MENU_ZOOM_DN: if (_fontScale < FONT_MAX) { _fontScale += FONT_SCALE_INTERVAL; fontSize = (_initialFontSize * _fontScale / 100); } break; case MENU_COPY: case MENU_CUT: if (get_focus_edit() != NULL) { char *text = get_focus_edit()->copy(menuItem == MENU_CUT); if (text) { setClipboardText(text); free(text); _output->redraw(); } } break; case MENU_PASTE: if (get_focus_edit() != NULL) { char *text = getClipboardText(); get_focus_edit()->paste(text); _output->redraw(); free(text); } break; case MENU_SELECT_ALL: if (get_focus_edit() != NULL) { get_focus_edit()->selectAll(); _output->redraw(); } break; case MENU_CTRL_MODE: if (get_focus_edit() != NULL) { bool controlMode = get_focus_edit()->getControlMode(); get_focus_edit()->setControlMode(!controlMode); } break; case MENU_EDITMODE: opt_ide = (opt_ide == IDE_NONE ? IDE_INTERNAL : IDE_NONE); break; case MENU_AUDIO: opt_mute_audio = !opt_mute_audio; break; case MENU_SCREENSHOT: ::screen_dump(); break; case MENU_UNDO: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_CTRL('z'); break; case MENU_REDO: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_CTRL('y'); break; case MENU_SAVE: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_CTRL('s'); break; case MENU_RUN: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_F(9); break; case MENU_DEBUG: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_F(5); break; case MENU_OUTPUT: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_CTRL('o'); break; case MENU_HELP: event.type = EVENT_TYPE_KEY_PRESSED; event.key = SB_KEY_F(1); break; case MENU_SHORTCUT: if (!_activeFile.empty()) { addShortcut(_activeFile.c_str()); } break; case MENU_SHARE: if (!_activeFile.empty()) { share(_activeFile.c_str()); } break; case MENU_COMPLETION_0: completeKeyword(0); break; case MENU_COMPLETION_1: completeKeyword(1); break; case MENU_COMPLETION_2: completeKeyword(2); break; case MENU_COMPLETION_3: completeKeyword(3); break; } if (fontSize != _output->getFontSize()) { // restart the shell _output->setFontSize(fontSize); setRestart(); } if (!isRunning()) { _output->flush(true); } }
void Runtime::pollEvents(bool blocking) { if (isActive() && !isRestart()) { SDL_Event ev; SDL_Keymod mod; if (blocking ? SDL_WaitEvent(&ev) : SDL_PollEvent(&ev)) { MAEvent *maEvent = NULL; switch (ev.type) { case SDL_TEXTINPUT: // pre-transformed/composted text mod = SDL_GetModState(); if (!mod || (mod & (KMOD_SHIFT|KMOD_CAPS))) { // ALT + CTRL keys handled in SDL_KEYDOWN for (int i = 0; ev.text.text[i] != 0; i++) { MAEvent *keyEvent = new MAEvent(); keyEvent->type = EVENT_TYPE_KEY_PRESSED; keyEvent->key = ev.text.text[i]; keyEvent->nativeKey = 0; pushEvent(keyEvent); } } break; case SDL_QUIT: setExit(true); break; case SDL_KEYDOWN: if (!isEditing() && ev.key.keysym.sym == SDLK_c && (ev.key.keysym.mod & KMOD_CTRL)) { setExit(true); } else if (ev.key.keysym.sym == SDLK_m && (ev.key.keysym.mod & KMOD_CTRL)) { showMenu(); } else if (ev.key.keysym.sym == SDLK_b && (ev.key.keysym.mod & KMOD_CTRL)) { setBack(); } else if (ev.key.keysym.sym == SDLK_BACKSPACE && get_focus_edit() == NULL && ((ev.key.keysym.mod & KMOD_CTRL) || !isRunning())) { setBack(); } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEUP && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(true, true); } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEDOWN && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(false, true); } else if (!isEditing() && ev.key.keysym.sym == SDLK_UP && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(true, false); } else if (!isEditing() && ev.key.keysym.sym == SDLK_DOWN && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(false, false); } else if (ev.key.keysym.sym == SDLK_p && (ev.key.keysym.mod & KMOD_CTRL)) { ::screen_dump(); } else { int lenMap = sizeof(keymap) / sizeof(keymap[0]); for (int i = 0; i < lenMap; i++) { if (ev.key.keysym.sym == keymap[i][0]) { maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_KEY_PRESSED; maEvent->key = keymap[i][1]; maEvent->nativeKey = ev.key.keysym.mod; break; } } if (maEvent == NULL && ((ev.key.keysym.sym >= SDLK_KP_1 && ev.key.keysym.sym <= SDLK_KP_9) || ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym != SDLK_LSHIFT && ev.key.keysym.sym != SDLK_RSHIFT && ev.key.keysym.sym != SDLK_LCTRL && ev.key.keysym.sym != SDLK_RCTRL) || (ev.key.keysym.mod & KMOD_ALT))) { maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_KEY_PRESSED; maEvent->key = ev.key.keysym.sym; maEvent->nativeKey = ev.key.keysym.mod; } } break; case SDL_MOUSEBUTTONDOWN: if (ev.button.button == SDL_BUTTON_RIGHT) { _menuX = ev.motion.x; _menuY = ev.motion.y; showMenu(); } else if (ev.motion.x != 0 && ev.motion.y != 0) { // avoid phantom down message when launching in windows maEvent = getMotionEvent(EVENT_TYPE_POINTER_PRESSED, &ev); } break; case SDL_MOUSEMOTION: maEvent = getMotionEvent(EVENT_TYPE_POINTER_DRAGGED, &ev); break; case SDL_MOUSEBUTTONUP: SDL_SetCursor(_cursorArrow); maEvent = getMotionEvent(EVENT_TYPE_POINTER_RELEASED, &ev); break; case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: SDL_SetModState(KMOD_NONE); break; case SDL_WINDOWEVENT_RESIZED: onResize(ev.window.data1, ev.window.data2); break; case SDL_WINDOWEVENT_EXPOSED: _graphics->redraw(); break; case SDL_WINDOWEVENT_LEAVE: _output->removeHover(); break; } break; case SDL_DROPFILE: setLoadPath(ev.drop.file); setExit(false); SDL_free(ev.drop.file); break; case SDL_MOUSEWHEEL: if (!_output->scroll(ev.wheel.y == 1, false)) { maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_KEY_PRESSED; maEvent->key = ev.wheel.y == 1 ? SB_KEY_UP : SB_KEY_DN; maEvent->nativeKey = KMOD_CTRL; } break; } if (maEvent != NULL) { pushEvent(maEvent); } } } }