initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / cellrenderer_time.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file cellrenderer_time.cpp
3 **      \brief Template File
4 **
5 **      $Id: cellrenderer_time.cpp,v 1.1.1.1 2005/01/07 03:34:35 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include <gtkmm/entry.h>
32 #include <gtkmm/button.h>
33 #include "cellrenderer_time.h"
34 #include "app.h"
35 #include "widget_time.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 //using namespace etl;
43 using namespace sinfg;
44 using namespace studio;
45
46 /* === M A C R O S ========================================================= */
47
48 #if ! defined(_)
49 #define _(x)    (x)
50 #endif
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 CellRenderer_Time::CellRenderer_Time():
59         Glib::ObjectBase        (typeid(CellRenderer_Time)),
60         Gtk::CellRendererText   (),
61         property_time_(*this,"time",sinfg::Time(0)),
62         property_fps_(*this,"fps", float(0))
63 {
64         CellRendererText::signal_edited().connect(sigc::mem_fun(*this,&studio::CellRenderer_Time::string_edited_));
65 }
66
67 CellRenderer_Time::~CellRenderer_Time()
68 {
69         sinfg::info("CellRenderer_Time::~CellRenderer_Time(): deleted");
70 }
71
72 void
73 CellRenderer_Time::string_edited_(const Glib::ustring&path,const Glib::ustring&str)
74 {
75         signal_edited_(path,Time((String)str,(Real)Time(property_fps_)));
76 }
77
78 void
79 CellRenderer_Time::render_vfunc(
80                 const Glib::RefPtr<Gdk::Drawable>& window,
81                 Gtk::Widget& widget,
82                 const Gdk::Rectangle& background_area,
83                 const Gdk::Rectangle& ca,
84                 const Gdk::Rectangle& expose_area,
85                 Gtk::CellRendererState flags)
86 {
87         if(!window)
88                 return;
89         //int   height = ca.get_height();
90
91         Gtk::StateType state = Gtk::STATE_INSENSITIVE;
92         if(property_editable())
93                 state = Gtk::STATE_NORMAL;
94         if((flags & Gtk::CELL_RENDERER_SELECTED) != 0)
95                 state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;
96
97         const Time time(property_time_);
98         const float fps((Real)Time(property_fps_));
99         
100         property_text()=(Glib::ustring)time.get_string(fps,App::get_time_format());
101
102         CellRendererText::render_vfunc(window,widget,background_area,ca,expose_area,flags);
103 }
104
105
106 Gtk::CellEditable*
107 CellRenderer_Time::start_editing_vfunc(
108         GdkEvent* event,
109         Gtk::Widget& widget,
110         const Glib::ustring& path,
111         const Gdk::Rectangle& background_area,
112         const Gdk::Rectangle& cell_area,
113         Gtk::CellRendererState flags)
114 {
115         // If we aren't editable, then there is nothing to do
116         if(!property_editable())
117                 return 0;
118
119         const Time time(property_time_);
120         const float fps((Real)Time(property_fps_));
121         
122         property_text()=(Glib::ustring)time.get_string(fps,App::get_time_format()|Time::FORMAT_FULL);
123 #if 0
124         Widget_Time* widget_time(manage(new Widget_Time));
125         widget_time->set_fps(fps);
126         widget_time->set_value(time);
127         widget_time->signal_editing_done().connect(sigc::mem_fun(*this, &CellRenderer_Time::on_value_editing_done));
128         return widget_time;
129 #else
130         return CellRendererText::start_editing_vfunc(event,widget,path,background_area,cell_area,flags);
131 #endif
132 }