home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
DIALOGF2.PRG
< prev
next >
Wrap
Text File
|
1996-04-16
|
9KB
|
307 lines
// dialogf2.prg - dialog functions
//
// 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_CB
#define WIN_WANT_LB
#define WIN_WANT_ALL
#include "windows.ch"
//#include "topclass.ch"
#include "vo.ch"
#include "dialog.ch"
#include "vbxbi.ch"
// saDlg is { aDlg, ... }
// aDlg is: from CreateDialog() or resource from _Create_Dialog() below
#define D_ID 1 // { cnId, // in aDlg made by _Create_Dialog()
#define D_INST 2 // hInst,
#define D_INITVBX 3 // bInitVBX }
#define D_MAX 4 // used to detect aDlg made by _Create_Dialog()
// saParams is { aParams, ... }
// aParams is { aItem }
// aItem is:
#define P_ID 1 // { nId, // but nil for a bInit block in bAction
#define P_WCLASS 2 // cnWClass,
#define P_INIT 3 // xInit,
#define P_ACTION 4 // bAction,
#define P_VALID 5 // bValid,
#define P_INIRET 6 // xIniRet }
#define P_VBX P_WCLASS // cnWClass: shared with bVBX for INIT_PARAMS
#define P_MODAL P_INIT // xInit: shared with lModal for INIT_PARAMS
STATIC GLOBAL saDlg := {}
STATIC GLOBAL saParams := {} AS ARRAY // OF ARRAY OF ARRAY, parallel to saDlg
#command END DIALOG <hDlg>,<lModal>,<nwParam> ;
=> IF <lModal> ;
; EndDialog(<hDlg>, <nwParam>) ;
; ELSE ;
; DestroyWindow(<hDlg>) ;
; END
#translate INIT_PARAMS(aParams) => atail(aParams)
/*
* This function returns an array (aDlg) to be similar to the Clip-4-Win API
* function CreateDialog() - a little ugly but very convenient.
*/
function _Create_Dialog(cnId, hInst, bInitVBX)
return {cnId, hInst, bInitVBX} // A special aDlg made here! Not for AppendDialog()
function _Add_Dialog(aDlg, nId, cnWClass, xInit, bAction, bValid)
local i, hDlg, a := {nId, cnWClass, xInit, bAction, bValid, nil}
// also: {nil, bVBX, lModal, bInit, nil, nil}
if valtype(aDlg) == "N"
// an existing dialog
hDlg = aDlg
if nId != nil .and. xInit != nil
if valtype(cnWClass) == "N"
do case
case cnWClass == DLG_EDIT
if valtype(xInit) == "B" // a GET
a[P_INIRET] = eval(xInit, hDlg)
else
SetWindowText(GetDlgItem(hDlg, nId), ;
xInit)
endif
case cnWClass == DLG_COMBOBOX
BoxInit(hDlg, a, .t.)
case cnWClass == DLG_LISTBOX
if valtype(xInit) == "B" // a browse
a[P_INIRET] = eval(xInit, hDlg)
else
BoxInit(hDlg, a, .f.)
endif
case cnWClass == DLG_STATIC
SetWindowText(GetDlgItem(hDlg, nId), xInit)
case cnWClass == DLG_BUTTON
SetWindowText(GetDlgItem(hDlg, nId), xInit)
endcase
endif
endif
elseif (i := AScanExact(saDlg, aDlg)) == 0
if (i := AScanExact(saDlg, nil)) == 0
aadd(saDlg, aDlg)
i = len(saDlg)
aadd(saParams, {a})
else
saDlg[i] = aDlg
saParams[i] = {a}
endif
else
aadd(saParams[i], a)
endif
return i
function _Show_Dialog(aDlg, lModal, hWnd, bInit)
local nRet, nPos, cnId_aDlg, hInst, bVBX
if len(aDlg) < D_MAX
// resource dialog
cnId_aDlg = aDlg[D_ID]
hInst = aDlg[D_INST]
bVBX = aDlg[D_INITVBX]
else
cnId_aDlg = aDlg
// hInst = nil // it's nil anyway!
// bVBX = nil // no auto-init resource
endif
nPos = _Add_Dialog(aDlg, , bVBX, lModal, bInit)
if lModal
nRet = DialogBox(hInst, cnId_aDlg, hWnd, ;
{|hDlg, nMsg, nwParam, nlParam| ;
DlgProc(hDlg, nMsg, nwParam, nlParam, nPos)})
if nRet == -1
MessageBox(hWnd, "Dialog error e.g. resource not found", "Show Dialog")
endif
else
nRet = CreateDialog(hInst, cnId_aDlg, hWnd, ;
{|hDlg, nMsg, nwParam, nlParam| ;
DlgProc(hDlg, nMsg, nwParam, nlParam, nPos)})
if nRet == 0
MessageBox(hWnd, "Dialog error e.g. resource not found", "Show Dialog")
endif
endif
return nRet
static function DlgProc(hDlg, nMsg, nwParam, nlParam, nPos)
local nRet
do case
case nMsg == WM_INITDIALOG
nRet = OnInitDialog(hDlg, nwParam, nlParam, saParams[nPos])
case nMsg == WM_COMMAND
nRet = OnCommand(hDlg, nwParam, nlParam, saParams[nPos])
case nMsg == WM_VBXFIREEVENT
nRet = OnVBXFireEvent(hDlg, nwParam, nlParam, saParams[nPos])
case nMsg == WM_NCDESTROY
// last message in the life of this dialog - clean up
saDlg[nPos] := saParams[nPos] := nil
otherwise
nRet = 0 // want default behaviour
endcase
return nRet
static function BoxInit(hDlg, a, lCombo)
local hCtrl := GetDlgItem(hDlg, a[P_ID])
local nReset := iif(lCombo, CB_RESETCONTENT, LB_RESETCONTENT)
local nAdd := iif(lCombo, CB_ADDSTRING, LB_ADDSTRING)
local nSetSel := iif(lCombo, CB_SETCURSEL, LB_SETCURSEL)
SendMessage(hCtrl, WM_SETREDRAW, 0, 0)
SendMessage(hCtrl, nReset, 0, 0)
aeval(a[P_INIT], {|c| SendMessage(hCtrl, nAdd, 0, c)})
SendMessage(hCtrl, nSetSel, 0, 0)
SendMessage(hCtrl, WM_SETREDRAW, 1, 0)
return nil
static function OnCommand(hDlg, nwParam, nlParam, aParams)
local nRet, i, bAction, hCtrl, nCode, lOk, bValid, nId, a
/*
* A message from a control. We may have a code block to handle it.
*/
for i=1 to len(aParams)
if aParams[i, P_ID] == nwParam ;
.and. (bAction := aParams[i, P_ACTION]) != nil
// bAction is {|hDlg, hCtrl, nCode, nId, xIniRet| ...}
hCtrl = C4W_LoWord(nlParam)
nCode = C4W_HiWord(nlParam)
nRet = eval(bAction, hDlg, hCtrl, nCode, nwParam, aParams[i, P_INIRET])
exit
endif
next i
// default for Ok/Cancel, if not already handled
if nRet == nil
do case
case nwParam == IDOK
// check DIALOG GETs are ok
lOk = IsDialogOK(hDlg)
// check all VALID blocks are ok
for i=1 to len(aParams)
if (bValid := aParams[i, P_VALID]) != nil
// bValid is {|hDlg, hCtrl, nId, xIniRet| ...}
if !lOk
exit
endif
a = aParams[i]
nId = a[P_ID]
hCtrl = GetDlgItem(hDlg, nId)
lOk = eval(bValid, hDlg, hCtrl, nId, a[P_INIRET])
endif
next i
if lOk
END DIALOG hDlg, INIT_PARAMS(aParams)[P_MODAL], nwParam
endif
nRet = 1 // means msg handled
case nwParam == IDCANCEL
CANCEL DIALOG hDlg
END DIALOG hDlg, INIT_PARAMS(aParams)[P_MODAL], nwParam
nRet = 1 // means msg handled
endcase
endif
// note: the default return value is 0 for this (and most) messages
return iif(valtype(nRet) == "N" .and. nRet == 1, 1, 0)
static function OnInitDialog(hDlg, nwParam, nlParam, aParams)
local nRet, i, n := len(aParams)
local bAction, a, cnWClass, aInitParams := INIT_PARAMS(aParams)
if aInitParams[P_VBX] != nil
eval(aInitParams[P_VBX], hDlg)
endif
// do auto-init
for i=1 to n
if (a := aParams[i])[P_ID] != nil .and. a[P_INIT] != nil
if valtype(cnWClass := a[P_WCLASS]) == "N"
do case
case cnWClass == DLG_EDIT
if valtype(a[P_INIT]) == "B" // a GET
a[P_INIRET] = eval(a[P_INIT], hDlg)
else
SetWindowText(GetDlgItem(hDlg, a[P_ID]), ;
a[P_INIT])
endif
case cnWClass == DLG_COMBOBOX
BoxInit(hDlg, a, .t.)
case cnWClass == DLG_LISTBOX
if valtype(a[P_INIT]) == "B" // a browse
a[P_INIRET] = eval(a[P_INIT], hDlg)
else
BoxInit(hDlg, a, .f.)
endif
case cnWClass == DLG_STATIC
SetWindowText(GetDlgItem(hDlg, a[P_ID]), ;
a[P_INIT])
case cnWClass == DLG_BUTTON
SetWindowText(GetDlgItem(hDlg, a[P_ID]), ;
a[P_INIT])
endcase
endif
endif
next i
// give user a chance
if (bAction := aInitParams[P_ACTION]) != nil
// if bAction sets the input focus, it should return 0
nRet = eval(bAction, hDlg, WM_INITDIALOG, nwParam, nlParam)
endif
// note: the default return value below is 1 for this msg only
// (so by default the input focus is set automatically)
return iif(valtype(nRet) == "N" .and. nRet == 0, 0, 1)
static function OnVBXFireEvent(hDlg, nwParam, nlParam, aParams)
local aVBXEventStruct := Bin2A(C4W_Peek(nlParam, VBXEV_BYTELEN), ;
VBXEV_STRUCT_DEF)
local i, nId := aVBXEventStruct[VBXEV_ID], aInit, aEv, cEvent
for i=1 to len(aParams)
if aParams[i, P_ID] == nId
if (cEvent := aVBXEventStruct[VBXEV_EventName]) == nil
exit
endif
// found the control
aInit = aParams[i, P_INIT]
aEv = aInit[3] // event info
for i=1 to len(aEv) step 2
if aEv[i] == cEvent
//TBD: more params?
eval(aEv[i + 1], hDlg, aVBXEventStruct)
exit
endif
next i
exit
endif
next i
// note: the default return value is 0 for this (and most) messages
return 1