1 // $Id: menu.cc,v 1.35 2002/06/24 15:34:52 christof Exp $
2 /*  glade--: C++ frontend for glade (Gtk+ User Interface Builder)
3  *  Copyright (C) 1998  Christof Petig
4  *  Copyright (C) 1999-2000 Adolf Petig GmbH & Co. KG, written by Christof Petig
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 #include "container.hh"
22 #include "menuitem.hh"
23 #include <typeinfo>
24 
25 class Gtk_Menu : public Gtk_Container
26 {public:
27 	typedef Gtk_Container Parent;
28 	virtual const std::string TypeName(const Widget &w) const;
29 	virtual const std::string IncludeName(const Widget &w) const;
30 	Gtk_Menu();
AddChild(const Widget & w,CxxFile & f,const std::string & instance) const31 	virtual void AddChild(const Widget &w,CxxFile &f,const std::string &instance) const
32 	{}
NeedExplicitCtor(const Widget & w) const33 	virtual bool NeedExplicitCtor(const Widget &w) const
34 	{  return false; }
ConstructionArgs(Widget const & w,CxxFile & f) const35 	virtual void ConstructionArgs(Widget const &w, CxxFile &f) const
36 	{  f.FunctionArg(); }
37 	virtual void CreatePointer_depending(const Widget &w,CxxFile &f) const;
38 };
39 
40 static Gtk_Menu Gtk_Menu;
41 
TypeName(const Widget & w) const42 const std::string Gtk_Menu::TypeName(const Widget &w) const
43 {  return GtkPrefix()+"Menu";
44 }
45 
IncludeName(const Widget & w) const46 const std::string Gtk_Menu::IncludeName(const Widget &w) const
47 {  return Configuration.GtkmmIncludePath()+"menu.h";
48 }
49 
Gtk_Menu()50 Gtk_Menu::Gtk_Menu()
51 {  Writer["GtkMenu"]=this;
52 }
53 
CreatePointer_depending(const Widget & w,CxxFile & f) const54 void Gtk_Menu::CreatePointer_depending(const Widget &w,CxxFile &f) const
55 {  if (!Configuration.gnome_support)
56    {  for (Widget::const_iterator i=w.begin();i!=w.end();++i)
57          PushMenuElem(*i, f, Configuration.InstanceName(w.Name())+"->");
58    }
59    Parent::CreatePointer_depending(w,f);
60 }
61 
62 // this should go into a different class - but which ?
PushMenuElem(const Widget & w,CxxFile & f,const std::string & instance) const63 void Gtk_Container::PushMenuElem(const Widget &w,CxxFile &f,
64 				 const std::string &instance) const
65 { try
66   { const Gtk_MenuItem &wr=dynamic_cast<const Gtk_MenuItem &>(LookupWriter(w));
67     std::string childInstance=Configuration.InstanceName(w.Name()) + "->";
68 
69     f.Declaration();		// *** Necessary to get state right.
70     f.FunctionName() << instance << "items().push_back";
71     f.FunctionArg();
72     wr.MenuElemCreation(w,f);
73 
74     f.Statement() << Configuration.InstanceName(w.Name());
75     f.Assignment() << "(" << wr.TypeName(w) << " *)";
76     if (Configuration.gtkmm_version>=Pkg_Version(1,3,17)) f << '&';
77     f << instance << "items().back()";
78 
79     // is this really needed?
80 //    wr.Configure(w,f,Configuration.InstanceName(w.Name())+"->");
81   }
82   catch (std::bad_cast &e) {
83     f.Statement() << instance << "append(" << Reference(w) << ')';
84   }
85 }
86