formscript.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "formscript.h"
21#include "scriptmanager.h"
22
23#include "form.h"
24#include "objecttree.h"
25// Kross Includes
26#include "main/manager.h"
27#include "main/scriptcontainer.h"
28#include "api/exception.h"
29
30#include <kdebug.h>
31
32using namespace KFormDesigner;
33
34FormScript::FormScript(Form *form, ScriptManager *manager, const char *name)
35 : TQObject(manager, name), m_manager(manager), m_form(form)
36{
37 m_script = manager->krossManager()->getScriptContainer(form->widget()->name());
38}
39
40FormScript::~FormScript()
41{
42}
43
44TQString
45FormScript::getCode(const TQString &)
46{
48 return m_script->getCode();
49}
50
51void
52FormScript::setCode(const TQString &code)
53{
54 m_script->setCode(code);
55}
56
57void
59{
60 TQString s = m_script->getCode();
61 s.append("\n");
62 s.append(code);
63 m_script->setCode(s);
64}
65
66bool
68{
70 try {
71 m_script->callFunction(functionName);
72 }
73 catch(Kross::Api::Exception& e) {
74 kdDebug() << TQString("EXCEPTION type='%1' description='%2'").arg(e.type()).arg(e.description()) << endl;
75 return false;
76 }
77 return true;
78}
79
80void
82{
83 if(!m_form || !m_form->objectTree())
84 return;
85 // first call addTQObject for each widget in the Form
86 ObjectTreeDict *dict = m_form->objectTree()->dict();
88 for(; it.current(); ++it)
89 m_script->addTQObject(it.current()->widget());
90 m_script->addTQObject(m_form->widget());
91
92 // Then we connect all signals
93 TQValueListConstIterator<Event*> endIt = m_list.constEnd();
94 for(TQValueListConstIterator<Event*> it = m_list.constBegin(); it != endIt; ++it) {
95 if( (*it)->type() == Event::Slot) {
96 connect((*it)->sender(), (*it)->signal(), (*it)->receiver(), (*it)->slot());
97 }
98 else if( (*it)->type() == Event::UserFunction) {
99 m_script->connect((*it)->sender(), (*it)->signal(), (*it)->slot());
100 }
101 else if( (*it)->type() == Event::Action) {
103 }
104 }
105}
106
107
108#include "formscript.moc"
109
bool execute(const TQString &functionName)
TQString getCode(const TQString &functionName=TQString())
void connectEvents()
void setCode(const TQString &code)
void appendCode(const TQString &code)
A simple class representing a form.
Definition form.h:136
ObjectTree * objectTree() const
Definition form.h:167
TQWidget * widget() const
Definition form.cpp:114
ObjectTreeDict * dict()
Definition objecttree.h:157
TQDictIterator< ObjectTreeItem > ObjectTreeDictIterator
An iterator for ObjectTreeDict.
Definition objecttree.h:51
type * findParent(TQObject *o, const char *className, TQObject *&prevPrev)
TQDict< ObjectTreeItem > ObjectTreeDict
A TQString-based disctionary of ObjectTreeItem pointers.
Definition objecttree.h:48