From c5ea2260b7b8ad4cfe8a4ed1bf133c3bfccce969 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 27 Jul 2026 09:24:56 +0200 Subject: [PATCH] EgtExecutor : - migliorie e correzioni a dialoghi lua con selezione oggetti. --- EXE_GdbObjSelection.cpp | 10 ++--- LUA_GenDialog.cpp | 91 ++++++++++++++++++++--------------------- LUA_GenDialog.h | 3 ++ 3 files changed, 53 insertions(+), 51 deletions(-) diff --git a/EXE_GdbObjSelection.cpp b/EXE_GdbObjSelection.cpp index 1e96ac1..ca962d6 100644 --- a/EXE_GdbObjSelection.cpp +++ b/EXE_GdbObjSelection.cpp @@ -75,7 +75,7 @@ ExeSelectObj( int nId) if ( bOk) UpdateDialogIds() ; // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { + if ( IsCmdLog() && ! IsSelectionFromDialog()) { string sLua = "EgtSelectObj(" + ToString( nId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -102,7 +102,7 @@ ExeDeselectObj( int nId) if ( bOk) UpdateDialogIds() ; // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { + if ( IsCmdLog() && ! IsSelectionFromDialog()) { string sLua = "EgtDeselectObj(" + ToString( nId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -165,7 +165,7 @@ ExeDeselectAll( void) if ( bOk) UpdateDialogIds() ; // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { + if ( IsCmdLog() && ! IsSelectionFromDialog()) { string sLua = "EgtDeselectAll()" " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -194,7 +194,7 @@ ExeSelectGroupObjs( int nGroupId) if ( bOk) UpdateDialogIds() ; // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { + if ( IsCmdLog() && ! IsSelectionFromDialog()) { string sLua = "EgtSelectGroupObjs(" + ToString( nGroupId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -220,7 +220,7 @@ ExeDeselectGroupObjs( int nGroupId) if ( bOk) UpdateDialogIds() ; // se richiesto, salvo il comando Lua equivalente - if ( IsCmdLog()) { + if ( IsCmdLog() && ! IsSelectionFromDialog()) { string sLua = "EgtDeselectGroupObjs(" + ToString( nGroupId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; diff --git a/LUA_GenDialog.cpp b/LUA_GenDialog.cpp index 78de367..2d788c9 100644 --- a/LUA_GenDialog.cpp +++ b/LUA_GenDialog.cpp @@ -46,8 +46,7 @@ static int s_nType[MAX_CTRLS] ; static bool s_bOk = false ; // uscita con Ok static bool s_bCustomColorsInit = false ; // flag di inizializzazione colori custom static COLORREF s_CustomColors[16] = {12632256} ; // 16 colori GRAY -static bool s_bSelectionMode = false ; // se true allora diventa dialogo "Modeless" -static int s_nDlgItem = -1 ; // indice dell'Item di selezione +static int s_nDlgSelItem = -1 ; // indice dell'Item di selezione //----------------------------------------------------------------------------- static string @@ -92,18 +91,17 @@ StartSelectionMode( HWND hDlg, int nEditId) for ( int i = 0; i < s_nCtrls ; ++ i) { if ( s_nType[i] == CTRL_BUTTON) { int idEdit = IDC_EDIT1 + i ; - EnableWindow( GetDlgItem( hDlg, idEdit), ( idEdit == s_nDlgItem ? TRUE : FALSE)) ; + EnableWindow( GetDlgItem( hDlg, idEdit), ( idEdit == s_nDlgSelItem ? TRUE : FALSE)) ; } } // seleziono solo gli elementi presenti nell'edit corrispondente - s_nDlgItem = - 1 ; - ExeDeselectAll() ; // !<-- NB. avendo messo s_nDlgItem = -1 il testo non viene rimosso + s_nDlgSelItem = - 1 ; + ExeDeselectAll() ; // !<-- NB. avendo messo s_nDlgSelItem = -1 il testo non viene rimosso AtoWEX<128> wsEdit( "") ; GetDlgItemText( hDlg, nEditId, LPWSTR( wsEdit), 128) ; ValidateSelection( wstrztoA( wsEdit), true) ; - s_bSelectionMode = true ; - s_nDlgItem = nEditId ; + s_nDlgSelItem = nEditId ; ExeDraw() ; } @@ -116,8 +114,10 @@ StartSelectionMode( HWND hDlg, int nEditId) static void EndSelectionMode( HWND hDlg) { - s_bSelectionMode = false ; - s_nDlgItem = -1 ; + if ( s_nDlgSelItem == -1) + return ; + + s_nDlgSelItem = -1 ; // disabilito tutti gli edit associati ai BS for ( int i = 0; i < s_nCtrls ; ++ i) { @@ -133,7 +133,7 @@ EndSelectionMode( HWND hDlg) EnableWindow( hMain, FALSE) ; SetFocus( hDlg) ; // deseleziono tutto - ExeDeselectAll() ; //!<-- NB. avendo messo nDlgModelessItem = -1 il testo non viene rimosso + ExeDeselectAll() ; //!<-- NB. avendo messo s_nDlgSelItem = -1 il testo non viene rimosso ExeDraw() ; } @@ -200,17 +200,14 @@ CALLBACK UpdateDialogSelection( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara static void OnClosingDialog( HWND hwndDlg) { - // reset stato globale - s_bSelectionMode = false ; - s_nDlgItem = -1 ; + // chiudo eventuale selezione ancora attiva + EndSelectionMode( hwndDlg) ; // il controllo passa al Main HWND hMain = GetParent( hwndDlg) ; EnableWindow( hMain, TRUE) ; DestroyWindow( hwndDlg) ; s_hDlg = NULL ; SetFocus( hMain) ; - // deseleziono tutto - ExeDeselectAll() ; ExeDraw() ; } @@ -460,29 +457,21 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam if ( nId >= IDC_BUTTON_SEL1 && nId < IDC_BUTTON_SEL1 + MAX_CTRLS) { int nBtnId = nId ; int nEditId = IDC_EDIT1 + ( nId - IDC_BUTTON_SEL1) ; - // se il bottone premuto è lo stesso - if ( s_nDlgItem == nEditId) { - // se selezione attiva, allora deve terminare - if ( s_bSelectionMode) { - SetDlgItemText( hwndDlg, nBtnId, strztoW( "+")) ; - EndSelectionMode( hwndDlg) ; - } - // se selezione non attiva, allora viene attivata - else { - SetDlgItemText( hwndDlg, nBtnId, strztoW( "S")) ; - StartSelectionMode( hwndDlg, nEditId) ; - } + // se il bottone premuto è quello attivo, allora devo terminare la selezione + if ( s_nDlgSelItem == nEditId) { + SetDlgItemText( hwndDlg, nBtnId, strztoW( "+")) ; + EndSelectionMode( hwndDlg) ; } - // se nuovo buttone premuto + // se premuto nuovo bottone else { // se esisteva una selezione precedente, questa viene annullata - if ( s_nDlgItem != -1) { + if ( s_nDlgSelItem != -1) { // recupero il Button di selezione precedente e modifico il suo testo - int nPrevBtnId = IDC_BUTTON_SEL1 + ( s_nDlgItem - IDC_EDIT1) ; + int nPrevBtnId = IDC_BUTTON_SEL1 + ( s_nDlgSelItem - IDC_EDIT1) ; SetDlgItemText( hwndDlg, nPrevBtnId, strztoW( "+")) ; } // la selezione passa al comando corrente - s_nDlgItem = nEditId ; + s_nDlgSelItem = nEditId ; SetDlgItemText( hwndDlg, nBtnId, strztoW( "S")) ; // il dialogo diventa "Modeless" temporaneamente StartSelectionMode( hwndDlg, nEditId) ; @@ -492,14 +481,12 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam // --- se comando di Preview per brush di colori mediante click del mouse else if ( nCode == STN_CLICKED && nId >= IDC_COLOR1 && nId <= IDC_COLOR8) { - // se selezione attiva, allora deve terminare - if ( s_bSelectionMode) { - // se esisteva una selezione precedente, questa viene annullata - if ( s_nDlgItem != -1) { - // recupero il Button di selezione precedente e modifico il suo testo - int nPrevBtnId = IDC_BUTTON_SEL1 + ( s_nDlgItem - IDC_EDIT1) ; - SetDlgItemText( hwndDlg, nPrevBtnId, strztoW( "+")) ; - } + // se esisteva una selezione precedente, questa viene terminata + if ( s_nDlgSelItem != -1) { + // recupero il Button di selezione precedente e modifico il suo testo + int nPrevBtnId = IDC_BUTTON_SEL1 + ( s_nDlgSelItem - IDC_EDIT1) ; + SetDlgItemText( hwndDlg, nPrevBtnId, strztoW( "+")) ; + // esco dalla modalità selezione EndSelectionMode( hwndDlg) ; } int idx = nId - IDC_COLOR1 ; @@ -583,9 +570,9 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam } // se siamo in modalità di Selezione e il comando attivo non si riferisce ad un button di Selezione (SB), il dialogo torna modale - if ( s_bSelectionMode) { + if ( s_nDlgSelItem != -1) { bool bIsBS = ( nId >= IDC_BUTTON_SEL1 && nId < IDC_BUTTON_SEL1 + MAX_CTRLS) ; - bool bIsActiveEdit = ( nId == s_nDlgItem) ; + bool bIsActiveEdit = ( nId == s_nDlgSelItem) ; // il dialogo torna modale if ( ! bIsBS && ! bIsActiveEdit) EndSelectionMode( hwndDlg) ; @@ -603,12 +590,19 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam return FALSE ; } +//----------------------------------------------------------------------------- +bool +IsSelectionFromDialog( void) +{ + return ! ( s_hDlg == NULL || s_nDlgSelItem == -1) ; +} + //----------------------------------------------------------------------------- bool UpdateDialogIds( void) { // verifico presenza dialogo e item di selezione - if ( s_hDlg == NULL || s_nDlgItem == -1) + if ( s_hDlg == NULL || s_nDlgSelItem == -1) return false ; // recupero tutti gli elementi selezionati @@ -622,7 +616,7 @@ UpdateDialogIds( void) sIds.pop_back() ; // aggiorno il contenuto nel dialogo - return ( SetDlgItemText( s_hDlg, s_nDlgItem, stringtoW( sIds))) ; + return ( SetDlgItemText( s_hDlg, s_nDlgSelItem, stringtoW( sIds)) != FALSE) ; } //------------------------------------------------------------------------------- @@ -707,11 +701,13 @@ LuaDialogBox( lua_State* L) return 1 ; } + // disabilito log dei comandi + bool bPrevCmdLog = SetCmdLog( false) ; + // creazione di un dialogo Modeless HWND hMainWnd = ExeGetMainWindowHandle() ; s_bOk = false ; - s_bSelectionMode = false ; - s_nDlgItem = -1 ; + s_nDlgSelItem = -1 ; s_hDlg = ( CreateDialogParam( GetModuleIstance(), MAKEINTRESOURCE( IDD_LUADLG), hMainWnd, (DLGPROC)DialogBoxProc, NULL)) ; if ( s_hDlg == NULL) { LuaSetParam( L) ; @@ -734,12 +730,15 @@ LuaDialogBox( lua_State* L) if ( GetMessage( &msg, NULL, 0, 0) <= 0) break ; if ( ! IsDialogMessage( s_hDlg, &msg) && - ( ! s_bSelectionMode || PtInRect( &rctWnd, msg.pt) != FALSE)) { + ( s_nDlgSelItem == -1 || PtInRect( &rctWnd, msg.pt) != FALSE)) { TranslateMessage( &msg) ; DispatchMessage( &msg) ; } } + // ripristino stato precedente di log dei comandi + SetCmdLog( bPrevCmdLog) ; + // ritorno i valori lua if ( s_bOk) { STRVECTOR vRes ; diff --git a/LUA_GenDialog.h b/LUA_GenDialog.h index f2885f0..c7ec217 100644 --- a/LUA_GenDialog.h +++ b/LUA_GenDialog.h @@ -20,5 +20,8 @@ // Funzione implementazione DialogBox per lua int LuaDialogBox( lua_State* L) ; +// Funzione che restituisce stato selezione da dialogo +bool IsSelectionFromDialog( void) ; + // Funzione per passaggio di parametri tra Selezione DB e dialogo non modale bool UpdateDialogIds( void) ;