win.tcl 132 KB

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