win.tcl 136 KB

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