static void InputHandler_KeyDown(void* obj, int key, bool was) { struct Screen* active; int idx; struct HotkeyData* hkey; String text; if (!was && InputHandler_SimulateMouse(key, true)) return; active = Gui_GetActiveScreen(); #ifndef CC_BUILD_WEB if (key == KEY_ESCAPE && active->Closable) { /* Don't want holding down escape to go in and out of pause menu */ if (!was) Gui_Close(active); return; } #endif if (InputHandler_IsShutdown(key)) { /* TODO: Do we need a separate exit function in Game class? */ Window_Close(); return; } else if (key == KeyBinds[KEYBIND_SCREENSHOT] && !was) { Game_ScreenshotRequested = true; return; } else if (Elem_HandlesKeyDown(active, key, was)) { return; } else if ((key == KEY_ESCAPE || key == KEY_PAUSE) && !active->HandlesAllInput) { #ifdef CC_BUILD_WEB /* Can't do this in KeyUp, because pressing escape without having */ /* explicitly disabled mouse lock means a KeyUp event isn't sent. */ /* But switching to pause screen disables mouse lock, causing a KeyUp */ /* event to be sent, triggering the active->Closable case which immediately /* closes the pause screen. Hence why the next KeyUp must be supressed. */ suppressEscape = true; #endif Gui_FreeActive(); Gui_SetActive(PauseScreen_MakeInstance()); return; } /* These should not be triggered multiple times when holding down */ if (was) return; if (InputHandler_HandleCoreKey(key)) { } else if (LocalPlayer_HandlesKey(key)) { } else { idx = Hotkeys_FindPartial(key); if (idx == -1) return; hkey = &HotkeysList[idx]; text = StringsBuffer_UNSAFE_Get(&HotkeysText, hkey->TextIndex); if (!hkey->StaysOpen) { Chat_Send(&text, false); } else if (!Gui_Active) { HUDScreen_OpenInput(Gui_HUD, &text); } } }
PyObject* Window_OnAction(Window *self, PyObject *args) { Action* action; if (!PyArg_ParseTuple(args, (char*)"O", &action)) return NULL; if(action->id == ACTION_PREVIOUS_MENU || action->id == ACTION_NAV_BACK) { Window_Close(self, args); } Py_INCREF(Py_None); return Py_None; }
void Window_Dealloc(Window* self) { GilSafeSingleLock lock(g_graphicsContext); if (self->bIsPythonWindow) { // first change to an existing window if (ACTIVE_WINDOW == self->iWindowId && !g_application.m_bStop) { if(g_windowManager.GetWindow(self->iOldWindowId)) { g_windowManager.ActivateWindow(self->iOldWindowId); } // old window does not exist anymore, switch to home else g_windowManager.ActivateWindow(WINDOW_HOME); } // no callbacks are possible any longer ((CGUIPythonWindowXML*)self->pWindow)->SetCallbackWindow(NULL, NULL); } else { // BUG: // This is an existing window, so no resources are free'd. Note that // THIS WILL FAIL for any controls newly created by python - they will // remain after the script ends. Ideally this would be remedied by // a flag in Control that specifies that it was python created - any python // created controls could then be removed + free'd from the window. // how this works with controlgroups though could be a bit tricky. } // and free our list of controls std::vector<Control*>::iterator it = self->vecControls.begin(); while (it != self->vecControls.end()) { Control* pControl = *it; // initialize control to zero pControl->pGUIControl = NULL; pControl->iControlId = 0; pControl->iParentId = 0; Py_DECREF(pControl); ++it; } if (self->bIsPythonWindow) { if (self->pWindow && g_windowManager.IsWindowVisible(self->iWindowId)) { // if window isn't closed - mark it to delete itself after deiniting // and trigger window closing if (self->bUsingXML) ((CGUIPythonWindowXML*)self->pWindow)->SetDestroyAfterDeinit(); else ((CGUIPythonWindow*)self->pWindow)->SetDestroyAfterDeinit(); Window_Close(self, NULL); } else g_windowManager.Delete(self->iWindowId); } lock.Leave(); self->vecControls.clear(); self->vecControls.~vector(); self->sFallBackPath.~string(); self->sXMLFileName.~string(); self->ob_type->tp_free((PyObject*)self); }
static void Find_OnCommand(HWND hwnd, int idCtl, HWND hwndCtl, UINT uNotifyCode) { LPEDITINTERFACE lpInterface = PCP_Edit_GetInterface(MDI_MyGetActive(TRUE)); switch (idCtl) { case IDCANCEL: Window_Close(hwnd); break; case IDOK: { Find_GetSettings(hwnd, s_bReplaceMode); s_ptCurrentPos = PCP_Edit_GetCursorPos(lpInterface); if (s_bReplaceMode) { EDITSEARCHINFO esi; if (!s_bFound) { s_ptFoundAt = s_ptCurrentPos; s_bFound = Find_DoHighlightText(lpInterface, hwnd); return; } PCP_Edit_GetSearchInfo(lpInterface, &esi); if (esi.nLastSearchLen == 0) { if (s_ptFoundAt.y + 1 < PCP_Edit_GetLineCount(lpInterface)) { s_ptFoundAt.x = 0; s_ptFoundAt.y++; } else { s_bFound = FALSE; return; } } else { s_ptFoundAt.x += 1; // FIXME: ?? } s_bFound = Find_DoHighlightText(lpInterface, hwnd); return; } if (!Find_FindText(hwnd, s_szSearchText, s_ptCurrentPos, TRUE)) { s_ptCurrentPos.x = 0; s_ptCurrentPos.y = 0; return; } if (!s_bReplaceMode) Window_Close(hwnd); } break; case IDC_BUTTON_REPLACE: { Find_GetSettings(hwnd, s_bReplaceMode); if (!s_bFound) { s_ptFoundAt = s_ptCurrentPos; s_bFound = Find_DoHighlightText(lpInterface); return; } s_bFound = Find_Replace_Imp(lpInterface); MRU_Write(_T("Find MRU"), s_szSearchText, g_MRUSettings.nFindMax); MRU_Write(_T("Replace MRU"), s_szReplaceText, g_MRUSettings.nReplaceMax); } break; case IDC_BUTTON_REPLACEALL: { HCURSOR hOldCursor; SetCapture(g_hwndMain); hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); Window_SetRedraw(lpew->hwnd, FALSE); s_ptCurrentPos.x = 0; s_ptCurrentPos.y = 0; Find_GetSettings(hwnd, s_bReplaceMode); if (!s_bFound) { s_ptFoundAt = s_ptCurrentPos; s_bFound = Find_DoHighlightText(lpInterface); } while (s_bFound) s_bFound = Find_Replace_Imp(lpInterface); Window_SetRedraw(lpew->hwnd, TRUE); RedrawWindow(lpew->hwnd, NULL, NULL, RDW_INVALIDATE); SetCursor(hOldCursor); ReleaseCapture(); MRU_Write(_T("Find MRU"), s_szSearchText, g_MRUSettings.nFindMax); MRU_Write(_T("Replace MRU"), s_szReplaceText, g_MRUSettings.nReplaceMax); } break; case IDC_COMBO_FIND: { HWND hwndFindNext = GetDlgItem(hwnd, IDOK); if (uNotifyCode == CBN_EDITCHANGE) { BOOL bText = Window_GetDlgItemTextLength(hwnd, IDC_COMBO_FIND); if (bText) EnableWindow(hwndFindNext, TRUE); else EnableWindow(hwndFindNext, FALSE); } else if (uNotifyCode == CBN_SELENDOK) { EnableWindow(hwndFindNext, TRUE); } } break; case IDC_CHECK_REGEXP: /* * if conducting a regular expression search we need to disable * some other options since they are of no relevance to such a * search */ if (IsDlgButtonChecked(hwnd, IDC_CHECK_REGEXP)) { CheckDlgButton(hwnd, IDC_CHECK_WHOLEWORD, BST_UNCHECKED); Window_EnableDlgItem(hwnd, IDC_CHECK_WHOLEWORD, FALSE); g_FindSettings.bWholeWords = FALSE; } else { Window_EnableDlgItem(hwnd, IDC_CHECK_WHOLEWORD, TRUE); } break; case IDC_RADIO_DIRECTION_UP: if (s_bReplaceMode) { /* * search context == selection * in replace mode can't allow finding next (IDOK) * or replacing (IDC_BUTTON_REPLACE) */ Window_EnableDlgItem(hwnd, IDOK, FALSE); Window_EnableDlgItem(hwnd, IDC_BUTTON_REPLACE, FALSE); } break; case IDC_RADIO_DIRECTION_DOWN: if (s_bReplaceMode) { /* * search context == whole file * in replace mode finding next (IDOK) and replacing * (IDC_BUTTON_REPLACE) may have been disabled by * settings search context to selection. Fix this by * re-enabling the buttons */ Window_EnableDlgItem(hwnd, IDOK, TRUE); Window_EnableDlgItem(hwnd, IDC_BUTTON_REPLACE, TRUE); } break; } }
void File_Open(LPTSTR pszFile, int nLineFeedType) { MDICREATESTRUCT mcs; HWND hwndChild, hwndEdit, hwndPrev; HCURSOR hOldCursor; // LPEDITVIEW lpew; FILEINFO fi; int i; // FIXME: TEMP INITSTRUCT(fi, FALSE); SetCapture(g_hwndMain); hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); EnumChildWindows(g_hwndMDIClient, FindOpenFileEnumProc, (LPARAM)pszFile); if (s_bOpen) { HWND hwnd; TCHAR szMsg[MAX_PATH + 30]; s_bOpen = FALSE; hwnd = Main_GetFileInfoByFileName(pszFile, &fi); ASSERT(!(fi.dwFileType & FI_TYPE_MASK_EDIT)); MDI_Activate(g_hwndMDIClient, hwnd); // FIXME: Should only be done if modified _stprintf(szMsg, String_LoadString(IDS_FORMAT_FILE_ALREADYOPEN), pszFile); if (MessageBox(g_hwndMain, szMsg, g_szAppName, MB_YESNO | MB_ICONQUESTION) == IDYES) { File_ReloadFile(pszFile); } goto err_return; } hwndPrev = MDI_MyGetActive(FALSE); mcs.szTitle = pszFile; mcs.szClass = g_szEditChild; // g_szHexChild mcs.hOwner = g_hInstance; mcs.x = mcs.cx = CW_USEDEFAULT; mcs.y = mcs.cy = CW_USEDEFAULT; mcs.style = MDIS_ALLCHILDSTYLES | WS_CLIPCHILDREN; // a messy way of setting the file to open for the edit control if (String_Equal(pszFile, _T("Edit"), TRUE)) { s_nNumEdits++; fi.dwFileType |= FI_TYPE_MASK_EDIT; _stprintf(fi.szFileName, _T("Edit%d"), s_nNumEdits); } else { ASSERT(Path_FileExists(pszFile)); fi.dwFileType = FI_TYPE_TEXT; _tcscpy(fi.szFileName, pszFile); } mcs.lParam = (LPARAM)&fi; if ((!IsWindow(hwndPrev) && g_WindowSettings.nMDIWinState == MDISTATE_MAXIMIZED) || (IsWindow(hwndPrev) && IsMaximized(hwndPrev))) { mcs.style |= WS_MAXIMIZE; g_WindowSettings.nMDIWinState = MDISTATE_MAXIMIZED; } hwndChild = MDI_Create(g_hwndMDIClient, &mcs); ASSERT(hwndChild != NULL); hwndEdit = GetDlgItem(hwndChild, IDC_EDIT_MDICHILD); if ((_tcscmp(pszFile, _T("Edit"))) == 0) { File_Addify(hwndChild, hwndEdit, fi.szFileName); goto normal_return; } else { TCHAR szText[MAX_PATH]; TC_ITEM tci; FILEINFO fi; tci.mask = TCIF_TEXT | TCIF_PARAM; tci.pszText = szText; tci.cchTextMax = MAX_PATH; if (TabCtrl_GetItem(g_hwndTabWindowBar, 0, &tci)) { ASSERT(IsWindow((HWND)tci.lParam)); Main_GetFileInfo((HWND)tci.lParam, &fi); if ((fi.dwFileType & FI_TYPE_MASK_FIRST) && !EditView_GetModify(GetDlgItem((HWND)tci.lParam, IDC_EDIT_MDICHILD))) { Window_Close((HWND)tci.lParam); } } } File_Addify(hwndChild, hwndEdit, pszFile); FileNotify_AddFile(&s_fns, pszFile, FN_NOTIFY_DEFAULT); FileNotify_StartMonitoring(&s_fns); MRU_Write(_T("File MRU"), pszFile, g_MRUSettings.nFileMax); for (i = IDM_RECENTFILES; DeleteMenu(g_hMenuRecentFiles, i, MF_BYCOMMAND); i++) ; /* empty body */ MRU_SetMenu(g_hMenuRecentFiles, _T("File MRU"), g_MRUSettings.nFileMax, IDM_RECENTFILES); normal_return: // lpew = MDI_GetEditView(NULL); /// TextBuffer_SetCRLFMode(lpew->lpes, (nLineFeedType == CRLF_STYLE_AUTOMATIC) ? TextBuffer_GetCRLFMode(lpew->lpes) : nLineFeedType); // EditChild_SetLineFeed(lpew->hwnd, TextBuffer_GetCRLFMode(lpew->lpes)); err_return: SetCursor(hOldCursor); ReleaseCapture(); }
void WorldGL::Input_ProcessEvent( const SDL_Event & Event ) { m_Events.push_back (Event); switch (Event.type) { case (SDL_KEYDOWN): { if (m_KeyUpdateAmount > KEY_UPDATE_QUEUE_MAX) Debug::Warning("WorldGL::Input_ProcessEvent | Unable to process key event; too many event received at once. (m_KeyUpdateAmount > KEY_UPDATE_QUEUE_MAX"); SDLKey key = Event.key.keysym.sym; m_InputContainer.m_KeyState [key].active = true; m_InputContainer.m_KeyState [key].down = true; m_KeyUpdateList [m_KeyUpdateAmount].m_Key = key; m_KeyUpdateList [m_KeyUpdateAmount].m_Update = KeyUpdate::UPDATE_DOWN; m_KeyUpdateAmount++; } break; case (SDL_KEYUP): { SDLKey key = Event.key.keysym.sym; m_InputContainer.m_KeyState [key].active = false; m_InputContainer.m_KeyState [key].up = true; m_KeyUpdateList [m_KeyUpdateAmount].m_Key = key; m_KeyUpdateList [m_KeyUpdateAmount].m_Update = KeyUpdate::UPDATE_UP; m_KeyUpdateAmount++; } break; case (SDL_MOUSEMOTION): { m_InputContainer.m_MouseX = Event.motion.x; m_InputContainer.m_MouseY = Event.motion.y; } break; case (SDL_MOUSEBUTTONDOWN): { switch (Event.button.button) { case (SDL_BUTTON_LEFT): m_InputContainer.m_LeftMouseButton.active = true; m_InputContainer.m_LeftMouseButton.down = true; break; case (SDL_BUTTON_MIDDLE): m_InputContainer.m_MiddleMouseButton.active = true; m_InputContainer.m_MiddleMouseButton.down = true; break; case (SDL_BUTTON_RIGHT): m_InputContainer.m_RightMouseButton.active = true; m_InputContainer.m_RightMouseButton.down = true; break; case (SDL_BUTTON_WHEELDOWN): m_Input_ScrollAmount--; break; } break; } case (SDL_MOUSEBUTTONUP): { switch (Event.button.button) { // TODO: Implement access for press/release events on mouse buttons case (SDL_BUTTON_LEFT): m_InputContainer.m_LeftMouseButton.active = false; m_InputContainer.m_LeftMouseButton.up = true; break; case (SDL_BUTTON_MIDDLE): m_InputContainer.m_MiddleMouseButton.active = false; m_InputContainer.m_MiddleMouseButton.up = true; break; case (SDL_BUTTON_RIGHT): m_InputContainer.m_RightMouseButton.active = false; m_InputContainer.m_RightMouseButton.up = true; break; case (SDL_BUTTON_WHEELUP): m_Input_ScrollAmount++; break; } break; } case (SDL_QUIT): { Window_Close (); break; } } }