win.tcl 135 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156
  1. ###########################################################
  2. # Name: win.tcl
  3. # Author: Daniele Bonini (posta@elettronica.lol)
  4. # Date: 26/11/2023
  5. # Desc: Win namespace of RadXIDE.
  6. #
  7. # Win namespace scaffolding and most of the code
  8. # here presented and distributed contains excerpts
  9. # from [alited](https://github.com/aplsimple/alited
  10. # by Alex Plotnikov and contributors to the project.
  11. # The original code of these excerpts could be
  12. # borrowed from other sources which the author
  13. # and the contributors to this RadXIDE have no
  14. # knowledge about.
  15. #
  16. # License: MIT. Copyrights 5 Mode (Last implementation and adaptations.)
  17. # Copyright (c) 2021-2023 Alex Plotnikov https://aplsimple.github.io (original scaffolding and excerpts.)
  18. #
  19. ###########################################################
  20. namespace eval win {
  21. array set _PU_opts [list -NONE =NONE=]
  22. set _PU_opts(_MODALWIN_) [list]
  23. variable _AP_Properties; array set _AP_Properties [list]
  24. variable _AP_ICO { none folder OpenFile SaveFile saveall print font color \
  25. date help home misc terminal run tools file find replace other view \
  26. categories actions config pin cut copy paste plus minus add delete \
  27. change diagram box trash double more undo redo up down previous next \
  28. previous2 next2 upload download tag tagoff tree lock light restricted \
  29. attach share mail www map umbrella gulls sound heart clock people info \
  30. err warn ques retry yes no ok cancel exit }
  31. variable _AP_IMG; array set _AP_IMG [list]
  32. variable _AP_VARS; array set _AP_VARS [list]
  33. variable UFF "\uFFFF"
  34. variable querydlg {}
  35. variable CheckNomore
  36. array set msgarray [list]
  37. set Dlgpath ""
  38. set Dlgname ""
  39. set dlg(PATH) ""
  40. set dlg(NAME) ""
  41. set dlg(FIELDS) {}
  42. set Indexdlg 0
  43. set _savedvv [list]
  44. set MODALWINDOW {}
  45. set Foundstr {}
  46. # array set data [list]
  47. # set data(en1) {}
  48. # set data(docheck) yes
  49. set Foundstr {} ;# current found string
  50. set HLstring {} ;# current selected string
  51. set Widgetopts [list]
  52. set _Defaults [dict create \
  53. bts {{} {}} \
  54. but {{} {}} \
  55. buT {{} {-width -20 -pady 1}} \
  56. btT {{} {-width -20 -pady 1 -relief flat -overrelief raised -highlightthickness 0 -takefocus 0}} \
  57. can {{} {}} \
  58. chb {{} {}} \
  59. swi {{} {}} \
  60. chB {{} {-relief sunken -padx 6 -pady 2}} \
  61. cbx {{} {}} \
  62. fco {{} {}} \
  63. ent {{} {}} \
  64. enT {{} {-insertwidth $::apave::cursorwidth -insertofftime 250 -insertontime 750}} \
  65. fil {{} {}} \
  66. fis {{} {}} \
  67. dir {{} {}} \
  68. fon {{} {}} \
  69. clr {{} {}} \
  70. dat {{} {}} \
  71. fiL {{} {}} \
  72. fiS {{} {}} \
  73. diR {{} {}} \
  74. foN {{} {}} \
  75. clR {{} {}} \
  76. daT {{} {}} \
  77. sta {{} {}} \
  78. too {{} {}} \
  79. fra {{} {}} \
  80. ftx {{} {}} \
  81. frA {{} {}} \
  82. gut {{} {-width 0 -highlightthickness 1}} \
  83. lab {{-sticky w} {}} \
  84. laB {{-sticky w} {}} \
  85. lfr {{} {}} \
  86. lfR {{} {-relief groove}} \
  87. lbx {{} {-activestyle none -exportselection 0 -selectmode browse}} \
  88. flb {{} {}} \
  89. meb {{} {}} \
  90. meB {{} {}} \
  91. nbk {{} {}} \
  92. opc {{} {}} \
  93. pan {{} {}} \
  94. pro {{} {}} \
  95. rad {{} {}} \
  96. raD {{} {-padx 6 -pady 2}} \
  97. sca {{} {-orient horizontal -takefocus 0}} \
  98. scA {{} {-orient horizontal -takefocus 0}} \
  99. sbh {{-sticky ew} {-orient horizontal -takefocus 0}} \
  100. sbH {{-sticky ew} {-orient horizontal -takefocus 0}} \
  101. sbv {{-sticky ns} {-orient vertical -takefocus 0}} \
  102. sbV {{-sticky ns} {-orient vertical -takefocus 0}} \
  103. scf {{} {}} \
  104. seh {{-sticky ew} {-orient horizontal -takefocus 0}} \
  105. sev {{-sticky ns} {-orient vertical -takefocus 0}} \
  106. siz {{} {}} \
  107. spx {{} {}} \
  108. spX {{} {}} \
  109. tbl {{} {-selectborderwidth 1 -highlightthickness 2 \
  110. -labelcommand tablelist::sortByColumn -stretch all \
  111. -showseparators 1}} \
  112. tex {{} {-undo 1 -maxundo 0 -highlightthickness 2 -insertofftime 250 -insertontime 750 -insertwidth $::apave::cursorwidth -wrap word -selborderwidth 1 -exportselection 0}} \
  113. tre {{} {-selectmode browse}} \
  114. h_ {{-sticky ew -csz 3 -padx 3} {}} \
  115. v_ {{-sticky ns -rsz 3 -pady 3} {}}]
  116. set TexM {}
  117. # __________________________ AddButtonIcon _________________________ #
  118. proc AddButtonIcon {w attrsName} {
  119. # Gets the button's icon based on its text and name (e.g. butOK) and
  120. # appends it to the attributes of button.
  121. # w - button's name
  122. # attrsName - name of variable containing attributes of the button
  123. upvar 1 $attrsName attrs
  124. set com [getOption -com {*}$attrs]
  125. if {[string is integer -strict $com]} {
  126. extractOptions attrs -com {}
  127. append attrs " -com {::radxide::win::res {} $com}" ;# returned integer result
  128. }
  129. if {[getOption -image {*}$attrs] ne {}} return
  130. set txt [getOption -t {*}$attrs]
  131. if {$txt eq {}} { set txt [getOption -text {*}$attrs] }
  132. set im {}
  133. set icolist [list {exit abort} {exit close} \
  134. {SaveFile save} {OpenFile open}]
  135. # ok, yes, cancel, apply buttons should be at the end of list
  136. # as their texts can be renamed (e.g. "Help" in e_menu's "About")
  137. lappend icolist {*}[iconImage] {yes apply}
  138. foreach icon $icolist {
  139. lassign $icon ic1 ic2
  140. # text of button is of highest priority at defining its icon
  141. if {[string match -nocase $ic1 $txt] || \
  142. [string match -nocase b*t$ic1 $w] || ($ic2 ne {} && ( \
  143. [string match -nocase b*t$ic2 $w] || [string match -nocase $ic2 $txt]))} {
  144. if {[string match -nocase btT* $w]} {
  145. set cmpd none
  146. } else {
  147. set cmpd left
  148. }
  149. append attrs " [iconA $ic1 small $cmpd]"
  150. break
  151. }
  152. }
  153. return
  154. }
  155. # __________________ AddPopupAttr ________________#
  156. proc AddPopupAttr {w attrsName atRO isRO args} {
  157. # Adds the attribute to call a popup menu for an editable widget.
  158. # w - widget's name
  159. # attrsName - variable name for attributes of widget
  160. # atRO - "readonly" attribute (internally used)
  161. # isRO - flag of readonly widget
  162. # args - widget states to be checked
  163. upvar 1 $attrsName attrs
  164. lassign $args state state2
  165. if {$state2 ne {}} {
  166. if {[getOption -state {*}$attrs] eq $state2} return
  167. set isRO [expr {$isRO || [getOption -state {*}$attrs] eq $state}]
  168. }
  169. if {$isRO} {append atRO RO}
  170. append attrs " $atRO $w"
  171. return
  172. }
  173. # __________________________ AppendButtons _________________________ #
  174. proc AppendButtons {widlistName buttons neighbor pos defb timeout win modal} {
  175. # Adds buttons to the widget list from a position of neighbor widget.
  176. # widlistName - variable name for widget list
  177. # buttons - buttons to add
  178. # neighbor - neighbor widget
  179. # pos - position of neighbor widget
  180. # defb - default button
  181. # timeout - timeout (to count down seconds and invoke a button)
  182. # win - dialogue's path
  183. # modal - yes if the window is modal
  184. # Returns list of "Help" button's name and command.
  185. upvar $widlistName widlist
  186. namespace upvar ::radxide dan dan
  187. variable Dlgpath
  188. set Defb1 [set Defb2 [set bhlist {}]]
  189. foreach {but txt res} $buttons {
  190. #set com "res $Dlgpath"
  191. #set com "::radxide::win::res $Dlgpath"
  192. #if {[info commands $res] eq {}} {
  193. # set com "$com $res"
  194. #} else {
  195. # if {$res eq {destroy}} {
  196. # # for compatibility with old modal windows
  197. # if {$modal} {set res "$com 0"} {set res "destroy $win"}
  198. # }
  199. # set com $res ;# "res" is set as a command
  200. #}
  201. set com $res
  202. if {$but eq {butHELP}} {
  203. # Help button contains the command in "res"
  204. set com [string map "%w $win" $res]
  205. set bhlist [list $but $com]
  206. } elseif {$Defb1 eq {}} {
  207. set Defb1 $but
  208. } elseif {$Defb2 eq {}} {
  209. set Defb2 $but
  210. }
  211. if {[set _ [string first "::" $txt]]>-1} {
  212. set tt " -tip {[string range $txt $_+2 end]}"
  213. set txt [string range $txt 0 $_-1]
  214. } else {
  215. set tt {}
  216. }
  217. if {$timeout ne {} && ($defb eq $but || $defb eq {})} {
  218. set tmo "-timeout {$timeout}"
  219. } else {
  220. set tmo {}
  221. }
  222. if {$but eq {butHELP}} {
  223. set neighbor [lindex $widlist end 1]
  224. set widlist [lreplace $widlist end end]
  225. lappend widlist [list $but $neighbor T 1 1 {-st w} \
  226. "-t \"$txt\" -com \"$com\"$tt $tmo -tip F1"]
  227. set h h_Help
  228. lappend widlist [list $h $but L 1 94 {-st we}]
  229. set neighbor $h
  230. } else {
  231. lappend widlist [list $but $neighbor $pos 1 1 {-st we} \
  232. "-t \"$txt\" -com \"$com\"$tt $tmo"]
  233. set neighbor $but
  234. }
  235. set pos L
  236. }
  237. lassign [LowercaseWidgetName $Dlgpath.fra.$Defb1] Defb1
  238. lassign [LowercaseWidgetName $Dlgpath.fra.$Defb2] Defb2
  239. return $bhlist
  240. }
  241. # __________________________ appendDialogField _________________________ #
  242. proc addDialogField {fldname oldval newval} {
  243. variable dlg
  244. set newlist [list $fldname $oldval $newval]
  245. set dlg(FIELDS) [linsert $dlg(FIELDS) end $newlist]
  246. }
  247. # __________________________ basicFontSize _________________________ #
  248. proc basicFontSize {{fs 0} {ds 0}} {
  249. # Gets/Sets a basic size of font used in apave
  250. # fs - font size
  251. # ds - incr/decr of size
  252. # If 'fs' is omitted or ==0, this method gets it.
  253. # If 'fs' >0, this method sets it.
  254. namespace upvar ::radxide dan dan
  255. #if {$fs} {
  256. # set ::radxide::_CS_(fs) [expr {$fs + $ds}]
  257. # my create_Fonts
  258. # return $::radxide::_CS_(fs)
  259. #} else {
  260. # return [expr {$::radxide::_CS_(fs) + $ds}]
  261. #}
  262. return $dan(CHARSIZE)
  263. }
  264. # __________________________ basicDefFont _________________________ #
  265. proc basicDefFont {{deffont ""}} {
  266. # Gets/Sets a basic default font.
  267. # deffont - font
  268. # If 'deffont' is omitted or =="", this method gets it.
  269. # If 'deffont' is set, this method sets it.
  270. namespace upvar ::radxide dan dan
  271. #if {$deffont ne ""} {
  272. # return [set ::apave::_CS_(defFont) $deffont]
  273. #} else {
  274. # return $::apave::_CS_(defFont)
  275. #}
  276. return $dan(CHARFAMILY)
  277. }
  278. # __________________________ basicTextFont _________________________ #
  279. proc basicTextFont {{textfont ""}} {
  280. # Gets/Sets a basic font used in editing/viewing text widget.
  281. # textfont - font
  282. # If 'textfont' is omitted or =="", this method gets it.
  283. # If 'textfont' is set, this method sets it.
  284. namespace upvar ::radxide dan dan
  285. #if {$textfont ne ""} {
  286. # return [set ::apave::_CS_(textFont) $textfont]
  287. #} else {
  288. # return $::apave::_CS_(textFont)
  289. #}
  290. return $dan(CHARFAMILY)
  291. }
  292. # __________________________ checkXY _________________________ #
  293. proc checkXY {win w h x y} {
  294. # Checks the coordinates of window (against the screen).
  295. # w - width of window
  296. # h - height of window
  297. # x - window's X coordinate
  298. # y - window's Y coordinate
  299. # Returns new coordinates in +X+Y form.
  300. # check for left/right edge of screen (accounting decors)
  301. set scrw [expr {[winfo vrootwidth $win] - 12}]
  302. set scrh [expr {[winfo vrootheight $win] - 36}]
  303. if {($x + $w) > $scrw } {
  304. set x [expr {$scrw - $w}]
  305. }
  306. if {($y + $h) > $scrh } {
  307. set y [expr {$scrh - $h}]
  308. }
  309. if {![string match -* $x]} {set x +[string trimleft $x +]}
  310. if {![string match -* $y]} {set y +[string trimleft $y +]}
  311. return ${x}x${y}
  312. }
  313. # _________________________ centeredXY ________________________ #
  314. proc centeredXY {win rw rh rx ry w h} {
  315. # Gets the coordinates of centered window (against its parent).
  316. # rw - parent's width
  317. # rh - parent's height
  318. # rx - parent's X coordinate
  319. # ry - parent's Y coordinate
  320. # w - width of window to be centered
  321. # h - height of window to be centered
  322. # Returns centered coordinates in +X+Y form.
  323. set x [expr {max(0, $rx + ($rw - $w) / 2)}]
  324. set y [expr {max(0,$ry + ($rh - $h) / 2)}]
  325. return [checkXY $win $w $h $x $y]
  326. }
  327. # ________________________ centerWin _________________________ #
  328. proc centerWin {win wwidth wheight} {
  329. namespace upvar ::radxide dan dan
  330. set screen_width [winfo screenwidth $win]
  331. set screen_height [winfo screenheight $win]
  332. #tk_messageBox -title $dan(TITLE) -icon error -message $screen_width
  333. set half_screen_w [expr {0}]
  334. if {[expr {$screen_width/$screen_height} > 2]} {
  335. set half_screen_w [expr {$screen_width/2}]
  336. set wrong_geo [centeredXY $win $half_screen_w $screen_height 0 0 $wwidth $wheight]
  337. } else {
  338. set wrong_geo [centeredXY $win $screen_width $screen_height 0 0 $wwidth $wheight]
  339. }
  340. #set geo [string map {x ""} $geo]
  341. #wm geometry $dan(WIN) "=$dan(WIDTH)x$dan(HEIGHT)$geo"
  342. wm geometry $win =${wwidth}x${wheight}
  343. # Lets do it modal:
  344. set offsetx [winfo x $win]
  345. set offsety [winfo y $win]
  346. set disinfox [winfo pointerx [winfo parent $win]]
  347. #tk_messageBox -title $dan(TITLE) -icon error -message $disinfox
  348. #tk_messageBox -title $dan(TITLE) -icon error -message $half_screen_w
  349. set display [expr {1}]
  350. if { $disinfox>$half_screen_w } {
  351. set display [expr {2}]
  352. }
  353. #tk_messageBox -title $dan(TITLE) -icon error -message $display
  354. set newx [expr {($half_screen_w-$wwidth)/2}]
  355. if {$display>1} {
  356. set newx [expr {$half_screen_w+(($half_screen_w-$wwidth)/2)}]
  357. }
  358. #tk_messageBox -title $dan(TITLE) -icon error -message newx=$newx
  359. set newy [expr {70}]
  360. wm geometry $win +$newx+$newy
  361. }
  362. #_______________________ CheckData _______________________ #
  363. # proc CheckData {op} {
  364. # # Checks if the find/replace data are valid.
  365. # # op - if "repl", checks for "Replace" operation
  366. # # Return "yes", if the input data are valid.
  367. #
  368. # namespace upvar :radxide dan dan
  369. #
  370. # variable data
  371. #
  372. # # this means "no checks when used outside of the dialogue":
  373. # if {!$data(docheck)} {return yes}
  374. #
  375. # set ret yes
  376. # if {[set data(en1)] eq {}} { set ret no }
  377. # if {[set data(en1)] > $dan(MAXFINDLENGTH)} { set ret no }
  378. #
  379. # if {$ret eq no} {
  380. # # if find/replace field is empty, let the bell tolls for him
  381. # bell
  382. # return no
  383. # }
  384. # return yes
  385. # }
  386. # ________________________ CleanUps _________________________ #
  387. proc CleanUps {{wr ""}} {
  388. }
  389. proc danInitDialogs {} {
  390. namespace upvar ::radxide dan dan
  391. variable Dlgpath
  392. variable Dlgname
  393. variable dlg
  394. variable Indexdlg
  395. set Dlgpath ""
  396. set Dlgname ""
  397. set dlg(PATH) ""
  398. set dlg(NAME) ""
  399. set dlg(FIELDS) {}
  400. set Indexdlg 0
  401. }
  402. # ________________________ defaultATTRS _________________________ #
  403. proc defaultATTRS {{type ""} {opts ""} {atrs ""} {widget ""}} {
  404. # Sets, gets or registers default options and attributes for widget type.
  405. # type - widget type
  406. # opts - new default grid/pack options
  407. # atrs - new default attributes
  408. # widget - Tcl/Tk command for the new registered widget type
  409. # The *type* should be a three letter unique string.
  410. # If the *type* is absent in the registered types and *opts* and/or *atrs*
  411. # is not set to "", defaultATTRS registers the new *type* with its grid/pack
  412. # options and attributes. At that *widget* is a command for the new widget
  413. # type. For example, to register "toolbutton" widget:
  414. # my defaultATTRS tbt {} {-style Toolbutton -compound top} ttk::button
  415. # Options and attributes may contain data (variables and commands)
  416. # to be processed by [subst].
  417. # Returns:
  418. # - if not set *type*: a full list of options and attributes of all types
  419. # - if set *type* only: a list of options, attributes and *widget*
  420. # - else: a list of updated options, attributes and *widget*
  421. variable _Defaults
  422. if {$type eq {}} {return $_Defaults}
  423. set optatr "$opts$atrs"
  424. if {[catch {set def1 [dict get $_Defaults $type]}]} {
  425. if {$optatr eq {}} {
  426. set err "[self method]: \"$type\" widget type not registered."
  427. puts -nonewline stderr $err
  428. return -code error $err
  429. }
  430. set def1 [list $opts $atrs $widget]
  431. }
  432. if {$optatr eq {}} {return [subst $def1]}
  433. lassign $def1 defopts defatrs widget
  434. if {[catch {set defopts [dict replace $defopts {*}$opts]}]} {
  435. set defopts [string trim "$defopts $opts"]
  436. }
  437. if {[catch {set defatrs [dict replace $defatrs {*}$atrs]}]} {
  438. set defatrs [string trim "$defatrs $atrs"]
  439. }
  440. set newval [list $defopts $defatrs $widget]
  441. dict set _Defaults $type $newval
  442. return $newval
  443. }
  444. # ________________________ defaultAttrs _________________________ #
  445. proc defaultAttrs {{type ""} {opts ""} {atrs ""} {widget ""}} {
  446. # Sets, gets or registers default options and attributes for widget type.
  447. # type - widget type
  448. # opts - new default grid/pack options
  449. # atrs - new default attributes
  450. # widget - Tcl/Tk command for the new registered widget type
  451. # See also: APaveBase::defaultATTRS
  452. return [defaultATTRS $type $opts $atrs $widget]
  453. }
  454. # ________________________ dlgPath _________________________ #
  455. proc dlgPath {} {
  456. # Gets a current dialogue's path.
  457. # In fact, it does the same as [my dlgPath], but it can be
  458. # called outside of apave dialogue object (useful sometimes).
  459. namespace upvar ::radxide dan dan
  460. #variable Dlgpath
  461. # xxx
  462. variable Dlgname
  463. variable Indexdlg
  464. set Winpath $dan(WIN)
  465. # xxx
  466. #set wdia $Winpath.dia
  467. set wdia $Winpath.dia$Dlgname$Indexdlg
  468. return [set dlg(PATH) [set Dlgpath $wdia]]
  469. }
  470. # ________________________ DiaWidgetNameter _________________________ #
  471. proc DiaWidgetName {w} {
  472. # Gets a widget name of apave dialogue.
  473. # w - name of widget
  474. # The name of widget may be partial. In this case it's prepended
  475. # the current dialogue's frame path.
  476. # Useful in "input" dialogue when -method option is present
  477. # or widget names are uppercased.
  478. # See also: MakeWidgetName, input
  479. if {[string index $w 0] eq {.}} {return $w}
  480. return $Dlgpath.fra.$w
  481. }
  482. # ________________________ displayTaggedText _________________________ #
  483. proc displayTaggedText {w contsName {tags ""}} {
  484. # Sets the text widget's contents using tags (ornamental details).
  485. # w - text widget's name
  486. # contsName - variable name for contents to be set in the widget
  487. # tags - list of tags to be applied to the text
  488. # The lines in *text contents* are divided by \n and can include
  489. # *tags* like in a html layout, e.g. <red>RED ARMY</red>.
  490. # The *tags* is a list of "name/value" pairs. 1st is a tag's name, 2nd
  491. # is a tag's value.
  492. # The tag's name is "pure" one (without <>) so e.g.for <b>..</b> the tag
  493. # list contains "b".
  494. # The tag's value is a string of text attributes (-font etc.).
  495. # If the tag's name is FG, FG2, BG or BG2, then it is really a link color.
  496. }
  497. # ________________________ displayText _________________________ #
  498. proc displayText {w conts {pos 1.0}} {
  499. # Sets the text widget's contents.
  500. # w - text widget's name
  501. # conts - contents to be set in the widget
  502. if {[set state [$w cget -state]] ne {normal}} {
  503. $w configure -state normal
  504. }
  505. $w replace 1.0 end $conts
  506. $w edit reset; $w edit modified no
  507. if {$state eq {normal}} {
  508. ::tk::TextSetCursor $w $pos
  509. } else {
  510. $w configure -state $state
  511. }
  512. return
  513. }
  514. # __________________________ editDialogField _________________________ #
  515. proc editDialogField {index fldname oldval newval} {
  516. namespace upvar ::radxide dan dan
  517. variable dlg
  518. set newlist {$fldname $oldval $newval}
  519. lset dlg(FIELDS) $index $newlist
  520. }
  521. # ________________________ ExpandOptions _________________________ #
  522. proc ExpandOptions {options} {
  523. # Expands shortened options.
  524. set options [string map {
  525. { -st } { -sticky }
  526. { -com } { -command }
  527. { -t } { -text }
  528. { -w } { -width }
  529. { -h } { -height }
  530. { -var } { -variable }
  531. { -tvar } { -textvariable }
  532. { -lvar } { -listvariable }
  533. { -ro } { -readonly }
  534. } " $options"]
  535. return $options
  536. }
  537. # ________________________ error _________________________ #
  538. proc error {{fileName ""}} {
  539. # Gets the error's message at reading/writing.
  540. # fileName - if set, return a full error messageat opening file
  541. variable _PU_opts
  542. if {$fileName eq ""} {
  543. return $_PU_opts(_ERROR_)
  544. }
  545. return "Error of access to\n\"$fileName\"\n\n$_PU_opts(_ERROR_)"
  546. }
  547. # ________________________ extractOption _________________________ #
  548. proc extractOptions {optsVar args} {
  549. # Gets options' values and removes the options from the input list.
  550. # optsVar - variable name for the list of options and values
  551. # args - list of "option / default value" pairs
  552. # Returns a list of options' values, according to args.
  553. # See also: parseOptions
  554. upvar 1 $optsVar opts
  555. set retlist [parseOptions $opts {*}$args]
  556. foreach {o v} $args {
  557. set opts [removeOptions $opts $o]
  558. }
  559. return $retlist
  560. }
  561. # ________________________ FCfieldAttrs _________________________ #
  562. proc FCfieldAttrs {wnamefull attrs varopt} {
  563. # Fills the non-standard attributes of file content widget.
  564. # wnamefull - a widget name
  565. # attrs - a list of all attributes
  566. # varopt - a variable option
  567. # The *varopt* refers to a variable part such as tvar, lvar:
  568. # * -inpval option means an initial value of the field
  569. # * -retpos option has p1:p2 format (e.g. 0:10) to cut a substring from a returned value
  570. # Returns *attrs* without -inpval and -retpos options.
  571. # xxx
  572. variable Widgetopts
  573. lassign [parseOptions $attrs $varopt {} -retpos {} -inpval {}] \
  574. vn rp iv
  575. if {[string first {-state disabled} $attrs]<0 && $vn ne {}} {
  576. set all {}
  577. if {$varopt eq {-lvar}} {
  578. lassign [extractOptions attrs -values {} -ALL 0] iv a
  579. if {[string is boolean -strict $a] && $a} {set all ALL}
  580. lappend Widgetopts "-lbxname$all $wnamefull $vn"
  581. }
  582. if {$rp ne {}} {
  583. if {$all ne {}} {set rp 0:end}
  584. lappend Widgetopts "-retpos $wnamefull $vn $rp"
  585. }
  586. }
  587. if {$iv ne {}} { set $vn $iv }
  588. return [removeOptions $attrs -retpos -inpval]
  589. }
  590. # ________________________ FCfieldValues _________________________ #
  591. proc FCfieldValues {wnamefull attrs} {
  592. # Fills the file content widget's values.
  593. # wnamefull - name (path) of fco widget
  594. # attrs - attributes of the widget
  595. ; proc readFCO {fname} {
  596. # Reads a file's content.
  597. # Returns a list of (non-empty) lines of the file.
  598. if {$fname eq {}} {
  599. set retval {{}}
  600. } else {
  601. set retval {}
  602. foreach ln [split [readTextFile $fname {} 1] \n] {
  603. # probably, it's bad idea to have braces in the file of contents
  604. set ln [string map [list \\ \\\\ \{ \\\{ \} \\\}] $ln]
  605. if {$ln ne {}} {lappend retval $ln}
  606. }
  607. }
  608. return $retval
  609. }
  610. ; proc contFCO {fline opts edge args} {
  611. # Given a file's line and options,
  612. # cuts a substring from the line.
  613. # xxx
  614. variable Widgetopts
  615. lassign [parseOptionsFile 1 $opts {*}$args] opts
  616. lassign $opts - - - div1 - div2 - pos - len - RE - ret
  617. set ldv1 [string length $div1]
  618. set ldv2 [string length $div2]
  619. set i1 [expr {[string first $div1 $fline]+$ldv1}]
  620. set i2 [expr {[string first $div2 $fline]-1}]
  621. set filterfile yes
  622. if {$ldv1 && $ldv2} {
  623. if {$i1<0 || $i2<0} {return $edge}
  624. set retval [string range $fline $i1 $i2]
  625. } elseif {$ldv1} {
  626. if {$i1<0} {return $edge}
  627. set retval [string range $fline $i1 end]
  628. } elseif {$ldv2} {
  629. if {$i2<0} {return $edge}
  630. set retval [string range $fline 0 $i2]
  631. } elseif {$pos ne {} && $len ne {}} {
  632. set retval [string range $fline $pos $pos+[incr len -1]]
  633. } elseif {$pos ne {}} {
  634. set retval [string range $fline $pos end]
  635. } elseif {$len ne {}} {
  636. set retval [string range $fline 0 $len-1]
  637. } elseif {$RE ne {}} {
  638. set retval [regexp -inline $RE $fline]
  639. if {[llength $retval]>1} {
  640. foreach r [lrange $retval 1 end] {append retval_tmp $r}
  641. set retval $retval_tmp
  642. } else {
  643. set retval [lindex $retval 0]
  644. }
  645. } else {
  646. set retval $fline
  647. set filterfile no
  648. }
  649. if {$retval eq {} && $filterfile} {return $edge}
  650. set retval [string map [list "\}" "\\\}" "\{" "\\\{"] $retval]
  651. return [list $retval $ret]
  652. }
  653. set edge $Edge
  654. set ldv1 [string length $edge]
  655. set filecontents {}
  656. set optionlists {}
  657. set tplvalues {}
  658. set retpos {}
  659. set values [getOption -values {*}$attrs]
  660. if {[string first $edge $values]<0} { ;# if 1 file, edge
  661. set values "$edge$values$edge" ;# may be omitted
  662. }
  663. # get: files' contents, files' options, template line
  664. set lopts {-list {} -div1 {} -div2 {} -pos {} -len {} -RE {} -ret 0}
  665. while {1} {
  666. set i1 [string first $edge $values]
  667. set i2 [string first $edge $values $i1+1]
  668. if {$i1>=0 && $i2>=0} {
  669. incr i1 $ldv1
  670. append tplvalues [string range $values 0 $i1-1]
  671. set fdata [string range $values $i1 $i2-1]
  672. lassign [parseOptionsFile 1 $fdata {*}$lopts] fopts fname
  673. lappend filecontents [readFCO $fname]
  674. lappend optionlists $fopts
  675. set values [string range $values $i2+$ldv1 end]
  676. } else {
  677. append tplvalues $values
  678. break
  679. }
  680. }
  681. # fill the combobox lines, using files' contents and options
  682. if {[set leno [llength $optionlists]]} {
  683. set newvalues {}
  684. set ilin 0
  685. lassign $filecontents firstFCO
  686. foreach fline $firstFCO { ;# lines of first file for a base
  687. set line {}
  688. set tplline $tplvalues
  689. for {set io 0} {$io<$leno} {incr io} {
  690. set opts [lindex $optionlists $io]
  691. if {$ilin==0} { ;# 1st cycle: add items from -list option
  692. lassign $opts - list1 ;# -list option goes first
  693. if {[llength $list1]} {
  694. foreach l1 $list1 {append newvalues "\{$l1\} "}
  695. lappend Widgetopts "-list $wnamefull [list $list1]"
  696. }
  697. }
  698. set i1 [string first $edge $tplline]
  699. if {$i1>=0} {
  700. lassign [contFCO $fline $opts $edge {*}$lopts] retline ret
  701. if {$ret ne "0" && $retline ne $edge && \
  702. [string first $edge $line]<0} {
  703. set p1 [expr {[string length $line]+$i1}]
  704. if {$io<($leno-1)} {
  705. set p2 [expr {$p1+[string length $retline]-1}]
  706. } else {
  707. set p2 end
  708. }
  709. set retpos "-retpos $p1:$p2"
  710. }
  711. append line [string range $tplline 0 $i1-1] $retline
  712. set tplline [string range $tplline $i1+$ldv1 end]
  713. } else {
  714. break
  715. }
  716. set fline [lindex [lindex $filecontents $io+1] $ilin]
  717. }
  718. if {[string first $edge $line]<0} {
  719. # put only valid lines into the list of values
  720. append newvalues "\{$line$tplline\} "
  721. }
  722. incr ilin
  723. }
  724. # replace old 'values' attribute with the new 'values'
  725. lassign [parseOptionsFile 2 $attrs -values \
  726. [string trimright $newvalues]] attrs
  727. }
  728. return "$attrs $retpos"
  729. }
  730. # ________________________ fillGutter _________________________ #
  731. proc fillGutter {txt {canvas ""} {width ""} {shift ""} fg bg} {
  732. # Fills a gutter of text with the text's line numbers.
  733. # txt - path to the text widget
  734. # canvas - canvas of the gutter
  735. # width - width of the gutter, in chars
  736. # shift - addition to the width (to shift from the left side)
  737. # args - additional arguments for tracing
  738. # The code is borrowed from open source tedit project.
  739. namespace upvar ::radxide dan dan
  740. $canvas configure -state normal
  741. if {$canvas eq {}} {
  742. event generate $txt <Configure> ;# repaints the gutter
  743. return
  744. }
  745. set i 1
  746. set gcont [list]
  747. set totlines [expr [$txt count -lines 0.0 end]]
  748. while true {
  749. if {$i > $totlines} break
  750. #set dline [$txt dlineinfo $i] ;# xxx
  751. set dline [$txt get [lindex [split $i .] 0].0 [lindex [split $i .] 0].end]
  752. #if {[llength $dline] == 0} break
  753. #set height [lindex $dline 3] ;# xxx
  754. #set y [expr {[lindex $dline 1]}] ;# xxx
  755. set linenum [format "%${width}d" [lindex [split $i .] 0]]
  756. #set i [$txt index "$i +1 lines linestart"] # xxx
  757. #lappend gcont [list $y $linenum\n]
  758. lappend gcont [list [lindex [split $i .] 0] [expr {$linenum}]\n]
  759. incr i
  760. }
  761. set newwidth $dan(GUTTERWIDTH);
  762. $canvas delete 1.0 end
  763. set y [expr {0}]
  764. foreach g $gcont {
  765. lassign $g y linenum
  766. $canvas insert [expr {$y}].0 $linenum
  767. }
  768. $canvas configure -state disabled
  769. return 2
  770. }
  771. # ________________________ FieldName _________________________ #
  772. proc FieldName {name} {
  773. # Gets a field name.
  774. return fraM.fra$name.$name
  775. }
  776. # ________________________ findInText ___________________________ #
  777. proc findInText {{donext 0} {txt ""} {varFind ""} {dobell yes}} {
  778. # Finds a string in text widget.
  779. # donext - "1" means 'from a current position'
  780. # txt - path to the text widget
  781. # varFind - variable
  782. # dobell - if yes, bells
  783. # Returns yes, if found (or nothing to find), otherwise returns "no";
  784. # also, if there was a real search, the search string is added.
  785. namespace upvar ::radxide dan dan
  786. variable Foundstr
  787. if {$txt eq {}} {
  788. set txt $dan(TEXT)
  789. set sel $Foundstr
  790. } elseif {$donext && [set sel [get_HighlightedString]] ne {}} {
  791. # find a string got with alt+left/right
  792. } elseif {$varFind eq {}} {
  793. set sel $Foundstr
  794. } else {
  795. set sel [set $varFind]
  796. }
  797. if {$donext} {
  798. set pos [$txt index insert]
  799. if {{sel} in [$txt tag names $pos]} {
  800. set pos [$txt index "$pos + 1 chars"]
  801. }
  802. set pos [$txt search -- $sel $pos end]
  803. } else {
  804. set pos {}
  805. set_HighlightedString {}
  806. }
  807. if {![string length "$pos"]} {
  808. set pos [$txt search -- $sel 1.0 end]
  809. }
  810. if {[string length "$pos"]} {
  811. ::tk::TextSetCursor $txt $pos
  812. $txt tag add sel $pos [$txt index "$pos + [string length $sel] chars"]
  813. #focus $txt
  814. set res yes
  815. } else {
  816. if {$dobell} bell
  817. set res no
  818. }
  819. return [list $res $sel]
  820. }
  821. # ________________________ findTextOK _________________________ #
  822. proc findTextOK {} {
  823. namespace upvar ::radxide dan dan
  824. variable dlg
  825. variable data
  826. variable Foundstr
  827. set wt $dan(TEXT)
  828. #if {$inv>-1} {set data(lastinvoke) $inv}
  829. #set t $Dlgpath.fra.fraM.fraent.ent
  830. set t [dlgPath].fra.[FieldName [lindex [getDialogField 0] 0]]
  831. #tk_messageBox -title $dan(TITLE) -icon info -message textbox=$t
  832. set varname [lindex [getDialogField end] 0]
  833. #tk_messageBox -title $dan(TITLE) -icon info -message varname=$varname
  834. set oldsearchtext [lindex [getDialogField end] 1]
  835. #tk_messageBox -title $dan(TITLE) -icon info -message oldsearchtext=$oldsearchtext
  836. set newsearchtext [string trim [$t get]]
  837. #tk_messageBox -title $dan(TITLE) -icon info -message newsearchtext=$newsearchtext
  838. set Foundstr $newsearchtext
  839. findInText 1 $wt
  840. #ShowResults1 [FindAll $wt]
  841. return 1
  842. }
  843. # ________________________ findTextCancel _________________________ #
  844. proc findTextCancel {} {
  845. #catch {[destroy .danwin.diaRenameFile1]}
  846. catch {[destroy [dlgPath]]}
  847. return 0
  848. }
  849. # ________________________ GetAttrs _________________________ #
  850. proc GetAttrs {options {nam3 ""} {disabled 0} } {
  851. # Expands attributes' values.
  852. # options - list of attributes and values
  853. # nam3 - first three letters (type) of widget's name
  854. # disabled - flag of "disabled" state
  855. # Returns expanded attributes.
  856. set opts [list]
  857. foreach {opt val} [list {*}$options] {
  858. switch -exact -- $opt {
  859. -t - -text {
  860. ;# these options need translating \\n to \n
  861. # catch {set val [subst -nocommands -novariables $val]}
  862. set val [string map [list \\n \n \\t \t] $val]
  863. set opt -text
  864. }
  865. -st {set opt -sticky}
  866. -com {set opt -command}
  867. -w {set opt -width}
  868. -h {set opt -height}
  869. -var {set opt -variable}
  870. -tvar {set opt -textvariable}
  871. -lvar {set opt -listvariable}
  872. -ro {set opt -readonly}
  873. }
  874. lappend opts $opt \{$val\}
  875. }
  876. if {$disabled} {
  877. append opts [NonTtkStyle $nam3 1]
  878. }
  879. return $opts
  880. }
  881. # ________________________ get_HighlightedString _________________________ #
  882. proc get_HighlightedString {} {
  883. # Returns a string got from highlighting by Alt+left/right/q/w.
  884. variable HLstring
  885. if {[info exists HLstring]} {
  886. return $HLstring
  887. }
  888. return {}
  889. }
  890. # ________________________ GetIntOptions _________________________ #
  891. proc GetIntOptions {w options row rowspan col colspan} {
  892. # Gets specific integer options. Then expands other options.
  893. # w - widget's name
  894. # options - grid options
  895. # row, rowspan - row and its span of thw widget
  896. # col, colspan - column and its span of thw widget
  897. # The options are set in grid options as "-rw <int>", "-cw <int>" etc.
  898. # Returns the resulting grid options.
  899. set opts {}
  900. foreach {opt val} [list {*}$options] {
  901. switch -exact -- $opt {
  902. -rw {SpanConfig $w row $row $rowspan -weight $val}
  903. -cw {SpanConfig $w column $col $colspan -weight $val}
  904. -rsz {SpanConfig $w row $row $rowspan -minsize $val}
  905. -csz {SpanConfig $w column $col $colspan -minsize $val}
  906. -ro {SpanConfig $w column $col $colspan -readonly $val}
  907. default {append opts " $opt $val"}
  908. }
  909. }
  910. # Get other grid options
  911. return [ExpandOptions $opts]
  912. }
  913. # ________________________ GetLinkLab _________________________ #
  914. proc GetLinkLab {m} {
  915. # Gets a link for label.
  916. # m - label with possible link (between <link> and </link>)
  917. # Returns: list of "pure" message and link for label.
  918. if {[set i1 [string first "<link>" $m]]<0} {
  919. return [list $m]
  920. }
  921. set i2 [string first "</link>" $m]
  922. set link [string range $m $i1+6 $i2-1]
  923. set m [string range $m 0 $i1-1][string range $m $i2+7 end]
  924. return [list $m [list -link $link]]
  925. }
  926. # ________________________ getOption _________________________ #
  927. proc getOption {optname args} {
  928. # Extracts one option from an option list.
  929. # optname - option name
  930. # args - option list
  931. # Returns an option value or "".
  932. # Example:
  933. # set options [list -name some -value "any value" -tip "some tip"]
  934. # set optvalue [::apave::getOption -tip {*}$options]
  935. set optvalue [lindex [parseOptions $args $optname ""] 0]
  936. return $optvalue
  937. }
  938. # ________________________ GetOutputValues _________________________ #
  939. proc GetOutputValues {} {
  940. # Makes output values for some widgets (lbx, fco).
  941. # Some i/o widgets need a special method to get their returned values.
  942. # xxx
  943. variable Widgetopts
  944. foreach aop $Widgetopts {
  945. lassign $aop optnam vn v1 v2
  946. switch -glob -- $optnam {
  947. -lbxname* {
  948. # To get a listbox's value, its methods are used.
  949. # The widget may not exist when an apave object is used for
  950. # several dialogs which is a bad style (very very bad).
  951. if {[winfo exists $vn]} {
  952. lassign [$vn curselection] s1
  953. if {$s1 eq {}} {set s1 0}
  954. set w [string range $vn [string last . $vn]+1 end]
  955. if {[catch {set v0 [$vn get $s1]}]} {set v0 {}}
  956. if {$optnam eq {-lbxnameALL}} {
  957. # when -ALL option is set to 1, listbox returns
  958. # a list of 3 items - sel index, sel contents and all contents
  959. set $v1 [list $s1 $v0 [set $v1]]
  960. } else {
  961. set $v1 $v0
  962. }
  963. }
  964. }
  965. -retpos { ;# a range to cut from -tvar/-lvar variable
  966. lassign [split $v2 :] p1 p2
  967. set val1 [set $v1]
  968. # there may be -list option for this widget
  969. # then if the value is from the list, it's fully returned
  970. foreach aop2 $Widgetopts {
  971. lassign $aop2 optnam2 vn2 lst2
  972. if {$optnam2 eq {-list} && $vn eq $vn2} {
  973. foreach val2 $lst2 {
  974. if {$val1 eq $val2} {
  975. set p1 0
  976. set p2 end
  977. break
  978. }
  979. }
  980. break
  981. }
  982. }
  983. set $v1 [string range $val1 $p1 $p2]
  984. }
  985. }
  986. }
  987. return
  988. }
  989. # __________________________ getDialogField _________________________ #
  990. proc getDialogField {index} {
  991. variable dlg
  992. set ret [lindex $dlg(FIELDS) $index]
  993. return $ret
  994. }
  995. #_______________________ getProperty _______________________#
  996. proc getProperty {name {defvalue ""}} {
  997. # Gets a property's value as "application-wide".
  998. # name - name of property
  999. # defvalue - default value
  1000. # If the property had been set, the method returns its value.
  1001. # Otherwise, the method returns the default value (`$defvalue`).
  1002. variable _AP_Properties
  1003. if {[info exists _AP_Properties($name)]} {
  1004. return $_AP_Properties($name)
  1005. }
  1006. return $defvalue
  1007. }
  1008. # ________________________ getShowOption _________________________ #
  1009. proc getShowOption {name {defval ""}} {
  1010. # Gets a default show option, used in showModal.
  1011. # name - name of option
  1012. # defval - default value
  1013. # See also: showModal
  1014. getProperty [ShowOption $name] $defval
  1015. }
  1016. # ________________________ GetVarsValues _________________________ #
  1017. proc GetVarsValues {lwidgets} {
  1018. # Gets values of entries passed (or set) in -tvar.
  1019. # lwidgets - list of widget items
  1020. set res [set vars [list]]
  1021. foreach wl $lwidgets {
  1022. set ownname [ownWName [lindex $wl 0]]
  1023. set vv [varName $ownname]
  1024. set attrs [lindex $wl 6]
  1025. if {[string match "ra*" $ownname]} {
  1026. # only for widgets with a common variable (e.g. radiobuttons):
  1027. foreach t {-var -tvar} {
  1028. if {[set v [getOption $t {*}$attrs]] ne {}} {
  1029. array set a $attrs
  1030. set vv $v
  1031. }
  1032. }
  1033. }
  1034. if {[info exist $vv] && [lsearch $vars $vv]==-1} {
  1035. lappend res [set $vv]
  1036. lappend vars $vv
  1037. }
  1038. }
  1039. return $res
  1040. }
  1041. # ________________________ GotoLineOK _________________________ #
  1042. proc GotoLineOK {} {
  1043. namespace upvar ::radxide dan dan
  1044. variable dlg
  1045. set wt $dan(TEXT)
  1046. set lmax [expr {int([$wt index "end -1c"])}]
  1047. #set t $Dlgpath.fra.fraM.fraent.ent
  1048. set t [dlgPath].fra.[FieldName [lindex [getDialogField 0] 0]]
  1049. #tk_messageBox -title $dan(TITLE) -icon info -message textbox=$t
  1050. set varname [lindex [getDialogField end] 0]
  1051. #tk_messageBox -title $dan(TITLE) -icon info -message varname=$varname
  1052. set oldlinenumber [lindex [getDialogField end] 1]
  1053. #tk_messageBox -title $dan(TITLE) -icon info -message oldlinenumber=$oldlinenumber
  1054. set newlinenumber [string trim [$t get]]
  1055. #tk_messageBox -title $dan(TITLE) -icon info -message newlinenumber=$newlinenumber
  1056. if {$newlinenumber>$lmax} {
  1057. tk_messageBox -title $dan(TITLE) -icon info -message "Line $newlinenumber doesn't exist $newlinenumber>MAXLINES."
  1058. return 0
  1059. }
  1060. ::tk::TextSetCursor $wt 0.0
  1061. after 200 "tk::TextSetCursor $wt [expr $newlinenumber].0"
  1062. catch {[destroy [dlgPath]]}
  1063. return 1
  1064. }
  1065. # ________________________ GotoLineCancel _________________________ #
  1066. proc GotoLineCancel {} {
  1067. #catch {[destroy .danwin.diaRenameFile1]}
  1068. catch {[destroy [dlgPath]]}
  1069. return 0
  1070. }
  1071. # ________________________ iconImage _________________________ #
  1072. proc iconA {icon {iconset small} {cmpd left}} {
  1073. # Gets icon attributes for buttons, menus etc.
  1074. # icon - name of icon
  1075. # iconset - one of small/middle/large
  1076. # cmpd - value of -compound option
  1077. # The *iconset* is "small" for menus (recommended and default).
  1078. return "-image [iconImage $icon $iconset] -compound $cmpd"
  1079. }
  1080. # ________________________ iconifyOption _________________________ #
  1081. proc iconifyOption {args} {
  1082. # Gets/sets "-iconify" option.
  1083. # args - if contains no arguments, gets "-iconify" option; otherwise sets it
  1084. # Option values mean:
  1085. # none - do nothing: no withdraw/deiconify
  1086. # Linux - do withdraw/deiconify for Linux
  1087. # Windows - do withdraw/deiconify for Windows
  1088. # default - do withdraw/deiconify depending on the platform
  1089. # See also: withdraw, deiconify
  1090. if {[llength $args]} {
  1091. set iconify [setShowOption -iconify $args]
  1092. } else {
  1093. set iconify [getShowOption -iconify]
  1094. }
  1095. return $iconify
  1096. }
  1097. # ________________________ iconImage _________________________ #
  1098. proc iconImage {{icon ""} {iconset "small"} {doit no}} {
  1099. # Gets a defined icon's image or list of icons.
  1100. # If *icon* equals to "-init", initializes apave's icon set.
  1101. # icon - icon's name
  1102. # iconset - one of small/middle/large
  1103. # doit - force the initialization
  1104. # Returns the icon's image or, if *icon* is blank, a list of icons
  1105. # available in *apave*.
  1106. variable _AP_IMG
  1107. variable _AP_ICO
  1108. return folder
  1109. # if {$icon eq {}} {return $_AP_ICO}
  1110. # ; proc imagename {icon} { # Get a defined icon's image name
  1111. # return _AP_IMG(img$icon)
  1112. # }
  1113. # variable apaveDir
  1114. # if {![array size _AP_IMG] || $doit} {
  1115. # # Make images of icons
  1116. # source [file join $apaveDir apaveimg.tcl]
  1117. # if {$iconset ne "small"} {
  1118. # foreach ic $_AP_ICO { ;# small icons best fit for menus
  1119. # set _AP_IMG($ic-small) [set _AP_IMG($ic)]
  1120. # }
  1121. # if {$iconset eq "middle"} {
  1122. # source [file join $apaveDir apaveimg2.tcl]
  1123. # } else {
  1124. # source [file join $apaveDir apaveimg2.tcl] ;# TODO
  1125. # }
  1126. # }
  1127. # foreach ic $_AP_ICO {
  1128. # if {[catch {image create photo [imagename $ic] -data [set _AP_IMG($ic)]}]} {
  1129. # # some png issues on old Tk
  1130. # image create photo [imagename $ic] -data [set _AP_IMG(none)]
  1131. # } elseif {$iconset ne "small"} {
  1132. # image create photo [imagename $ic-small] -data [set _AP_IMG($ic-small)]
  1133. # }
  1134. # }
  1135. # }
  1136. # if {$icon eq "-init"} {return $_AP_ICO} ;# just to get to icons
  1137. # if {$icon ni $_AP_ICO} {set icon [lindex $_AP_ICO 0]}
  1138. # if {$iconset eq "small" && "_AP_IMG(img$icon-small)" in [image names]} {
  1139. # set icon $icon-small
  1140. # }
  1141. # return [imagename $icon]
  1142. }
  1143. # ________________________ InfoFind _________________________ #
  1144. proc InfoFind {w modal} {
  1145. # Searches data of a window in a list of registered windows.
  1146. # w - root window's path
  1147. # modal - yes, if the window is modal
  1148. # Returns: the window's path or "" if not found.
  1149. # See also: InfoWindow
  1150. variable _PU_opts
  1151. foreach winfo [lrange $_PU_opts(_MODALWIN_) 1 end] { ;# skip 1st window
  1152. incr i
  1153. lassign $winfo w1 var1 modal1
  1154. if {[winfo exists $w1]} {
  1155. if {$w eq $w1 && ($modal && $modal1 || !$modal && !$modal1)} {
  1156. return $w1
  1157. }
  1158. } else {
  1159. catch {set _PU_opts(_MODALWIN_) [lreplace $_PU_opts(_MODALWIN_) $i $i]}
  1160. }
  1161. }
  1162. return {}
  1163. }
  1164. # ________________________ InitFindInText _________________________ #
  1165. proc InitFindInText { {ctrlf 0} {txt {}} } {
  1166. # Initializes the search in the text.
  1167. # ctrlf - "1" means that the method is called by Ctrl+F
  1168. # txt - path to the text widget
  1169. namespace upvar ::radxide dan dan
  1170. variable Foundstr
  1171. if {$txt eq {}} {set txt $dan(TEXT)}
  1172. #if {$ctrlf} { ;# Ctrl+F moves cursor 1 char ahead
  1173. # ::tk::TextSetCursor $txt [$txt index "insert -1 char"]
  1174. #}
  1175. if {[set seltxt [selectedWordText $txt]] ne {}} {
  1176. set Foundstr $seltxt
  1177. }
  1178. return $Foundstr
  1179. }
  1180. # ________________________ initInput _________________________ #
  1181. proc initInput {} {
  1182. # Initializes input and clears variables made in previous session.
  1183. variable _savedvv
  1184. # xxx
  1185. variable Widgetopts
  1186. foreach {vn vv} $_savedvv {
  1187. catch {unset $vn}
  1188. }
  1189. set _savedvv [list]
  1190. set Widgetopts [list]
  1191. return
  1192. }
  1193. proc InfoWindow {{val ""} {w .} {modal no} {var ""} {regist no}} {
  1194. # Registers/unregisters windows. Also sets/gets 'count of open modal windows'.
  1195. # val - current number of open modal windows
  1196. # w - root window's path
  1197. # modal - yes, if the window is modal
  1198. # var - variable's name for tkwait
  1199. # regist - yes or no for registering/unregistering
  1200. variable _PU_opts
  1201. if {$modal || $regist} {
  1202. set info [list $w $var $modal]
  1203. set i [lsearch -exact $_PU_opts(_MODALWIN_) $info]
  1204. catch {set _PU_opts(_MODALWIN_) [lreplace $_PU_opts(_MODALWIN_) $i $i]}
  1205. if {$regist} {
  1206. lappend _PU_opts(_MODALWIN_) $info
  1207. }
  1208. set res [IntStatus . MODALS $val]
  1209. } else {
  1210. set res [IntStatus . MODALS]
  1211. }
  1212. return $res
  1213. }
  1214. # ________________________ input _________________________ #
  1215. proc input {dlgname icon ttl iopts args} {
  1216. # Makes and runs an input dialog.
  1217. # dlgname - dialog name
  1218. # icon - icon (omitted if equals to "")
  1219. # ttl - title of window
  1220. # iopts - list of widgets and their attributes
  1221. # args - list of dialog's attributes
  1222. # The `iopts` contains lists of three items:
  1223. # name - name of widgets
  1224. # prompt - prompt for entering data
  1225. # valopts - value options
  1226. # The `valopts` is a list specific for a widget's type, however
  1227. # a first item of `valopts` is always an initial input value.
  1228. namespace upvar ::radxide dan dan
  1229. variable Indexdlg
  1230. variable _savedvv
  1231. variable Dlgpath
  1232. variable Dlgname
  1233. variable dlg
  1234. #tk_messageBox -title $dan(TITLE) -icon error -message "proc Input"
  1235. danInitDialogs
  1236. set Winpath $dan(WIN)
  1237. set Dlgname [set dlg(NAME) $dlgname]
  1238. set wdia $Winpath.dia$Dlgname[incr Indexdlg]
  1239. set dlg(PATH) [set Dlgpath $wdia]
  1240. if {$iopts ne {}} {
  1241. initInput ;# clear away all internal vars
  1242. }
  1243. set pady "-pady 2"
  1244. if {[set focusopt [getOption -focus {*}$args]] ne {}} {
  1245. set focusopt "-focus $focusopt"
  1246. }
  1247. lappend inopts [list fraM + T 1 98 "-st nsew $pady -rw 1"]
  1248. set _savedvv [list]
  1249. set frameprev {}
  1250. foreach {name prompt valopts} $iopts {
  1251. if {$name eq {}} continue
  1252. lassign $prompt prompt gopts attrs
  1253. lassign [extractOptions attrs -method {} -toprev {}] ismeth toprev
  1254. if {[string toupper $name 0] eq $name} {
  1255. set ismeth yes ;# overcomes the above setting
  1256. set name [string tolower $name 0]
  1257. }
  1258. set ismeth [string is true -strict $ismeth]
  1259. set gopts "$pady $gopts"
  1260. set typ [string tolower [string range $name 0 1]]
  1261. if {$typ eq "v_" || $typ eq "se"} {
  1262. lappend inopts [list fraM.$name - - - - "pack -fill x $gopts"]
  1263. continue
  1264. }
  1265. set tvar "-tvar"
  1266. switch -exact -- $typ {
  1267. ch { set tvar "-var" }
  1268. sp { set gopts "$gopts -expand 0 -side left"}
  1269. }
  1270. set framename fraM.fra$name
  1271. if {$typ in {lb te tb}} { ;# the widgets sized vertically
  1272. lappend inopts [list $framename - - - - "pack -expand 1 -fill both"]
  1273. } else {
  1274. lappend inopts [list $framename - - - - "pack -fill x"]
  1275. }
  1276. set vv [::radxide::win::varName $name]
  1277. #tk_messageBox -title $dan(TITLE) -icon info -message vv=$vv
  1278. set ff [FieldName $name]
  1279. set Name [string toupper $name 0]
  1280. if {$ismeth && $typ ni {ra}} {
  1281. # -method option forces making "WidgetName" method from "widgetName"
  1282. MakeWidgetName $ff $Name -
  1283. }
  1284. if {$typ ne {la} && $toprev eq {}} {
  1285. set takfoc [parseOptions $attrs -takefocus 1]
  1286. if {$focusopt eq {} && $takfoc} {
  1287. if {$typ in {fi di cl fo da}} {
  1288. set _ en*$name ;# 'entry-like mega-widgets'
  1289. } elseif {$typ eq "ft"} {
  1290. set _ te*$name ;# ftx - 'text-like mega-widget'
  1291. } else {
  1292. set _ $name
  1293. }
  1294. set focusopt "-focus $_"
  1295. }
  1296. if {$typ in {lb tb te}} {set anc nw} {set anc w}
  1297. lappend inopts [list fraM.fra$name.labB$name - - - - \
  1298. "pack -side left -anchor $anc -padx 3" \
  1299. "-t \"$prompt\" -font \
  1300. \"-family {[basicTextFont]} -size [basicFontSize]\""]
  1301. }
  1302. # for most widgets:
  1303. # 1st item of 'valopts' list is the current value
  1304. # 2nd and the rest of 'valopts' are a list of values
  1305. if {$typ ni {fc te la}} {
  1306. # curr.value can be set with a variable, so 'subst' is applied
  1307. set vsel [lindex $valopts 0]
  1308. catch {set vsel [subst -nocommands -nobackslashes $vsel]}
  1309. set vlist [lrange $valopts 1 end]
  1310. }
  1311. if {[set msgLab [getOption -msgLab {*}$attrs]] ne {}} {
  1312. set attrs [removeOptions $attrs -msgLab]
  1313. }
  1314. # define a current widget's info
  1315. switch -exact -- $typ {
  1316. lb - tb {
  1317. set $vv $vlist
  1318. lappend attrs -lvar $vv
  1319. if {$vsel ni {{} -}} {
  1320. lappend attrs -lbxsel "$UFF$vsel$UFF"
  1321. }
  1322. lappend inopts [list $ff - - - - \
  1323. "pack -side left -expand 1 -fill both $gopts" $attrs]
  1324. lappend inopts [list fraM.fra$name.sbv$name $ff L - - "pack -fill y"]
  1325. }
  1326. cb {
  1327. if {![info exist $vv]} {catch {set $vv $vsel}}
  1328. lappend attrs -tvar $vv -values $vlist
  1329. if {$vsel ni {{} -}} {
  1330. lappend attrs -cbxsel $UFF$vsel$UFF
  1331. }
  1332. lappend inopts [list $ff - - - - "pack -side left -expand 1 -fill x $gopts" $attrs]
  1333. }
  1334. fc {
  1335. if {![info exist $vv]} {catch {set $vv {}}}
  1336. lappend inopts [list $ff - - - - "pack -side left -expand 1 -fill x $gopts" "-tvar $vv -values \{$valopts\} $attrs"]
  1337. }
  1338. op {
  1339. set $vv $vsel
  1340. lappend inopts [list $ff - - - - "pack -fill x $gopts" "$vv $vlist"]
  1341. }
  1342. ra {
  1343. if {![info exist $vv]} {catch {set $vv $vsel}}
  1344. set padx 0
  1345. foreach vo $vlist {
  1346. set name $name
  1347. set FF $ff[incr nnn]
  1348. lappend inopts [list $FF - - - - "pack -side left $gopts -padx $padx" "-var $vv -value \"$vo\" -t \"$vo\" $attrs"]
  1349. if {$ismeth} {
  1350. MakeWidgetName $FF $Name$nnn -
  1351. }
  1352. set padx [expr {$padx ? 0 : 9}]
  1353. }
  1354. }
  1355. te {
  1356. if {![info exist $vv]} {
  1357. set valopts [string map [list \\n \n \\t \t] $valopts]
  1358. set $vv [string map [list \\\\ \\ \\\} \} \\\{ \{] $valopts]
  1359. }
  1360. # xxx
  1361. #tk_messageBox -title $dan(TITLE) -icon error -message $vv
  1362. if {[dict exist $attrs -state] && [dict get $attrs -state] eq "disabled"} \
  1363. {
  1364. # disabled text widget cannot be filled with a text, so we should
  1365. # compensate this through a home-made attribute (-disabledtext)
  1366. set disattr "-disabledtext \{[set $vv]\}"
  1367. } elseif {[dict exist $attrs -readonly] && [dict get $attrs -readonly] || [dict exist $attrs -ro] && [dict get $attrs -ro]} {
  1368. set disattr "-rotext \{[set $vv]\}"
  1369. set attrs [removeOptions $attrs -readonly -ro]
  1370. } else {
  1371. set disattr {}
  1372. }
  1373. lappend inopts [list $ff - - - - "pack -side left -expand 1 -fill both $gopts" "$attrs $disattr"]
  1374. lappend inopts [list fraM.fra$name.sbv$name $ff L - - "pack -fill y"]
  1375. }
  1376. la {
  1377. if {$prompt ne {}} { set prompt "-t \"$prompt\" " } ;# prompt as -text
  1378. lappend inopts [list $ff - - - - "pack -anchor w $gopts" "$prompt$attrs"]
  1379. continue
  1380. }
  1381. bu - bt - ch {
  1382. set prompt {}
  1383. if {$toprev eq {}} {
  1384. lappend inopts [list $ff - - - - \
  1385. "pack -side left -expand 1 -fill both $gopts" "$tvar $vv $attrs"]
  1386. } else {
  1387. lappend inopts [list $frameprev.$name - - - - \
  1388. "pack -side left $gopts" "$tvar $vv $attrs"]
  1389. }
  1390. if {$vv ne {}} {
  1391. if {![info exist $vv]} {
  1392. catch {
  1393. if {$vsel eq {}} {set vsel 0}
  1394. set $vv $vsel
  1395. }
  1396. }
  1397. }
  1398. }
  1399. default {
  1400. if {$vlist ne {}} {lappend attrs -values $vlist}
  1401. lappend inopts [list $ff - - - - \
  1402. "pack -side left -expand 1 -fill x $gopts" "$tvar $vv $attrs"]
  1403. if {$vv ne {}} {
  1404. if {![info exist $vv]} {catch {set $vv $vsel}}
  1405. }
  1406. }
  1407. }
  1408. if {$msgLab ne {}} {
  1409. lassign $msgLab lab msg attlab
  1410. set lab [parentWName [lindex $inopts end 0]].$lab
  1411. if {$msg ne {}} {set msg "-t {$msg}"}
  1412. append msg " $attlab"
  1413. lappend inopts [list $lab - - - - "pack -side left -expand 1 -fill x" $msg]
  1414. }
  1415. if {![info exist $vv]} {set $vv {}}
  1416. # xxx
  1417. if {$typ eq "en"} {
  1418. #tk_messageBox -title $dan(TITLE) -icon error -message setvv=[set $vv]
  1419. addDialogField $name [set $vv] ""
  1420. }
  1421. lappend _savedvv $vv [set $vv]
  1422. set frameprev $framename
  1423. }
  1424. lassign [parseOptions $args -titleHELP {} -buttons {} -comOK 1 \
  1425. -titleOK OK -titleCANCEL Cancel -centerme {}] \
  1426. titleHELP buttons comOK titleOK titleCANCEL centerme
  1427. if {$titleHELP eq {}} {
  1428. set butHelp {}
  1429. } else {
  1430. lassign $titleHELP title command
  1431. set butHelp [list butHELP $title $command]
  1432. }
  1433. if {$titleCANCEL eq {}} {
  1434. set butCancel {}
  1435. } else {
  1436. set butCancel "butCANCEL $titleCANCEL destroy"
  1437. }
  1438. if {$centerme eq {}} {
  1439. set centerme {-centerme 1}
  1440. } else {
  1441. set centerme "-centerme $centerme"
  1442. }
  1443. set args [removeOptions $args \
  1444. -titleHELP -buttons -comOK -titleOK -titleCANCEL -centerme -modal]
  1445. # xxx
  1446. #set buttons [string map {"butOK OK 1" "" "butCANCEL Cancel destroy" ""} $buttons]
  1447. #tk_messageBox -title $dan(TITLE) -icon info -message new_buttons=$buttons
  1448. lappend args {*}$focusopt
  1449. #lassign [PrepArgs {*}$args] args
  1450. if {[catch { \
  1451. lassign [PrepArgs {*}$args] args
  1452. set res [Query $dlgname $icon $ttl {} \
  1453. "$butHelp $buttons butOK $titleOK $comOK $butCancel" \
  1454. butOK $inopts $args {} {*}$centerme -input yes]} e]} {
  1455. catch {destroy $Dlgpath]} ;# Query's window
  1456. # ::apave::obj ok err "ERROR" "\n$e\n" \
  1457. # -t 1 -head "\nAPave returned an error: \n" -hfg red -weight bold
  1458. #tk_messageBox -title $dan(TITLE) -icon info -message "::win returned an error:$e"
  1459. set res 0
  1460. set msg "\nERROR in win:"
  1461. puts \n$msg\n\n$e$::errorInfo\n
  1462. #set msg "$msg\n\n$e\n\nPlease, inform authors.\nDetails are in stdout."
  1463. #tk_messageBox -title $dan(TITLE) -icon error -message $msg
  1464. #exit 2
  1465. return $res
  1466. }
  1467. if {![lindex $res 0]} { ;# restore old values if OK not chosen
  1468. foreach {vn vv} $_savedvv {
  1469. # tk_optionCascade (destroyed now) was tracing its variable => catch
  1470. catch {set $vn $vv}
  1471. }
  1472. }
  1473. return $res
  1474. }
  1475. # _______________________ insert tab amenities _______________ #
  1476. proc insertTab {} {
  1477. namespace upvar ::radxide dan dan
  1478. set wt $dan(TEXT)
  1479. #set idx1 [$wt index {insert linestart}]
  1480. #set idx2 [$wt index {insert lineend}]
  1481. #set line [$wt get $idx1 $idx2]
  1482. $wt insert {insert} $dan(TAB_IN_SPACE)
  1483. return -code break
  1484. }
  1485. # ________________________ IntStatus _________________________ #
  1486. proc IntStatus {w {name "status"} {val ""}} {
  1487. # Sets/gets a status of window. The status is an integer assigned to a name.
  1488. # w - window's path
  1489. # name - name of status
  1490. # val - if blank, to get a value of status; otherwise a value to set
  1491. # Default value of status is 0.
  1492. # Returns an old value of status.
  1493. # See also: WindowStatus
  1494. set old [WindowStatus $w $name {} 0]
  1495. if {$val ne {}} {WindowStatus $w $name $val 1}
  1496. return $old
  1497. }
  1498. # ________________________ LbxSelect _________________________ #
  1499. proc LbxSelect {w idx} {
  1500. # Selects a listbox item.
  1501. # w - listbox's path
  1502. # idx - item index
  1503. $w activate $idx
  1504. $w see $idx
  1505. if {[$w cget -selectmode] in {single browse}} {
  1506. $w selection clear 0 end
  1507. $w selection set $idx
  1508. event generate $w <<ListboxSelect>>
  1509. }
  1510. }
  1511. # ________________________ ListboxesAttrs _________________________ #
  1512. proc ListboxesAttrs {w attrs} {
  1513. # Appends selection attributes to listboxes.
  1514. # Details:
  1515. # 1. https://wiki.tcl-lang.org/page/listbox+selection
  1516. # 2. https://stackoverflow.com, the question:
  1517. # the-tablelist-curselection-goes-at-calling-the-directory-dialog
  1518. if {{-exportselection} ni $attrs} {
  1519. append attrs " -ListboxSel $w -selectmode extended -exportselection 0"
  1520. }
  1521. return $attrs
  1522. }
  1523. # ________________________ LowercaseWidgetName _________________________ #
  1524. proc LowercaseWidgetName {name} {
  1525. # Makes the widget name lowercased.
  1526. # name - widget's name
  1527. # The widgets of widget list can have uppercased names which
  1528. # means that the appropriate methods will be created to access
  1529. # their full pathes with a command `my Name`.
  1530. # This method gets a "normal" name of widget accepted by Tk.
  1531. # See also: MakeWidgetName
  1532. set root [ownWName $name]
  1533. return [list [string range $name 0 [string last . $name]][string tolower $root 0 0] $root]
  1534. }
  1535. # ________________________ NonTtkStyle _________________________ #
  1536. proc NonTtkStyle {typ {dsbl 0}} {
  1537. # Gets a style for non-ttk widgets.
  1538. # typ - the type of widget (in apave terms, i.e. but, buT etc.)
  1539. # dsbl - a mode to get style of disabled (1) or readonly (2) widgets
  1540. # See also: widgetType
  1541. # Method to be redefined in descendants/mixins.
  1542. return
  1543. }
  1544. # ________________________ NormalizeName _________________________ #
  1545. proc NormalizeName {refname refi reflwidgets} {
  1546. # Gets the real name of widget from *.name*.
  1547. # refname - variable name for widget name
  1548. # refi - variable name for index in widget list
  1549. # reflwidgets - variable name for widget list
  1550. # The *.name* means "child of some previous" and should be normalized.
  1551. # Example:
  1552. # If parent: fra.fra .....
  1553. # child: .but
  1554. # => normalized: fra.fra.but
  1555. upvar $refname name $refi i $reflwidgets lwidgets
  1556. set wname $name
  1557. if {[string index $name 0] eq {.}} {
  1558. for {set i2 [expr {$i-1}]} {$i2 >=0} {incr i2 -1} {
  1559. lassign [lindex $lwidgets $i2] name2
  1560. if {[string index $name2 0] ne {.}} {
  1561. set name2 [lindex [LowercaseWidgetName $name2] 0]
  1562. set wname "$name2$name"
  1563. set name [lindex [LowercaseWidgetName $name] 0]
  1564. set name "$name2$name"
  1565. break
  1566. }
  1567. }
  1568. }
  1569. return [list $name $wname]
  1570. }
  1571. # ________________________ makeMainWindow _________________________ #
  1572. # Scrollbars amenities
  1573. proc Yset {widgets master sb args} {
  1574. #if {$master eq "master"} {
  1575. #list $sb set [expr [lindex $args 0]] [expr [lindex $args 1]]
  1576. set sb1 [lrange $sb 0 0]
  1577. set sb2 [lrange $sb 1 1]
  1578. $sb1 set {*}$args
  1579. $sb2 set {*}$args
  1580. set myw [lrange $widgets 1 end]
  1581. #} else {
  1582. # set myw [lrange $widgets 0 0]
  1583. #}
  1584. ::radxide::win::Yview $myw moveto [lindex $args 0]
  1585. #::radxide::win::Yview [lrange $widgets 0 0] moveto [lindex $args 0]
  1586. }
  1587. proc Yview {widgets args} {
  1588. foreach w $widgets {
  1589. $w yview {*}$args
  1590. }
  1591. }
  1592. proc makeMainWindow {win ttl bg fg} {
  1593. namespace upvar ::radxide dan dan
  1594. set w [set wtop [string trimright $win .]]
  1595. set withfr [expr {[set pp [string last . $w]]>0 && \
  1596. [string match *.fra $w]}]
  1597. if {$withfr} {
  1598. set wtop [string range $w 0 $pp-1]
  1599. }
  1600. # menu
  1601. set m [::radxide::menu::menuScaf]
  1602. toplevel $wtop -menu $m
  1603. if {$withfr} {
  1604. # main frame
  1605. pack [frame $w -background $bg ] -expand 1 -fill both
  1606. # panedwindow
  1607. pack [set pan [ttk::panedwindow $w.pan -orient horizontal]] -side top -fill both -expand 1
  1608. # tree pane (panL)
  1609. pack [set w1 [frame $pan.fra1 -background $bg ]] -side left -fill both ;#-expand 1 -fill both
  1610. set panL [$pan add $pan.fra1]
  1611. pack [set tree [ttk::treeview $w1.tree -selectmode extended]] -side left -fill both -expand 1
  1612. set dan(TREEVIEW) $w1.tree
  1613. $tree heading #0 -text " Project" -anchor "w"
  1614. # main pane (panR)
  1615. pack [set w2 [ttk::panedwindow $pan.fra2 -orient horizontal]] -side left -fill both -expand 1
  1616. set panR [$pan add $pan.fra2]
  1617. text $w2.gutText -background "lightgray" -foreground "#222223" -font "Monospace 10" -width 5
  1618. text $w2.text -font "monospace 10" -bd 0 -padx 13 -spacing1 0 -spacing2 0 -spacing3 0 -exportselection yes -width 115 -wrap none
  1619. set ww [list .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText]
  1620. $w2.text configure -xscrollcommand [list $w2.xscroll set]
  1621. scrollbar $w2.xscroll -orient horizontal \
  1622. -command [list $w2.text xview]
  1623. scrollbar $w2.yscroll1 -orient vertical \
  1624. -command [list ::radxide::win::Yview $ww]
  1625. scrollbar $w2.yscroll2 -orient vertical \
  1626. -command [list $w2.gutText yview]
  1627. set ssbb [list .danwin.fra.pan.fra2.yscroll1 .danwin.fra.pan.fra2.yscroll2]
  1628. $w2.text configure -yscrollcommand [list ::radxide::win::Yset $ww master $ssbb]
  1629. $w2.gutText configure -yscrollcommand [list .danwin.fra.pan.fra2.yscroll2 set]
  1630. grid $w2.gutText $w2.text $w2.yscroll1 -sticky nsew
  1631. grid $w2.xscroll -columnspan 2 -sticky nsew
  1632. grid rowconfigure $w2 0 -weight 1
  1633. grid columnconfigure $w2 1 -weight 1
  1634. set dan(GUTTEXT) $w2.gutText
  1635. set dan(TEXT) $w2.text
  1636. $dan(GUTTEXT) configure -state disabled
  1637. $dan(TEXT) configure -state disabled
  1638. # set colors
  1639. $dan(TEXT) configure -background $dan(TEXTBG) -foreground $dan(TEXTFG)
  1640. $dan(TEXT) configure -selectforeground $dan(TEXTSELFG)
  1641. $dan(TEXT) configure -insertbackground $dan(CURSORCOLOR) -insertwidth $dan(CURSORWIDTH);
  1642. # code library
  1643. pack [set w3 [frame $pan.fra3 -background $bg]] -side left -fill y -expand 1;
  1644. set panC [$pan add $pan.fra3]
  1645. ::radxide::eglib::create $w3
  1646. # update gutter, key bindings
  1647. bind $dan(TEXT) "<Return>" {::radxide::win::fillGutter .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText 5 1 "#FFFFFF" "#222223"}
  1648. bind $dan(TEXT) "<BackSpace>" {::radxide::win::fillGutter .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText 5 1 "#FFFFFF" "#222223"}
  1649. bind $dan(TEXT) "<Cancel>" {::radxide::win::fillGutter .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText 5 1 "#FFFFFF" "#222223" ;::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll -0 units ;::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll 1 units}
  1650. bind $dan(TEXT) "<Delete>" {::radxide::win::fillGutter .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText 5 1 "#FFFFFF" "#222223" ;::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll -1 units ;::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll 1 units}
  1651. bind $tree "<ButtonPress>" {after idle {::radxide::tree::buttonPress %b %x %y %X %Y}}
  1652. bind $tree "<ButtonRelease>" {after idle {::radxide::tree::buttonRelease %b %s %x %y %X %Y}}
  1653. }
  1654. #wm title $wtop ttl
  1655. # window shortcut bindings
  1656. set canvas $w2.gutText
  1657. ::radxide::menu::defWinShortcuts $dan(TEXT) $canvas
  1658. ::radxide::menu::defWinShortcuts $dan(TREEVIEW) $canvas
  1659. }
  1660. # ________________________ MakeWidgetName _________________________ #
  1661. proc MakeWidgetName {w name {an {}}} {
  1662. # Makes an exported method named after root widget, if it's uppercased.
  1663. # w - name of root widget
  1664. # name - name of widget
  1665. # an - additional prefix for name (if "-", $w is full/partial name)
  1666. # The created method used for easy access to the widget's path.
  1667. # Example:
  1668. # fra1.fra2.fra3.Entry1
  1669. # => method Entry1 {} {...}
  1670. # ...
  1671. # my Entry1 ;# instead of .win.fra1.fra2.fra3.Entry1
  1672. if {$an eq {-}} {
  1673. set wnamefull "\[DiaWidgetName $w\]"
  1674. } else {
  1675. set wnamefull [WidgetNameFull $w $name $an]
  1676. lassign [LowercaseWidgetName $wnamefull] wnamefull
  1677. }
  1678. set method [ownWName $name]
  1679. set root1 [string index $method 0]
  1680. #if {[string is upper $root1]} {
  1681. # oo::objdefine [self] "method $method {} {return $wnamefull} ; \
  1682. # export $method"
  1683. #}
  1684. return $wnamefull
  1685. }
  1686. # ________________________ makeWindow _________________________ #
  1687. proc makeWindow {w ttl args} {
  1688. # Creates a toplevel window that has to be paved.
  1689. # w - window's name
  1690. # ttl - window's title
  1691. # args - options for 'toplevel' command
  1692. # If $w matches "*.fra" then ttk::frame is created with name $w.
  1693. namespace upvar ::radxide dan dan
  1694. #CleanUps
  1695. set w [set wtop [string trimright $w .]]
  1696. set withfr [expr {[set pp [string last . $w]]>0 && \
  1697. [string match *.fra $w]}]
  1698. if {$withfr} {
  1699. set wtop [string range $w 0 $pp-1]
  1700. }
  1701. catch {destroy $wtop}
  1702. lassign [extractOptions args -type {}] type
  1703. toplevel $wtop {*}$args
  1704. withdraw $wtop ;# nice to hide all gui manipulations
  1705. if {$type ne {} && [tk windowingsystem] eq {x11}} {
  1706. wm attributes $wtop -type $type
  1707. }
  1708. if {$withfr} {
  1709. pack [frame $w -background $dan(BG)] -expand 1 -fill both
  1710. }
  1711. wm title $wtop $ttl
  1712. return $wtop
  1713. }
  1714. # ________________________ ownWName _________________________ #
  1715. proc ownWName {name} {
  1716. # Gets a tail (last part) of widget's name
  1717. # name - name (path) of the widget
  1718. return [lindex [split $name .] end]
  1719. }
  1720. # ________________________ parentWName _________________________ #
  1721. proc parentWName {name} {
  1722. # Gets parent name of widget.
  1723. # name - name (path) of the widget
  1724. return [string range $name 0 [string last . $name]-1]
  1725. }
  1726. # ________________________ parseOptionsFile _________________________ #
  1727. proc parseOptionsFile {strict inpargs args} {
  1728. # Parses argument list containing options and (possibly) a file name.
  1729. # strict - if 0, 'args' options will be only counted for,
  1730. # other options are skipped
  1731. # strict - if 1, only 'args' options are allowed,
  1732. # all the rest of inpargs to be a file name
  1733. # - if 2, the 'args' options replace the
  1734. # appropriate options of 'inpargs'
  1735. # inpargs - list of options, values and a file name
  1736. # args - list of default options
  1737. #
  1738. # The inpargs list contains:
  1739. # - option names beginning with "-"
  1740. # - option values following their names (may be missing)
  1741. # - "--" denoting the end of options
  1742. # - file name following the options (may be missing)
  1743. #
  1744. # The *args* parameter contains the pairs:
  1745. # - option name (e.g., "-dir")
  1746. # - option default value
  1747. #
  1748. # If the *args* option value is equal to =NONE=, the *inpargs* option
  1749. # is considered to be a single option without a value and,
  1750. # if present in inpargs, its value is returned as "yes".
  1751. #
  1752. # If any option of *inpargs* is absent in *args* and strict==1,
  1753. # the rest of *inpargs* is considered to be a file name.
  1754. #
  1755. # The proc returns a list of two items:
  1756. # - an option list got from args/inpargs according to 'strict'
  1757. # - a file name from inpargs or {} if absent
  1758. #
  1759. # Examples see in tests/obbit.test.
  1760. variable _PU_opts
  1761. set actopts true
  1762. array set argarray "$args yes yes" ;# maybe, tail option without value
  1763. if {$strict==2} {
  1764. set retlist $inpargs
  1765. } else {
  1766. set retlist $args
  1767. }
  1768. set retfile {}
  1769. for {set i 0} {$i < [llength $inpargs]} {incr i} {
  1770. set parg [lindex $inpargs $i]
  1771. if {$actopts} {
  1772. if {$parg eq "--"} {
  1773. set actopts false
  1774. } elseif {[catch {set defval $argarray($parg)}]} {
  1775. if {$strict==1} {
  1776. set actopts false
  1777. append retfile $parg " "
  1778. } else {
  1779. incr i
  1780. }
  1781. } else {
  1782. if {$strict==2} {
  1783. if {$defval == $_PU_opts(-NONE)} {
  1784. set defval yes
  1785. }
  1786. incr i
  1787. } else {
  1788. if {$defval == $_PU_opts(-NONE)} {
  1789. set defval yes
  1790. } else {
  1791. set defval [lindex $inpargs [incr i]]
  1792. }
  1793. }
  1794. set ai [lsearch -exact $retlist $parg]
  1795. incr ai
  1796. set retlist [lreplace $retlist $ai $ai $defval]
  1797. }
  1798. } else {
  1799. append retfile $parg " "
  1800. }
  1801. }
  1802. return [list $retlist [string trimright $retfile]]
  1803. }
  1804. # ________________________ parseOptions _________________________ #
  1805. proc parseOptions {opts args} {
  1806. # Parses argument list containing options.
  1807. # opts - list of options and values
  1808. # args - list of "option / default value" pairs
  1809. # It's the same as parseOptionsFile, excluding the file name stuff.
  1810. # Returns a list of options' values, according to args.
  1811. # See also: parseOptionsFile
  1812. lassign [parseOptionsFile 0 $opts {*}$args] tmp
  1813. foreach {nam val} $tmp {
  1814. lappend retlist $val
  1815. }
  1816. return $retlist
  1817. }
  1818. # ________________________ popupHighlightCommands _________________________ #
  1819. proc popupHighlightCommands {{pop ""} {txt ""}} {
  1820. # Returns highlighting commands for a popup menu on a text.
  1821. # pop - path to the menu
  1822. # txt - path to the text
  1823. set res ""
  1824. return $res
  1825. }
  1826. # ________________________ Pre _________________________ #
  1827. proc Pre {refattrs} {
  1828. # "Pre" actions for the text widget and similar
  1829. # which all require some actions before and after their creation e.g.:
  1830. # the text widget's text cannot be filled if disabled
  1831. # so, we must act this way:
  1832. # 1. call Pre - to get a text of widget
  1833. # 2. create the widget
  1834. # 3. call Post - to enable, then fill it with a text, then disable it
  1835. # It's only possible with Pre and Post methods.
  1836. # See also: Post
  1837. upvar 1 $refattrs attrs
  1838. set attrs_ret [set Prepost [list]]
  1839. foreach {a v} $attrs {
  1840. switch -exact -- $a {
  1841. -disabledtext - -rotext - -lbxsel - -cbxsel - -notebazook - \
  1842. -entrypop - -entrypopRO - -textpop - -textpopRO - -ListboxSel - \
  1843. -callF2 - -timeout - -bartabs - -onReturn - -linkcom - -selcombobox - \
  1844. -afteridle - -gutter - -propagate - -columnoptions - -selborderwidth -
  1845. -selected - -popup - -bindEC - -tags - -debug - -clearcom {
  1846. # attributes specific to apave, processed below in "Post"
  1847. set v2 [string trimleft $v \{]
  1848. set v2 [string range $v2 0 end-[expr {[string length $v]-[string length $v2]}]]
  1849. lappend Prepost [list $a $v2]
  1850. }
  1851. -myown {
  1852. lappend Prepost [list $a [subst $v]]
  1853. }
  1854. -labelwidget { ;# widget path as a method
  1855. set v [string trim $v \{\}]
  1856. catch {set v [$::win::$v]}
  1857. lappend attrs_ret $a $v
  1858. }
  1859. default {
  1860. lappend attrs_ret $a $v
  1861. }
  1862. }
  1863. }
  1864. set attrs $attrs_ret
  1865. return
  1866. }
  1867. # ________________________ PrepArgs _________________________ #
  1868. proc PrepArgs {args} {
  1869. # Prepares a list of arguments.
  1870. # Returns the list (wrapped in list) and a command for OK button.
  1871. lassign [parseOptions $args -modal {} -ch {} -comOK {} -onclose {}] \
  1872. modal ch comOK onclose
  1873. if {[string is true -strict $modal]} {
  1874. set com 1
  1875. } elseif {$ch ne {}} {
  1876. # some options are incompatible with -ch
  1877. if {$onclose eq {destroy}} {set onclose {}}
  1878. lappend args -modal 1 -onclose $onclose
  1879. set com 1
  1880. } elseif {$comOK eq {}} {
  1881. set com destroy ;# non-modal without -ch option
  1882. } else {
  1883. set com $comOK
  1884. }
  1885. return [list [list $args] $com]
  1886. }
  1887. ## ________________________ Query _________________________ ##
  1888. proc Query {dlgname icon ttl msg buttons defb inopts argdia {precom ""} args} {
  1889. # Makes a query (or a message) and gets the user's response.
  1890. # dlgname - dialog name
  1891. # icon - icon name (info, warn, ques, err)
  1892. # ttl - title
  1893. # msg - message
  1894. # buttons - list of triples "button name, text, ID"
  1895. # defb - default button (OK, YES, NO, CANCEL, RETRY, ABORT)
  1896. # inopts - options for input dialog
  1897. # argdia - list of dialog's options
  1898. # precom - command(s) performed before showing the dialog
  1899. # args - additional options (message's font etc.)
  1900. # The *argdia* may contain additional options of the query, like these:
  1901. # -checkbox text (-ch text) - makes the checkbox's text visible
  1902. # -geometry +x+y (-g +x+y) - sets the geometry of dialog
  1903. # -color cval (-c cval) - sets the color of message
  1904. # If "-geometry" option is set (even equaling "") the Query procedure
  1905. # returns a list with chosen button's ID and a new geometry.
  1906. # Otherwise it returns only the chosen button's ID.
  1907. # See also:
  1908. # [aplsimple.github.io](https://aplsimple.github.io/en/tcl/pave/index.html)
  1909. namespace upvar ::radxide dan dan
  1910. variable Indexdlg
  1911. variable Foundstr
  1912. variable Dlgpath
  1913. variable Dlgname
  1914. variable dlg
  1915. #tk_messageBox -title $dan(TITLE) -icon error -message "Query"
  1916. set Winpath $dan(WIN)
  1917. set Dlgname $dlg(NAME)
  1918. set wdia $Winpath.dia$Dlgname
  1919. #append wdia [lindex [split :] end] ;# be unique per apave object
  1920. #set qdlg [set dlg(PATH) [set Dlgpath $wdia[incr Indexdlg]]]
  1921. set qdlg $Dlgpath
  1922. #tk_messageBox -title $dan(TITLE) -icon error -message $qdlg
  1923. # remember the focus (to restore it after closing the dialog)
  1924. set focusback [focus]
  1925. set focusmatch {}
  1926. # options of dialog
  1927. lassign {} chmsg geometry optsLabel optsMisc optsFont optsFontM optsHead \
  1928. root rotext head hsz binds postcom onclose timeout tab2 \
  1929. tags cc themecolors optsGrid addpopup minsize
  1930. set wasgeo [set textmode [set stay [set waitvar 0]]]
  1931. set readonly [set hidefind [set scroll [set modal 1]]]
  1932. set curpos {1.0}
  1933. set CheckNomore 0
  1934. foreach {opt val} {*}$argdia {
  1935. if {$opt in {-c -color -fg -bg -fgS -bgS -cc -hfg -hbg}} {
  1936. # take colors by their variables
  1937. if {[info exist $val]} {set val [set $val]}
  1938. }
  1939. switch -- $opt {
  1940. -H - -head {
  1941. set head [string map {$ \$ \" \'\' \{ ( \} )} $val]
  1942. }
  1943. -help {
  1944. set buttons "butHELP Help {$val} $buttons"
  1945. }
  1946. -ch - -checkbox {set chmsg "$val"}
  1947. -g - -geometry {
  1948. set geometry $val
  1949. if {[set wasgeo [expr {[string first "pointer" $val]<0}]]} {
  1950. lassign [splitGeometry $geometry] - - gx gy
  1951. }
  1952. }
  1953. -c - -color {append optsLabel " -foreground {$val}"}
  1954. -a { ;# additional grid options of message labels
  1955. append optsGrid " $val" }
  1956. -centerme - -ontop - -themed - -resizable - -checkgeometry - -onclose - -comOK - -transient {
  1957. lappend args $opt $val ;# options delegated to showModal method
  1958. }
  1959. -parent - -root { ;# obsolete, used for compatibility
  1960. lappend args -centerme $val
  1961. }
  1962. -t - -text {set textmode $val}
  1963. -tags {
  1964. upvar 2 $val _tags
  1965. set tags $_tags
  1966. }
  1967. -ro - -readonly {set readonly [set hidefind $val]}
  1968. -rotext {set hidefind 0; set rotext $val}
  1969. -w - -width {set charwidth $val}
  1970. -h - -height {set charheight $val}
  1971. -fg {append optsMisc " -foreground {$val}"}
  1972. -bg {append optsMisc " -background {$val}"}
  1973. -fgS {append optsMisc " -selectforeground {$val}"}
  1974. -bgS {append optsMisc " -selectbackground {$val}"}
  1975. -cc {append optsMisc " -insertbackground {$val}"}
  1976. -my - -myown {append optsMisc " -myown {$val}"}
  1977. -pos {set curpos "$val"}
  1978. -hfg {append optsHead " -foreground {$val}"}
  1979. -hbg {append optsHead " -background {$val}"}
  1980. -hsz {append hsz " -size $val"}
  1981. -minsize {set minsize "-minsize {$val}"}
  1982. -focus {set focusmatch "$val"}
  1983. -theme {append themecolors " {$val}"}
  1984. -post {set postcom $val}
  1985. -popup {set addpopup [string map [list %w $qdlg.fra.texM] "$val"]}
  1986. -timeout - -focusback - -scroll - -tab2 - -stay - -modal - -waitvar {
  1987. set [string range $opt 1 end] $val
  1988. }
  1989. default {
  1990. append optsFont " $opt $val"
  1991. if {$opt ne "-family"} {
  1992. append optsFontM " $opt $val"
  1993. }
  1994. }
  1995. }
  1996. }
  1997. if {[set wprev [InfoFind $wdia $modal]] ne {}} {
  1998. catch {
  1999. wm withdraw $wprev
  2000. wm deiconify $wprev
  2001. puts "$wprev already exists: selected now"
  2002. }
  2003. return 0
  2004. }
  2005. set optsFont [string trim $optsFont]
  2006. set optsHeadFont $optsFont
  2007. set fs [basicFontSize]
  2008. set textfont "-family {[basicTextFont]}"
  2009. if {$optsFont ne {}} {
  2010. if {[string first "-size " $optsFont]<0} {
  2011. append optsFont " -size $fs"
  2012. }
  2013. if {[string first "-size " $optsFontM]<0} {
  2014. append optsFontM " -size $fs"
  2015. }
  2016. if {[string first "-family " $optsFont]>=0} {
  2017. set optsFont "-font \{$optsFont"
  2018. } else {
  2019. set optsFont "-font \{$optsFont -family {[basicDefFont]}"
  2020. }
  2021. append optsFont "\}"
  2022. } else {
  2023. set optsFont "-font {[basicDefFont] -size $fs}"
  2024. set optsFontM "-size $fs"
  2025. }
  2026. set msgonly [expr {$readonly || $hidefind || $chmsg ne {}}]
  2027. if {!$textmode || $msgonly} {
  2028. set textfont "-family {[basicDefFont]}"
  2029. if {!$textmode} {
  2030. set msg [string map [list \\ \\\\ \{ \\\\\{ \} \\\\\}] $msg]
  2031. }
  2032. }
  2033. set optsFontM [string trim $optsFontM]
  2034. set optsFontM "-font \{$optsFontM $textfont\}"
  2035. # layout: add the icon
  2036. if {$icon ni {{} -}} {
  2037. #tk_messageBox -title $dan(TITLE) -icon error -message "Yess!"
  2038. set widlist [list [list labBimg - - 99 1 \
  2039. {-st n -pady 7} "-image [iconImage $icon]"]]
  2040. set prevl labBimg
  2041. } else {
  2042. set widlist [list [list labimg - - 99 1]]
  2043. set prevl labimg ;# this trick would hide the prevw at all
  2044. }
  2045. set prevw labBimg
  2046. #tk_messageBox -title $dan(TITLE) -icon info -message Header:$head
  2047. if {$head ne {}} {
  2048. # set the dialog's heading (-head option)
  2049. if {$optsHeadFont ne {} || $hsz ne {}} {
  2050. if {$hsz eq {}} {set hsz "-size [basicFontSize]"}
  2051. set optsHeadFont [string trim "$optsHeadFont $hsz"]
  2052. set optsHeadFont "-font \"$optsHeadFont\""
  2053. }
  2054. set optsFont {}
  2055. set prevp L
  2056. set head [string map {\\n \n} $head]
  2057. foreach lh [split $head "\n"] {
  2058. set labh "labheading[incr il]"
  2059. lappend widlist [list $labh $prevw $prevp 1 99 {-st we} \
  2060. "-t \"$lh\" $optsHeadFont $optsHead"]
  2061. set prevw [set prevh $labh]
  2062. set prevp T
  2063. }
  2064. } else {
  2065. # add the upper (before the message) blank frame
  2066. lappend widlist [list h_1 $prevw L 1 1 {-pady 3}]
  2067. set prevw [set prevh h_1]
  2068. set prevp T
  2069. }
  2070. # add the message lines
  2071. set il [set maxw 0]
  2072. if {$readonly && $rotext eq {}} {
  2073. # only for messaging (not for editing/viewing texts):
  2074. set msg [string map {\\\\n \\n \\n \n} $msg]
  2075. }
  2076. foreach m [split $msg \n] {
  2077. set m [string map {$ \$ \" \'\'} $m]
  2078. if {[set mw [string length $m]] > $maxw} {
  2079. set maxw $mw
  2080. }
  2081. incr il
  2082. if {!$textmode} {
  2083. lassign [GetLinkLab $m] m link
  2084. lappend widlist [list Lab$il $prevw $prevp 1 7 \
  2085. "-st w -rw 1 $optsGrid" "-t \"$m \" $optsLabel $optsFont $link"]
  2086. }
  2087. set prevw Lab$il
  2088. set prevp T
  2089. }
  2090. if {$inopts ne {}} {
  2091. # here are widgets for input (in fraM frame)
  2092. set io0 [lindex $inopts 0]
  2093. lset io0 1 $prevh
  2094. lset inopts 0 $io0
  2095. foreach io $inopts {
  2096. lappend widlist $io
  2097. }
  2098. set prevw fraM
  2099. } elseif {$textmode} {
  2100. # here is text widget (in fraM frame)
  2101. ; proc vallimits {val lowlimit isset limits} {
  2102. set val [expr {max($val,$lowlimit)}]
  2103. if {$isset} {
  2104. upvar $limits lim
  2105. lassign $lim l1 l2
  2106. set val [expr {min($val,$l1)}] ;# forced low
  2107. if {$l2 ne {}} {set val [expr {max($val,$l2)}]} ;# forced high
  2108. }
  2109. return $val
  2110. }
  2111. set il [vallimits $il 1 [info exists charheight] charheight]
  2112. incr maxw
  2113. set maxw [vallimits $maxw 20 [info exists charwidth] charwidth]
  2114. rename vallimits {}
  2115. lappend widlist [list fraM $prevh T 10 12 {-st nswe -pady 3 -rw 1}]
  2116. lappend widlist [list TexM - - 1 12 {pack -side left -expand 1 -fill both -in \
  2117. $qdlg.fra.fraM} [list -h $il -w $maxw {*}$optsFontM {*}$optsMisc \
  2118. -wrap word -textpop 0 -tabnext "$qdlg.fra.[lindex $buttons 0] *but0"]]
  2119. if {$scroll} {
  2120. lappend widlist {sbv texM L 1 1 {pack -in $qdlg.fra.fraM}}
  2121. }
  2122. set prevw fraM
  2123. }
  2124. # add the lower (after the message) blank frame
  2125. lappend widlist [list h_2 $prevw T 1 1 {-pady 0 -ipady 0 -csz 0}]
  2126. # underline the message
  2127. lappend widlist [list seh $prevl T 1 99 {-st ew}]
  2128. # add left frames and checkbox (before buttons)
  2129. lappend widlist [list h_3 seh T 1 1 {-pady 0 -ipady 0 -csz 0}]
  2130. if {$textmode} {
  2131. # binds to the special popup menu of the text widget
  2132. set wt "\[TexM\]"
  2133. set binds "set pop $wt.popupMenu
  2134. bind $wt <Button-3> \{[self] themePopup $wt.popupMenu; tk_popup $wt.popupMenu %X %Y \}"
  2135. if {$msgonly} {
  2136. append binds "
  2137. menu \$pop
  2138. \$pop add command [iconA copy] -accelerator Ctrl+C -label \"Copy\" \\
  2139. -command \"event generate $wt <<Copy>>\""
  2140. if {$hidefind || $chmsg ne {}} {
  2141. append binds "
  2142. \$pop configure -tearoff 0
  2143. \$pop add separator
  2144. \$pop add command [iconA none] -accelerator Ctrl+A \\
  2145. -label \"Select All\" -command \"$wt tag add sel 1.0 end\"
  2146. bind $wt <Control-a> \"$wt tag add sel 1.0 end; break\""
  2147. }
  2148. }
  2149. }
  2150. set appendHL no
  2151. if {$chmsg eq {}} {
  2152. if {$textmode} {
  2153. set noIMG "[iconA none]"
  2154. if {$hidefind} {
  2155. lappend widlist [list h__ h_3 L 1 4 {-cw 1}]
  2156. } else {
  2157. lappend widlist [list labfnd h_3 L 1 1 "-st e" "-t {$::win::msgarray(find)}"]
  2158. lappend widlist [list Entfind labfnd L 1 1 \
  2159. {-st ew -cw 1} "-tvar [namespace current]::Foundstr -w 10"]
  2160. lappend widlist [list labfnd2 Entfind L 1 1 "-cw 2" "-t {}"]
  2161. lappend widlist [list h__ labfnd2 L 1 1]
  2162. #append binds "
  2163. # bind \[[self] Entfind\] <Return> {[self] findInText}
  2164. # bind \[[self] Entfind\] <KP_Enter> {[self] findInText}
  2165. # bind \[[self] Entfind\] <FocusIn> {\[[self] Entfind\] selection range 0 end}
  2166. # bind $qdlg <F3> {[self] findInText 1}
  2167. # bind $qdlg <Control-f> \"InitFindInText 1; focus \[[self] Entfind\]; break\"
  2168. # bind $qdlg <Control-F> \"InitFindInText 1; focus \[[self] Entfind\]; break\""
  2169. }
  2170. if {$readonly} {
  2171. if {!$hidefind} {
  2172. # append binds "
  2173. # \$pop add separator
  2174. # \$pop add command [iconA find] -accelerator Ctrl+F -label \\
  2175. # \"Find First\" -command \"[self] InitFindInText; focus \[[self] Entfind\]\"
  2176. # \$pop add command $noIMG -accelerator F3 -label \"Find Next\" \\
  2177. # -command \"[self] findInText 1\"
  2178. # $addpopup
  2179. # \$pop add separator
  2180. # \$pop add command [iconA exit] -accelerator Esc -label \"Close\" \\
  2181. # -command \"\[[self] paveoptionValue Defb1\] invoke\"
  2182. # "
  2183. } else {
  2184. set appendHL yes
  2185. }
  2186. } else {
  2187. # make bindings and popup menu for text widget
  2188. #after idle "set_highlight_matches \[TexM\]"
  2189. #append binds "
  2190. # [setTextBinds $wt]
  2191. # menu \$pop
  2192. # \$pop add command [iconA cut] -accelerator Ctrl+X -label \"Cut\" \\
  2193. # -command \"event generate $wt <<Cut>>\"
  2194. # \$pop add command [iconA copy] -accelerator Ctrl+C -label \"Copy\" \\
  2195. # -command \"event generate $wt <<Copy>>\"
  2196. # \$pop add command [iconA paste] -accelerator Ctrl+V -label \"Paste\" \\
  2197. # -command \"event generate $wt <<Paste>>\"
  2198. # [popupBlockCommands \$pop $wt]
  2199. # [popupHighlightCommands \$pop $wt]
  2200. # [popupFindCommands \$pop $wt]
  2201. # $addpopup
  2202. # \$pop add separator
  2203. # \$pop add command [iconA SaveFile] -accelerator Ctrl+W \\
  2204. # -label \"Save and Close\" -command \"[self] res $qdlg 1\"
  2205. # "
  2206. }
  2207. #set onclose [namespace current]::exitEditor
  2208. #oo::objdefine [self] export InitFindInText
  2209. } else {
  2210. lappend widlist [list h__ h_3 L 1 4 {-cw 1}]
  2211. }
  2212. } else {
  2213. lappend widlist [list chb h_3 L 1 1 \
  2214. {-st w} "-t {$chmsg} -var [namespace current]::CheckNomore"]
  2215. lappend widlist [list h_ chb L 1 1]
  2216. lappend widlist [list sev h_ L 1 1 {-st nse -cw 1}]
  2217. lappend widlist [list h__ sev L 1 1]
  2218. set appendHL $textmode
  2219. }
  2220. #if {$appendHL} {
  2221. # after idle "set_highlight_matches $wt"
  2222. # append binds "
  2223. # [popupHighlightCommands \$pop $wt]"
  2224. #}
  2225. # add the buttons
  2226. # xxx
  2227. if {$dlgname eq "RenameFile" || $dlgname eq "RenameFolder" || $dlgname eq "Find" || $dlgname eq "GotoLine"} {
  2228. set buttons [string map {"butOK OK 1" "" "butCANCEL Cancel destroy" ""} $buttons]
  2229. }
  2230. lassign [AppendButtons widlist $buttons h__ L $defb $timeout $qdlg $modal] \
  2231. bhelp bcomm
  2232. # make the dialog's window
  2233. set wtop [makeWindow $qdlg.fra $ttl]
  2234. if {$bhelp ne {}} {
  2235. bind $qdlg <F1> $bcomm
  2236. }
  2237. # pave the dialog's window
  2238. if {$tab2 eq {}} {
  2239. set widlist [rockWindow $qdlg.fra $widlist]
  2240. } else {
  2241. # pave with the notebook tabs (titl1 title2 [title3...] widlist2 [widlist3...])
  2242. lassign $tab2 ttl1 ttl2 widlist2 ttl3 widlist3 ttl4 widlist4 ttl5 widlist5
  2243. foreach nt {3 4 5} {
  2244. set ttl ttl$nt
  2245. set wdl widlist$nt
  2246. if {[set _ [set $ttl]] ne {}} {
  2247. set $ttl [list f$nt "-t {$_}"]
  2248. set $wdl [list $qdlg.fra.nbk.f$nt "[set $wdl]"]
  2249. }
  2250. }
  2251. set widlist0 [list [list nbk - - - - {pack -side top -expand 1 -fill both} [list \
  2252. f1 "-t {$ttl1}" \
  2253. f2 "-t {$ttl2}" \
  2254. {*}$ttl3 \
  2255. {*}$ttl4 \
  2256. {*}$ttl5 \
  2257. ]]]
  2258. set widlist1 [list]
  2259. foreach it $widlist {
  2260. lassign $it w nei pos r c opt atr
  2261. set opt [string map {$qdlg.fra $qdlg.fra.nbk.f1} $opt]
  2262. lappend widlist1 [list $w $nei $pos $r $c $opt $atr]
  2263. }
  2264. set widlist [rockWindow $qdlg.fra $widlist0 \
  2265. $qdlg.fra.nbk.f1 $widlist1 \
  2266. $qdlg.fra.nbk.f2 $widlist2 \
  2267. {*}$widlist3 \
  2268. {*}$widlist4 \
  2269. {*}$widlist5 \
  2270. ]
  2271. set tab2 nbk.f1.
  2272. }
  2273. if {$precom ne {}} {
  2274. {*}$precom ;# actions before showModal
  2275. }
  2276. # if {$themecolors ne {}} {
  2277. # # themed colors are set as sequentional '-theme' args
  2278. # if {[llength $themecolors]==2} {
  2279. # # when only 2 main fb/bg colors are set (esp. for TKE)
  2280. # lassign [::apave::parseOptions $optsMisc -foreground black \
  2281. # -background white -selectforeground black \
  2282. # -selectbackground gray -insertbackground black] v0 v1 v2 v3 v4
  2283. # # the rest colors should be added, namely:
  2284. # # tfg2 tbg2 tfgS tbgS tfgD tbgD tcur bclr help fI bI fM bM fW bW bHL2
  2285. # lappend themecolors $v0 $v1 $v2 $v3 $v3 $v1 $v4 $v4 $v3 $v2 $v3 $v0 $v1 black #ffff9e $v1
  2286. # }
  2287. # catch {
  2288. # my themeWindow $qdlg $themecolors no
  2289. # }
  2290. # }
  2291. # after creating widgets - show dialog texts if any
  2292. SetGetTexts set $qdlg.fra $inopts $widlist
  2293. lassign [LowercaseWidgetName $qdlg.fra.$tab2$defb] focusnow
  2294. if {$textmode} {
  2295. displayTaggedText [TexM] msg $tags
  2296. if {$defb eq "ButTEXT"} {
  2297. if {$readonly} {
  2298. lassign [LowercaseWidgetName $Defb1] focusnow
  2299. } else {
  2300. set focusnow [TexM]
  2301. catch "::tk::TextSetCursor $focusnow $curpos"
  2302. foreach k {w W} \
  2303. {catch "bind $focusnow <Control-$k> {[self] res $qdlg 1; break}"}
  2304. }
  2305. }
  2306. if {$readonly} {
  2307. readonlyWidget ::[TexM] true false
  2308. }
  2309. }
  2310. if {$focusmatch ne {}} {
  2311. foreach w $widlist {
  2312. lassign $w widname
  2313. lassign [LowercaseWidgetName $widname] wn rn
  2314. if {[string match $focusmatch $rn]} {
  2315. lassign [LowercaseWidgetName $qdlg.fra.$wn] focusnow
  2316. break
  2317. }
  2318. }
  2319. }
  2320. catch "$binds"
  2321. set args [removeOptions $args -focus]
  2322. set querydlg $qdlg
  2323. showModal $qdlg -modal $modal -waitvar $waitvar -onclose $onclose \
  2324. -focus $focusnow -geometry $geometry {*}$minsize {*}$args
  2325. if {![winfo exists $qdlg] || (!$modal && !$waitvar)} {
  2326. return 0
  2327. }
  2328. set pdgeometry [wm geometry $qdlg]
  2329. # the dialog's result is defined by "pave res" + checkbox's value
  2330. # xxx
  2331. #tk_messageBox -title $dan(TITLE) -icon info -message $qdlg
  2332. set res [set result [::radxide::win::res $qdlg]]
  2333. #tk_messageBox -title $dan(TITLE) -icon info -message resX=$res
  2334. set chv $CheckNomore
  2335. if { [string is integer $res] } {
  2336. if {$res && $chv} { incr result 10 }
  2337. } else {
  2338. set res [expr {$result ne {} ? 1 : 0}]
  2339. if {$res && $chv} { append result 10 }
  2340. }
  2341. if {$textmode && !$readonly} {
  2342. set focusnow [TexM]
  2343. set textcont [$focusnow get 1.0 end]
  2344. if {$res && $postcom ne {}} {
  2345. {*}$postcom textcont [TexM] ;# actions after showModal
  2346. }
  2347. set textcont " [$focusnow index insert] $textcont"
  2348. } else {
  2349. set textcont {}
  2350. }
  2351. if {$res && $inopts ne {}} {
  2352. SetGetTexts get $qdlg.fra $inopts $widlist
  2353. set inopts " [GetVarsValues $widlist]"
  2354. } else {
  2355. set inopts {}
  2356. }
  2357. if {$textmode && $rotext ne {}} {
  2358. set $rotext [string trimright [TexM] get 1.0 end]]
  2359. }
  2360. if {!$stay} {
  2361. destroy $qdlg
  2362. update
  2363. # pause a bit and restore the old focus
  2364. if {$focusback ne {} && [winfo exists $focusback]} {
  2365. set w ".[lindex [split $focusback .] 1]"
  2366. after 50 [list if "\[winfo exist $focusback\]" "focus -force $focusback" elseif "\[winfo exist $w\]" "focus $w"]
  2367. } else {
  2368. after 50 list focus .
  2369. }
  2370. }
  2371. if {$wasgeo} {
  2372. lassign [splitGeometry $pdgeometry] w h x y
  2373. catch {
  2374. # geometry option can contain pointer/root etc.
  2375. if {abs($x-$gx)<30} {set x $gx}
  2376. if {abs($y-$gy)<30} {set y $gy}
  2377. }
  2378. return [list $result ${w}x$h$x$y $textcont [string trim $inopts]]
  2379. }
  2380. return "$result$textcont$inopts"
  2381. }
  2382. # ________________________ readonlyWidget _________________________ #
  2383. proc readonlyWidget {w {on yes} {popup yes}} {
  2384. # Switches on/off a widget's readonly state for a text widget.
  2385. # w - text widget's path
  2386. # on - "on/off" boolean flag
  2387. # popup - "make popup menu" boolean flag
  2388. # See also:
  2389. # [wiki.tcl-lang.org](https://wiki.tcl-lang.org/page/Read-only+text+widget)
  2390. #my TextCommandForChange $w {} $on
  2391. #if {$popup} {my makePopup $w $on yes}
  2392. return
  2393. }
  2394. proc readTextFile {fileName {varName ""} {doErr 0} args} {
  2395. # Reads a text file.
  2396. # fileName - file name
  2397. # varName - variable name for file content or ""
  2398. # doErr - if 'true', exit at errors with error message
  2399. # Returns file contents or "".
  2400. variable _PU_opts
  2401. if {$varName ne {}} {upvar $varName fvar}
  2402. if {[catch {set chan [open $fileName]} _PU_opts(_ERROR_)]} {
  2403. if {$doErr} {error [::radxide::win::error $fileName]}
  2404. set fvar {}
  2405. } else {
  2406. set enc [getOption -encoding {*}$args]
  2407. set eol [string tolower [getOption -translation {*}$args]]
  2408. if {$eol eq {}} {set eol auto} ;# let EOL be autodetected by default
  2409. textChanConfigure $chan $enc $eol
  2410. set fvar [read $chan]
  2411. close $chan
  2412. logMessage "read $fileName"
  2413. }
  2414. return $fvar
  2415. }
  2416. # ________________________ renameFileOK _________________________ #
  2417. proc renameFileOK {} {
  2418. namespace upvar ::radxide dan dan project project
  2419. variable dlg
  2420. #set t $Dlgpath.fra.fraM.fraent.ent
  2421. set t [dlgPath].fra.[FieldName [lindex [getDialogField 0] 0]]
  2422. #tk_messageBox -title $dan(TITLE) -icon info -message textbox=$t
  2423. set varname [lindex [getDialogField end] 0]
  2424. #tk_messageBox -title $dan(TITLE) -icon info -message varname=$varname
  2425. set oldpath [lindex [getDialogField end] 1]
  2426. #tk_messageBox -title $dan(TITLE) -icon info -message oldpath=$oldpath
  2427. set newpath [string trim [$t get]]
  2428. #tk_messageBox -title $dan(TITLE) -icon info -message newpath=$newpath
  2429. set pathlength [expr [string length $newpath]-1]
  2430. if {[string range $newpath $pathlength $pathlength] eq "/"} {
  2431. tk_messageBox -title $dan(TITLE) -icon info -message "Destination can't be a folder!"
  2432. return 0
  2433. }
  2434. if {[string first $dan(WORKDIR) $newpath] eq -1} {
  2435. tk_messageBox -title $dan(TITLE) -icon info -message "New file path outside the Working Dir!"
  2436. return 0
  2437. }
  2438. if {[string first $project(ROOT) $newpath] eq -1} {
  2439. tk_messageBox -title $dan(TITLE) -icon info -message "New file path outside the Project Dir!"
  2440. return 0
  2441. }
  2442. if {[catch {file rename $oldpath $newpath} e]} {
  2443. set msg "\nERROR in win:"
  2444. puts \n$msg\n\n$e$::errorInfo\n
  2445. set msg "$msg\n\n$e\n\nPlease, inform authors.\nDetails are in stdout."
  2446. tk_messageBox -title $dan(TITLE) -icon error -message $msg
  2447. return 0
  2448. }
  2449. # saving {field oldval newval} for later use
  2450. editDialogField end $varname $oldpath $newpath
  2451. ::radxide::tree::create
  2452. # Workaround for an overwheling activation of the main text editor..
  2453. if {$project(CUR_FILE_PATH) eq ""} {
  2454. $dan(TEXT) configure -state disabled
  2455. }
  2456. catch {destroy [dlgPath]}
  2457. return 1
  2458. }
  2459. # ________________________ renameFileCancel _________________________ #
  2460. proc renameFileCancel {} {
  2461. #catch {[destroy .danwin.diaRenameFile1]}
  2462. catch {[destroy [dlgPath]]}
  2463. return 0
  2464. }
  2465. # ________________________ renameFolderOK _________________________ #
  2466. proc renameFolderOK {} {
  2467. namespace upvar ::radxide dan dan project project
  2468. variable dlg
  2469. #set t $Dlgpath.fra.fraM.fraent.ent
  2470. set t [dlgPath].fra.[FieldName [lindex [getDialogField 0] 0]]
  2471. #tk_messageBox -title $dan(TITLE) -icon info -message textbox=$t
  2472. set varname [lindex [getDialogField end] 0]
  2473. #tk_messageBox -title $dan(TITLE) -icon info -message varname=$varname
  2474. set oldpath [lindex [getDialogField end] 1]
  2475. #tk_messageBox -title $dan(TITLE) -icon info -message oldpath=$oldpath
  2476. set newpath [string trim [$t get]]
  2477. #tk_messageBox -title $dan(TITLE) -icon info -message newpath=$newpath
  2478. set oldparent [string range $oldpath 0 [expr [string last "/" $oldpath]-1]]
  2479. #tk_messageBox -title $dan(TITLE) -icon info -message oldparent=$oldparent
  2480. set newparent [string range $newpath 0 [expr [string last "/" $newpath]-1]]
  2481. #tk_messageBox -title $dan(TITLE) -icon info -message newparent=$newparent
  2482. set pathlength [expr [string length $newpath]-1]
  2483. if {[string range $newpath $pathlength $pathlength] eq "/"} {
  2484. tk_messageBox -title $dan(TITLE) -icon info -message "Please delete the final '\/'!"
  2485. return 0
  2486. }
  2487. if {[string first $dan(WORKDIR) $newpath] eq -1} {
  2488. tk_messageBox -title $dan(TITLE) -icon info -message "New file path outside the Working Dir!"
  2489. return 0
  2490. }
  2491. if {[string first $project(ROOT) $newpath] eq -1} {
  2492. tk_messageBox -title $dan(TITLE) -icon info -message "New file path outside the Project Dir!"
  2493. return 0
  2494. }
  2495. if {$oldparent ne $newparent} {
  2496. tk_messageBox -title $dan(TITLE) -icon info -message "Change of parent folder disallowed!"
  2497. return 0
  2498. }
  2499. if {[catch {file rename $oldpath $newpath} e]} {
  2500. set msg "\nERROR in win:"
  2501. puts \n$msg\n\n$e$::errorInfo\n
  2502. set msg "$msg\n\n$e\n\nPlease, inform authors.\nDetails are in stdout."
  2503. tk_messageBox -title $dan(TITLE) -icon error -message $msg
  2504. return 0
  2505. }
  2506. # savind {field oldval newval} for later use
  2507. editDialogField end $varname $oldpath $newpath
  2508. ::radxide::tree::create
  2509. # Workaround for an overwheling activation of the main text editor..
  2510. if {$project(CUR_FILE_PATH) eq ""} {
  2511. $dan(TEXT) configure -state disabled
  2512. }
  2513. catch {destroy [dlgPath]}
  2514. return 1
  2515. }
  2516. # ________________________ renameFolderCancel _________________________ #
  2517. proc renameFolderCancel {} {
  2518. #catch {[destroy .danwin.diaRenameFolder1]}
  2519. catch {[destroy [dlgPath]]}
  2520. return 0
  2521. }
  2522. # ________________________ Replace_Tcl _________________________ #
  2523. proc Replace_Tcl {r1 r2 r3 args} {
  2524. # Replaces Tcl code with its resulting items in *lwidgets* list.
  2525. # r1 - variable name for a current index in *lwidgets* list
  2526. # r2 - variable name for a length of *lwidgets* list
  2527. # r3 - variable name for *lwidgets* list
  2528. # args - "tcl" and "tcl code" for "tcl" type of widget
  2529. # The code should use the wildcard that goes first at a line:
  2530. # %C - a command for inserting an item into lwidgets list.
  2531. # The "tcl" widget type can be useful to automate the inserting
  2532. # a list of similar widgets to the list of widgets.
  2533. # See tests/test2_pave.tcl where the "tcl" fills "Color schemes" tab.
  2534. lassign $args _name _code
  2535. if {[ownWName $_name] ne {tcl}} {return $args}
  2536. upvar 1 $r1 _ii $r2 _lwlen $r3 _lwidgets
  2537. ; proc lwins {lwName i w} {
  2538. upvar 2 $lwName lw
  2539. set lw [linsert $lw $i $w]
  2540. }
  2541. set _lwidgets [lreplace $_lwidgets $_ii $_ii] ;# removes tcl item
  2542. set _inext [expr {$_ii-1}]
  2543. eval [string map {%C {lwins $r3 [incr _inext] }} $_code]
  2544. return {}
  2545. }
  2546. # ________________________ removeOptions _________________________ #
  2547. proc removeOptions {options args} {
  2548. # Removes some options from a list of options.
  2549. # options - list of options and values
  2550. # args - list of option names to remove
  2551. # The `options` may contain "key value" pairs and "alone" options
  2552. # without values.
  2553. # To remove "key value" pairs, `key` should be an exact name.
  2554. # To remove an "alone" option, `key` should be a glob pattern with `*`.
  2555. foreach key $args {
  2556. while {[incr maxi]<99} {
  2557. if {[set i [lsearch -exact $options $key]]>-1} {
  2558. catch {
  2559. # remove a pair "option value"
  2560. set options [lreplace $options $i $i]
  2561. set options [lreplace $options $i $i]
  2562. }
  2563. } elseif {[string first * $key]>=0 && \
  2564. [set i [lsearch -glob $options $key]]>-1} {
  2565. # remove an option only
  2566. set options [lreplace $options $i $i]
  2567. } else {
  2568. break
  2569. }
  2570. }
  2571. }
  2572. return $options
  2573. }
  2574. # ________________________ res _________________________ #
  2575. proc res {{win {}} {result get}} {
  2576. # Gets/sets a variable for *vwait* command.
  2577. # win - window's path
  2578. # result - value of variable
  2579. # This method is used when
  2580. # - an event cycle should be stopped with changing a variable's value
  2581. # - a result of event cycle (the variable's value) should be got
  2582. # In the first case, *result* is set to an integer. In *apave* dialogs
  2583. # the integer is corresponding a pressed button's index.
  2584. # In the second case, *result* is omitted or equal to "get".
  2585. # Returns a value of variable that controls an event cycle.
  2586. if {$win eq {}} {set win [dlgPath]}
  2587. set varname [WinVarname $win]
  2588. if {$result eq {get}} {
  2589. return [set $varname]
  2590. }
  2591. #CleanUps $win
  2592. return [set $varname $result]
  2593. }
  2594. # ___________________ rockWindow _________________ #
  2595. proc rockWindow {args} {
  2596. # Processes "win / list_of_widgets" pairs.
  2597. # args - list of pairs "win / lwidgets"
  2598. # The *win* is a window's path. The *lwidgets* is a list of widget items.
  2599. # Each widget item contains:
  2600. # name - widget's name (first 3 characters define its type)
  2601. # neighbor - top or left neighbor of the widget
  2602. # posofnei - position of neighbor: T (top) or L (left)
  2603. # rowspan - row span of the widget
  2604. # colspan - column span of the widget
  2605. # options - grid/pack options
  2606. # attrs - attributes of widget
  2607. # First 3 items are mandatory, others are set at need.
  2608. # This method calls *paveWindow* in a cycle, to process a current "win/lwidgets" pair.
  2609. namespace upvar ::radxide dan dan
  2610. #tk_messageBox -title $dan(TITLE) -icon info -message "Start rock-Window!"
  2611. set res [list]
  2612. set wmain [set wdia {}]
  2613. foreach {w lwidgets} $args {
  2614. if {[lindex $lwidgets 0 0] eq {after}} {
  2615. # if 1st item is "after idle" or like "after 1000", layout the window after...
  2616. # (fit for "invisible independent" windows/frames/tabs)
  2617. set what [lindex $lwidgets 0 1]
  2618. if {$what eq {idle} || [string is integer -strict $what]} {
  2619. after $what [rockWindow $w [lrange $lwidgets 1 end]]
  2620. #after $what [list [self] colorWindow $w -doit]
  2621. }
  2622. continue
  2623. }
  2624. lappend res {*}[Window $w $lwidgets]
  2625. if {[set ifnd [regexp -indices -inline {[.]dia\d+} $w]] ne {}} {
  2626. set wdia [string range $w 0 [lindex $ifnd 0 1]]
  2627. } else {
  2628. set wmain .[lindex [split $w .] 1]
  2629. }
  2630. }
  2631. # add a system Menu binding for the created window
  2632. #if {[winfo exists $wdia]} {::apave::initPOP $wdia} elseif {
  2633. # [winfo exists $wmain]} {::apave::initPOP $wmain}
  2634. return $res
  2635. }
  2636. # ________________________ Search _________________________ #
  2637. # proc Search {wtxt} {
  2638. # # Searches a text for a string to find.
  2639. # # wtxt - text widget's path
  2640. #
  2641. # namespace upvar ::alited obPav obPav
  2642. # variable counts
  2643. # variable data
  2644. # set idx [$wtxt index insert]
  2645. # #lassign [FindOptions $wtxt] findstr options
  2646. # set options {}
  2647. # set findstr $data(en1)
  2648. # if {![CheckData find]} {return {}}
  2649. # $obPav set_HighlightedString $findstr
  2650. # SetTags $wtxt
  2651. # lassign [Search1 $wtxt 1.0] err fnd
  2652. # if {$err} {return {}}
  2653. # set i 0
  2654. # set res [list]
  2655. # foreach index1 $fnd {
  2656. # set index2 [$wtxt index "$index1 + [lindex $counts $i]c"]
  2657. # if {[CheckWord $wtxt $index1 $index2]} {
  2658. # lappend res [list $index1 $index2]
  2659. # }
  2660. # incr i
  2661. # }
  2662. # return $res
  2663. # }
  2664. #_______________________ selectedWordText _____________________ #
  2665. proc selectedWordText {txt} {
  2666. # Returns a word under the cursor or a selected text.
  2667. # txt - the text's path
  2668. set seltxt {}
  2669. if {![catch {$txt tag ranges sel} seltxt]} {
  2670. if {$seltxt eq ""} {return ""}
  2671. set forword [expr {$seltxt eq {}}]
  2672. #if {[set forword [expr {$seltxt eq {}}]]} {
  2673. # set pos [$txt index "insert wordstart"]
  2674. # set pos2 [$txt index "insert wordend"]
  2675. # set seltxt [string trim [$txt get $pos $pos2]]
  2676. # if {![string is wordchar -strict $seltxt]} {
  2677. # # when cursor just at the right of word: take the word at the left
  2678. # set pos [$txt index "insert -1 char wordstart"]
  2679. # set pos2 [$txt index "insert -1 char wordend"]
  2680. # }
  2681. #} else {
  2682. lassign $seltxt pos pos2
  2683. #}
  2684. #catch {
  2685. set seltxt [$txt get $pos $pos2]
  2686. if {[set sttrim [string trim $seltxt]] ne {}} {
  2687. if {$forword} {set seltxt $sttrim}
  2688. }
  2689. #}
  2690. }
  2691. return $seltxt
  2692. }
  2693. # ________________________ setAppIcon _________________________ #
  2694. proc setAppIcon {win {winicon ""}} {
  2695. # Sets application's icon.
  2696. # win - path to a window of application
  2697. # winicon - data of icon
  2698. # The *winicon* may be a contents of variable (as supposed by default) or
  2699. # a file's name containing th image data.
  2700. # If it fails to find an image in either, no icon is set.
  2701. set appIcon {}
  2702. if {$winicon ne {}} {
  2703. if {[catch {set appIcon [image create photo -data $winicon]}]} {
  2704. catch {set appIcon [image create photo -file $winicon]}
  2705. }
  2706. }
  2707. if {$appIcon ne {}} {wm iconphoto $win -default $appIcon}
  2708. }
  2709. # ________________________ SetGetTexts _________________________ #
  2710. proc SetGetTexts {oper w iopts lwidgets} {
  2711. # Sets/gets contents of text fields.
  2712. # oper - "set" to set, "get" to get contents of text field
  2713. # w - window's name
  2714. # iopts - equals to "" if no operation
  2715. # lwidgets - list of widget items
  2716. if {$iopts eq {}} return
  2717. foreach widg $lwidgets {
  2718. set wname [lindex $widg 0]
  2719. set name [ownWName $wname]
  2720. if {[string range $name 0 1] eq "te"} {
  2721. set vv [::radxide::win::varName $name]
  2722. if {$oper eq "set"} {
  2723. displayText $w.$wname [set $vv]
  2724. } else {
  2725. set $vv [string trimright [$w.$wname get 1.0 end]]
  2726. }
  2727. }
  2728. }
  2729. return
  2730. }
  2731. # ________________________ set_HighlightedString _________________________ #
  2732. proc set_HighlightedString {sel} {
  2733. # Saves a string got from highlighting by Alt+left/right/q/w.
  2734. # sel - the string to be saved
  2735. set HLstring $sel
  2736. if {$sel ne {}} {set Foundstr $sel}
  2737. }
  2738. # ________________________ set_highlight_matches _________________________ #
  2739. proc set_highlight_matches {w} {
  2740. # Creates bindings to highlight matches in a text.
  2741. # w - path to the text
  2742. }
  2743. # ________________________ setNewLineWithIndent _________________________ #
  2744. proc setNewLineWithIndent {} {
  2745. namespace upvar ::radxide dan dan
  2746. set wt $dan(TEXT)
  2747. # getting previous line
  2748. set idx1 [$wt index {insert linestart}]
  2749. set idx2 [$wt index {insert lineend}]
  2750. set line [$wt get $idx1 $idx2]
  2751. # erasing tabs, replacing them with spaces..
  2752. set line [string map {\t $dan(TAB_IN_SPACE)} $line]
  2753. # calculating identation..
  2754. set orilength [string length $line]
  2755. set newlength [string length [string trimleft $line]]
  2756. if {$newlength <= 0} {
  2757. # case previous line is only spaces..
  2758. set $newlength 0
  2759. set nindent 0
  2760. ::radxide::win::fillGutter .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText 5 1 "#FFFFFF" "#222223"
  2761. ::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll -1 units
  2762. ::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll 1 units
  2763. return 0
  2764. } else {
  2765. set nspacesofindent [expr $orilength - $newlength]
  2766. # inserintg correct identation..
  2767. $wt insert [$wt index {insert}] \n[string repeat " " $nspacesofindent]
  2768. set idx3 [$wt index insert]
  2769. set idx4 [$wt index "$idx3 +1 line"]
  2770. ::tk::TextSetCursor $wt $idx3
  2771. ::radxide::win::fillGutter .danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText 5 1 "#FFFFFF" "#222223"
  2772. ::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll -1 units
  2773. ::radxide::win::Yview {.danwin.fra.pan.fra2.text .danwin.fra.pan.fra2.gutText} scroll 1 units
  2774. return -code break
  2775. }
  2776. }
  2777. # ________________________ setTextBinds _________________________ #
  2778. proc setTextBinds {wt} {
  2779. # Returns bindings for a text widget.
  2780. # wt - the text's path
  2781. set res ""
  2782. return $res
  2783. }
  2784. # ________________________ showModal _________________________ #
  2785. proc showModal {win args} {
  2786. # Shows a window as modal.
  2787. # win - window's name
  2788. # args - attributes of window ("-name value" pairs)
  2789. namespace upvar ::radxide dan dan
  2790. variable MODALWINDOW
  2791. set MODALWINDOW [set Modalwin $win]
  2792. setAppIcon $win
  2793. lassign [extractOptions args -centerme {} -ontop 0 -modal yes -minsize {} \
  2794. -themed {} -input 0 -variable {} -waitvar {} -transient {-} -root {} -parent {}] \
  2795. centerme ontop modal minsize themed input varname waitvar transient root parent
  2796. $win configure -bg $dan(BG) ;# removes blinking by default bg
  2797. #if {$themed in {{} {0}} && [my csCurrent] != [apave::cs_Non]} {
  2798. # my colorWindow $win
  2799. #}
  2800. if {$centerme eq {}} {
  2801. # obsolete options: -root, -parent
  2802. if {$root ne {}} {set centerme $root} {set centerme $parent}
  2803. }
  2804. set root [winfo parent $win]
  2805. set rooted 1
  2806. if {$centerme ne {}} {
  2807. ;# forced centering relative to a caller's window
  2808. lassign [split $centerme x+] rw rh rx ry
  2809. set rooted [expr {![regexp {[+|-]+\d+\++} $centerme]}]
  2810. if {$rooted && [winfo exist $centerme]} {
  2811. set root $centerme
  2812. }
  2813. }
  2814. set decor [expr {$root in {{} .}}]
  2815. foreach {o v} [list -decor $decor -focus {} -onclose {} -geometry {} \
  2816. -resizable {} -ontop 0 -escape 1 -checkgeometry 1] {
  2817. lappend defargs $o [getShowOption $o $v]
  2818. }
  2819. if {$varname ne {}} {
  2820. set waitvar 1
  2821. } else {
  2822. set waitvar [string is true $waitvar] ;# default 1: wait for closing the window
  2823. set varname [WinVarname $win]
  2824. }
  2825. array set opt [list {*}$defargs {*}$args]
  2826. if {$ontop eq {}} {
  2827. if {$opt(-ontop)} {
  2828. set ontop yes
  2829. } else {
  2830. set ontop no
  2831. catch {
  2832. set ontop [wm attributes [winfo parent $win] -topmost]
  2833. }
  2834. if {!$ontop} {
  2835. # find if a window child of "." is topmost
  2836. # if so, let this one be topmost too
  2837. foreach w [winfo children .] {
  2838. catch {set ontop [wm attributes $w -topmost]}
  2839. if {$ontop} break
  2840. }
  2841. }
  2842. }
  2843. }
  2844. if {$rooted} {
  2845. lassign [splitGeometry [wm geometry [winfo toplevel $root]]] rw rh rx ry
  2846. }
  2847. if {$transient ne {-}} {
  2848. wm transient $win $transient
  2849. } elseif {!$opt(-decor)} {
  2850. wm transient $win $root
  2851. }
  2852. if {[set destroy [expr {$opt(-onclose) eq {destroy}}]]} {
  2853. set opt(-onclose) {}
  2854. }
  2855. if {$opt(-onclose) eq {}} {
  2856. set opt(-onclose) "set $varname 0"
  2857. } else {
  2858. set opt(-onclose) "$opt(-onclose) $varname" ;# $opt(-onclose) is a command
  2859. }
  2860. #if {$destroy} {append opt(-onclose) " ; destroy $win"}
  2861. if {$destroy} {append opt(-onclose) " ; destroy $win"}
  2862. if {$opt(-resizable) ne {}} {
  2863. if {[string is boolean $opt(-resizable)]} {
  2864. set opt(-resizable) "$opt(-resizable) $opt(-resizable)"
  2865. }
  2866. wm resizable $win {*}$opt(-resizable)
  2867. }
  2868. if {!($modal || $waitvar)} {
  2869. append opt(-onclose) "; CleanUps $win"
  2870. }
  2871. wm protocol $win WM_DELETE_WINDOW $opt(-onclose)
  2872. # get the window's geometry from its requested sizes
  2873. set inpgeom $opt(-geometry)
  2874. if {$inpgeom eq {}} {
  2875. # this is for less blinking:
  2876. set opt(-geometry) [centeredXY $win $rw $rh $rx $ry \
  2877. [winfo reqwidth $win] [winfo reqheight $win]]
  2878. } elseif {[string first pointer $inpgeom]==0} {
  2879. lassign [split $inpgeom+0+0 +] -> x y
  2880. set inpgeom +[expr {$x+[winfo pointerx .]}]+[expr {$y+[winfo pointery .]}]
  2881. set opt(-geometry) $inpgeom
  2882. } elseif {[string first root $inpgeom]==0} {
  2883. set root .[string trimleft [string range $inpgeom 5 end] .]
  2884. set opt(-geometry) [set inpgeom {}]
  2885. }
  2886. if {$opt(-geometry) ne {}} {
  2887. lassign [splitGeometry $opt(-geometry) {} {}] - - x y
  2888. if {$x ne {}} {wm geometry $win $x$y}
  2889. }
  2890. if {$opt(-focus) eq {}} {
  2891. set opt(-focus) $win
  2892. }
  2893. set $varname {-}
  2894. if {$opt(-escape)} {bind $win <Escape> $opt(-onclose)}
  2895. update
  2896. if {![winfo exists $win]} {
  2897. return 0 ;# looks idiotic, yet possible at sporadic calls
  2898. }
  2899. set w [winfo reqwidth $win]
  2900. set h [winfo reqheight $win]
  2901. if {$inpgeom eq {}} { ;# final geometrizing with actual sizes
  2902. set geo [centeredXY $win $rw $rh $rx $ry $w $h]
  2903. set y [lindex [split $geo +] end]
  2904. if {!$rooted || $root ne {.} && (($h/2-$ry-$rh/2)>30 || [::radxide::iswindows] && $y>0)} {
  2905. # ::tk::PlaceWindow needs correcting in rare cases, namely:
  2906. # when 'root' is of less sizes than 'win' and at screen top
  2907. wm geometry $win $geo
  2908. } else {
  2909. ::tk::PlaceWindow $win widget $root
  2910. }
  2911. } else {
  2912. lassign [splitGeometry $inpgeom {} {}] - - x y
  2913. if {$x ne {} && $y ne {} && [string first x $inpgeom]<0 && $opt(-checkgeometry)} {
  2914. set inpgeom [checkXY $win $w $h $x $y]
  2915. } elseif {$x eq {} && $y eq {} && $centerme ne {} && $opt(-geometry) ne {}} {
  2916. lassign [split $opt(-geometry) x+] w h
  2917. lassign [split [centeredXY $win $rw $rh $rx $ry $w $h] +] -> x y
  2918. set inpgeom ${w}x$h+$x+$y
  2919. }
  2920. wm geometry $win $inpgeom
  2921. }
  2922. after 50 [list if "\[winfo exist $opt(-focus)\]" "focus -force $opt(-focus)"]
  2923. #if {[info exists ::transpops::my::cntwait]} {
  2924. # # this specific bind - for transpops package (to hide a demo message by keys)
  2925. # bind $win <Control-Alt-0> {set ::transpops::my::cntwait 0}
  2926. #}
  2927. showWindow $win $modal $ontop $varname $minsize $waitvar
  2928. set res 0
  2929. #catch {
  2930. if {$modal || $waitvar} {CleanUps $win}
  2931. if {[winfo exists $win]} {
  2932. if {$input} {GetOutputValues}
  2933. set res [set [set _ $varname]]
  2934. }
  2935. #}
  2936. return $res
  2937. }
  2938. # ________________________ showWindow _________________________ #
  2939. proc showWindow {win modal ontop {var ""} {minsize ""} {waitvar 1}} {
  2940. # Displays a windows and goes in tkwait cycle to interact with a user.
  2941. # win - the window's path
  2942. # modal - yes at showing the window as modal
  2943. # ontop - yes at showing the window as topmost
  2944. # var - variable's name to receive a result (tkwait's variable)
  2945. # minsize - list {minwidth minheight} or {}
  2946. # waitvar - if yes, force tkwait variable (mostly for non-modal windows)
  2947. InfoWindow [expr {[InfoWindow] + 1}] $win $modal $var yes
  2948. #::apave::deiconify $win
  2949. if {$minsize eq {}} {
  2950. set minsize [list [winfo width $win] [winfo height $win]]
  2951. }
  2952. wm minsize $win {*}$minsize
  2953. bind $win <Configure> "[namespace current]::WinResize $win"
  2954. if {$ontop} {wm attributes $win -topmost 1}
  2955. if {$modal} {
  2956. # modal window:
  2957. waitWinVar $win $var $modal
  2958. InfoWindow [expr {[InfoWindow] - 1}] $win $modal $var
  2959. } else {
  2960. # non-modal window:
  2961. if {[set wgr [grab current]] ne {}} {
  2962. # otherwise the non-modal window is irresponsive (in Windows even at WM level):
  2963. grab release $wgr
  2964. }
  2965. if {$waitvar && $var ne {}} {
  2966. waitWinVar $win $var $modal ;# show and wait for closing the window
  2967. }
  2968. }
  2969. }
  2970. # ________________________ setShowOption _________________________ #
  2971. proc setShowOption {name args} {
  2972. # Sets / gets a default show option, used in showModal.
  2973. # name - name of option
  2974. # args - value of option
  2975. # See also: showModal
  2976. setProperty [ShowOption $name] {*}$args
  2977. }
  2978. # ________________________ setProperty _________________________ #
  2979. proc setProperty {name args} {
  2980. # Sets a property's value as "application-wide".
  2981. # name - name of property
  2982. # args - value of property
  2983. # If *args* is omitted, the method returns a property's value.
  2984. # If *args* is set, the method sets a property's value as $args.
  2985. variable _AP_Properties
  2986. switch -exact [llength $args] {
  2987. 0 {return [getProperty $name]}
  2988. 1 {return [set _AP_Properties($name) [lindex $args 0]]}
  2989. }
  2990. puts -nonewline stderr \
  2991. "Wrong # args: should be \"::win::setProperty propertyname ?value?\""
  2992. return -code error
  2993. }
  2994. # ________________________ ShowOption _________________________ #
  2995. proc ShowOption {name} {
  2996. # Gets a default show option, used in showModal.
  2997. # name - name of option
  2998. # See also: getShowOption, setShowOption
  2999. return "_SHOWMODAL_$name"
  3000. }
  3001. # ________________________ SpanConfig _________________________ #
  3002. proc SpanConfig {w rcnam rc rcspan opt val} {
  3003. # The method is used by *GetIntOptions* method to configure
  3004. # row/column for their *span* options.
  3005. for {set i $rc} {$i < ($rc + $rcspan)} {incr i} {
  3006. eval [grid ${rcnam}configure $w $i $opt $val]
  3007. }
  3008. return
  3009. }
  3010. # ________________________ splitGeometry _________________________ #
  3011. proc splitGeometry {geom {X +0} {Y +0}} {
  3012. # Gets widget's geometry components.
  3013. # geom - geometry
  3014. # X - default X-coordinate
  3015. # Y - default Y-coordinate
  3016. # Returns a list of width, height, X and Y (coordinates are always with + or -).
  3017. lassign [split $geom x+-] w h
  3018. lassign [regexp -inline -all {([+-][[:digit:]]+)} $geom] -> x y
  3019. if {$geom ne {}} {
  3020. if {$x in {"" 0} || [catch {expr {$x+0}}]} {set x $X}
  3021. if {$y in {"" 0} || [catch {expr {$y+0}}]} {set y $Y}
  3022. }
  3023. return [list $w $h $x $y]
  3024. }
  3025. # ________________________ textChanConfigure _________________________ #
  3026. proc textChanConfigure {channel {coding {}} {eol {}}} {
  3027. # Configures a channel for text file.
  3028. # channel - the channel
  3029. # coding - if set, defines encoding of the file
  3030. # eol - if set, defines EOL of the file
  3031. if {$coding eq {}} {
  3032. chan configure $channel -encoding utf-8
  3033. } else {
  3034. chan configure $channel -encoding $coding
  3035. }
  3036. if {$eol eq {}} {
  3037. chan configure $channel {*}[textEOL translation]
  3038. } else {
  3039. chan configure $channel -translation $eol
  3040. }
  3041. }
  3042. # ________________________ textEOL _________________________ #
  3043. proc textEOL {{EOL "-"}} {
  3044. # Gets/sets End-of-Line for text reqding/writing.
  3045. # EOL - LF, CR, CRLF or {}
  3046. # If EOL omitted or equals to {} or "-", return the current EOL.
  3047. # If EOL equals to "translation", return -translation option or {}.
  3048. variable _PU_opts
  3049. if {$EOL eq "-"} {return $_PU_opts(_EOL_)}
  3050. if {$EOL eq "translation"} {
  3051. if {$_PU_opts(_EOL_) eq ""} {return ""}
  3052. return "-translation $_PU_opts(_EOL_)"
  3053. }
  3054. set _PU_opts(_EOL_) [string trim [string tolower $EOL]]
  3055. }
  3056. # ________________________ TreSelect _________________________ #
  3057. proc TreSelect {w idx} {
  3058. # Selects a treeview item.
  3059. # w - treeview's path
  3060. # idx - item index
  3061. set items [$w children {}]
  3062. catch {
  3063. set it [lindex $items $idx]
  3064. $w see $it
  3065. $w focus $it
  3066. $w selection set $it ;# generates <<TreeviewSelect>>
  3067. }
  3068. }
  3069. # ________________________ varName _________________________ #
  3070. proc varName {wname} {
  3071. # Gets a variable name associated with a widget's name of "input" dialogue.
  3072. # wname - widget's name
  3073. return [namespace current]::var$wname
  3074. }
  3075. # ________________________ waitWinVar _________________________ #
  3076. proc waitWinVar {win var modal} {
  3077. # Tk waiting for variable's change.
  3078. # win - the window's path
  3079. # var - variable's name to receive a result (tkwait's variable)
  3080. # modal - yes at showing the window as modal
  3081. # first of all, wait till the window be visible
  3082. after 1 ;# solves an issue with doubleclicking buttons
  3083. if {![winfo viewable $win]} {
  3084. tkwait visibility $win
  3085. }
  3086. set wmain [winfo parent $win]
  3087. if {$modal} { ;# for modal, grab the window
  3088. set wgr [grab current]
  3089. if {$wmain ne {} && $wmain ne $win} {
  3090. if {[catch {grab set $win} e]} {
  3091. catch {tkwait visibility $win} ;# 2nd attempt to get the window visible, by force
  3092. catch {grab set $win} ;# (not sure, where it can fire, still let it be)
  3093. puts stderr "\n::radxide::win::waitWinVar - please send a note to apave developers on this catch. Error: $e"
  3094. catch {puts stderr "::radxide::win::waitWinVar - [info level -1]\n"}
  3095. }
  3096. }
  3097. }
  3098. # at need, wait till the window associated variable be changed
  3099. if {$var ne {}} {
  3100. tkwait variable $var
  3101. }
  3102. if {$modal} { ;# for modal, release the grab and restore the old one
  3103. catch {grab release $win}
  3104. if {$wgr ne {}} {
  3105. catch {grab set $wgr}
  3106. }
  3107. }
  3108. }
  3109. # ________________________ widgetType _________________________ #
  3110. proc widgetType {wnamefull options attrs} {
  3111. # Gets the widget type based on 3 initial letters of its name. Also
  3112. # fills the grid/pack options and attributes of the widget.
  3113. # wnamefull - path to the widget
  3114. # options - grid/pack options of the widget
  3115. # attrs - attribute of the widget
  3116. # Returns a list of items:
  3117. # widget - Tk/Ttk widget name
  3118. # options - grid/pack options of the widget
  3119. # attrs - attribute of the widget
  3120. # nam3 - 3 initial letters of widget's name
  3121. # disabled - flag of *disabled* state
  3122. set disabled [expr {[getOption -state {*}$attrs] eq {disabled}}]
  3123. set pack $options
  3124. set name [ownWName $wnamefull]
  3125. #if {[info exists ::apave::_AP_VARS(ProSplash,type)] && \
  3126. #$::apave::_AP_VARS(ProSplash,type) eq {}} {
  3127. # set val [my progress_Go [incr ::apave::_AP_VARS(ProSplash,curvalue)] {} $name]
  3128. #}
  3129. set nam3 [string tolower [string index $name 0]][string range $name 1 2]
  3130. if {[string index $nam3 1] eq "_"} {set k [string range $nam3 0 1]} {set k $nam3}
  3131. lassign [defaultATTRS $k] defopts defattrs newtype
  3132. set options "$defopts $options"
  3133. set attrs "$defattrs $attrs"
  3134. switch -glob -- $nam3 {
  3135. #bts {
  3136. # set widget ttk::frame
  3137. # if {![info exists ::bartabs::NewBarID]} {package require bartabs}
  3138. # set attrs "-bartabs {$attrs}"
  3139. #}
  3140. but {
  3141. set widget ttk::button
  3142. AddButtonIcon $name attrs
  3143. }
  3144. buT - btT {
  3145. set widget button
  3146. AddButtonIcon $name attrs
  3147. }
  3148. can {set widget canvas}
  3149. chb {set widget ttk::checkbutton}
  3150. swi {
  3151. set widget ttk::checkbutton
  3152. #if {![my apaveTheme]} {
  3153. # set attrs "$attrs -style Switch.TCheckbutton"
  3154. #}
  3155. }
  3156. chB {set widget checkbutton}
  3157. cbx - fco {
  3158. set widget ttk::combobox
  3159. if {$nam3 eq {fco}} { ;# file content combobox
  3160. set attrs [FCfieldValues $wnamefull $attrs]
  3161. }
  3162. set attrs [FCfieldAttrs $wnamefull $attrs -tvar]
  3163. }
  3164. ent {set widget ttk::entry}
  3165. enT {set widget entry}
  3166. fil - fiL -
  3167. fis - fiS -
  3168. dir - diR -
  3169. fon - foN -
  3170. clr - clR -
  3171. dat - daT -
  3172. sta -
  3173. too -
  3174. fra {
  3175. # + frame for choosers and bars
  3176. set widget ttk::frame
  3177. }
  3178. frA {
  3179. set widget frame
  3180. if {$disabled} {set attrs [removeOptions $attrs -state]}
  3181. }
  3182. ftx {set widget ttk::labelframe}
  3183. gut {set widget canvas}
  3184. lab {
  3185. set widget ttk::label
  3186. if {$disabled} {
  3187. set grey lightgray
  3188. set attrs "-foreground $grey $attrs"
  3189. }
  3190. lassign [parseOptions $attrs -link {} -style {} -font {}] \
  3191. cmd style font
  3192. if {$cmd ne {}} {
  3193. set attrs "-linkcom {$cmd} $attrs"
  3194. set attrs [removeOptions $attrs -link]
  3195. }
  3196. if {$style eq {} && $font eq {}} {
  3197. set attrs "-font {$::radxide::dan(CHARFAMILY)} $attrs"
  3198. } elseif {$style ne {}} {
  3199. # some themes stumble at ttk styles, so bring their attrs directly
  3200. set attrs [removeOptions $attrs -style]
  3201. set attrs "[ttk::style configure $style] $attrs"
  3202. }
  3203. }
  3204. laB {set widget label}
  3205. lfr {set widget ttk::labelframe}
  3206. lfR {
  3207. set widget labelframe
  3208. if {$disabled} {set attrs [removeOptions $attrs -state]}
  3209. }
  3210. lbx - flb {
  3211. set widget listbox
  3212. if {$nam3 eq {flb}} { ;# file content listbox
  3213. set attrs [FCfieldValues $wnamefull $attrs]
  3214. }
  3215. set attrs "[FCfieldAttrs $wnamefull $attrs -lvar]"
  3216. set attrs "[ListboxesAttrs $wnamefull $attrs]"
  3217. AddPopupAttr $wnamefull attrs -entrypop 1
  3218. foreach {ev com} {Home {LbxSelect %w 0} End {LbxSelect %w end}} {
  3219. append attrs " -bindEC {<$ev> {$com}} "
  3220. }
  3221. }
  3222. meb {set widget ttk::menubutton}
  3223. meB {set widget menubutton}
  3224. nbk {
  3225. set widget ttk::notebook
  3226. set attrs "-notebazook {$attrs}"
  3227. }
  3228. opc {
  3229. # tk_optionCascade - example of "my method" widget
  3230. # arguments: vname items mbopts precom args
  3231. #set widget {tk_optionCascade}
  3232. #set imax [expr {min(4,[llength $attrs])}]
  3233. #for {set i 0} {$i<$imax} {incr i} {
  3234. # set atr [lindex $attrs $i]
  3235. # if {$i!=1} {
  3236. # lset attrs $i \{$atr\}
  3237. # } elseif {[llength $atr]==1 && [info exist $atr]} {
  3238. # lset attrs $i [set $atr] ;# items stored in a variable
  3239. # }
  3240. #}
  3241. }
  3242. pan {set widget ttk::panedwindow
  3243. if {[string first -w $attrs]>-1 && [string first -h $attrs]>-1} {
  3244. # important for panes with fixed (customized) dimensions
  3245. set attrs "-propagate {$options} $attrs"
  3246. }
  3247. }
  3248. pro {set widget ttk::progressbar}
  3249. rad {set widget ttk::radiobutton}
  3250. raD {set widget radiobutton}
  3251. sca {set widget ttk::scale}
  3252. scA {set widget scale}
  3253. sbh {set widget ttk::scrollbar}
  3254. sbH {set widget scrollbar}
  3255. sbv {set widget ttk::scrollbar}
  3256. sbV {set widget scrollbar}
  3257. scf {
  3258. # if {![namespace exists ::apave::sframe]} {
  3259. # namespace eval ::apave {
  3260. # source [file join $::apave::apaveDir sframe.tcl]
  3261. # }
  3262. # }
  3263. # # scrolledFrame - example of "my method" widget
  3264. # set widget {my scrolledFrame}
  3265. }
  3266. seh {set widget ttk::separator}
  3267. sev {set widget ttk::separator}
  3268. siz {set widget ttk::sizegrip}
  3269. spx - spX {
  3270. if {$nam3 eq {spx}} {set widget ttk::spinbox} {set widget spinbox}
  3271. lassign [::apave::parseOptions $attrs \
  3272. -command {} -com {} -from {} -to {}] cmd cmd2 from to
  3273. append cmd $cmd2
  3274. lassign [::apave::extractOptions attrs -tip {} -tooltip {}] t1 t2
  3275. set t2 "$t1$t2"
  3276. if {$from ne {} || $to ne {}} {
  3277. if {$t2 ne {}} {set t2 "\n $t2"}
  3278. set t2 " $from .. $to $t2"
  3279. }
  3280. if {$t2 ne {}} {set t2 "-tip {$t2}"}
  3281. append attrs " -onReturn {$UFF{$cmd} {$from} {$to}$UFF} $t2"
  3282. }
  3283. tbl { ;# tablelist
  3284. package require tablelist
  3285. set widget tablelist::tablelist
  3286. set attrs "[FCfieldAttrs $wnamefull $attrs -lvar]"
  3287. set attrs "[ListboxesAttrs $wnamefull $attrs]"
  3288. }
  3289. tex {set widget text
  3290. if {[getOption -textpop {*}$attrs] eq {}} {
  3291. AddPopupAttr $wnamefull attrs -textpop \
  3292. [expr {[getOption -rotext {*}$attrs] ne {}}] -- disabled
  3293. }
  3294. lassign [parseOptions $attrs -ro {} -readonly {} -rotext {} \
  3295. -gutter {} -gutterwidth 5 -guttershift 6] r1 r2 r3 g1 g2 g3
  3296. set b1 [expr [string is boolean -strict $r1]]
  3297. set b2 [expr [string is boolean -strict $r2]]
  3298. if {($b1 && $r1) || ($b2 && $r2) || \
  3299. ($r3 ne {} && !($b1 && !$r1) && !($b2 && !$r2))} {
  3300. set attrs "-takefocus 0 $attrs"
  3301. }
  3302. set attrs [removeOptions $attrs -gutter -gutterwidth -guttershift]
  3303. if {$g1 ne {}} {
  3304. set attrs "$attrs -gutter {-canvas $g1 -width $g2 -shift $g3}"
  3305. }
  3306. }
  3307. tre {
  3308. set widget ttk::treeview
  3309. foreach {ev com} {Home {TreSelect %w 0} End {TreSelect %w end}} {
  3310. append attrs " -bindEC {<$ev> {$com}} "
  3311. }
  3312. }
  3313. h_* {set widget ttk::frame}
  3314. v_* {set widget ttk::frame}
  3315. default {set widget $newtype}
  3316. }
  3317. #set attrs [GetMC $attrs]
  3318. if {$nam3 in {cbx ent enT fco spx spX}} {
  3319. # entry-like widgets need their popup menu
  3320. set clearcom [lindex [parseOptions $attrs -clearcom -] 0]
  3321. if {$clearcom eq {-}} {
  3322. AddPopupAttr $wnamefull attrs -entrypop 0 readonly disabled
  3323. }
  3324. }
  3325. if {[string first pack [string trimleft $pack]]==0} {
  3326. catch {
  3327. # try to expand -after option (if set as WidgetName instead widgetName)
  3328. if {[set i [lsearch -exact $pack {-after}]]>=0} {
  3329. set aft [lindex $pack [incr i]]
  3330. if {[regexp {^[A-Z]} $aft]} {
  3331. set aft [my $aft]
  3332. set pack [lreplace $pack $i $i $aft]
  3333. }
  3334. }
  3335. }
  3336. set options $pack
  3337. }
  3338. set options [string trim $options]
  3339. set attrs [list {*}$attrs]
  3340. return [list $widget $options $attrs $nam3 $disabled]
  3341. }
  3342. # ________________________ WidgetNameFull _________________________ #
  3343. proc WidgetNameFull {w name {an {}}} {
  3344. # Gets a full name of a widget.
  3345. # w - name of root widget
  3346. # name - name of widget
  3347. # an - additional prefix for name
  3348. # See also: apave::sframe::content
  3349. set wn [string trim [parentWName $name].$an[ownWName $name] .]
  3350. set wnamefull $w.$wn
  3351. set wcc canvas.container.content ;# sframe.tcl may be not sourced
  3352. if {[set i1 [string first .scf $wnamefull]]>0 && \
  3353. [set i2 [string first . $wnamefull $i1+1]]>0 && \
  3354. [string first .$wcc. $wnamefull]<0} {
  3355. # insert a container's name into a scrolled frame's child
  3356. set wend [string range $wnamefull $i2 end]
  3357. set wnamefull [string range $wnamefull 0 $i2]
  3358. append wnamefull $wcc $wend
  3359. }
  3360. return $wnamefull
  3361. }
  3362. # ________________________ Window _________________________ #
  3363. proc Window {w inplists} {
  3364. # Paves the window with widgets.
  3365. # w - window's name (path)
  3366. # inplists - list of widget items (lists of widget data)
  3367. # Contents of a widget's item:
  3368. # name - widget's name (first 3 characters define its type)
  3369. # neighbor - top (T) or left (L) neighbor of the widget
  3370. # posofnei - position of neighbor: T (top) or L (left)
  3371. # rowspan - row span of the widget
  3372. # colspan - column span of the widget
  3373. # options - grid/pack options
  3374. # attrs - attributes of widget
  3375. # First 3 items are mandatory, others are set at need.
  3376. # Called by *paveWindow* method to process a portion of widgets.
  3377. # The "portion" refers to a separate block of widgets such as
  3378. # notebook's tabs or frames.
  3379. namespace upvar ::radxide dan dan
  3380. #tk_messageBox -title $dan(TITLE) -icon info -message "Start Window!"
  3381. set lwidgets [list]
  3382. # comments be skipped
  3383. foreach lst $inplists {
  3384. if {[string index $lst 0] ne {#}} {
  3385. lappend lwidgets $lst
  3386. }
  3387. }
  3388. set lused [list]
  3389. set lwlen [llength $lwidgets]
  3390. if {$lwlen<2 && [string trim $lwidgets "{} "] eq {}} {
  3391. set lwidgets [list {fra - - - - {pack -padx 99 -pady 99}}]
  3392. set lwlen 1
  3393. }
  3394. for {set i 0} {$i < $lwlen} {} {
  3395. set lst1 [lindex $lwidgets $i]
  3396. if {[Replace_Tcl i lwlen lwidgets {*}$lst1] ne {}} {incr i}
  3397. }
  3398. # firstly, normalize all names that are "subwidgets" (.lab for fra.lab)
  3399. # also, "+" for previous neighbors
  3400. set i [set lwlen [llength $lwidgets]]
  3401. while {$i>1} {
  3402. incr i -1
  3403. set lst1 [lindex $lwidgets $i]
  3404. lassign $lst1 name neighbor
  3405. if {$neighbor eq {+}} {set neighbor [lindex $lwidgets $i-1 0]}
  3406. lassign [NormalizeName name i lwidgets] name wname
  3407. set neighbor [lindex [NormalizeName neighbor i lwidgets] 0]
  3408. set lst1 [lreplace $lst1 0 1 $wname $neighbor]
  3409. set lwidgets [lreplace $lwidgets $i $i $lst1]
  3410. }
  3411. for {set i 0} {$i < $lwlen} {} {
  3412. # List of widgets contains data per widget:
  3413. # widget's name,
  3414. # neighbor widget, position of neighbor (T, L),
  3415. # widget's rowspan and columnspan (both optional),
  3416. # grid options, widget's attributes (both optional)
  3417. set lst1 [lindex $lwidgets $i]
  3418. #set lst1 [my Replace_chooser w i lwlen lwidgets {*}$lst1]
  3419. #if {[set lst1 [my Replace_bar w i lwlen lwidgets {*}$lst1]] eq {}} {
  3420. # incr i
  3421. # continue
  3422. #}
  3423. lassign $lst1 name neighbor posofnei rowspan colspan options1 attrs1
  3424. lassign [NormalizeName name i lwidgets] name wname
  3425. set wname [MakeWidgetName $w $wname]
  3426. if {$colspan eq {} || $colspan eq {-}} {
  3427. set colspan 1
  3428. if {$rowspan eq {} || $rowspan eq {-}} {
  3429. set rowspan 1
  3430. }
  3431. }
  3432. foreach ao {attrs options} {
  3433. if {[catch {set $ao [uplevel 2 subst -nocommand -nobackslashes [list [set ${ao}1]]]}]} {
  3434. set $ao [set ${ao}1]
  3435. }
  3436. }
  3437. lassign [widgetType $wname $options $attrs] widget options attrs nam3 dsbl
  3438. # The type of widget (if defined) means its creation
  3439. # (if not defined, it was created after "makewindow" call
  3440. # and before "window" call)
  3441. if { !($widget eq {} || [winfo exists $widget])} {
  3442. set attrs [GetAttrs $attrs $nam3 $dsbl]
  3443. set attrs [ExpandOptions $attrs]
  3444. # for scrollbars - set up the scrolling commands
  3445. if {$widget in {ttk::scrollbar scrollbar}} {
  3446. set neighbor [lindex [LowercaseWidgetName $neighbor] 0]
  3447. set wneigb [WidgetNameFull $w $neighbor]
  3448. if {$posofnei eq {L}} {
  3449. $wneigb config -yscrollcommand "$wname set"
  3450. set attrs "$attrs -com \\\{$wneigb yview\\\}"
  3451. append options { -side right -fill y} ;# -after $wneigb"
  3452. } elseif {$posofnei eq {T}} {
  3453. $wneigb config -xscrollcommand "$wname set"
  3454. set attrs "$attrs -com \\\{$wneigb xview\\\}"
  3455. append options { -side bottom -fill x} ;# -before $wneigb"
  3456. }
  3457. set options [string map [list %w $wneigb] $options]
  3458. }
  3459. #% doctest 1
  3460. #% set a "123 \\\\\\\\ 45"
  3461. #% eval append b {*}$a
  3462. #% set b
  3463. #> 123\45
  3464. #> doctest
  3465. Pre attrs
  3466. #set addcomms [my AdditionalCommands $w $wname attrs]
  3467. eval $widget $wname {*}$attrs
  3468. #my Post $wname $attrs
  3469. #foreach acm $addcomms {{*}$acm}
  3470. # for buttons and entries - set up the hotkeys (Up/Down etc.)
  3471. #my DefineWidgetKeys $wname $widget
  3472. }
  3473. if {$neighbor eq {-} || $row < 0} {
  3474. set row [set col 0]
  3475. }
  3476. # check for simple creation of widget (without pack/grid)
  3477. if {$neighbor ne {#}} {
  3478. set options [GetIntOptions $w $options $row $rowspan $col $colspan]
  3479. set pack [string trim $options]
  3480. if {[string first add $pack]==0} {
  3481. set comm "[winfo parent $wname] add $wname [string range $pack 4 end]"
  3482. {*}$comm
  3483. } elseif {[string first pack $pack]==0} {
  3484. set opts [string trim [string range $pack 5 end]]
  3485. if {[string first forget $opts]==0} {
  3486. pack forget {*}[string range $opts 6 end]
  3487. } else {
  3488. pack $wname {*}$opts
  3489. }
  3490. } else {
  3491. grid $wname -row $row -column $col -rowspan $rowspan \
  3492. -columnspan $colspan -padx 1 -pady 1 {*}$options
  3493. }
  3494. }
  3495. lappend lused [list $name $row $col $rowspan $colspan]
  3496. if {[incr i] < $lwlen} {
  3497. lassign [lindex $lwidgets $i] name neighbor posofnei
  3498. set neighbor [lindex [LowercaseWidgetName $neighbor] 0]
  3499. set row -1
  3500. foreach cell $lused {
  3501. lassign $cell uname urow ucol urowspan ucolspan
  3502. if {[lindex [LowercaseWidgetName $uname] 0] eq $neighbor} {
  3503. set col $ucol
  3504. set row $urow
  3505. if {$posofnei eq {T} || $posofnei eq {}} {
  3506. incr row $urowspan
  3507. } elseif {$posofnei eq {L}} {
  3508. incr col $ucolspan
  3509. }
  3510. }
  3511. }
  3512. }
  3513. }
  3514. return $lwidgets
  3515. }
  3516. # ________________________ WindowStatus _________________________ #
  3517. proc WindowStatus {w name {val ""} {defval ""}} {
  3518. # Sets/gets a status of window. The status is a value assigned to a name.
  3519. # w - window's path
  3520. # name - name of status
  3521. # val - if blank, to get a value of status; otherwise a value to set
  3522. # defval - default value (actual if the status not set beforehand)
  3523. # Returns a value of status.
  3524. # See also: IntStatus
  3525. variable _AP_VARS
  3526. if {$val eq {}} { ;# getting
  3527. if {[info exist _AP_VARS($w,$name)]} {
  3528. return $_AP_VARS($w,$name)
  3529. }
  3530. return $defval
  3531. }
  3532. return [set _AP_VARS($w,$name) $val] ;# setting
  3533. }
  3534. # ________________________ WinResize _________________________ #
  3535. proc WinResize {win} {
  3536. # Restricts the window's sizes (thus fixing Tk's issue with a menubar)
  3537. # win - path to a window to be of restricted sizes
  3538. if {[$win cget -menu] ne {}} {
  3539. lassign [splitGeometry [wm geometry $win]] w h
  3540. lassign [wm minsize $win] wmin hmin
  3541. if {$w<$wmin && $h<$hmin} {
  3542. set corrgeom ${wmin}x$hmin
  3543. } elseif {$w<$wmin} {
  3544. set corrgeom ${wmin}x$h
  3545. } elseif {$h<$hmin} {
  3546. set corrgeom ${w}x$hmin
  3547. } else {
  3548. return
  3549. }
  3550. wm geometry $win $corrgeom
  3551. }
  3552. return
  3553. }
  3554. # ________________________ WinVarname _________________________ #
  3555. proc WinVarname {win} {
  3556. # Gets a unique varname for a window.
  3557. # win - window's path
  3558. return [namespace current]::PV(_WIN_,$win)
  3559. }
  3560. # ________________________ withdraw _________________________ #
  3561. proc withdraw {w} {
  3562. # Does 'withdraw' for a window.
  3563. # w - the window's path
  3564. # See also: iconifyOption
  3565. switch -- [iconifyOption] {
  3566. none { ; # no withdraw/deiconify actions
  3567. }
  3568. Linux { ; # do it for Linux
  3569. wm withdraw $w
  3570. }
  3571. Windows { ; # do it for Windows
  3572. wm withdraw $w
  3573. wm attributes $w -alpha 0.0
  3574. }
  3575. default { ; # do it depending on the platform
  3576. wm withdraw $w
  3577. if {[::radxide::iswindows]} {
  3578. wm attributes $w -alpha 0.0
  3579. }
  3580. }
  3581. }
  3582. }
  3583. # ________________________ #
  3584. }