home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
genwif.tcl
< prev
next >
Wrap
Text File
|
1996-12-09
|
22KB
|
791 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1995-1996 by Cayenne Software Inc..
#
# This software is furnished under a license and may be used only in
# accordance with the terms of such license and with the inclusion of
# the above copyright notice. This software or any other copies thereof
# may not be provided or otherwise made available to any other person.
# No title to and ownership of the software is hereby transferred.
#
# The information in this software is subject to change without notice
# and should not be construed as a commitment by Cayenne Software Inc..
#
#---------------------------------------------------------------------------
#
# File : @(#)genwif.tcl /main/hindenburg/6
# Original date : 14-02-1995
# Description :
#
#---------------------------------------------------------------------------
#
require wif_const.tcl
require wif_regen.tcl
require guiclassin.tcl
global ne_wif_sections
set ne_wif_sections {
wif_sect
}
# Entry point for wif generation ...
#
proc class::generate_wif {guiClass} {
puts stdout "Generating for class '[$guiClass getName]'"
class2wiftgtfile $guiClass wif_file
global guiClassInfo
set guiClassInfo [GuiClassInfo new $guiClass]
if {[$guiClassInfo initStatus] == -1} {
# errors are given in GuiClassInfo constructor already
global ne_error_state
set ne_error_state 1
global gen_file
return
}
if [catch {prepare_wif_regeneration $guiClass} result] {
switch $errorCode {
ERR_REGEN {puts stderr $result}
default {error $result $errorInfo $errorCode}
}
global gen_file
catch {unset gen_file($wif_file)}
unset guiClassInfo
return
}
set class [$guiClassInfo refClass]
if {![genwif::checkRefClassName $guiClass $class]} {
global ne_error_state
set ne_error_state 1
unset guiClassInfo
return
}
genwif::version
genwif::ixwindow $guiClass $class
genwif::ixsuptbl $guiClass $class
genwif::ixsupflds $guiClass $class
genwif::ixsuptblbtns $guiClass $class
genwif::ixmenus $guiClass
genwif::calc_geometry $guiClass $class
global ne_sections
set ne_sections(wif_sect) [TextSection new]
$ne_sections(wif_sect) indent 0 "\t"
genwif::wif2section $ne_sections(wif_sect)
do_write_ne_sections [$guiClass getName] $wif_file $ne_wif_sections
unset guiClassInfo
}
proc genwif::checkRefClassName {guiClass class} {
# make sure that the referred class name is the same as in the wif file.
set orgName [lindex [wif_regen::get_contained_wif_obj_names ixWindow \
[ixwindow::genname $guiClass] ixSuperTable] 0]
if {$orgName == ""} {
return 1
}
set curName [ixsuptbl::genname $class]
if {$orgName != $curName} {
puts "ERROR: Property 'Referred Class' of gui-class '[$guiClass\
getName]' has changed since last Wif generation."
return 0
}
return 1
}
proc genwif::version {} {
global wif_regen
global WifVersion
if [info exists wif_regen] {
return
}
set wif_regen(VERSION) $WifVersion
}
proc genwif::ixwindow {guiClass class} {
global wif_regen
global DefWindowProps
global UserWindowProps
global WindowProps
global DefWindowHandlers
global WindowHandlers
set object_name [uncap [$guiClass getName]]WN
set wif_obj ixWindow$object_name
global $wif_obj
if {![info exists wif_regen(OBJECTS)]} {
set wif_regen(OBJECTS) $wif_obj
set ${wif_obj}(BEGIN) "BEGIN ixWindow $object_name"
foreach p $WindowProps {
if {[info exist UserWindowProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p = $UserWindowProps(${p})"
} elseif {[info exist DefWindowProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p *= $DefWindowProps(${p})"
} else {
lappend ${wif_obj}(PROPS) "$p = [\
ixwindow::generate_${p} $guiClass]"
}
}
foreach h $WindowHandlers {
lappend ${wif_obj}(HANDLERS) "[genwif::expand_handler \
$guiClass $class ixwindow $h]"
}
set ${wif_obj}(END) "END"
return
}
global UpdWindowProps
foreach p $UpdWindowProps {
wif_regen::update_prop_value ixWindow $object_name $p \
[ixwindow::generate_$p $guiClass]
}
}
proc ixwindow::generate_title {guiClass} {
return \"[$guiClass getName]\"
}
proc ixwindow::generate_database {guiClass} {
set cc [ClientContext::global]
set configV [$cc currentConfig]
if [$configV isNil] {
return NULL
}
set tdb_name [$configV getPropertyValue tdbname]
if {$tdb_name == ""} {
return NULL
}
return \"$tdb_name\"
}
proc ixwindow::generate_classname {guiClass} {
return \"[$guiClass getName]Window\"
}
proc ixwindow::genname {guiClass} {
return [uncap [$guiClass getName]]WN
}
proc ixwindow::generate_name {guiClass} {
return \"[ixwindow::genname $guiClass]\"
}
proc genwif::expand_handler {guiClass class wif_class handler {extra_arg ""}} {
set tmp_sect [TextSection new]
$tmp_sect indent 0 "\t"
if {$extra_arg == ""} {
${wif_class}::generate_${handler} $tmp_sect $guiClass $class
} else {
${wif_class}::generate_${handler} $tmp_sect $guiClass $class \
$extra_arg
}
return [$tmp_sect contents]
}
proc ixwindow::generate_pre_body {sect guiClass class} {
global DefWindowHandlers
set txt $DefWindowHandlers(pre_body)
class2tgtfiles $class src_file hdr_file
expand_text $sect $txt
}
proc ixwindow::generate_constructor_extension {sect guiClass class} {
global DefWindowHandlers
global TYPE_ID_NM
set txt $DefWindowHandlers(constructor_extension)
set cl_name [$class getName]
set class_type_supfld [uncap $cl_name][cap $TYPE_ID_NM]SF
expand_text $sect $txt
}
proc genwif::ixsuptbl {guiClass class} {
global wif_regen
global DefSupTblProps
global UserSupTblProps
global SupTblProps
global DefSupTblHandlers
global SupTblHandlers
set object_name [uncap [$class getName]]ST
set wif_obj ixSuperTable$object_name
global $wif_obj
if {![info exists $wif_obj]} {
set wif_containobj ixWindow[uncap [$guiClass getName]]WN
global $wif_containobj
lappend ${wif_containobj}(OBJECTS) $wif_obj
set ${wif_obj}(BEGIN) "BEGIN ixSuperTable $object_name"
foreach p $SupTblProps {
if {[info exist UserSupTblProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p = $UserSupTblProps(${p})"
} elseif {[info exist DefSupTblProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p *= $DefSupTblProps(${p})"
} else {
lappend ${wif_obj}(PROPS) \
"$p = [ixsuptbl::generate_${p} \
$guiClass $class]"
}
}
foreach h $SupTblHandlers {
lappend ${wif_obj}(HANDLERS) "[genwif::expand_handler \
$guiClass $class ixsuptbl $h]"
}
set ${wif_obj}(END) "END"
return
}
global UpdSupTblProps
foreach p $UpdSupTblProps {
wif_regen::update_prop_value ixSuperTable $object_name $p \
[ixsuptbl::generate_$p $guiClass $class]
}
}
# Get a all ancestor classes of the class (including class itself)
#
proc get_hierarchy {class {hierarchy ""}} {
if {[lsearch -exact $hierarchy $class] != -1} {
return $hierarchy
}
set hierarchy [linsert $hierarchy 0 $class]
foreach super [$class genNodeSet] {
set hierarchy [get_hierarchy [$super superClass] $hierarchy]
}
return $hierarchy
}
proc ixsuptbl::generate_updateTable {guiClass class} {
set class_hierarchy [get_hierarchy $class]
return \"[[[lindex $class_hierarchy 0] table] getUniqueName]\"
}
proc ixsuptbl::generate_numDisplayedCols {guiClass class} {
# note: add 1 for class_type field
set nr [llength [$guiClass dataAttrSet]]
return [incr nr]
}
proc ixsuptbl::generate_selectFromPart {guiClass class} {
set class_hierarchy [$guiClassInfo refClassHierarchy]
set table [[lvarpop class_hierarchy] table]
set from_part [$table getUniqueName]
while {![lempty $class_hierarchy]} {
set table [[lvarpop class_hierarchy] table]
append from_part ", "
append from_part [$table getUniqueName]
}
return \"${from_part}\"
}
proc ixsuptbl::generate_selectJoinPart {guiClass class} {
set class_hierarchy [$guiClassInfo refClassHierarchy]
set root_class [lvarpop class_hierarchy]
set rtabnm [[$root_class table] getUniqueName]
if [lempty $class_hierarchy] {
return NULL
}
foreach cl $class_hierarchy {
lappend table_names [[$cl table] getUniqueName]
}
set key_cols [get_col_list [$root_class table] KEYS_NO_TYPE]
foreach col $key_cols {
lappend key_names [$col getUniqueName]
}
set first 1
set join_part ""
foreach tabnm $table_names {
foreach key $key_names {
if !$first {
append join_part " AND "
}
set first 0
append join_part "$rtabnm.$key = $tabnm.$key"
}
}
return \"${join_part}\"
}
proc ixsuptbl::genname {class} {
return [uncap [$class getName]]ST
}
proc ixsuptbl::generate_name {guiClass class} {
return \"[ixsuptbl::genname $class]\"
}
proc ixsuptbl::generate_SQLDelete {sect guiClass class} {
global DefSupTblHandlers
set txt $DefSupTblHandlers(SQLDelete)
set cl_name [$class getName]
expand_text $sect $txt
}
proc ixsuptbl::generate_SQLInsert {sect guiClass class} {
global DefSupTblHandlers
set txt $DefSupTblHandlers(SQLInsert)
set cl_name [$class getName]
expand_text $sect $txt
}
proc ixsuptbl::generate_SQLUpdate {sect guiClass class} {
global DefSupTblHandlers
set txt $DefSupTblHandlers(SQLUpdate)
set cl_name [$class getName]
expand_text $sect $txt
}
proc genwif::ixsupflds {guiClass class} {
set orgSupFlds [wif_regen::get_contained_wif_obj_names ixSuperTable \
[ixsuptbl::genname $class] ixSuperField]
set colNum 1
foreach col [$guiClassInfo refColumns] {
genwif::ixsupfld $class $col $colNum
incr colNum
set supfldname [ixsupfld::genname $class $col]
set idx [lsearch $orgSupFlds $supfldname]
if {$idx != -1} {
set orgSupFlds [lreplace $orgSupFlds $idx $idx]
}
lappend orderedSupFldWifObjs ixSuperField$supfldname
}
# The remaining "orgSupFlds" are obsolete; they are not removed,
# however, their colNum and SQLRole properties are set to an
# appropriate value.
foreach sf $orgSupFlds {
wif_regen::update_prop_value ixSuperField $sf colNum $colNum
incr colNum
set sql_role [wif_regen::get_prop_value ixSuperField \
$sf SQLRole]
if {$sql_role != "ixSuperField::noRole"} {
puts "WARNING: Resetting SQLRole property of\
ixSuperField '$sf' to 'ixSuperField::noRole'"
wif_regen::update_prop_value ixSuperField \
$sf SQLRole ixSuperField::noRole
}
lappend orderedSupFldWifObjs ixSuperField$sf
}
if 0 {
# Put the ixSuperFields in the right order in the containing
# ixSuperTable.
set wif_containobj ixSuperTable[uncap [$class getName]]ST
global $wif_containobj
set btns [wif_regen::get_contained_wif_objs ixSuperTable \
[ixsuptbl::genname $class] ixButton]
set ${wif_containobj}(OBJECTS) [concat $orderedSupFldWifObjs \
$btns]
}
}
proc genwif::ixsupfld {class col colNum} {
global DefSupFldProps
global UserSupFldProps
global SupFldProps
set object_name [ixsupfld::genname $class $col]
set wif_obj ixSuperField$object_name
global $wif_obj
if {![info exists $wif_obj]} {
set wif_containobj ixSuperTable[uncap [$class getName]]ST
global $wif_containobj
lappend ${wif_containobj}(OBJECTS) $wif_obj
set ${wif_obj}(BEGIN) "BEGIN ixSuperField $object_name"
foreach p $SupFldProps {
if {[info exist UserSupFldProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p = $UserSupFldProps(${p})"
} elseif {[info exist DefSupFldProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p *= $DefSupFldProps(${p})"
} else {
lappend ${wif_obj}(PROPS) "$p =\
[ixsupfld::generate_${p} $class $col $colNum]"
}
}
global TYPE_ID_NM
if {[$col getName] == $TYPE_ID_NM} {
wif_regen::update_prop_value ixSuperField $object_name \
shown FALSE
wif_regen::update_prop_value ixSuperField $object_name \
queryState ixSuperField::readOnlyState
wif_regen::update_prop_value ixSuperField $object_name \
height 1
wif_regen::update_prop_value ixSuperField $object_name \
title_Height 1
}
set ${wif_obj}(END) "END"
return
}
global UpdSupFldProps
foreach p $UpdSupFldProps {
wif_regen::update_prop_value ixSuperField $object_name $p \
[ixsupfld::generate_$p $class $col $colNum]
}
}
proc ixsupfld::generate_SQLRole {class col colNum} {
if {[$col getColumnType] == "key"} {
return ixSuperField::noUpdateRole
} else {
return ixSuperField::updateRole
}
}
proc ixsupfld::generate_colNum {class col colNum} {
return $colNum
}
proc ixsupfld::generate_columnName {class col colNum} {
return \"[$col getUniqueName]\"
}
proc ixsupfld::generate_tableName {class col colNum} {
return \"[[$col table] getUniqueName]\"
}
proc ixsupfld::generate_title {class col colNum} {
return \"[$col getUniqueName]\"
}
proc ixsupfld::genname {class col} {
set ucl_name [uncap [$class getName]]
set ccol_name [cap [$col getUniqueName]]
return ${ucl_name}${ccol_name}SF
}
proc ixsupfld::generate_name {class col colNum} {
return \"[ixsupfld::genname $class $col]\"
}
proc ixsupfld::generate_encLength {class col colNum} {
return [map_fgl2enclength [$col getType4GL]]
}
proc ixsupfld::generate_initialDataValue {class col colNum} {
set initval [$col getPropertyValue initial_value]
if {$initval == ""} {
return NULL
}
if {[string index $initval 0] == "\""} {
return $initval
} else {
return \"${initval}\"
}
}
proc ixsupfld::generate_maxDataChars {class col colNum} {
return [map_fgl2maxdatachars [$col getType4GL]]
}
proc ixsupfld::generate_type {class col colNum} {
return [map_fgl2sqltype [$col getType4GL]]
}
proc ixsupfld::generate_nullable {class col colNum} {
if {[$col isNullable]} {
return TRUE
}
return FALSE
}
proc ixsupfld::generate_primaryKey {class col colNum} {
if {[$col get_obj_type] == "column" && [$col getColumnType] == "key"} {
return TRUE
}
return FALSE
}
proc genwif::ixsuptblbtns {guiClass class} {
global SupTblBtnProps
global DefSupTblBtnProps
global UserSupTblBtnProps
global SupTblBtnHandlers
set ucl_name [uncap [$class getName]]
set wif_containobj ixSuperTable${ucl_name}ST
global $wif_containobj
foreach oper [$guiClass operationSet] {
set btn_name [$oper getName]
set object_name ${ucl_name}${btn_name}BT
set wif_obj ixButton$object_name
global $wif_obj
if {![info exists $wif_obj]} {
lappend ${wif_containobj}(OBJECTS) $wif_obj
set ${wif_obj}(BEGIN) "BEGIN ixButton $object_name"
foreach p $SupTblBtnProps {
if {[info exist UserSupTblBtnProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p = $UserSupTblBtnProps(${p})"
} elseif {[info exist DefSupTblBtnProps($p)]} {
lappend ${wif_obj}(PROPS) \
"$p *= $DefSupTblBtnProps(${p})"
} else {
lappend ${wif_obj}(PROPS) "$p =\
[ixsuptblbtn::generate_${p} \
$ucl_name $btn_name]"
}
}
foreach h $SupTblBtnHandlers {
lappend ${wif_obj}(HANDLERS) \
"[genwif::expand_handler $guiClass \
$class ixsuptblbtn $h $btn_name]"
}
set ${wif_obj}(END) "END"
continue
}
global UpdSupTblBtnProps
foreach p $UpdSupTblBtnProps {
wif_regen::update_prop_value ixButton $object_name $p \
[ixsuptblbtn::generate_$p $ucl_name $btn_name]
}
}
}
proc ixsuptblbtn::generate_title {ucl_name btn_name} {
return \"${btn_name}\"
}
proc ixsuptblbtn::generate_name {ucl_name btn_name} {
return \"${ucl_name}${btn_name}BT\"
}
proc ixsuptblbtn::generate_activate {sect $guiClass class btn_name} {
global DefSTBtnActivateHdlrs
if {[info exists DefSTBtnActivateHdlrs($btn_name)]} {
set txt $DefSTBtnActivateHdlrs($btn_name)
} else {
set txt $DefSTBtnActivateHdlrs(NotYetImplemented)
}
expand_text $sect $txt
}
proc genwif::ixmenus {guiClass} {
# Note: generation of menus is different from generation of other wif
# objects. The contents of the customization file "stdixmenus.wif_tmpl"
# (containing ixMenu objects only) is incorporated in the generated
# wif file. This is only the case if no ixMenu objects are present
# yet in the (re)generated wif file.
set cl_name [$guiClass getName]
set ucl_name [uncap $cl_name]
if {[llength [wif_regen::get_contained_wif_objs ixWindow ${ucl_name}WN \
ixMenu]] != 0} {
# The containing window already contains menus
return
}
set fileName "stdixmenus"
set fileType "wif_tmpl"
set cc [ClientContext::global]
if {![$cc customFileExists $fileName $fileType etc]} {
return
}
set tmpFile [args_file {}]
$cc downLoadCustomFile $fileName $fileType etc $tmpFile
set object_name ${ucl_name}MN
set wif_obj ixMenu$object_name
global $wif_obj
set wif_containobj ixWindow${ucl_name}WN
global $wif_containobj
lappend ${wif_containobj}(OBJECTS) $wif_obj
set sect [TextSection new]
expand_file $sect $tmpFile current_section $sect guiClass $guiClass
BasicFS::removeFile $tmpFile
set ${wif_obj}(BEGIN) [$sect contents]
set ${wif_obj}(END) ""
}
proc genwif::calc_geometry {guiClass class} {
global SF_interspace
global SF_title_Width
global SF_title_interspace
global BT_interspace
global BT_height
set curr_top $SF_interspace
set curr_left [expr $SF_title_Width + 2 * $SF_title_interspace]
set curr_title_Top $SF_interspace
set curr_title_Left $SF_title_interspace
set suptblname [ixsuptbl::genname $class]
set allSupFlds [wif_regen::get_contained_wif_obj_names \
ixSuperTable $suptblname ixSuperField]
foreach sf $allSupFlds {
set left [wif_regen::get_prop_value ixSuperField $sf left]
if {$left == "NULL"} {
wif_regen::update_prop_value ixSuperField $sf left \
$curr_left
} else {
set curr_left $left
}
set top [wif_regen::get_prop_value ixSuperField $sf top]
if {$top == "NULL"} {
wif_regen::update_prop_value ixSuperField $sf top \
$curr_top
} else {
set curr_top $top
}
set title_Left [wif_regen::get_prop_value ixSuperField \
$sf title_Left]
if {$title_Left == "NULL"} {
wif_regen::update_prop_value ixSuperField $sf \
title_Left $curr_title_Left
} else {
set curr_title_Left $title_Left
}
set title_Top [wif_regen::get_prop_value ixSuperField \
$sf title_Top]
if {$title_Top == "NULL"} {
wif_regen::update_prop_value ixSuperField $sf \
title_Top $curr_title_Top
} else {
set curr_title_Top $title_Top
}
incr curr_top [wif_regen::get_prop_value ixSuperField $sf \
height]
incr curr_top $SF_interspace
set curr_title_Top $curr_top
}
set curr_left $BT_interspace
incr curr_top [expr $SF_interspace + $BT_interspace]
set suptbl_height [wif_regen::get_prop_value ixSuperTable \
$suptblname height]
set minimal_curr_top [expr $suptbl_height - $BT_height - $BT_interspace]
if { $minimal_curr_top > $curr_top } {
set curr_top $minimal_curr_top
}
set allButns [wif_regen::get_contained_wif_obj_names \
ixSuperTable $suptblname ixButton]
foreach btn $allButns {
set left [wif_regen::get_prop_value ixButton $btn left]
if {$left == "NULL"} {
wif_regen::update_prop_value ixButton $btn left \
$curr_left
} else {
set curr_left $left
}
set top [wif_regen::get_prop_value ixButton $btn top]
if {$top == "NULL"} {
wif_regen::update_prop_value ixButton $btn top \
$curr_top
} else {
set curr_top $top
}
incr curr_left [wif_regen::get_prop_value ixButton $btn width]
incr curr_left $BT_interspace
}
incr curr_top [expr $BT_height + $BT_interspace]
set windowname [ixwindow::genname $guiClass]
set suptbl_width [wif_regen::get_prop_value ixSuperTable \
$suptblname width]
set delta_width [expr $curr_left - $suptbl_width]
if {$delta_width > 0} {
wif_regen::update_prop_value ixSuperTable $suptblname width \
$curr_left
set window_width [wif_regen::get_prop_value ixWindow \
$windowname width]
incr window_width $delta_width
wif_regen::update_prop_value ixWindow $windowname width \
$window_width
}
set delta_height [expr $curr_top - $suptbl_height]
if {$delta_height > 0} {
wif_regen::update_prop_value ixSuperTable $suptblname height \
$curr_top
set window_height [wif_regen::get_prop_value ixWindow \
$windowname height]
incr window_height $delta_height
wif_regen::update_prop_value ixWindow $windowname height \
$window_height
}
}
proc genwif::wif2section {sect} {
global wif_regen
if {[info exist wif_regen(VERSION)]} {
$sect append "VERSION $wif_regen(VERSION)\n"
}
if {[info exist wif_regen(OBJECTS)]} {
genwif::wifobject2section $wif_regen(OBJECTS) $sect
}
catch {unset wif_regen}
}
proc genwif::wifobject2section {wifobject sect} {
global $wifobject
$sect append "[string trimleft [set ${wifobject}(BEGIN)]]\n"
$sect indent +
if [info exists ${wifobject}(PROPS)] {
foreach prop [set ${wifobject}(PROPS)] {
$sect append "[string trimleft $prop]\n"
}
}
if [info exists ${wifobject}(OBJECTS)] {
foreach obj [set ${wifobject}(OBJECTS)] {
genwif::wifobject2section $obj $sect
}
}
set curr_indent [$sect indent]
if [info exists ${wifobject}(HANDLERS)] {
foreach handl [set ${wifobject}(HANDLERS)] {
split_handler $handl start_h body_h end_h
$sect append "[string trim $start_h]\n"
$sect indent 0
$sect append "$body_h"
$sect indent $curr_indent
$sect append "[string trim $end_h]\n"
}
}
$sect indent -
$sect append "[string trimleft [set ${wifobject}(END)]]\n"
catch {unset $wifobject}
}
proc split_handler {handl start_h body_h end_h} {
upvar $start_h sh
upvar $body_h bh
upvar $end_h eh
set first_nl [string first "\n" $handl]
set last_nl [string last "\n" $handl]
set sh [string range $handl 0 $first_nl]
set bh [string range $handl [incr first_nl] $last_nl]
set eh [string range $handl $last_nl end]
}