[wpdev-commits] wolfpack console_win.cpp,1.3,1.4
Brought to you by:
rip,
thiagocorrea
|
From: <dar...@us...> - 2003-09-09 11:18:00
|
Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv17395
Modified Files:
console_win.cpp
Log Message:
Trying out new console code.
Index: console_win.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/console_win.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** console_win.cpp 9 Sep 2003 03:24:15 -0000 1.3
--- console_win.cpp 9 Sep 2003 11:17:56 -0000 1.4
***************
*** 54,57 ****
--- 54,58 ----
// Variables important for this GUI implementation
#define CONTROL_LOGWINDOW 0x10
+ #define CONTROL_INPUT 0x11
HWND logWindow = 0; // Log Window
***************
*** 61,64 ****
--- 62,66 ----
HFONT font = 0; // The font we'll use
unsigned int inputHeight = 0; // For measuring the height of the input field
+ unsigned int logLimit = 0; // How many characters fit into the log window
/*
***************
*** 82,87 ****
LRESULT CALLBACK wpWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
! CHARFORMAT cf;
LOGFONT lfont;
switch( msg )
--- 84,90 ----
LRESULT CALLBACK wpWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
! CHARFORMAT cf;
LOGFONT lfont;
+ NMHDR *notify = (NMHDR*)lparam;
switch( msg )
***************
*** 98,101 ****
--- 101,106 ----
}
+ logLimit = SendMessage( logWindow, EM_GETLIMITTEXT, 0, 0 );
+
// Set up the fonts we need
ZeroMemory( &lfont, sizeof( LOGFONT ) );
***************
*** 124,128 ****
// Create InputWindow
! inputWindow = CreateWindow( "EDIT", 0, ES_LEFT|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, 0, 0, 10, 10, hwnd, 0, appInstance, 0 );
return 0;
--- 129,133 ----
// Create InputWindow
! inputWindow = CreateWindow( "EDIT", 0, ES_LEFT|ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, 0, 0, 10, 10, hwnd, (HMENU)CONTROL_INPUT, appInstance, 0 );
return 0;
***************
*** 163,169 ****
case WM_NOTIFY:
if( wparam == CONTROL_LOGWINDOW )
! {
! NMHDR *notify = (NMHDR*)lparam;
!
if( notify->code == EN_LINK )
{
--- 168,172 ----
case WM_NOTIFY:
if( wparam == CONTROL_LOGWINDOW )
! {
if( notify->code == EN_LINK )
{
***************
*** 187,191 ****
--- 190,206 ----
}
}
+ else if( notify->code == EN_MSGFILTER )
+ {
+ MSGFILTER *msg = (MSGFILTER*)notify;
+
+ // Append to the Input Control
+ if( msg->msg == WM_CHAR )
+ {
+ SendMessage( inputWindow, WM_SETFOCUS, 0, 0 );
+ SendMessage( inputWindow, WM_CHAR, msg->wParam, msg->lParam );
+ }
+ }
}
+ return 0;
case WM_DESTROY:
***************
*** 316,319 ****
--- 331,337 ----
while( GetMessage( &msg, mainWindow, 0, 0 ) > 0 )
{
+ if( msg.message == WM_CHAR && msg.hwnd == inputWindow && msg.lParam == '\r' )
+ continue;
+
TranslateMessage( &msg );
DispatchMessage( &msg );
***************
*** 342,345 ****
--- 360,388 ----
void cConsole::send(const QString &sMessage)
{
+ unsigned int ctrlLength = GetWindowTextLength( logWindow );
+ unsigned int textLength = sMessage.length();
+
+ // Check for the caret
+ CHARRANGE range;
+ SendMessage( logWindow, EM_EXGETSEL, 0, (LPARAM)&range );
+
+ // Delete lines from the beginning if we exceed the maximum limit.
+ if( ctrlLength + textLength > logLimit )
+ {
+ unsigned int linecount = 0;
+ unsigned int textcount = 0;
+
+ do
+ {
+ char buffer[1024] = { 0, };
+ ((short*)buffer)[0] = 1024;
+ textcount += SendMessage( logWindow, EM_GETLINE, linecount++, (WPARAM)buffer );
+ }
+ while( textcount < ( ctrlLength + textLength ) - logLimit );
+
+ SendMessage( logWindow, EM_SETSEL, 0, textcount );
+ SendMessage( logWindow, EM_REPLACESEL, FALSE, (LPARAM)"" );
+ }
+
// process \b properly
if ( sMessage.contains("\b") )
***************
*** 360,372 ****
}
}
! // Make sure we append, so move to last character.
! int nLines = SendMessage(logWindow, EM_GETLINECOUNT, 0, 0);
! LONG nLastChar = SendMessage(logWindow, EM_LINEINDEX, nLines, 0);
! CHARRANGE range;
! range.cpMin = nLastChar;
! range.cpMax = nLastChar;
! SendMessage( logWindow, EM_EXSETSEL, 0, (LPARAM) &range);
// Now it will get right, even if the user had selected sth.
SendMessage( logWindow, EM_REPLACESEL, FALSE, (LPARAM)sMessage.latin1() );
}
--- 403,419 ----
}
}
!
! range.cpMin = GetWindowTextLength( logWindow );
! range.cpMax = GetWindowTextLength( logWindow );
! SendMessage( logWindow, EM_EXSETSEL, 0, (LPARAM)&range );
!
// Now it will get right, even if the user had selected sth.
SendMessage( logWindow, EM_REPLACESEL, FALSE, (LPARAM)sMessage.latin1() );
+
+ // And ofcourse if not some control is currently capturing the input
+ if( !GetCapture() )
+ {
+ SendMessage( logWindow, EM_LINESCROLL, 0, SendMessage( logWindow, EM_LINEFROMCHAR, ( ctrlLength + textLength ) - 1, 0 ) );
+ }
}
|