define window_1 as 'owner' of window_2

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
Anand
Posts: 314
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 62 times
Been thanked: 44 times

define window_1 as 'owner' of window_2

Post by Anand » Wed Sep 12, 2018 4:15 pm

Dear Members,

I have main window. It opens entry window, which further opens sub-entry window, which also may open another pop-up window, etc.
In short one window opens another and so on. This is real scenario in my live application to client.

2018-09-12_133249.png
2018-09-12_133249.png (141.63 KiB) Viewed 402 times

Now I want that when one window_1 opens another window_2, itself (window_1) should remain disabled, i.e. no mouse click should work on it. I can achieve same using 'modal' clause but I do not want that as I may open two window at same time as related information and allow user to click one and refresh in another.

In another programing language I can define window_1 as 'owner' of window_2 and it (window_1) gets auto disabled. Is there anything similar in hmg ?

I have attached sample codes which I used to try the same. I have used both hmg and minigui logic.

Regards,

Anand
Attachments
win_test.zip
(140.51 KiB) Downloaded 17 times
Image

User avatar
gfilatov
Posts: 573
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 14 times
Been thanked: 136 times
Contact:

Post by gfilatov » Wed Sep 12, 2018 6:06 pm

Anand wrote:
Wed Sep 12, 2018 4:15 pm
Dear Members,
...
In another programing language I can define window_1 as 'owner' of window_2 and it (window_1) gets auto disabled. Is there anything similar in hmg ?
Dear Anand,

It is possible in the Minigui Ex with using OOP mode.

I've attached your updated sample for your review.

Hope give you some idea. :idea:
Attachments
win_test_2.zip
Sample for Minigui Ex with using command SET OOP ON
(1.15 KiB) Downloaded 23 times
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Thu Sep 13, 2018 8:29 am

I have two solutions:
First, by disabling the availability of the "owner" window:

Code: Select all

#include "hmg.ch"

proc main
	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'Test';
		MAIN

      DEFINE MAIN MENU
              POPUP 'Standard'
                ITEM 'Open Window' ACTION {|| DoWindow2() } 
              END POPUP
      END MENU

      DEFINE BUTTON B_OK
        ROW    20
        COL    30
        WIDTH  100
        HEIGHT 28
        ACTION Msgbox('OK')
        CAPTION "OK"
    END BUTTON
      
	END WINDOW

	activate window Form_1
retu

//*****************************************************************************
func DoWindow2()
Local cOwnerFormName:=ThisWindow.Name, cOwnerFormTitle:=ThisWindow.Title
	DEFINE WINDOW Form_2 ;
		AT 0,0 ;
		WIDTH 600 HEIGHT 400 ;
		TITLE 'Win 2' ;
		ON INIT ( SetProperty( cOwnerFormName, "Enabled", .F.), SetProperty( cOwnerFormName, "Title", cOwnerFormTitle + " - Disabled") ) ; 
		ON RELEASE ( SetProperty( cOwnerFormName, "Enabled", .T.), SetProperty( cOwnerFormName, "Title", cOwnerFormTitle) ) ;

		@ 20,40 BUTTON Button_2 caption 'Win 3' WIDTH 100 HEIGHT 20 ACTION {|| DoWindow3() }

	END WINDOW

	activate window Form_2
return

//*****************************************************************************
func DoWindow3()
Local cOwnerFormName:=ThisWindow.Name, cOwnerFormTitle:=ThisWindow.Title
	DEFINE WINDOW Form_3 ;
		AT 0,0 ;
		WIDTH 600 HEIGHT 400 ;
		TITLE 'Win 3' ;
		ON INIT ( SetProperty( cOwnerFormName, "Enabled", .F.), SetProperty( cOwnerFormName, "Title", cOwnerFormTitle + " - Disabled") ) ; 
		ON RELEASE ( SetProperty( cOwnerFormName, "Enabled", .T.), SetProperty( cOwnerFormName, "Title", cOwnerFormTitle) ) ;

		@ 50,100 BUTTON Button_2 caption 'OK' WIDTH 100 HEIGHT 20 ACTION {|| MsgBox('OK') }

	END WINDOW

	activate window Form_3
return
************************************************************************************
Second, by switching off all events in the "owner" window:

Code: Select all

#include "hmg.ch"

MEMVAR _HMG_SYSDATA

proc main
	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'Test';
		MAIN

      DEFINE MAIN MENU
              POPUP 'Standard'
                ITEM 'Open Window' ACTION {|| DoWindow2() } 
              END POPUP
      END MENU

      DEFINE BUTTON B_OK
        ROW    20
        COL    30
        WIDTH  100
        HEIGHT 28
        ACTION Msgbox('OK')
        CAPTION "OK"
      END BUTTON
      
	END WINDOW

	activate window Form_1
retu

//*****************************************************************************
func DoWindow2()
Local cOwnerFormName:=ThisWindow.Name
	DEFINE WINDOW Form_2 ;
		AT 0,0 ;
		WIDTH 600 HEIGHT 400 ;
		TITLE 'Win 2' ;
		ON INIT StopEvents( cOwnerFormName, .T. ) ;
		ON RELEASE StopEvents( cOwnerFormName, .F. )

		@ 20,40 BUTTON Button_2 caption 'Win 3' WIDTH 100 HEIGHT 20 ACTION {|| DoWindow3() }

	END WINDOW

	activate window Form_2
return

//*****************************************************************************
func DoWindow3()
Local cOwnerFormName:=ThisWindow.Name
	DEFINE WINDOW Form_3 ;
		AT 0,0 ;
		WIDTH 600 HEIGHT 400 ;
		TITLE 'Win 3' ;
		ON INIT StopEvents( cOwnerFormName, .T. ) ;
		ON RELEASE StopEvents( cOwnerFormName, .F. )

		@ 50,100 BUTTON Button_2 caption 'OK' WIDTH 100 HEIGHT 20 ACTION {|| MsgBox('OK') }

	END WINDOW

	activate window Form_3
return


************************************************************************************
Function StopEvents( cForm, lStop )
Local hWnd, hCtrWnd, nPos

DEFAULT cForm := '', lStop := .F.
IF !hb_IsLogical( lStop )
	lStop := .F.
ENDIF
IF EMPTY( cForm ) .OR. !_isWindowDefined( cForm )
	RETURN Nil
ENDIF

hWnd := GetFormHandle( cForm )

StopWindowEventProcedure (cForm, lStop)
AEVAL( _HMG_SYSDATA[ 4 ], { | hCtrWnd, nPos | IF( hCtrWnd == hWnd, _HMG_StopControlEventProcedure [nPos]:= lStop, Nil ) } )

Return Nil

User avatar
Anand
Posts: 314
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 62 times
Been thanked: 44 times

Post by Anand » Thu Sep 13, 2018 9:59 am

Grigory and Edk thanks for the solution.

Edk's 1st solution disables the parent window completely, i.e. no mouse click works. Solves my problem.
Edk's 2nd solution allows mouse click and sets window back to focus but further click does not work. This does not solve as parent window now blocks the called window.

Grigory solution looks advance to me. I am bit novice in understanding the codes used. Though mouse click on parent works but window remains in background. This I will have to further study and understand to use in my codes.

Since my live application is in MiniGUI, compiling the Edk's 1st solution with minigui does not work. Grigory please guide me what changes I need to do to compile it in minigui ?

Regards,

Anand
Image

User avatar
gfilatov
Posts: 573
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 14 times
Been thanked: 136 times
Contact:

Post by gfilatov » Sat Sep 15, 2018 4:44 pm

Anand wrote:
Thu Sep 13, 2018 9:59 am
...
Grigory please guide me what changes I need to do to compile it in minigui ?

Regards,

Anand
Dear Anand,

Thanks for your request!

I've added the following description in the current change log:
* Updated: Synchronized Extended HMG for compatibility with Official HMG:
Added the set/get 'Enabled' property for the forms:
- ThisWindow|<FormName>.Enabled [ := | --> ] lBoolean
Your updated sample for a next build is below:

Code: Select all

#include "hmg.ch"

PROCEDURE main

   LOCAL cActiveFormName := 'Form_2'

   DEFINE WINDOW Form_1 ;
      AT 0, 0 ;
      WIDTH 640 HEIGHT 480 ;
      TITLE 'Main Window';
      MAIN

   DEFINE MAIN MENU
      POPUP 'Child Window'
         ITEM 'Open Win 2' ACTION {|| DoWindow2() }
      END POPUP
   END MENU

   DEFINE BUTTON B_OK
      ROW    20
      COL    30
      WIDTH  100
      HEIGHT 28
      ACTION Msgbox( 'OK' )
      CAPTION "OK"
   END BUTTON

   DEFINE TIMER T_1 INTERVAL 250 ACTION SetProperty( ThisWindow.Name, "Enabled", ( _IsWindowActive( cActiveFormName ) == .F. ) )

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

RETURN

*****************************************************************************
PROCEDURE DoWindow2()

   LOCAL cActiveFormName := 'Form_3'
   LOCAL cOwnerFormName := ThisWindow.Name, cOwnerFormTitle := ThisWindow.Title

   DEFINE WINDOW Form_2 ;
      AT App.Row + 30, App.Col + 30 ;
      WIDTH 600 HEIGHT 400 ;
      TITLE 'Win 2' ;
      CHILD ;
      ON INIT ( SetProperty( cOwnerFormName, "Title", cOwnerFormTitle + " - Disabled" ) ) ;
      ON RELEASE ( SetProperty( cOwnerFormName, "Title", cOwnerFormTitle ) ) ;

      @ 20, 40 BUTTON Button_2 caption 'Child Win 3' WIDTH 100 HEIGHT 28 ACTION {|| DoWindow3() }

   DEFINE TIMER T_1 INTERVAL 250 ACTION SetProperty( ThisWindow.Name, "Enabled", ( _IsWindowActive( cActiveFormName ) == .F. ) )

   END WINDOW

   ACTIVATE WINDOW Form_2

RETURN

*****************************************************************************
PROCEDURE DoWindow3()

   LOCAL cOwnerFormName := ThisWindow.Name, cOwnerFormTitle := ThisWindow.Title

   DEFINE WINDOW Form_3 ;
      AT App.Row + 60, App.Col + 60 ;
      WIDTH 600 HEIGHT 400 ;
      TITLE 'Win 3' ;
      CHILD ;
      ON INIT ( SetProperty( cOwnerFormName, "Title", cOwnerFormTitle + " - Disabled" ) ) ;
      ON RELEASE ( SetProperty( cOwnerFormName, "Enabled", .T. ), SetProperty( cOwnerFormName, "Title", cOwnerFormTitle ), ;
         DoMethod( cOwnerFormName, "setFocus" ) )

   @ 50, 100 BUTTON Button_2 caption 'OK' WIDTH 100 HEIGHT 28 ACTION {|| MsgBox( 'OK' ) }

   END WINDOW

   ACTIVATE WINDOW Form_3

RETURN
***********************************************************************************
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

User avatar
Anand
Posts: 314
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 62 times
Been thanked: 44 times

Post by Anand » Sun Sep 16, 2018 11:27 am

Thanks Grigory.

Waiting for the next build :)

Regards,

Anand
Image

User avatar
Anand
Posts: 314
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 62 times
Been thanked: 44 times

Post by Anand » Sat Sep 29, 2018 5:52 pm

MiniGUI 18.09 supports 'enabled' for form now and it is working same as HMG.

Thank you Grigory.

Regards,

Anand
Image

Post Reply