home *** CD-ROM | disk | FTP | other *** search
- * Program.......: EXAMPLE.PRG
- * Author........: Barbara Geller
- * Date..........: 06/01/90
- * Description...: Examples
- * Notice........: 1990 Clipper Developers Conference
-
- #include "j:\beta\inkey.ch"
- #include "j:\beta\setcurs.ch"
- #include "j:\beta\achoice.ch"
-
- #define MY_HSEP "═╤═"
- #define MY_CSEP " │ "
- #define MY_FSEP "═╧═"
-
- #define MY_CSEP2 " ║ "
- #define MY_HSEP2 "═╦═"
- #define MY_FSEP2 "═╩═"
-
- PARAMETERS shade
-
- IF TYPE('shade') == "U"
- shade := "color"
- ENDIF
-
- INITS()
- PAINT(co_norm)
-
- DO WHILE .t.
- clear
-
- @ 0, 1 to 23,78 double
- CENTER_SH(2,"CLIPPER 5.0 - DEVCON 1990",1,5,3,74,4)
-
- CENTER_SH(0,"",6,17,14,62,4)
- CENTER(17,'Enter Selection . . .')
-
- PAINT(co_detail)
-
- @ 8,35 prompt "Achoice "
- @ 9,35 prompt "Get System "
- @ 10,35 prompt "Browse DBF "
- @ 11,35 prompt "Browse ARRAY "
- @ 12,35 prompt "Exit Program "
- menu TO choice
-
- PAINT(pop)
-
- DO CASE
- CASE choice == 1
- EX_ACH()
-
- CASE choice == 2
- EX_GET()
-
- CASE choice == 3
- EX_BROW1()
-
- CASE choice == 4
- EX_BROW2()
-
- CASE choice == 0 .or. choice == 5
- exit
- ENDCASE
- ENDDO
-
- SETCURSOR(.t.)
- close all
- clear
- quit
-
- * EOF : EXAMPLE.PRG
-
- *******************************************
- *******************************************
-
- FUNCTION ex_ach
- clear
-
- PAINT(co_banner)
- CENTER_SH(2,"ACHOICE EXAMPLE",1,20,3,59,4)
- PAINT(pop)
-
- m->date := DATE()
- m->position := "PROGRAMMER"
- m->degree := "None "
-
- @ 7,28 say "Hire Date :"
- @ 8,28 say "Job Title :"
- @ 9,28 say "Qualified :"
-
- CENTER(23,"<ESC> to Abort")
-
- DO WHILE .t.
- @ 7,42 get m->date
- @ 8,42 get m->position WHEN ACH_POSIT(8,28,"Job Title :")
- @ 9,42 get m->degree PICTURE "!"
-
- READC()
-
- IF LASTKEY() == 27
- exit
- ENDIF
- ENDDO
-
- return .t.
- * EOF : achoice example
-
- FUNCTION ach_posit(trow,tcol,tmsg)
- LOCAL start
- PRIVATE readv
-
- readv := READVAR()
- lastk := LASTKEY()
-
- * track array name for achoice UDF
- ach_array := "ach_posit"
-
- PAINT(co_invwind)
- @ trow,tcol say tmsg
- PAINT(pop)
-
- PAINT(co_wind)
- PCLR("pbuff",6,9,arr_bott+1,22,4)
- @ 6,14 say 'JOB '
-
- start := ASCAN(ach_posit,&readv)
- ans := ACHOICE(7,11,arr_bott,20,ach_posit,.t.,"a_udf",start)
- PAINT(pop)
-
- IF ans > 0
- m->position := SUBSTR(ach_posit[ans],1,10)
- ENDIF
-
- RESTSCREEN(6,9,arr_bott+1,22,pbuff)
- @ trow,tcol say tmsg
- keyboard CHR(lastk)
-
- return .t.
- * endfunc
-
- FUNCTION a_udf
- PARAMETER mode, elem_posit, rel_posit
- PRIVATE retval, lastk
-
- retval := AC_CONT && continue
- lastk := LASTKEY()
-
- DO CASE
- CASE mode == AC_IDLE && idle
- * comes here after processing all non-keyboard exception keys
-
- CASE mode == AC_HITTOP && up arrow past top of list
- * wrap to the bottom of the list
- PCLR("ebuff",20,30,21,75,1)
-
- PAINT(co_err)
- @ 20,30 say "User cursored past the first item on the list."
- @ 21,30 say " Press any key to continue . . . "
- INKEY(0)
-
- PAINT(pop)
- RESTSCREEN(20,30,21,75,ebuff)
-
- KEYBOARD CHR(K_CTRL_PGDN) && Ctrl Pg Dn
-
- CASE mode == AC_HITBOTTOM && down arrow past bottom of list
- PCLR("ebuff",20,30,21,74,1)
-
- PAINT(co_err)
- @ 20,30 say "User cursored past the last item on the list."
- @ 21,30 say " Press any key to continue . . . "
- INKEY(0)
-
- PAINT(pop)
- RESTSCREEN(20,30,21,74,ebuff)
-
- CASE mode == AC_EXCEPT && keystroke exception
- DO CASE
- CASE lastk == K_ENTER
- retval := AC_SELECT
-
- CASE lastk == K_ESC
- retval := AC_ABORT && abort
-
- OTHERWISE
- IF ASCAN(&ach_array,UPPER(CHR(lastk))) > 0
- * add next line in if you want to select item
- * keyboard chr(K_ENTER)
- retval := AC_GOTO
- ENDIF
-
- ENDCASE
- ENDCASE
-
- return retval
- * endfunc
-
- *******************************************
- *******************************************
-
- FUNCTION ex_get
- PUBLIC dog := "This is the First Get to Test"
-
- clear
-
- PAINT(co_banner)
- CENTER_SH(2,"GET LIST EXAMPLE",1,20,3,59,4)
- PAINT(pop)
-
- DO WHILE LASTKEY() # K_ESC
- @ 8,15 get dog VALID udf_a()
- READC()
- ENDDO
-
- return .t.
- * endfunc
-
- FUNCTION udf_a
- LOCAL dog := "Welcome to DevCon 1990"
- PRIVATE getList := {}, tiger := "This is the third Get list."
-
- @ 12,15 GET dog
- @ 14,15 GET tiger
- READC()
-
- return .t.
- * endfunc
-
- *******************************************
- *******************************************
-
- FUNCTION ex_brow1
- clear
-
- PAINT(co_banner)
- CENTER_SH(2,"TBROWSE EXAMPLE #1",1,20,3,59,4)
- PAINT(pop)
-
- USE test NEW
-
- TEST_BR1(8,11,18,68)
-
- USE
- SETCOLOR(co_norm) // temp fix
-
- return NIL
- * endfunc
-
- FUNCTION test_br1(t,l,b,r)
- LOCAL browse, column, lastk, done := .f.
-
- /* make a new browse object */
- browse := TBrowseDB(t+1, l+1, b, r-1)
-
- /* default heading and column separators */
- browse:headSep := MY_HSEP
- browse:colSep := MY_CSEP
- browse:footSep := MY_FSEP
-
- /* specify colors 1 2 3 4 5 6 7 */
- browse:colorSpec := "N/W, B/W, B/BG, GR+/W, B/BG, R/W, BG/R"
-
- /* make a new column <1> */
- column := TBColumnNew(" Name", {|| TRIM(fname) + " " + TRIM(lname) } )
- column:defColor := {2, 3}
- column:width := 20
- column:cargo := "name"
- browse:addColumn(column)
-
- /* make a new column <2> */
- column := TBColumnNew("Score 1", {|x| if(x == NIL, test->score_1, test->score_1 := x) } )
- column:headSep := MY_HSEP2
- column:colSep := MY_CSEP2
- column:footSep := MY_FSEP2
- column:colorBlock := {|x| if( x < 0, {6, 7}, {4, 5} )}
- browse:addColumn(column)
-
- /* make a new column <3> */
- column := TBColumnNew("Score 2", {|x| if(x == NIL, test->score_2, test->score_2 := x) } )
- column:colorBlock := {|x| if( x < 0, {6, 7}, {4, 5} )}
- browse:addColumn(column)
-
- /* make a new column <4> */
- column := TBColumnNew("Rating", {|score_1, score_2| RATE_IT(test->score_1 + test->score_2) } )
- column:colorBlock := {|score_1, score_2| if( (test->score_1 + test->score_2) <= 0, {6, 5}, {4, 5} )}
- column:width := 12
- column:cargo := "rating"
- browse:addColumn(column)
-
- PAINT("N/W")
- @ t, l, b, r BOX "╒═╕│╛═╘│"
- PAINT(pop)
-
- WHILE ( ! done )
-
- /* stabilize the display */
- WHILE ( ! browse:STABILIZE() )
- lastk := INKEY()
-
- IF ( lastk != 0 )
- exit /* (abort if a key is waiting) */
- ENDIF
- ENDDO
-
- IF ( browse:stable )
- lastk := INKEY(0)
- ENDIF
-
- /* process key */
- DO CASE
-
- CASE ( lastk == K_DOWN )
- browse:DOWN()
-
- CASE ( lastk == K_UP )
- browse:UP()
-
- CASE ( lastk == K_PGDN )
- browse:PAGEDOWN()
-
- CASE ( lastk == K_PGUP )
- browse:PAGEUP()
-
- CASE ( lastk == K_RIGHT )
- browse:RIGHT()
-
- CASE ( lastk == K_LEFT )
- browse:LEFT()
-
- CASE ( lastk == K_HOME )
- browse:HOME()
-
- CASE ( lastk == K_END )
- browse:END()
-
- CASE ( lastk == K_ESC )
- done := .t.
-
- CASE ( lastk == K_RETURN )
-
- /* don't allow editing of first or last column */
- column:= browse:GetColumn(browse:colPos)
-
- IF ( column:cargo == "name" .or. column:cargo == "rating")
- loop
- ELSE
- GET_IT(browse)
- ENDIF
-
- ENDCASE
-
- ENDDO
-
- return .t.
- * endfunc
-
- FUNCTION get_it(bget)
- LOCAL old_ins, column, get
-
- /* make sure browse is stable */
- WHILE ( ! bget:STABILIZE() )
- *
- ENDDO
-
- /* save state */
- old_ins := SETKEY(K_INS)
-
- /* set insert key to toggle insert mode and cursor */
- SETKEY(K_INS,;
- {|| SetCursor(if(ReadInsert(!READINSERT()), SC_NORMAL, SC_INSERT))})
-
- /* initial cursor setting */
- SetCursor( if(READINSERT(), SC_INSERT, SC_NORMAL) )
-
- /* get column object from browse */
- column := bget:GETCOLUMN(bget:colPos)
-
- /* create a corresponding GET */
- get := GetNew(ROW(), COL(), column:block, column:heading, ,"N/W,N/BG")
-
- /* read it */
- ReadModal( {get} )
-
- /* restore state */
- SetCursor(0)
- SetKey(K_INS, old_ins)
-
- /* force redisplay of current row */
- bget:refreshCurrent()
-
- return NIL
- * endfunc
-
- FUNCTION rate_it(score)
- LOCAL msg := "AVERAGE"
-
- IF score <= 0
- msg := "UNACCEPTABLE"
-
- ELSEIF score > 100
- msg := "GREAT"
-
- ENDIF
-
- return msg
- * endfunc
-
- *******************************************
- *******************************************
-
- FUNCTION ex_brow2
- clear
-
- PUBLIC big_array := { {"chicken", "fish", "turkey", "sushi" },;
- {"wine", "beer", "water", "plum wine" }, ;
- { "apple pie", "carrot cake", "ice cream", "cookies" } }
-
- PAINT(co_banner)
- CENTER_SH(2,"TBROWSE EXAMPLE #2",1,20,3,59,4)
- PAINT(pop)
-
- TEST_BR2(8,11,18,68)
-
- SETCOLOR(co_norm)
-
- return NIL
- * endfunc
-
- FUNCTION test_br2(t,l,b,r)
- LOCAL browse, column, lastk, done := .f. , index := 1
-
- /* make a new browse object */
- browse := TBrowseDB(t+1, l+1, b, r-1)
-
- /* default heading and column separators */
- browse:headSep := MY_HSEP
- browse:colSep := MY_CSEP
- browse:footSep := MY_FSEP
-
- /* define top and bottom */
- browse:gotopblock := { || index := 1 }
- browse:gobottomblock := { || index := LEN(big_array) }
-
- /* add custom 'skip UDF' */
- browse:skipBlock := {|x| Skip_it(x,@index)}
-
- /* specify colors 1 2 3 4 5 6 7 */
- browse:colorSpec := "N/W, B/W, B/BG, GR+/W, B/BG, R/W, BG/R"
-
- /* make a new column <1> */
- column := TBColumnNew("Main Course",;
- {|x| if(x == NIL, big_array[1,index], big_array[1,index]:= x) } )
-
- column:defColor := {2, 3}
- column:width := 10
- browse:addColumn(column)
-
- /* make a new column <2> */
- column := TBColumnNew("Drinks",;
- {|x| if(x == NIL, big_array[2,index], big_array[2,index]:= x) } )
-
- column:defColor := {2, 3}
- column:width := 10
- browse:addColumn(column)
-
- /* make a new column <3> */
- column := TBColumnNew(" Desserts",;
- {|x| if(x == NIL, big_array[3,index], big_array[3,index]:= x) } )
-
- column:defColor := {2, 3}
- column:width := 15
- browse:addColumn(column)
-
- PAINT("N/W")
- @ t, l, b, r BOX "╒═╕│╛═╘│"
- PAINT(pop)
-
- WHILE ( ! done )
-
- /* stabilize the display */
- WHILE ( ! browse:STABILIZE() )
- lastk := INKEY()
-
- IF ( lastk != 0 )
- exit /* (abort if a key is waiting) */
- ENDIF
- ENDDO
-
- IF ( browse:stable )
- lastk := INKEY(0)
- ENDIF
-
- /* process key */
- DO CASE
-
- CASE ( lastk == K_DOWN )
- browse:DOWN()
-
- CASE ( lastk == K_UP )
- browse:UP()
-
- CASE ( lastk == K_PGDN )
- browse:PAGEDOWN()
-
- CASE ( lastk == K_PGUP )
- browse:PAGEUP()
-
- CASE ( lastk == K_CTRL_PGUP )
- browse:GOTOP()
-
- CASE ( lastk == K_CTRL_PGDN )
- browse:GOBOTTOM()
-
- CASE ( lastk == K_RIGHT )
- browse:RIGHT()
-
- CASE ( lastk == K_LEFT )
- browse:LEFT()
-
- CASE ( lastk == K_HOME )
- browse:HOME()
-
- CASE ( lastk == K_END )
- browse:END()
-
- CASE ( lastk == K_ESC )
- done := .t.
-
- CASE ( lastk == K_RETURN )
- GET_IT(browse)
-
- ENDCASE
-
- ENDDO
-
- return .t.
- * endfunc
-
- FUNCTION skip_it(n,index)
- LOCAL moved := 0, max := LEN(big_array[1])
-
- IF ( n >= 0)
-
- IF (index + n) > max
- moved := max - index
- index := max
-
- ELSE
- index += n
- moved := n
-
- ENDIF
-
- ELSE
-
- IF (index + n) < 1
- moved := 1 - index
- index := 1
-
- ELSE
- index += n
- moved := n
-
- ENDIF
-
- ENDIF
-
- return moved
- * endfunc
-