WmDefault.tcl 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #
  4. # $Id: WmDefault.tcl,v 1.7 2008/03/17 22:47:00 hobbs Exp $
  5. #
  6. # Description: Package for making Tk apps use the CDE/KDE/Gnome/Windows scheme
  7. # Prefix: wm_default::
  8. # Url: http://tix.sourceforge.net/Tixapps/
  9. #
  10. # Usage:
  11. # It should be sufficient at the beginning of a wish app to simply:
  12. #
  13. # package require wm_default
  14. # wm_default::setup
  15. # wm_default::addoptions
  16. #
  17. # wm_default::setup takes an optional argument - the scheme if already
  18. # known, one of: windows gnome kde1 kde2 cde kde
  19. # wm_default::addoptions takes optional arguments - pairs of variables
  20. # and values to override the kde settings. e.g.
  21. # wm_default::addoptions -background blue
  22. #
  23. # Description:
  24. # package for making Tk apps look nice under CDE or KDE or Windows
  25. #
  26. # The stuff below attempts to use the options database and the
  27. # various files under ~/.dt, $DTHOME, and /usr/dt to figure out
  28. # the user's current font and color set. It then uses tk's
  29. # palette routines to set sensible defaults, and then override
  30. # some of the options to try to make them look like CDE.
  31. #
  32. # There really *must* be an easier way to get text background
  33. # colors and the radiobutton highlight colors out of the
  34. # options database or winfo atom... Unfortunately, I can't
  35. # figure out how...
  36. # This package is based on the cde package by D. J. Hagberg, Jr.:
  37. # dhagberg@glatmos.com
  38. ########################################################################
  39. #
  40. #
  41. # Copyright 1998 D. J. Hagberg, Jr. and Global Atmospherics, Inc.
  42. #
  43. # Permission to use, copy, modify, and distribute this software and its
  44. # documentation for any purpose and without fee is hereby granted, provided
  45. # that the above copyright notice appear in all copies.
  46. # D. J. Hagberg, Jr. and Global Atmospherics, Inc. make no representations
  47. # about the suitability of this software for any It is provided "as is"
  48. # without express or implied warranty. By use of this software the user
  49. # agrees to indemnify and hold harmless D. J. Hagberg, Jr. and Global
  50. # Atmospherics, Inc. from any claims or liability for loss arising out
  51. # of such use.
  52. ########################################################################
  53. package require Tk
  54. proc tixDetermineWM {} {
  55. # Returns one of cde kde1 kde2 gnome windows or ""
  56. global tcl_platform env
  57. set type ""
  58. if {$tcl_platform(platform) eq "windows"} {
  59. set type windows
  60. } else {
  61. # The most definitive way is to check the X atoms
  62. # I'm not sure if we can determine this using regular Tk wm calls
  63. # I don't want to intern these symbols if they're not there.
  64. if {![catch {exec xlsatoms} xatoms]} {
  65. if {[string match *GNOME_SESSION_CORBA_COOKIE* $xatoms]} {
  66. set type gnome
  67. } elseif {[string match *KDEChangeStyle* $xatoms]} {
  68. set type kde1
  69. } elseif {[string match *KDE_DESKTOP_WINDOW* $xatoms]} {
  70. set type kde2
  71. }
  72. }
  73. if {$type != ""} {
  74. # drop through
  75. } elseif {[info exists env(KDEDIR)] && [file isdir $env(KDEDIR)]} {
  76. # one or two?
  77. set type kde2
  78. } elseif {[info exists env(DTHOME)] && [file isdir $env(DTHOME)]} {
  79. set type cde
  80. } else {
  81. # Maybe look for other Unix window managers?
  82. # if {[file isfile $env(HOME)/.fwm2rc]} {}
  83. # if {[file isfile $env(HOME)/.fwmrc]} {}
  84. # if {[file isfile $env(HOME)/.twmrc]} {}
  85. # But twm and fwm don't color applications; mwm maybe?
  86. # Hope someone comes up with the code for openlook :-)
  87. return ""
  88. }
  89. }
  90. return $type
  91. }
  92. namespace eval ::wm_default {
  93. global tcl_platform env
  94. set _usetix [llength [info commands "tix"]]
  95. variable wm ""
  96. variable _frame_widgets {*Frame *Toplevel}
  97. #what about tixGrid?
  98. if {$_usetix} {
  99. lappend _frame_widgets *TixLabelFrame *TixButtonBox *TixCObjView \
  100. *TixListNoteBook *TixPanedWindow *TixStdButtonBox \
  101. *TixExFileSelectBox
  102. }
  103. variable _menu_font_widgets {*Menu *Menubutton}
  104. if {$_usetix} {lappend _menu_font_widgets *TixMenu}
  105. variable _button_font_widgets {*Button}
  106. variable _system_font_widgets {*Label \
  107. *Message \
  108. *Scale *Radiobutton *Checkbutton
  109. }
  110. if {$_usetix} {
  111. lappend _system_font_widgets \
  112. *TixBalloon*message *TixLabelFrame*Label \
  113. *TixControl*label *TixControl*Label \
  114. *TixLabelEntry*label *TixNoteBook.nbframe \
  115. *TixFileEntry*label *TixComboBox*label \
  116. *TixOptionMenu*menubutton *TixBitmapButton*label \
  117. *TixMwmClient*title *TixFileSelectBox*Label
  118. }
  119. variable _text_type_widgets {*Canvas *Entry *Listbox *Text}
  120. if {$_usetix} {
  121. lappend _text_type_widgets \
  122. *TixComboBox*Entry *TixControl*entry *TixScrolledHList*hlist \
  123. *TixDirTree*hlist *TixDirList*hlist *TixTree*hlist \
  124. *TixMultiList*Listbox *TixScrolledListBox*listbox \
  125. *TixFileEntry*Entry *TixLabelEntry*Entry \
  126. *TixFileEntry*entry *TixLabelEntry*entry \
  127. *TixScrolledTList*tlist *TixScrolledText*text \
  128. *TixHList *TixCheckList*hlist
  129. # These arent working yet
  130. lappend _text_type_widgets \
  131. *TixDirTree*f1 *TixDirList*f1 \
  132. *TixFileSelectBox*file*listbox \
  133. *TixFileSelectBox*directory*listbox \
  134. *TixExFileSelectBox*filelist*listbox
  135. }
  136. variable _insert_type_widgets {*Entry *Text}
  137. if {$_usetix} {
  138. lappend _insert_type_widgets \
  139. *TixControl*entry *TixComboBox*Entry
  140. }
  141. variable _select_type_widgets {*Checkbutton \
  142. *Radiobutton \
  143. *Menu}
  144. variable _active_borderwidth_widgets {*Button *Radiobutton *Checkbutton}
  145. # Other Widgets that are given a borderwidth of $wm_default::borderwidth
  146. variable _nonzero_borderwidth_widgets {}
  147. # Widgets that are given a borderwidth of 0
  148. # must not be *Entry
  149. variable _null_borderwidth_widgets {*Menubutton *Label}
  150. variable _scrollbar_widgets {}
  151. variable _scrollbar_widgets {*Scrollbar}
  152. if {$_usetix} {
  153. lappend _scrollbar_widgets \
  154. *TixTree*Scrollbar *TixDirTree*Scrollbar *TixDirList*Scrollbar \
  155. *TixScrolledTList*Scrollbar *TixScrolledListBox*Scrollbar \
  156. *TixScrolledHList*Scrollbar *TixMultiView*Scrollbar \
  157. *TixScrolledText*Scrollbar *TixScrolledWindow*Scrollbar \
  158. *TixCObjView*Scrollbar
  159. }
  160. proc debug {str} {
  161. if {[llength [info commands "tix"]] &&
  162. [string is true -strict [tix cget -debug]]} {
  163. puts $str
  164. }
  165. }
  166. # Return the array of what we have deduced
  167. proc getoptions {} {
  168. set retval {}
  169. set len [string length "::wm_default::"]
  170. foreach variable [lsort [info vars ::wm_default::*]] {
  171. if {[string match ::wm_default::_* $variable]} {continue}
  172. set key [string range $variable $len end]
  173. lappend retval $key [set $variable]
  174. }
  175. return $retval
  176. }
  177. # Print out the array of what we have deduced
  178. proc parray {} {
  179. set retval ""
  180. foreach {key val} [::wm_default::getoptions] {
  181. append retval [join [list $key $val]] "\n"
  182. }
  183. debug $retval
  184. return $retval
  185. }
  186. # Pick a default borderwidth in pixels
  187. set _bd 2
  188. # Pick a default font size in pixels
  189. set _screenheight [winfo screenheight .]
  190. if {$_screenheight < 500} {
  191. # for 800x600 or smaller
  192. set _pixel 10
  193. set _point 8
  194. # Pick a default borderwidth which smaller
  195. set _bd 1
  196. } elseif {$_screenheight < 800} {
  197. # for 1024x768
  198. set _pixel 12
  199. set _point 8
  200. } elseif {$_screenheight < 1100} {
  201. # for 1200x1000
  202. set _pixel 12
  203. set _point 8
  204. } else {
  205. set _pixel 12
  206. set _point 10
  207. }
  208. # setup defaults depending on the OS and Window Manager
  209. # Really should do another version for mono
  210. if {$tcl_platform(platform) eq "windows"} {
  211. if {$tcl_platform(osVersion) < 5} {
  212. set _prop_default "MS Sans Serif"
  213. } else {
  214. set _prop_default "Tahoma"
  215. }
  216. # make sure this font is installed
  217. set _allowed [string tolow [font families]]
  218. foreach font [list $_prop_default "MS Sans Serif" Tahoma Arial System] {
  219. if {[lsearch -exact $_allowed [string tolow $font]] > -1} {
  220. set _prop_default $font
  221. break
  222. }
  223. }
  224. set _fixed_default {Courier New}
  225. # make sure this font is installed
  226. foreach font [list $_fixed_default Courier System] {
  227. if {[lsearch -exact $_allowed [string tolow $font]] > -1} {
  228. set _fixed_default $font
  229. break
  230. }
  231. }
  232. # Windows colors:
  233. # "3dDarkShadow", COLOR_3DDKSHADOW,
  234. # "3dLight", COLOR_3DLIGHT,
  235. # "ActiveBorder", COLOR_ACTIVEBORDER,
  236. # "ActiveCaption", COLOR_ACTIVECAPTION,
  237. # "AppWorkspace", COLOR_APPWORKSPACE,
  238. # "Background", COLOR_BACKGROUND,
  239. # "ButtonFace", COLOR_BTNFACE,
  240. # "ButtonHighlight", COLOR_BTNHIGHLIGHT,
  241. # "ButtonShadow", COLOR_BTNSHADOW,
  242. # "ButtonText", COLOR_BTNTEXT,
  243. # "CaptionText", COLOR_CAPTIONTEXT,
  244. # "DisabledText", COLOR_GRAYTEXT,
  245. # "GrayText", COLOR_GRAYTEXT,
  246. # "Highlight", COLOR_HIGHLIGHT,
  247. # "HighlightText", COLOR_HIGHLIGHTTEXT,
  248. # "InactiveBorder", COLOR_INACTIVEBORDER,
  249. # "InactiveCaption", COLOR_INACTIVECAPTION,
  250. # "InactiveCaptionText", COLOR_INACTIVECAPTIONTEXT,
  251. # "InfoBackground", COLOR_INFOBK,
  252. # "InfoText", COLOR_INFOTEXT,
  253. # "Menu", COLOR_MENU,
  254. # "MenuText", COLOR_MENUTEXT,
  255. # "Scrollbar", COLOR_SCROLLBAR,
  256. # "Window", COLOR_WINDOW,
  257. # "WindowFrame", COLOR_WINDOWFRAME,
  258. # "WindowText", COLOR_WINDOWTEXT,
  259. variable \
  260. background "SystemButtonFace" \
  261. foreground "SystemButtonText" \
  262. disabledforeground "SystemDisabledText" \
  263. disabledbackground "SystemButtonShadow" \
  264. textfamily $_prop_default \
  265. systemfamily $_prop_default \
  266. menufamily $_prop_default \
  267. fixedfamily $_fixed_default \
  268. fontsize $_point \
  269. textbackground "SystemWindow" \
  270. textforeground "SystemWindowText" \
  271. disabledtextbackground "SystemDisabledText" \
  272. selectbackground "SystemHighlight" \
  273. selectforeground "SystemHighlightText" \
  274. selectcolor "SystemWindow" \
  275. highlightcolor "SystemWindowFrame" \
  276. highlightbackground "SystemButtonFace" \
  277. scrollbars "SystemScrollbar" \
  278. borderwidth $_bd \
  279. menubackground "SystemMenu" \
  280. menuforeground "SystemMenuText"
  281. variable highlightthickness 1
  282. # Windows does not have an activebackground, but Tk does
  283. variable activebackground $background
  284. variable activeforeground $foreground
  285. } else {
  286. # intended for Unix
  287. # Tk uses the following defaults:
  288. #define NORMAL_BG "#d9d9d9"
  289. #define ACTIVE_BG "#ececec"
  290. #define SELECT_BG "#c3c3c3"
  291. #define TROUGH "#c3c3c3"
  292. #define INDICATOR "#b03060"
  293. #define DISABLED "#a3a3a3"
  294. # We know . exists and it has a background
  295. # This should be "#d9d9d9" under default Tk
  296. set _bg [. cget -background]
  297. set _prop_default helvetica
  298. # make sure this font is installed
  299. set _allowed [string tolow [font families]]
  300. foreach font [list $_prop_default times fixed] {
  301. if {[lsearch -exact $_allowed [string tolow $font]] > -1} {
  302. set _prop_default $font
  303. break
  304. }
  305. }
  306. set _fixed_default courier
  307. # make sure this font is installed
  308. foreach font [list $_fixed_default fixed] {
  309. if {[lsearch -exact $_allowed [string tolow $font]] > -1} {
  310. set _fixed_default $font
  311. break
  312. }
  313. }
  314. variable \
  315. background $_bg \
  316. foreground Black \
  317. disabledforeground #808080 \
  318. disabledbackground #a3a3a3 \
  319. textfamily $_prop_default \
  320. systemfamily $_prop_default \
  321. menufamily $_prop_default \
  322. fixedfamily $_fixed_default \
  323. fontsize $_pixel \
  324. textbackground white \
  325. textforeground Black \
  326. disabledtextbackground $_bg \
  327. selectbackground #000080 \
  328. selectforeground white \
  329. selectcolor yellow \
  330. highlightcolor Black \
  331. highlightbackground $_bg \
  332. scrollbars "#c3c3c3" \
  333. borderwidth $_bd \
  334. menubackground $_bg \
  335. menuforeground Black
  336. variable highlightthickness 1
  337. # Windows does not have an activebackground, but Tk does
  338. variable activebackground "#ececec"
  339. variable activeforeground $foreground
  340. }
  341. # priority should be userDefault?
  342. if {$_usetix} {
  343. variable priority [tix cget -schemepriority]
  344. } else {
  345. variable priority 75
  346. }
  347. # variables that will be derived during addoptions - set to null for now
  348. variable system_font {}
  349. variable menu_font {}
  350. variable fixed_font {}
  351. variable text_font {}
  352. # Different desktops have different visible regions
  353. # This is not working properly yet.
  354. variable geometry 0+0+[winfo screenwidth .]+$_screenheight
  355. # Different desktops have different focusmodels: clicktofocus or
  356. # followsmouse This is not working properly yet
  357. variable focusmodel clicktofocus
  358. # Some desktops have standardized link colors
  359. # This is not working properly yet
  360. variable linkcolor "#0000ff" vlinkcolor "#800000" alinkcolor "#800080"
  361. proc default {args} {
  362. # Override the defaults with any optional arguments
  363. foreach {var val} $args {
  364. set $var $val
  365. }
  366. }
  367. proc setup {{type ""}} {
  368. # type is one of the recognized window managers
  369. # one of: cde kde win
  370. global tcl_platform env
  371. if {$type == ""} {
  372. if {[set type [::tixDetermineWM]] == ""} {
  373. set ::wm_default::wm ""
  374. # Generic unix
  375. return
  376. }
  377. }
  378. setup-$type
  379. set ::wm_default::wm $type
  380. # todo - make the menubutton enter and leave events more compatible
  381. }
  382. proc setup-windows {args} {
  383. # Already done by Tk above.
  384. # Should find out the useable window region
  385. }
  386. proc setup-gnome {args} {
  387. # GNOME is still barely supported because of the difficulty
  388. # of finding and parsing sawfish definition files.
  389. # First you have to find what window manager, then what theme,
  390. # then find the files, then parse them according to each Wm's syntax.
  391. global env
  392. set bg $wm_default::background
  393. set fg $wm_default::foreground
  394. set txtFont $wm_default::textfamily
  395. set btnFont $wm_default::systemfamily
  396. debug "Setting up Gnome environment"
  397. set file ~/.gnome/theme-switcher-capplet
  398. if {![file exists $file] || \
  399. [catch {open $file} fd] || $fd == ""} {
  400. debug "Skipping $file"
  401. } else {
  402. debug "Reading $file"
  403. set contents [read $fd]
  404. catch {close $fd}
  405. if {![regexp -- "use_theme_font=true" $contents]} {
  406. # not activated
  407. } elseif {[regexp -- "\nfont=(\[-a-zA-Z0-9,\]+)" $contents \
  408. foo font]} {
  409. set_unix_font $font
  410. }
  411. }
  412. }
  413. proc set_unix_font {font} {
  414. set list [split $font "-"]
  415. set font [lindex $list 2]
  416. set font [string tolow $font]
  417. if {$font != "" && [lsearch -exact [font families] $font] > -1} {
  418. set wm_default::textfamily $font
  419. debug "Setting textfamily to $font"
  420. set wm_default::systemfamily $font
  421. set wm_default::menufamily $font
  422. } else {
  423. debug "Unable to set font: '$list'"
  424. }
  425. if {[set size [lindex $list 7]] != "" && \
  426. [string is integer -strict $size]} {
  427. debug "Setting fontsize to '$size'"
  428. set wm_default::fontsize $size
  429. } elseif {[set size [lindex $list 8]] != "" && \
  430. [string is integer -strict $size]} {
  431. if {$size > 100} {set size [expr {$size / 10}]}
  432. debug "Setting fontsize to '$size'"
  433. set wm_default::fontsize $size
  434. } else {
  435. debug "Unable to set fontsize: '$list'"
  436. }
  437. }
  438. # Common to KDE1 and KDE2
  439. proc setup-kde {args} {
  440. global env
  441. set file ~/.kderc
  442. if {![file exists $file] || [catch {open $file} fd] || $fd == ""} {
  443. debug "Skipping $file"
  444. } else {
  445. debug "Reading $file"
  446. set contents [read $fd]
  447. catch {close $fd}
  448. if {[regexp -- "\nfixedfamily=(\[-a-zA-Z0-9, \]+)" $contents \
  449. foo font]} {
  450. set list [split $font ","]
  451. set font [lindex $list 0]
  452. set wm_default::fixedfamily $font
  453. debug "Setting fixedfamily to $font"
  454. }
  455. if {[regexp -- "\nfont=(\[-a-zA-Z0-9, \]+)" $contents \
  456. foo font]} {
  457. set list [split $font ","]
  458. set font [lindex $list 0]
  459. set wm_default::textfamily $font
  460. debug "Setting textfamily to $font"
  461. set wm_default::systemfamily $font
  462. set wm_default::menufamily $font
  463. }
  464. }
  465. }
  466. proc setup-kde1 {args} {
  467. # Shortcut for the moment
  468. return [eval setup-kde $args]
  469. }
  470. proc set-kde2-color {str contents var} {
  471. if {[regexp -- "\n${str}=(\[0-9,\]+)" $contents -> color]} {
  472. set color [eval [list format "#%02x%02x%02x"] [split $color ","]]
  473. set ::wm_default::$var $color
  474. debug "setting $var to $color"
  475. }
  476. }
  477. proc setup-kde2 {args} {
  478. global env
  479. set bg $wm_default::background
  480. set fg $wm_default::foreground
  481. set txtFont $wm_default::textfamily
  482. set btnFont $wm_default::systemfamily
  483. debug "Setting up KDE environment"
  484. # Look for system the user settings
  485. set dirs ~/.kde
  486. if {[info exists env(KDEDIR)] && [file isdir $env(KDEDIR)]} {
  487. lappend dirs $env(KDEDIR)
  488. }
  489. # read them sequentially and overwrite the previous values
  490. foreach dir $dirs {
  491. set file $dir/share/config/kdeglobals
  492. if {![file exists $file] || [catch {open $file} fd] || $fd == ""} {
  493. debug "Skipping $file"
  494. } else {
  495. debug "Reading $file"
  496. set contents [read $fd]
  497. catch {close $fd}
  498. set-kde2-color background $contents background
  499. set-kde2-color foreground $contents foreground
  500. set-kde2-color selectBackground $contents selectbackground
  501. set-kde2-color selectForeground $contents selectforeground
  502. set-kde2-color windowBackground $contents textbackground
  503. set-kde2-color visitedLinkColor $contents vlinkcolor
  504. set-kde2-color linkColor $contents linkcolor
  505. if {[regexp -- "\nactiveFont=(\[-a-zA-Z0-9, \]+)" $contents \
  506. foo font]} {
  507. set list [split $font ","]
  508. set font [lindex $list 0]
  509. set wm_default::textfamily $font
  510. set size [lindex $list 1]
  511. if {[string is integer -strict $size]} {
  512. set wm_default::fontsize $size
  513. }
  514. debug "Setting textfamily to $font"
  515. set wm_default::systemfamily $font
  516. set wm_default::menufamily $font
  517. }
  518. }
  519. # should pick up visitedLinkColor
  520. set file $dir/share/config/kwmrc
  521. if {![file exists $file] || [catch {open $file} fd] || $fd == ""} {
  522. debug "Skipping $file"
  523. } else {
  524. debug "Reading $file"
  525. set contents [read $fd]
  526. catch {close $fd}
  527. if {[regexp -- "\nDesktop1Region=(\[0-9+\]+)" $contents \
  528. foo region]} {
  529. set wm_default::geometry $region
  530. debug "Setting geometry to $region"
  531. }
  532. if {[regexp -- "\nFocusPolicy=ClickToFocus" $contents \
  533. foo region]} {
  534. set wm_default::focusmodel clicktofocus
  535. debug "Setting focusmodel to clicktofocus"
  536. } else {
  537. # followsmouse
  538. }
  539. }
  540. }
  541. return [eval setup-kde $args]
  542. }
  543. proc setup-cde {args} {
  544. namespace import wm_default::*
  545. set bg $wm_default::background
  546. set fg $wm_default::foreground
  547. set txtFont $wm_default::textfamily
  548. set sysFont $wm_default::systemfamily
  549. debug "Setting up CDE environment"
  550. # if any of these options are missing, we must not be under CDE
  551. set txtFont [option get . textfamilyList textfamilyList]
  552. set sysFont [option get . systemfamilyList systemfamilyList]
  553. if {$txtFont ne "" && $sysFont ne ""} {
  554. set txtFont [lindex [split $txtFont :] 0]
  555. set sysFont [lindex [split $sysFont :] 0]
  556. if {$txtFont ne ""} {set textfamily $txtFont}
  557. if {$sysFont ne ""} {set systemfamily $sysFont}
  558. #
  559. # If we can find the user's dt.resources file, we can find out the
  560. # palette and text background/foreground colors
  561. #
  562. set txtBg $bg
  563. set txtFg $fg
  564. set selFg $selectforeground
  565. set selBg $selectbackground
  566. set selCol $selectcolor
  567. set fh ""
  568. set palf ""
  569. set cur_rsrc ~/.dt/sessions/current/dt.resources
  570. set hom_rsrc ~/.dt/sessions/home/dt.resources
  571. if {[file readable $cur_rsrc] && [file readable $hom_rsrc]} {
  572. if {[file mtime $cur_rsrc] > [file mtime $hom_rsrc]} {
  573. if {[catch {open $cur_rsrc r} fh]} {set fh ""}
  574. } else {
  575. if {[catch {open $hom_rsrc r} fh]} {set fh ""}
  576. }
  577. } elseif {[file readable $cur_rsrc]} {
  578. if {[catch {open $cur_rsrc r} fh]} {set fh ""}
  579. } elseif {[file readable $hom_rsrc]} {
  580. if {[catch {open $hom_rsrc r} fh]} {set fh ""}
  581. }
  582. if {[string length $fh] > 0} {
  583. while {[gets $fh ln] != -1} {
  584. regexp -- "^\\*0\\*ColorPalette:\[ \t]*(.*)\$" $ln nil palf
  585. regexp -- "^Window.Color.Background:\[ \t]*(.*)\$" $ln nil txtBg
  586. regexp -- "^Window.Color.Foreground:\[ \t]*(.*)\$" $ln nil txtFg
  587. }
  588. catch {close $fh}
  589. if {$txtBg ne $bg} {
  590. set selBg $txtFg
  591. set selFg $txtBg
  592. }
  593. }
  594. #
  595. # If the *0*ColorPalette setting was found above, try to find the
  596. # indicated file in ~/.dt, $DTHOME, or /usr/dt. The 3rd line in the
  597. # file will be the radiobutton/checkbutton selectColor.
  598. #
  599. if {[string length $palf]} {
  600. set dtdir /usr/dt
  601. if [info exists env(DTHOME)] {
  602. set dtdir $env(DTHOME)
  603. }
  604. if {[file readable ~/.dt/palettes/$palf]} {
  605. set palf ~/.dt/palettes/$palf
  606. } elseif {[file readable $dtdir/palettes/$palf]} {
  607. set palf $dtdir/palettes/$palf
  608. } else {
  609. set palf ""
  610. }
  611. if {[string length $palf]} {
  612. if {![catch {open $palf r} fh]} {
  613. # selectColor will be the 3rd line in the file --
  614. set ln ""; catch {gets $fh; gets $fh; gets $fh ln}
  615. set ln [string trim $ln]
  616. if {[string length $ln]} {set selCol $ln}
  617. close $fh
  618. }
  619. }
  620. }
  621. set wm_default::background $bg
  622. set wm_default::foreground $fg
  623. set wm_default::textfamily $txtFont
  624. set wm_default::systemfamily $sysFont
  625. set wm_default::menufamily $sysFont
  626. set wm_default::textbackground $txtBg
  627. set wm_default::textforeground $txtFg
  628. set wm_default::selectbackground $selBg
  629. set wm_default::selectforeground $selFg
  630. set wm_default::selectcolor $selCol
  631. }
  632. }
  633. proc derivefonts {} {
  634. global tcl_platform env
  635. # variables that will be derived
  636. variable system_font
  637. variable menu_font
  638. variable fixed_font
  639. variable text_font
  640. #
  641. # Set default fonts
  642. #
  643. global tcl_platform env
  644. switch -exact -- $tcl_platform(platform) windows {
  645. set system_font [list $::wm_default::systemfamily $::wm_default::fontsize]
  646. set menu_font [list $::wm_default::menufamily $::wm_default::fontsize]
  647. set text_font [list $::wm_default::textfamily $::wm_default::fontsize]
  648. set fixed_font [list $::wm_default::fixedfamily $::wm_default::fontsize]
  649. } default {
  650. set system_font [list $::wm_default::systemfamily -$::wm_default::fontsize]
  651. if {[set type $::wm_default::wm] == ""} {
  652. # Generic unix
  653. # some Unix Wms seem to make Menu fonts bold - ugly IMHO
  654. set menu_font [list $::wm_default::menufamily -$::wm_default::fontsize bold]
  655. } else {
  656. # gnome kde1 kde2 cde kde don't
  657. set menu_font [list $::wm_default::menufamily -$::wm_default::fontsize]
  658. }
  659. set text_font [list $::wm_default::textfamily -$::wm_default::fontsize]
  660. set fixed_font [list $::wm_default::fixedfamily -$::wm_default::fontsize]
  661. }
  662. }
  663. proc addoptions {args} {
  664. global tcl_platform env tix_version
  665. # variables that will be derived
  666. variable system_font
  667. variable menu_font
  668. variable fixed_font
  669. variable text_font
  670. if {[info commands "tix"] != ""} {set _usetix 1} {set _usetix 0}
  671. # Override what you have found with any optional arguments
  672. foreach {var val} $args {
  673. set var [string trimleft $var "-"]
  674. set ::wm_default::$var $val
  675. }
  676. set pri $::wm_default::priority
  677. # If you are running under Tix, set the colorscheme now
  678. # The options below will then override the Tix settings
  679. if {$_usetix} {
  680. # Tix's focus model is very non-standard
  681. bind TixComboBox <FocusIn> ""
  682. bind TixComboBox <FocusOut> ""
  683. if {$tix_version < "8.2"} {
  684. # works??
  685. option add *TixNoteBook.nbframe.inactiveBackground \
  686. $::wm_default::disabledbackground $pri
  687. } else {
  688. # works??
  689. option add *TixNoteBook.nbframe.inactiveBackground \
  690. $::wm_default::background $pri
  691. }
  692. # works??
  693. option add *TixPanedWindow.seperatorBg \
  694. $::wm_default::disabledbackground $pri
  695. option add *TixPanedWindow.handleBg \
  696. $::wm_default::disabledbackground $pri
  697. # works??
  698. option add *TixPanedWindow.separatorActiveBg \
  699. $::wm_default::activebackground $pri
  700. option add *TixPanedWindow.handleActiveBg \
  701. $::wm_default::activebackground $pri
  702. option add *TixPanedWindow.Background \
  703. $::wm_default::disabledbackground $pri
  704. # works??
  705. option add *TixResizeHandle*background \
  706. $::wm_default::disabledbackground $pri
  707. }
  708. foreach pref $wm_default::_frame_widgets {
  709. option add $pref.background $::wm_default::background $pri
  710. }
  711. option add *Background $::wm_default::background $pri
  712. derivefonts
  713. # Set the global defaults to the system font
  714. foreach pref [list *Font *font] {
  715. option add $pref $system_font $pri
  716. }
  717. # Set the "system" type defaults to the system font
  718. foreach pref $wm_default::_menu_font_widgets {
  719. option add $pref.font $menu_font $pri
  720. }
  721. foreach pref $wm_default::_button_font_widgets {
  722. option add $pref.font $system_font $pri
  723. option add $pref.disabledForeground $::wm_default::disabledforeground $pri
  724. option add $pref.background $::wm_default::background $pri
  725. option add $pref.foreground $::wm_default::foreground $pri
  726. option add $pref.highlightBackground $::wm_default::highlightbackground $pri
  727. }
  728. foreach pref $wm_default::_system_font_widgets {
  729. option add $pref.font $system_font $pri
  730. option add $pref.background $::wm_default::background $pri
  731. option add $pref.foreground $::wm_default::foreground $pri
  732. option add $pref.highlightBackground $::wm_default::highlightbackground $pri
  733. }
  734. foreach pref $wm_default::_text_type_widgets {
  735. option add $pref.font $text_font $pri
  736. option add $pref.relief sunken $pri
  737. option add $pref.borderWidth $::wm_default::borderwidth $pri
  738. option add $pref.background $::wm_default::textbackground $pri
  739. option add $pref.foreground $::wm_default::textforeground $pri
  740. option add $pref.selectBackground $::wm_default::selectbackground $pri
  741. option add $pref.selectForeground $::wm_default::selectforeground $pri
  742. option add $pref.highlightThickness $::wm_default::highlightthickness $pri
  743. option add $pref.disabledBackground $::wm_default::disabledtextbackground $pri
  744. }
  745. foreach pref $wm_default::_insert_type_widgets {
  746. option add $pref.relief sunken $pri
  747. option add $pref.insertBackground $::wm_default::textforeground $pri
  748. option add $pref.highlightThickness $::wm_default::highlightthickness $pri
  749. }
  750. #
  751. # Set the Selector color for radiobuttons, checkbuttons, et. al
  752. #
  753. foreach pref $wm_default::_select_type_widgets {
  754. option add $pref.selectColor $::wm_default::selectcolor $pri
  755. option add $pref.background $::wm_default::background $pri
  756. option add $pref.foreground $::wm_default::foreground $pri
  757. option add $pref.activeBackground $::wm_default::activebackground $pri
  758. option add $pref.activeForeground $::wm_default::activeforeground $pri
  759. }
  760. # Set the "active" defaults - this could be controversial
  761. foreach pref $wm_default::_menu_font_widgets {
  762. option add $pref.activeBackground $::wm_default::activebackground $pri
  763. option add $pref.activeForeground $::wm_default::activeforeground $pri
  764. option add $pref.background $::wm_default::background $pri
  765. option add $pref.foreground $::wm_default::foreground $pri
  766. option add $pref.disabledForeground $::wm_default::disabledforeground $pri
  767. option add $pref.highlightThickness $::wm_default::highlightthickness $pri
  768. }
  769. switch -exact -- $tcl_platform(platform) windows {
  770. # Make sure this is set to foreground - check marks on menus
  771. set _menu_select_color $::wm_default::foreground
  772. } default {
  773. # On unix there are recessed check boxes not check marks
  774. set _menu_select_color $::wm_default::selectcolor
  775. }
  776. option add *Menu.selectColor $_menu_select_color $pri
  777. if {$_usetix} {
  778. option add *TixMenu.selectColor $_menu_select_color $pri
  779. option add *TixBalloon*message.background $::wm_default::textbackground $pri
  780. }
  781. # Windows does not have an activebackground, but Tk does
  782. foreach pref $wm_default::_button_font_widgets {
  783. option add $pref.activeBackground $::wm_default::activebackground $pri
  784. option add $pref.activeForeground $::wm_default::activeforeground $pri
  785. }
  786. #
  787. # Set the default *button borderwidth
  788. #
  789. # option add *.borderWidth $::wm_default::borderwidth $pri
  790. foreach pref $wm_default::_active_borderwidth_widgets {
  791. option add $pref.activeBorderWidth $::wm_default::borderwidth $pri
  792. option add $pref.borderWidth $::wm_default::borderwidth $pri
  793. }
  794. foreach pref $wm_default::_nonzero_borderwidth_widgets {
  795. option add $pref.borderWidth $::wm_default::borderwidth $pri
  796. }
  797. foreach pref $wm_default::_null_borderwidth_widgets {
  798. option add $pref.borderWidth 0 $pri
  799. }
  800. if {$_usetix} {
  801. if {$tix_version < "8.2"} {
  802. option add *TixNoteBook.nbframe.inactiveBackground \
  803. $::wm_default::disabledbackground $pri
  804. option add *TixNoteBook*nbframe.inactiveBackground \
  805. $::wm_default::disabledbackground $pri
  806. } else {
  807. option add *TixNoteBook.nbframe.inactiveBackground \
  808. $::wm_default::background $pri
  809. option add *TixNoteBook*nbframe.inactiveBackground \
  810. $::wm_default::background $pri
  811. }
  812. }
  813. foreach pref $wm_default::_scrollbar_widgets {
  814. option add $pref.background $::wm_default::background $pri
  815. option add $pref.foreground $::wm_default::foreground $pri
  816. # Tix 8.1.1 had these wrong
  817. option add $pref.troughColor $::wm_default::scrollbars $pri
  818. option add $pref.borderWidth $::wm_default::borderwidth $pri
  819. }
  820. option add *Scale.borderWidth $::wm_default::borderwidth $pri
  821. option add *Scale.troughColor $::wm_default::scrollbars $pri
  822. option add *highlightColor $::wm_default::highlightcolor $pri
  823. option add *highlightBackground $::wm_default::highlightbackground $pri
  824. option add *HighlightBackground $::wm_default::highlightbackground $pri
  825. # not _system_font_widgets
  826. set _focus_widgets [concat \
  827. $::wm_default::_frame_widgets \
  828. $::wm_default::_menu_font_widgets \
  829. $::wm_default::_text_type_widgets \
  830. $::wm_default::_insert_type_widgets \
  831. $::wm_default::_select_type_widgets \
  832. $::wm_default::_active_borderwidth_widgets \
  833. $::wm_default::_nonzero_borderwidth_widgets \
  834. $::wm_default::_null_borderwidth_widgets ]
  835. if {$_usetix} {
  836. set _tix_hl_widgets [list *TixBitmapButton*label \
  837. *TixComboBox*Entry \
  838. *TixControl*entry \
  839. *TixDirList*hlist \
  840. *TixDirTree*hlist \
  841. *TixFileEntry*Entry \
  842. *TixFileEntry*entry \
  843. *TixMultiList*Listbox \
  844. *TixNoteBook.nbframe \
  845. *TixOptionMenu*menubutton \
  846. *TixScrolledHList*hlist \
  847. *TixScrolledListBox*listbox\
  848. *TixScrolledTList*tlist \
  849. *TixTree*hlist]
  850. eval lappend _focus_widgets $_tix_hl_widgets
  851. }
  852. foreach pref [lsort -uniq $_focus_widgets] {
  853. option add $pref.highlightBackground $::wm_default::highlightbackground $pri
  854. }
  855. # Now for some things to make it look more like the WM
  856. # todo - look for and call
  857. if {$::wm_default::focusmodel eq "followsmouse"} {
  858. tk_focusFollowsMouse
  859. }
  860. if {$_usetix} {
  861. tixSetDefaultOptions
  862. if {[lsearch -exact {windows kde1 kde2} $::wm_default::wm] > -1} {
  863. # Fix the way Button boxes are packed
  864. if {![llength [info procs ::tixButtonBox:add]]} {
  865. uplevel #0 auto_load tixButtonBox
  866. }
  867. proc ::tixButtonBox:add {w name args} {
  868. upvar #0 $w data
  869. eval [linsert $args 0 button $w.$name]
  870. if {![info exists data(-padx)]} {set data(-padx) 5}
  871. if {![info exists data(-pady)]} {set data(-pady) 10}
  872. if {$data(-orientation) eq "horizontal"} {
  873. # Push the Buttons to the right
  874. if {[info commands $w.pad] == ""} {
  875. label $w.pad
  876. pack $w.pad -side left -expand yes -fill both
  877. }
  878. pack $w.$name -side left \
  879. -expand no \
  880. -padx $data(-padx) -pady $data(-pady)
  881. } else {
  882. pack $w.$name -side top \
  883. -expand no -fill x \
  884. -padx $data(-padx) -pady $data(-pady)
  885. }
  886. lappend data(g:buttons) $name
  887. set data(w:$name) $w.$name
  888. return $w.$name
  889. }
  890. option add *TixButtonBox.relief flat $::wm_default::priority
  891. option add *TixButtonBox.borderwidth 2 $::wm_default::priority
  892. }
  893. }
  894. return [getoptions]
  895. }
  896. namespace export setup addoptions getoptions parray
  897. }
  898. package provide wm_default 1.0
  899. proc tixSetDefaultOptions {} {
  900. # Returns one of cde kde1 kde2 gnome windows or ""
  901. global tcl_platform env tixOption
  902. # There is no overlap between the wm_default variable names and
  903. # the old style tixOption names. So we can add the wm_default variable
  904. # names to the array tixOption, and allow people to upgrade in time.
  905. foreach variable {
  906. wm
  907. linkcolor
  908. vlinkcolor
  909. alinkcolor
  910. background
  911. foreground
  912. disabledforeground
  913. disabledbackground
  914. textfamily
  915. systemfamily
  916. menufamily
  917. fixedfamily
  918. fontsize
  919. textbackground
  920. textforeground
  921. disabledtextbackground
  922. selectbackground
  923. selectforeground
  924. selectcolor
  925. highlightcolor
  926. highlightbackground
  927. scrollbars
  928. borderwidth
  929. priority
  930. menubackground
  931. menuforeground
  932. activebackground
  933. activeforeground
  934. system_font
  935. menu_font
  936. fixed_font
  937. text_font
  938. } {
  939. set tixOption($variable) [set ::wm_default::$variable]
  940. }
  941. }