"OnKey Event" SAME AS "OnDblClick Event"

Moderator: Rathinagiri

Post Reply
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

"OnKey Event" SAME AS "OnDblClick Event"

Post by andyglezl »

Pudiera ser que el evento ON KEY dentro del Control GRID, tuviera disponibles los DATA, funcionando como el evento OnDblClick ?
----------------------------------------------------------------------------------------------------------------------------------------------------------
It may be that the ON KEY event within the GRID control, have available the DATA, functioning as the OnDblClick event?
Event OnDblClick Occurs when the user double clicks on the control
Syntax:
OnDblClick <ActionProcedure>

The following data are available at ‘OnDblClick’ procedure:

- This.CellRowIndex
- This.CellColIndex
- This.CellRow
- This.CellCol
- This.CellWidth
- This.CellHeight
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: "OnKey Event" SAME AS "OnDblClick Event"

Post by Rathinagiri »

Not only for Grid, it is now possible to do onkey event on any control!

Syntax:
CREATE EVENT PROCNAME cProcName [ HWND hWnd ] [ MSG nMsg ] [ STOREINDEX nIndex ]

For example, I have enabled anywhere searching in ComboBox with the following code:

See this:

Code: Select all

Create Event ProcName _ComboBoxAnywhereSearch( 'accounts', 'txn' ) HWND GetControlHandle ( 'accounts', 'txn' )
TXN is form name and accounts is combobox name.

Code: Select all

#include <hmg.ch>


function _ComboBoxAnywhereSearchInit( lShowLabel )
   if .not. __mvexist( '_cComboSearchString' )
      public _cComboSearchString := ''
   endif
   if lShowLabel
      if .not. iscontroldefined( _combolabel, &( thiswindow.name ) )
         define label _combolabel
            parent &(thiswindow.name) 
            row this.row - 30
            col this.col 
            width this.width 
            backcolor { 0, 0, 255 }
            fontcolor { 255, 255, 255 }
            fontname this.fontname
            fontsize 14
            fontbold .t.
            autosize .t.
         end label
      endif         
   endif   
   return nil
    
function _ComboBoxAnywhereSearchClose( )
   if __mvexist( '_cComboSearchString' )
      _cComboSearchString := ''
   endif
   if iscontroldefined( _combolabel, &(thiswindow.name))
      domethod( thiswindow.name, '_combolabel', 'RELEASE' )
   endif
   return nil
   
function _ComboBoxAnywhereSearch( cComboName, cWindowName )
   local lFound := .f.
   local nEventMsg := EventMsg()
   local ch
   local nVKDown := HMG_GetLastVirtualKeyDown()
   
   ch := HMG_GetLastCharacter()
   HMG_CleanLastCharacter( .t. )

   do case
   case nVKDown == VK_BACK   //   backspace
      HMG_CleanLastVirtualKeyDown()
      _cComboSearchString := HB_ULEFT( _cComboSearchString, max( 0, ( HMG_Len( _cComboSearchString ) - 1 ) ) )
      _ComboBoxAnywhereSearchUpdate( cWindowName )
   case nVKDown == VK_UP .or. nVKDown ==  VK_DOWN 
      HMG_CleanLastVirtualKeyDown()
      if hmg_len( _cComboSearchString ) == 0
         return nil
      else
         nLineNo := getproperty( cWindowName, cComboName, 'VALUE' )
         if nVKDown == VK_UP
            lFound := .f.
            for i := nLineNo - 1 to 1 step - 1
               // first check in the starting chars...
               if  hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
                  lFound := .t.
                  setproperty( cWindowName, cComboName, 'VALUE', i )
                  exit
               endif  
            next i   
            if .not. lFound // anywhere searching...
               for i := nLineNo - 1 to 1 step - 1
                  if  HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) )  ) > 0
                     lFound := .t.
                     setproperty( cWindowName, cComboName, 'VALUE', i )
                     exit
                  endif  
               next i         
            endif   
            if .not. lFound
               playbeep()
            endif                 
         else // down key search for next   
            lFound := .f.
            for i := nLineNo + 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
               // first check in the starting chars...
               if  hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
                  lFound := .t.
                  setproperty( cWindowName, cComboName, 'VALUE', i )
                  exit
               endif  
            next i   
            if .not. lFound // anywhere searching...
               for i := nLineNo + 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
                  if  HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) )  ) > 0
                     lFound := .t.
                     setproperty( cWindowName, cComboName, 'VALUE', i )
                     exit
                  endif  
               next i         
            endif   
            if .not. lFound
               playbeep()
            endif                 
         endif
         return 1 
      endif   
   case nVKDown == VK_ESCAPE
      HMG_CleanLastVirtualKeyDown()
      _cComboSearchString := ''
      _ComboBoxAnywhereSearchUpdate( cWindowName )
      return 1
   case nVKDown ==  VK_RIGHT .or. nVKDown ==  VK_LEFT .or. nVKDown ==  VK_HOME .or. nVKDown ==  VK_END  
      HMG_CleanLastVirtualKeyDown()
      _cComboSearchString := ''
      _ComboBoxAnywhereSearchUpdate( cWindowName )
      return nil
   case EventIsMouseMessage () 
      HMG_CleanLastVirtualKeyDown()
//      _cComboSearchString := ''
      _ComboBoxAnywhereSearchUpdate( cWindowName )
      return nil
   otherwise
      IF nEventMsg <> WM_CHAR
         Return Nil   // enable processing the current message
      ENDIF
      _cComboSearchString := _cComboSearchString + ch
      _ComboBoxAnywhereSearchUpdate( cWindowName )
   endcase

   lFound := .f.
   for i := 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
      // first check in the starting chars...
      if  hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
         lFound := .t.
         setproperty( cWindowName, cComboName, 'VALUE', i )
         exit
      endif  
   next i   
   if .not. lFound // anywhere searching...
      for i := 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
         if  HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) )  ) > 0
            lFound := .t.
            setproperty( cWindowName, cComboName, 'VALUE', i )
            exit
         endif  
      next i         
   endif   
   if .not. lFound
      playbeep()
      _cComboSearchString := HB_ULEFT( _cComboSearchString, max( 0, ( HMG_Len( _cComboSearchString ) - 1 ) ) )
      _ComboBoxAnywhereSearchUpdate( cWindowName )
   endif      
   return 1


function _ComboBoxAnywhereSearchUpdate( cWindowName )   
   if iscontroldefined( _combolabel, &cWindowName )
      setproperty( cWindowName, '_combolabel', 'VALUE', _cComboSearchString )
   endif
return nil
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: "OnKey Event" SAME AS "OnDblClick Event"

Post by andyglezl »

Gracias Rathinagiri, lo voy a probar...
----------------------------------------------------
Rathinagiri thanks, I'll try ...
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

"OnKey Event" SAME AS "OnDblClick Event"

Post by Pablo César »

Hola Andrés,

Después de haber verificado tu cuestionamiento sobre ONKEY en Grids en hmgdoc, abri una nueva página que faltaba en Events y este es específico para Grids. Fijate si esto te ayuda:
Screen1.png
Screen1.png (61.85 KiB) Viewed 3498 times
A respecto de las funciones HMG_GetLastVirtualKeyDown() y HMG_CleanLastVirtualKeyDown(), poderás encontrar en: Advanced / Read Keyboard and Mouse

Gracias a la participación de los usuários, podemos mejorar la documentacion para ser más clara y precisa.

Un abrazo,
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: "OnKey Event" SAME AS "OnDblClick Event"

Post by andyglezl »

Hola Pablo Cesar

Si, es lo que encontré y añadí al post que envié. viewtopic.php?f=20&t=4103&p=41661#p41661
Gracias
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: "OnKey Event" SAME AS "OnDblClick Event"

Post by andyglezl »

Hola Rathinagiri

Tratando de entender tu ejemplo con el "Create Event", hice lo siguiente: (pero no se si así es como deba funcionar)

* Siempre encuentra el primer registro "fer" pero existen 2
* Puse "ON INIT _ComboBoxAnywhereSearchInit( .f. )" para hacer la llamada a esta función // Pero da ERROR si pongo .T.
* Si pongo la propiedad SORT, me da ERROR
* En que momento se hace la llamada a la "funcion _ComboBoxAnywhereSearchClose( )"
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello Rathinagiri

Trying to understand your example with the "Create Event", I did the following: (but not if this is how it should work)

* Always find the first record "fer" but there are two
* Put "ON INIT _ComboBoxAnywhereSearchInit (.f.)" To make the call to this function // But fails if I put .T.
* If you get the property SORT gives me ERROR
* At what point it is the call to "_ComboBoxAnywhereSearchClose() function"
CreateEvent.jpg
CreateEvent.jpg (156.78 KiB) Viewed 3461 times

Code: Select all

#include <hmg.ch>

PROCEDURE Main()
	PUBLIC aRows [21], _cComboSearchString := ''		//	ERROR if it is not defined

	aRows [1]    := "Simpson	 Homer  	555-5555"
	aRows [2]    := "Mulder 	 Fox		324-6432"
	aRows [3]    := "Smart		 Max		432-5892"
	aRows [4]    := "Grillo		 Pepe		894-2332"
	aRows [5]    := "Kirk		 James		346-9873"
	aRows [6]    := "Barriga	 Carlos		394-9654"
	aRows [7]    := "Flanders	 Ned		435-3211"
	aRows [8]    := "Smith		 John		123-1234"
	aRows [9]    := "Pedemonti	 Flavio		000-0000"
	aRows [10]   := "Gomez		 Juan		583-4832"
	aRows [11]   := "Fernandez	 Raul		321-4332"
	aRows [12]   := "Borges		 Javier		326-9430"
	aRows [13]   := "Alvarez	 Alberto	543-7898"
	aRows [14]   := "Gonzalez	 Ambo		437-8473"
	aRows [15]   := "Batistuta	 Gol		485-2843"
	aRows [16]   := "Vinazzi	 Amigo		394-5983"
	aRows [17]   := "Pedemonti	 Flavio		534-7984"
	aRows [18]   := "Samarbide	 Armando	854-7873"
	aRows [19]   := "Pradon		 Alejandra	???-????"
	aRows [20]   := "Reyes		 Monica		432-5836"
	aRows [21]   := "Fernández	 two		000-0000"

	DEFINE WINDOW txn AT 0,0 WIDTH 640 HEIGHT 480 TITLE 'CREATE EVENT TEST' MAIN ON INIT _ComboBoxAnywhereSearchInit( .f. )		// if .t.  ERROR

		@ 010, 010  COMBOBOX accounts ITEMS aRows VALUE 1 WIDTH 300 HEIGHT 200 FONT "Verdana" SIZE 12 TOOLTIP "cToolTipText" DROPPEDWIDTH 350 DISPLAYEDIT	//  SORT  <=== ERROR 
		
            *[ ON GOTFOCUS <OnGotFocusProcedur> | <bBlock> ]
            *[ ON CHANGE <OnChangeProcedure> | <bBlock> ]
            *[ ON LOSTFOCUS <OnLostFocusProcedure> | <bBlock> ]
            *[ ON ENTER <OnEnterProcedure> | <bBlock> ]
            *[ ON DISPLAYCHANGE <OnDisplayChangeProcedure> | <bBlock> ]
            *[ ON DROPDOWN <OnDropDownProcedure> | <bBlock> ]
            *[ ON CLOSEUP <OnCloseUpProcedure> | <bBlock> ]
            *[ IMAGE <acImageNames> ] 
            *[ ON CANCEL <OnCancelProcedure> | <bBlock>  ] 
            *[ NOTRANSPARENT ]
 
	END WINDOW 
	Create Event ProcName _ComboBoxAnywhereSearch( 'accounts', 'txn' ) HWND GetControlHandle ( 'accounts', 'txn' )
	TXN.CENTER
	TXN.ACTIVATE
RETURN nil

FUNCTION _ComboBoxAnywhereSearchInit( lShowLabel )
	if .not. __mvexist( '_cComboSearchString' )
		public _cComboSearchString := ''
	endif
	if lShowLabel
		if .not. iscontroldefined( _combolabel, &( thiswindow.name ) )
			define label _combolabel
				parent &(thiswindow.name) 
				row this.row - 30
				col this.col 
				width this.width 
				backcolor { 0, 0, 255 }
				fontcolor { 255, 255, 255 }
				fontname this.fontname				// 	ERROR	when lShowLabel = .t.
				fontsize 14
				fontbold .t.
				autosize .t.
			end label
		endif         
	endif   
RETURN nil
    
FUNCTION _ComboBoxAnywhereSearchClose( )			//  when it called ?
	if __mvexist( '_cComboSearchString' )
		_cComboSearchString := ''
	endif
	if iscontroldefined( _combolabel, &(thiswindow.name))
		domethod( thiswindow.name, '_combolabel', 'RELEASE' )
	endif
RETURN nil
   
FUNCTION _ComboBoxAnywhereSearch( cComboName, cWindowName )
	local lFound := .f.
	local nEventMsg := EventMsg()
	local ch
	local nVKDown := HMG_GetLastVirtualKeyDown()
   
	ch := HMG_GetLastCharacter()
	HMG_CleanLastCharacter( .t. )

	do case
	
		case nVKDown == VK_BACK   //   backspace
			HMG_CleanLastVirtualKeyDown()
			_cComboSearchString := HB_ULEFT( _cComboSearchString, max( 0, ( HMG_Len( _cComboSearchString ) - 1 ) ) )
			_ComboBoxAnywhereSearchUpdate( cWindowName )
			
		case nVKDown == VK_UP .or. nVKDown ==  VK_DOWN
			HMG_CleanLastVirtualKeyDown()
			if hmg_len( _cComboSearchString ) == 0
				return nil
			else
				nLineNo := getproperty( cWindowName, cComboName, 'VALUE' )
				if nVKDown == VK_UP
					lFound := .f.
					for i := nLineNo - 1 to 1 step - 1
						// first check in the starting chars...
						if  hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
							lFound := .t.
							setproperty( cWindowName, cComboName, 'VALUE', i )
							exit
						endif  
					next i   
					if .not. lFound // anywhere searching...
						for i := nLineNo - 1 to 1 step - 1
							if  HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) )  ) > 0
								lFound := .t.
								setproperty( cWindowName, cComboName, 'VALUE', i )
								exit
							endif  
						next i         
					endif   
					if .not. lFound
						playbeep()
					endif                 
				else // down key search for next   
					lFound := .f.
					for i := nLineNo + 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
						// first check in the starting chars...
						if  hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
							lFound := .t.
							setproperty( cWindowName, cComboName, 'VALUE', i )
							exit
						endif  
					next i   
					if .not. lFound // anywhere searching...
						for i := nLineNo + 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
							if  HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) )  ) > 0
								lFound := .t.
								setproperty( cWindowName, cComboName, 'VALUE', i )
								exit
							endif  
						next i         
					endif   
					if .not. lFound
						playbeep()
					endif                 
				endif
				return 1 
			endif   
		case nVKDown == VK_ESCAPE
			HMG_CleanLastVirtualKeyDown()
			_cComboSearchString := ''
			_ComboBoxAnywhereSearchUpdate( cWindowName )
			return 1
		case nVKDown ==  VK_RIGHT .or. nVKDown ==  VK_LEFT .or. nVKDown ==  VK_HOME .or. nVKDown ==  VK_END  
			HMG_CleanLastVirtualKeyDown()
			_cComboSearchString := ''
			_ComboBoxAnywhereSearchUpdate( cWindowName )
			return nil
		case EventIsMouseMessage () 
			HMG_CleanLastVirtualKeyDown()
//			  _cComboSearchString := ''
			_ComboBoxAnywhereSearchUpdate( cWindowName )
			return nil
	otherwise
		IF nEventMsg <> WM_CHAR
			Return Nil   // enable processing the current message
		ENDIF
		_cComboSearchString := _cComboSearchString + ch
		_ComboBoxAnywhereSearchUpdate( cWindowName )
	endcase

	lFound := .f.
	for i := 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
		// first check in the starting chars...
		if  hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
			lFound := .t.
			setproperty( cWindowName, cComboName, 'VALUE', i )
			exit
		endif  
	next i   
	if .not. lFound // anywhere searching...
		for i := 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
			if  HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) )  ) > 0
				lFound := .t.
				setproperty( cWindowName, cComboName, 'VALUE', i )
				exit
			endif  
		next i         
	endif   
	if .not. lFound
		playbeep()
		_cComboSearchString := HB_ULEFT( _cComboSearchString, max( 0, ( HMG_Len( _cComboSearchString ) - 1 ) ) )
		_ComboBoxAnywhereSearchUpdate( cWindowName )
	endif      
RETURN 1


FUNCTION _ComboBoxAnywhereSearchUpdate( cWindowName )   
	if iscontroldefined( _combolabel, &cWindowName )
		setproperty( cWindowName, '_combolabel', 'VALUE', _cComboSearchString )
	endif
RETURN nil
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply