home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
WBTDEMO.ZIP
/
CELLEDIT.PRG
< prev
next >
Wrap
Text File
|
1995-05-30
|
11KB
|
311 lines
#define WIN_WANT_ALL
#include "windows.ch"
#include "dialog.ch"
#include "accel.ch"
// foo dialog - include it in your applications resource file
// or things are not going to work very well! Note we have added
// WS_BORDER...
// foo DIALOG 38, 108, 84, 15
// STYLE WS_POPUP | WS_BORDER
// BEGIN
// CONTROL "", 101, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 84, 15
// END
FUNCTION CellEdit( oB, nMsg, nwParamb, nlParamb )
STATIC aRect := {}
LOCAL xKeyVal
LOCAL xData
LOCAL cPicture
LOCAL nResults
LOCAL nField
LOCAL aCellData
LOCAL hWnd
LOCAL aARect
LOCAL nCrec
LOCAL lMoved
aRect := GetClientRect( oB:hWnd )
// Filter out the keystrokes we don't want
DO CASE
CASE nMsg == WM_LBUTTONDBLCLK
CASE nwParamB == 32
CASE nwParamB == 13
CASE nwParamB > 111 .OR.;
nWparamB < 48
RETURN( .F. )
ENDCASE
nField := oB:GetColCargo( oB:colPos )
IF nField == NIL
RETURN( .F. )
ENDIF
xKeyVal := IIF( EMPTY( INDEXKEY() ), NIL, &( INDEXKEY() ) )
nCrec := ( oB:alias )->( RECNO() )
lMoved := .F.
// This might look crazy but there is logic in the madness!
// When a modal dialog is active Windows disables it's parent
// window but leaves other windows active. To allow us
// to double click in another cell within the browse window
// we give the modal dialog used for editing another parent
// window which we don't care if it becomes inactive since
// the user can't see it anyway!
hWnd := CreateWindow("DEMO","",WS_EX_TRANSPARENT,0,0,0,0,0,0, _GetInstance() )
aCellData := oB:GetCellData()
xData := FIELDGET( nField )
cPicture := aCellData[ 2 ]
// Turn off CTL3D - if you are not using CTL3D.DLL then you can
// comment out the following line
Ctl3DUnRegister( _GetInstance() )
nResults := DialogBox(_GetInstance() , "foo", hWnd, ;
{|hDlg, nMsg, nWparam, nLparam|;
MFoo( hDlg, nMsg, nWparam, nLparam, oB, @xData, cPicture, nwParamb, nlParamb, xKeyVal, nField ) })
// Turn 3D effects back on - comment out the next two lines
// if you are not using CTL3D.DLL
Ctl3DRegister( _GetInstance() )
Ctl3DAutoSubClass( _GetInstance() )
// This part is important. Windows is going to send a WM_PAINT message
// if we click outside the currently active get/edit cell ( don't ask
// why - it just does!). To prevent unsightly re-draws we tell Windows
// that the client area of the WBrowse() window is ok!
// Just in case the user re-sized the browse window while celledit was
// active we DON'T want to validate the client area...
aARect := GetClientRect( oB:hWnd )
IF ( aRect[ 3 ] + aRect[ 4 ] == aARect[ 3 ] + aARect[ 4 ] )
ValidateRect( oB:hWnd )
ENDIF
lMoved := ( ( oB:alias )->( RECNO() ) != nCrec )
SetFocus( oB:hWnd )
( oB:alias )->( DBGOTO( nCrec ) )
FIELDPUT( nField, xData )
COMMIT
IF EMPTY( INDEXKEY() ) .OR. ( xKeyVal == &( INDEXKEY() ) ) ;
.AND. !lMoved
// make sure browse is correctly updated
oB:refreshCol( oB:colPos)
ELSE
// record may have moved relative to other records
oB:refreshAll()
ENDIF
IF nResults == WM_USER+2
oB:up()
ENDIF
IF nResults == WM_USER+1
oB:down()
ENDIF
// Get rid of our hidden window
DestroyWindow( hWnd )
RETURN( .T. )
// BCellEdit() - Used for BListBox()'s - NOTE the additional param hDlgWnd
// Please note that we don't use a "hidden" window for this one. The
// way things work in dialogs is a bit different than in "normal" windows.
//
FUNCTION BCellEdit( oB, nMsg, nwParamb, nlParamb, hDlgWnd )
LOCAL xKeyVal
LOCAL xData
LOCAL cPicture
LOCAL nResults
LOCAL nField
LOCAL aCellData
// Filter out the keystrokes we don't want
DO CASE
CASE nMsg == WM_LBUTTONDBLCLK
CASE nwParamB == 32
CASE nwParamB == 13
CASE nwParamB > 111 .OR.;
nWparamB < 48
RETURN( .F. )
ENDCASE
nField := oB:GetColCargo( oB:colPos )
IF nField == NIL
RETURN( .F. )
ENDIF
xKeyVal := IIF( EMPTY( INDEXKEY() ), NIL, &( INDEXKEY() ) )
aCellData := oB:GetCellData()
xData := FIELDGET( nField )
cPicture := aCellData[ 2 ]
Ctl3DUnRegister( _GetInstance() )
nResults := DialogBox(_GetInstance() , "foo", , ;
{|hDlg, nMsg, nWparam, nLparam|;
MFoo( hDlg, nMsg, nWparam, nLparam, oB, @xData, cPicture, nwParamb, nlParamb, xKeyVal, nField ) })
Ctl3DRegister( _GetInstance() )
Ctl3DAutoSubClass( _GetInstance() )
// In this case we tell Windows that the client area of the hidden listbox
// control/window is ok so we don't get a WM_PAINT message we don't want
// Just in case the user re-sized the browse window while celledit was
// active we DON'T want to validate the client area...
ValidateRect( GetDlgItem( hDlgWnd, 999 ), GetClientRect( GetDlgItem( hDlgWnd, 999 ) ) )
// This is of special importance! To keep keystrokes going to our BListBox()
// you HAVE to keep the focus on the hidden listbox control/window since
// BListBox() has subclassed it internally and gets the keystrokes that way.
// Setting focus to oB:hWnd is not going to get the job done! In your dialog
// procedure you should also set focus back to the hidden edit control/window
// each time the user switches focus to another control ( after you process
// it of course!).
SetFocus( GetDlgItem( hDlgWnd, 999 ) )
FIELDPUT( nField, xData )
COMMIT
IF EMPTY( INDEXKEY() ) .OR. ( xKeyVal == &( INDEXKEY() ) )
// make sure browse is correctly updated
oB:refreshCol( oB:colPos)
ELSE
// record may have moved relative to other records
oB:refreshAll()
ENDIF
IF nResults == WM_USER+2
oB:up()
ENDIF
IF nResults == WM_USER+1
oB:down()
ENDIF
RETURN( .T. )
// MFoo() - Used by both CellEdit() and BCellEdit()
//
STATIC FUNCTION MFoo( hDlgWnd, nMsg, nWparam, nLparam, oB, xData, cPicture, nwParamb, nlParamb, xKeyVal, nField )
STATIC GetList := {}
LOCAL hFont
DO CASE
CASE nMsg == WM_INITDIALOG
GetList := {}
PosEditWin( oB, hDlgWnd )
DoSubClEC( GetDlgItem( hDlgWnd, 101 ), hDlgWnd )
hFont := oB:colFont
IF hFont == NIL
@ DIALOG hDlgWnd ID 101 GET xData PICTURE IIF(cPicture != NIL,cPicture,"")
ELSE
@ DIALOG hDlgWnd ID 101 GET xData PICTURE IIF(cPicture != NIL,cPicture,"") FONT hFont
ENDIF
IF nwParamB != VK_RETURN
PostMessage( GetDlgItem( hDlgWnd, 101 ), WM_KEYDOWN, nwParamb, nlParamb )
ENDIF
RETURN(1)
CASE nMsg == WM_USER+1 .OR.; // down
nMsg == WM_USER+2 .OR.; // up
nMsg == WM_USER+3 // click on another cell
IsDialogOk( hDlgWnd, 101 )
xData:= GetList[1]:VarGet()
EndDialog( hDlgWnd, nMsg )
RETURN(1)
CASE nMsg == WM_COMMAND
DO CASE
CASE nWparam == IDOK
PostMessage( hDlgWnd, WM_USER+3, 0, 0 )
RETURN(1)
CASE nWparam == IDCANCEL
CANCEL DIALOG hDlgWnd
EndDialog( hDlgWnd, IDCANCEL )
RETURN(1)
ENDCASE
ENDCASE
RETURN(0)
// Please not the addition of the WM_KILLFOCUS message.
// It tells us when the user clicks in another cell..
//
FUNCTION DoSubClEC(hWnd, hDlgWnd)
LOCAL nProc
nProc := SubClassWindow(hWnd, ;
{|hWnd, nMsg, nWparam, nLparam| ;
WndProcEC(nProc, hWnd, nMsg, nWparam, nLparam, hDlgWnd)},;
{WM_KEYDOWN, WM_KEYUP, WM_KILLFOCUS})
RETURN(NIL)
STATIC FUNCTION WndProcEC(nProc, hWnd, nMsg, nWparam, nLparam, hDlgWnd)
DO CASE
CASE nMsg == WM_KEYDOWN
IF nWparam == VK_UP
SendMessage( hDlgWnd, WM_USER+2, 0, 0 )
ELSE
IF nWparam == VK_DOWN
SendMessage( hDlgWnd, WM_USER+1,0,0 )
ENDIF
ENDIF
CASE nMsg == WM_KILLFOCUS
PostMessage( hDlgWnd, WM_USER+3,0,0 )
ENDCASE
RETURN(CallWindowProc(nProc, hWnd, nMsg, nWparam, nLparam))
// No changes here - we still need to keep our window title/border, etc.
// from being re-drawn in the inactive mode..
//
FUNCTION DoSubClBWA(hWnd)
LOCAL nProc
nProc := SubClassWindow(hWnd, ;
{|hWnd, nMsg, nWparam, nLparam| ;
WndProcBWA(nProc, hWnd, nMsg, nWparam, nLparam)},;
{WM_NCACTIVATE})
RETURN(NIL)
STATIC FUNCTION WndProcBWA(nProc, hWnd, nMsg, nWparam, nLparam)
// IF nWparam is 0 then Windows is telling the window
// it needs to re-draw things in the inactive mode. If
// we don't pass the message along things will get messed
// up so we change the message param to 1 and the window
// proc will be fooled!
DO CASE
CASE nMsg == WM_NCACTIVATE
IF nWparam < 1
nWparam := 1
ENDIF
ENDCASE
RETURN(CallWindowProc(nProc, hWnd, nMsg, nWparam, nLparam))
// Modified Again!
// This one keeps the thick border around the active cell
// You can fiddle around with it if you like but be sure
// to save this one <g>...
//
STATIC FUNCTION PosEditWin( oB, hDlgWnd )
LOCAL aCell := oB:GetCellRect()
LOCAL aPoint[2]
LOCAL nWidth, nHeight
nWidth := aCell[3]
nHeight := aCell[4]
aPoint[1] := aCell[1]
aPoint[2] := aCell[2]
ClienttoScreen(oB:hWnd,aPoint)
MoveWindow(hDlgWnd,aPoint[1],aPoint[2]-1,nWidth,nHeight+1,.F.)
MoveWindow(GetDlgItem(hDlgWnd,101),3,1,nWidth-4,nHeight+1,.F.)
RETURN(NIL)