home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
WBROWDEF.PRG
< prev
next >
Wrap
Text File
|
1995-06-21
|
5KB
|
170 lines
// WBrowDef.prg - WBrowse(s) Default behaviour
// (current/specified alias, all columns)
//
// Written by: John M. Skelton, Jun-94.
//
// Copyright (C) 1994 Skelton Software, Kendal Cottage, Hillam, Leeds LS25 5HP, UK.
// All Rights Reserved.
//
// Part of Clip-4-Win.
#define WIN_WANT_ALL
#include "windows.ch"
#include "topclass.ch"
#ifdef TESTING
#define NO_C4WCLASS
#include "commands.ch"
static oB, lChild
function main()
local oApp, hWnd
CREATE APPLICATION oApp WINDOW hWnd ;
TITLE "Simple Clip-4-Win WBrowse Demo" ;
ON INIT MenuSetup(hWnd) ;
ON WM_SIZE OnSize(hWnd) ;
ON WM_SETFOCUS OnSetFocus(hWnd)
return nil
static function MenuSetup(hWnd)
MENU IN hWnd
POPUP "&File"
// MENUITEM "&Browse" ACTION WBrowseDef(hWnd, "Clip-4-Win Browse", alias())
MENUITEM "Browse (&Child)" ACTION DoBrowse(.t.)
MENUITEM "Browse (&Overlapped)" ACTION DoBrowse(.f.)
MENUITEM SEPARATOR
MENUITEM "E&xit" ACTION PostQuitMessage(0)
ENDPOPUP
POPUP "&Help"
MENUITEM "&About" ACTION MessageBox( , "Easy!", "Clip-4-Win App")
ENDPOPUP
ENDMENU
return nil
static function DoBrowse(lChld)
local cFile
if oB != nil .and. IsWindow(oB:hWnd)
DestroyWindow(oB:hWnd)
oB = nil
endif
close all
if (cFile := GetOpenFileName( , "*.dbf", "Select a database", ;
{{"Data Files (*.DBF)", "*.DBF"}})) != nil
use (cFile) new shared
oB := WBrowseDef( , , , lChild := lChld)
endif
return nil
static function OnSetFocus(hWnd)
if oB != nil .and. lChild
SetFocus(oB:hWnd)
endif
return 0
static function OnSize(hWnd)
local a := GetClientRect(hWnd)
local nLeft := a[1], nTop := a[2], nWidth := a[3], nHeight := a[4]
if oB != nil .and. lChild
MoveWindow(oB:hWnd, nLeft, nTop, nWidth, nHeight, .t.)
endif
return 0
#endif // TESTING
// WBrowse with default settings. hoWnd can be hWnd or oWnd.
function WBrowseDef(hoWnd, cTitle, cAlias, lChild, nStyle)
local lObj := (valtype(hoWnd) == "O")
local hWnd := iif(hoWnd == nil, SelectWindow(), ;
iif(lObj, hoWnd:hWnd, hoWnd))
local a := GetClientRect(hWnd)
local nLeft := a[1], nTop := a[2], nWidth := a[3], nHeight := a[4]
local oB, i, aFields // fields/codeblocks for browse
local nOldArea
default cAlias to alias()
default lChild to (lObj .and. hoWnd:App:MDI)
if lChild
default nStyle to WS_CHILD + WS_HSCROLL + WS_VSCROLL
/*
* You usually want to re-size the browse window if the parent size
* is changed - e.g. see the OnSize() above. This happens
* automatically if hoWnd is a descendant of the WFrameWindow
* class and you assign the browse window to its Client.
*/
else
default cTitle to "Clip-4-Win Browser - " + cAlias
nLeft := nTop := CW_USEDEFAULT
endif
oB = iif(lObj, WBWindow{hoWnd, nLeft, nTop, nWidth, nHeight, cTitle, nStyle},;
WBrowse{hWnd, nLeft, nTop, nWidth, nHeight, cTitle, nStyle})
nOldArea := select()
select(oB:Alias := cAlias)
oB:Escape := .f.
//oB:AutoLite := .f. // use this to highlight just a cell instead of a row
aFields := LdDbrowFlds()
for i = 1 to len(aFields)
oB:AddColumn( WBColumn{aFields[i, 1], aFields[i, 2]} )
next i
SetFocus(oB:hWnd)
oB:GoTop()
select(nOldArea)
return oB
CLASS WBWindow INHERIT WWindow, WBrowse
METHOD Init(oParent, nLeft, nTop, nWidth, nHeight, cTitle, nStyle) ;
INLINE ::oParent := oParent, ;
super:Init(oParent:hWnd, nLeft, nTop, nWidth, nHeight,;
cTitle, nStyle), ;
self
ENDCLASS
// LdDBrowFlds() - Returns an array for use by WBrowse{} that contains
// ALL fields in a database (except MEMO)
STATIC FUNCTION LdDBrowFlds()
LOCAL nCtr
LOCAL aFldList := {}
LOCAL aStruct := DBSTRUCT()
FOR nCtr := 1 TO LEN(aStruct)
DO CASE
CASE aStruct[nCtr][2] == 'C'
AADD(aFldList, {aStruct[nCtr][1], Compile(aStruct[nCtr][1])})
CASE aStruct[nCtr][2] == 'N'
AADD(aFldList, {aStruct[nCtr][1], Compile("STR("+aStruct[nCtr][1]+")")})
CASE aStruct[nCtr][2] == 'L'
AADD(aFldList, {aStruct[nCtr][1], Compile("IIF("+aStruct[nCtr][1]+",'.T.','.F.')")})
CASE aStruct[nCtr][2] == 'D'
AADD(aFldList, {aStruct[nCtr][1], Compile("DTOC("+aStruct[nCtr][1]+")")})
CASE aStruct[nCtr][2] == 'M'
// Memo fields not supported!
ENDCASE
NEXT
RETURN(aFldList)
STATIC FUNCTION Compile(cStr)
RETURN(&("{||"+cStr+"}"))