-/* $Id: guiconsole.c,v 1.23 2004/12/04 22:09:02 navaraf Exp $
+/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
/* INCLUDES ******************************************************************/
-#include <windows.h>
-#include "conio.h"
-#include "guiconsole.h"
-#include "win32csr.h"
+#include "w32csr.h"
#define NDEBUG
#include <debug.h>
#define CURSOR_BLINK_TIME 500
-static BOOL Initialized = FALSE;
+static BOOL ConsInitialized = FALSE;
static HWND NotifyWnd;
/* FUNCTIONS *****************************************************************/
SelectObject(Dc, OldFont);
GuiData->MemoryDC = CreateCompatibleDC(Dc);
- GuiData->MemoryBitmap = CreateCompatibleBitmap(Dc,
- Console->Size.X * GuiData->CharWidth,
+ GuiData->MemoryBitmap = CreateCompatibleBitmap(Dc,
+ Console->Size.X * GuiData->CharWidth,
Console->Size.Y * GuiData->CharHeight);
- DeleteObject(SelectObject(GuiData->MemoryDC, GuiData->MemoryBitmap));
- SelectObject(GuiData->MemoryDC, GuiData->Font); /* Don't delete stock font. */
+ /* NOTE: Don't delete the "first bitmap", it's done in DeleteDC. */
+ SelectObject(GuiData->MemoryDC, GuiData->MemoryBitmap);
+ /* NOTE: Don't delete stock font. */
+ SelectObject(GuiData->MemoryDC, GuiData->Font);
ReleaseDC(hWnd, Dc);
GuiData->CursorBlinkOn = TRUE;
GuiData->ForceCursorOff = FALSE;
GuiData->Selection.left = -1;
-
+
Console->PrivateData = GuiData;
SetWindowLongPtrW(hWnd, GWL_USERDATA, (DWORD_PTR) Console);
GuiConsoleUpdateSelection(HWND hWnd, PRECT rc, PGUI_CONSOLE_DATA GuiData)
{
RECT oldRect = GuiData->Selection;
-
+
if(rc != NULL)
{
RECT changeRect = *rc;
changeRect.top *= GuiData->CharHeight;
changeRect.right *= GuiData->CharWidth;
changeRect.bottom *= GuiData->CharHeight;
-
+
if(rc->left != oldRect.left ||
rc->top != oldRect.top ||
rc->right != oldRect.right ||
if(oldRect.left != -1)
{
HRGN rgn1, rgn2;
-
+
oldRect.left *= GuiData->CharWidth;
oldRect.top *= GuiData->CharHeight;
oldRect.right *= GuiData->CharWidth;
oldRect.bottom *= GuiData->CharHeight;
-
+
/* calculate the region that needs to be updated */
if((rgn1 = CreateRectRgnIndirect(&oldRect)))
{
GuiConsoleSetTextColors(GuiData->MemoryDC, Attribute);
LastAttribute = Attribute;
}
- }
- MultiByteToWideChar(Console->OutputCodePage, 0, From, 1, To, 1);
+ }
+ MultiByteToWideChar(Console->OutputCodePage, 0, (PCHAR)From, 1, To, 1);
To++;
From += 2;
}
Ps.rcPaint.right - Ps.rcPaint.left + 1,
Ps.rcPaint.bottom - Ps.rcPaint.top + 1, GuiData->MemoryDC,
Ps.rcPaint.left, Ps.rcPaint.top, SRCCOPY);
-
+
if (GuiData->Selection.left != -1)
{
RECT rc = GuiData->Selection;
-
+
rc.left *= GuiData->CharWidth;
rc.top *= GuiData->CharHeight;
rc.right *= GuiData->CharWidth;
rc.bottom *= GuiData->CharHeight;
if (IntersectRect(&rc, &Ps.rcPaint, &rc))
- {
+ {
PatBlt(Dc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, DSTINVERT);
- }
- }
-
+ }
+ }
+
EndPaint (hWnd, &Ps);
LeaveCriticalSection(&GuiData->Lock);
}
Message.message = msg;
Message.wParam = wParam;
Message.lParam = lParam;
-
+
if(msg == WM_CHAR || msg == WM_SYSKEYDOWN)
{
/* clear the selection */
}
static VOID STDCALL
-GuiWriteStream(PCSRSS_CONSOLE Console, RECT *Region, UINT CursorStartX, UINT CursorStartY,
+GuiWriteStream(PCSRSS_CONSOLE Console, RECT *Region, LONG CursorStartX, LONG CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length)
{
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->PrivateData;
PGUI_CONSOLE_DATA GuiData;
POINTS pt;
RECT rc;
-
+
GuiConsoleGetDataPointers(hWnd, &Console, &GuiData);
if (Console == NULL || GuiData == NULL) return;
rc.top = pt.y / GuiData->CharHeight;
rc.right = rc.left + 1;
rc.bottom = rc.top + 1;
-
+
GuiData->SelectionStart.x = rc.left;
GuiData->SelectionStart.y = rc.top;
-
+
SetCapture(hWnd);
-
+
GuiData->MouseDown = TRUE;
-
+
GuiConsoleUpdateSelection(hWnd, &rc, GuiData);
}
PGUI_CONSOLE_DATA GuiData;
RECT rc;
POINTS pt;
-
+
GuiConsoleGetDataPointers(hWnd, &Console, &GuiData);
if (Console == NULL || GuiData == NULL) return;
if (GuiData->Selection.left == -1 || !GuiData->MouseDown) return;
-
+
pt = MAKEPOINTS(lParam);
-
+
rc.left = GuiData->SelectionStart.x;
rc.top = GuiData->SelectionStart.y;
rc.right = (pt.x >= 0 ? (pt.x / GuiData->CharWidth) + 1 : 0);
rc.top = max(rc.bottom - 1, 0);
rc.bottom = tmp + 1;
}
-
+
GuiData->MouseDown = FALSE;
GuiConsoleUpdateSelection(hWnd, &rc, GuiData);
-
+
ReleaseCapture();
}
PGUI_CONSOLE_DATA GuiData;
RECT rc;
POINTS pt;
-
+
if (!(wParam & MK_LBUTTON)) return;
-
+
GuiConsoleGetDataPointers(hWnd, &Console, &GuiData);
if (Console == NULL || GuiData == NULL || !GuiData->MouseDown) return;
}
GuiConsoleUpdateSelection(hWnd, &rc, GuiData);
-}
+}
static VOID FASTCALL
GuiConsoleRightMouseDown(HWND hWnd)
{
PCSRSS_CONSOLE Console;
PGUI_CONSOLE_DATA GuiData;
-
+
GuiConsoleGetDataPointers(hWnd, &Console, &GuiData);
if (Console == NULL || GuiData == NULL) return;
else
{
/* FIXME - copy selection to clipboard */
-
+
GuiConsoleUpdateSelection(hWnd, NULL, GuiData);
}
-}
+}
static LRESULT CALLBACK
GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- LRESULT Result;
+ LRESULT Result = 0;
switch(msg)
{
break;
case WM_PAINT:
GuiConsoleHandlePaint(hWnd);
- Result = 0;
break;
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_CHAR:
GuiConsoleHandleKey(hWnd, msg, wParam, lParam);
- Result = 0;
break;
case WM_TIMER:
GuiConsoleHandleTimer(hWnd);
- Result = 0;
break;
case WM_CLOSE:
GuiConsoleHandleClose(hWnd);
- Result = 0;
break;
case WM_NCDESTROY:
GuiConsoleHandleNcDestroy(hWnd);
- Result = 0;
break;
case WM_LBUTTONDOWN:
GuiConsoleLeftMouseDown(hWnd, lParam);
{
HWND NewWindow;
LONG WindowCount;
+ MSG Msg;
+ PWCHAR Buffer, Title;
PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) lParam;
switch(msg)
SetWindowLongW(hWnd, GWL_USERDATA, 0);
return 0;
case PM_CREATE_CONSOLE:
- NewWindow = CreateWindowW(L"Win32CsrConsole",
- Console->Title.Buffer,
+ Buffer = HeapAlloc(Win32CsrApiHeap, 0,
+ Console->Title.Length + sizeof(WCHAR));
+ if (NULL != Buffer)
+ {
+ memcpy(Buffer, Console->Title.Buffer, Console->Title.Length);
+ Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0';
+ Title = Buffer;
+ }
+ else
+ {
+ Title = L"";
+ }
+ NewWindow = CreateWindowW(L"ConsoleWindowClass",
+ Title,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
(HINSTANCE) GetModuleHandleW(NULL),
(PVOID) Console);
+ if (NULL != Buffer)
+ {
+ HeapFree(Win32CsrApiHeap, 0, Buffer);
+ }
Console->hWindow = NewWindow;
if (NULL != NewWindow)
{
}
return (LRESULT) NewWindow;
case PM_DESTROY_CONSOLE:
+ /* Window creation is done using a PostMessage(), so it's possible that the
+ * window that we want to destroy doesn't exist yet. So first empty the message
+ * queue */
+ while(PeekMessageW(&Msg, NULL, 0, 0, PM_REMOVE))
+ {
+ TranslateMessage(&Msg);
+ DispatchMessageW(&Msg);
+ }
DestroyWindow(Console->hWindow);
Console->hWindow = NULL;
WindowCount = GetWindowLongW(hWnd, GWL_USERDATA);
}
wc.cbSize = sizeof(WNDCLASSEXW);
- wc.lpszClassName = L"Win32CsrConsole";
+ wc.lpszClassName = L"ConsoleWindowClass";
wc.lpfnWndProc = GuiConsoleWndProc;
wc.style = 0;
wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL);
Buffer->DefaultAttrib = 0x0f;
}
-STATIC BOOL STDCALL
+static BOOL STDCALL
GuiChangeTitle(PCSRSS_CONSOLE Console)
{
- SendMessageW(Console->hWindow, WM_SETTEXT, 0, (LPARAM) Console->Title.Buffer);
+ PWCHAR Buffer, Title;
+
+ Buffer = HeapAlloc(Win32CsrApiHeap, 0,
+ Console->Title.Length + sizeof(WCHAR));
+ if (NULL != Buffer)
+ {
+ memcpy(Buffer, Console->Title.Buffer, Console->Title.Length);
+ Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0';
+ Title = Buffer;
+ }
+ else
+ {
+ Title = L"";
+ }
+ SendMessageW(Console->hWindow, WM_SETTEXT, 0, (LPARAM) Title);
+ if (NULL != Buffer)
+ {
+ HeapFree(Win32CsrApiHeap, 0, Buffer);
+ }
return TRUE;
}
-STATIC BOOL STDCALL
+static BOOL STDCALL
GuiChangeIcon(PCSRSS_CONSOLE Console)
{
SendMessageW(Console->hWindow, WM_SETICON, ICON_BIG, (LPARAM)Console->hWindowIcon);
HANDLE GraphicsStartupEvent;
HANDLE ThreadHandle;
- if (! Initialized)
+ if (! ConsInitialized)
{
- Initialized = TRUE;
+ ConsInitialized = TRUE;
if (! GuiInit())
{
- Initialized = FALSE;
+ ConsInitialized = FALSE;
return STATUS_UNSUCCESSFUL;
}
}
ScrollRect.top = Dest->top * GuiData->CharHeight;
ScrollRect.bottom = (Dest->bottom + 1) * GuiData->CharHeight;
EnterCriticalSection(&GuiData->Lock);
- BitBlt(GuiData->MemoryDC, ScrollRect.left, ScrollRect.top,
+ BitBlt(GuiData->MemoryDC, ScrollRect.left, ScrollRect.top,
ScrollRect.right - ScrollRect.left, ScrollRect.bottom - ScrollRect.top,
GuiData->MemoryDC, Source->left * GuiData->CharWidth, Source->top * GuiData->CharHeight, SRCCOPY);