VOID NTAPI ConDrvDeleteConsole(IN PCONSOLE Console) { DPRINT("ConDrvDeleteConsole(0x%p)\n", Console); /* * Forbid validation of any console by other threads * during the deletion of this console. */ ConDrvLockConsoleListExclusive(); /* * If the console is already being destroyed, i.e. not running * or finishing to be initialized, just return. */ if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE) && !ConDrvValidateConsoleUnsafe(Console, CONSOLE_INITIALIZING, TRUE)) { /* Unlock the console list and return */ ConDrvUnlockConsoleList(); return; } /* * We are about to be destroyed. Signal it to other people * so that they can terminate what they are doing, and that * they cannot longer validate the console. */ Console->State = CONSOLE_TERMINATING; /* * Allow other threads to finish their job: basically, unlock * all other calls to EnterCriticalSection(&Console->Lock); by * ConDrvValidateConsoleUnsafe functions so that they just see * that we are not in CONSOLE_RUNNING state anymore, or unlock * other concurrent calls to ConDrvDeleteConsole so that they * can see that we are in fact already deleting the console. */ LeaveCriticalSection(&Console->Lock); ConDrvUnlockConsoleList(); /* Deregister the terminal */ DPRINT("Deregister terminal\n"); ConDrvDetachTerminal(Console); DPRINT("Terminal deregistered\n"); /*** * Check that the console is in terminating state before continuing * (the cleanup code must not change the state of the console... * ...unless to cancel console deletion ?). ***/ ConDrvLockConsoleListExclusive(); if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_TERMINATING, TRUE)) { ConDrvUnlockConsoleList(); return; } /* We are now in destruction */ Console->State = CONSOLE_IN_DESTRUCTION; /* We really delete the console. Reset the count to be sure. */ Console->ReferenceCount = 0; /* Remove the console from the list */ RemoveConsole(Console); /* Delete the last screen buffer */ ConDrvDeleteScreenBuffer(Console->ActiveBuffer); Console->ActiveBuffer = NULL; if (!IsListEmpty(&Console->BufferList)) { /***ConDrvUnlockConsoleList();***/ ASSERTMSG("BUGBUGBUG!! screen buffer list not empty\n", FALSE); } /* Deinitialize the input buffer */ ConDrvDeinitInputBuffer(Console); if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent); DPRINT("ConDrvDeleteConsole - Unlocking\n"); LeaveCriticalSection(&Console->Lock); DPRINT("ConDrvDeleteConsole - Destroying lock\n"); DeleteCriticalSection(&Console->Lock); DPRINT("ConDrvDeleteConsole - Lock destroyed ; freeing console\n"); ConsoleFreeHeap(Console); DPRINT("ConDrvDeleteConsole - Console destroyed\n"); /* Unlock the console list and return */ ConDrvUnlockConsoleList(); }
LRESULT FAR PASCAL WndProc( HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { DWORD dwImmRet = 0; // return value of ImmSrvProcessKey() try { switch (Message) { case CONIME_CREATE: DBGPRINT(("CONIME: CONIME_CREATE: Console Handle=%08x\n", wParam)); return InsertNewConsole(hWnd,(HANDLE)wParam,(HWND)lParam); case CONIME_DESTROY: DBGPRINT(("CONIME: CONIME_DESTROY: Console Handle=%08x\n", wParam)); return RemoveConsole(hWnd, (HANDLE)wParam); case CONIME_SETFOCUS: DBGPRINT(("CONIME: CONIME_SETFOCUS: Console Handle=%08x\n", wParam)); return ConsoleSetFocus(hWnd, (HANDLE)wParam, (HKL)lParam); case CONIME_KILLFOCUS: DBGPRINT(("CONIME: CONIME_KILLFOCUS: Console Handle=%08x\n", wParam)); return ConsoleKillFocus(hWnd, (HANDLE)wParam); case CONIME_GET_NLSMODE: DBGPRINT(("CONIME: CONIME_GET_NLSMODE: Console Handle=%08x\n", wParam)); return GetNLSMode(hWnd, (HANDLE)wParam); case CONIME_SET_NLSMODE: DBGPRINT(("CONIME: CONIME_SET_NLSMODE: Console Handle=%08x\n", wParam)); return SetNLSMode(hWnd, (HANDLE)wParam, (DWORD)lParam); case CONIME_HOTKEY: DBGPRINT(("CONIME: CONIME_HOTKEY\n")); return ConimeHotkey(hWnd, (HANDLE)wParam, (DWORD)lParam); case CONIME_NOTIFY_VK_KANA: DBGPRINT(("CONIME: CONIME_NOTIFY_VK_KANA\n")); return ImeUISetConversionMode(hWnd); case CONIME_NOTIFY_SCREENBUFFERSIZE: { COORD ScreenBufferSize; DBGPRINT(("CONIME: CONIME_NOTIFY_SCREENBUFFERSIZE: Console Handle=%08x\n", wParam)); ScreenBufferSize.X = LOWORD(lParam); ScreenBufferSize.Y = HIWORD(lParam); return ConsoleScreenBufferSize(hWnd, (HANDLE)wParam, ScreenBufferSize); } case CONIME_INPUTLANGCHANGE: { DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGE: Console Handle=%08x \n",wParam)); ConImeInputLangchange(hWnd, (HANDLE)wParam, (HKL)lParam ); return TRUE; } case CONIME_NOTIFY_CODEPAGE: { BOOL Output; WORD Codepage; Codepage = HIWORD(lParam); Output = LOWORD(lParam); DBGPRINT(("CONIME: CONIME_NOTIFY_CODEPAGE: Console Handle=%08x %04x %04x\n",wParam, Output, Codepage)); return ConsoleCodepageChange(hWnd, (HANDLE)wParam, Output, Codepage); } case WM_KEYDOWN +CONIME_KEYDATA: case WM_KEYUP +CONIME_KEYDATA: case WM_SYSKEYDOWN +CONIME_KEYDATA: case WM_SYSKEYUP +CONIME_KEYDATA: case WM_DEADCHAR +CONIME_KEYDATA: case WM_SYSDEADCHAR+CONIME_KEYDATA: case WM_SYSCHAR +CONIME_KEYDATA: case WM_CHAR +CONIME_KEYDATA: CharHandlerFromConsole( hWnd, Message, (ULONG)wParam, (ULONG)lParam ); break; case WM_KEYDOWN: case WM_KEYUP: case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_DEADCHAR: case WM_SYSDEADCHAR: case WM_SYSCHAR: case WM_CHAR: CharHandlerToConsole( hWnd, Message, (ULONG)wParam, (ULONG)lParam ); break; case WM_INPUTLANGCHANGE: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGE: Console Handle=%08x \n",wParam)); InputLangchange(hWnd, (DWORD)wParam, (HKL)lParam ); return TRUE; case WM_INPUTLANGCHANGEREQUEST: // Console IME never receive this message for this window is hidden // and doesn't have focus. // // However, Hot key of IME_CHOTKEY_IME_NONIME_TOGGLE/IME_THOTKEY_IME_NONIME_TOGGLE // are send this message by ImmSimulateHotKey API. // // If nothing processing by this message, then DefWindowProc calls // ActivateKeyboardLayout on kernel side. // And, ActivateKeyboardLayout send WM_INPUTLANGCHANGE message to focus window // on this message queue. // It window is console window procedure. // Console window procedure can do send CONIME_INPUTLANGCHANGE message to // console IME window. // In console window is windowed case, this sequence as well. // But, In console window is full screen case, message queue have not focus. // WM_INPUTLANGCHANGE message can not send to console window procedure. // // This code avoid console full screen mode problem. // Send message to console window procedure when this window receive it. // { PCONSOLE_TABLE ConTbl; ConTbl = SearchConsole(LastConsole); if (ConTbl == NULL) { return DefWindowProc(hWnd, Message, wParam, lParam); } PostMessage(ConTbl->hWndCon, Message, wParam, lParam); } return TRUE; // TRUE : process this message by application case CONIME_INPUTLANGCHANGEREQUEST: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGEREQUEST: Console Handle=%08x \n",wParam)); return ConImeInputLangchangeRequest(hWnd, (HANDLE)wParam, (HKL)lParam, CONIME_DIRECT); case CONIME_INPUTLANGCHANGEREQUESTFORWARD: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGEREQUEST: Console Handle=%08x \n",wParam)); return ConImeInputLangchangeRequest(hWnd, (HANDLE)wParam, (HKL)lParam, CONIME_FORWARD); case CONIME_INPUTLANGCHANGEREQUESTBACKWARD: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGEREQUEST: Console Handle=%08x \n",wParam)); return ConImeInputLangchangeRequest(hWnd, (HANDLE)wParam, (HKL)lParam, CONIME_BACKWARD); #ifdef DEBUG_MODE case WM_MOVE: ImeUIMoveCandWin( hWnd ); break; case WM_COMMAND: // message: command from application menu // Message packing of wparam and lparam have changed for Win32, // so use the GET_WM_COMMAND macro to unpack the commnad switch (LOWORD(wParam)) { case MM_EXIT: PostMessage(hWnd,WM_CLOSE,0,0L); break; case MM_ACCESS_VIOLATION: { PBYTE p = 0; *p = 0; } break; } break; #endif case WM_IME_STARTCOMPOSITION: ImeUIStartComposition( hWnd ); break; case WM_IME_ENDCOMPOSITION: ImeUIEndComposition( hWnd ); break; case WM_IME_COMPOSITION: ImeUIComposition( hWnd, wParam, lParam ); break; case WM_IME_COMPOSITIONFULL: break; case WM_IME_NOTIFY: if ( !ImeUINotify( hWnd, wParam, lParam ) ) { return DefWindowProc(hWnd, Message, wParam, lParam); } break; case WM_IME_SETCONTEXT: // // The application have to pass WM_IME_SETCONTEXT to DefWindowProc. // When the application want to handle the IME at the timing of // focus changing, the application should use WM_GETFOCUS or // WM_KILLFOCUS. // lParam &= ~ISC_SHOWUIALL; return DefWindowProc( hWnd, Message, wParam, lParam ); case WM_IME_SYSTEM: switch (wParam) { case IMS_CLOSEPROPERTYWINDOW: case IMS_OPENPROPERTYWINDOW: ImeSysPropertyWindow(hWnd, wParam, lParam); break; default: return DefWindowProc( hWnd, Message, wParam, lParam ); } break; case WM_CREATE: return Create(hWnd); break; case WM_DESTROY: DBGPRINT(("CONIME:Recieve WM_DESTROY\n")); ExitList(hWnd); PostQuitMessage(0); return 0; break; case WM_CLOSE: DBGPRINT(("CONIME:Recieve WM_CLOSE\n")); DestroyWindow(hWnd); return 0; break; case WM_ENABLE:{ PCONSOLE_TABLE FocusedConsole; if (!wParam) { FocusedConsole = SearchConsole(LastConsole); if (FocusedConsole != NULL && FocusedConsole->hConsole != NULL) { FocusedConsole->Enable = FALSE; EnableWindow(FocusedConsole->hWndCon,FALSE); gfDoNotKillFocus = TRUE; } } else{ DWORD i; LockConsoleTable(); for ( i = 1; i < NumberOfConsoleTable; i ++){ FocusedConsole = ConsoleTable[i]; if (FocusedConsole != NULL) { if ((FocusedConsole->hConsole != NULL)&& (!FocusedConsole->Enable)&& (!IsWindowEnabled(FocusedConsole->hWndCon))){ EnableWindow(FocusedConsole->hWndCon,TRUE); FocusedConsole->Enable = TRUE; if (!FocusedConsole->LateRemove) SetForegroundWindow(FocusedConsole->hWndCon); } } } UnlockConsoleTable(); } return DefWindowProc(hWnd, Message, wParam, lParam); break; } #ifdef DEBUG_MODE case WM_SETFOCUS: CreateCaret( hWnd, NULL, IsUnicodeFullWidth( ConvertLine[xPos] ) ? CaretWidth*2 : CaretWidth, (UINT)cyMetrics ); SetCaretPos( xPos * cxMetrics, 0 ); ShowCaret( hWnd ); break; case WM_KILLFOCUS: HideCaret( hWnd ); DestroyCaret(); break; case WM_PAINT: { PAINTSTRUCT pstruc; HDC hDC; hDC = BeginPaint(hWnd,&pstruc); ReDraw(hWnd); EndPaint(hWnd,&pstruc); break; } #endif case WM_QUERYENDSESSION: #ifdef HIRSHI_DEBUG /* * If specified ntsd debugger on this process, * then never catch WM_QUERYENDSESSION when logoff/shutdown because * this process will terminate when ntsd process terminated. */ { int i; i = MessageBox(hWnd,TEXT("Could you approve exit session?"), TEXT("Console IME"), MB_ICONSTOP | MB_YESNO); return (i == IDYES ? TRUE : FALSE); } #endif return TRUE; // Logoff or shutdown time. case WM_ENDSESSION: DBGPRINT(("CONIME:Recieve WM_ENDSESSION\n")); ExitList(hWnd); return 0; default: // Passes it on if unproccessed return DefWindowProc(hWnd, Message, wParam, lParam); } } except (InputExceptionFilter(GetExceptionInformation())) { if (dwConsoleThreadId) { DBGPRINT(("CONIME: Exception on WndProc!!\n")); UnregisterConsoleIME(); dwConsoleThreadId = 0; DestroyWindow(hWnd); return 0; } } return TRUE; }