1 // $Id: window.cc,v 1.43 2003/03/31 14:09:27 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 // AccelGroups really made it ugly
22
23 #include "window.hh"
24
25 static Gtk_Window Gtk_Window(false);
26
TypeName(const Widget & w) const27 const std::string Gtk_Window::TypeName(const Widget &w) const
28 { return GtkPrefix()+"Window";
29 }
30
IncludeName(const Widget & w) const31 const std::string Gtk_Window::IncludeName(const Widget &w) const
32 { return Configuration.GtkmmIncludePath()+"window.h";
33 }
34
Gtk_Window(bool base_class_init)35 Gtk_Window::Gtk_Window(bool base_class_init)
36 { if (!base_class_init) Writer["GtkWindow"]=this;
37 }
38
39 #if 0
40 void Gtk_Window::CInclude(const Widget &w,CxxFile &f) const
41 { Parent::CInclude(w,f)
42 if (Configuration.sample_code && !hasSignal("delete_event"))
43 f.Include(Configuration.GtkmmIncludePath()+"main.h");
44 }
45 #endif
46
ConstructionArgs(const Widget & w,CxxFile & f) const47 void Gtk_Window::ConstructionArgs(const Widget &w, CxxFile &f) const
48 { std::string type=w.getProperty("type","GTK_WINDOW_TOPLEVEL");
49 f.FunctionArg(Gtkmm2Namespace(type));
50 }
51
NeedExplicitCtor(const Widget & w) const52 bool Gtk_Window::NeedExplicitCtor(const Widget &w) const
53 { return w.hasProperty("type");
54 }
55
Configure(const Widget & w,CxxFile & f,const std::string & instance) const56 void Gtk_Window::Configure(const Widget &w, CxxFile &f,const std::string &instance) const
57 { Parent::Configure(w,f,instance);
58
59 WriteTranslatableProperty(w,f,instance, "title");
60 WriteIntIntProperty(w,f,instance, "default_width", "default_height", "default_size");
61 WriteBoolProperty(w,f,instance, "modal");
62
63 // or window_position ???
64 WriteEnumPropertyNS(w,f,instance, "position");
65 if (GTKMM2)
66 WriteEnumPropertyNS(w,f,instance, "window_position", true);
67
68 #if 1
69 // Compatibility cruft!
70 if (w.hasProperty("allow_shrink") ||
71 w.hasProperty("allow_grow") ||
72 w.hasProperty("auto_shrink"))
73 { bool allow_shrink=w.getBoolProperty("allow_shrink",false);
74 bool allow_grow=w.getBoolProperty("allow_grow",true);
75 bool auto_shrink=w.getBoolProperty("auto_shrink",false);
76 if (allow_shrink || !allow_grow || auto_shrink)
77 { if (GTKMM2)
78 { if (!allow_shrink && !allow_grow && auto_shrink)
79 f.Statement() << instance << "set_resizable(false)";
80 else
81 { std::cerr << w.Name() << ": non recommended window behaviour\n";
82 WriteBoolProperty(w,f,instance, "allow_shrink", true);
83 WriteBoolProperty(w,f,instance, "allow_grow", true);
84 // WriteBoolProperty(w,f,instance, "auto_shrink", true);
85 }
86 }
87 else
88 f.Statement() << instance << "set_policy("
89 << PRINT_BOOL(allow_shrink)
90 << ", " << PRINT_BOOL(allow_grow)
91 << ", " << PRINT_BOOL(auto_shrink) << ')';
92 }
93 }
94 #endif
95
96 if (GTKMM2)
97 WriteBoolProperty(w,f,instance, "resizable");
98
99 if (w.getBoolProperty("modal",false))
100 std::cerr << "To make your window modal you must also call set_transient_for()\n";
101
102 if (Configuration.has_accelerators && GTKMM1)
103 f.Statement() << instance << "add_accel_group(*(gmm_data->getAccelGroup()))";
104 if (GTKMM2)
105 WriteBoolProperty(w,f,instance, "destroy_with_parent", true);
106 }
107
108 #if 0
109 bool Gtk_Window::SampleCode(CxxFile &f,const Widget &w,enum WriterType::CodePosition pos,const std::string misc)
110 { switch(pos)
111 {
112 #if 0
113 case WriterType::ContainingConstructor: // not needed now ...
114 break;
115 #endif
116 case WriterType::Constructor:
117 { Widget::const_iterator i=w.get_Signals();
118 for (;i!=w.end() && (*i).getProperty("name","")!="delete_event";++i);
119 if (i==w.end())
120 { // 1.1: connect_to_method($1,$2,$3) => $1.connect(SigC::slot($2,$3))
121 f << "\tconnect_to_method(destroy, "
122 << GtkPrefix() << "Main::instance(), &"
123 << GtkPrefix() << "Main::quit);\n";
124 }
125 }
126 break;
127 default: break;
128 }
129 return false;
130 }
131 #endif
132
get_accelgroup(const Widget & w) const133 const Widget Gtk_Window::get_accelgroup(const Widget &w) const
134 { static Tag accelgroup("widget");
135 std::string name(Configuration.InstanceName(w.Name())+"_accgrp");
136 if (Widget(accelgroup).Name()==name)
137 { return Widget(accelgroup);
138 }
139 accelgroup=createWidgetTag("GtkAccelGroup", name);
140 Widget w2(accelgroup);
141 w2.setProperty(CXX_IS_MANAGED);
142 return w2;
143 }
144
CreatePointer(const Widget & w,CxxFile & f) const145 void Gtk_Window::CreatePointer(const Widget &w,CxxFile &f) const
146 { const bool never_reached(false);
147 assert(never_reached);
148 }
149
AdditionalMemberVars(const Widget & w,CxxFile & f,bool container) const150 void Gtk_Window::AdditionalMemberVars(const Widget &w,CxxFile &f,bool container) const
151 { if (Configuration.has_accelerators)
152 { Widget w2(get_accelgroup(w));
153 f.Private();
154 LookupWriter(w2).GHDeclaration(w2,f);
155 f.Declaration("GlademmData *gmm_data");
156 }
157 Parent::AdditionalMemberVars(w,f,container);
158 }
159
DestroyPointer(const Widget & w,CxxFile & f) const160 void Gtk_Window::DestroyPointer(const Widget &w,CxxFile &f) const
161 { const bool never_reached(false);
162 assert(never_reached);
163 }
164
ApplyPreferences(Tag & t) const165 void Gtk_Window::ApplyPreferences(Tag &t) const
166 { Parent::ApplyPreferences(t);
167 if (Configuration.has_accelerators)
168 { Widget w(&t);
169 static bool did_warn;
170 if (!did_warn && GTKMM1)
171 { did_warn=true;
172 std::cerr << "WARNING: accelerators break code compatibility.\n";
173 }
174 }
175 }
176
GCInclude(const Widget & w,CxxFile & f) const177 void Gtk_Window::GCInclude(const Widget &w, CxxFile &f) const
178 { if (Configuration.has_accelerators) // cheap assertion, doesn't hurt
179 { f.Include("gdk/gdkkeysyms.h");
180 Widget w2(get_accelgroup(w));
181 LookupWriter(w2).GCInclude(w2,f);
182 }
183 }
184
ClassConstructor(const Widget & w,CxxFile & f) const185 void Gtk_Window::ClassConstructor(const Widget &w, CxxFile &f) const
186 { Parent::ClassConstructor(w,f);
187 if (Configuration.has_accelerators)
188 { if (GTKMM1)
189 { Widget w2(get_accelgroup(w));
190 LookupWriter(w2).CreatePointer(w2,f);
191 f.Statement("gmm_data").Assignment("new ").FunctionName("GlademmData")
192 .FunctionArg(Pointer(w2));
193 }
194 else
195 { f.Statement("gmm_data").Assignment("new ").FunctionName("GlademmData")
196 .FunctionArg("get_accel_group()");
197 }
198 f.EndLine();
199 }
200 }
201
ClassDestructor(const Widget & w,CxxFile & f) const202 void Gtk_Window::ClassDestructor(const Widget &w, CxxFile &f) const
203 { if (Configuration.has_accelerators)
204 { if (GTKMM1)
205 { Widget w2(get_accelgroup(w));
206 LookupWriter(w2).DestroyPointer(w2,f);
207 }
208 f.Statement("delete gmm_data").EndLine();
209 }
210 Parent::ClassDestructor(w,f);
211 }
212
213