home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: OtherApp
/
OtherApp.zip
/
phoneb.zip
/
PHONEBK.VRX
< prev
next >
Wrap
Text File
|
1995-03-14
|
23KB
|
822 lines
/*:VRX Main
*/
/* Main
*/
Main:
/* Process the arguments.
Get the parent window.
*/
parse source . calledAs .
parent = ""
argCount = arg()
argOff = 0
if( calledAs \= "COMMAND" )then do
if argCount >= 1 then do
parent = arg(1)
argCount = argCount - 1
argOff = 1
end
end; else do
call VROptions 'ImplicitNames'
end
InitArgs.0 = argCount
if( argCount > 0 )then do i = 1 to argCount
InitArgs.i = arg( i + argOff )
end
drop calledAs argCount argOff
/* Load the windows
*/
call VRInit
parse source . . spec
_VREPrimaryWindowPath = ,
VRParseFileName( spec, "dpn" ) || ".VRW"
_VREPrimaryWindow = ,
VRLoad( parent, _VREPrimaryWindowPath )
drop parent spec
if( _VREPrimaryWindow == "" )then do
call VRMessage "", "Cannot load window:" VRError(), ,
"Error!"
_VREReturnValue = 32000
signal _VRELeaveMain
end
/* Process events
*/
call Init
signal on halt
do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
_VREEvent = VREvent()
interpret _VREEvent
end
_VREHalt:
_VREReturnValue = Fini()
call VRDestroy _VREPrimaryWindow
_VRELeaveMain:
call VRFini
exit _VREReturnValue
VRLoadSecondary:
__vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
if __vrlsWait then do
call VRFlush
end
__vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
if __vrlsHWnd = '' then signal __vrlsDone
if __vrlsWait \= 1 then signal __vrlsDone
call VRSet __vrlsHWnd, 'WindowMode', 'Modal'
__vrlsTmp = __vrlsWindows.0
if( DataType(__vrlsTmp) \= 'NUM' ) then do
__vrlsTmp = 1
end
else do
__vrlsTmp = __vrlsTmp + 1
end
__vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
__vrlsWindows.0 = __vrlsTmp
do while( VRIsValidObject( VRWindow() ) = 1 )
__vrlsEvent = VREvent()
interpret __vrlsEvent
end
__vrlsTmp = __vrlsWindows.0
__vrlsWindows.0 = __vrlsTmp - 1
call VRWindow __vrlsWindows.__vrlsTmp
__vrlsHWnd = ''
__vrlsDone:
return __vrlsHWnd
/*:VRX CN_People_ContextMenu
*/
CN_People_ContextMenu:
call VRMethod "MI_Popup","Popup"
return
/*:VRX CN_People_DoubleClick
*/
CN_People_DoubleClick:
container = "CN_People"
/* get all selected records */
call VRMethod container, "GetRecordList", "Selected", "reclist."
/* Get names of all the fields */
call VRMethod container, "GetFieldList", "FieldHandle."
do i=1 to FieldHandle.0
FieldName.i = VRMethod(container, "GetFieldAttr", FieldHandle.i, "Name")
fldname = FieldName.i
call value "FieldHandle.!"fldname, FieldHandle.i
end
FieldName.0 = FieldHandle.0
/* loop through all selected records */
do r=1 to reclist.0
call VRMethod container, "GetFieldData", reclist.r, "FieldData."
/* build the text version of the record */
record = ""
do i = 1 to FieldName.0
record = record";"FieldName.i";"FieldData.i
end
record = ";"FieldData.!name";;;"||record
/* open the notebook so user can edit the record */
record = NoteBk( VRWindow(), record )
parse var record ';' Name ';' icon ';' left ';' bottom ';' rem
call VRSet container, "Painting", 0
do while length(rem) > 0
parse var rem field ';' value ';' rem
ok = VRMethod( container, "SetFieldData", reclist.r, value("FieldHandle.!"field), value)
end
call VRSet container, "Painting", 1
end
/* turn off selection of container if container itself is currently selected */
call VRSet container, "Source", 0
return
/*:VRX CN_People_EndEdit
*/
CN_People_EndEdit:
/***********************************************************************
* This routine is needed under two circumstances:
* 1. when the user directly edits the caption of an icon (Icon view)
* this routine sets the Name field to the same value *so it displays
* the correct name on next switch to Detail view)
* 2. when the user directly edits the Name field (in Detail view)
* this routine sets the caption to the same value (so it displays
* the correct name on next switch to Icon view)
***********************************************************************
*/
container = "CN_People"
recordID = VRInfo("Record")
fieldID = VRInfo("Field")
recordID = VRInfo("Record")
cancelled = VRInfo("Cancelled")
if cancelled then
return
if fieldID = "" then /* from experience this is the caption */
do
fldvalue = VRMethod(container,"GetRecordAttr",recordID,"Caption")
rc = VRMethod(container,"SetFieldData", recordID, "Name", fldvalue)
return
end
/* Get names of all the fields */
call VRMethod container, "GetFieldList", "FieldHandle."
do i=1 to FieldHandle.0
fldname = VRMethod(container, "GetFieldAttr", FieldHandle.i, "Name")
FieldName.i = fldname
if FieldHandle.i = fieldID then
do
/* say fldname "changed" */
chgFieldName = fldname
if fldname = "Name" then
do
fldvalue = VRMethod(container, "GetFieldData", recordID, fieldID)
call VRMethod container, "SetRecordAttr", recordID, "Caption", fldvalue
end
end
call value "FieldHandle.!"fldname, FieldHandle.i
end
FieldName.0 = FieldHandle.0
return
/*:VRX CN_People_Init
*/
CN_People_Init: procedure expose Globals.
recordHandle = VRMethod( "CN_People", "AddField", "String", "Name", "Name" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "Company", "Company" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "Street", "Street" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "City", "City" )
/* call VRMethod "CN_People", "SetFieldAttr", recordHandle, "Visible", 0 */
recordHandle = VRMethod( "CN_People", "AddField", "String", "State", "State" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "ZIPCode", "ZIPCode" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "Telephone", "Telephone" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "FAX", "FAX" )
recordHandle = VRMethod( "CN_People", "AddField", "String", "Notes", "Notes")
return
/*:VRX CN_People_Load
*/
CN_People_Load:
/* Don't paint while we fill the container */
ok = VRSet( "CN_People", "Painting", 0 )
if FileName = "" | FileName = "[New]" then
do
people.0 = 1
people.1 = ";John Doe;person.ico;;;Name;John Doe;Company;ABC Corp;Street;1 Main Street;City;Podunk;State;CA;Telephone;(415) 555-1212;Notes;"
end
else
do
do i=1 while lines(FileName)
rec = linein(FileName)
people.i = rec
end
people.0 = i-1
rc = stream(FileName,"C","CLOSE")
end
/* Fill the container */
ok = VRMethod( "CN_People", "AddRecordList", , "", "people.")
/* Set default sort order */
ok = VRSet( "CN_People", "DetailSort", "Name" )
/* Set to paint now */
ok = VRSet( "CN_People", "Painting", 1 )
return
/*:VRX CN_People_PopupMenu
*/
CN_People_PopupMenu:
call VRMethod "M_Person", "Popup"
return
/*:VRX dialerDone
*/
dialerDone:
status = VRInfo("status")
/* say "Dialer sent status:" status */
return
/*:VRX Fini
*/
Fini:
window = VRWindow()
call VRSet window, "Visible", 0
drop window
return 0
/*:VRX getINIKeys
*/
getINIKeys:
AppName = "PhoneBook" /* INI application name */
INIFile = "PHONEBK.INI" /* INI file name */
COMPortKey = "COMPort" /* INI key for comport */
BaudRateKey = "BaudRate" /* INI key for baudrate */
DialStringKey = "DialString" /* INI key for dialing string */
HangupStringKey = "HangupString" /* INI key for hangup string */
LastFileKey = "LastFile" /* INI key for last phonebook file used */
return
/*:VRX Halt
*/
Halt:
signal _VREHalt
return
/*:VRX Init
*/
Init:
call ReadINI
call setFileName FileName
/* Make our main window active and visible */
window = VRWindow()
call VRMethod window, "CenterWindow"
call VRSet window, "Visible", 1
call VRMethod window, "Activate"
drop window
call CN_People_Init /* initialize the container window */
call CN_People_Load /* fille the container window */
return
/*:VRX MainWindow_Close
*/
MainWindow_Close:
call Quit
return
/*:VRX MainWindow_Resize
*/
MainWindow_Resize:
call VRSet "CN_People", "Painting", 0
call VRSet "CN_People", "Height", max(VRGet(VRWindow(),"Height")-939,0)
call VRSet "CN_People", "Width", max(VRGet(VRWindow(), "Width")-96,0)
call VRSet "CN_People", "Painting", 1
return
/*:VRX MI_File_Open_Click
*/
MI_File_Open_Click:
do forever
path = VRFileDialog( VRWindow(), "Open Phonebook", "Open", "*.PBK")
if path = "" then
return
RC = stream(path,"C","QUERY EXISTS")
if RC = "" then
do
msg.0 = 3
msg.1 = "Cannot find Phonebook file:"
msg.2 = path
msg.3 = "Press OK to continue."
button.0 = 1
button.1 = "OK"
call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
end
else
leave
end
path = RC
do i=1 while lines(path)
line.i = linein(path)
end
line.0 = i
call setFileName path
RC = stream(path,"C","CLOSE")
call WriteINI
return
/*:VRX MI_File_Save_As_Click
*/
MI_File_Save_As_Click:
do forever
path = VRFileDialog( VRWindow(), "Save Phonebook", "Save", "*.PBK")
if path = "" then
return
RC = stream(path,"C","QUERY EXISTS")
if RC \= "" then
do
msg.0 = 3
msg.1 = "Phonebook file already exists:"
msg.2 = path
msg.3 = "Press Yes to overwrite."
button.0 = 3
button.1 = "Yes"
button.2 = "No"
button.3 = "Cancel"
button = VRMessageStem( VRWindow(), "msg.","Error","N","button.",1,1)
if button = 1 then
leave
end
else
leave
end
/* path = RC */
call saveFile path
call setFileName path
call writeINI
return
/*:VRX MI_File_Save_Click
*/
MI_File_Save_Click:
if FileName = "" | FileName = "[New]" then
call MI_File_Save_As_Click
else
do
call saveFile FileName
end
return
/*:VRX MI_Help_About_Click
*/
MI_Help_About_Click:
call ProdHelp VRWindow()
return
/*:VRX MI_Options_Click
*/
MI_Options_Click:
call Options VRWindow()
call WriteINI
return
/*:VRX MI_Popup_Delete_Click
*/
MI_Popup_Delete_Click:
container = VRInfo("Source")
call VRMethod container, "GetRecordList", "Source", "reclist."
do i=1 to reclist.0
call VRMethod "CN_People", "GetFieldData", reclist.i, "Fields."
call VRMethod "CN_People", "RemoveRecord", reclist.i
end
/* turn off selection of container if container itself is currently selected */
call VRSet container, "Source", 0
return
/*:VRX MI_Popup_Dial_Click
*/
MI_Popup_Dial_Click:
container = VRInfo("Source")
call VRMethod container, "GetRecordList", "Source", "reclist."
if reclist.0 > 1 then
do
msg.0 = 3
msg.1 = "Cannot dial more than one person at a time."
msg.2 = "Select only one record to dial."
msg.3 = "Press OK to continue."
button.0 = 1
button.1 = "OK"
call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
end
if reclist.0 = 0 then
do
msg.0 = 3
msg.1 = "No person selected for dialing"
msg.2 = "Select one record to dial, then select Dial command."
msg.3 = "Press OK to continue."
button.0 = 1
button.1 = "OK"
call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
end
do i=1 to reclist.0
call VRMethod "CN_People", "GetFieldData", reclist.i, "Fields."
threadID = VRMethod("Application","StartThread","Dialer", Fields.!Telephone)
if threadID = -1 then
do
msg.0 = 3
msg.1 = "Could not start the dialer thread."
msg.2 = ""
msg.3 = "Press OK to continue."
button.0 = 1
button.1 = "OK"
call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
end
msg.0 = 3
msg.1 = "Dialing ..."
msg.2 = "Thread" threadID
msg.3 = "Press Cancel to abort dialing."
button.0 = 1
button.1 = "Cancel"
call VRMessageStem VRWindow(), "msg.","Dialing in progress","N","button.",1,1
call VRMethod "APplication","HaltThread",threadID
end
/* turn off selection of container if container itself is currently selected */
call VRSet container, "Source", 0
return
/*:VRX MI_Popup_New_Click
*/
MI_Popup_New_Click:
retvalue = NoteBk( VRWindow(), "New" )
drop rec.
rec.0 = 1
rec.1 = retvalue
ok = VRMethod("CN_People","AddRecordList",,,"rec.")
return
/*:VRX MI_Popup_Open_Click
*/
MI_Popup_Open_Click:
container = VRInfo("Source")
call VRMethod container, "GetRecordList", "Source", "reclist."
/* Get names of all the fields */
call VRMethod container, "GetFieldList", "FieldHandle."
do i=1 to FieldHandle.0
FieldName.i = VRMethod("CN_People", "GetFieldAttr", FieldHandle.i, "Name")
end
FieldName.0 = FieldHandle.0
do r=1 to reclist.0
record = ""
call VRMethod "CN_People", "GetFieldData", reclist.r, "FieldData."
do i = 1 to FieldName.0
record = record";"FieldName.i";"FieldData.i
end
record = ";"FieldData.!name";;;"||record
record = NoteBk( VRWindow(), record )
/* say "record = "record */
end
/* turn off selection of container if container itself is currently selected */
call VRSet container, "Source", 0
return
/*:VRX MI_Popup_Sort_By_City_Click
*/
MI_Popup_Sort_By_City_Click:
call MI_Sort_By "City"
return
/*:VRX MI_Popup_Sort_By_Company_Click
*/
MI_Popup_Sort_By_Company_Click:
call MI_Sort_By "Company"
return
/*:VRX MI_Popup_Sort_By_Name_Click
*/
MI_Popup_Sort_By_Name_Click:
call MI_Sort_By "Name"
return
/*:VRX MI_Popup_Sort_By_State_Click
*/
MI_Popup_Sort_By_State_Click:
call MI_Sort_By "State"
return
/*:VRX MI_Popup_Sort_By_Street_Click
*/
MI_Popup_Sort_By_Street_Click:
call MI_Sort_By "Street"
return
/*:VRX MI_Popup_Sort_By_Telephone_Click
*/
MI_Popup_Sort_By_Telephone_Click:
call MI_Sort_By "Telephone"
return
/*:VRX MI_Popup_Sort_By_ZIPCode_Click
*/
MI_Popup_Sort_By_ZIPCode_Click:
call MI_Sort_By "ZIPCode"
return
/*:VRX MI_Popup_View_Detail_Click
*/
MI_Popup_View_Detail_Click:
call MI_View_As "Detail"
return
/*:VRX MI_Popup_View_Icon_Click
*/
MI_Popup_View_Icon_Click:
call MI_View_As "Icon"
call VRMethod "CN_People","Arrange"
return
/*:VRX MI_Popup_View_Name_Click
*/
MI_Popup_View_Name_Click:
call MI_View_As "Name"
return
/*:VRX MI_Popup_View_Text_Click
*/
MI_Popup_View_Text_Click:
call MI_View_As "Text"
return
/*:VRX MI_Sort_By
*/
MI_Sort_By:
call VRSet "CN_People", "Sort", "Ascending"
call VRSet "CN_People", "DetailSort", arg(1)
call VRMethod "CN_People", "SortRecords"
/* Uncheck all sort by menu items and check the one selected as arg(1) */
names = "Name Company Street City State ZIPCode Telephone"
do n=1 to words(Names)
name = word(Names,n)
call VRSet "MI_Sort_By_"||name,"Checked",arg(1) = name
call VRSet "MI_Popup_Sort_By_"||name, "Checked", arg(1) = name
end
return
/*:VRX MI_Sort_By_City_Click
*/
MI_Sort_By_City_Click:
call MI_Sort_By "City"
return
/*:VRX MI_Sort_By_Company_Click
*/
MI_Sort_By_Company_Click:
call MI_Sort_By "Company"
return
/*:VRX MI_Sort_By_Name_Click
*/
MI_Sort_By_Name_Click:
call MI_Sort_By "Name"
return
/*:VRX MI_Sort_By_State_Click
*/
MI_Sort_By_State_Click:
call MI_Sort_By "State"
return
/*:VRX MI_Sort_By_Street_Click
*/
MI_Sort_By_Street_Click:
call MI_Sort_By "Street"
return
/*:VRX MI_Sort_By_Telephone_Click
*/
MI_Sort_By_Telephone_Click:
call MI_Sort_By "Telephone"
return
/*:VRX MI_Sort_By_ZIPCode_Click
*/
MI_Sort_By_ZIPCode_Click:
call MI_Sort_By "ZIPCode"
return
/*:VRX MI_View_arrange_Click
*/
MI_View_Arrange_Click:
call VRMethod "CN_People","Arrange"
return
/*:VRX MI_View_As
*/
MI_View_As:
/* Set the View of the container as requested by arg(1) */
Call VRSet "CN_People","View",arg(1)
/* Uncheck all View menu items and check the one selected as arg(1) */
names = "Icon Name Text Detail"
do n=1 to words(Names)
name = word(Names,n)
call VRSet "MI_View_"||name,"Checked",arg(1) = name
call VRSet "MI_Popup_View_"||name,"Checked", arg(1) = name
end
return
/*:VRX MI_View_Detail_Click
*/
MI_View_Detail_Click:
call MI_View_As "Detail"
return
/*:VRX MI_View_Icon_Click
*/
MI_View_Icon_Click:
call MI_View_As "Icon"
call VRMethod "CN_People","Arrange"
return
/*:VRX MI_View_Name_Click
*/
MI_View_Name_Click:
call MI_View_As "Name"
return
/*:VRX MI_View_Text_Click
*/
MI_View_Text_Click:
call MI_View_As "Text"
return
/*:VRX Quit
*/
Quit:
window = VRWindow()
call VRSet window, "Shutdown", 1
drop window
return
/*:VRX ReadINI
*/
ReadINI:
/************************************************************************
* Get values from INI file - PHONEBK.INI or create it if necessary
************************************************************************
*/
call getINIkeys
COMPort = VRGetIni( AppName, COMPortKey, INIFile, "NoClose" )
if COMPort = "" then
do
COMPort = "COM1:"
BaudRate = "2400"
DialString = "ATDT"
HangupString = "ATH"
FileName = "PHONEBK.PBK"
ok = VRSetIni(AppName, COMPortKey, COMPort, INIFile, "NoClose")
ok = VRSetIni(AppName, BaudRateKey, BaudRate, INIFile, "NoClose")
ok = VRSetIni(AppName, DialStringKey, DialString, INIFile, "NoClose")
ok = VRSetIni(AppName, HangupStringKey, HangupString, INIFile, "NoClose")
ok = VRSetIni(AppName, LastFileKey, FileName, INIFile)
end
else
do
BaudRate = VRGetIni( AppName, BaudRateKey, INIFile, "NoClose")
DialString = VRGetIni( AppName, DialStringKey, INIFile, "NoClose")
HangupString = VRGetIni( AppName, HangupStringKey, INIFile, "NoClose")
FileName = VRGetIni( AppName, LastFileKey, INIFile)
end
/* Set global variables so other files can get to them */
call VRMethod "Application", "PutVar", "COMPort"
call VRMethod "Application", "PutVar", "BaudRate"
call VRMethod "Application", "PutVar", "DialString"
call VRMethod "Application", "PutVar", "HangupString"
call VRMethod "Application", "PutVar", "FileName"
return
/*:VRX saveFile
*/
saveFile:
path = arg(1)
RC = stream(path,"C", "QUERY EXISTS")
if RC \= "" then
"@del" path /* Delete old file */
container = "CN_People"
/* Get names of all the fields */
call VRMethod container, "GetFieldList", "FieldHandle."
do i=1 to FieldHandle.0
FieldName.i = VRMethod("CN_People", "GetFieldAttr", FieldHandle.i, "Name")
end
FieldName.0 = FieldHandle.0
/* get all the records */
call VRMethod container, "GetRecordList", "All", "rec."
/* loop to write each record */
do r=1 to rec.0
record = ""
call VRMethod container, "GetFieldData", rec.r, "FieldData."
do i = 1 to FieldName.0
record = record";"FieldName.i";"FieldData.i
end
left = VRMethod( container, "GetRecordAttr", rec.r, "Left")
bottom = VRMethod( container, "GetRecordAttr", rec.r, "Bottom")
icon = VRMethod( container, "GetRecordAttr", rec.r, "Icon")
record = ";"FieldData.!name";"icon";"left";"bottom||record
/* say "record = "record */
ok = lineout(path,record)
end
RC = stream(path,"C","CLOSE")
return
/*:VRX setFileName
*/
setFileName:
FileName = arg(1)
call VRSet "MainWindow", "Caption", "Phone Book -" FileName
return
/*:VRX WriteINI
*/
WriteINI:
/************************************************************************
* Save values in INI file - PHONEBK.INI or create it if necessary
************************************************************************
*/
call getINIkeys
/* Get global variables values */
call VRMethod "Application", "GetVar", "COMPort"
call VRMethod "Application", "GetVar", "BaudRate"
call VRMethod "Application", "GetVar", "DialString"
call VRMethod "Application", "GetVar", "HangupString"
call VRMethod "Application", "GetVar", "FileName"
/* say COMport BaudRate DialString HangupString FileName */
ok = VRSetIni(AppName, COMPortKey, COMPort, INIFile, "NoClose")
ok = VRSetIni(AppName, BaudRateKey, BaudRate, INIFile, "NoClose")
ok = VRSetIni(AppName, DialStringKey, DialString, INIFile, "NoClose")
ok = VRSetIni(AppName, HangupStringKey, HangupString, INIFile, "NoClose")
ok = VRSetIni(AppName, LastFileKey, FileName, INIFile)
return