CSBox Reviewed

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: CSBox Reviewed

Post by esgici »

Hello Sudip
sudip wrote: How can I change Items of Combosearchbox on the fly?
Which kind of change you want make on the fly ? Delete, insert, edit some item(s) or change all items ?

IMHO the first case is inapplicable. Because we have only one editing box and we use it for enter search string. If we want using same box both for editing item and for enter search string, how prg can know our intent? If we use two separate box, IMHO it will be very cumbersome.

IMHO, changing all items will be possible: delete all items, load new items and refresh. I haven't test.
sudip wrote: And I found that I have to press Esc key when I want to select another control without selecting any item of CSB. Can this behavior be changed?
As you know (because you has followed its development), CSBox isn't a real HMG control. It may be considered only an artificial control. In fact, searching process is realized into a modal window. By definition, before a modal window released user cannot use any other thing. So, unless terminating or escaping a search operation, it's impossible selecting another one control.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: CSBox Reviewed

Post by sudip »

Hello Brother Esgici,

Thank you for your mail.
esgici wrote: Which kind of change you want make on the fly ? Delete, insert, edit some item(s) or change all items ?

IMHO the first case is inapplicable. Because we have only one editing box and we use it for enter search string. If we want using same box both for editing item and for enter search string, how prg can know our intent? If we use two separate box, IMHO it will be very cumbersome.

IMHO, changing all items will be possible: delete all items, load new items and refresh. I haven't test.
I stored some names (eg., Account names in my case) in an array beforehand and used it with CSB. It ran fine. But, I don't know how can I change this array (lookup array) on the fly, like I do with ComboBox. I didn't found DeleteAllItems as per documentation of CSB. Can I use it, as I did in following function with Combobox.

Code: Select all

static function ParentAcLookupCreate()
	local mOldRec
	mOldRec := iif(Acct->(eof()), 0, Acct->(recno()))
	aAcctcd := {}; aAcctnm := {}
	netselect("acct")
	go top
	dbeval({|| aadd(aAcctcd, acct->acctcd), aadd(aAcctnm, acct->acctnm)}, {|| empty(acct->parentac)})
	netselect("acct")
	if mOldRec != 0
		go (mOldrec)
	endif
	frmAcct.cboParentac.DeleteAllItems()
	aeval(aAcctnm, {|x| frmAcct.cboParentAc.AddItem(x)})
	return nil
With best regards.
Sudip
With best regards,
Sudip
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: CSBox Reviewed

Post by esgici »

Hello Sudip
sudip wrote: I didn't found DeleteAllItems as per documentation of CSB.
You are rigth. Unfortunately CSBox doesn't have DeleteAllItems method :(

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: CSBox Reviewed

Post by sudip »

Hello Esgici,
esgici wrote: You are rigth. Unfortunately CSBox doesn't have DeleteAllItems method :(
So, can we expect it in the next version? :)
Regards.
Sudip
With best regards,
Sudip
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: CSBox Reviewed

Post by Rathinagiri »

Hi,

I enclose herewith a new edition of CSBox, where in we can add an item, delete an item or delete all items. Kindly check up and give your valuable suggestions. I don't know how to change "include" file to make the function to our semi-oop style.

c:\hmg\hfcl\source\combosearchbox.prg

Code: Select all

#include "minigui.ch"

PROC _DefineComboSearchBox( cCSBoxName,; 
                            cCSBoxParent,; 
                            cCSBoxCol,; 
                            cCSBoxRow,; 
                            cCSBoxWidth,; 
                            cCSBoxHeight,; 
                            cCSBoxValue,;
                            cFontName,; 
                            nFontSize,; 
                            cToolTip,; 
                            nMaxLenght,;
                            lUpper,; 
                            lLower,; 
                            lNumeric,;
                            bLostFocus,; 
                            bGotFocus,; 
                            bEnter,;
                            lRightAlign,; 
                            nHelpId,; 
                            lBold,; 
                            lItalic,; 
                            lUnderline,; 
                            aBackColor,; 
                            aFontColor,; 
                            lNoTabStop,; 
                            aArray )
            
   LOCAL   cParentName := ''
          
   DEFAULT cCSBoxWidth  := 120
   DEFAULT cCSBoxHeight := 24
   DEFAULT cCSBoxValue  := ""
   DEFAULT bGotFocus    := ""
   DEFAULT bLostFocus   := ""
   DEFAULT nMaxLenght   := 255
   DEFAULT lUpper       := .F.
   DEFAULT lLower       := .F.
   DEFAULT lNumeric     := .F.
   DEFAULT bEnter       := ""
           
   IF _HMG_SYSDATA [ 264 ] = .T.                  // _HMG_BeginWindowActive
      cParentName := _HMG_SYSDATA [ 223 ]         // _HMG_ActiveFormName 
   ELSE
      cParentName := cCSBoxParent
   ENDIF


   DEFINE TEXTBOX &cCSBoxName
      PARENT        &cCSBoxParent
      ROW           cCSBoxRow
      COL           cCSBoxCol
      WIDTH         cCSBoxWidth
      HEIGHT        cCSBoxHeight
      VALUE         cCSBoxValue
      FONTNAME      cFontName
      FONTSIZE      nFontSize
      TOOLTIP       cToolTip
      MAXLENGTH     nMaxLenght
      UPPERCASE     lUpper
      LOWERCASE     lLower
      NUMERIC       lNumeric
      ONLOSTFOCUS   bLostFocus
      ONGOTFOCUS    bGotFocus
      ONENTER       bEnter
      ONCHANGE      CreateCSBox( cParentName, cCSBoxName, aArray, cCSBoxRow, cCSBoxCol)
      RIGHTALIGN    lRightAlign
      HELPID        nHelpId
      FONTBOLD      lBold
      FONTITALIC    lItalic
      FONTUNDERLINE lUnderline
      BACKCOLOR     aBackColor
      FONTCOLOR     aFontColor
      TABSTOP       lNoTabStop
      
   END TEXTBOX
   
	mVar := '_' + cParentName + '_' + cCSBoxName
   _HMG_SYSDATA [ 17 ] [&mVar] := aclone(aArray)

    
RETURN // _DefineComboSearchBox()


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

STATIC PROC CreateCSBox( cParentName, cCSBoxName, aitems ) 

   LOCAL nFormRow       := thisWindow.row
   LOCAL nFormCol       := thisWindow.col
   LOCAL nControlRow    := this.row
   LOCAL nControlCol    := this.col
   LOCAL nControlWidth  := this.width
   LOCAL nControlHeight := this.height
   LOCAL cCurValue      := this.value
   LOCAL aResults       := {}
   LOCAL nContIndx      := GetControlIndex( this.name, thiswindow.name )   
   LOCAL result         := 0
   LOCAL nItemNo        := 0
   LOCAL nListBoxHeight := 0
   LOCAL caret          := this.CaretPos
   
   LOCAL cCSBxName := 'frm' + cCSBoxName
   
 	i := GetControlIndex ( cCSBoxName , cParentName)
   aitems := _HMG_SYSDATA [ 17 ] [i]
   
   IF !EMPTY(cCurValue)
   
      IF _HMG_SYSDATA [ 23, nContIndx ] # -1                     // _HMG_aControlContainerRow
         nControlRow += _HMG_SYSDATA [  23, nContIndx ]          // _HMG_aControlContainerRow
         nControlCol += _HMG_SYSDATA [  24, nContIndx ]          // _HMG_aControlContainerCol 
      ENDIF   
   
      FOR nItemNo := 1 TO LEN(aitems)
         IF UPPER( aitems[ nItemNo ] ) == UPPER( cCurValue )
            EXIT // item selected already
         ENDIF
         IF UPPER( LEFT( aitems[ nItemNo ], LEN( cCurValue ))) == UPPER(cCurValue)
            AADD( aResults, aitems[ nItemNo ] )
         ENDIF
      NEXT nItemNo
      
      IF LEN( aResults ) > 0
      
         nListBoxHeight := MAX(MIN((LEN(aResults) * 16)+60,thiswindow.height - nControlRow - nControlHeight-10),40)
         
         DEFINE WINDOW &cCSBxName ;
            AT     nFormRow+nControlRow+20, nFormCol+nControlCol ;
            WIDTH  nControlWidth+6 ;
            HEIGHT nListBoxHeight+nControlHeight ;
            TITLE '' ;
            MODAL ;
            NOCAPTION ;
            NOSIZE 
         
            ON KEY UP     OF This.Window ACTION _CSDoUpKey()  
            ON KEY DOWN   OF This.Window ACTION _CSDoDownKey()
            ON KEY ESCAPE OF This.Window ACTION _CSDoEscKey() 
            
            DEFINE TEXTBOX _cstext
               ROW           3
               COL           3
               WIDTH         nControlWidth
               HEIGHT        nControlHeight
               FONTNAME      this.fontname
               FONTSIZE      this.Fontsize
               TOOLTIP       this.tooltip
               FONTBOLD      this.fontbold
               FONTITALIC    this.fontitalic
               FONTUNDERLINE this.fontunderline
               BACKCOLOR     this.backcolor
               FONTCOLOR     this.fontcolor
               ON CHANGE     _CSTextChanged( cParentName, aitems, cCSBoxName )
               ON ENTER      _CSItemSelected( cParentName, aitems, cCSBoxName )
            END TEXTBOX
            
            DEFINE LISTBOX _cslist
               ROW         nControlHeight+3
               COL         3
               WIDTH       nControlWidth
               HEIGHT      nListBoxHeight
               ITEMS       aResults
               ON DBLCLICK _CSItemSelected( cParentName, aitems, cCSBoxName )
               VALUE       1    
            END LISTBOX
            
         END WINDOW
         
         SetProperty( cCSBxName, '_cstext', "VALUE", cCurValue )
         SetProperty( cCSBxName, '_cstext', "CaretPos", caret )
         
         ACTIVATE WINDOW &cCSBxName
         
         
      ENDIF
   ENDIF   
  
RETURN // CreateCSBox()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
   
STATIC PROC _CSTextChanged( cParentName, aItems, cTxBName )

   LOCAL cCurValue      := GetProperty( ThisWindow.Name, '_cstext', "VALUE" ) 
   LOCAL aResults       := {}
   LOCAL nItemNo        := 0
   LOCAL nListBoxHeight := 0
   LOCAL nParentHeight  := GetProperty(cParentName,"HEIGHT")
   LOCAL nParentRow     := GetProperty(cParentName,"ROW")
   
   DoMethod( ThisWindow.Name, "_csList", 'DeleteAllItems' ) 
   
   FOR nItemNo := 1 TO LEN(aitems)
      IF UPPER( LEFT( aitems[ nItemNo ], LEN(cCurValue))) == UPPER(cCurValue)
         AADD(aResults,aitems[ nItemNo ])
      ENDIF
   NEXT nItemNo
   
   IF LEN(aResults) > 0
      FOR nItemNo := 1 TO LEN(aResults)
         DoMethod( ThisWindow.Name, "_csList", 'AddItem', aResults[ nItemNo ] ) 
      NEXT i
      SetProperty( ThisWindow.Name, "_csList", "VALUE", 1 ) 
   ENDIF
   
   nListBoxHeight := MAX(MIN((LEN(aResults) * 16)+6,(nParentHeight + nParentRow - ;
                    GetProperty( ThisWindow.Name, 'ROW' ) -  ;
                    GetProperty( ThisWindow.Name, "_csText", 'ROW' ) -  ;
                    GetProperty( ThisWindow.Name, "_csText", 'HEIGHT' ) -  14)), 40) 
   
   SetProperty( ThisWindow.Name, "_csList", "HEIGHT", nListBoxHeight ) 
   SetProperty( ThisWindow.Name, "HEIGHT", nListBoxHeight + GetProperty( ThisWindow.Name, '_cstext', "HEIGHT" ) ) 

RETURN // _CSTextChanged()

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

STATIC PROC _CSItemSelected( cParentName, aitems, cTxBName )

   if GetProperty( ThisWindow.Name, "_csList", "VALUE" ) > 0 
   
      nListValue := GetProperty( ThisWindow.Name, '_csList', "VALUE" )
      cListItem  := GetProperty( ThisWindow.Name, '_csList', "ITEM", nListValue )
      
      SetProperty( cParentName, cTxBName, "VALUE", cListItem )
      
      SetProperty(cParentName,cTxBName,"CARETPOS",;
                    LEN( GetProperty( ThisWindow.Name, '_csList', "ITEM",; 
                         GetProperty( ThisWindow.Name, '_csList', "VALUE" ) ) ) )
      
      DoMethod( ThisWindow.Name, "Release" ) 
      
   ENDIF  
          
RETURN // _CSItemSelected()

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

STATIC PROC _CSDoUpKey()

   IF GetProperty( ThisWindow.Name, '_csList', "ItemCount" ) > 0 .AND. ;
      GetProperty( ThisWindow.Name, '_csList', "VALUE" ) > 1
   
      SetProperty( ThisWindow.Name, '_csList', "VALUE", GetProperty( ThisWindow.Name, '_csList', "VALUE" ) - 1 )
     
      
   ENDIF
   
RETURN // _CSDoUpKey()

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

STATIC PROC _CSDoDownKey()

   IF GetProperty( ThisWindow.Name, '_csList', "ItemCount" ) > 0 .AND. ;
      GetProperty( ThisWindow.Name, '_csList', "VALUE" )     < ;
      GetProperty( ThisWindow.Name, '_csList', "ItemCount" )
      
      SetProperty( ThisWindow.Name, '_csList', "VALUE", GetProperty( ThisWindow.Name, '_csList', "VALUE" ) + 1 ) 
      
   ENDIF

RETURN // _CSDoDownKey()

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

STATIC PROC _CSDoEscKey()

   SetProperty( ThisWindow.Name, '_csText', "VALUE",'')
   
   DoMethod( ThisWindow.Name, "Release" ) 

RETURN // _CSDoEscKey()

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

function _CSBDeleteAllItems(cCSBoxName,cCSBoxParent)
local mvar
	mVar := '_' + cCSBoxParent + '_' + cCSBoxName
   _HMG_SYSDATA [ 17 ] [&mVar] := {}
return nil

function _CSBDeleteItem(cCSBoxName,cCSBoxParent,x)
local mvar
	mVar := '_' + cCSBoxParent + '_' + cCSBoxName
 	adel(_HMG_SYSDATA [ 17 ] [&mvar],x)
 	asize(_HMG_SYSDATA [ 17 ] [&mvar],len(_HMG_SYSDATA [ 17 ] [&mvar]) - 1)
return nil

function _CSBAddItem(cCSBoxName,cCSBoxParent,x)
local mvar
	mVar := '_' + cCSBoxParent + '_' + cCSBoxName
 	aadd(_HMG_SYSDATA [ 17 ] [&mvar],x)
return nil
 	

c:\hmg\hfcl\samples\combosearchbox\main.prg (sample)

Code: Select all

/*
 

   Multiple CSBox ( Combined Search Box ) with tabbing test


*/

#include "minigui.ch"
#include "combosearchbox.ch"


PROC Main()

   aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
   aLargCits  := HB_ATOKENS( MEMOREAD( "LargCits.lst" ),   CRLF )
   aNationals := HB_ATOKENS( MEMOREAD( "Nationality.lst" ),   CRLF )
   
   ASORT( aCountries )                    
   ASORT( aLargCits )                    
   ASORT( aNationals )                    
       
   DEFINE WINDOW frmMCSBTest ;
      AT     0,0 ;
      WIDTH  550 ;
      HEIGHT 300 ;
      TITLE  'Combined Search Box Sample' ;
      MAIN
     
      ON KEY ESCAPE ACTION frmMCSBTest.Release
     
      DEFINE LABEL lblCountries
         ROW        27
         COL        10
         WIDTH      70
         VALUE      "Country :"
         RIGHTALIGN .T.
      END LABEL
      
      DEFINE LABEL lblCities
         ROW        57
         COL        10
         WIDTH      70
         VALUE      "City :"
         RIGHTALIGN .T.
      END LABEL
     
     
      DEFINE COMBOSEARCHBOX csbxCountries
         ROW        25
         COL        90
         WIDTH      150
         ITEMS      aCountries
         ON ENTER    MsgBox( this.Value )
      END COMBOSEARCHBOX
     
      DEFINE COMBOSEARCHBOX csbxLargCits  
         ROW        55
         COL        90
         WIDTH      150
         ITEMS      aLargCits  
      END COMBOSEARCHBOX
      
      
      DEFINE TAB tabMCSBox ;
         AT     20, 250  ;
         WIDTH  280      ;
         HEIGHT 240

         DEFINE PAGE "Blank Page"
            @ 90, 10 LABEL lblBlank WIDTH  200 VALUE "This page left intentionally blank."  CENTERALIGN 
         END PAGE
         
         DEFINE PAGE "Tabbed CSBox"

            DEFINE LABEL lblNations
               ROW        37
               COL        10
               WIDTH      70
               VALUE      "Nationality :"
               RIGHTALIGN .T.
            END LABEL
            
            DEFINE COMBOSEARCHBOX csbxNations
               ROW        35
               COL        90
               WIDTH      150
               ITEMS      aNationals 
            END COMBOSEARCHBOX
            
         END PAGE

       END TAB
       define button addcountry
          row 90
          col 10
          caption "Add Country"
          action _CSBAddItem("csbxCountries","frmMCSBTest","New Country")
       end button 
       define button delcountry
          row 120
          col 10
          caption "Del Country"
          action _CSBDeleteItem("csbxCountries","frmMCSBTest",1)
       end button 
       define button delallcountries
          row 150
          col 10
          caption "Del All Countries"
          action _CSBDeleteAllItems("csbxCountries","frmMCSBTest")
       end button 
   
   END WINDOW // frmMCSBTest
   
   frmMCSBTest.Center

   frmMCSBTest.Activate

     
RETU // Main()



East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: CSBox Reviewed

Post by sudip »

Hello Rathi,

Thanks a lot. I tested it. It runs fine :)

With best regards.

Sudip
With best regards,
Sudip
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: CSBox Reviewed

Post by esgici »

Thanks Rathi :)

I'll check it.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
Post Reply