From 9ec9384fa5040373ec464f259c17edd25d7aa72f Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Thu, 1 Apr 2010 14:44:19 +0000 Subject: [PATCH] 2010-04-01 16:44 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/gtwin/gtwin.c * harbour/src/rtl/gtwvt/gtwvt.h * harbour/src/rtl/gtwvt/gtwvt.c * modified to use in UNICODE builds current HVM CP if user has not set display CP using HB_SETTERMCP() or HB_SETDISPCP() * harbour/src/rtl/gtwvt/gtwvt.h * harbour/src/rtl/gtwvt/gtwvt.c * eliminated most of HB_TCHAR_*() translations % optimized setting SelectCopy menu item name to avoid unnecessary memory allocation and to use hb_str*() API ! allow to set window title before displaying the window (HB_GTI_WINTITLE) % use hb_str*() API for window title setting ! removed redundant window title setting just after creating new window ! pass pointer to HB_GTWVT structure as lpParam in CreateWindow() function to allow WM_CREATE message processing and early window handle registration * harbour/tests/cpinfo.prg * added HB_SETTERMCP() setting * harbour/examples/gtwvw/tests/cbtest1.prg * harbour/examples/gtwvw/tests/cbtest6.prg * harbour/examples/gtwvw/tests/ebtest7.prg * small cleanup to compile with Harbour --- harbour/ChangeLog | 28 +++ harbour/examples/gtwvw/tests/cbtest1.prg | 2 +- harbour/examples/gtwvw/tests/cbtest6.prg | 143 +++++++------- harbour/examples/gtwvw/tests/ebtest7.prg | 2 +- harbour/src/rtl/gtwin/gtwin.c | 61 ++++-- harbour/src/rtl/gtwvt/gtwvt.c | 239 ++++++++++------------- harbour/src/rtl/gtwvt/gtwvt.h | 21 +- harbour/tests/cpinfo.prg | 1 + 8 files changed, 267 insertions(+), 230 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 36caedc13b..0c1dad8863 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,34 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-04-01 16:44 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rtl/gtwin/gtwin.c + * harbour/src/rtl/gtwvt/gtwvt.h + * harbour/src/rtl/gtwvt/gtwvt.c + * modified to use in UNICODE builds current HVM CP if user + has not set display CP using HB_SETTERMCP() or HB_SETDISPCP() + + * harbour/src/rtl/gtwvt/gtwvt.h + * harbour/src/rtl/gtwvt/gtwvt.c + * eliminated most of HB_TCHAR_*() translations + % optimized setting SelectCopy menu item name to avoid unnecessary + memory allocation and to use hb_str*() API + ! allow to set window title before displaying the window + (HB_GTI_WINTITLE) + % use hb_str*() API for window title setting + ! removed redundant window title setting just after creating new window + ! pass pointer to HB_GTWVT structure as lpParam in CreateWindow() + function to allow WM_CREATE message processing and early window + handle registration + + * harbour/tests/cpinfo.prg + * added HB_SETTERMCP() setting + + * harbour/examples/gtwvw/tests/cbtest1.prg + * harbour/examples/gtwvw/tests/cbtest6.prg + * harbour/examples/gtwvw/tests/ebtest7.prg + * small cleanup to compile with Harbour + 2010-03-30 21:55 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/gtwvg/gtwvg.h ! fixed compilation with XCC diff --git a/harbour/examples/gtwvw/tests/cbtest1.prg b/harbour/examples/gtwvw/tests/cbtest1.prg index 448bb5c04d..3b7428e093 100644 --- a/harbour/examples/gtwvw/tests/cbtest1.prg +++ b/harbour/examples/gtwvw/tests/cbtest1.prg @@ -31,7 +31,7 @@ static s_cThankYou := "Thanks for participating in our survey :-)" ANNOUNCE HB_NOSTARTUPWINDOW proc main -local nMaxWidth, nCBid +local nMaxWidth, nCBid, nPBid, nPos local ch,ncursor setcolor("N/W") WVW_SetTitle(NIL,"Quick Survey") diff --git a/harbour/examples/gtwvw/tests/cbtest6.prg b/harbour/examples/gtwvw/tests/cbtest6.prg index c49cb6aaa7..577c2025b1 100644 --- a/harbour/examples/gtwvw/tests/cbtest6.prg +++ b/harbour/examples/gtwvw/tests/cbtest6.prg @@ -17,19 +17,20 @@ #include "getexit.ch" #include "inkey.ch" -* Two different keyboard handling method -* (notes: WVW_CB_KBD_CLIPPER doesn't mimic anything from Clipper -* it just 'feels like Clipper' to me) +/* Two different keyboard handling method + * (notes: WVW_CB_KBD_CLIPPER doesn't mimic anything from Clipper + * it just 'feels like Clipper' to me) + */ #define WVW_CB_KBD_STANDARD 0 #define WVW_CB_KBD_CLIPPER 1 -* our preferred method (choose one of the above) +// our preferred method (choose one of the above) static s_nCB_Kbd := WVW_CB_KBD_CLIPPER -* list of created comboboxes +// list of created comboboxes static s_aComboList := {} -* create these two as local, otherwise it will be assumed PRIVATE +// create these two as local, otherwise it will be assumed PRIVATE MEMVAR __nCBid__,__temp__ #xcommand @ , COMBOBOX ; @@ -37,18 +38,18 @@ MEMVAR __nCBid__,__temp__ WIDTH => ; ; ; - __nCBid__ := wvw_cbCreate(NIL, , , , ; - , ; - {|nWinNum,nId,nEvent,nIndex, temp| ; + __nCBid__ := wvw_cbCreate(NIL, , , , ; + , ; + {|nWinNum,nId,nEvent,nIndex, temp| ; CBhandler(nWinNum,nId,nEvent,nIndex,<"var">,GetList); - },; - NIL,NIL,s_nCB_Kbd,NIL); ; - AADD(s_aComboList, {__nCBid__, <"var"> }); ; - __temp__ := wvw_cbFindString(NIL, __nCBid__, );; - if(__temp__>=0, wvw_cbSetIndex(NIL, __nCBid__, __temp__),NIL);; - setpos(,);; - AAdd(GetList,_GET_(,<"var">,repl("X",),,) ) ;; - ATAIL(GetList):cargo := __nCBid__; ; + }, ; + NIL,NIL,s_nCB_Kbd,NIL); ; + AADD(s_aComboList, {__nCBid__, <"var"> }); ; + __temp__ := wvw_cbFindString(NIL, __nCBid__, ); ; + if(__temp__>=0, wvw_cbSetIndex(NIL, __nCBid__, __temp__),NIL); ; + setpos(,); ; + AAdd(GetList,_GET_(,<"var">,repl("X",),,) ) ; ; + ATAIL(GetList):cargo := __nCBid__; ; ATAIL(GetList):reader := {|get| CBreader(get)} proc main @@ -59,7 +60,7 @@ local __nCBid__,__temp__ //these two are temporary var required by CB get creat WVW_SetLineSpacing(NIL,4) WVW_SetLSpaceColor(NIL,0) WVW_cbSetFont(NIL, "Arial", 14) //std: 20-2 - set(_SET_TRACESTACK, 0) + //set(_SET_TRACESTACK, 0) //wvw_setmousemove(,.t.) @@ -100,31 +101,32 @@ local __nCBid__,__temp__ //these two are temporary var required by CB get creat return //main function CBhandler(nWinNum,nId,nEvent,nIndex, cVar, GetList) -* this function is called by GTWVW indirectly, through the main program's codeblock -* which adds 'cVar' and 'GetList' parameter to the original 4 parameter passed -* by GTWVW. -* -* This is a sample of how a combobox bound to a GetList is handled. -* -* Events handled here: -* CBN_SETFOCUS: (3) -* Find i where GetList[i] is Get object beneath the combobox, then -* synchronize the contents, and let TGetList think she is working on it. -* -* CBN_KILLFOCUS: (4) -* Find i where GetList[i] is Get object beneath the combobox, then -* synchronize the contents. -* -* CBN_SELCHANGE: (1) -* (do nothing) -* +/* this function is called by GTWVW indirectly, through the main program's codeblock + * which adds 'cVar' and 'GetList' parameter to the original 4 parameter passed + * by GTWVW. + * + * This is a sample of how a combobox bound to a GetList is handled. + * + * Events handled here: + * CBN_SETFOCUS: (3) + * Find i where GetList[i] is Get object beneath the combobox, then + * synchronize the contents, and let TGetList think she is working on it. + * + * CBN_KILLFOCUS: (4) + * Find i where GetList[i] is Get object beneath the combobox, then + * synchronize the contents. + * + * CBN_SELCHANGE: (1) + * (do nothing) + */ local i, ccursel local oGetList := __GetListActive() local oGet := GetActive() - * if GetList is empty, then READ session is already ended - * this should not be happenning! + /* if GetList is empty, then READ session is already ended + * this should not be happenning! + */ if empty(GetList) MyAlert("Bad practice: you left an active combobox, but READ already ended") return NIL//ignore this event @@ -134,31 +136,33 @@ local oGet := GetActive() case nEvent==3 //CBN_SETFOCUS i := ascan(GetList, {|x|x:Name==cVar}) if i>0 - * !oGet:HasFocus means - * CBN_SETFOCUS was NOT initiated from mouseclick - * then we don't need to bother about setting focus to the - * new GET. GetSys has already done that via CBreader(). - * It is CBreader() that brought us here, so ignore it. + /* !oGet:HasFocus means + * CBN_SETFOCUS was NOT initiated from mouseclick + * then we don't need to bother about setting focus to the + * new GET. GetSys has already done that via CBreader(). + * It is CBreader() that brought us here, so ignore it. + */ if oGet:HasFocus - * So user has jumped here by clicking on the combobox. - * And this combobox has oNewGet beneath it. - * But do NOT assign oGetList:oGet into this oNewGet - * from within here! - * Remember that the reader() is still suspended - * on inkey(0). If we change the ActiveGet from here, then - * when we leave this CB (eg. by means of K_TAB) - * this reader() will resume, but alas the active get - * is no longer the same! Thus reader() most likely - * will behave incorrectly. - - * The trick is simple: - * reject the SETFOCUS. This will cause reader() - * resume its action on inkey(0). - * All we have to do here is emulate the mouseclick - * event on oNewGet object beneath the CB, ie. - * putting K_LBUTTONDOWN into keyboard buffer - * at proper coordinate. - * We will then arrive at cbreader(). + /* So user has jumped here by clicking on the combobox. + * And this combobox has oNewGet beneath it. + * But do NOT assign oGetList:oGet into this oNewGet + * from within here! + * Remember that the reader() is still suspended + * on inkey(0). If we change the ActiveGet from here, then + * when we leave this CB (eg. by means of K_TAB) + * this reader() will resume, but alas the active get + * is no longer the same! Thus reader() most likely + * will behave incorrectly. + * + * The trick is simple: + * reject the SETFOCUS. This will cause reader() + * resume its action on inkey(0). + * All we have to do here is emulate the mouseclick + * event on oNewGet object beneath the CB, ie. + * putting K_LBUTTONDOWN into keyboard buffer + * at proper coordinate. + * We will then arrive at cbreader(). + */ SetWinFocus(nWinNum) msetpos(GetList[i]:row, GetList[i]:col+1) @@ -166,13 +170,14 @@ local oGet := GetActive() endif //oGet:HasFocus else //i==0 - * there's no GET object beneath the combobox. - * This must be a combobox living in the wild. - * Do what you want with it, we do nothing here. + /* there's no GET object beneath the combobox. + * This must be a combobox living in the wild. + * Do what you want with it, we do nothing here. + */ endif case nEvent==4 //CBN_KILLFOCUS - * put current content of combobox into GET variable beneath it. + // put current content of combobox into GET variable beneath it. cCurSel := wvw_cbGetCurText(nWinNum, nId) oGet:varput(cCurSel) oGet:display() //this is optional @@ -210,7 +215,7 @@ FUNCTION CBreader( oGet ) oGet:exitState := GE_UP ELSEIF ( nKey == K_DOWN ) - * NOTE that in WVW_CB_KBD_STANDARD mode we will never get here + // NOTE that in WVW_CB_KBD_STANDARD mode we will never get here oGet:exitState := GE_DOWN ELSEIF ( nKey == K_TAB ) @@ -253,7 +258,7 @@ RETURN (NIL) //cbreader() /* not used: static function MoveToGet(GetList, nPos) -* move focus to GET object at GetList[nPos] +// move focus to GET object at GetList[nPos] local i local oGetList := __GetListActive( ) local oGet @@ -279,7 +284,7 @@ return .t. /* miscellaneous **********************************/ static function SetWinFocus(nWinNum) -* Set FOCUS to window nWinNum +// Set FOCUS to window nWinNum local hWnd := wvw_getWindowHandle(nWinNum) WIN_SETFOCUS(hWnd) return NIL diff --git a/harbour/examples/gtwvw/tests/ebtest7.prg b/harbour/examples/gtwvw/tests/ebtest7.prg index 34c656f73b..d19b6d42c8 100644 --- a/harbour/examples/gtwvw/tests/ebtest7.prg +++ b/harbour/examples/gtwvw/tests/ebtest7.prg @@ -51,7 +51,7 @@ #define __GET_NEBID 10 #define __GET_LFOCUSED 11 -REQUEST HB_NOSTARTUPWINDOW +//REQUEST HB_NOSTARTUPWINDOW proc main local nOpen, nClose diff --git a/harbour/src/rtl/gtwin/gtwin.c b/harbour/src/rtl/gtwin/gtwin.c index 66929f0f99..13857603f2 100644 --- a/harbour/src/rtl/gtwin/gtwin.c +++ b/harbour/src/rtl/gtwin/gtwin.c @@ -593,9 +593,18 @@ static BOOL WINAPI hb_gt_win_CtrlHandler( DWORD dwCtrlType ) static void hb_gt_win_xGetScreenContents( PHB_GT pGT, SMALL_RECT * psrWin ) { int iRow, iCol, i; +#if defined( UNICODE ) + PHB_CODEPAGE cdpHost; +#endif HB_TRACE(HB_TR_DEBUG, ("hb_gt_win_xGetScreenContents(%p,%p)", pGT, psrWin)); +#if defined( UNICODE ) + cdpHost = s_cdpHost; + if( !cdpHost ) + cdpHost = hb_vmCDP(); +#endif + for( iRow = psrWin->Top; iRow <= psrWin->Bottom; ++iRow ) { i = iRow * _GetScreenWidth() + psrWin->Left; @@ -610,8 +619,8 @@ static void hb_gt_win_xGetScreenContents( PHB_GT pGT, SMALL_RECT * psrWin ) * very slow in some cases */ - uc = hb_cdpGetChar( s_cdpHost, HB_FALSE, wc ); - if( uc == '?' && wc >= 0x100 && s_cdpHost != s_cdpBox ) + uc = hb_cdpGetChar( cdpHost, HB_FALSE, wc ); + if( uc == '?' && wc >= 0x100 && cdpHost != s_cdpBox ) { uc = hb_cdpGetChar( s_cdpBox, HB_FALSE, wc ); if( uc != '?' ) @@ -827,13 +836,13 @@ static void hb_gt_win_Init( PHB_GT pGT, HB_FHANDLE hFilenoStdin, HB_FHANDLE hFil s_bAltKeyHandling = HB_TRUE; #if defined( UNICODE ) - s_cdpHost = s_cdpIn = hb_vmCDP(); + /* s_cdpHost = s_cdpIn = hb_vmCDP(); */ s_cdpBox = hb_cdpFind( "EN" ); -#endif - +#else /* initialize code page translation */ HB_GTSELF_SETDISPCP( pGT, NULL, NULL, HB_FALSE ); HB_GTSELF_SETKEYCP( pGT, NULL, NULL ); +#endif #ifndef HB_NO_ALLOC_CONSOLE /* @@ -1475,7 +1484,8 @@ static int hb_gt_win_ReadKey( PHB_GT pGT, int iEventMask ) #if defined( UNICODE ) ch = s_irInBuf[ s_cNumIndex ].Event.KeyEvent.uChar.UnicodeChar; - ch = hb_cdpGetChar( s_cdpIn, HB_FALSE, ( HB_WCHAR ) ch ); + ch = hb_cdpGetChar( s_cdpIn ? s_cdpIn : hb_vmCDP(), HB_FALSE, + ( HB_WCHAR ) ch ); #else ch = s_irInBuf[ s_cNumIndex ].Event.KeyEvent.uChar.AsciiChar; #endif @@ -2068,25 +2078,36 @@ static void hb_gt_win_Refresh( PHB_GT pGT ) { HB_TRACE( HB_TR_DEBUG, ("hb_gt_win_Refresh(%p)", pGT) ); - HB_GTSUPER_REFRESH( pGT ); - - if( s_pCharInfoScreen ) { - int iRow, iCol, iStyle; +#if defined( UNICODE ) + PHB_CODEPAGE cdpHost = s_cdpHost; + if( !cdpHost ) + s_cdpHost = hb_vmCDP(); +#endif - HB_GTSELF_GETSCRCURSOR( pGT, &iRow, &iCol, &iStyle ); + HB_GTSUPER_REFRESH( pGT ); - s_iCurRow = iRow; - s_iCurCol = iCol; + if( s_pCharInfoScreen ) + { + int iRow, iCol, iStyle; - if( iRow < 0 || iCol < 0 || - iRow >= ( int ) _GetScreenHeight() || - iCol >= ( int ) _GetScreenWidth() ) - s_iCursorStyle = SC_NONE; - else - s_iCursorStyle = iStyle; + HB_GTSELF_GETSCRCURSOR( pGT, &iRow, &iCol, &iStyle ); - hb_gt_win_xScreenUpdate(); + s_iCurRow = iRow; + s_iCurCol = iCol; + + if( iRow < 0 || iCol < 0 || + iRow >= ( int ) _GetScreenHeight() || + iCol >= ( int ) _GetScreenWidth() ) + s_iCursorStyle = SC_NONE; + else + s_iCursorStyle = iStyle; + + hb_gt_win_xScreenUpdate(); + } +#if defined( UNICODE ) + s_cdpHost = cdpHost; +#endif } } diff --git a/harbour/src/rtl/gtwvt/gtwvt.c b/harbour/src/rtl/gtwvt/gtwvt.c index 41e449aae8..4bf789be25 100644 --- a/harbour/src/rtl/gtwvt/gtwvt.c +++ b/harbour/src/rtl/gtwvt/gtwvt.c @@ -223,8 +223,11 @@ static void hb_gt_wvt_Free( PHB_GTWVT pWVT ) HB_WVT_UNLOCK - if( pWVT->pszSelectCopy ) - hb_xfree( pWVT->pszSelectCopy ); + if( pWVT->hSelectCopy ) + hb_strfree( pWVT->hSelectCopy ); + + if( pWVT->hWindowTitle ) + hb_strfree( pWVT->hWindowTitle ); #if !defined( UNICODE ) if( pWVT->hFontBox && pWVT->hFontBox != pWVT->hFont ) @@ -324,8 +327,20 @@ static PHB_GTWVT hb_gt_wvt_New( PHB_GT pGT, HINSTANCE hInstance, int iCmdShow ) pWVT->bBeingMarked = HB_FALSE; pWVT->bBeginMarked = HB_FALSE; - pWVT->pszSelectCopy = hb_strdup( "Mark and Copy" ); + pWVT->lpSelectCopy = TEXT( "Mark and Copy" ); + pWVT->hSelectCopy = NULL; pWVT->bSelectCopy = HB_TRUE; + + { + PHB_FNAME pFileName = hb_fsFNameSplit( hb_cmdargARGV()[ 0 ] ); + PHB_ITEM pItem = hb_itemPutC( NULL, pFileName->szName ); + + pWVT->lpWindowTitle = HB_ITEMGETSTR( pItem, &pWVT->hWindowTitle, NULL ); + + hb_itemRelease( pItem ); + hb_xfree( pFileName ); + } + pWVT->bResizable = HB_TRUE; pWVT->bClosable = HB_TRUE; @@ -334,10 +349,9 @@ static PHB_GTWVT hb_gt_wvt_New( PHB_GT pGT, HINSTANCE hInstance, int iCmdShow ) pWVT->bResizing = HB_FALSE; pWVT->bAlreadySizing = HB_FALSE; - pWVT->hostCDP = hb_vmCDP(); #if defined( UNICODE ) - pWVT->inCDP = hb_vmCDP(); - pWVT->boxCDP = hb_cdpFind( "EN" ); + /* pWVT->hostCDP = pWVT->inCDP = hb_vmCDP(); */ + pWVT->boxCDP = hb_cdpFind( "EN" ); #else { int i; @@ -554,6 +568,7 @@ static void hb_gt_wvt_TranslateKey( PHB_GTWVT pWVT, int key, int shiftkey, int a } } +#if !defined( UNICODE ) static int hb_gt_wvt_key_ansi_to_oem( int c ) { BYTE pszSrc[ 2 ]; @@ -570,6 +585,7 @@ static int hb_gt_wvt_key_ansi_to_oem( int c ) return pszDst[ 0 ]; } +#endif static void hb_gt_wvt_FitRows( PHB_GTWVT pWVT ) { @@ -885,31 +901,6 @@ static void hb_gt_wvt_ResetWindowSize( PHB_GTWVT pWVT, HFONT hFont ) hb_gt_wvt_UpdateCaret( pWVT ); } -static void hb_gt_wvt_SetWindowTitle( HWND hWnd, const char * title ) -{ - LPTSTR text = HB_TCHAR_CONVTO( title ); - SetWindowText( hWnd, text ); - HB_TCHAR_FREE( text ); -} - -static HB_BOOL hb_gt_wvt_GetWindowTitle( HWND hWnd, char ** title ) -{ - TCHAR buffer[ WVT_MAX_TITLE_SIZE ]; - int iResult; - - iResult = GetWindowText( hWnd, buffer, WVT_MAX_TITLE_SIZE ); - if( iResult > 0 ) - { - *title = ( char * ) hb_xgrab( iResult + 1 ); - HB_TCHAR_GETFROM( *title, buffer, iResult ); - ( *title )[ iResult ] = '\0'; - return HB_TRUE; - } - - *title = NULL; - return HB_FALSE; -} - static HB_BOOL hb_gt_wvt_SetWindowSize( PHB_GTWVT pWVT, int iRows, int iCols ) { if( HB_GTSELF_RESIZE( pWVT->pGT, iRows, iCols ) ) @@ -1370,17 +1361,18 @@ static HB_BOOL hb_gt_wvt_KeyEvent( PHB_GTWVT pWVT, UINT message, WPARAM wParam, hb_gt_wvt_AddCharToInputQueue( pWVT, K_ESC ); break; default: - if( pWVT->inCDP ) - { #if defined( UNICODE ) - c = hb_cdpGetChar( pWVT->inCDP, HB_FALSE, ( HB_WCHAR ) c ); + c = hb_cdpGetChar( pWVT->inCDP ? pWVT->inCDP : hb_vmCDP(), + HB_FALSE, ( HB_WCHAR ) c ); #else + if( pWVT->fKeyTrans ) + { if( c > 0 && c <= 255 && pWVT->keyTransTbl[ c ] ) c = pWVT->keyTransTbl[ c ]; -#endif } else if( pWVT->CodePage == OEM_CHARSET ) c = hb_gt_wvt_key_ansi_to_oem( c ); +#endif hb_gt_wvt_AddCharToInputQueue( pWVT, c ); break; } @@ -1555,7 +1547,9 @@ static void hb_gt_wvt_PaintText( PHB_GTWVT pWVT, RECT updateRect ) int iRow, iCol, startCol, len; int iColor, iOldColor = 0; HB_BYTE bAttr; -#if ! defined( UNICODE ) +#if defined( UNICODE ) + PHB_CODEPAGE hostCDP; +#else HFONT hFont, hOldFont = NULL; #endif HB_USHORT usChar; @@ -1563,6 +1557,7 @@ static void hb_gt_wvt_PaintText( PHB_GTWVT pWVT, RECT updateRect ) hdc = BeginPaint( pWVT->hWnd, &ps ); #if defined( UNICODE ) SelectObject( hdc, pWVT->hFont ); + hostCDP = pWVT->hostCDP ? pWVT->hostCDP : hb_vmCDP(); #endif rcRect = hb_gt_wvt_GetColRowFromXYRect( pWVT, updateRect ); @@ -1582,7 +1577,7 @@ static void hb_gt_wvt_PaintText( PHB_GTWVT pWVT, RECT updateRect ) */ iColor &= 0xff; #if defined( UNICODE ) - usChar = hb_cdpGetU16( bAttr & HB_GT_ATTR_BOX ? pWVT->boxCDP : pWVT->hostCDP, HB_TRUE, ( HB_BYTE ) usChar ); + usChar = hb_cdpGetU16( bAttr & HB_GT_ATTR_BOX ? pWVT->boxCDP : hostCDP, HB_TRUE, ( HB_BYTE ) usChar ); if( len == 0 ) { iOldColor = iColor; @@ -1633,10 +1628,25 @@ static LRESULT CALLBACK hb_gt_wvt_WndProc( HWND hWnd, UINT message, WPARAM wPara { PHB_GTWVT pWVT = hb_gt_wvt_Find( hWnd ); + if( !pWVT ) + { + if( message == WM_CREATE ) + { + pWVT = ( PHB_GTWVT ) ( ( LPCREATESTRUCT ) lParam )->lpCreateParams; + if( pWVT ) + { + if( s_wvtWindows[ pWVT->iHandle ] == pWVT ) + pWVT->hWnd = hWnd; + else + pWVT = NULL; + } + } + } + if( pWVT ) switch( message ) { case WM_CREATE: - return hb_gt_wvt_InitWindow( pWVT, pWVT->ROWS, pWVT->COLS, NULL ); + return hb_gt_wvt_InitWindow( pWVT, pWVT->ROWS, pWVT->COLS, NULL ) ? 0 : -1; case WM_PAINT: { @@ -1819,38 +1829,32 @@ static HB_BOOL hb_gt_wvt_ValidWindowSize( HWND hWnd, int rows, int cols, HFONT h return ( width <= maxWidth ) && ( height <= maxHeight ); } -static HWND hb_gt_wvt_CreateWindow( HINSTANCE hInstance, HB_BOOL bResizable ) +static void hb_gt_wvt_CreateWindow( PHB_GTWVT pWVT ) { - HWND hWnd; - LPTSTR szAppName; + DWORD dwStyle; /* InitCommonControls(); */ - szAppName = HB_TCHAR_CONVTO( hb_cmdargARGV()[ 0 ] ); + dwStyle = pWVT->bResizable ? _WVT_WS_DEF : _WVT_WS_NORESIZE; - hWnd = CreateWindow( - s_szClassName, /* classname */ - szAppName, /* window name */ - bResizable ? _WVT_WS_DEF : _WVT_WS_NORESIZE, /* style */ - 0, /* x */ - 0, /* y */ - CW_USEDEFAULT, /* width */ - CW_USEDEFAULT, /* height */ - NULL, /* window parent */ - NULL, /* menu */ - hInstance, /* instance */ - NULL ); /* lpParam */ - - HB_TCHAR_FREE( szAppName ); - - return hWnd; + pWVT->hWnd = CreateWindow( s_szClassName, /* classname */ + pWVT->lpWindowTitle, /* window name */ + dwStyle, /* style */ + 0, /* x */ + 0, /* y */ + CW_USEDEFAULT, /* width */ + CW_USEDEFAULT, /* height */ + NULL, /* window parent */ + NULL, /* menu */ + pWVT->hInstance, /* instance */ + ( LPVOID ) pWVT ); /* lpParam */ } static HB_BOOL hb_gt_wvt_CreateConsoleWindow( PHB_GTWVT pWVT ) { if( !pWVT->hWnd ) { - pWVT->hWnd = hb_gt_wvt_CreateWindow( pWVT->hInstance, pWVT->bResizable ); + hb_gt_wvt_CreateWindow( pWVT ); if( !pWVT->hWnd ) hb_errInternal( 10001, "Failed to create WVT window", NULL, NULL ); @@ -1872,15 +1876,13 @@ static HB_BOOL hb_gt_wvt_CreateConsoleWindow( PHB_GTWVT pWVT ) #endif pSetLayeredWindowAttributes( pWVT->hWnd, - ( COLORREF ) 0 /* COLORREF crKey */, - 255 /* BYTE bAlpha */, - LWA_ALPHA /* DWORD dwFlags */ ); + ( COLORREF ) 0, /* COLORREF crKey */ + 255, /* BYTE bAlpha */ + LWA_ALPHA /* DWORD dwFlags */ ); } } #endif - hb_gt_wvt_InitWindow( pWVT, pWVT->ROWS, pWVT->COLS, NULL ); - /* Set icon */ if( pWVT->hIcon ) { @@ -1888,22 +1890,13 @@ static HB_BOOL hb_gt_wvt_CreateConsoleWindow( PHB_GTWVT pWVT ) SendNotifyMessage( pWVT->hWnd, WM_SETICON, ICON_BIG , ( LPARAM ) pWVT->hIcon ); /* Set Task List Icon */ } - /* Set default window title */ - { - PHB_FNAME pFileName = hb_fsFNameSplit( hb_cmdargARGV()[ 0 ] ); - hb_gt_wvt_SetWindowTitle( pWVT->hWnd, pFileName->szName ); - hb_xfree( pFileName ); - } - { HMENU hSysMenu = GetSystemMenu( pWVT->hWnd, FALSE ); if( hSysMenu ) { /* Create "Mark" prompt in SysMenu to allow console type copy operation */ - LPTSTR buffer = HB_TCHAR_CONVTO( pWVT->pszSelectCopy ); - AppendMenu( hSysMenu, MF_STRING, SYS_EV_MARK, buffer ); - HB_TCHAR_FREE( buffer ); - + AppendMenu( hSysMenu, MF_STRING, SYS_EV_MARK, pWVT->lpSelectCopy ); + /* disable [x] button / close menu item */ if( ! pWVT->bClosable ) EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED ); } @@ -2302,23 +2295,13 @@ static HB_BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) break; } case HB_GTI_WINTITLE: - if( pWVT->hWnd ) + pInfo->pResult = HB_ITEMPUTSTR( pInfo->pResult, pWVT->lpWindowTitle ); + if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { - char * pszTitle = NULL; - if( hb_gt_wvt_GetWindowTitle( pWVT->hWnd, &pszTitle ) ) - pInfo->pResult = hb_itemPutCPtr( pInfo->pResult, pszTitle ); - else - pInfo->pResult = hb_itemPutC( pInfo->pResult, NULL ); - - if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) - { - char * pszFreeTitle = NULL; - - hb_gt_wvt_SetWindowTitle( pWVT->hWnd, hb_osEncodeCP( hb_itemGetCPtr( pInfo->pNewVal ), &pszFreeTitle, NULL ) ); - - if( pszFreeTitle ) - hb_xfree( pszFreeTitle ); - } + hb_strfree( pWVT->hWindowTitle ); + pWVT->lpWindowTitle = HB_ITEMGETSTR( pInfo->pNewVal, &pWVT->hWindowTitle, NULL ); + if( pWVT->hWnd ) + SetWindowText( pWVT->hWnd, pWVT->lpWindowTitle ); } break; @@ -2413,14 +2396,14 @@ static HB_BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { if( ( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) ) { - HICON hIconToFree = ( pWVT->hIcon && pWVT->bIconToFree ) ? pWVT->hIcon : NULL; - LPTSTR lpImage; + HICON hIconToFree = pWVT->bIconToFree ? pWVT->hIcon : NULL; + void * hImageName; - lpImage = HB_TCHAR_CONVTO( hb_itemGetCPtr( pInfo->pNewVal ) ); pWVT->bIconToFree = HB_TRUE; - pWVT->hIcon = ( HICON ) LoadImage( ( HINSTANCE ) NULL, lpImage, + pWVT->hIcon = ( HICON ) LoadImage( ( HINSTANCE ) NULL, + HB_ITEMGETSTR( pInfo->pNewVal, &hImageName, NULL ), IMAGE_ICON, 0, 0, LR_LOADFROMFILE ); - HB_TCHAR_FREE( lpImage ); + hb_strfree( hImageName ); if( pWVT->hWnd ) { SendNotifyMessage( pWVT->hWnd, WM_SETICON, ICON_SMALL, ( LPARAM ) pWVT->hIcon ); /* Set Title Bar Icon */ @@ -2438,14 +2421,13 @@ static HB_BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { - HICON hIconToFree = ( pWVT->hIcon && pWVT->bIconToFree ) ? pWVT->hIcon : NULL; - LPTSTR lpIcon; + HICON hIconToFree = pWVT->bIconToFree ? pWVT->hIcon : NULL; + void * hIconName; - lpIcon = HB_TCHAR_CONVTO( hb_itemGetCPtr( pInfo->pNewVal ) ); pWVT->bIconToFree = HB_FALSE; - pWVT->hIcon = LoadIcon( pWVT->hInstance, lpIcon ); - HB_TCHAR_FREE( lpIcon ); - + pWVT->hIcon = LoadIcon( pWVT->hInstance, + HB_ITEMGETSTR( pInfo->pNewVal, &hIconName, NULL ) ); + hb_strfree( hIconName ); if( pWVT->hWnd ) { SendNotifyMessage( pWVT->hWnd, WM_SETICON, ICON_SMALL, ( LPARAM ) pWVT->hIcon ); /* Set Title Bar Icon */ @@ -2457,7 +2439,7 @@ static HB_BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) } else if( hb_itemType( pInfo->pNewVal ) & HB_IT_NUMERIC ) { - HICON hIconToFree = ( pWVT->hIcon && pWVT->bIconToFree ) ? pWVT->hIcon : NULL; + HICON hIconToFree = pWVT->bIconToFree ? pWVT->hIcon : NULL; pWVT->bIconToFree = HB_FALSE; pWVT->hIcon = LoadIcon( pWVT->hInstance, @@ -2573,56 +2555,45 @@ static HB_BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) break; case HB_GTI_SELECTCOPY: - pInfo->pResult = hb_itemPutL( pInfo->pResult, pWVT->bSelectCopy ); - if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { - pInfo->pResult = hb_itemPutC( pInfo->pResult, pWVT->pszSelectCopy ); + pInfo->pResult = HB_ITEMPUTSTR( pInfo->pResult, pWVT->lpSelectCopy ); if( hb_itemGetCLen( pInfo->pNewVal ) ) { HMENU hSysMenu = pWVT->hWnd ? GetSystemMenu( pWVT->hWnd, FALSE ) : NULL; if( hSysMenu || !pWVT->hWnd ) { - char * pszFreeTitle = NULL; - - if( pWVT->pszSelectCopy ) - hb_xfree( pWVT->pszSelectCopy ); - - pWVT->pszSelectCopy = hb_strdup( hb_osEncodeCP( hb_itemGetCPtr( pInfo->pNewVal ), &pszFreeTitle, NULL ) ); + hb_strfree( pWVT->hSelectCopy ); + pWVT->lpSelectCopy = HB_ITEMGETSTR( pInfo->pNewVal, &pWVT->hSelectCopy, NULL ); pWVT->bSelectCopy = HB_TRUE; - - if( pszFreeTitle ) - hb_xfree( pszFreeTitle ); - #if !defined( HB_OS_WIN_CE ) /* WinCE does not support ModifyMenu */ if( hSysMenu ) - { - LPTSTR buffer; - buffer = HB_TCHAR_CONVTO( pWVT->pszSelectCopy ); - ModifyMenu( hSysMenu, SYS_EV_MARK, MF_BYCOMMAND | MF_STRING | MF_ENABLED, SYS_EV_MARK, buffer ); - HB_TCHAR_FREE( buffer ); - } + ModifyMenu( hSysMenu, SYS_EV_MARK, MF_BYCOMMAND | MF_STRING | MF_ENABLED, SYS_EV_MARK, pWVT->lpSelectCopy ); #endif } } } - else if( pInfo->pNewVal ) + else { - HB_BOOL bNewValue = hb_itemGetL( pInfo->pNewVal ); - if( bNewValue != pWVT->bSelectCopy ) + pInfo->pResult = hb_itemPutL( pInfo->pResult, pWVT->bSelectCopy ); + if( pInfo->pNewVal ) { - if( pWVT->hWnd ) + HB_BOOL bNewValue = hb_itemGetL( pInfo->pNewVal ); + if( bNewValue != pWVT->bSelectCopy ) { - HMENU hSysMenu = GetSystemMenu( pWVT->hWnd, FALSE ); - if( hSysMenu ) + if( pWVT->hWnd ) { - EnableMenuItem( hSysMenu, SYS_EV_MARK, MF_BYCOMMAND | ( bNewValue ? MF_ENABLED : MF_GRAYED ) ); - pWVT->bSelectCopy = bNewValue; + HMENU hSysMenu = GetSystemMenu( pWVT->hWnd, FALSE ); + if( hSysMenu ) + { + EnableMenuItem( hSysMenu, SYS_EV_MARK, MF_BYCOMMAND | ( bNewValue ? MF_ENABLED : MF_GRAYED ) ); + pWVT->bSelectCopy = bNewValue; + } } + else + pWVT->bSelectCopy = bNewValue; } - else - pWVT->bSelectCopy = bNewValue; } } break; @@ -3025,9 +2996,11 @@ static HB_BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const ch cdpHost = hb_cdpFind( pszHostCDP ); for( i = 0; i < 256; i++ ) + { pWVT->keyTransTbl[ i ] = ( HB_BYTE ) hb_cdpTranslateChar( i, HB_FALSE, cdpTerm, cdpHost ); - pWVT->inCDP = cdpTerm; + } + pWVT->fKeyTrans = HB_TRUE; } # endif diff --git a/harbour/src/rtl/gtwvt/gtwvt.h b/harbour/src/rtl/gtwvt/gtwvt.h index d652c4a312..5366ac3d54 100644 --- a/harbour/src/rtl/gtwvt/gtwvt.h +++ b/harbour/src/rtl/gtwvt/gtwvt.h @@ -66,6 +66,7 @@ #include "hbvm.h" #include "hbthread.h" #include "hbgfxdef.ch" +#include "hbwinuni.h" #include #if defined( HB_OS_WIN_CE ) @@ -151,10 +152,12 @@ typedef struct HWND hWnd; /* the window handle */ HB_BOOL fInit; /* logical variable indicating that window should be open */ - PHB_CODEPAGE hostCDP; /* Host/HVM CodePage for unicode output translations */ - PHB_CODEPAGE inCDP; /* Host/HVM CodePage for unicode input translations */ #if defined( UNICODE ) + PHB_CODEPAGE inCDP; /* Host/HVM CodePage for unicode input translations */ + PHB_CODEPAGE hostCDP; /* Host/HVM CodePage for unicode output translations */ PHB_CODEPAGE boxCDP; /* CodePage for legacy drawing chars: IBM437 */ +#else + HB_BOOL fKeyTrans; /* logical variable indicating that CP key translation is enabled */ #endif #if !defined( UNICODE ) @@ -165,6 +168,9 @@ typedef struct HICON hIcon; /* Title Bar and Task List icon. Can be NULL. */ HB_BOOL bIconToFree; /* Do we need to free this icon when it's not NULL? */ + void * hWindowTitle; + LPCTSTR lpWindowTitle; + int CodePage; /* Code page to use for display characters */ #if ! defined( UNICODE ) int boxCodePage; /* Code page to use for display draw line characters */ @@ -175,19 +181,22 @@ typedef struct HB_BOOL IgnoreWM_SYSCHAR; + HB_BOOL bResizable; + HB_BOOL bClosable; + HB_BOOL bMaximized; /* Flag is set when window has been maximized */ HB_BOOL bBeingMarked; /* Flag to control DOS window like copy operation */ HB_BOOL bBeginMarked; - HB_BOOL bResizable; HB_BOOL bSelectCopy; - char * pszSelectCopy; - HB_BOOL bClosable; + void * hSelectCopy; + LPCTSTR lpSelectCopy; - int ResizeMode; /* Sets the resizing mode either to FONT or ROWS */ RECT sRectNew; RECT sRectOld; + int ResizeMode; /* Sets the resizing mode either to FONT or ROWS */ + HB_BOOL bResizing; HB_BOOL bAlreadySizing; diff --git a/harbour/tests/cpinfo.prg b/harbour/tests/cpinfo.prg index 1a15b10d0a..ed884f6476 100644 --- a/harbour/tests/cpinfo.prg +++ b/harbour/tests/cpinfo.prg @@ -28,6 +28,7 @@ proc main( cdp, info, unicode ) #ifdef __HARBOUR__ /* for test */ set( _SET_CODEPAGE, iif( empty( cdp ), "PLMAZ", upper( cdp ) ) ) + hb_setTermCP( set( _SET_CODEPAGE ), set( _SET_CODEPAGE ) ) lEqual := .t. #else lEqual := .f.