win.tcl 132 KB

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