From bb05aaa0e0f0a830c429f1d6b5929f7ca8d33805 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 23 Dec 2009 04:37:00 +0000 Subject: [PATCH] 2009-12-23 05:36 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/gtwin/gtwin.c ! applied a little bit modified the patch from Jacek Potempa for setmode() in GTWIN - many thanks. Please test. --- harbour/ChangeLog | 5 ++++ harbour/src/rtl/gtwin/gtwin.c | 49 ++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7f9222f979..1f170769e2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,11 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-23 05:36 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rtl/gtwin/gtwin.c + ! applied a little bit modified the patch from Jacek Potempa for + setmode() in GTWIN - many thanks. Please test. + 2009-12-23 02:59 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.pt_BR.po ! Restored stripped accents while saving the file with Windows-1250 CP diff --git a/harbour/src/rtl/gtwin/gtwin.c b/harbour/src/rtl/gtwin/gtwin.c index bb93e8962f..78ac66b3a0 100644 --- a/harbour/src/rtl/gtwin/gtwin.c +++ b/harbour/src/rtl/gtwin/gtwin.c @@ -865,24 +865,65 @@ static BOOL hb_gt_win_SetMode( PHB_GT pGT, int iRows, int iCols ) srWin.Bottom = ( SHORT ) ( iRows - 1 ); srWin.Right = ( SHORT ) ( iCols - 1 ); - /* if the current buffer is larger than what we want, resize the */ - /* console window first, then the buffer */ - if( ( DWORD ) _GetScreenWidth() * _GetScreenHeight() > ( DWORD ) iCols * iRows ) + if( ( int ) _GetScreenWidth() >= iCols && + ( int ) _GetScreenHeight() >= iRows ) { + /* the new dimensions do not exceed the current buffer dimensions so + * we can safely resize the console window first, then the buffer + */ if( SetConsoleWindowInfo( s_HOutput, TRUE, &srWin ) ) { SetConsoleScreenBufferSize( s_HOutput, coBuf ); fRet = TRUE; } } - else + else if( ( int ) _GetScreenWidth() <= iCols && + ( int ) _GetScreenHeight() <= iRows ) { + /* none of the current buffer dimensions is larger then the + * new dimensions so we can safely enlarge the buffer to new + * dimensions then adjust the console window dimensions + */ if( SetConsoleScreenBufferSize( s_HOutput, coBuf ) ) { SetConsoleWindowInfo( s_HOutput, TRUE, &srWin ); fRet = TRUE; } } + else + { + /* one of the new dimensions is smaller and second larger then the + * current buffer dimensions. Windows API needs to keep the buffer + * dimensions not smaller then console window size and there is + * no single API call which allow to change both buffer and console + * window dimensions. It means that we have to resize one of the + * above objects in two steps. We can temporary enlarge the buffer + * dimensions or reduce the console window dimensions. + * To reduce the possibility that we will exploit some WIN API + * limits for the maximum buffer size instead of enlarging it we + * decrease the one of console window dimensions which is larger + * then the corresponding new one. + */ + if( ( int ) _GetScreenWidth() < iCols ) + srWin.Right = ( SHORT ) ( _GetScreenWidth() - 1 ); + else + srWin.Bottom = ( SHORT ) ( _GetScreenHeight() - 1 ); + if( SetConsoleWindowInfo( s_HOutput, TRUE, &srWin ) ) + { + /* now we can safely set the new buffer dimensions because + * none of them is smaller then corresponding dimensions of + * just reduced console window and then we set final console + * window size. + */ + if( SetConsoleScreenBufferSize( s_HOutput, coBuf ) ) + { + srWin.Bottom = ( SHORT ) ( iRows - 1 ); + srWin.Right = ( SHORT ) ( iCols - 1 ); + SetConsoleWindowInfo( s_HOutput, TRUE, &srWin ); + } + fRet = TRUE; + } + } if( fRet ) hb_gt_win_xInitScreenParam( pGT );