win.tcl 129 KB

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