From c04afe2af335968f65a288ce189a54581f801c03 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Wed, 11 Jun 2008 19:35:37 +0000 Subject: [PATCH] 2008-06-11 12:30 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com * harbour/source/rtl/gtwvt/gtwvt.c * harbour/source/rtl/gtwvt/gtwvt.h * harbour/include/hbgtinfo.ch + Added HB_GTI_CLOSABLE Hb_GtInfo( HB_GTI_CLOSABLE, TRUE|FALSE ) -> lPrevState TRUE enables the "X" button, FALSE disbles it. + Added functionality to respond to WM_CLOSE message. If application returns 1 then application is exited. * harbour/tests/wvtext.prg + Added functionality to demonstrate above feature. --- harbour/ChangeLog | 13 ++++++++++++ harbour/include/hbgtinfo.ch | 2 +- harbour/source/rtl/gtwvt/gtwvt.c | 34 ++++++++++++++++++++++++------- harbour/source/rtl/gtwvt/gtwvt.h | 1 + harbour/tests/wvtext.prg | 35 +++++++++++++++++++++++--------- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 00b273dc51..5661cf5848 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,19 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-11 12:30 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com + * harbour/source/rtl/gtwvt/gtwvt.c + * harbour/source/rtl/gtwvt/gtwvt.h + * harbour/include/hbgtinfo.ch + + Added HB_GTI_CLOSABLE + Hb_GtInfo( HB_GTI_CLOSABLE, TRUE|FALSE ) -> lPrevState + TRUE enables the "X" button, FALSE disbles it. + + Added functionality to respond to WM_CLOSE message. + If application returns 1 then application is exited. + + * harbour/tests/wvtext.prg + + Added functionality to demonstrate above feature. + 2008-06-11 19:39 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * ChangeLog + Marked changes merged with RC1. diff --git a/harbour/include/hbgtinfo.ch b/harbour/include/hbgtinfo.ch index 3ade255c15..3cf8e4b912 100644 --- a/harbour/include/hbgtinfo.ch +++ b/harbour/include/hbgtinfo.ch @@ -120,7 +120,7 @@ #define HB_GTI_SELECTCOPY 48 /* toggles screen content selection and copy to clipboard (supported by: GTWVT) */ #define HB_GTI_RESIZABLE 49 /* toggles ability to resize window (supported by: GTWVT) */ -#define HB_GTI_CLOSEALLOWED 50 /* toggles ability to close window (supported by: GTWVT) */ +#define HB_GTI_CLOSABLE 50 /* toggles ability to close window (supported by: GTWVT) */ /* Additional constants to enhance GT */ #define HB_GTI_NOTIFIERBLOCK 51 /* This optional codeblock gets called whenever certain events occur. See HB_GTE_* */ diff --git a/harbour/source/rtl/gtwvt/gtwvt.c b/harbour/source/rtl/gtwvt/gtwvt.c index 3f4eaa77dd..2cb2b5cf59 100644 --- a/harbour/source/rtl/gtwvt/gtwvt.c +++ b/harbour/source/rtl/gtwvt/gtwvt.c @@ -227,6 +227,7 @@ static PHB_GTWVT hb_gt_wvt_New( PHB_GT pGT ) pWVT->bSelectCopy = TRUE; pWVT->bResizable = TRUE; + pWVT->bClosable = TRUE; return pWVT; } @@ -525,9 +526,9 @@ static void hb_gt_wvt_FitSize( PHB_GTWVT pWVT ) width = tm.tmAveCharWidth * pWVT->COLS; height = tm.tmHeight * pWVT->ROWS; - if( width <= maxWidth && - height <= maxHeight && - tm.tmAveCharWidth >= 3 && + if( width <= maxWidth && + height <= maxHeight && + tm.tmAveCharWidth >= 3 && tm.tmHeight >= 4 ) { if( pWVT->hFont ) @@ -1427,6 +1428,7 @@ static void hb_gt_wvt_PaintText( PHB_GTWVT pWVT, RECT updateRect ) static LRESULT CALLBACK hb_gt_wvt_WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { PHB_GTWVT pWVT = hb_gt_wvt_Find( hWnd ); + int iEvResult; if( pWVT ) switch( message ) { @@ -1483,10 +1485,12 @@ static LRESULT CALLBACK hb_gt_wvt_WndProc( HWND hWnd, UINT message, WPARAM wPara case WM_CLOSE: /* Clicked 'X' on system menu */ /* NOTE: this follows more code . will post later as it needs to be cleaned */ /* But it demonstrates the concept */ - hb_gt_wvt_FireEvent( pWVT, HB_GTE_CLOSE ); - - if( hb_set.HB_SET_CANCEL ) - hb_vmRequestCancel(); + iEvResult = hb_gt_wvt_FireEvent( pWVT, HB_GTE_CLOSE ); + if( iEvResult == 0 ) + { + if( hb_set.HB_SET_CANCEL ) + hb_vmRequestCancel(); + } return 0; case WM_QUIT: @@ -2273,6 +2277,22 @@ static BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) } break; } + case HB_GTI_CLOSABLE: + { + pInfo->pResult = hb_itemPutL( pInfo->pResult, pWVT->bClosable ); + if( pInfo->pNewVal ) + { + BOOL bNewValue = hb_itemGetL( pInfo->pNewVal ); + if( bNewValue != pWVT->bClosable ) + { + HMENU hSysMenu = GetSystemMenu( pWVT->hWnd, FALSE ); + + EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND | ( bNewValue ? MF_ENABLED : MF_GRAYED ) ); + pWVT->bClosable = bNewValue; + } + } + break; + } default: return HB_GTSUPER_INFO( pGT, iType, pInfo ); } diff --git a/harbour/source/rtl/gtwvt/gtwvt.h b/harbour/source/rtl/gtwvt/gtwvt.h index b7d5b81f51..4f47a16e7e 100644 --- a/harbour/source/rtl/gtwvt/gtwvt.h +++ b/harbour/source/rtl/gtwvt/gtwvt.h @@ -162,6 +162,7 @@ typedef struct BOOL bResizable; BOOL bSelectCopy; + BOOL bClosable; } HB_GTWVT, * PHB_GTWVT; diff --git a/harbour/tests/wvtext.prg b/harbour/tests/wvtext.prg index 75672f2f2e..ee24d31234 100644 --- a/harbour/tests/wvtext.prg +++ b/harbour/tests/wvtext.prg @@ -20,7 +20,7 @@ //----------------------------------------------------------------------// FUNCTION Main() - Local nKey, lMark, lResize + Local nKey, lMark, lResize, lClose Local nHeight := 20 Local nWidth := Int( nHeight/2 ) Local cFont @@ -58,6 +58,10 @@ FUNCTION Main() lResize := Hb_GtInfo( HB_GTI_RESIZABLE ) Hb_GtInfo( HB_GTI_RESIZABLE, !lResize ) + CASE nKey == K_F4 + lClose := Hb_GtInfo( HB_GTI_CLOSABLE ) + hb_GtInfo( HB_GTI_CLOSABLE, !lClose ) + ENDCASE ENDDO @@ -70,12 +74,12 @@ STATIC FUNCTION MyNotifier( nEvent, ... ) CASE nEvent == HB_GTE_SETFOCUS DispScreen() - Alert( "We got focus" ) + DispOutAt( maxrow(), 33, "We got focus", 'B/G*' ) CASE nEvent == HB_GTE_CLOSE DispScreen() - if Alert( 'Close Application', {'Yes','No' } ) == 1 - QUIT + if Alert( 'Close Application', {'Yes','No' } ) == 2 + Return ( 1 ) endif ENDCASE @@ -85,15 +89,24 @@ STATIC FUNCTION MyNotifier( nEvent, ... ) //----------------------------------------------------------------------// STATIC FUNCTION DispScreen() + Local nRow := 18, nCol := 28 + Local cColor := 'N/W*' CLS DispOutAt( 0, 0,padc( 'Harbour GT - New Features', maxcol()+1 ), 'N/GR*' ) - DispOutAt( maxrow() - 1, 0, padc( ' ', maxcol()+1 ), 'N/G*' ) - DispOutAt( maxrow(), 0, Space( maxcol()+1 ), 'N/G*' ) - DispOutAt( 0, 0, "TL" ) - DispOutAt( 0, MaxCol() - 1, "TR" ) - DispOutAt( MaxRow(), 0, "BL" ) - DispOutAt( MaxRow(), MaxCol() - 1, "BR" ) + + DispOutAt( nRow+0, nCol, '< F2 MarkCopy Toggle >', cColor ) + DispOutAt( nRow+1, nCol, '< F3 Resize Toggle >', cColor ) + DispOutAt( nRow+2, nCol, '< F4 Closable Toggle >', cColor ) + DispOutAt( nRow+3, nCol, '< Click Other Window >', cColor ) + DispOutAt( nRow+4, nCol, '< Click X Button >', cColor ) + + DispOutAt( maxrow(), 0, Space( maxcol()+1 ), "N/G*" ) + + DispOutAt( 0, 0 , "TL", "N/GR*" ) + DispOutAt( 0, MaxCol() - 1 , "TR", "N/GR*" ) + DispOutAt( MaxRow(), 0 , "BL", "N/G*" ) + DispOutAt( MaxRow(), MaxCol() - 1, "BR", "N/G*" ) RETURN NIL @@ -104,6 +117,8 @@ PROCEDURE HB_GTSYS() REQUEST HB_GT_WIN RETURN +//----------------------------------------------------------------------// + PROCEDURE HB_GT_WVT_DEFAULT() RETURN