-------------------------------------------------------------------
--           RAPID - RAPID ADA PORTABLE INTERFACE DESIGNER         
--           MCC GUI PACKAGE LIBRARY                               
--           Copyright (C) 1999 Martin C. Carlisle.                
--                                                                 
-- RAPID is free software;  you can  redistribute it  and/or modify
-- it under terms of the  GNU General Public License as published  
-- by the Free Software  Foundation;  either version 2,  or (at your
-- option) any later version.  RAPID is distributed in the hope that 
-- it will be useful, but WITHOUT ANY WARRANTY;  without even the 
-- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE.  See the GNU General Public License for more details.  
-- You should have  received  a copy of the GNU General Public License
-- distributed with RAPID; see file COPYING.  If not, write to the 
-- Free Software Foundation,  59 Temple Place - Suite 330,  Boston, 
-- MA 02111-1307, USA.                                                 
--                                                                     
-- As a special exception, if other files instantiate generics from
-- this unit, or you link this unit with other files to produce an 
-- executable, this unit does not by itself cause the resulting 
-- executable to be covered by the GNU General Public License.  
-- This exception does not however invalidate any other reasons 
-- why the executable file might be covered by the GNU Public 
-- License.  This exception does not apply to executables which
-- are GUI design tools, or that could act as a replacement
-- for RAPID.
------------------------------------------------------------------------------
with gdk;
with gdk.color;
with glib;
with gtk.enums;
with gtk.widget;
with gtk.style;
with mcc.gui.Container;
with hex;
with Peer.Style;
with Gtk.Tooltips;
with Ada.Text_IO;

package body Mcc.Gui.Widget is

   ----------------
   -- Get_Parent --
   ----------------

   function Get_Parent(Obj : in Widget'Class)return Mcc.Gui.Container.Container_Pointer
   is
   begin
      return Obj.Parent;
   end Get_Parent;

   --------------------------
   -- Set_Foreground_Color --
   --------------------------

   procedure Set_Foreground_Color(Obj       : in out Widget;
                                  New_Color : in     Color)is
      old_style : gtk.style.gtk_style;
      new_style : gtk.style.gtk_style;
      color     : gdk.color.gdk_color;
      colormap  : gdk.color.gdk_colormap;
      success   : boolean;
   begin--Set_Foreground_Color
      --Set color
      -- Note RGB colors are out of 65536 possible, not 256
      gdk.color.Set_RGB(
         Color => Color,
         Red   => Glib.Gushort(New_Color.Red   * 65535/255),
         Green => Glib.Gushort(New_Color.Green * 65535/255),
         Blue  => Glib.Gushort(New_Color.Blue  * 65535/255)
         );
      gdk.color.Set_Pixel(
         Color => Color,
         Pixel => 0);
      colormap := Gdk.Color.Get_System;
      Gdk.Color.Alloc_Color(
         Colormap   => colormap,
         Color      => color,
         Writeable  => True,
         Best_Match => True,
         Success    => Success);

      --create a new_style
      Old_Style := Gtk.Widget.Get_Style(Gtk.Widget.Gtk_Widget(Obj.My_Peer));
      New_Style := Gtk.Style.Copy(Old_Style);
      
      --Change color for each of the five states
      gtk.style.Set_Foreground(new_style,gtk.enums.State_Normal,color); 
      gtk.style.Set_Foreground(new_style,gtk.enums.State_Active,color); 
      gtk.style.Set_Foreground(new_style,gtk.enums.State_prelight,color); 
      gtk.style.Set_Foreground(new_style,gtk.enums.State_selected,color); 
      gtk.style.Set_Foreground(new_style,gtk.enums.State_insensitive,color); 
      gtk.style.Set_Text(new_style,gtk.enums.State_Normal,color); 
      gtk.style.Set_Text(new_style,gtk.enums.State_Active,color); 
      gtk.style.Set_Text(new_style,gtk.enums.State_prelight,color); 
      gtk.style.Set_Text(new_style,gtk.enums.State_selected,color); 
      gtk.style.Set_Text(new_style,gtk.enums.State_insensitive,color); 
      Peer.Style.Set_Style_Recursively(widget => Gtk.Widget.Gtk_Widget(Obj.My_Peer),
                                       style  => new_style);
   end Set_Foreground_Color;

   ----------------------
   -- Set_Tooltip_Text --
   ----------------------

   procedure Set_Tooltip_Text(Obj  : in out Widget;
                              Text : in String) is
                              
      new_tooltip : Gtk.Tooltips.Gtk_Tooltips;
   
   begin--Set_Tooltip_Text
      Gtk.Tooltips.Gtk_New(Widget => new_tooltip);
      Gtk.Tooltips.Set_Tip(Tooltips => new_tooltip,
                           Widget   => Gtk.Widget.Gtk_Widget(Obj.My_Peer),
                           Tip_Text => Text);
   end Set_Tooltip_Text;


   -----------
   -- focus --
   -----------
   
   procedure focus (obj : in widget) is
   begin
      gtk.widget.grab_focus(Gtk.Widget.Gtk_Widget(Obj.My_Peer)); -- 20030425ph
   end focus;

end Mcc.Gui.Widget;