home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / WBROWDEF.PRG < prev    next >
Text File  |  1995-06-21  |  5KB  |  170 lines

  1. //    WBrowDef.prg - WBrowse(s) Default behaviour
  2. //                   (current/specified alias, all columns)
  3. //
  4. //    Written by:    John M. Skelton,  Jun-94.
  5. //
  6. //    Copyright (C) 1994 Skelton Software, Kendal Cottage, Hillam, Leeds LS25 5HP, UK.
  7. //    All Rights Reserved.
  8. //
  9. //    Part of Clip-4-Win.
  10.  
  11. #define    WIN_WANT_ALL
  12. #include "windows.ch"
  13. #include "topclass.ch"
  14.  
  15. #ifdef    TESTING
  16.  
  17. #define    NO_C4WCLASS
  18. #include "commands.ch"
  19.  
  20. static    oB, lChild
  21.  
  22. function main()
  23. local    oApp, hWnd
  24.  
  25. CREATE APPLICATION oApp  WINDOW hWnd               ;
  26.     TITLE "Simple Clip-4-Win WBrowse Demo"         ;
  27.     ON INIT        MenuSetup(hWnd)                 ;
  28.     ON WM_SIZE     OnSize(hWnd)                    ;
  29.     ON WM_SETFOCUS OnSetFocus(hWnd)
  30.  
  31. return nil
  32.  
  33.  
  34. static function MenuSetup(hWnd)
  35.  
  36. MENU IN hWnd
  37.     POPUP "&File"
  38. //        MENUITEM "&Browse" ACTION WBrowseDef(hWnd, "Clip-4-Win Browse", alias())
  39.         MENUITEM "Browse (&Child)"      ACTION DoBrowse(.t.)
  40.         MENUITEM "Browse (&Overlapped)" ACTION DoBrowse(.f.)
  41.         MENUITEM SEPARATOR
  42.         MENUITEM "E&xit"   ACTION PostQuitMessage(0)
  43.     ENDPOPUP
  44.     POPUP "&Help"
  45.         MENUITEM "&About"  ACTION MessageBox( , "Easy!", "Clip-4-Win App")
  46.     ENDPOPUP
  47. ENDMENU
  48.  
  49. return nil
  50.  
  51.  
  52. static function DoBrowse(lChld)
  53. local    cFile
  54.  
  55. if oB != nil .and. IsWindow(oB:hWnd)
  56.     DestroyWindow(oB:hWnd)
  57.     oB = nil
  58. endif
  59. close all
  60. if (cFile := GetOpenFileName( , "*.dbf", "Select a database",        ;
  61.                              {{"Data Files (*.DBF)", "*.DBF"}})) != nil
  62.     use (cFile) new shared
  63.     oB := WBrowseDef( , , , lChild := lChld)
  64. endif
  65. return nil
  66.  
  67.  
  68. static function OnSetFocus(hWnd)
  69. if oB != nil .and. lChild
  70.     SetFocus(oB:hWnd)
  71. endif
  72. return 0
  73.  
  74.  
  75. static function OnSize(hWnd)
  76. local    a := GetClientRect(hWnd)
  77. local    nLeft := a[1], nTop := a[2], nWidth := a[3], nHeight := a[4]
  78.  
  79. if oB != nil .and. lChild
  80.     MoveWindow(oB:hWnd, nLeft, nTop, nWidth, nHeight, .t.)
  81. endif
  82. return 0
  83.  
  84. #endif    // TESTING
  85.  
  86.  
  87. // WBrowse with default settings.  hoWnd can be hWnd or oWnd.
  88.  
  89. function WBrowseDef(hoWnd, cTitle, cAlias, lChild, nStyle)
  90. local    lObj := (valtype(hoWnd) == "O")
  91. local    hWnd := iif(hoWnd == nil, SelectWindow(),            ;
  92.                 iif(lObj, hoWnd:hWnd, hoWnd))
  93. local    a := GetClientRect(hWnd)
  94. local    nLeft := a[1], nTop := a[2], nWidth := a[3], nHeight := a[4]
  95. local    oB, i, aFields        // fields/codeblocks for browse
  96. local    nOldArea
  97.  
  98. default cAlias to alias()
  99. default lChild to (lObj .and. hoWnd:App:MDI)
  100.  
  101. if lChild
  102.     default nStyle to WS_CHILD + WS_HSCROLL + WS_VSCROLL
  103.     /*
  104.      *  You usually want to re-size the browse window if the parent size
  105.      *  is changed - e.g. see the OnSize() above.  This happens
  106.      *  automatically if hoWnd is a descendant of the WFrameWindow
  107.      *  class and you assign the browse window to its Client.
  108.      */
  109. else
  110.     default cTitle to "Clip-4-Win Browser - " + cAlias
  111.     nLeft := nTop := CW_USEDEFAULT
  112. endif
  113.  
  114. oB = iif(lObj, WBWindow{hoWnd, nLeft, nTop, nWidth, nHeight, cTitle, nStyle},;
  115.                WBrowse{hWnd, nLeft, nTop, nWidth, nHeight, cTitle, nStyle})
  116.  
  117. nOldArea := select()
  118. select(oB:Alias := cAlias)
  119. oB:Escape := .f.
  120. //oB:AutoLite := .f.    // use this to highlight just a cell instead of a row
  121.  
  122. aFields := LdDbrowFlds()
  123. for i = 1 to len(aFields)
  124.     oB:AddColumn( WBColumn{aFields[i, 1], aFields[i, 2]} )
  125. next i
  126.  
  127. SetFocus(oB:hWnd)
  128. oB:GoTop()
  129. select(nOldArea)
  130.  
  131. return oB
  132.  
  133.  
  134. CLASS WBWindow INHERIT WWindow, WBrowse
  135.     METHOD Init(oParent, nLeft, nTop, nWidth, nHeight, cTitle, nStyle)  ;
  136.            INLINE ::oParent := oParent,                                 ;
  137.                   super:Init(oParent:hWnd, nLeft, nTop, nWidth, nHeight,;
  138.                              cTitle, nStyle),                           ;
  139.                   self
  140. ENDCLASS
  141.  
  142.  
  143. // LdDBrowFlds() - Returns an array for use by WBrowse{} that contains
  144. //                 ALL fields in a database (except MEMO)
  145.  
  146. STATIC FUNCTION LdDBrowFlds()
  147.        LOCAL nCtr
  148.        LOCAL aFldList := {}
  149.        LOCAL aStruct  := DBSTRUCT()
  150.  
  151.        FOR nCtr := 1 TO LEN(aStruct)
  152.            DO CASE
  153.               CASE aStruct[nCtr][2] == 'C'
  154.                    AADD(aFldList, {aStruct[nCtr][1], Compile(aStruct[nCtr][1])})
  155.               CASE aStruct[nCtr][2] == 'N'
  156.                    AADD(aFldList, {aStruct[nCtr][1], Compile("STR("+aStruct[nCtr][1]+")")})
  157.               CASE aStruct[nCtr][2] == 'L'
  158.                    AADD(aFldList, {aStruct[nCtr][1], Compile("IIF("+aStruct[nCtr][1]+",'.T.','.F.')")})
  159.               CASE aStruct[nCtr][2] == 'D'
  160.                    AADD(aFldList, {aStruct[nCtr][1], Compile("DTOC("+aStruct[nCtr][1]+")")})
  161.               CASE aStruct[nCtr][2] == 'M'
  162.                    // Memo fields not supported!
  163.            ENDCASE
  164.          NEXT
  165. RETURN(aFldList)
  166.  
  167. STATIC FUNCTION Compile(cStr)
  168. RETURN(&("{||"+cStr+"}"))
  169.  
  170.