diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /tools/designer/plugins/cppeditor | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'tools/designer/plugins/cppeditor')
26 files changed, 4286 insertions, 0 deletions
diff --git a/tools/designer/plugins/cppeditor/common.cpp b/tools/designer/plugins/cppeditor/common.cpp new file mode 100644 index 000000000..661b85b0b --- /dev/null +++ b/tools/designer/plugins/cppeditor/common.cpp @@ -0,0 +1,111 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "editorinterfaceimpl.h" +#include "languageinterfaceimpl.h" +#include "preferenceinterfaceimpl.h" +#include "projectsettingsinterfaceimpl.h" +#include "sourcetemplateinterfaceimpl.h" + +class CommonInterface : public TQComponentInformationInterface +{ +public: + CommonInterface(); + virtual ~CommonInterface(); + + TQRESULT queryInterface( const TQUuid&, TQUnknownInterface** ); + Q_REFCOUNT; + + TQString name() const { return "C++"; } + TQString description() const { return "C++ Integration"; } + TQString version() const { return "0.1"; } + TQString author() const { return "Trolltech AS"; } + +private: + LanguageInterfaceImpl *langIface; + PreferenceInterfaceImpl *prefIface; + ProjectSettingsInterfaceImpl *proIface; + SourceTemplateInterfaceImpl *srcIface; + +}; + +CommonInterface::CommonInterface() +{ + langIface = new LanguageInterfaceImpl( this ); + langIface->addRef(); + prefIface = new PreferenceInterfaceImpl( this ); + prefIface->addRef(); + proIface = new ProjectSettingsInterfaceImpl( this ); + proIface->addRef(); + srcIface = new SourceTemplateInterfaceImpl; + srcIface->addRef(); +} + +CommonInterface::~CommonInterface() +{ + langIface->release(); + prefIface->release(); + proIface->release(); + srcIface->release(); +} + +TQRESULT CommonInterface::queryInterface( const TQUuid &uuid, TQUnknownInterface** iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = (TQUnknownInterface*)this; + else if ( uuid == IID_QComponentInformation ) + *iface = (TQComponentInformationInterface*)this; + else if ( uuid == IID_Editor ) + *iface = new EditorInterfaceImpl; + else if ( uuid == IID_Language ) + *iface = langIface; + else if ( uuid == IID_Preference ) + *iface = prefIface; + else if ( uuid == IID_ProjectSettings ) + *iface = proIface; + else if ( uuid == IID_SourceTemplate ) + *iface = srcIface; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} + + +Q_EXPORT_COMPONENT() +{ + Q_CREATE_INSTANCE( CommonInterface ) +} diff --git a/tools/designer/plugins/cppeditor/cppbrowser.cpp b/tools/designer/plugins/cppeditor/cppbrowser.cpp new file mode 100644 index 000000000..169e30dd5 --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppbrowser.cpp @@ -0,0 +1,78 @@ +/********************************************************************** +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "cppbrowser.h" +#include <private/qrichtext_p.h> +#include <qprocess.h> +#include <qmainwindow.h> +#include <qstatusbar.h> +#include <editor.h> + +CppEditorBrowser::CppEditorBrowser( Editor *e ) + : EditorBrowser( e ) +{ +} + +void CppEditorBrowser::showHelp( const TQString &w ) +{ + TQString word( w ); + if ( word[ 0 ] == 'Q' ) { + if ( word[ (int)word.length() - 1 ] == '&' || + word[ (int)word.length() - 1 ] == '*' ) + word.remove( word.length() - 1, 1 ); + word = word.lower() + ".html"; + TQStringList lst; + lst << "assistant" << "-file" << word; + TQProcess proc( lst ); + proc.start(); + return; + } + + if ( word.find( '(' ) != -1 ) { + TQString txt = "::" + word.left( word.find( '(' ) ); + TQTextDocument *doc = curEditor->document(); + TQTextParagraph *p = doc->firstParagraph(); + while ( p ) { + if ( p->string()->toString().find( txt ) != -1 ) { + curEditor->setCursorPosition( p->paragId(), 0 ); + return; + } + p = p->next(); + } + } + + TQMainWindow *mw = ::qt_cast<TQMainWindow*>(curEditor->topLevelWidget()); + if ( mw ) + mw->statusBar()->message( tr( "Nothing available for '%1'" ).arg( w ), 1500 ); +} diff --git a/tools/designer/plugins/cppeditor/cppbrowser.h b/tools/designer/plugins/cppeditor/cppbrowser.h new file mode 100644 index 000000000..065802500 --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppbrowser.h @@ -0,0 +1,50 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef CPPBROWSER_H +#define CPPBROWSER_H + +#include <browser.h> + +class CppEditorBrowser : public EditorBrowser +{ + Q_OBJECT + +public: + CppEditorBrowser( Editor *e ); + void showHelp( const TQString &word ); + +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/cppcompletion.cpp b/tools/designer/plugins/cppeditor/cppcompletion.cpp new file mode 100644 index 000000000..97f226f28 --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppcompletion.cpp @@ -0,0 +1,220 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "cppcompletion.h" +#include <qobject.h> +#include <qmetaobject.h> +#include <qobjectlist.h> +#include <qregexp.h> + +CppEditorCompletion::CppEditorCompletion( Editor *e ) + : EditorCompletion( e ) +{ +} + +bool CppEditorCompletion::doObjectCompletion( const TQString &objName ) +{ + if ( !ths ) + return FALSE; + TQString object( objName ); + int i = -1; + if ( ( i = object.findRev( "->" ) ) != -1 ) + object = object.mid( i + 2 ); + if ( ( i = object.findRev( "." ) ) != -1 ) + object = object.mid( i + 1 ); + object = object.simplifyWhiteSpace(); + TQObject *obj = 0; + if ( ths->name() == object || object == "this" ) { + obj = ths; + } else { + obj = ths->child( object ); + } + + if ( !obj ) + return FALSE; + + TQValueList<CompletionEntry> lst; + + if ( obj->children() ) { + for ( TQObjectListIt cit( *obj->children() ); cit.current(); ++cit ) { + TQString s( cit.current()->name() ); + if ( s.find( " " ) == -1 && s.find( "qt_" ) == -1 && s.find( "unnamed" ) == -1 ) { + CompletionEntry c; + c.type = "variable"; + c.text = s; + c.prefix = ""; + lst << c; + } + } + } + + TQStrList props = obj->metaObject()->propertyNames( TRUE ); + for ( TQPtrListIterator<char> pit( props ); pit.current(); ++pit ) { + TQString f( pit.current() ); + TQChar c = f[ 0 ]; + f.remove( (uint)0, 1 ); + f.prepend( c.upper() ); + f.prepend( "set" ); + + CompletionEntry ce; + ce.type = "property"; + ce.text = f; + ce.postfix = "()"; + + if ( lst.find( ce ) == lst.end() ) + lst << ce; + } + + TQStrList slts = obj->metaObject()->slotNames( TRUE ); + for ( TQPtrListIterator<char> sit( slts ); sit.current(); ++sit ) { + TQString f( sit.current() ); + f = f.left( f.find( "(" ) ); + CompletionEntry c; + c.type = "slot"; + c.text = f; + c.postfix = "()"; + if ( lst.find( c ) == lst.end() ) + lst << c; + } + + if ( lst.isEmpty() ) + return FALSE; + + showCompletion( lst ); + return TRUE; +} + +TQValueList<TQStringList> CppEditorCompletion::functionParameters( const TQString &expr, TQChar &separator, + TQString &prefix, TQString &postfix ) +{ + Q_UNUSED( prefix ); + Q_UNUSED( postfix ); + separator = ','; + if ( !ths ) + return TQValueList<TQStringList>(); + TQString func; + TQString objName; + int i = -1; + + i = expr.findRev( "->" ); + if ( i == -1 ) + i = expr.findRev( "." ); + else + ++i; + if ( i == -1 ) { + i = expr.findRev( " " ); + + if ( i == -1 ) + i = expr.findRev( "\t" ); + else + objName = ths->name(); + + if ( i == -1 && expr[ 0 ] != ' ' && expr[ 0 ] != '\t' ) + objName = ths->name(); + } + + if ( !objName.isEmpty() ) { + func = expr.mid( i + 1 ); + func = func.simplifyWhiteSpace(); + } else { + func = expr.mid( i + 1 ); + func = func.simplifyWhiteSpace(); + TQString ex( expr ); + ex.remove( i, 0xFFFFFF ); + if ( ex[ (int)ex.length() - 1 ] == '-' ) + ex.remove( ex.length() - 1, 1 ); + int j = -1; + j = ex.findRev( "->" ); + if ( j == -1 ) + j = ex.findRev( "." ); + else + ++j; + if ( j == -1 ) { + j = ex.findRev( " " ); + + if ( j == -1 ) + j = ex.findRev( "\t" ); + else + objName = ths->name(); + + if ( j == -1 ) + objName = ths->name(); + } + objName = ex.mid( j + 1 ); + objName = objName.simplifyWhiteSpace(); + } + + TQObject *obj = 0; + if ( ths->name() == objName || objName == "this" ) { + obj = ths; + } else { + obj = ths->child( objName ); + } + + if ( !obj ) + return TQValueList<TQStringList>(); + + TQStrList slts = obj->metaObject()->slotNames( TRUE ); + for ( TQPtrListIterator<char> sit( slts ); sit.current(); ++sit ) { + TQString f( sit.current() ); + f = f.left( f.find( "(" ) ); + if ( f == func ) { + f = TQString( sit.current() ); + f.remove( (uint)0, f.find( "(" ) + 1 ); + f = f.left( f.find( ")" ) ); + TQStringList lst = TQStringList::split( ',', f ); + if ( !lst.isEmpty() ) { + TQValueList<TQStringList> l; + l << lst; + return l; + } + } + } + + const TQMetaProperty *prop = + obj->metaObject()-> + property( obj->metaObject()->findProperty( func[ 3 ].lower() + func.mid( 4 ), TRUE ), TRUE ); + if ( prop ) { + TQValueList<TQStringList> l; + l << TQStringList( prop->type() ); + return l; + } + + return TQValueList<TQStringList>(); +} + +void CppEditorCompletion::setContext( TQObject *this_ ) +{ + ths = this_; +} diff --git a/tools/designer/plugins/cppeditor/cppcompletion.h b/tools/designer/plugins/cppeditor/cppcompletion.h new file mode 100644 index 000000000..abc0c90ad --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppcompletion.h @@ -0,0 +1,60 @@ +/********************************************************************** +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef CPPCOMPLETION_H +#define CPPCOMPLETION_H + +#include <completion.h> +#include <qguardedptr.h> + +class CppEditorCompletion : public EditorCompletion +{ + Q_OBJECT + +public: + CppEditorCompletion( Editor *e ); + +#if defined(Q_USING) + using EditorCompletion::doObjectCompletion; +#endif + bool doObjectCompletion( const TQString &object ); + TQValueList<TQStringList> functionParameters( const TQString &func, TQChar &, TQString &prefix, TQString &postfix ); + void setContext( TQObject *this_ ); + +private: + TQGuardedPtr<TQObject> ths; + +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/cppeditor.cpp b/tools/designer/plugins/cppeditor/cppeditor.cpp new file mode 100644 index 000000000..399afa521 --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppeditor.cpp @@ -0,0 +1,168 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "cppeditor.h" +#include "syntaxhighliter_cpp.h" +#include <cindent.h> +#include "cppcompletion.h" +#include "cppbrowser.h" +#include <parenmatcher.h> +#include <qsettings.h> +#include <qpopupmenu.h> +#include <qinputdialog.h> +#include <designerinterface.h> + +CppEditor::CppEditor( const TQString &fn, TQWidget *parent, const char *name, DesignerInterface *i ) + : Editor( fn, parent, name ), dIface( i ) +{ + if ( dIface ) + dIface->addRef(); + document()->setPreProcessor( new SyntaxHighlighter_CPP ); + document()->setIndent( (indent = new CIndent) ); + completion = new CppEditorCompletion( this ); + browser = new CppEditorBrowser( this ); + int j = 0; + while ( SyntaxHighlighter_CPP::keywords[ j ] != TQString::null ) + completion->addCompletionEntry( SyntaxHighlighter_CPP::keywords[ j++ ], 0, FALSE ); + configChanged(); +} + +CppEditor::~CppEditor() +{ + delete completion; + if ( dIface ) + dIface->release(); +} + +void CppEditor::configChanged() +{ + TQString path = "/Trolltech/CppEditor/"; + TQMap<TQString, ConfigStyle> styles = Config::readStyles( path ); + config()->styles = styles; + ( (SyntaxHighlighter_CPP*)document()->preProcessor() )->updateStyles( config()->styles ); + + completion->setEnabled( Config::completion( path ) ); + parenMatcher->setEnabled( Config::parenMatching( path ) ); + if ( Config::wordWrap( path ) ) { + if ( hScrollBarMode() != AlwaysOff ) { + document()->setFormatter( new TQTextFormatterBreakInWords ); + setHScrollBarMode( AlwaysOff ); + } + } else { + if ( hScrollBarMode() != AlwaysOn ) { + TQTextFormatterBreakWords *f = new TQTextFormatterBreakWords; + f->setWrapEnabled( FALSE ); + document()->setFormatter( f ); + setHScrollBarMode( AlwaysOn ); + } + } + + setFont( ( (SyntaxHighlighter_CPP*)document()->preProcessor() )->format( 0 )->font() ); + + indent->setTabSize( Config::indentTabSize( path ) ); + indent->setIndentSize( Config::indentIndentSize( path ) ); + indent->setKeepTabs( Config::indentKeepTabs( path ) ); + indent->setAutoIndent( Config::indentAutoIndent( path ) ); + if ( !Config::indentAutoIndent( path ) ) + document()->setIndent( 0 ); + else + document()->setIndent( indent ); + + document()->setTabStops( ( (SyntaxHighlighter_CPP*)document()->preProcessor() )->format( TQTextPreProcessor::Standard )->width( 'x' ) * Config::indentTabSize( path ) ); + + Editor::configChanged(); +} + +TQPopupMenu *CppEditor::createPopupMenu( const TQPoint &p ) +{ + TQPopupMenu *m = Editor::createPopupMenu( p ); + m->insertSeparator(); + int adddeclid = m->insertItem( tr( "Add Include File (in Declaration)..." ), this, SLOT( addInclDecl() ) ); + int addimplid = m->insertItem( tr( "Add Include File (in Implementation)..." ), this, SLOT( addInclImpl() ) ); + int addforid = m->insertItem( tr( "Add Forward Declaration..." ), this, SLOT( addForward() ) ); + if ( !dIface->currentForm() ) { + m->setItemEnabled( adddeclid, FALSE ); + m->setItemEnabled( addimplid, FALSE ); + m->setItemEnabled( addforid, FALSE ); + } + return m; +} + +void CppEditor::addInclDecl() +{ + if ( !dIface ) + return; + TQString s = TQInputDialog::getText( tr( "Add Include File (In Declaration)" ), + tr( "Input this using the format <b><include.h></b> or <b>\"include.h\"</b>" ) ); + if ( s.isEmpty() ) + return; + DesignerFormWindow *form = dIface->currentForm(); + TQStringList lst = form->declarationIncludes(); + lst << s; + form->setDeclarationIncludes( lst ); +} + +void CppEditor::addInclImpl() +{ + if ( !dIface ) + return; + TQString s = TQInputDialog::getText( tr( "Add Include File (In Implementation)" ), + tr( "Input this using the format <b><include.h></b> or <b>\"include.h\"</b>" ) ); + if ( s.isEmpty() ) + return; + DesignerFormWindow *form = dIface->currentForm(); + TQStringList lst = form->implementationIncludes(); + lst << s; + form->setImplementationIncludes( lst ); +} + +void CppEditor::addForward() +{ + if ( !dIface ) + return; + TQString s = TQInputDialog::getText( tr( "Add Forward Declaration" ), + tr( "Input this using the format <b>ClassName;</b>" ) ); + if ( s.isEmpty() ) + return; + DesignerFormWindow *form = dIface->currentForm(); + TQStringList lst = form->forwardDeclarations(); + lst << s; + form->setForwardDeclarations( lst ); +} + +void CppEditor::paste() +{ + Editor::paste(); + emit intervalChanged(); +} diff --git a/tools/designer/plugins/cppeditor/cppeditor.h b/tools/designer/plugins/cppeditor/cppeditor.h new file mode 100644 index 000000000..b0cd64fc2 --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppeditor.h @@ -0,0 +1,78 @@ +/********************************************************************** +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef CPPEDITOR_H +#define CPPEDITOR_H + +#include <editor.h> + +class EditorCompletion; +class EditorBrowser; +struct DesignerInterface; +class CIndent; + +class CppEditor : public Editor +{ + Q_OBJECT + +public: + CppEditor( const TQString &fn, TQWidget *parent, const char *name, DesignerInterface *i ); + ~CppEditor(); + + virtual EditorCompletion *completionManager() { return completion; } + virtual EditorBrowser *browserManager() { return browser; } + void configChanged(); + + bool supportsBreakPoints() const { return FALSE; } +#if defined(Q_USING) + using TQTextEdit::createPopupMenu; +#endif + TQPopupMenu *createPopupMenu( const TQPoint &p ); + + void paste(); + +private slots: + void addInclDecl(); + void addInclImpl(); + void addForward(); + +protected: + EditorCompletion *completion; + EditorBrowser *browser; + DesignerInterface *dIface; + CIndent *indent; + +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/cppeditor.pro b/tools/designer/plugins/cppeditor/cppeditor.pro new file mode 100644 index 000000000..391c1d73e --- /dev/null +++ b/tools/designer/plugins/cppeditor/cppeditor.pro @@ -0,0 +1,21 @@ +TEMPLATE = lib +CONFIG += qt warn_on plugin + +SOURCES += cppeditor.cpp syntaxhighliter_cpp.cpp cppcompletion.cpp editorinterfaceimpl.cpp languageinterfaceimpl.cpp common.cpp preferenceinterfaceimpl.cpp yyreg.cpp cppbrowser.cpp projectsettingsinterfaceimpl.cpp sourcetemplateinterfaceimpl.cpp +HEADERS += cppeditor.h syntaxhighliter_cpp.h cppcompletion.h editorinterfaceimpl.h languageinterfaceimpl.h preferenceinterfaceimpl.h yyreg.h cppbrowser.h projectsettingsinterfaceimpl.h sourcetemplateinterfaceimpl.h +FORMS = projectsettings.ui mainfilesettings.ui + +TARGET = cppeditor +DESTDIR = ../../../../plugins/designer +VERSION = 1.0.0 + +INCLUDEPATH += ../../interfaces ../../editor $$QT_BUILD_TREE/tools/designer/editor + +hpux-* { + LIBS += $$QT_BUILD_TREE/lib/libeditor.a +} else { + LIBS += -L$$QT_BUILD_TREE/lib -leditor +} + +target.path += $$plugins.path/designer +INSTALLS += target diff --git a/tools/designer/plugins/cppeditor/editorinterfaceimpl.cpp b/tools/designer/plugins/cppeditor/editorinterfaceimpl.cpp new file mode 100644 index 000000000..3816727dd --- /dev/null +++ b/tools/designer/plugins/cppeditor/editorinterfaceimpl.cpp @@ -0,0 +1,338 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "editorinterfaceimpl.h" +#include <viewmanager.h> +#include "cppeditor.h" +#include <private/qrichtext_p.h> +#include <qapplication.h> +#include "completion.h" +#include <designerinterface.h> +#include <qtimer.h> + +EditorInterfaceImpl::EditorInterfaceImpl() + : EditorInterface(), viewManager( 0 ), dIface( 0 ) +{ + updateTimer = new TQTimer( this ); + connect( updateTimer, SIGNAL( timeout() ), + this, SLOT( update() ) ); +} + +EditorInterfaceImpl::~EditorInterfaceImpl() +{ + updateTimer->stop(); + delete (ViewManager*)viewManager; + if ( dIface ) + dIface->release(); +} + +TQRESULT EditorInterfaceImpl::queryInterface( const TQUuid &uuid, TQUnknownInterface** iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = (TQUnknownInterface*)this; + else if ( uuid == IID_Editor ) + *iface = (EditorInterface*)this; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} + +TQWidget *EditorInterfaceImpl::editor( bool readonly, + TQWidget *parent, TQUnknownInterface *iface ) +{ + if ( !viewManager ) { + ( (EditorInterfaceImpl*)this )->viewManager = new ViewManager( parent, 0 ); + ( (EditorInterfaceImpl*)this )->viewManager->showMarkerWidget( FALSE ); + if ( iface ) + iface->queryInterface( IID_Designer, (TQUnknownInterface**) &dIface ); + CppEditor *e = new CppEditor( TQString::null, viewManager, "editor", dIface ); + e->setEditable( !readonly ); + e->installEventFilter( this ); + connect( e, SIGNAL( intervalChanged() ), this, SLOT( intervalChanged() ) ); + TQApplication::sendPostedEvents( viewManager, TQEvent::ChildInserted ); + } + return viewManager->currentView(); +} + +void EditorInterfaceImpl::setText( const TQString &txt ) +{ + if ( !viewManager || !viewManager->currentView() ) + return; + CppEditor *e = (CppEditor*)viewManager->currentView(); + disconnect( e, SIGNAL( modificationChanged( bool ) ), this, SLOT( modificationChanged( bool ) ) ); + e->setText( txt ); + e->setModified( FALSE ); + connect( e, SIGNAL( modificationChanged( bool ) ), this, SLOT( modificationChanged( bool ) ) ); +} + +TQString EditorInterfaceImpl::text() const +{ + if ( !viewManager || !viewManager->currentView() ) + return TQString::null; + TQString txt = ( (CppEditor*)viewManager->currentView() )->text(); + if ( !txt.isEmpty() && !txt.endsWith("\n") ) + txt += "\n"; + return txt; +} + +bool EditorInterfaceImpl::isUndoAvailable() const +{ + if ( !viewManager || !viewManager->currentView() ) + return FALSE; + return ( (CppEditor*)viewManager->currentView() )->isUndoAvailable(); +} + +bool EditorInterfaceImpl::isRedoAvailable() const +{ + if ( !viewManager || !viewManager->currentView() ) + return FALSE; + return ( (CppEditor*)viewManager->currentView() )->isRedoAvailable(); +} + +void EditorInterfaceImpl::undo() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->undo(); +} + +void EditorInterfaceImpl::redo() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->redo(); +} + +void EditorInterfaceImpl::cut() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->cut(); +} + +void EditorInterfaceImpl::copy() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->copy(); +} + +void EditorInterfaceImpl::paste() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->paste(); +} + +void EditorInterfaceImpl::selectAll() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->selectAll(); +} + +bool EditorInterfaceImpl::find( const TQString &expr, bool cs, bool wo, bool forward, bool startAtCursor ) +{ + if ( !viewManager || !viewManager->currentView() ) + return FALSE; + CppEditor *e = (CppEditor*)viewManager->currentView(); + if ( startAtCursor ) + return e->find( expr, cs, wo, forward ); + int dummy = 0; + return e->find( expr, cs, wo, forward, &dummy, &dummy ); +} + +bool EditorInterfaceImpl::replace( const TQString &find, const TQString &replace, bool cs, bool wo, + bool forward, bool startAtCursor, bool replaceAll ) +{ + if ( !viewManager || !viewManager->currentView() ) + return FALSE; + CppEditor *e = (CppEditor*)viewManager->currentView(); + bool ok = FALSE; + if ( startAtCursor ) { + ok = e->find( find, cs, wo, forward ); + } else { + int dummy = 0; + ok = e->find( find, cs, wo, forward, &dummy, &dummy ); + } + + if ( ok ) { + e->removeSelectedText(); + e->insert( replace, FALSE, FALSE ); + } + + if ( !replaceAll || !ok ) { + if ( ok ) + e->setSelection( e->textCursor()->paragraph()->paragId(), + e->textCursor()->index() - replace.length(), + e->textCursor()->paragraph()->paragId(), + e->textCursor()->index() ); + return ok; + } + + bool ok2 = TRUE; + while ( ok2 ) { + ok2 = e->find( find, cs, wo, forward ); + if ( ok2 ) { + e->removeSelectedText(); + e->insert( replace, FALSE, FALSE ); + } + } + + return TRUE; +} + +void EditorInterfaceImpl::gotoLine( int line ) +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->setCursorPosition( line, 0 ); +} + +void EditorInterfaceImpl::indent() +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->TQTextEdit::indent(); +} + +void EditorInterfaceImpl::splitView() +{ +#if 0 + if ( !viewManager || !viewManager->currentView() ) + return; + TQTextDocument *doc = ( (CppEditor*)viewManager->currentView() )->document(); + CppEditor *editor = new CppEditor( TQString::null, viewManager, "editor" ); + editor->setDocument( doc ); +#endif +} + +void EditorInterfaceImpl::scrollTo( const TQString &txt, const TQString & ) +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->sync(); + TQTextDocument *doc = ( (CppEditor*)viewManager->currentView() )->document(); + TQTextParagraph *p = doc->firstParagraph(); + while ( p ) { + if ( p->string()->toString().find( txt ) != -1 ) { + ( (CppEditor*)viewManager->currentView() )->setCursorPosition( p->paragId() + 2, 0 ); + break; + } + p = p->next(); + } + ( (CppEditor*)viewManager->currentView() )->setFocus(); +} + +void EditorInterfaceImpl::setContext( TQObject *this_ ) +{ + if ( !viewManager || !viewManager->currentView() ) + return; + ( (CppEditor*)viewManager->currentView() )->completionManager()->setContext( this_ ); +} + +void EditorInterfaceImpl::setError( int line ) +{ + if ( !viewManager ) + return; + viewManager->setError( line ); +} + +void EditorInterfaceImpl::readSettings() +{ + if ( !viewManager ) + return; + ( (CppEditor*)viewManager->currentView() )->configChanged(); +} + +void EditorInterfaceImpl::modificationChanged( bool m ) +{ + if ( viewManager && dIface ) + dIface->setModified( m, viewManager->currentView() ); +} + +void EditorInterfaceImpl::setModified( bool m ) +{ + if ( !viewManager ) + return; + ( (CppEditor*)viewManager->currentView() )->setModified( m ); +} + +bool EditorInterfaceImpl::isModified() const +{ + if ( !viewManager ) + return FALSE; + return ( (CppEditor*)viewManager->currentView() )->isModified(); +} + +bool EditorInterfaceImpl::eventFilter( TQObject *o, TQEvent *e ) +{ + if ( e->type() == TQEvent::KeyPress ) + updateTimer->stop(); + else if ( e->type() == TQEvent::FocusOut ) + update(); + + return TQObject::eventFilter( o, e ); +} + +int EditorInterfaceImpl::numLines() const +{ + if ( !viewManager || !viewManager->currentView() ) + return 0; + return ( (CppEditor*)viewManager->currentView() )->paragraphs(); +} + +void EditorInterfaceImpl::intervalChanged() +{ + if ( !dIface ) + return; + updateTimer->start( 2000, TRUE ); +} + +void EditorInterfaceImpl::update() +{ + if ( !dIface ) + return; + dIface->updateFunctionList(); +} + +void EditorInterfaceImpl::onBreakPointChange( TQObject *receiver, const char *slot ) +{ + if ( !viewManager ) + return; + connect( viewManager, SIGNAL( markersChanged() ), receiver, slot ); +} diff --git a/tools/designer/plugins/cppeditor/editorinterfaceimpl.h b/tools/designer/plugins/cppeditor/editorinterfaceimpl.h new file mode 100644 index 000000000..3ad411bd7 --- /dev/null +++ b/tools/designer/plugins/cppeditor/editorinterfaceimpl.h @@ -0,0 +1,107 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef EDITORINTERFACEIMPL_H +#define EDITORINTERFACEIMPL_H + +#include <editorinterface.h> +#include <qobject.h> +#include <qguardedptr.h> + +class TQTimer; +class ViewManager; +struct DesignerInterface; + +class EditorInterfaceImpl : public TQObject, public EditorInterface +{ + Q_OBJECT + +public: + EditorInterfaceImpl(); + virtual ~EditorInterfaceImpl(); + + TQRESULT queryInterface( const TQUuid&, TQUnknownInterface** ); + Q_REFCOUNT; + + TQWidget *editor( bool readonly, TQWidget *parent, TQUnknownInterface *designerIface ); + + void setText( const TQString &txt ); + TQString text() const; + bool isUndoAvailable() const; + bool isRedoAvailable() const; + void undo(); + void redo(); + void cut(); + void copy(); + void paste(); + void selectAll(); + bool find( const TQString &expr, bool cs, bool wo, bool forward, bool startAtCursor ); + bool replace( const TQString &find, const TQString &replace, bool cs, bool wo, bool forward, bool startAtCursor, bool replaceAll ); + void gotoLine( int line ); + void indent(); + void scrollTo( const TQString &txt, const TQString &first ); + void splitView(); + void setContext( TQObject *this_ ); + void readSettings(); + + void setError( int line ); + void setStep( int ) {} + void clearStep() {} + void setModified( bool m ); + bool isModified() const; + void setMode( Mode ) {} + + int numLines() const; + void breakPoints( TQValueList<uint> & ) const {} + void setBreakPoints( const TQValueList<uint> & ) {} + void onBreakPointChange( TQObject *receiver, const char *slot ); + void clearStackFrame() {} + void setStackFrame( int ) {} + +protected: + bool eventFilter( TQObject*, TQEvent* ); + +private slots: + void modificationChanged( bool m ); + void intervalChanged(); + void update(); + +private: + TQGuardedPtr<ViewManager> viewManager; + DesignerInterface *dIface; + TQTimer *updateTimer; + +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/languageinterfaceimpl.cpp b/tools/designer/plugins/cppeditor/languageinterfaceimpl.cpp new file mode 100644 index 000000000..9c2cd2053 --- /dev/null +++ b/tools/designer/plugins/cppeditor/languageinterfaceimpl.cpp @@ -0,0 +1,249 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "languageinterfaceimpl.h" +#include <qobject.h> +#include <designerinterface.h> +#include <qfile.h> +#include "yyreg.h" +#include <qmetaobject.h> + +LanguageInterfaceImpl::LanguageInterfaceImpl( TQUnknownInterface *outer ) + : parent( outer ), ref( 0 ) +{ +} + +ulong LanguageInterfaceImpl::addRef() +{ + return parent ? parent->addRef() : ref++; +} + +ulong LanguageInterfaceImpl::release() +{ + if ( parent ) + return parent->release(); + if ( !--ref ) { + delete this; + return 0; + } + return ref; +} + +TQRESULT LanguageInterfaceImpl::queryInterface( const TQUuid &uuid, TQUnknownInterface** iface ) +{ + if ( parent ) + return parent->queryInterface( uuid, iface ); + + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = (TQUnknownInterface*)this; + else if ( uuid == IID_Language ) + *iface = (LanguageInterface*)this; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} + + +class NormalizeObject : public TQObject +{ +public: + NormalizeObject() : TQObject() {} + static TQCString normalizeSignalSlot( const char *signalSlot ) { return TQObject::normalizeSignalSlot( signalSlot ); } +}; + +void LanguageInterfaceImpl::functions( const TQString &code, TQValueList<Function> *functionMap ) const +{ + TQValueList<CppFunction> l; + extractCppFunctions( code, &l ); + for ( TQValueList<CppFunction>::Iterator it = l.begin(); it != l.end(); ++it ) { + Function func; + func.name = (*it).prototype(); + func.name.remove( 0, (*it).returnType().length() ); + if ( func.name.find( "::" ) == -1 ) + continue; + func.name.remove( (uint)0, func.name.find( "::" ) + 2 ); + func.body = (*it).body(); + func.returnType = (*it).returnType(); + func.start = (*it).functionStartLineNum(); + func.end = (*it).closingBraceLineNum(); + functionMap->append( func ); + } +} + +TQString LanguageInterfaceImpl::createFunctionStart( const TQString &className, const TQString &func, + const TQString &returnType, + const TQString & ) +{ + return returnType + " " + className + "::" + func; +} + +TQStringList LanguageInterfaceImpl::definitions() const +{ + TQStringList lst; + lst << "Includes (in Implementation)" << "Includes (in Declaration)" << "Forward Declarations" << "Signals"; + return lst; +} + +TQStringList LanguageInterfaceImpl::definitionEntries( const TQString &definition, TQUnknownInterface *designerIface ) const +{ + DesignerInterface *iface = 0; + designerIface->queryInterface( IID_Designer, (TQUnknownInterface**) &iface ); + if ( !iface ) + return TQStringList(); + DesignerFormWindow *fw = iface->currentForm(); + if ( !fw ) + return TQStringList(); + TQStringList lst; + if ( definition == "Includes (in Implementation)" ) { + lst = fw->implementationIncludes(); + } else if ( definition == "Includes (in Declaration)" ) { + lst = fw->declarationIncludes(); + } else if ( definition == "Forward Declarations" ) { + lst = fw->forwardDeclarations(); + } else if ( definition == "Signals" ) { + lst = fw->signalList(); + } + iface->release(); + return lst; +} + +void LanguageInterfaceImpl::setDefinitionEntries( const TQString &definition, const TQStringList &entries, TQUnknownInterface *designerIface ) +{ + DesignerInterface *iface = 0; + designerIface->queryInterface( IID_Designer, (TQUnknownInterface**) &iface ); + if ( !iface ) + return; + DesignerFormWindow *fw = iface->currentForm(); + if ( !fw ) + return; + if ( definition == "Includes (in Implementation)" ) { + fw->setImplementationIncludes( entries ); + } else if ( definition == "Includes (in Declaration)" ) { + fw->setDeclarationIncludes( entries ); + } else if ( definition == "Forward Declarations" ) { + fw->setForwardDeclarations( entries ); + } else if ( definition == "Signals" ) { + fw->setSignalList( entries ); + } + iface->release(); +} + +TQString LanguageInterfaceImpl::createEmptyFunction() +{ + return "{\n\n}\n"; +} + +bool LanguageInterfaceImpl::supports( Support s ) const +{ + if ( s == ReturnType ) + return TRUE; + if ( s == ConnectionsToCustomSlots ) + return TRUE; + return FALSE; +} + +TQStringList LanguageInterfaceImpl::fileFilterList() const +{ + TQStringList f; + f << "C++ Files (*.cpp *.C *.cxx *.c++ *.c *.h *.H *.hpp *.hxx)"; + return f; + +} +TQStringList LanguageInterfaceImpl::fileExtensionList() const +{ + TQStringList f; + f << "cpp" << "C" << "cxx" << "c++" << "c" <<"h" << "H" << "hpp" << "hxx"; + return f; +} + +TQString LanguageInterfaceImpl::projectKeyForExtension( const TQString &extension ) const +{ + // also handle something like foo.ut.cpp + TQString ext = extension; + int i = ext.findRev('.'); + if ( i > -1 && i < (int)(ext.length()-1) ) + ext = ext.mid( i + 1 ); + if ( ext[ 0 ] == 'c' || ext[ 0 ] == 'C' ) + return "SOURCES"; + return "HEADERS"; +} + +void LanguageInterfaceImpl::sourceProjectKeys( TQStringList &keys ) const +{ + keys << "HEADERS" << "SOURCES"; +} + + class CheckObject : public TQObject +{ +public: + CheckObject() {} + bool checkConnectArgs( const char *signal, const char *member ) { return TQObject::checkConnectArgs( signal, 0, member ); } + +}; + +bool LanguageInterfaceImpl::canConnect( const TQString &signal, const TQString &slot ) +{ + CheckObject o; + return o.checkConnectArgs( signal.latin1(), slot.latin1() ); +} + +void LanguageInterfaceImpl::loadFormCode( const TQString &, const TQString &filename, + TQValueList<Function> &functions, + TQStringList &, + TQValueList<Connection> & ) +{ + TQFile f( filename ); + if ( !f.open( IO_ReadOnly ) ) + return; + TQTextStream ts( &f ); + TQString code( ts.read() ); + this->functions( code, &functions ); +} + +void LanguageInterfaceImpl::preferedExtensions( TQMap<TQString, TQString> &extensionMap ) const +{ + extensionMap.insert( "cpp", "C++ Source File" ); + extensionMap.insert( "h", "C++ Header File" ); +} + +TQStrList LanguageInterfaceImpl::signalNames( TQObject *obj ) const +{ + TQStrList sigs; + sigs = obj->metaObject()->signalNames( TRUE ); + sigs.remove( "destroyed()" ); + return sigs; +} diff --git a/tools/designer/plugins/cppeditor/languageinterfaceimpl.h b/tools/designer/plugins/cppeditor/languageinterfaceimpl.h new file mode 100644 index 000000000..af06a61ed --- /dev/null +++ b/tools/designer/plugins/cppeditor/languageinterfaceimpl.h @@ -0,0 +1,90 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef LANGUAGEINTERFACEIMPL_H +#define LANGUAGEINTERFACEIMPL_H + +#include <languageinterface.h> + +class LanguageInterfaceImpl : public LanguageInterface +{ +public: + LanguageInterfaceImpl( TQUnknownInterface *outer = 0 ); + + ulong addRef(); + ulong release(); + + TQRESULT queryInterface( const TQUuid&, TQUnknownInterface** ); + + void functions( const TQString &code, TQValueList<Function> *funcs ) const; + void connections( const TQString &, TQValueList<Connection> * ) const {}; + TQString createFunctionStart( const TQString &className, const TQString &func, + const TQString &returnType, const TQString &access ); + TQStringList definitions() const; + TQStringList definitionEntries( const TQString &definition, TQUnknownInterface *designerIface ) const; + void setDefinitionEntries( const TQString &definition, const TQStringList &entries, TQUnknownInterface *designerIface ); + TQString createArguments( const TQString & ) { return TQString::null; } + TQString createEmptyFunction(); + bool supports( Support s ) const; + TQStringList fileFilterList() const; + TQStringList fileExtensionList() const; + void preferedExtensions( TQMap<TQString, TQString> &extensionMap ) const; + void sourceProjectKeys( TQStringList &keys ) const; + TQString projectKeyForExtension( const TQString &extension ) const; + TQString cleanSignature( const TQString &sig ) { return sig; } // #### implement me + void loadFormCode( const TQString &, const TQString &, + TQValueList<Function> &, + TQStringList &, + TQValueList<Connection> & ); + TQString formCodeExtension() const { return ".h"; } + bool canConnect( const TQString &signal, const TQString &slot ); + void compressProject( const TQString &, const TQString &, bool ) {} + TQString uncompressProject( const TQString &, const TQString & ) { return TQString::null; } + TQString aboutText() const { return ""; } + + void addConnection( const TQString &, const TQString &, + const TQString &, const TQString &, + TQString * ) {} + void removeConnection( const TQString &, const TQString &, + const TQString &, const TQString &, + TQString * ) {} + TQStrList signalNames( TQObject *obj ) const; + +private: + TQUnknownInterface *parent; + ulong ref; + +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/mainfilesettings.ui b/tools/designer/plugins/cppeditor/mainfilesettings.ui new file mode 100644 index 000000000..80461afb2 --- /dev/null +++ b/tools/designer/plugins/cppeditor/mainfilesettings.ui @@ -0,0 +1,211 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>CppMainFile</class> +<comment>********************************************************************* +** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +*********************************************************************</comment> +<widget class="TQDialog"> + <property name="name"> + <cstring>CppMainFile</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>308</width> + <height>283</height> + </rect> + </property> + <property name="caption"> + <string>Configure Main-File</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string>Filename:</string> + </property> + </widget> + <widget class="TQLineEdit" row="0" column="1"> + <property name="name"> + <cstring>editFileName</cstring> + </property> + </widget> + <widget class="TQLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>Main-Form:</string> + </property> + </widget> + <widget class="TQListBox" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>listForms</cstring> + </property> + </widget> + <widget class="TQLayoutWidget" row="3" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQPushButton"> + <property name="name"> + <cstring>buttonHelp</cstring> + </property> + <property name="text"> + <string>Help</string> + </property> + <property name="accel"> + <number>4144</number> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>OK</string> + </property> + <property name="accel"> + <number>0</number> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="TQPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>Cancel</string> + </property> + <property name="accel"> + <number>0</number> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>CppMainFile</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>CppMainFile</receiver> + <slot>reject()</slot> + </connection> + <connection> + <sender>listForms</sender> + <signal>selectionChanged()</signal> + <receiver>CppMainFile</receiver> + <slot>updateOkButton()</slot> + </connection> + <connection> + <sender>listForms</sender> + <signal>currentChanged(TQListBoxItem*)</signal> + <receiver>CppMainFile</receiver> + <slot>updateOkButton()</slot> + </connection> + <connection> + <sender>editFileName</sender> + <signal>textChanged(const TQString&)</signal> + <receiver>CppMainFile</receiver> + <slot>updateOkButton()</slot> + </connection> +</connections> +<includes> + <include location="local" impldecl="in implementation">mainfilesettings.ui.h</include> +</includes> +<forwards> + <forward>struct TQUnknownInterface;</forward> +</forwards> +<slots> + <slot>init()</slot> + <slot>setup( TQUnknownInterface * appIface )</slot> + <slot>updateOkButton()</slot> +</slots> +<pixmapinproject/> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/tools/designer/plugins/cppeditor/mainfilesettings.ui.h b/tools/designer/plugins/cppeditor/mainfilesettings.ui.h new file mode 100644 index 000000000..7dd3906c5 --- /dev/null +++ b/tools/designer/plugins/cppeditor/mainfilesettings.ui.h @@ -0,0 +1,36 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use TQt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ + +#include <designerinterface.h> + +void CppMainFile::init() +{ +} + +void CppMainFile::setup( TQUnknownInterface *appIface ) +{ + DesignerInterface *dIface = 0; + appIface->queryInterface( IID_Designer, (TQUnknownInterface**)&dIface ); + if ( !dIface ) + return; + TQStringList l = dIface->currentProject()->formNames(); + editFileName->setText( "main.cpp" ); + listForms->clear(); + listForms->insertStringList( l ); + listForms->setCurrentItem( 0 ); + updateOkButton(); + editFileName->setFocus(); + editFileName->selectAll(); +} + +void CppMainFile::updateOkButton() +{ + buttonOk->setEnabled( editFileName->text().length() > 0 && listForms->currentItem() != -1 ); +} + + diff --git a/tools/designer/plugins/cppeditor/preferenceinterfaceimpl.cpp b/tools/designer/plugins/cppeditor/preferenceinterfaceimpl.cpp new file mode 100644 index 000000000..b4f4a3328 --- /dev/null +++ b/tools/designer/plugins/cppeditor/preferenceinterfaceimpl.cpp @@ -0,0 +1,102 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "preferenceinterfaceimpl.h" +#include <preferences.h> + +PreferenceInterfaceImpl::PreferenceInterfaceImpl( TQUnknownInterface *outer ) + : parent( outer ), + ref( 0 ), + cppEditorSyntax( 0 ) +{ +} + +PreferenceInterfaceImpl::~PreferenceInterfaceImpl() +{ +} + +ulong PreferenceInterfaceImpl::addRef() +{ + return parent ? parent->addRef() : ref++; +} + +ulong PreferenceInterfaceImpl::release() +{ + if ( parent ) + return parent->release(); + if ( !--ref ) { + delete this; + return 0; + } + return ref; +} + +TQRESULT PreferenceInterfaceImpl::queryInterface( const TQUuid &uuid, TQUnknownInterface** iface ) +{ + if ( parent ) + return parent->queryInterface( uuid, iface ); + + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = (TQUnknownInterface*)this; + else if ( uuid == IID_Preference ) + *iface = (PreferenceInterface*)this; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} + +PreferenceInterface::Preference *PreferenceInterfaceImpl::preference() +{ + if ( !cppEditorSyntax ) { + cppEditorSyntax = new PreferencesBase( 0, "cppeditor_syntax" ); + ( (PreferencesBase*)cppEditorSyntax )->setPath( "/Trolltech/CppEditor/" ); + cppEditorSyntax->hide(); + } + Preference *pf = 0; + pf = new Preference; + pf->tab = cppEditorSyntax; + pf->title = "C++ Editor"; + pf->receiver = pf->tab; + pf->init_slot = SLOT( reInit() ); + pf->accept_slot = SLOT( save() ); + return pf; +} + +void PreferenceInterfaceImpl::deletePreferenceObject( Preference *p ) +{ + delete p; +} diff --git a/tools/designer/plugins/cppeditor/preferenceinterfaceimpl.h b/tools/designer/plugins/cppeditor/preferenceinterfaceimpl.h new file mode 100644 index 000000000..08ad3f55d --- /dev/null +++ b/tools/designer/plugins/cppeditor/preferenceinterfaceimpl.h @@ -0,0 +1,64 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef PREFERENCEINTERFACEIMPL_H +#define PREFERENCEINTERFACEIMPL_H + +#include <preferenceinterface.h> +class TQWidget; + +class PreferenceInterfaceImpl : public PreferenceInterface +{ +public: + PreferenceInterfaceImpl( TQUnknownInterface *outer = 0 ); + virtual ~PreferenceInterfaceImpl(); + + ulong addRef(); + ulong release(); + + TQRESULT queryInterface( const TQUuid&, TQUnknownInterface** ); + + Preference *preference(); + void connectTo( TQUnknownInterface * ) {} + void deletePreferenceObject( Preference * ); + +private: + TQUnknownInterface *parent; + int ref; + TQWidget *cppEditorSyntax; + +}; + +#endif + diff --git a/tools/designer/plugins/cppeditor/projectsettings.ui b/tools/designer/plugins/cppeditor/projectsettings.ui new file mode 100644 index 000000000..759e6af73 --- /dev/null +++ b/tools/designer/plugins/cppeditor/projectsettings.ui @@ -0,0 +1,347 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>CppProjectSettings</class> +<comment>********************************************************************* +** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +*********************************************************************</comment> +<include location="local" implDecl="in declaration">projectsettings.ui.h</include> +<forward>struct TQUnknownInterface;</forward> +<variable>TQMap<TQString, TQString> config, libs, defines, includes;</variable> +<pixmapinproject/> +<layoutdefaults spacing="6" margin="11"/> +<widget class="TQWidget"> + <property name="name"> + <cstring>CppProjectSettings</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>373</width> + <height>191</height> + </rect> + </property> + <property name="caption"> + <string>Project Settings</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string>Config:</string> + </property> + </widget> + <spacer row="5" column="2"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel2_2</cstring> + </property> + <property name="text"> + <string>Defines:</string> + </property> + </widget> + <widget class="TQLineEdit" row="3" column="2"> + <property name="name"> + <cstring>editDefines</cstring> + </property> + </widget> + <widget class="TQLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>Libs:</string> + </property> + </widget> + <widget class="TQLabel" row="4" column="0"> + <property name="name"> + <cstring>TextLabel2_3</cstring> + </property> + <property name="text"> + <string>Includepath:</string> + </property> + </widget> + <widget class="TQComboBox" row="3" column="1"> + <item> + <property name="text"> + <string>(all)</string> + </property> + </item> + <item> + <property name="text"> + <string>unix</string> + </property> + </item> + <item> + <property name="text"> + <string>win32</string> + </property> + </item> + <item> + <property name="text"> + <string>mac</string> + </property> + </item> + <property name="name"> + <cstring>comboDefines</cstring> + </property> + </widget> + <widget class="TQComboBox" row="4" column="1"> + <item> + <property name="text"> + <string>(all)</string> + </property> + </item> + <item> + <property name="text"> + <string>unix</string> + </property> + </item> + <item> + <property name="text"> + <string>win32</string> + </property> + </item> + <item> + <property name="text"> + <string>mac</string> + </property> + </item> + <property name="name"> + <cstring>comboInclude</cstring> + </property> + </widget> + <widget class="TQLineEdit" row="4" column="2"> + <property name="name"> + <cstring>editInclude</cstring> + </property> + </widget> + <widget class="TQLineEdit" row="2" column="2"> + <property name="name"> + <cstring>editLibs</cstring> + </property> + </widget> + <widget class="TQLineEdit" row="1" column="2"> + <property name="name"> + <cstring>editConfig</cstring> + </property> + </widget> + <widget class="TQComboBox" row="2" column="1"> + <item> + <property name="text"> + <string>(all)</string> + </property> + </item> + <item> + <property name="text"> + <string>unix</string> + </property> + </item> + <item> + <property name="text"> + <string>win32</string> + </property> + </item> + <item> + <property name="text"> + <string>mac</string> + </property> + </item> + <property name="name"> + <cstring>comboLibs</cstring> + </property> + </widget> + <widget class="TQComboBox" row="1" column="1"> + <item> + <property name="text"> + <string>(all)</string> + </property> + </item> + <item> + <property name="text"> + <string>unix</string> + </property> + </item> + <item> + <property name="text"> + <string>win32</string> + </property> + </item> + <item> + <property name="text"> + <string>mac</string> + </property> + </item> + <property name="name"> + <cstring>comboConfig</cstring> + </property> + </widget> + <widget class="TQLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel3</cstring> + </property> + <property name="text"> + <string>Template:</string> + </property> + </widget> + <spacer row="0" column="2"> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQComboBox" row="0" column="1"> + <item> + <property name="text"> + <string>app</string> + </property> + </item> + <item> + <property name="text"> + <string>lib</string> + </property> + </item> + <property name="name"> + <cstring>comboTemplate</cstring> + </property> + </widget> + </grid> +</widget> +<connections> + <connection language="C++"> + <sender>comboConfig</sender> + <signal>activated(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>configPlatformChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>comboLibs</sender> + <signal>activated(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>libsPlatformChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>comboDefines</sender> + <signal>activated(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>definesPlatformChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>editConfig</sender> + <signal>textChanged(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>configChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>editLibs</sender> + <signal>textChanged(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>libsChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>editDefines</sender> + <signal>textChanged(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>definesChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>editInclude</sender> + <signal>textChanged(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>includesChanged(const TQString&)</slot> + </connection> + <connection language="C++"> + <sender>comboInclude</sender> + <signal>activated(const TQString&)</signal> + <receiver>CppProjectSettings</receiver> + <slot>includesPlatformChanged(const TQString&)</slot> + </connection> + <slot access="public" specifier="virtual" language="C++" returnType="void">reInit( TQUnknownInterface * iface )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">save( TQUnknownInterface * iface )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">configChanged( const TQString & str )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">libsChanged( const TQString & str )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">definesChanged( const TQString & str )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">includesChanged( const TQString & str )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">configPlatformChanged( const TQString & plat )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">libsPlatformChanged( const TQString & plat )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">definesPlatformChanged( const TQString & plat )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">includesPlatformChanged( const TQString & plat )</slot> +</connections> +<tabstops> + <tabstop>comboTemplate</tabstop> + <tabstop>comboConfig</tabstop> + <tabstop>editConfig</tabstop> + <tabstop>comboLibs</tabstop> + <tabstop>editLibs</tabstop> + <tabstop>comboDefines</tabstop> + <tabstop>editDefines</tabstop> + <tabstop>comboInclude</tabstop> + <tabstop>editInclude</tabstop> +</tabstops> +</UI> diff --git a/tools/designer/plugins/cppeditor/projectsettings.ui.h b/tools/designer/plugins/cppeditor/projectsettings.ui.h new file mode 100644 index 000000000..32e770c93 --- /dev/null +++ b/tools/designer/plugins/cppeditor/projectsettings.ui.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** Add custom slot implementations here. Use a slot init() for +** initialization code called during construction, and a slot destroy() +** for cleanup code called during destruction. +** +** This file gets modified by TQt Designer whenever you add, rename or +** remove custom slots. Implementation code does not get lost. +*****************************************************************************/ + +#include <designerinterface.h> + +void CppProjectSettings::reInit( TQUnknownInterface *iface ) +{ + comboConfig->setCurrentItem( 0 ); + comboLibs->setCurrentItem( 0 ); + comboDefines->setCurrentItem( 0 ); + comboInclude->setCurrentItem( 0 ); + + DesignerInterface *dIface = 0; + iface->queryInterface( IID_Designer, (TQUnknownInterface**)&dIface ); + if ( !dIface ) + return; + DesignerProject *project = dIface->currentProject(); + if ( project->templte() == "app" ) + comboTemplate->setCurrentItem( 0 ); + else + comboTemplate->setCurrentItem( 1 ); + + config.clear(); + defines.clear(); + libs.clear(); + defines.clear(); + includes.clear(); + + const TQString platforms[] = { "(all)", "win32", "unix", "mac", TQString::null }; + for ( int i = 0; platforms[ i ] != TQString::null; ++i ) { + config.replace( platforms[ i ], project->config( platforms[ i ] ) ); + libs.replace( platforms[ i ], project->libs( platforms[ i ] ) ); + defines.replace( platforms[ i ], project->defines( platforms[ i ] ) ); + includes.replace( platforms[ i ], project->includePath( platforms[ i ] ) ); + } + editConfig->setText( config[ "(all)" ] ); + editLibs->setText( libs[ "(all)" ] ); + editDefines->setText( defines[ "(all)" ] ); + editInclude->setText( includes[ "(all)" ] ); +} + +void CppProjectSettings::save( TQUnknownInterface *iface ) +{ + DesignerInterface *dIface = 0; + iface->queryInterface( IID_Designer, (TQUnknownInterface**)&dIface ); + if ( !dIface ) + return; + DesignerProject *project = dIface->currentProject(); + + project->setTemplate( comboTemplate->currentText() ); + const TQString platforms[] = { "(all)", "win32", "unix", "mac", TQString::null }; + for ( int i = 0; platforms[ i ] != TQString::null; ++i ) { + project->setConfig( platforms[ i ], config[ platforms[ i ] ] ); + project->setLibs( platforms[ i ], libs[ platforms[ i ] ] ); + project->setDefines( platforms[ i ], defines[ platforms[ i ] ] ); + project->setIncludePath( platforms[ i ], includes[ platforms[ i ] ] ); + } +} + +void CppProjectSettings::configChanged( const TQString &str ) +{ + config.replace( comboConfig->currentText(), str ); +} + +void CppProjectSettings::libsChanged( const TQString &str ) +{ + libs.replace( comboLibs->currentText(), str ); +} + +void CppProjectSettings::definesChanged( const TQString &str ) +{ + defines.replace( comboDefines->currentText(), str ); +} + +void CppProjectSettings::includesChanged( const TQString &str ) +{ + includes.replace( comboInclude->currentText(), str ); +} + +void CppProjectSettings::configPlatformChanged( const TQString &plat ) +{ + editConfig->setText( config[ plat ] ); +} + +void CppProjectSettings::libsPlatformChanged( const TQString &plat ) +{ + editLibs->setText( libs[ plat ] ); +} + +void CppProjectSettings::definesPlatformChanged( const TQString &plat ) +{ + editDefines->setText( defines[ plat ] ); +} + +void CppProjectSettings::includesPlatformChanged( const TQString &plat ) +{ + editInclude->setText( includes[ plat ] ); +} diff --git a/tools/designer/plugins/cppeditor/projectsettingsinterfaceimpl.cpp b/tools/designer/plugins/cppeditor/projectsettingsinterfaceimpl.cpp new file mode 100644 index 000000000..b389b8de9 --- /dev/null +++ b/tools/designer/plugins/cppeditor/projectsettingsinterfaceimpl.cpp @@ -0,0 +1,106 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "projectsettingsinterfaceimpl.h" +#include "projectsettings.h" + +ProjectSettingsInterfaceImpl::ProjectSettingsInterfaceImpl( TQUnknownInterface *outer ) + : parent( outer ), + ref( 0 ), + settingsTab( 0 ) +{ +} + +ulong ProjectSettingsInterfaceImpl::addRef() +{ + return parent ? parent->addRef() : ref++; +} + +ulong ProjectSettingsInterfaceImpl::release() +{ + if ( parent ) + return parent->release(); + if ( !--ref ) { + delete this; + return 0; + } + return ref; +} + +ProjectSettingsInterface::ProjectSettings *ProjectSettingsInterfaceImpl::projectSetting() +{ + if ( !settingsTab ) { + settingsTab = new CppProjectSettings( 0 ); + settingsTab->hide(); + } + ProjectSettings *pf = 0; + pf = new ProjectSettings; + pf->tab = settingsTab; + pf->title = "C++"; + pf->receiver = pf->tab; + pf->init_slot = SLOT( reInit( TQUnknownInterface * ) ); + pf->accept_slot = SLOT( save( TQUnknownInterface * ) ); + return pf; +} + +TQStringList ProjectSettingsInterfaceImpl::projectSettings() const +{ + return TQStringList(); +} + +void ProjectSettingsInterfaceImpl::connectTo( TQUnknownInterface * ) +{ +} + +void ProjectSettingsInterfaceImpl::deleteProjectSettingsObject( ProjectSettings *pf ) +{ + delete pf; +} + +TQRESULT ProjectSettingsInterfaceImpl::queryInterface( const TQUuid &uuid, TQUnknownInterface **iface ) +{ + if ( parent ) + return parent->queryInterface( uuid, iface ); + + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = (TQUnknownInterface*)this; + else if ( uuid == IID_ProjectSettings ) + *iface = (ProjectSettingsInterface*)this; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} diff --git a/tools/designer/plugins/cppeditor/projectsettingsinterfaceimpl.h b/tools/designer/plugins/cppeditor/projectsettingsinterfaceimpl.h new file mode 100644 index 000000000..784b6a022 --- /dev/null +++ b/tools/designer/plugins/cppeditor/projectsettingsinterfaceimpl.h @@ -0,0 +1,62 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef PROJECTSETTINGSINTERFACEIMPL_H +#define PROJECTSETTINGSINTERFACEIMPL_H + +#include <projectsettingsiface.h> + +class CppProjectSettings; + +class ProjectSettingsInterfaceImpl : public ProjectSettingsInterface +{ +public: + ProjectSettingsInterfaceImpl( TQUnknownInterface *outer = 0 ); + + ulong addRef(); + ulong release(); + + ProjectSettings *projectSetting(); + TQStringList projectSettings() const; + void connectTo( TQUnknownInterface *appInterface ); + void deleteProjectSettingsObject( ProjectSettings * ); + TQRESULT queryInterface( const TQUuid &uuid, TQUnknownInterface **iface ); + +private: + TQUnknownInterface *parent; + int ref; + CppProjectSettings *settingsTab; +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/sourcetemplateinterfaceimpl.cpp b/tools/designer/plugins/cppeditor/sourcetemplateinterfaceimpl.cpp new file mode 100644 index 000000000..a9ae3b7ed --- /dev/null +++ b/tools/designer/plugins/cppeditor/sourcetemplateinterfaceimpl.cpp @@ -0,0 +1,117 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "sourcetemplateinterfaceimpl.h" +#include <designerinterface.h> +#include "mainfilesettings.h" +#include <qlineedit.h> +#include <qlistbox.h> + +SourceTemplateInterfaceImpl::SourceTemplateInterfaceImpl() +{ +} + +TQRESULT SourceTemplateInterfaceImpl::queryInterface( const TQUuid &uuid, TQUnknownInterface **iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = (TQUnknownInterface*)this; + else if ( uuid == IID_QFeatureList ) + *iface = (TQFeatureListInterface*)this; + else if ( uuid == IID_SourceTemplate ) + *iface = (SourceTemplateInterface*)this; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} + +TQStringList SourceTemplateInterfaceImpl::featureList() const +{ + TQStringList l; + l << "C++ Main-File (main.cpp)"; + return l; +} + +static TQString generateMainCppCode( const TQString &formname, const TQString &include ) +{ + TQString code; + code += "#include <qapplication.h>\n"; + code += "#include \"" + include + "\"\n"; + code += "\n"; + code += "int main( int argc, char ** argv )\n"; + code += "{\n"; + code += " TQApplication a( argc, argv );\n"; + code += " " + formname + " w;\n"; + code += " w.show();\n"; + code += " a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( tquit() ) );\n"; + code += " return a.exec();\n"; + code += "}\n"; + return code; +} + +SourceTemplateInterface::Source SourceTemplateInterfaceImpl::create( const TQString &templ, + TQUnknownInterface *appIface ) +{ + SourceTemplateInterface::Source src; + src.type = SourceTemplateInterface::Source::Invalid; + if ( templ == "C++ Main-File (main.cpp)" ) { + CppMainFile dia( 0, 0, TRUE ); + dia.setup( appIface ); + if ( dia.exec() == TQDialog::Accepted ) { + DesignerInterface *dIface = 0; + appIface->queryInterface( IID_Designer, (TQUnknownInterface**)&dIface ); + if ( dIface ) { + src.type = SourceTemplateInterface::Source::FileName; + src.filename = dia.editFileName->text(); + TQString include = dIface->currentProject()-> + formFileName( dia.listForms->text( dia.listForms->currentItem() ) ); + include.remove( include.length() - 2, 2 ); + include += "h"; + int slashFind = include.findRev('/'); + if (slashFind != -1) + include = include.mid(slashFind+1); + src.code = generateMainCppCode( dia.listForms->text( dia.listForms->currentItem() ), + include ); + } + } + } + return src; +} + +TQString SourceTemplateInterfaceImpl::language( const TQString & ) const +{ + return "C++"; +} diff --git a/tools/designer/plugins/cppeditor/sourcetemplateinterfaceimpl.h b/tools/designer/plugins/cppeditor/sourcetemplateinterfaceimpl.h new file mode 100644 index 000000000..efddc9794 --- /dev/null +++ b/tools/designer/plugins/cppeditor/sourcetemplateinterfaceimpl.h @@ -0,0 +1,54 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef SOURCETEMPLATEINTERFACEIMPL_H +#define SOURCETEMPLATEINTERFACEIMPL_H + +#include <sourcetemplateiface.h> + +class SourceTemplateInterfaceImpl : public SourceTemplateInterface +{ +public: + SourceTemplateInterfaceImpl(); + + TQRESULT queryInterface( const TQUuid&, TQUnknownInterface** ); + TQStringList featureList() const; + Source create( const TQString &templ, TQUnknownInterface *appIface ); + TQString language( const TQString &templ ) const; + + Q_REFCOUNT +}; + + +#endif diff --git a/tools/designer/plugins/cppeditor/syntaxhighliter_cpp.cpp b/tools/designer/plugins/cppeditor/syntaxhighliter_cpp.cpp new file mode 100644 index 000000000..e1d338430 --- /dev/null +++ b/tools/designer/plugins/cppeditor/syntaxhighliter_cpp.cpp @@ -0,0 +1,550 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "syntaxhighliter_cpp.h" +#include "paragdata.h" +#include "qstring.h" +#include "qstringlist.h" +#include "qmap.h" +#include "qapplication.h" +#include "qregexp.h" + +const char * const SyntaxHighlighter_CPP::keywords[] = { + // C++ keywords + "and", + "and_eq", + "asm", + "auto", + "bitand", + "bitor", + "bool", + "break", + "case", + "catch", + "char", + "class", + "compl", + "const", + "const_cast", + "continue", + "default", + "delete", + "do", + "double", + "dynamic_cast", + "else", + "enum", + "explicit", + "export", + "extern", + "false", + "FALSE", + "float", + "for", + "friend", + "goto", + "if", + "inline", + "int", + "long", + "mutable", + "namespace", + "new", + "not", + "not_eq", + "operator", + "or", + "or_eq", + "private", + "protected", + "public", + "register", + "reinterpret_cast", + "return", + "short", + "signed", + "sizeof", + "static", + "static_cast", + "struct", + "switch", + "template", + "this", + "throw", + "true", + "TRUE", + "try", + "typedef", + "typeid", + "typename", + "union", + "unsigned", + "using", + "virtual", + "void", + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq", + // additional "keywords" intoduced by TQt + "slots", + "signals", + "uint", + "ushort", + "ulong", + "emit", + // end of array + 0 +}; + +static TQMap<int, TQMap<TQString, int > > *wordMap = 0; + +SyntaxHighlighter_CPP::SyntaxHighlighter_CPP() + : TQTextPreProcessor(), lastFormat( 0 ), lastFormatId( -1 ) +{ + TQFont f( qApp->font() ); + + addFormat( Standard, new TQTextFormat( f, TQt::black ) ); + addFormat( Number, new TQTextFormat( f, TQt::darkBlue ) ); + addFormat( String, new TQTextFormat( f, TQt::darkGreen ) ); + addFormat( Type, new TQTextFormat( f, TQt::darkMagenta ) ); + addFormat( Keyword, new TQTextFormat( f, TQt::darkYellow ) ); + addFormat( PreProcessor, new TQTextFormat( f, TQt::darkBlue ) ); + addFormat( Label, new TQTextFormat( f, TQt::darkRed ) ); + f.setFamily( "times" ); + addFormat( Comment, new TQTextFormat( f, TQt::red ) ); + + if ( wordMap ) + return; + + wordMap = new TQMap<int, TQMap<TQString, int> >; + int len; + for ( int i = 0; keywords[ i ]; ++i ) { + len = (int)strlen( keywords[ i ] ); + if ( !wordMap->contains( len ) ) + wordMap->insert( len, TQMap<TQString, int >() ); + TQMap<TQString, int> &map = wordMap->operator[]( len ); + map[ keywords[ i ] ] = Keyword; + } +} + +SyntaxHighlighter_CPP::~SyntaxHighlighter_CPP() +{ +} + +static int string2Id( const TQString &s ) +{ + if ( s == "Standard" ) + return SyntaxHighlighter_CPP::Standard; + if ( s == "Comment" ) + return SyntaxHighlighter_CPP::Comment; + if ( s == "Number" ) + return SyntaxHighlighter_CPP::Number; + if ( s == "String" ) + return SyntaxHighlighter_CPP::String; + if ( s == "Type" ) + return SyntaxHighlighter_CPP::Type; + if ( s == "Preprocessor" ) + return SyntaxHighlighter_CPP::PreProcessor; + if ( s == "Label" ) + return SyntaxHighlighter_CPP::Label; + if ( s == "Keyword" ) + return SyntaxHighlighter_CPP::Keyword; + return SyntaxHighlighter_CPP::Standard; +} + +void SyntaxHighlighter_CPP::updateStyles( const TQMap<TQString, ConfigStyle> &styles ) +{ + for ( TQMap<TQString, ConfigStyle>::ConstIterator it = styles.begin(); it != styles.end(); ++it ) { + int id = string2Id( it.key() ); + TQTextFormat *f = format( id ); + if ( !f ) + continue; + f->setFont( (*it).font ); + f->setColor( (*it).color ); + } +} + +void SyntaxHighlighter_CPP::process( TQTextDocument *doc, TQTextParagraph *string, int, bool invalidate ) +{ + + TQTextFormat *formatStandard = format( Standard ); + TQTextFormat *formatComment = format( Comment ); + TQTextFormat *formatNumber = format( Number ); + TQTextFormat *formatString = format( String ); + TQTextFormat *formatType = format( Type ); + TQTextFormat *formatPreProcessor = format( PreProcessor ); + TQTextFormat *formatLabel = format( Label ); + + // states + const int StateStandard = 0; + const int StateCommentStart1 = 1; + const int StateCCommentStart2 = 2; + const int StateCppCommentStart2 = 3; + const int StateCComment = 4; + const int StateCppComment = 5; + const int StateCCommentEnd1 = 6; + const int StateCCommentEnd2 = 7; + const int StateStringStart = 8; + const int StateString = 9; + const int StateStringEnd = 10; + const int StateString2Start = 11; + const int StateString2 = 12; + const int StateString2End = 13; + const int StateNumber = 14; + const int StatePreProcessor = 15; + + // tokens + const int InputAlpha = 0; + const int InputNumber = 1; + const int InputAsterix = 2; + const int InputSlash = 3; + const int InputParen = 4; + const int InputSpace = 5; + const int InputHash = 6; + const int InputQuotation = 7; + const int InputApostrophe = 8; + const int InputSep = 9; + + static uchar table[ 16 ][ 10 ] = { + { StateStandard, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateStandard + { StateStandard, StateNumber, StateCCommentStart2, StateCppCommentStart2, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateCommentStart1 + { StateCComment, StateCComment, StateCCommentEnd1, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment }, // StateCCommentStart2 + { StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment }, // CppCommentStart2 + { StateCComment, StateCComment, StateCCommentEnd1, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment }, // StateCComment + { StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment, StateCppComment }, // StateCppComment + { StateCComment, StateCComment, StateCCommentEnd1, StateCCommentEnd2, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment }, // StateCCommentEnd1 + { StateStandard, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateCCommentEnd2 + { StateString, StateString, StateString, StateString, StateString, StateString, StateString, StateStringEnd, StateString, StateString }, // StateStringStart + { StateString, StateString, StateString, StateString, StateString, StateString, StateString, StateStringEnd, StateString, StateString }, // StateString + { StateStandard, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateStringEnd + { StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2End, StateString2 }, // StateString2Start + { StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2End, StateString2 }, // StateString2 + { StateStandard, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateString2End + { StateNumber, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateNumber + { StatePreProcessor, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard } // StatePreProcessor + }; + + TQString buffer; + + int state = StateStandard; + if ( string->prev() ) { + if ( string->prev()->endState() == -1 ) + process( doc, string->prev(), 0, FALSE ); + state = string->prev()->endState(); + } + int input = -1; + int i = 0; + bool lastWasBackSlash = FALSE; + bool makeLastStandard = FALSE; + + ParagData *paragData = (ParagData*)string->extraData(); + if ( paragData ) + paragData->parenList.clear(); + else + paragData = new ParagData; + + TQString alphabeth = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPTQRSTUVWXYZ"; + TQString mathChars = "xXeE"; + TQString numbers = "0123456789"; + bool questionMark = FALSE; + TQChar lastChar; + for (;;) { + TQChar c = string->at( i )->c; + + if ( lastWasBackSlash ) { + input = InputSep; + } else { + switch ( c ) { + case '*': + input = InputAsterix; + break; + case '/': + input = InputSlash; + break; + case '(': case '[': case '{': + input = InputParen; + if ( state == StateStandard || + state == StateNumber || + state == StatePreProcessor || + state == StateCCommentEnd2 || + state == StateCCommentEnd1 || + state == StateString2End || + state == StateStringEnd ) + paragData->parenList << Paren( Paren::Open, c, i ); + break; + case ')': case ']': case '}': + input = InputParen; + if ( state == StateStandard || + state == StateNumber || + state == StatePreProcessor || + state == StateCCommentEnd2 || + state == StateCCommentEnd1 || + state == StateString2End || + state == StateStringEnd ) + paragData->parenList << Paren( Paren::Closed, c, i ); + break; + case '#': + input = InputHash; + break; + case '"': + input = InputQuotation; + break; + case '\'': + input = InputApostrophe; + break; + case ' ': + input = InputSpace; + break; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': case '0': + if ( alphabeth.find( lastChar ) != -1 && + ( mathChars.find( lastChar ) == -1 || numbers.find( string->at( i - 1 )->c ) == -1 ) ) { + input = InputAlpha; + } else { + if ( input == InputAlpha && numbers.find( lastChar ) != -1 ) + input = InputAlpha; + else + input = InputNumber; + } + break; + case ':': { + input = InputAlpha; + TQChar nextChar = ' '; + if ( i < string->length() - 1 ) + nextChar = string->at( i + 1 )->c; + if ( state == StateStandard && !questionMark && lastChar != ':' && nextChar != ':' ) { + for ( int j = 0; j < i; ++j ) { + if ( string->at( j )->format() == formatStandard ) + string->setFormat( j, 1, formatLabel, FALSE ); + } + } + } break; + default: { + if ( !questionMark && c == '?' ) + questionMark = TRUE; + if ( c.isLetter() || c == '_' ) + input = InputAlpha; + else + input = InputSep; + } break; + } + } + + lastWasBackSlash = !lastWasBackSlash && c == '\\'; + + if ( input == InputAlpha ) + buffer += c; + + state = table[ state ][ input ]; + + switch ( state ) { + case StateStandard: { + int len = buffer.length(); + string->setFormat( i, 1, formatStandard, FALSE ); + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + if ( buffer.length() > 0 && input != InputAlpha ) { + if ( buffer[ 0 ] == 'Q' ) { + string->setFormat( i - buffer.length(), buffer.length(), formatType, FALSE ); + } else { + TQMap<int, TQMap<TQString, int > >::Iterator it = wordMap->find( len ); + if ( it != wordMap->end() ) { + TQMap<TQString, int >::Iterator it2 = ( *it ).find( buffer ); + if ( it2 != ( *it ).end() ) + string->setFormat( i - buffer.length(), buffer.length(), format( ( *it2 ) ), FALSE ); + } + } + buffer = TQString::null; + } + } break; + case StateCommentStart1: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = TRUE; + buffer = TQString::null; + break; + case StateCCommentStart2: + string->setFormat( i - 1, 2, formatComment, FALSE ); + makeLastStandard = FALSE; + buffer = TQString::null; + break; + case StateCppCommentStart2: + string->setFormat( i - 1, 2, formatComment, FALSE ); + makeLastStandard = FALSE; + buffer = TQString::null; + break; + case StateCComment: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatComment, FALSE ); + buffer = TQString::null; + break; + case StateCppComment: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatComment, FALSE ); + buffer = TQString::null; + break; + case StateCCommentEnd1: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatComment, FALSE ); + buffer = TQString::null; + break; + case StateCCommentEnd2: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatComment, FALSE ); + buffer = TQString::null; + break; + case StateStringStart: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatStandard, FALSE ); + buffer = TQString::null; + break; + case StateString: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatString, FALSE ); + buffer = TQString::null; + break; + case StateStringEnd: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatStandard, FALSE ); + buffer = TQString::null; + break; + case StateString2Start: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatStandard, FALSE ); + buffer = TQString::null; + break; + case StateString2: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatString, FALSE ); + buffer = TQString::null; + break; + case StateString2End: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatStandard, FALSE ); + buffer = TQString::null; + break; + case StateNumber: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatNumber, FALSE ); + buffer = TQString::null; + break; + case StatePreProcessor: + if ( makeLastStandard ) + string->setFormat( i - 1, 1, formatStandard, FALSE ); + makeLastStandard = FALSE; + string->setFormat( i, 1, formatPreProcessor, FALSE ); + buffer = TQString::null; + break; + } + + lastChar = c; + i++; + if ( i >= string->length() ) + break; + } + + string->setExtraData( paragData ); + + int oldEndState = string->endState(); + if ( state == StateCComment || + state == StateCCommentEnd1 ) { + string->setEndState( StateCComment ); + } else if ( state == StateString ) { + string->setEndState( StateString ); + } else if ( state == StateString2 ) { + string->setEndState( StateString2 ); + } else { + string->setEndState( StateStandard ); + } + + string->setFirstPreProcess( FALSE ); + + TQTextParagraph *p = string->next(); + if ( (!!oldEndState || !!string->endState()) && oldEndState != string->endState() && + invalidate && p && !p->firstPreProcess() && p->endState() != -1 ) { + while ( p ) { + if ( p->endState() == -1 ) + return; + p->setEndState( -1 ); + p = p->next(); + } + } +} + +TQTextFormat *SyntaxHighlighter_CPP::format( int id ) +{ + if ( lastFormatId == id && lastFormat ) + return lastFormat; + + TQTextFormat *f = formats[ id ]; + lastFormat = f ? f : formats[ 0 ]; + lastFormatId = id; + return lastFormat; +} + +void SyntaxHighlighter_CPP::addFormat( int id, TQTextFormat *f ) +{ + formats.insert( id, f ); +} + +void SyntaxHighlighter_CPP::removeFormat( int id ) +{ + formats.remove( id ); +} + diff --git a/tools/designer/plugins/cppeditor/syntaxhighliter_cpp.h b/tools/designer/plugins/cppeditor/syntaxhighliter_cpp.h new file mode 100644 index 000000000..25b16607f --- /dev/null +++ b/tools/designer/plugins/cppeditor/syntaxhighliter_cpp.h @@ -0,0 +1,73 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQCPPSYNTAXHIGHLIGHTER_H +#define TQCPPSYNTAXHIGHLIGHTER_H + +#include <private/qrichtext_p.h> +#include <conf.h> + +class SyntaxHighlighter_CPP : public TQTextPreProcessor +{ +public: + enum CppIds { + Comment = 1, + Number, + String, + Type, + Keyword, + PreProcessor, + Label + }; + + SyntaxHighlighter_CPP(); + virtual ~SyntaxHighlighter_CPP(); + void process( TQTextDocument *doc, TQTextParagraph *string, int start, bool invalidate = TRUE ); + void updateStyles( const TQMap<TQString, ConfigStyle> &styles ); + + static const char * const keywords[]; + + TQTextFormat *format( int id ); + +private: + void addFormat( int id, TQTextFormat *f ); + void removeFormat( int id ); + + TQTextFormat *lastFormat; + int lastFormatId; + TQIntDict<TQTextFormat> formats; + +}; + +#endif diff --git a/tools/designer/plugins/cppeditor/yyreg.cpp b/tools/designer/plugins/cppeditor/yyreg.cpp new file mode 100644 index 000000000..2e0709e46 --- /dev/null +++ b/tools/designer/plugins/cppeditor/yyreg.cpp @@ -0,0 +1,800 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include <qregexp.h> + +#include <ctype.h> +#include <stdio.h> + +#include "yyreg.h" + +/* + First comes the tokenizer. We don't need something that knows much + about C++. However, we need something that gives tokens from the + end of the file to the start, which is tricky. + + If you are not familiar with hand-written tokenizers and parsers, + you might want to read other simpler parsers written in the same + style: + + $(QTDIR)/src/tools/qregexp.cpp + $(QTDIR)/tools/inspector/cppparser.cpp + + You might also want to read Section 2 in the Dragon Book. +*/ + +/* + Those are the tokens we are interested in. Tok_Something represents + any C++ token that does not interest us, but it's dangerous to + ignore tokens completely. +*/ +enum { Tok_Boi, Tok_Ampersand, Tok_Aster, Tok_LeftParen, Tok_RightParen, + Tok_Equal, Tok_LeftBrace, Tok_RightBrace, Tok_Semicolon, Tok_Colon, + Tok_LeftAngle, Tok_RightAngle, Tok_Comma, Tok_Ellipsis, Tok_Gulbrandsen, + Tok_LeftBracket, Tok_RightBracket, Tok_Tilde, Tok_Something, Tok_Comment, + Tok_Ident, + + Tok_char, Tok_const, Tok_double, Tok_int, Tok_long, Tok_operator, + Tok_short, Tok_signed, Tok_unsigned }; + +/* + The following variables store the lexical analyzer state. The best way + to understand them is to implement a function myGetToken() that calls + getToken(), to add some qDebug() statements in there and then to + #define getToken() myGetToken(). +*/ +static TQString *yyIn; // the input stream +static int yyPos; // the position of the current token in yyIn +static int yyCurPos; // the position of the next lookahead character +static char *yyLexBuf; // the lexeme buffer +static const int YYLexBufSize = 65536; // big enough for long comments +static char *yyLex; // the lexeme itself (a pointer into yyLexBuf) +static int yyCh; // the lookbehind character + +/* + Moves back to the previous character in the input stream and + updates the tokenizer state. This function is to be used only by + getToken(), which provides the right abstraction. +*/ +static inline void readChar() +{ + if ( yyCh == EOF ) + return; + + if ( yyLex > yyLexBuf ) + *--yyLex = (char) yyCh; + + if ( yyCurPos < 0 ) + yyCh = EOF; + else + yyCh = (*yyIn)[yyCurPos].unicode(); + yyCurPos--; +} + +/* + Sets up the tokenizer. +*/ +static void startTokenizer( const TQString& in ) +{ + yyIn = new TQString; + *yyIn = in; + yyPos = yyIn->length() - 1; + yyCurPos = yyPos; + yyLexBuf = new char[YYLexBufSize]; + yyLex = yyLexBuf + YYLexBufSize - 1; + *yyLex = '\0'; + yyCh = '\0'; + readChar(); +} + +/* + Frees resources allocated by the tokenizer. +*/ +static void stopTokenizer() +{ + delete yyIn; + delete[] yyLexBuf; + yyLexBuf = 0; +} + +/* + These two macros implement tquick-and-dirty hashing for telling + apart keywords fast. +*/ +#define HASH( ch, len ) ( (ch) | ((len) << 8) ) +#define CHECK( target ) \ + if ( strcmp((target), yyLex) != 0 ) \ + break; + +/* + Returns the previous token in the abstract token stream. The parser + deals only with tokens, not with characters. +*/ +static int getToken() +{ + // why "+ 2"? try putting some qDebug()'s and see + yyPos = yyCurPos + 2; + + for ( ;; ) { + /* + See if the previous token is interesting. If it isn't, we + will loop anyway an go to the token before the previous + token, and so on. + */ + + yyLex = yyLexBuf + YYLexBufSize - 1; + *yyLex = '\0'; + + if ( yyCh == EOF ) { + break; + } else if ( isspace(yyCh) ) { + bool metNL = FALSE; + do { + metNL = ( metNL || yyCh == '\n' ); + readChar(); + } while ( isspace(yyCh) ); + + if ( metNL ) { + /* + C++ style comments are tricky. In left-to-right + thinking, C++ comments start with "//" and end with + '\n'. In right-to-left thinking, they start with a + '\n'; but of course not every '\n' starts a comment. + + When we meet the '\n', we look behind, on the same + line, for a "//", and if there is one we mess + around with the tokenizer state to effectively + ignore the comment. Beware of off-by-one and + off-by-two bugs when you modify this code by adding + qDebug()'s here and there. + */ + if ( yyCurPos >= 0 ) { + int lineStart = yyIn->findRev( TQChar('\n'), yyCurPos ) + 1; + TQString line = yyIn->mid( lineStart, + yyCurPos - lineStart + 2 ); + int commentStart = line.find( TQString("//") ); + if ( commentStart != -1 ) { + yyCurPos = lineStart + commentStart - 1; + yyPos = yyCurPos + 2; + readChar(); + } + } + } + } else if ( isalnum(yyCh) || yyCh == '_' ) { + do { + readChar(); + } while ( isalnum(yyCh) || yyCh == '_' ); + + switch ( HASH(yyLex[0], strlen(yyLex)) ) { + case HASH( 'c', 4 ): + CHECK( "char" ); + return Tok_char; + case HASH( 'c', 5 ): + CHECK( "const" ); + return Tok_const; + case HASH( 'd', 6 ): + CHECK( "double" ); + return Tok_double; + case HASH( 'i', 3 ): + CHECK( "int" ); + return Tok_int; + case HASH( 'l', 4 ): + CHECK( "long" ); + return Tok_long; + case HASH( 'o', 8 ): + CHECK( "operator" ); + return Tok_operator; + case HASH( 's', 5 ): + CHECK( "short" ); + return Tok_short; + case HASH( 's', 6 ): + CHECK( "signed" ); + return Tok_signed; + case HASH( 'u', 8 ): + CHECK( "unsigned" ); + return Tok_unsigned; + } + if ( isdigit(*yyLex) ) + return Tok_Something; + else + return Tok_Ident; + } else { + int quote; + + switch ( yyCh ) { + case '!': + case '%': + case '^': + case '+': + case '-': + case '?': + case '|': + readChar(); + return Tok_Something; + case '"': + case '\'': + quote = yyCh; + readChar(); + + while ( yyCh != EOF && yyCh != '\n' ) { + if ( yyCh == quote ) { + readChar(); + if ( yyCh != '\\' ) + break; + } else { + readChar(); + } + } + return Tok_Something; + case '&': + readChar(); + if ( yyCh == '&' ) { + readChar(); + return Tok_Something; + } else { + return Tok_Ampersand; + } + case '(': + readChar(); + return Tok_LeftParen; + case ')': + readChar(); + return Tok_RightParen; + case '*': + readChar(); + return Tok_Aster; + case ',': + readChar(); + return Tok_Comma; + case '.': + readChar(); + if ( yyCh == '.' ) { + do { + readChar(); + } while ( yyCh == '.' ); + return Tok_Ellipsis; + } else { + return Tok_Something; + } + case '/': + /* + C-style comments are symmetric. C++-style comments + are handled elsewhere. + */ + readChar(); + if ( yyCh == '*' ) { + bool metAster = FALSE; + bool metAsterSlash = FALSE; + + readChar(); + + while ( !metAsterSlash ) { + if ( yyCh == EOF ) + break; + + if ( yyCh == '*' ) + metAster = TRUE; + else if ( metAster && yyCh == '/' ) + metAsterSlash = TRUE; + else + metAster = FALSE; + readChar(); + } + break; + // return Tok_Comment; + } else { + return Tok_Something; + } + case ':': + readChar(); + if ( yyCh == ':' ) { + readChar(); + return Tok_Gulbrandsen; + } else { + return Tok_Colon; + } + case ';': + readChar(); + return Tok_Semicolon; + case '<': + readChar(); + return Tok_LeftAngle; + case '=': + readChar(); + return Tok_Equal; + case '>': + readChar(); + return Tok_RightAngle; + case '[': + readChar(); + return Tok_LeftBracket; + case ']': + readChar(); + return Tok_RightBracket; + case '{': + readChar(); + return Tok_LeftBrace; + case '}': + readChar(); + return Tok_RightBrace; + case '~': + readChar(); + return Tok_Tilde; + default: + readChar(); + } + } + } + return Tok_Boi; +} + +/* + Follow the member function(s) of CppFunction. +*/ + +/* + Returns the prototype for the C++ function, without the semicolon. +*/ +TQString CppFunction::prototype() const +{ + TQString proto; + + if ( !returnType().isEmpty() ) + proto = returnType() + TQChar( ' ' ); + proto += scopedName(); + proto += TQChar( '(' ); + if ( !parameterList().isEmpty() ) { + TQStringList::ConstIterator p = parameterList().begin(); + proto += *p; + ++p; + while ( p != parameterList().end() ) { + proto += TQString( ", " ); + proto += *p; + ++p; + } + } + proto += TQChar( ')' ); + if ( isConst() ) + proto += TQString( " const" ); + return proto; +} + +/* + The parser follows. We are not really parsing C++, just trying to + find the start and end of function definitions. + + One important pitfall is that the parsed code needs not be valid. + Parsing from right to left helps cope with that, as explained in + comments below. + + In the examples, we will use the symbol @ to stand for the position + in the token stream. In "int @ x ;", the lookahead token (yyTok) is + 'int'. +*/ + +static int yyTok; // the current token + +/* + Returns TRUE if thingy is a constructor or a destructor; otherwise + returns FALSE. +*/ +static bool isCtorOrDtor( const TQString& thingy ) +{ + // e.g., Alpha<a>::Beta<Bar<b, c> >::~Beta + TQRegExp xtor( TQString( + "(?:([A-Z_a-z][0-9A-Z_a-z]*)" // class name + "(?:<(?:[^>]|<[^>]*>)*>)*" // template arguments + "::)+" // many in a row + "~?" // ctor or dtor? + "\\1") ); // function has same name as class + return xtor.exactMatch( thingy ); +} + +/* + Skips over any template arguments with balanced angle brackets, and + returns the skipped material as a string. + + Before: TQMap < TQString , TQValueList < TQString > > @ m ; + After: TQMap @ < TQString , TQValueList < TQString > > m ; +*/ +static TQString matchTemplateAngles() +{ + TQString t; + + if ( yyTok == Tok_RightAngle ) { + int depth = 0; + do { + if ( yyTok == Tok_RightAngle ) + depth++; + else if ( yyTok == Tok_LeftAngle ) + depth--; + t.prepend( yyLex ); + yyTok = getToken(); + } while ( depth > 0 && yyTok != Tok_Boi && yyTok != Tok_LeftBrace ); + } + return t; +} + +/* + Similar to matchTemplateAngles(), but for array brackets in parameter + data types (as in "int *argv[]"). +*/ +static TQString matchArrayBrackets() +{ + TQString t; + + while ( yyTok == Tok_RightBracket ) { + t.prepend( yyLex ); + yyTok = getToken(); + if ( yyTok == Tok_Something ) { + t.prepend( yyLex ); + yyTok = getToken(); + } + if ( yyTok != Tok_LeftBracket ) + return TQString::null; + t.prepend( yyLex ); + yyTok = getToken(); + } + return t; +} + +/* + Prepends prefix to *type. This operation is in theory trivial, but + for the spacing to look good, we have to do something. The original + spacing is lost as the input is tokenized. +*/ +static void prependToType( TQString *type, const TQString& prefix ) +{ + if ( !type->isEmpty() && !prefix.isEmpty() ) { + TQChar left = prefix[(int) prefix.length() - 1]; + TQChar right = (*type)[0]; + + if ( left.isLetter() && + (right.isLetter() || right == TQChar('*') || right == TQChar('&')) ) + type->prepend( TQChar(' ') ); + } + type->prepend( prefix ); +} + +static bool isModifier( int tok ) +{ + return ( tok == Tok_signed || tok == Tok_unsigned || + tok == Tok_short || tok == Tok_long ); +} + +/* + Parses a data type (backwards as usual) and returns a textual + representation of it. +*/ +static TQString matchDataType() +{ + TQString type; + + while ( yyTok == Tok_Ampersand || yyTok == Tok_Aster || + yyTok == Tok_const ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + } + + /* + This code is really hard to follow... sorry. The loop matches + Alpha::Beta::Gamma::...::Omega. + */ + for ( ;; ) { + bool modifierMet = FALSE; + + prependToType( &type, matchTemplateAngles() ); + + if ( yyTok != Tok_Ident ) { + /* + People may write 'const unsigned short' or + 'short unsigned const' or any other permutation. + */ + while ( yyTok == Tok_const || isModifier(yyTok) ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + if ( yyTok != Tok_const ) + modifierMet = TRUE; + } + + if ( yyTok == Tok_Tilde ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + } + } + + if ( !modifierMet ) { + if ( yyTok == Tok_Ellipsis || yyTok == Tok_Ident || + yyTok == Tok_char || yyTok == Tok_int || + yyTok == Tok_double ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + } else { + return TQString::null; + } + } else if ( yyTok == Tok_int || yyTok == Tok_char || + yyTok == Tok_double ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + } + + while ( yyTok == Tok_const || isModifier(yyTok) ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + } + + if ( yyTok == Tok_Gulbrandsen ) { + prependToType( &type, yyLex ); + yyTok = getToken(); + } else { + break; + } + } + return type; +} + +/* + Parses a function prototype (without the semicolon) and returns an + object that stores information about this function. +*/ +static CppFunction matchFunctionPrototype( bool stripParamNames ) +{ + CppFunction func; +#if 0 + TQString documentation; +#endif + TQString returnType; + TQString scopedName; + TQStringList params; + TQString qualifier; + bool cnst = FALSE; + + if ( yyTok == Tok_const ) { + cnst = TRUE; + yyTok = getToken(); + } + + if ( yyTok != Tok_RightParen ) + return func; + yyTok = getToken(); + + if ( yyTok != Tok_LeftParen ) { + for ( ;; ) { + TQString brackets = matchArrayBrackets(); + TQString name; + if ( yyTok == Tok_Ident ) { + name = yyLex; + yyTok = getToken(); + } + TQString type = matchDataType(); + + if ( type.isEmpty() ) { + if ( name.isEmpty() ) + return func; + type = name; + name = TQString::null; + } + if ( stripParamNames ) + name = TQString::null; + + TQString param = type + TQChar( ' ' ) + name + brackets; + params.prepend( param.stripWhiteSpace() ); + + if ( yyTok != Tok_Comma ) + break; + yyTok = getToken(); + } + if ( yyTok != Tok_LeftParen ) + return func; + } + yyTok = getToken(); + + for ( ;; ) { + scopedName.prepend( matchTemplateAngles() ); + + if ( yyTok != Tok_Ident ) { + // the operator keyword should be close + int i = 0; + while ( i < 4 && yyTok != Tok_operator ) { + scopedName.prepend( yyLex ); + i++; + } + if ( yyTok != Tok_operator ) + return func; + } + scopedName.prepend( yyLex ); + yyTok = getToken(); + + if ( yyTok != Tok_Gulbrandsen ) + break; + scopedName.prepend( yyLex ); + yyTok = getToken(); + } + + if ( !isCtorOrDtor(scopedName) ) { + returnType = matchDataType(); + if ( returnType.isEmpty() ) + return func; + } + + /* + The documentation feature is unused so far, since we cannot + really distinguist between a normal comment between two + functions and one that relates to the following function. One + good heuristic is to assume that a comment immediately followed + by a function with no blank line in between relates to the + function, but there's no easy way to find that out with a + tokenizer. + */ +#if 0 + if ( yyTok == Tok_Comment ) { + documentation = yyLex; + yyTok = getToken(); + } + + func.setDocumentation( documentation ); +#endif + func.setReturnType( returnType ); + func.setScopedName( scopedName ); + func.setParameterList( params ); + func.setConst( cnst ); + return func; +} + +/* + Try to set the body. It's not sufficient to call + func->setBody(somewhatBody), as the somewhatBody might be too large. + Case in point: + + void foo() + { + printf( "Hello" ); + } + + int n; + + void bar() + { + printf( " world!\n" ); + } + + The parser first finds bar(). Then it finds "void foo() {" and + naively expects the body to extend up to "void bar()". This + function's job is to count braces and make sure "int n;" is not + counted as part of the body. + + Cases where the closing brace of the body is missing retquire no + special processing. +*/ +static void setBody( CppFunction *func, const TQString& somewhatBody ) +{ + TQString body = somewhatBody; + + int braceDepth = 0; + int i = 0; + while ( i < (int) body.length() ) { + if ( body[i] == TQChar('{') ) { + braceDepth++; + } else if ( body[i] == TQChar('}') ) { + braceDepth--; + if ( braceDepth == 0 ) { + body.truncate( i + 1 ); + break; + } + } + i++; + } + + func->setBody( body ); +} + +/* + Parses a whole C++ file, looking for function definitions. Case in + point: + + void foo() + { + printf( "Hello" ); + + void bar() + { + printf( " world!\n" ); + } + + The parser looks for left braces and tries to parse a function + prototype backwards. First it finds "void bar() {". Then it works + up and finds "void foo() {". +*/ +static void matchTranslationUnit( TQValueList<CppFunction> *flist ) +{ + int endBody = -1; + int startBody; + + for ( ;; ) { + if ( endBody == -1 ) + endBody = yyPos; + + while ( yyTok != Tok_Boi && yyTok != Tok_LeftBrace ) + yyTok = getToken(); + if ( yyTok == Tok_Boi ) + break; + + // found a left brace + yyTok = getToken(); + startBody = yyPos; + CppFunction func = matchFunctionPrototype( FALSE ); + if ( !func.scopedName().isEmpty() ) { + TQString body = yyIn->mid( startBody, endBody - startBody ); + setBody( &func, body ); + body = func.body(); // setBody() can change the body + + /* + Compute important line numbers. + */ + int functionStartLineNo = 1 + TQConstString( yyIn->unicode(), yyPos ) + .string().contains( TQChar('\n') ); + int startLineNo = functionStartLineNo + + TQConstString( yyIn->unicode() + yyPos, startBody - yyPos ) + .string().contains( TQChar('\n') ); + int endLineNo = startLineNo + body.contains( TQChar('\n') ); + + func.setLineNums( functionStartLineNo, startLineNo, endLineNo ); + flist->prepend( func ); + endBody = -1; + } + } +} + +/* + Extracts C++ function from source code and put them in a list. +*/ +void extractCppFunctions( const TQString& code, TQValueList<CppFunction> *flist ) +{ + startTokenizer( code ); + yyTok = getToken(); + matchTranslationUnit( flist ); + stopTokenizer(); +} + +/* + Returns the prototype with the parameter names removed. +*/ +TQString canonicalCppProto( const TQString& proto ) +{ + startTokenizer( proto ); + yyTok = getToken(); + CppFunction func = matchFunctionPrototype( TRUE ); + stopTokenizer(); + return func.prototype(); +} diff --git a/tools/designer/plugins/cppeditor/yyreg.h b/tools/designer/plugins/cppeditor/yyreg.h new file mode 100644 index 000000000..42a352e03 --- /dev/null +++ b/tools/designer/plugins/cppeditor/yyreg.h @@ -0,0 +1,88 @@ +/********************************************************************** +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef YYREG_H +#define YYREG_H + +#include <qstringlist.h> +#include <qvaluelist.h> + +class CppFunction +{ +public: + CppFunction() : cnst( FALSE ), lineno1( 0 ), lineno2( 0 ) { } + + void setReturnType( const TQString& r ) { ret = r; } + void setScopedName( const TQString& n ) { nam = n; } + void setParameterList( const TQStringList& p ) { params = p; } + void setConst( bool c ) { cnst = c; } + void setBody( const TQString& b ) { bod = b; } + void setDocumentation( const TQString& d ) { doc = d; } + void setLineNums( int functionStart, int openingBrace, int closingBrace ) { + lineno0 = functionStart; + lineno1 = openingBrace; + lineno2 = closingBrace; + } + + const TQString& returnType() const { return ret; } + const TQString& scopedName() const { return nam; } + const TQStringList& parameterList() const { return params; } + bool isConst() const { return cnst; } + TQString prototype() const; + const TQString& body() const { return bod; } + const TQString& documentation() const { return doc; } + int functionStartLineNum() const { return lineno0; } + int openingBraceLineNum() const { return lineno1; } + int closingBraceLineNum() const { return lineno2; } + +#if defined(Q_FULL_TEMPLATE_INSTANTIATION) + bool operator==( const CppFunction& ) const { return FALSE; } +#endif + +private: + TQString ret; + TQString nam; + TQStringList params; + bool cnst; + TQString bod; + TQString doc; + int lineno0; + int lineno1; + int lineno2; +}; + +void extractCppFunctions( const TQString& code, TQValueList<CppFunction> *flist ); +TQString canonicalCppProto( const TQString& proto ); + +#endif |