diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2d65e0727c..bee7eafa86 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,27 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-08 08:57 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com + * harbour/source/rtl/gtwvt/gtwvt.c + + Added functionality to disable "Mark and Copy" prompt in the SysMenu. + Include Function Hb_NoCopyConsole() if you do not want this functionality. + + + Added funtionality to resize the console window with mouse operations. + /* + Resizing of console is enabled by default. + To supress this behavior include a dummy function Hb_NoResizableWindow() + + Resizing is available in both directions. I mean horizontal as well as verticle. + Maximize button is also enabled. Click it to see to your surprize that now + console window will provide you DOS like terminal. + + However there is a bug in maximized operation, last row does not show up correct. + I feel it belongs to some miscalculation, but what that is I am unable to locate, so far. + Please experiment. + */ + * harbour/tests/wvtext.prg + * Updated to new HB_GT*_ constants and new functionality. + 2008-06-08 15:18 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * include/hbgtinfo.ch + Added comment to compatibility #defines, to not use diff --git a/harbour/source/rtl/gtwvt/gtwvt.c b/harbour/source/rtl/gtwvt/gtwvt.c index ab23243277..a66dccbf26 100644 --- a/harbour/source/rtl/gtwvt/gtwvt.c +++ b/harbour/source/rtl/gtwvt/gtwvt.c @@ -610,6 +610,7 @@ static void hb_gt_wvt_KillCaret( PHB_GTWVT pWVT ) } } + static void hb_gt_wvt_ResetWindowSize( PHB_GTWVT pWVT ) { HDC hdc; @@ -685,6 +686,91 @@ static void hb_gt_wvt_ResetWindowSize( PHB_GTWVT pWVT ) HB_GTSELF_EXPOSEAREA( pWVT->pGT, 0, 0, pWVT->ROWS, pWVT->COLS ); } +static void hb_gt_wvt_FitSize( PHB_GTWVT pWVT, USHORT mode ) +{ + HDC hdc; + HFONT hOldFont, hFont; + USHORT width, height, maxWidth, maxHeight, fontHeight, fontWidth, n, left, top; + TEXTMETRIC tm; + RECT wi, ci; + + HB_SYMBOL_UNUSED( mode ); + + if( pWVT->bMaximized ) + { + SystemParametersInfo( SPI_GETWORKAREA, 0, &ci, 0 ); + } + else + { + GetWindowRect( pWVT->hWnd, &wi ); + GetClientRect( pWVT->hWnd, &ci ); + } + + maxWidth = ci.right - ci.left; + maxHeight = ci.bottom - ci.top ; + fontHeight = maxHeight / pWVT->ROWS; + fontWidth = maxWidth / pWVT->COLS; + + hFont = hb_gt_wvt_GetFont( pWVT->fontFace, fontHeight, fontWidth, pWVT->fontWeight, pWVT->fontQuality, pWVT->CodePage ); + if( hFont ) + { + hdc = GetDC( pWVT->hWnd ); + hOldFont = ( HFONT ) SelectObject( hdc, hFont ); + GetTextMetrics( hdc, &tm ); + SetTextCharacterExtra( hdc, 0 ); + SelectObject( hdc, hOldFont ); + ReleaseDC( pWVT->hWnd, hdc ); + + width = (USHORT) ( tm.tmAveCharWidth * pWVT->COLS ); + height = (USHORT) ( tm.tmHeight * pWVT->ROWS ); + + if( width <= maxWidth && height <= maxHeight ) + { + if( pWVT->hFont ) + { + DeleteObject( pWVT->hFont ); + } + pWVT->hFont = hFont; + pWVT->fontHeight = tm.tmHeight; + pWVT->fontWidth = tm.tmAveCharWidth; + + pWVT->PTEXTSIZE.x = tm.tmAveCharWidth; + pWVT->PTEXTSIZE.y = tm.tmHeight; + +#if defined(HB_WINCE) + pWVT->FixedFont = FALSE; +#else + pWVT->FixedFont = !pWVT->Win9X && pWVT->fontWidth >= 0 && + ( tm.tmPitchAndFamily & TMPF_FIXED_PITCH ) == 0 && + ( pWVT->PTEXTSIZE.x == tm.tmMaxCharWidth ); +#endif + for( n = 0; n < pWVT->COLS; n++ ) + { + pWVT->FixedSize[ n ] = pWVT->PTEXTSIZE.x; + } + + if( pWVT->bMaximized ) + { + left = ( ( ci.right - width ) / 2 ); + top = ( ( ci.bottom - height ) / 2 ); + } + else + { + left = wi.left; + top = wi.top; + width += ( USHORT ) ( wi.right - wi.left - ci.right ); + height += ( USHORT ) ( wi.bottom - wi.top - ci.bottom ); + } + + hb_gt_wvt_KillCaret( pWVT ); + hb_gt_wvt_UpdateCaret( pWVT ); + + SetWindowPos( pWVT->hWnd, NULL, left, top, width, height, SWP_NOZORDER ); + HB_GTSELF_EXPOSEAREA( pWVT->pGT, 0, 0, pWVT->ROWS, pWVT->COLS ); + } + } +} + static void hb_gt_wvt_SetWindowTitle( HWND hWnd, char * title ) { LPTSTR text = HB_TCHAR_CONVTO( title ); @@ -1521,6 +1607,7 @@ static LRESULT CALLBACK hb_gt_wvt_WndProc( HWND hWnd, UINT message, WPARAM wPara case WM_SIZE: if( !pWVT->bMaximized ) { + hb_gt_wvt_FitSize( pWVT,0 ); hb_gt_wvt_FireEvent( pWVT, HB_GTE_SIZE, (WPARAM) LOWORD( lParam ), (LPARAM) HIWORD( lParam ) ); } else @@ -1539,9 +1626,12 @@ static LRESULT CALLBACK hb_gt_wvt_WndProc( HWND hWnd, UINT message, WPARAM wPara case SC_MAXIMIZE: { RECT rc = {0,0,0,0}; - pWVT->bMaximized = TRUE; - SystemParametersInfo( SPI_GETWORKAREA,0, &rc, 0 ); + pWVT->bMaximized = TRUE; + hb_gt_wvt_FitSize( pWVT,1 ); + pWVT->bMaximized = FALSE; + + SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 ); hb_gt_wvt_FireEvent( pWVT, HB_GTE_SIZE, (WPARAM) (rc.right-rc.left-pWVT->PTEXTSIZE.x), (LPARAM) (rc.bottom-rc.top-(pWVT->PTEXTSIZE.y*1)) ); @@ -1601,6 +1691,7 @@ static HWND hb_gt_wvt_CreateWindow( HINSTANCE hInstance, HINSTANCE hPrevInstance { HWND hWnd; WNDCLASS wndclass; + ULONG style; HB_SYMBOL_UNUSED( hPrevInstance ); HB_SYMBOL_UNUSED( szCmdLine ); @@ -1625,9 +1716,18 @@ static HWND hb_gt_wvt_CreateWindow( HINSTANCE hInstance, HINSTANCE hPrevInstance return 0; } + if( hb_dynsymFind( "HB_NORESIZEABLEWINDOW" ) != NULL ) + { + style = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_BORDER; + } + else + { + style = WS_THICKFRAME|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX; + } + hWnd = CreateWindow( s_szAppName, /* classname */ TEXT( "HARBOUR_WVT" ), /* window name */ - WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX, /* style */ + style, /* style */ 0, /* x */ 0, /* y */ CW_USEDEFAULT, /* width */ @@ -1711,6 +1811,7 @@ static void hb_gt_wvt_Init( PHB_GT pGT, FHANDLE hFilenoStdin, FHANDLE hFilenoStd } /* Create "Mark" prompt in SysMenu to allow console type copy operation */ + if( hb_dynsymFind( "HB_NOCOPYCONSOLE" ) == NULL ) { HMENU hSysMenu = GetSystemMenu( pWVT->hWnd, FALSE ); AppendMenu( hSysMenu, MF_STRING, SYS_EV_MARK, "Mark and Copy" ); diff --git a/harbour/tests/wvtext.prg b/harbour/tests/wvtext.prg index c78ad99c09..8a70ef325f 100644 --- a/harbour/tests/wvtext.prg +++ b/harbour/tests/wvtext.prg @@ -11,33 +11,44 @@ //----------------------------------------------------------------------// #include 'HbGtInfo.ch' +#include 'inkey.ch' //----------------------------------------------------------------------// FUNCTION Main() Local nKey + Local nHeight := 20 + Local nWidth := Int( nHeight/2 ) + Local cFont + + //cFont := 'Courier New' + //cFont := 'Times New Roman' + cFont := 'Lucida Console' + + Hb_GtInfo( HB_GTI_FONTNAME , cFont ) + Hb_GtInfo( HB_GTI_FONTWIDTH, nWidth ) + Hb_GtInfo( HB_GTI_FONTSIZE , nHeight ) SetMode( 25,80 ) SetCursor( 0 ) SetColor( 'n/w' ) - // Any CALLBACK function receive 5 parameters PLUS any additional parameters // supplied with the CALLBACK Block. // - HB_GtInfo( GTI_CALLBACK, { GTI_CB_SETFOCUS, {|a,b,c,d,e| MyCallBacks( a,b,c,d,e,'MyParam' ) }, { 'MyCargo' } } ) - HB_GtInfo( GTI_CALLBACK, { GTI_CB_CLOSE , {|a,b,c,d,e| MyCallBacks( a,b,c,d,e ) } } ) + HB_GtInfo( HB_GTI_CALLBACK, { HB_GTE_SETFOCUS, {|a,b,c,d,e| MyCallBacks( a,b,c,d,e,'MyParam' ) }, { 'MyCargo' } } ) + HB_GtInfo( HB_GTI_CALLBACK, { HB_GTE_CLOSE , {|a,b,c,d,e| MyCallBacks( a,b,c,d,e ) } } ) DispScreen() DO WHILE .T. nKey := Inkey() - if nKey == 27 + if nKey == K_ESC exit endif DO CASE - CASE nKey == 13 + CASE nKey == K_ENTER Alert( ' Pressed' ) ENDCASE @@ -50,11 +61,11 @@ STATIC FUNCTION MyCallBacks( nEvent, iGT, xCargo, wParam, lParam, xSentByMe ) DO CASE - CASE nEvent == GTI_CB_SETFOCUS + CASE nEvent == HB_GTE_SETFOCUS DispOutAt( 5,10, xCargo[ 1 ], 'N/W' ) // We have sent { 'MyCargo' } DispOutAt( 6,10, xSentByMe , 'R/W' ) // We are sending 'MyParam' - CASE nEvent == GTI_CB_CLOSE + CASE nEvent == HB_GTE_CLOSE DispScreen() if Alert( 'Close Application', {'Yes','No' } ) == 1 QUIT @@ -74,6 +85,17 @@ STATIC FUNCTION DispScreen() RETURN NIL +//----------------------------------------------------------------------// +// Comment out this function if you do not want console window be resizable with mouse +// +//FUNCTION Hb_NoResizeableWindow() ; RETURN NIL + +//----------------------------------------------------------------------// +// Comment out this function if you do not want "Mark and Copy" prompt +// available in SysMenu at the left of Title Bar of the application window. +// +//FUNCTION Hb_NoCopyConsole() ; RETURN NIL + //----------------------------------------------------------------------// FUNCTION HB_GTSYS() @@ -83,4 +105,3 @@ FUNCTION HB_GTSYS() RETURN nil //----------------------------------------------------------------------// -