GDB (API)
/home/stan/gdb/src/gdb/gdbtk/library/prefs.tcl
Go to the documentation of this file.
00001 # Local preferences functions for Insight.
00002 # Copyright (C) 1997-2012 Red Hat, Inc.
00003 #
00004 # This program is free software; you can redistribute it and/or modify it
00005 # under the terms of the GNU General Public License (GPL) as published by
00006 # the Free Software Foundation; either version 2 of the License, or (at
00007 # your option) any later version.
00008 #
00009 # This program is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU General Public License for more details.
00013 
00014 
00015 # On STARTUP:
00016 # 1. Options database (.Xdefaults on Unix  or ? on Windows) is read
00017 # 2. GDB prefs file is read ("gdbtk.ini" on Windows; ".gdbtkinit" on Unix)
00018 # 3. GDB init script is read
00019 #
00020 # Normally all preferences will be set in the prefs file, which is
00021 # a generated file.  Hand-editing, if necessary, should be done to the
00022 # GDB init script.
00023 #
00024 # when "save options" is selected, the contents of the
00025 # preferences array is written out to the GDB prefs file.
00026 #
00027 # Usage:
00028 #   pref_save
00029 #   pref_read
00030 # ----------------------------------------------------------------------
00031 #
00032 
00033 proc pref_read {} {
00034   global prefs_init_filename env gdb_ImageDir GDBTK_LIBRARY GDBStartup
00035   global gdbtk_platform
00036 
00037   if {[info exists env(HOME)]} {
00038     if {$gdbtk_platform(os) == "cygwin"} {
00039       set home [ide_cygwin_path to_win32 $env(HOME)]
00040     } else {
00041       set home $env(HOME)
00042     }
00043   } else {
00044     set home ""
00045   }
00046 
00047   if {$gdbtk_platform(platform) == "windows"} {
00048     set prefs_init_filename "gdbtk.ini"
00049   } else {
00050     set prefs_init_filename ".gdbtkinit"
00051   }
00052 
00053   if {!$GDBStartup(inhibit_prefs) \
00054       || [info exists env(INSIGHT_FORCE_READ_PREFERENCES)]} {
00055     set file_opened 0
00056     if {[file exists $prefs_init_filename]} {
00057       if {[catch {open $prefs_init_filename r} fd]} {
00058   dbug E "$fd"
00059   return
00060       }
00061       set file_opened 1
00062     } elseif {$home != ""} {
00063       set name [file join $home $prefs_init_filename]
00064       if {[file exists $name]} {
00065   if {[catch {open $name r} fd]} {
00066     dbug E "$fd"
00067     return
00068   }
00069   set prefs_init_filename $name
00070   set file_opened 1
00071       }
00072     }
00073 
00074     if {$file_opened == "1"} {
00075       set section gdb
00076       set version 0
00077       while {[gets $fd line] >= 0} {
00078   switch -regexp -- $line {
00079     {^[ \t\n]*#.*} {
00080       # Comment.  We recognize one magic comment that includes
00081       # the version number.
00082       if {[regexp -- "^# GDBtkInitVersion: (\[0-9\]+)\$" $line \
00083              dummy v]} {
00084         set version $v
00085       }
00086     }
00087 
00088     {^[ \t\n]*$} {
00089       ;# empty line; ignore it
00090     }
00091 
00092     {^[ \t\n]*\[.*\]} {
00093       regexp {\[(.*)\]} $line match section
00094     }
00095 
00096     {^[ \t\n]*option.*} {
00097       set line [string trimleft $line]
00098       eval $line
00099     }
00100 
00101     default {
00102       set a ""
00103       set name ""
00104       set val ""
00105       regexp "\[ \t\n\]*\(.+\)=\(.+\)" $line a name val
00106       if {$a == "" || $name == ""} {
00107         dbug W "Cannot parse line: $line"
00108       } else {
00109         # Must unescape equal signs in val
00110         set val [unescape_value $val $version]
00111         if {$section == "gdb"} {
00112           pref setd gdb/$name $val
00113         } elseif {$section == "global" && [regexp "^font/" $name]} {
00114           set name [split $name /]
00115           set f global/
00116           append f [join [lrange $name 1 end] /]
00117           if {[lsearch [font names] $f] == -1} {
00118             # new font
00119             eval define_font $f $val
00120           } else {
00121             # existing font
00122             pref set global/font/[join [lrange $name 1 end] /] $val
00123           }
00124         } elseif {$section == "global"} {
00125           pref setd $section/$name $val
00126         } else {
00127           # backwards compatibility. recognize old src-font name
00128           if {$val == "src-font"} {set val "global/fixed"}
00129           pref setd gdb/$section/$name $val
00130         }
00131       }
00132     }
00133   }
00134       }
00135       close $fd
00136     } elseif {$home != ""} {
00137       set prefs_init_filename [file join $home $prefs_init_filename]
00138     }
00139     
00140     # now set global options
00141     set gdb_ImageDir [file join $GDBTK_LIBRARY [pref get gdb/ImageDir]]
00142 
00143   }
00144 
00145   # finally set colors, from system if possible
00146   if {[pref get gdb/use_color_schemes] != "1"} {
00147     pref_set_colors $home
00148   } else {
00149     # These colors are the same for all schemes
00150     global Colors
00151     set Colors(textfg) black
00152     set Colors(fg) black
00153     set Colors(sbg) \#4c59a5
00154     set Colors(sfg) white
00155     set_bg_colors
00156   }
00157 
00158   # Set color for changes.
00159   global Colors
00160   set Colors(change) [pref get gdb/src/PC_TAG]
00161 }
00162 
00163 # ------------------------------------------------------------------
00164 #  PROC:  pref_save - save preferences to a file and delete window
00165 # ------------------------------------------------------------------
00166 proc pref_save {{win {}}} {
00167   global prefs_init_filename GDBStartup env
00168 
00169   if {!$GDBStartup(inhibit_prefs)
00170       || [info exists env(INSIGHT_FORCE_READ_PREFERENCES)]} {
00171     debug "pref_save $prefs_init_filename"
00172 
00173     if {[catch {open $prefs_init_filename w} fd]} {
00174       debug "ERROR: $fd"
00175       return
00176     }
00177     
00178     puts $fd "\# GDBtk Init file"
00179     puts $fd {# GDBtkInitVersion: 1}
00180 
00181     set plist [pref list]
00182     # write out global options
00183     puts $fd "\[global\]"
00184     foreach var $plist {
00185       set t [split $var /]
00186       if {[lindex $t 0] == "global"} {
00187   set x [join [lrange $t 1 end] /]
00188   set v [escape_value [pref get $var]]
00189 
00190   if {$x != "" && $v != ""} {
00191     puts $fd "\t$x=$v"
00192   }
00193       }
00194     }
00195 
00196     # write out gdb-global options
00197     puts $fd "\[gdb\]"
00198     foreach var $plist {
00199       set t [split $var /]
00200       # We use the funny join/lreplace code because the session code
00201       # can generate a key where [lindex $t 2] is empty but there is
00202       # still stuff after that.  This happens because the session code
00203       # uses filenames, which can start with `/'.
00204       if {[lindex $t 0] == "gdb"
00205     && [string compare [join [lreplace $t 0 1] /] ""] == 0} {
00206   set x [lindex $t 1]
00207   set v [escape_value [pref get $var]]
00208   if {$x != "" && $v != ""} {
00209     puts $fd "\t$x=$v"
00210   }
00211       }
00212     }
00213 
00214     # now loop through all sections writing out values
00215     # FIXME: this is broken.  We should discover the list
00216     # dynamically.
00217     lappend secs load console src reg stack locals watch bp search \
00218       process geometry help browser kod window session mem bg ipc
00219 
00220     foreach section $secs {
00221       puts $fd "\[$section\]"
00222       foreach var $plist {
00223   set t [split $var /]
00224   if {[lindex $t 0] == "gdb" && [lindex $t 1] == $section} {
00225     set x [join [lrange $t 2 end] /]
00226     set v [escape_value [pref get $var]]
00227     if {$x != "" && $v != ""} {
00228       puts $fd "\t$x=$v"
00229     }
00230   }
00231       }
00232     }
00233     close $fd
00234   }
00235 
00236   if {$win != ""} {
00237     $win delete
00238   }
00239 }
00240 
00241 # -------------------------------------------------------
00242 #  PROC: escape_value - escape all equal signs for saving
00243 #         prefs to a file
00244 # -------------------------------------------------------
00245 proc escape_value {val} {
00246   # We use a URL-style quoting.  We encode `=', `%', the `[]'
00247   # characters and newlines.  We use a cute trick here: we regsub in
00248   # command expressions which we then expand using subst.
00249   if {[info tclversion] >= 8.1} {
00250     set expr {([\[\]=%\n])}
00251   } else {
00252     set expr "(\[\]\[=%\n\])"
00253   }
00254   regsub -all -- $expr $val \
00255     {[format "%%%02x" [scan {\1} %c x; set x]]} newval
00256   return [subst -nobackslashes -novariables $newval]
00257 }
00258 
00259 # -------------------------------------------------------
00260 #  PROC: unescape_value - unescape all equal signs for
00261 #         reading prefs from a file.  VERSION is the version
00262 #         number of the encoding.
00263 #  version 0 only encoded `='.
00264 #  version 1 correctly encoded more values
00265 # -------------------------------------------------------
00266 proc unescape_value {val version} {
00267   switch -exact -- $version {
00268     0 {
00269       # Old-style encoding.
00270       if {[regsub -all -- {!%} $val = newval]} {
00271   return $newval
00272       }
00273     }
00274 
00275     1 {
00276       # Version 1 uses URL encoding.
00277       regsub -all -- "%(..)" $val \
00278   {[format %c 0x\1]} newval
00279       return [subst -nobackslashes -novariables $newval]
00280     }
00281 
00282     default {
00283       error "Unknown encoding version $version"
00284     }
00285   }
00286 
00287   return $val  
00288 }
00289 
00290 # ------------------------------------------------------------------
00291 #  PROC:  pref_set_defaults - set up default values
00292 # ------------------------------------------------------------------
00293 proc pref_set_defaults {} {
00294   global GDBTK_LIBRARY gdbtk_platform gdb_ImageDir
00295   debug
00296 
00297   # Gdb global defaults
00298   pref define gdb/ImageDir                images2
00299   set gdb_ImageDir [file join $GDBTK_LIBRARY [pref get gdb/ImageDir]]
00300   pref define gdb/font_cache              ""
00301   pref define gdb/mode                    0;     # 0 no tracing, 1 tracing enabled
00302   pref define gdb/control_target          1;     # 0 can't control target (EMC), 1 can
00303   pref define gdb/B1_behavior             1;     # 0 means set/clear breakpoints,
00304   # 1 means set/clear tracepoints.
00305   pref define gdb/use_icons                 1;     # For Unix, use gdbtk_icon.gif as an icon
00306   # some window managers can't deal with it.
00307 
00308   # OS compatibility. Valid values are "Windows", "GNOME", "KDE", and "default"
00309   if {$gdbtk_platform(platform) == "windows"}  {
00310     pref define gdb/compat        "Windows"
00311   } elseif {$gdbtk_platform(platform) == "unix"}  {
00312     pref define gdb/compat        "GNOME"
00313   } else {
00314     pref define gdb/compat        "default"
00315   }
00316   
00317   # set download and execution options
00318   pref define gdb/load/verbose 0
00319   pref define gdb/load/main 1
00320   pref define gdb/load/exit 1
00321   pref define gdb/load/check 0
00322   pref define gdb/load/bp_at_func 0
00323   pref define gdb/load/bp_func ""
00324   pref define gdb/load/baud 38400
00325   if {$gdbtk_platform(platform) == "windows"}  {
00326     pref define gdb/load/port com1
00327   } else {
00328     pref define gdb/load/port "/dev/ttyS0"
00329   }
00330 
00331   # The list of active windows:
00332   pref define gdb/window/active           {}
00333 
00334   # Console defaults
00335   pref define gdb/console/prompt          "(gdb) "
00336   pref define gdb/console/deleteLeft      1
00337   pref define gdb/console/wrap            0
00338   pref define gdb/console/prompt_fg       DarkGreen
00339   pref define gdb/console/error_fg        red
00340   pref define gdb/console/log_fg          \#00b300
00341   pref define gdb/console/target_fg       blue
00342   pref define gdb/console/font            global/fixed
00343 
00344   # Source window defaults
00345   pref define gdb/src/PC_TAG              \#00b300
00346   pref define gdb/src/STACK_TAG           gold
00347   pref define gdb/src/BROWSE_TAG          \#9595e2
00348   pref define gdb/src/handlebg            red
00349   pref define gdb/src/bp_fg               red
00350   pref define gdb/src/temp_bp_fg          orange
00351   pref define gdb/src/disabled_fg         black
00352   pref define gdb/src/font                global/fixed
00353   pref define gdb/src/break_fg            black
00354   pref define gdb/src/source2_fg          navy
00355   pref define gdb/src/variableBalloons    1
00356   pref define gdb/src/trace_fg            magenta
00357   pref define gdb/src/tab_size            8
00358   pref define gdb/src/linenums              1
00359   pref define gdb/src/thread_fg           pink
00360   pref define gdb/src/top_control   1;    # 1 srctextwin controls on top, 0 bottom
00361 
00362   # Define the run button's functions. These are defined here in case
00363   # we do a "run" with an exec target (which never causes target.tcl to 
00364   # source)...
00365   pref define gdb/src/run_attach          0
00366   pref define gdb/src/run_load            0
00367   pref define gdb/src/run_run             1
00368   pref define gdb/src/run_cont            0
00369 
00370   # This is the disassembly flavor.  For now this is only supported on x86
00371   # machines.
00372 
00373   pref define gdb/src/disassembly-flavor  ""
00374 
00375   # Variable Window defaults
00376   pref define gdb/variable/font           global/fixed
00377   pref define gdb/variable/disabled_fg    gray
00378 
00379   # Stack Window
00380   pref define gdb/stack/font              global/fixed
00381   
00382   # Register Window
00383   pref define gdb/reg/rows                16
00384 
00385   # Global Prefs Dialogs
00386   pref define gdb/global_prefs/save_fg    red
00387   pref define gdb/global_prefs/message_fg white
00388   pref define gdb/global_prefs/message_bg red
00389 
00390   # Browser Window Search
00391   pref define gdb/search/last_symbol      ""
00392   pref define gdb/search/filter_mode     "starts with"
00393 
00394   pref define gdb/browser/hide_h          0
00395   pref define gdb/browser/layout  2
00396 
00397   # BP (breakpoint)
00398   pref define gdb/bp/show_threads         0
00399 
00400   # Help
00401   pref define gdb/help/browsername        ""
00402 
00403   # Kernel Objects (kod)
00404   pref define gdb/kod/show_icon           0
00405 
00406   # Various possible "main" functions. What's for Java?
00407   pref define gdb/main_names              [list main MAIN___ MAIN__ cyg_user_start cyg_start ]
00408 
00409   # These are the classes of warning dialogs, and whether the user plans
00410   # to ignore them.
00411   pref define gdb/warnings/signal         0
00412 
00413   # Memory window.
00414   pref define gdb/mem/size 4
00415   pref define gdb/mem/numbytes 0
00416   pref define gdb/mem/format x
00417   pref define gdb/mem/ascii 1
00418   pref define gdb/mem/ascii_char .
00419   pref define gdb/mem/bytes_per_row 16
00420   pref define gdb/mem/color green
00421   
00422   # External editor.
00423   pref define gdb/editor ""
00424 
00425   # background colors
00426   set ::gdb_bg_num 0
00427   pref define gdb/use_color_schemes       1
00428   pref define gdb/bg/0    \#ffffff
00429   pref define gdb/bg/1    \#ffffd0
00430   pref define gdb/bg/2    \#ffd0ff
00431   pref define gdb/bg/3    \#ffd0d0
00432   pref define gdb/bg/4    \#d0ffff
00433   pref define gdb/bg/5    \#d0ffd0
00434   pref define gdb/bg/6    \#d0d0ff
00435   pref define gdb/bg/7    \#d0d0d0
00436   pref define gdb/bg/8    \#ffffb0
00437   pref define gdb/bg/9    \#ffb0ff
00438   pref define gdb/bg/10   \#ffb0b0
00439   pref define gdb/bg/11   \#b0ffff
00440   pref define gdb/bg/12   \#b0ffb0
00441   pref define gdb/bg/13   \#b0b0ff
00442   pref define gdb/bg/14   \#b0b0b0
00443   pref define gdb/bg/15   \#d0b0d0
00444 
00445   # IPC prefs
00446   # set prefs based on GDB version?
00447   #set vers [lindex [split [lindex [split [gdb_cmd "show version"]] end-1 ] \"] 1]
00448   pref define gdb/ipc/enabled             0
00449   pref define gdb/ipc/port                9909
00450   pref define gdb/ipc/stop_button 1
00451   pref define gdb/ipc/step_button 1
00452   pref define gdb/ipc/cont_button 1
00453   pref define gdb/ipc/run_button  1
00454   pref define gdb/ipc/exit                1
00455 }
00456 
00457 
00458 ##########################################################################
00459 #
00460 # Everything below this point is code to try to determine the current OS
00461 # color scheme and use that.  It mostly works, but is not very compatible 
00462 # with the use of multiple color schemes for different instances of Insight.
00463 #
00464 ##########################################################################
00465 proc pref_set_colors {home} {
00466   # set color palette
00467   
00468   # In the past, tk widgets got their color information from Windows or
00469   # the X resource database.  Unfortunately Insight is a mixture of widgets 
00470   # from all over and was coded first in tcl and later in itcl.  So lots of 
00471   # color inheritance is broken or wrong. And Insight has some special color
00472   # requirements. We also have to deal with new Unix desktops that don't use the Xrdb.
00473   # To enable us to fix that without hardcoding colors, we create a color
00474   # array here and use it as needed to force widgets to the correct colors.
00475   
00476   global Colors
00477   debug
00478 
00479   # UNIX colors
00480   
00481   # For KDE3 (and probably earlier versions) when the user sets
00482   # a color scheme from the KDE control center, the appropriate color 
00483   # information is set in the X resource database.  Well, most of it 
00484   # is there but it is missing some settings, so we will carefully 
00485   # adjust things.
00486   #
00487   # For GNOME, we read .gtkrc or .gtkrc-1.2-gnome2 and parse it
00488   # for the color information.  We cannot really get this right,
00489   # but with luck we can read enough to get the colors to mostly match.
00490 
00491   # If there is no information, we provide reasonable defaults.
00492   
00493   # If some theme sets the text foreground and background to something unusual
00494   # then Insight won't be able to display sources and highlight things properly.
00495   # Therefore we will not change the textfg and textbg.
00496 
00497   pref_load_default
00498   switch [pref get gdb/compat] {
00499 
00500     "Windows" {
00501       debug "loading OS colors for Windows"
00502       set Colors(fg) SystemButtonText
00503       set Colors(bg) SystemButtonFace
00504       #set Colors(textfg) SystemWindowText
00505       #set Colors(textbg) SystemWindow
00506       set Colors(textfg) black
00507       set Colors(textbg) white
00508       set Colors(sfg) SystemHighlightText
00509       set Colors(sbg) SystemHighlight
00510       pref_set_option_db 0
00511     }
00512 
00513     "KDE" {
00514       debug "loading OS colors for KDE"
00515 
00516       # try loading "~/.gtkrc-kde"
00517       if {[pref_load_gnome $home [list .gtkrc-kde]]} {
00518   debug "loaded gnome file"
00519   pref_set_option_db 0
00520   debug "loaded option file"
00521       } else {
00522   # no .gtkrc-kde so assume X defaults have been set
00523 
00524   # create an empty entry widget so we can query its colors
00525   entry .e
00526   
00527   # text background
00528   # set Colors(textbg) [option get .e background {}]
00529   set Colors(textbg) white
00530   
00531   # text foreground
00532   #set Colors(textfg) [option get .e foreground {}]
00533   set Colors(textfg) black
00534   
00535   # background
00536   set Colors(bg) [option get . background {}]
00537   if {$Colors(bg) == ""} {set Colors(bg) lightgray}
00538   
00539   # foreground
00540   set Colors(fg) [option get . foreground {}]
00541   if {$Colors(fg) == ""} {set Colors(fg) black}
00542   
00543   # selectBackground
00544   set Colors(sbg) [option get .e selectBackground {}]
00545   if {$Colors(sbg) == ""} {set Colors(sbg) blue}
00546   
00547   # selectForeground
00548   set Colors(sfg) [option get .e selectForeground {}]
00549   if {$Colors(sfg) == ""} {set Colors(sfg) white}
00550   
00551   destroy .e
00552   pref_set_option_db 1
00553       }
00554     }
00555     
00556     "GNOME" {
00557       pref_load_gnome $home
00558       pref_set_option_db 0
00559     }
00560 
00561     "default" {
00562       pref_set_option_db 1
00563     }
00564   }
00565 }
00566 
00567 proc pref_load_default {} {
00568   global Colors
00569   debug "loading default colors"
00570   
00571   set Colors(textbg) white
00572   set Colors(textfg) black
00573   set Colors(bg) lightgray
00574   set Colors(fg) black
00575   
00576   # selectBackground
00577   set Colors(sbg) blue
00578   
00579   # selectForeground
00580   set Colors(sfg) white
00581 }
00582 
00583 
00584 # load GNOME colors and fonts, if possible.
00585 proc pref_load_gnome {home {possible_names {}}} {
00586   debug "loading OS colors for GNOME"
00587 
00588   if {$possible_names == ""} {
00589     set possible_names {.gtkrc .gtkrc-1.2-gnome2}
00590   }
00591 
00592   set found 0
00593   foreach name $possible_names {
00594     debug "home=$home name=$name"
00595     set fname [file join $home $name]
00596     debug "fname=$fname"
00597     if {[file exists $fname]} {
00598       if {[catch {open $fname r} fd]} {
00599   dbug W "cannot open $fname: $fd"
00600   return 0
00601       }
00602       set found 1
00603       break
00604     }
00605   }
00606   if {$found} {
00607     set found [load_gnome_file $fd]
00608     close $fd
00609   }
00610   return $found
00611 }
00612 
00613 proc load_gnome_file {fd} {
00614   global Colors
00615   set found 0
00616   
00617   while {[gets $fd line] >= 0} {
00618     if {[regexp {include \"([^\"]*)} $line foo incname]} {
00619       debug "include $incname $found"
00620       if {$found == 0 && [file exists $incname]} {
00621   if {[catch {open $incname r} fd2]} {
00622     dbug W "cannot open $incname: $fd2"
00623   } else {
00624     set found [load_gnome_file $fd2]
00625     close $fd2
00626     if {$found} {
00627       return $found
00628     }
00629   }
00630       }
00631       continue
00632     } elseif {[regexp "\[ \t\n\]*\(.+\) = \(.+\)" $line a name val] == 0} {
00633       continue 
00634     }
00635 
00636     if {[regexp "\"#......\"" $val a] == 1} {
00637   set val [lindex $a 0]
00638     } else {
00639   set res [scan $val "\{ %f, %f, %f \}" r g b]
00640   if {$res != 3} {
00641       continue
00642   }
00643   set r [expr int($r*255)]
00644   set g [expr int($g*255)]
00645   set b [expr int($b*255)]
00646   set val [format "\#%02x%02x%02x" $r $g $b]
00647     }
00648 
00649     debug "name=\"$name\"  val=\"$val\""
00650 
00651     # This is a bit of a hack and probably only
00652     # works for trivial cases.  Scan for colors and
00653     # use the first one found.
00654     switch [string trimright $name] {
00655       {bg[NORMAL]} {
00656   set found 1
00657   if {![info exists new(bg)]} {
00658     debug "setting bg to $val"
00659     set new(bg) $val
00660   }
00661       }
00662       {base[NORMAL]} {
00663   #if {![info exists new(textbg)]} {
00664   #  set new(textbg) $val
00665   #}
00666       }
00667       {text[NORMAL]} {
00668   #if {![info exists new(textfg)]} {
00669   #  set new(textfg) $val
00670   #}
00671       }
00672       {fg[NORMAL]} {
00673   if {![info exists new(fg)]} {
00674     set new(fg) $val
00675   }
00676       }
00677       {fg[ACTIVE]} {
00678   if {![info exists new(afg)]} {
00679     set new(afg) $val
00680   }
00681       }
00682       {bg[SELECTED]} {
00683   if {![info exists new(sbg)]} {
00684     set new(sbg) $val
00685   }
00686       }
00687       {base[SELECTED]} {
00688   if {![info exists new(sbg)]} {
00689     set new(sbg) $val
00690   }
00691       }
00692       {fg[SELECTED]} {
00693   if {![info exists new(sfg)]} {
00694     set new(sfg) $val
00695   }
00696       }
00697       {fg[INSENSITIVE]} {
00698   if {![info exists new(dfg)]} {
00699     set new(dfg) $val
00700   }
00701       }
00702       {bg[PRELIGHT]} {
00703   set Colors(prelight) $val
00704       }
00705       {base[PRELIGHT]} {
00706   set Colors(prelight) $val
00707       }
00708     }
00709   } 
00710 
00711   foreach c {fg bg sfg sbg dfg} {
00712     if {[info exists new($c)]} {
00713       set Colors($c) $new($c)
00714     }
00715   }
00716   return 1
00717 }
00718 
00719 
00720 # load the colors into the tcl option database
00721 proc pref_set_option_db {makebg} {
00722   global Colors
00723 
00724   option add *background $Colors(bg)
00725   option add *buttonBackground $Colors(bg)
00726   option add *Text*background $Colors(textbg)
00727   option add *Entry*background $Colors(textbg)
00728   option add *foreground $Colors(fg)
00729   option add *Text*foreground $Colors(textfg)
00730   option add *Entry*foreground $Colors(textfg)
00731 
00732   option add *highlightBackground $Colors(bg)
00733   option add *selectBackground $Colors(sbg)
00734 
00735   if {$::gdbtk_platform(platform) == "unix"}  {
00736     option add *activeBackground $Colors(sbg)
00737   }
00738 
00739   option add *selectForeground $Colors(sfg)
00740   option add *Menu*activeForeground $Colors(sfg)
00741 
00742   if {[info exists Colors(prelight)]} {
00743     option add *Button*activeBackground $Colors(prelight)
00744   }
00745   if {[info exists Colors(dfg)]} {
00746     option add *disabledForeground $Colors(dfg)
00747   }
00748   
00749   if {$makebg} {
00750     # calculate trough and activebackground as 90% of background
00751     set dbg [recolor $::Colors(bg) 90]
00752     option add *activeBackground $dbg
00753     option add *troughColor $dbg
00754   }
00755 
00756   # Change the default select color for checkbuttons, etc to match 
00757   # selectBackground.
00758   if {$::gdbtk_platform(platform) == "unix"}  {
00759     option add *selectColor $Colors(sbg)
00760   }
00761 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines