[glade--]Patch to enable gnome_dateedit widget



Hi all,

Attached is a patch (diff -Naur old new format) to add support for the
gnome_dateedit widget.  As discussed on the Gtk-- mailing list (see
http://www.geocrawler.com/archives/3/1110/2001/8/100/6356137/ for details)
the widget is not created in the normal way, but that is an issue for the
generated code only.  By the time a user gets ahold of the object it is
a first class Gnome::DateEdit object.

I'm new to the Glade-- code base, so I'm not sure it fits the all the
style and conventions completely, but I used existing classes as
guidelines.

The one tricky area I found is that I need to be able to return two
include files from the IncludeName(const Widget &w) call.  Not seeing
any interface for this (and not wanting to refactor something of this
scale on my first edit) I took the gross apporach of returning a string
with the end of one include statement and the start of the next.

This patch was developed against 6.2b taken from CVS today (12/17/2001)
and tested on RedHat 7.1 with Ximian Gnome 1.4 and Glade 0.6.2.

Thanks,
Jim Patterson
--
It's is not, it isn't ain't, and it's it's, not its, if you mean it
is.  If you don't, it's its.  Then too, it's hers.  It isn't her's.
It isn't our's either.  It's ours, and likewise yours and theirs.
                -- Oxford University Press, Edpress News

diff -Naur glade--/src/writers/Makefile.am glade--.gnome_dateedit/src/writers/Makefile.am
--- glade--/src/writers/Makefile.am	Tue Jun 12 09:43:27 2001
+++ glade--.gnome_dateedit/src/writers/Makefile.am	Mon Dec 17 22:03:20 2001
@@ -33,7 +33,8 @@
 	custom.cc default.cc dial.cc dialog.cc drawingarea.cc editable.cc \
 	entry.cc eventbox.cc fileselection.cc \
 	fixed.cc frame.cc gamma.cc gnome_about.cc \
-	gnome_app.cc gnome_appbar.cc gnome_calculator.cc gnome_dialog.cc \
+	gnome_app.cc gnome_appbar.cc gnome_calculator.cc gnome_dateedit.cc \
+	gnome_dialog.cc \
 	gnome_dock.cc gnome_dockitem.cc gnome_druid.cc gnome_druidpage.cc \
 	gnome_druidpagestart.cc gnome_druidpagestd.cc \
 	gnome_druidpagefinish.cc gnome_entry.cc \
diff -Naur glade--/src/writers/gnome_dateedit.cc glade--.gnome_dateedit/src/writers/gnome_dateedit.cc
--- glade--/src/writers/gnome_dateedit.cc	Thu Jan  1 00:00:00 1970
+++ glade--.gnome_dateedit/src/writers/gnome_dateedit.cc	Mon Dec 17 22:01:57 2001
@@ -0,0 +1,105 @@
+// $Id: gnome_dateedit.cc $
+/*  glade--: C++ frontend for glade (Gtk+ User Interface Builder)
+ *  Copyright (C) 2001 Jim Patterson, based on works copyright to Christof Petig
+ *  and Adolf Petig GmbH & Co. KG.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "box.hh"
+
+class Gnome_DateEdit : public Gtk_HBox
+{public:
+	typedef Gtk_HBox Parent;
+	virtual const std::string TypeName(const Widget &w) const;
+	virtual const std::string IncludeName(const Widget &w) const;
+	Gnome_DateEdit();
+	virtual void Configure(const Widget &w, CxxFile &f,const std::string &instance) const;
+	virtual bool NeedExplicitCtor(const Widget &w) const
+	{  return true; }
+        virtual bool CantMemberConstruct(const Widget &w) const
+        {  return true; }
+	virtual void ConstructionArgs(Widget const &w, CxxFile &f) const;
+        virtual void CreatePointer(const Widget &w,CxxFile &f) const;
+};
+
+static Gnome_DateEdit Gnome_DateEdit;
+
+const std::string Gnome_DateEdit::TypeName(const Widget &w) const
+{  return GnomePrefix()+"DateEdit";
+}
+
+// Ugh, that's ugly, need a better way to specify multiple includes.
+const std::string Gnome_DateEdit::IncludeName(const Widget &w) const
+{  return "gnome--/dateedit.h>\n#include <time.h";
+}
+
+Gnome_DateEdit::Gnome_DateEdit()
+{  Writer["GnomeDateEdit"]=this;
+}
+
+void Gnome_DateEdit::Configure(const Widget &w, CxxFile &f,const std::string &instance) const
+{  Parent::Configure(w,f,instance);
+   int lower_hour(w.getInt("lower_hour"));
+   int upper_hour(w.getInt("upper_hour"));
+
+   if ( (lower_hour<0) || (upper_hour>23) || (lower_hour>upper_hour) )
+       cerr << "Warning: nonsensical values for time popup ranges for "
+            << w.Name() << endl;
+   
+   bool show_time(w.getBool("show_time"));
+   bool use_24_format(w.getBool("use_24_format"));
+   bool week_start_monday(w.getBool("week_start_monday"));
+
+   f.Statement() << instance << "set_popup_range(" << lower_hour
+                 << "," << upper_hour << ')';
+
+   std::string flags("GnomeDateEditFlags(0");
+   if (show_time)
+       flags += "|GNOME_DATE_EDIT_SHOW_TIME";
+   if (use_24_format)
+       flags += "|GNOME_DATE_EDIT_24_HR";
+   if (week_start_monday)
+       flags += "|GNOME_DATE_EDIT_WEEK_STARTS_ON_MONDAY";
+   flags += ")";
+   f.Statement() << instance << "set_flags(" << flags << ')';
+}
+
+void Gnome_DateEdit::ConstructionArgs(Widget const &w, CxxFile &f) const
+{
+   f.FunctionArg();
+
+   bool show_time(w.getBool("show_time"));
+   bool use_24_format(w.getBool("use_24_format"));
+
+   f << "time(NULL)," << PRINT_BOOL(show_time) << ',' <<
+       PRINT_BOOL(use_24_format);
+}
+
+void Gnome_DateEdit::CreatePointer(const Widget &w, CxxFile &f) const
+{
+   f.Declaration() << TypeName(w) << " *";
+   f << Configuration.InstanceName(w.Name());
+   f.Assignment();
+   f.FunctionName("manage").FunctionArg();
+   w.markManaged();
+   f.FunctionName("Gtk::wrap").FunctionArg();
+   f.FunctionName("GNOME_DATE_EDIT").FunctionArg();
+   f.FunctionName() << "gnome_date_edit_new";
+   ConstructionArgs(w,f);
+   f.EndLine();
+   CreatePointer_Toplevel(w,f);
+}
+
diff -Naur glade--/tests/Makefile.am glade--.gnome_dateedit/tests/Makefile.am
--- glade--/tests/Makefile.am	Tue Nov 20 16:31:21 2001
+++ glade--.gnome_dateedit/tests/Makefile.am	Mon Dec 17 22:00:49 2001
@@ -14,7 +14,8 @@
 	test29_methods.glade test34_menu_raw.glade test35_menu_gnome.glade \
 	test37_sig2sig.glade test38_gnm_dialog.glade \
 	test39_midgard.glade test40_filesel.glade test41_vscbar.glade \
-	test42_umlaute.glade test43_toolbar.glade test44_menu.glade
+	test42_umlaute.glade test43_toolbar.glade test44_menu.glade \
+	test45_gnome_dateedit.glade
 FUTURE_TESTS = test26_gnome.glade test36_gnome.glade
 # these tests require gtk--addons installed
 EXTRA_TESTS = test14_dispo.glade test15_SearchCombo.glade \
diff -Naur glade--/tests/test45_gnome_dateedit.glade glade--.gnome_dateedit/tests/test45_gnome_dateedit.glade
--- glade--/tests/test45_gnome_dateedit.glade	Thu Jan  1 00:00:00 1970
+++ glade--.gnome_dateedit/tests/test45_gnome_dateedit.glade	Mon Dec 17 22:00:04 2001
@@ -0,0 +1,295 @@
+<?xml version="1.0"?>
+<GTK-Interface>
+
+<project>
+  <name>test45_gnome_dateedit</name>
+  <program_name>test45_gnome_dateedit</program_name>
+  <directory></directory>
+  <source_directory>src</source_directory>
+  <pixmaps_directory>pixmaps</pixmaps_directory>
+  <language>C++</language>
+  <gnome_support>True</gnome_support>
+  <gettext_support>False</gettext_support>
+  <backup_source_files>False</backup_source_files>
+</project>
+
+<widget>
+  <class>GtkWindow</class>
+  <name>window1</name>
+  <title>window1</title>
+  <type>GTK_WINDOW_TOPLEVEL</type>
+  <position>GTK_WIN_POS_NONE</position>
+  <modal>False</modal>
+  <allow_shrink>False</allow_shrink>
+  <allow_grow>True</allow_grow>
+  <auto_shrink>False</auto_shrink>
+
+  <widget>
+    <class>GtkTable</class>
+    <name>table1</name>
+    <border_width>5</border_width>
+    <rows>4</rows>
+    <columns>2</columns>
+    <homogeneous>False</homogeneous>
+    <row_spacing>10</row_spacing>
+    <column_spacing>10</column_spacing>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame6</name>
+      <label>time=false, 24=false, monday=false</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>0</left_attach>
+	<right_attach>1</right_attach>
+	<top_attach>0</top_attach>
+	<bottom_attach>1</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>True</xexpand>
+	<yexpand>True</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit1</name>
+	<show_time>False</show_time>
+	<use_24_format>False</use_24_format>
+	<week_start_monday>False</week_start_monday>
+	<lower_hour>7</lower_hour>
+	<upper_hour>19</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame7</name>
+      <label>time=false, 24=false, monday=true</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>0</left_attach>
+	<right_attach>1</right_attach>
+	<top_attach>1</top_attach>
+	<bottom_attach>2</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>False</xexpand>
+	<yexpand>True</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit2</name>
+	<show_time>False</show_time>
+	<use_24_format>False</use_24_format>
+	<week_start_monday>True</week_start_monday>
+	<lower_hour>7</lower_hour>
+	<upper_hour>19</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame8</name>
+      <label>time=false, 24=true, monday=false</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>0</left_attach>
+	<right_attach>1</right_attach>
+	<top_attach>2</top_attach>
+	<bottom_attach>3</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>False</xexpand>
+	<yexpand>True</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit3</name>
+	<show_time>False</show_time>
+	<use_24_format>True</use_24_format>
+	<week_start_monday>False</week_start_monday>
+	<lower_hour>7</lower_hour>
+	<upper_hour>19</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame9</name>
+      <label>time=false, 24=true, monday=true</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>0</left_attach>
+	<right_attach>1</right_attach>
+	<top_attach>3</top_attach>
+	<bottom_attach>4</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>False</xexpand>
+	<yexpand>True</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit4</name>
+	<show_time>False</show_time>
+	<use_24_format>True</use_24_format>
+	<week_start_monday>True</week_start_monday>
+	<lower_hour>7</lower_hour>
+	<upper_hour>19</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame10</name>
+      <label>time=true, 24=false, monday=false, low=0, high=0</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>1</left_attach>
+	<right_attach>2</right_attach>
+	<top_attach>0</top_attach>
+	<bottom_attach>1</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>True</xexpand>
+	<yexpand>False</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit5</name>
+	<show_time>True</show_time>
+	<use_24_format>False</use_24_format>
+	<week_start_monday>False</week_start_monday>
+	<lower_hour>0</lower_hour>
+	<upper_hour>0</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame11</name>
+      <label>time=true, 24=false, monday=true, lo=23, high=23</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>1</left_attach>
+	<right_attach>2</right_attach>
+	<top_attach>1</top_attach>
+	<bottom_attach>2</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>False</xexpand>
+	<yexpand>False</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit6</name>
+	<show_time>True</show_time>
+	<use_24_format>False</use_24_format>
+	<week_start_monday>True</week_start_monday>
+	<lower_hour>23</lower_hour>
+	<upper_hour>23</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame12</name>
+      <label>time=true, 24=true, monday=false, lo=0, hi=23</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>1</left_attach>
+	<right_attach>2</right_attach>
+	<top_attach>2</top_attach>
+	<bottom_attach>3</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>False</xexpand>
+	<yexpand>False</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit7</name>
+	<show_time>True</show_time>
+	<use_24_format>True</use_24_format>
+	<week_start_monday>False</week_start_monday>
+	<lower_hour>0</lower_hour>
+	<upper_hour>23</upper_hour>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>frame13</name>
+      <label>time=true, 24=true, monday=true, lo=23, hi=0</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<left_attach>1</left_attach>
+	<right_attach>2</right_attach>
+	<top_attach>3</top_attach>
+	<bottom_attach>4</bottom_attach>
+	<xpad>0</xpad>
+	<ypad>0</ypad>
+	<xexpand>False</xexpand>
+	<yexpand>False</yexpand>
+	<xshrink>False</xshrink>
+	<yshrink>False</yshrink>
+	<xfill>True</xfill>
+	<yfill>True</yfill>
+      </child>
+
+      <widget>
+	<class>GnomeDateEdit</class>
+	<name>dateedit8</name>
+	<show_time>True</show_time>
+	<use_24_format>True</use_24_format>
+	<week_start_monday>True</week_start_monday>
+	<lower_hour>23</lower_hour>
+	<upper_hour>0</upper_hour>
+      </widget>
+    </widget>
+  </widget>
+</widget>
+
+</GTK-Interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]