Page 3 of 6

Re: Incremental Search with Combo Box

Posted: Sun May 03, 2009 2:16 pm
by Rathinagiri
Hi Esgici,

I had modified/developed some code for up/down/enter keys. Kindly try this.

Code: Select all

/*
  

  CSBox ( Combined Search Box ) try


*/

#include "minigui.ch"

PROC Main()

set navigation extended
   aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
   
   ASORT( aCountries )                    // This Array MUST be sorted
       
   DEFINE WINDOW frmCSBTest ;
      AT 0,0 ;
      WIDTH 550 ;
      HEIGHT 300 ;
      TITLE 'CSBox ( Combined Search Box ) Test' ;
      MAIN ;
      ON INIT MakeCSBs()
      
      ON KEY ESCAPE ACTION frmCSBTest.Release
      
     @ 55, 190 TEXTBOX txbMessy
   
   END WINDOW // frmCSBTest
   
   frmCSBTest.Center
   
   frmCSBTest.Activate

      
RETU // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.


PROC MakeCSBs()                           // Making CSBox(s)

   DefnCSBox( ThisWindow.Name, 'Country',;         // Names suffix
                               'Country Name :',;  // Prompt
                               25,;                // CSBox Box Row No 
                               100,;               // CSBox Box Col No 
                               200,;               // Text Box Width  
                               20,;                // Text Box Height 
                               aCountries )   
                               
   frmCSBTest.TxBCountry.SetFocus()
   
RETU // MakeCSBs()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC DefnCSBox( ;                           // Define a CSBox  
              cFrmName,;    // Form / Window Name
              cCSBName,;    // CSBox Name
              cLblValu,;    // Prompt
              nCSBRow,;     // CSBox Row No
              nCSBCol,;     // CSBox Col No   
              nTxBWidth,;   // Text Box Width
              nTxBHeight,;  // Text Box Height
              aArray )      // Search array  
              
    Public cLblName := "Lbl" + cCSBName,;
          cTxBName := "TxB" + cCSBName,;
          cLsBName := "LsB" + cCSBName,;
          nLblWidt := 0,;
          nTxBCol  := 0,; 
          nLsBRow  := 0    
    DEFINE LABEL &cLblName  
       PARENT    &cFrmName
       ROW        nCSBRow
       COL        nCSBCol
       HEIGHT     nTxBHeight
       VALUE      cLblValu
       RIGHTALIGN .T.
       AUTOSIZE   .T.
    END LABEL // &lblName      

    nLblWidt := GetProperty( cFrmName, cLblName, "WIDTH" ) 
    nTxBCol  := nCSBCol + nLblWidt + 5
 
    DEFINE TEXTBOX &cTxBName 
       PARENT   &cFrmName
       ROW      nCSBRow - 2
       COL      nTxBCol
       WIDTH    nTxBWidth
       HEIGHT   nTxBHeight
       ongotfocus CSBoxGotFocus()
       onenter CloseCsBox()
       onlostfocus CSBoxLostFocus()
       ONCHANGE SetCSBoxVal( cFrmName, this.name , aArray )
    END TEXTBOX // &cTxBName   

    nLsBRow := GetProperty( cFrmName, cTxBName, "ROW" ) + nTxBHeight - 1
       
    DEFINE LISTBOX &cLsBName
       PARENT   &cFrmName
       COL      nTxBCol
       ROW      nLsBRow 
       WIDTH    nTxBWidth
       HEIGHT   200
       ITEMS    {}
    END LISTBOX
    
    SetProperty( cFrmName, cLsBName, "VISIBLE", .F. )
    
RETU // DefnCSBox()   
   
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC SetCSBoxVal( ;                       // Setting CSBox values
                  cFrmName,;   // Form / Windows name 
                  cTxBName,;   // Text Box Name 
                  aList )      // Items list 
   
   LOCAL cCurval  := GetProperty( cFrmName, cTxBName, "Value" ),;
         nFrmHeig := GetProperty( cFrmName, "HEIGHT" ),;
         aResults := {},;
         n1Result := 0,;
         cLsBName := "LsB" + SUBSTR( cTxBName, 4 ),;
         c1Found  := '',;
         cMethod  := '',;
         lNoResult := .F.
  
          
    IF !EMPTY( cCurval ) 
       WHILE ( n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )}, n1Result + 1 ) )  > 0  ;
             .AND. n1Result < LEN( aList )
          AADD( aResults, aList[ n1Result ] )
       ENDDO
       IF !EMPTY( aResults )
       
          nLsBRow  := GetProperty( cFrmName, cLsBName, "ROW" )
          nLsBCol  := GetProperty( cFrmName, cLsBName, "COL" )
          nLsBLeng := GetProperty( cFrmName, cLsBName, "WIDTH" )
          
          nLsBHeig := MAX( MIN( LEN( aResults ) * 15,  nFrmHeig - nLsBRow - 40 ), 20 )  
          
          DoMethod( cFrmName, cLsBName, "Release" ) 
          
          for i := 1 to len(_hmg_sysdata[1])
           
             
                if ((_hmg_sysdata[18,i] > nLsBRow .and. _hmg_sysdata[18,i] < nLsBRow + nLsBHeig) .or. (_hmg_sysdata[18,i]+_hmg_sysdata[21,i] > nLsBRow .and. _hmg_sysdata[18,i]+_hmg_sysdata[21,i] < nLsBRow + nLsBHeig)) .and. ((_hmg_sysdata[19,i] > nLsBCol .and. _hmg_sysdata[19,i] < nLsBCol + nLsBLeng) .or. (_hmg_sysdata[19,i]+_hmg_sysdata[20,i] > nLsBCol .and. _hmg_sysdata[19,i]+_hmg_sysdata[20,i] < nLsBCol + nLsBLeng)) .and. _hmg_sysdata[4,i] == GetFormHandle(CFrmName)
					setproperty(cFrmName,_hmg_sysdata[2,i],"VISIBLE",.f.)
                endif
             
          next i
          
          DEFINE LISTBOX &cLsBName
             PARENT     &cFrmName
             ROW        nLsBRow
             COL        nLsBCol 
             WIDTH      nLsBLeng
             HEIGHT     nLsBHeig
             ITEMS      aResults
             VALUE      1 
             ONDBLCLICK {||SetProperty( cFrmName, cTxBName, "VALUE", this.item( this.value ) ),;
						   SetProperty( cFrmName, cLsBName, "VISIBLE", .F. ),;
					       CSBoxSearchOver()}
          END LISTBOX
                     
          SetProperty( cFrmName, cLsBName, "VISIBLE", .T. )
          
       ELSE 
          lNoResult := .T.
       ENDIF !EMPTY( aResults )
    ELSE   
       lNoResult := .T.
    ENDIF !EMPTY( cCurval ) 
    
    IF lNoResult
       SetProperty( cFrmName, cLsBName, "VISIBLE", .F. )
    ENDIF

RETU // SetCSBoxVal()   
   
function CSBoxSearchOver()
Local nLsBRow := this.row
Local nLsBCol := this.col
Local nLsBLeng := this.width
Local nLsBHeig := this.height
Local cFrmname := thiswindow.name

          for i := 1 to len(_hmg_sysdata[1])
           
             
                if ((_hmg_sysdata[18,i] > nLsBRow .and. _hmg_sysdata[18,i] < nLsBRow + nLsBHeig) .or. (_hmg_sysdata[18,i]+_hmg_sysdata[21,i] > nLsBRow .and. _hmg_sysdata[18,i]+_hmg_sysdata[21,i] < nLsBRow + nLsBHeig)) .and. ((_hmg_sysdata[19,i] > nLsBCol .and. _hmg_sysdata[19,i] < nLsBCol + nLsBLeng) .or. (_hmg_sysdata[19,i]+_hmg_sysdata[20,i] > nLsBCol .and. _hmg_sysdata[19,i]+_hmg_sysdata[20,i] < nLsBCol + nLsBLeng)) .and. _hmg_sysdata[4,i] == GetFormHandle(CFrmName)
					setproperty(cFrmName,_hmg_sysdata[2,i],"VISIBLE",.t.)
                endif
             
          next i


return nil

function CSBoxGotFocus
local cFrmName := thiswindow.name
on key UP of &cFrmName action CSBoxDoUpKey()
on key DOWN of &cFrmName action CSBoxDoDownKey()
return nil

function CSBoxDoUpKey
local cFrmName := thiswindow.name
if iscontroldefined(&cLsBName,&cFrmName)
   if getproperty(cFrmName,cLsBName,"VALUE") > 1
      setproperty(cFrmName,cLsBName,"VALUE",getproperty(cFrmName,cLsBName,"VALUE")-1)
   endif
endif
return nil

function CSBoxDoDownKey
local cFrmName := thiswindow.name
if iscontroldefined(&cLsBName,&cFrmName)
   if getproperty(cFrmName,cLsBName,"VALUE") < getproperty(cFrmName,cLsBName,"ITEMCOUNT")
      setproperty(cFrmName,cLsBName,"VALUE",getproperty(cFrmName,cLsBName,"VALUE")+1)
   endif
endif
return nil


function CloseCsBox
local cFrmName := thiswindow.name
Local nLsBRow := 0
Local nLsBCol := 0
Local nLsBLeng := 0
Local nLsBHeig := 0

if iscontroldefined(&cLsBName,&cFrmName)
   nLsBRow := getproperty(cFrmName,cLsBName,"ROW")
   nLsBCol := getproperty(cFrmName,cLsBName,"COL")
   nLsBHeig := getproperty(cFrmName,cLsBName,"HEIGHT")
   nLsBLeng := getproperty(cFrmName,cLsBName,"WIDTH")

   if getproperty(cFrmName,cLsBName,"VALUE") > 0
	  SetProperty(cFrmName,cTxBName, "VALUE", getproperty(cFrmName,cLsBName,"ITEM",getproperty(cFrmName,cLsBName,"VALUE")) )
	  SetProperty(cFrmName,cLsBName, "VISIBLE", .F. )
   endif
   for i := 1 to len(_hmg_sysdata[1])
      if ((_hmg_sysdata[18,i] > nLsBRow .and. _hmg_sysdata[18,i] < nLsBRow + nLsBHeig) .or. (_hmg_sysdata[18,i]+_hmg_sysdata[21,i] > nLsBRow .and. _hmg_sysdata[18,i]+_hmg_sysdata[21,i] < nLsBRow + nLsBHeig)) .and. ((_hmg_sysdata[19,i] > nLsBCol .and. _hmg_sysdata[19,i] < nLsBCol + nLsBLeng) .or. (_hmg_sysdata[19,i]+_hmg_sysdata[20,i] > nLsBCol .and. _hmg_sysdata[19,i]+_hmg_sysdata[20,i] < nLsBCol + nLsBLeng)) .and. _hmg_sysdata[4,i] == GetFormHandle(cFrmName)
	     Setproperty(cFrmName,_hmg_sysdata[2,i],"VISIBLE",.t.)
      endif
   next i
endif
return nil

function CSBoxLostFocus
local cFrmName := thiswindow.name
release key UP of &cFrmName
release key DOWN of &cFrmName
CloseCsBox()
return nil
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

Re: Incremental Search with Combo Box

Posted: Sun May 03, 2009 2:21 pm
by Rathinagiri
IMHO, it is a better candidate for user defined controls as Roberto mentioned.

Thanks a lot Esgici. You had got my day!

Re: Incremental Search with Combo Box

Posted: Sun May 03, 2009 2:22 pm
by esgici
rathinagiri wrote: I had modified/developed some code for up/down/enter keys. Kindly try this.
Thanks a lot Rathi

This is Sunday and you are working for me.

I'll try it.

Best Regards

--

Esgici

Re: Incremental Search with Combo Box

Posted: Sun May 03, 2009 2:37 pm
by esgici
rathinagiri wrote:I think, I had done away the overlapping controls problem.
Hi Rathi

Again thanks, your code ran well :)

But only for current conditions :(

When changed position of txbMessy to the left, like

Code: Select all

@ 55, 100 TEXTBOX txbMessy
no problem; it works as expected.

But when expanded it's width like

Code: Select all

@ 55, 190 TEXTBOX txbMessy WIDTH 400
"mess" reoccurred.

Another problem is : if we add a second txbMessy like :

Code: Select all

@ 80, 190 TEXTBOX txbMessy2
when list box of CSBox open, this text box goes away, but does not return after CSBox closed.

Sorry for all of these inconveniences; I know you are very busy in daily works and moreover this is the Sunday :(

I'll try developed code for up/down/enter keys.

Best Regards

--

Esgici

Re: Incremental Search with Combo Box

Posted: Sun May 03, 2009 3:09 pm
by Rathinagiri
Yes, I guessed this would happen. :(

We shall fine tune. :)

Re: Incremental Search with Combo Box

Posted: Sun May 03, 2009 4:51 pm
by Rathinagiri
Changing the VISIBLE property of the overlapping controls and restoring them again at the end would give problems. :( This would make visible all the controls that might have been made invisible if any by the programmer!

I am trying another route without losing hope. :)

Re: Incremental Search with Combo Box

Posted: Tue May 05, 2009 9:00 am
by Rathinagiri
Hi Esgici,

Kindly check the new one and tell me about your comments. It is a raw one and has to be fine tuned more!

The inspiration for this is of course from Roberto, from his 'inplaceedit' concept.

Code: Select all

/*
  

  CSBox ( Combined Search Box ) try


*/

#include "minigui.ch"

PROC Main()

   aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
   
   ASORT( aCountries )                    // This Array MUST be sorted
       
   DEFINE WINDOW frmCSBTest ;
      AT 0,0 ;
      WIDTH 550 ;
      HEIGHT 300 ;
      TITLE 'CSBox ( Combined Search Box ) Test' ;
      MAIN ;
      ON INIT MakeCSBs()
      
      ON KEY ESCAPE ACTION frmCSBTest.Release
      
      @ 55, 190 TEXTBOX txbMessy width 400
      @ 85, 190 TEXTBOX txbMessy1 
      
   
   END WINDOW // frmCSBTest
   
   frmCSBTest.Center
   
   frmCSBTest.Activate

      
RETU // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.


PROC MakeCSBs()                           // Making CSBox(s)

   DefnCSBox( ThisWindow.Name, 'Country',;         // Names suffix
                               'Country Name :',;  // Prompt
                               25,;                // CSBox Box Row No 
                               100,;               // CSBox Box Col No 
                               200,;               // Text Box Width  
                               20,;                // Text Box Height 
                               aCountries )   
                               
   frmCSBTest.TxBCountry.SetFocus()
   
RETU // MakeCSBs()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC DefnCSBox( ;                           // Define a CSBox  
              cFrmName,;    // Form / Window Name
              cCSBName,;    // CSBox Name
              cLblValu,;    // Prompt
              nCSBRow,;     // CSBox Row No
              nCSBCol,;     // CSBox Col No   
              nTxBWidth,;   // Text Box Width
              nTxBHeight,;  // Text Box Height
              aArray )      // Search array  
              
    public cLblName := "Lbl" + cCSBName,;
          cTxBName := "TxB" + cCSBName,;
          cLsBName := "LsB" + cCSBName,;
          nLblWidt := 0,;
          nTxBCol  := 0,;    
          nLsBRow  := 0,;
          parentname := cFrmName,;
          parentheight := getproperty(cFrmName,"HEIGHT"),;
          parentrow := getproperty(cFrmName,"ROW"),;
          aItems := aArray
    
    DEFINE LABEL &cLblName  
       PARENT    &cFrmName
       ROW        nCSBRow
       COL        nCSBCol
       HEIGHT     nTxBHeight
       VALUE      cLblValu
       RIGHTALIGN .T.
       AUTOSIZE   .T.
    END LABEL // &lblName      

    nLblWidt := GetProperty( cFrmName, cLblName, "WIDTH" ) 
    nTxBCol  := nCSBCol + nLblWidt + 5
 
    DEFINE TEXTBOX &cTxBName 
       PARENT   &cFrmName
       ROW      nCSBRow - 2
       COL      nTxBCol
       WIDTH    nTxBWidth
       HEIGHT   nTxBHeight
       ONCHANGE createcsbox() 
    END TEXTBOX // &cTxBName   

    
RETU // DefnCSBox()   
   
 
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

function createcsbox
local formname := thiswindow.name
local formrow := thiswindow.row
local formcol := thiswindow.col
local controlrow := this.row
local controlcol := this.col
local controlwidth := this.width
local controlheight := this.height
local curvalue := this.value
local aresults := {}
local result := 0
local i := 0
local listboxheight := 0
local caret := this.CaretPos
if !empty(curvalue)
   for i := 1 to len(aitems)
      if upper(aitems[i]) == upper(curvalue)
         return nil //item selected already
      endif
      if upper(left(aitems[i],len(curvalue))) == upper(curvalue)
         aadd(aresults,aitems[i])
      endif
   next i
   if len(aresults) > 0
      listboxheight := max(min(len(aresults) * 15,thiswindow.height - controlrow - controlheight),20) 
      define window _hmg_csbox at formrow+controlrow+20,formcol+controlcol width controlwidth height listboxheight+controlheight title '' modal nocaption nosize //on interactiveclose _hmg_csbox.release()
         define textbox _cstext
            row 3
            col 3
            width controlwidth
            height controlheight 
            on change _cstextchanged()
            on enter _csitemselected()
         end textbox
         define listbox _cslist
            row controlheight+3
            col 3
            width controlwidth
            height listboxheight
            items aresults
            on dblclick _csitemselected()
            value 1
         end listbox
      end window
      on key UP of _hmg_csbox action _csdoupkey()
      on key DOWN of _hmg_csbox action _csdodownkey()
      _hmg_csbox._cstext.value := curvalue
      _hmg_csbox._cstext.CaretPos := caret
      _hmg_csbox.activate()
   endif
endif   
return nil         
   
function _cstextchanged
local curvalue := _hmg_csbox._cstext.value
local aresults := {}
local result := 0
local i := 0
local listboxheight := 0
_hmg_csbox._cslist.deleteallitems()
for i := 1 to len(aitems)
   if upper(left(aitems[i],len(curvalue))) == upper(curvalue)
      aadd(aresults,aitems[i])
   endif
next i
if len(aresults) > 0
   for i := 1 to len(aresults)
      _hmg_csbox._cslist.additem(aresults[i])
   next i
   _hmg_csbox._cslist.value := 1
endif
listboxheight := max(min(len(aresults) * 15,(parentheight + parentrow - _hmg_csbox.row - _hmg_csbox._cstext.row - _hmg_csbox._cstext.height - 10)),20) 
_hmg_csbox._cslist.height := listboxheight
_hmg_csbox.height := listboxheight+_hmg_csbox._cstext.height
return nil   
   
function _csitemselected
if _hmg_csbox._cslist.value > 0
   setproperty(parentname,cTxBName,"VALUE",_hmg_csbox._cslist.item(_hmg_csbox._cslist.value))
   setproperty(parentname,cTxBName,"CARETPOS",len(_hmg_csbox._cslist.item(_hmg_csbox._cslist.value)))
   _hmg_csbox.release()
endif
return nil

function _csdoupkey
if _hmg_csbox._cslist.itemcount > 0 .and. _hmg_csbox._cslist.value > 1
   _hmg_csbox._cslist.value := _hmg_csbox._cslist.value - 1
endif
return nil

function _csdodownkey
if _hmg_csbox._cslist.itemcount > 0 .and. _hmg_csbox._cslist.value < _hmg_csbox._cslist.itemcount
   _hmg_csbox._cslist.value := _hmg_csbox._cslist.value + 1
endif

return nil

Re: Incremental Search with Combo Box

Posted: Tue May 05, 2009 9:15 am
by esgici
Hi Rathi

Checked, work fine, problems gone away; thanks a lot :)

I'll review more deeply.

By the way, your implementation for "navigation in a control without set focus" is very attractive, thanks again for this. :)

Regards

--

Esgici

Re: Incremental Search with Combo Box

Posted: Tue May 05, 2009 10:27 am
by esgici
Hi Rathi

Modal Window :o wonderful :!: :D

As always I told you are a real diamond :D

I'm waiting eagerly fine tunes :)

Best Regards

--

Esgici

Re: Incremental Search with Combo Box

Posted: Tue May 05, 2009 2:05 pm
by sudip
Hello Rathi,

Excellent :o :shock: :D

Now, I want to learn can we create "USER DEFINED CONTROL" in HMG (like activex for Busy and Lazy programmers ;) )?
And how can it be added into Grid control? (if possible :) )

Regards.

Sudip