1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        gtk/settings.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  12 #pragma implementation "settings.h" 
  15 #include "wx/settings.h" 
  17 #include "wx/module.h" 
  18 #include "wx/cmndata.h" 
  21 #include <gdk/gdkprivate.h> 
  24 #define SHIFT (8*(sizeof(short int)-sizeof(char))) 
  26 //wxColour *g_systemWinColour          = (wxColour *) NULL; 
  27 wxColour 
*g_systemBtnFaceColour       
= (wxColour 
*) NULL
; 
  28 wxColour 
*g_systemBtnShadowColour     
= (wxColour 
*) NULL
; 
  29 wxColour 
*g_systemBtnHighlightColour  
= (wxColour 
*) NULL
; 
  30 wxColour 
*g_systemHighlightColour     
= (wxColour 
*) NULL
; 
  31 wxColour 
*g_systemHighlightTextColour 
= (wxColour 
*) NULL
; 
  32 wxColour 
*g_systemListBoxColour       
= (wxColour 
*) NULL
; 
  33 wxColour 
*g_systemBtnTextColour       
= (wxColour 
*) NULL
; 
  35 wxFont 
*g_systemFont 
= (wxFont 
*) NULL
; 
  37 // ---------------------------------------------------------------------------- 
  38 // wxSystemSettingsModule 
  39 // ---------------------------------------------------------------------------- 
  41 class wxSystemSettingsModule 
: public wxModule
 
  44     bool OnInit() { return TRUE
; } 
  47         //delete g_systemWinColour; 
  48         delete g_systemBtnFaceColour
; 
  49         delete g_systemBtnShadowColour
; 
  50         delete g_systemBtnHighlightColour
; 
  51         delete g_systemHighlightColour
; 
  52         delete g_systemHighlightTextColour
; 
  53         delete g_systemListBoxColour
; 
  55         delete g_systemBtnTextColour
; 
  57     DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
) 
  60 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
) 
  62 // ---------------------------------------------------------------------------- 
  63 // wxSystemSettings implementation 
  64 // ---------------------------------------------------------------------------- 
  66 // kind of widget to use in GetColourFromGTKWidget 
  81 // wxSystemSettings::GetColour() helper: get the colours from a GTK+ 
  82 // widget style, return true if we did get them, false to use defaults 
  83 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
, 
  84                                    wxGtkWidgetType type 
= wxGTK_BUTTON
, 
  85                                    GtkStateType state 
= GTK_STATE_NORMAL
, 
  86                                    wxGtkColourType colour 
= wxGTK_BG
) 
  92             wxFAIL_MSG( _T("unexpected GTK widget type") ); 
  96             widget 
= gtk_button_new(); 
 100             widget 
= gtk_list_new(); 
 103     GtkStyle 
*def 
= gtk_rc_get_style( widget 
); 
 105         def 
= gtk_widget_get_default_style(); 
 114                 wxFAIL_MSG( _T("unexpected GTK colour type") ); 
 130         red 
= col
[state
].red
; 
 131         green 
= col
[state
].green
; 
 132         blue 
= col
[state
].blue
; 
 141     gtk_widget_destroy( widget 
); 
 146 wxColour 
wxSystemSettingsNative::GetColour( wxSystemColour index 
) 
 150         case wxSYS_COLOUR_SCROLLBAR
: 
 151         case wxSYS_COLOUR_BACKGROUND
: 
 152         case wxSYS_COLOUR_ACTIVECAPTION
: 
 153         case wxSYS_COLOUR_INACTIVECAPTION
: 
 154         case wxSYS_COLOUR_MENU
: 
 155         case wxSYS_COLOUR_WINDOWFRAME
: 
 156         case wxSYS_COLOUR_ACTIVEBORDER
: 
 157         case wxSYS_COLOUR_INACTIVEBORDER
: 
 158         case wxSYS_COLOUR_BTNFACE
: 
 159         case wxSYS_COLOUR_MENUBAR
: 
 160         case wxSYS_COLOUR_3DLIGHT
: 
 161             if (!g_systemBtnFaceColour
) 
 163                 int red
, green
, blue
; 
 164                 if ( !GetColourFromGTKWidget(red
, green
, blue
) ) 
 171                 g_systemBtnFaceColour 
= new wxColour( red   
>> SHIFT
, 
 175             return *g_systemBtnFaceColour
; 
 177         case wxSYS_COLOUR_WINDOW
: 
 180         case wxSYS_COLOUR_3DDKSHADOW
: 
 183         case wxSYS_COLOUR_GRAYTEXT
: 
 184         case wxSYS_COLOUR_BTNSHADOW
: 
 185         //case wxSYS_COLOUR_3DSHADOW: 
 186             if (!g_systemBtnShadowColour
) 
 188                 wxColour 
faceColour(GetColour(wxSYS_COLOUR_3DFACE
)); 
 189                 g_systemBtnShadowColour 
= 
 190                    new wxColour((unsigned char) (faceColour
.Red() * 0.666), 
 191                                 (unsigned char) (faceColour
.Green() * 0.666), 
 192                                 (unsigned char) (faceColour
.Blue() * 0.666)); 
 195             return *g_systemBtnShadowColour
; 
 197         case wxSYS_COLOUR_3DHIGHLIGHT
: 
 198         //case wxSYS_COLOUR_BTNHIGHLIGHT: 
 200 /* I think this should normally be white (JACS 8/2000) 
 202    Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01) 
 203             if (!g_systemBtnHighlightColour) 
 205                 g_systemBtnHighlightColour = 
 206                     new wxColour( 0xea60 >> SHIFT, 
 210             return *g_systemBtnHighlightColour; 
 213         case wxSYS_COLOUR_HIGHLIGHT
: 
 214             if (!g_systemHighlightColour
) 
 216                 int red
, green
, blue
; 
 217                 if ( !GetColourFromGTKWidget(red
, green
, blue
, 
 219                                              GTK_STATE_SELECTED
) ) 
 226                 g_systemHighlightColour 
= new wxColour( red   
>> SHIFT
, 
 230             return *g_systemHighlightColour
; 
 232         case wxSYS_COLOUR_LISTBOX
: 
 233             if (!g_systemListBoxColour
) 
 235                 int red
, green
, blue
; 
 236                 if ( GetColourFromGTKWidget(red
, green
, blue
, 
 241                     g_systemListBoxColour 
= new wxColour( red   
>> SHIFT
, 
 247                     g_systemListBoxColour 
= new wxColour(*wxWHITE
); 
 250             return *g_systemListBoxColour
; 
 252         case wxSYS_COLOUR_MENUTEXT
: 
 253         case wxSYS_COLOUR_WINDOWTEXT
: 
 254         case wxSYS_COLOUR_CAPTIONTEXT
: 
 255         case wxSYS_COLOUR_INACTIVECAPTIONTEXT
: 
 256         case wxSYS_COLOUR_BTNTEXT
: 
 257         case wxSYS_COLOUR_INFOTEXT
: 
 258             if (!g_systemBtnTextColour
) 
 260                 int red
, green
, blue
; 
 261                 if ( !GetColourFromGTKWidget(red
, green
, blue
, 
 271                 g_systemBtnTextColour 
= new wxColour( red   
>> SHIFT
, 
 275             return *g_systemBtnTextColour
; 
 277             // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for 
 278             // tooltip windows - Robert, please change this code to use the 
 279             // real GTK tooltips when/if you can (TODO) 
 280         case wxSYS_COLOUR_INFOBK
: 
 281             return wxColour(255, 255, 225); 
 283         case wxSYS_COLOUR_HIGHLIGHTTEXT
: 
 284             if (!g_systemHighlightTextColour
) 
 286                 wxColour hclr 
= GetColour(wxSYS_COLOUR_HIGHLIGHT
); 
 287                 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200) 
 288                     g_systemHighlightTextColour 
= new wxColour(*wxBLACK
); 
 290                     g_systemHighlightTextColour 
= new wxColour(*wxWHITE
); 
 292             return *g_systemHighlightTextColour
; 
 294         case wxSYS_COLOUR_APPWORKSPACE
: 
 295             return *wxWHITE
;    // ? 
 297         case wxSYS_COLOUR_HOTLIGHT
: 
 298         case wxSYS_COLOUR_GRADIENTACTIVECAPTION
: 
 299         case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
: 
 300         case wxSYS_COLOUR_MENUHILIGHT
: 
 304         case wxSYS_COLOUR_MAX
: 
 306             wxFAIL_MSG( _T("unknown system colour index") ); 
 312 wxFont 
wxSystemSettingsNative::GetFont( wxSystemFont index 
) 
 316         case wxSYS_OEM_FIXED_FONT
: 
 317         case wxSYS_ANSI_FIXED_FONT
: 
 318         case wxSYS_SYSTEM_FIXED_FONT
: 
 320             return *wxNORMAL_FONT
; 
 322         case wxSYS_ANSI_VAR_FONT
: 
 323         case wxSYS_SYSTEM_FONT
: 
 324         case wxSYS_DEVICE_DEFAULT_FONT
: 
 325         case wxSYS_DEFAULT_GUI_FONT
: 
 329                 g_systemFont 
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL 
); 
 332             return *g_systemFont
; 
 340 int wxSystemSettingsNative::GetMetric( wxSystemMetric index 
) 
 344         case wxSYS_SCREEN_X
:   return gdk_screen_width(); 
 345         case wxSYS_SCREEN_Y
:   return gdk_screen_height(); 
 346         case wxSYS_HSCROLL_Y
:  return 15; 
 347         case wxSYS_VSCROLL_X
:  return 15; 
 349         // VZ: is there any way to get the cursor size with GDK? 
 350         case wxSYS_CURSOR_X
:   return 16; 
 351         case wxSYS_CURSOR_Y
:   return 16; 
 352         // MBN: ditto for icons 
 353         case wxSYS_ICON_X
:     return 32; 
 354         case wxSYS_ICON_Y
:     return 32; 
 356             wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") ); 
 361 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
) 
 365         case wxSYS_CAN_ICONIZE_FRAME
:  
 368         case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: