From 39f8a475b4ec5c87a11a7e9300a30ef1c5b4a7e1 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 31 Aug 2024 19:56:49 +0900 Subject: Rename remaining ntq[i-l]* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/dialogs/ntqinputdialog.h | 107 ---- src/dialogs/qinputdialog.cpp | 532 ----------------- src/dialogs/qprintdialog.cpp | 2 +- src/dialogs/qt_dialogs.pri | 4 +- src/dialogs/tqfiledialog.cpp | 2 +- src/dialogs/tqinputdialog.cpp | 532 +++++++++++++++++ src/dialogs/tqinputdialog.h | 107 ++++ src/inputmethod/ntqinputcontextfactory.h | 59 -- src/inputmethod/ntqinputcontextplugin.h | 67 --- src/inputmethod/qinputcontextfactory.cpp | 186 ------ src/inputmethod/qinputcontextinterface_p.h | 87 --- src/inputmethod/qinputcontextplugin.cpp | 231 -------- src/inputmethod/qt_inputmethod.pri | 10 +- src/inputmethod/tqinputcontextfactory.cpp | 186 ++++++ src/inputmethod/tqinputcontextfactory.h | 59 ++ src/inputmethod/tqinputcontextinterface_p.h | 87 +++ src/inputmethod/tqinputcontextplugin.cpp | 231 ++++++++ src/inputmethod/tqinputcontextplugin.h | 67 +++ src/kernel/ntqinputcontext.h | 131 ----- src/kernel/ntqjpegio.h | 52 -- src/kernel/ntqkeycode.h | 50 -- src/kernel/ntqkeysequence.h | 109 ---- src/kernel/ntqnamespace.h | 2 +- src/kernel/ntqt.h | 10 +- src/kernel/qapplication.cpp | 2 +- src/kernel/qapplication_x11.cpp | 2 +- src/kernel/qinputcontext.cpp | 849 ---------------------------- src/kernel/qinputcontext_p.h | 115 ---- src/kernel/qinputcontext_x11.cpp | 75 --- src/kernel/qjpegio.cpp | 595 ------------------- src/kernel/qkeysequence.cpp | 736 ------------------------ src/kernel/qscriptengine_x11.cpp | 2 +- src/kernel/qt_gfx.pri | 4 +- src/kernel/qt_kernel.pri | 16 +- src/kernel/qvariant.cpp | 2 +- src/kernel/tqaccel.h | 2 +- src/kernel/tqimage.cpp | 2 +- src/kernel/tqinputcontext.cpp | 849 ++++++++++++++++++++++++++++ src/kernel/tqinputcontext.h | 131 +++++ src/kernel/tqinputcontext_p.h | 115 ++++ src/kernel/tqinputcontext_x11.cpp | 75 +++ src/kernel/tqjpegio.cpp | 595 +++++++++++++++++++ src/kernel/tqjpegio.h | 52 ++ src/kernel/tqkeycode.h | 50 ++ src/kernel/tqkeysequence.cpp | 736 ++++++++++++++++++++++++ src/kernel/tqkeysequence.h | 109 ++++ src/kernel/tqttdeintegration_x11.cpp | 2 +- src/kernel/tqwidget.cpp | 2 +- src/kernel/tqwidget_x11.cpp | 4 +- src/libqt.map | 2 +- src/opengl/tqgl_x11.cpp | 2 +- src/tools/ntqlibrary.h | 86 --- src/tools/qcomlibrary_p.h | 2 +- src/tools/qlibrary.cpp | 443 --------------- src/tools/qlibrary_p.h | 84 --- src/tools/qlibrary_unix.cpp | 169 ------ src/tools/qt_tools.pri | 10 +- src/tools/qwinexport.cpp | 2 +- src/tools/tqfeatures.txt | 2 +- src/tools/tqgpluginmanager_p.h | 2 +- src/tools/tqlibrary.cpp | 443 +++++++++++++++ src/tools/tqlibrary.h | 86 +++ src/tools/tqlibrary_p.h | 84 +++ src/tools/tqlibrary_unix.cpp | 169 ++++++ src/tools/tqsettings.cpp | 2 +- src/widgets/tqaction.h | 2 +- src/widgets/tqbutton.h | 2 +- src/widgets/tqlineedit.cpp | 4 +- src/widgets/tqmenudata.h | 2 +- src/widgets/tqtextedit.cpp | 4 +- 70 files changed, 4817 insertions(+), 4817 deletions(-) delete mode 100644 src/dialogs/ntqinputdialog.h delete mode 100644 src/dialogs/qinputdialog.cpp create mode 100644 src/dialogs/tqinputdialog.cpp create mode 100644 src/dialogs/tqinputdialog.h delete mode 100644 src/inputmethod/ntqinputcontextfactory.h delete mode 100644 src/inputmethod/ntqinputcontextplugin.h delete mode 100644 src/inputmethod/qinputcontextfactory.cpp delete mode 100644 src/inputmethod/qinputcontextinterface_p.h delete mode 100644 src/inputmethod/qinputcontextplugin.cpp create mode 100644 src/inputmethod/tqinputcontextfactory.cpp create mode 100644 src/inputmethod/tqinputcontextfactory.h create mode 100644 src/inputmethod/tqinputcontextinterface_p.h create mode 100644 src/inputmethod/tqinputcontextplugin.cpp create mode 100644 src/inputmethod/tqinputcontextplugin.h delete mode 100644 src/kernel/ntqinputcontext.h delete mode 100644 src/kernel/ntqjpegio.h delete mode 100644 src/kernel/ntqkeycode.h delete mode 100644 src/kernel/ntqkeysequence.h delete mode 100644 src/kernel/qinputcontext.cpp delete mode 100644 src/kernel/qinputcontext_p.h delete mode 100644 src/kernel/qinputcontext_x11.cpp delete mode 100644 src/kernel/qjpegio.cpp delete mode 100644 src/kernel/qkeysequence.cpp create mode 100644 src/kernel/tqinputcontext.cpp create mode 100644 src/kernel/tqinputcontext.h create mode 100644 src/kernel/tqinputcontext_p.h create mode 100644 src/kernel/tqinputcontext_x11.cpp create mode 100644 src/kernel/tqjpegio.cpp create mode 100644 src/kernel/tqjpegio.h create mode 100644 src/kernel/tqkeycode.h create mode 100644 src/kernel/tqkeysequence.cpp create mode 100644 src/kernel/tqkeysequence.h delete mode 100644 src/tools/ntqlibrary.h delete mode 100644 src/tools/qlibrary.cpp delete mode 100644 src/tools/qlibrary_p.h delete mode 100644 src/tools/qlibrary_unix.cpp create mode 100644 src/tools/tqlibrary.cpp create mode 100644 src/tools/tqlibrary.h create mode 100644 src/tools/tqlibrary_p.h create mode 100644 src/tools/tqlibrary_unix.cpp (limited to 'src') diff --git a/src/dialogs/ntqinputdialog.h b/src/dialogs/ntqinputdialog.h deleted file mode 100644 index 67434b3ae..000000000 --- a/src/dialogs/ntqinputdialog.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Definition of TQInputDialog class -** -** Created : 991212 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQINPUTDIALOG_H -#define TQINPUTDIALOG_H - -#ifndef QT_H -#include "tqdialog.h" -#include "tqstring.h" -#include "tqlineedit.h" -#endif // QT_H - -#ifndef TQT_NO_INPUTDIALOG - -class TQSpinBox; -class TQComboBox; -class TQInputDialogPrivate; - -class TQ_EXPORT TQInputDialog : public TQDialog -{ - TQ_OBJECT - -private: - enum Type { LineEdit, SpinBox, ComboBox, EditableComboBox }; - - TQInputDialog( const TQString &label, TQWidget* parent=0, const char* name=0, - bool modal = TRUE, Type type = LineEdit ); //### 4.0: widget flag! - ~TQInputDialog(); - - TQLineEdit *lineEdit() const; - TQSpinBox *spinBox() const; - TQComboBox *comboBox() const; - TQComboBox *editableComboBox() const; - - void setType( Type t ); - Type type() const; - -public: - //### 4.0: widget flag! - static TQString getText( const TQString &caption, const TQString &label, TQLineEdit::EchoMode echo = TQLineEdit::Normal, - const TQString &text = TQString::null, bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); - static int getInteger( const TQString &caption, const TQString &label, int value = 0, int minValue = -2147483647, - int maxValue = 2147483647, - int step = 1, bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); - static double getDouble( const TQString &caption, const TQString &label, double value = 0, - double minValue = -2147483647, double maxValue = 2147483647, - int decimals = 1, bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); - static TQString getItem( const TQString &caption, const TQString &label, const TQStringList &list, - int current = 0, bool editable = TRUE, - bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); - -private slots: - void textChanged( const TQString &s ); - void tryAccept(); - -private: - TQInputDialogPrivate *d; - friend class TQInputDialogPrivate; /* to avoid 'has no friends' warnings... */ - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQInputDialog( const TQInputDialog & ); - TQInputDialog &operator=( const TQInputDialog & ); -#endif -}; - -#endif // TQT_NO_INPUTDIALOG - -#endif // TQINPUTDIALOG_H - diff --git a/src/dialogs/qinputdialog.cpp b/src/dialogs/qinputdialog.cpp deleted file mode 100644 index a459846df..000000000 --- a/src/dialogs/qinputdialog.cpp +++ /dev/null @@ -1,532 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQInputDialog class -** -** Created : 991212 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 "ntqinputdialog.h" - -#ifndef TQT_NO_INPUTDIALOG - -#include "tqlayout.h" -#include "tqlabel.h" -#include "tqlineedit.h" -#include "tqpushbutton.h" -#include "tqspinbox.h" -#include "tqcombobox.h" -#include "tqwidgetstack.h" -#include "tqvalidator.h" -#include "ntqapplication.h" - -class TQInputDialogPrivate -{ -public: - friend class TQInputDialog; - TQLabel *label; - TQLineEdit *lineEdit; - TQSpinBox *spinBox; - TQComboBox *comboBox, *editComboBox; - TQPushButton *ok; - TQWidgetStack *stack; - TQInputDialog::Type type; -}; - -/*! - \class TQInputDialog - \brief The TQInputDialog class provides a simple convenience dialog to get a single value from the user. - \ingroup dialogs - \mainclass - - The input value can be a string, a number or an item from a list. A - label must be set to tell the user what they should enter. - - Four static convenience functions are provided: - getText(), getInteger(), getDouble() and getItem(). All the - functions can be used in a similar way, for example: - \code - bool ok; - TQString text = TQInputDialog::getText( - "MyApp 3000", "Enter your name:", TQLineEdit::Normal, - TQString::null, &ok, this ); - if ( ok && !text.isEmpty() ) { - // user entered something and pressed OK - } else { - // user entered nothing or pressed Cancel - } - \endcode - - \img inputdialogs.png Input Dialogs -*/ - -/*! - \enum TQInputDialog::Type - - This enum specifies the type of the dialog, i.e. what kind of data you - want the user to input: - - \value LineEdit A TQLineEdit is used for obtaining string or numeric - input. The TQLineEdit can be accessed using lineEdit(). - - \value SpinBox A TQSpinBox is used for obtaining integer input. - Use spinBox() to access the TQSpinBox. - - \value ComboBox A read-only TQComboBox is used to provide a fixed - list of choices from which the user can choose. - Use comboBox() to access the TQComboBox. - - \value EditableComboBox An editable TQComboBox is used to provide a fixed - list of choices from which the user can choose, but which also - allows the user to enter their own value instead. - Use editableComboBox() to access the TQComboBox. -*/ - -/*! - Constructs the dialog. The \a label is the text which is shown to the user - (it should tell the user what they are expected to enter). The \a parent - is the dialog's parent widget. The widget is called \a name. If \a - modal is TRUE (the default) the dialog will be modal. The \a type - parameter is used to specify which type of dialog to construct. - - \sa getText(), getInteger(), getDouble(), getItem() -*/ - -TQInputDialog::TQInputDialog( const TQString &label, TQWidget* parent, - const char* name, bool modal, Type type ) - : TQDialog( parent, name, modal ) -{ - d = new TQInputDialogPrivate; - d->lineEdit = 0; - d->spinBox = 0; - d->comboBox = 0; - - TQVBoxLayout *vbox = new TQVBoxLayout( this, 6, 6 ); - - d->label = new TQLabel( label, this, "qt_inputdlg_lbl" ); - vbox->addWidget( d->label ); - - d->stack = new TQWidgetStack( this, "qt_inputdlg_ws" ); - vbox->addWidget( d->stack ); - d->lineEdit = new TQLineEdit( d->stack, "qt_inputdlg_le" ); - d->spinBox = new TQSpinBox( d->stack, "qt_inputdlg_sb" ); - d->comboBox = new TQComboBox( FALSE, d->stack, "qt_inputdlg_cb" ); - d->editComboBox = new TQComboBox( TRUE, d->stack, "qt_inputdlg_editcb" ); - - TQHBoxLayout *hbox = new TQHBoxLayout( 6 ); - vbox->addLayout( hbox, AlignRight ); - - d->ok = new TQPushButton( tr( "OK" ), this, "qt_ok_btn" ); - d->ok->setDefault( TRUE ); - TQPushButton *cancel = new TQPushButton( tr( "Cancel" ), this, "qt_cancel_btn" ); - - TQSize bs = d->ok->sizeHint().expandedTo( cancel->sizeHint() ); - d->ok->setFixedSize( bs ); - cancel->setFixedSize( bs ); - - hbox->addStretch(); - hbox->addWidget( d->ok ); - hbox->addWidget( cancel ); - - connect( d->lineEdit, TQ_SIGNAL( returnPressed() ), - this, TQ_SLOT( tryAccept() ) ); - connect( d->lineEdit, TQ_SIGNAL( textChanged(const TQString&) ), - this, TQ_SLOT( textChanged(const TQString&) ) ); - - connect( d->ok, TQ_SIGNAL( clicked() ), this, TQ_SLOT( accept() ) ); - connect( cancel, TQ_SIGNAL( clicked() ), this, TQ_SLOT( reject() ) ); - - TQSize sh = sizeHint().expandedTo( TQSize(400, 10) ); - setType( type ); - resize( sh.width(), vbox->heightForWidth(sh.width()) ); -} - -/*! - Returns the line edit which is used in LineEdit mode. -*/ - -TQLineEdit *TQInputDialog::lineEdit() const -{ - return d->lineEdit; -} - -/*! - Returns the spinbox which is used in SpinBox mode. -*/ - -TQSpinBox *TQInputDialog::spinBox() const -{ - return d->spinBox; -} - -/*! - Returns the combobox which is used in ComboBox mode. -*/ - -TQComboBox *TQInputDialog::comboBox() const -{ - return d->comboBox; -} - -/*! - Returns the combobox which is used in EditableComboBox mode. -*/ - -TQComboBox *TQInputDialog::editableComboBox() const -{ - return d->editComboBox; -} - -/*! - Sets the input type of the dialog to \a t. -*/ - -void TQInputDialog::setType( Type t ) -{ - TQWidget *input = 0; - switch ( t ) { - case LineEdit: - input = d->lineEdit; - break; - case SpinBox: - input = d->spinBox; - break; - case ComboBox: - input = d->comboBox; - break; - case EditableComboBox: - input = d->editComboBox; - break; - default: -#if defined(QT_CHECK_STATE) - tqWarning( "TQInputDialog::setType: Invalid type" ); -#endif - break; - } - if ( input ) { - d->stack->raiseWidget( input ); - d->stack->setFixedHeight( input->sizeHint().height() ); - input->setFocus(); -#ifndef TQT_NO_ACCEL - d->label->setBuddy( input ); -#endif - } - - d->type = t; -} - -/*! - Returns the input type of the dialog. - - \sa setType() -*/ - -TQInputDialog::Type TQInputDialog::type() const -{ - return d->type; -} - -/*! - Destructor. -*/ - -TQInputDialog::~TQInputDialog() -{ - delete d; -} - -/*! - Static convenience function to get a string from the user. \a - caption is the text which is displayed in the title bar of the - dialog. \a label is the text which is shown to the user (it should - say what should be entered). \a text is the default text which is - placed in the line edit. The \a mode is the echo mode the line edit - will use. If \a ok is not-null \e *\a ok will be set to TRUE if the - user pressed OK and to FALSE if the user pressed Cancel. The - dialog's parent is \a parent; the dialog is called \a name. The - dialog will be modal. - - This function returns the text which has been entered in the line - edit. It will not return an empty string. - - Use this static function like this: - - \code - bool ok; - TQString text = TQInputDialog::getText( - "MyApp 3000", "Enter your name:", TQLineEdit::Normal, - TQString::null, &ok, this ); - if ( ok && !text.isEmpty() ) { - // user entered something and pressed OK - } else { - // user entered nothing or pressed Cancel - } - \endcode -*/ - -TQString TQInputDialog::getText( const TQString &caption, const TQString &label, - TQLineEdit::EchoMode mode, const TQString &text, - bool *ok, TQWidget *parent, const char *name ) -{ - TQInputDialog *dlg = new TQInputDialog( label, parent, - name ? name : "qt_inputdlg_gettext", - TRUE, LineEdit ); - -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg->setCaption( caption ); -#endif - dlg->lineEdit()->setText( text ); - dlg->lineEdit()->setEchoMode( mode ); - - bool ok_ = FALSE; - TQString result; - ok_ = dlg->exec() == TQDialog::Accepted; - if ( ok ) - *ok = ok_; - if ( ok_ ) - result = dlg->lineEdit()->text(); - - delete dlg; - return result; -} - -/*! - Static convenience function to get an integer input from the - user. \a caption is the text which is displayed in the title bar - of the dialog. \a label is the text which is shown to the user - (it should say what should be entered). \a value is the default - integer which the spinbox will be set to. \a minValue and \a - maxValue are the minimum and maximum values the user may choose, - and \a step is the amount by which the values change as the user - presses the arrow buttons to increment or decrement the value. - - If \a ok is not-null *\a ok will be set to TRUE if the user - pressed OK and to FALSE if the user pressed Cancel. The dialog's - parent is \a parent; the dialog is called \a name. The dialog will - be modal. - - This function returns the integer which has been entered by the user. - - Use this static function like this: - - \code - bool ok; - int res = TQInputDialog::getInteger( - "MyApp 3000", "Enter a number:", 22, 0, 1000, 2, - &ok, this ); - if ( ok ) { - // user entered something and pressed OK - } else { - // user pressed Cancel - } - \endcode -*/ - -int TQInputDialog::getInteger( const TQString &caption, const TQString &label, - int value, int minValue, int maxValue, int step, bool *ok, - TQWidget *parent, const char *name ) -{ - TQInputDialog *dlg = new TQInputDialog( label, parent, - name ? name : "qt_inputdlg_getint", - TRUE, SpinBox ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg->setCaption( caption ); -#endif - dlg->spinBox()->setRange( minValue, maxValue ); - dlg->spinBox()->setSteps( step, 0 ); - dlg->spinBox()->setValue( value ); - - bool ok_ = FALSE; - int result; - ok_ = dlg->exec() == TQDialog::Accepted; - if ( ok ) - *ok = ok_; - result = dlg->spinBox()->value(); - - delete dlg; - return result; -} - -/*! - Static convenience function to get a floating point number from - the user. \a caption is the text which is displayed in the title - bar of the dialog. \a label is the text which is shown to the user - (it should say what should be entered). \a value is the default - floating point number that the line edit will be set to. \a - minValue and \a maxValue are the minimum and maximum values the - user may choose, and \a decimals is the maximum number of decimal - places the number may have. - - If \a ok is not-null \e *\a ok will be set to TRUE if the user - pressed OK and to FALSE if the user pressed Cancel. The dialog's - parent is \a parent; the dialog is called \a name. The dialog will - be modal. - - This function returns the floating point number which has been - entered by the user. - - Use this static function like this: - - \code - bool ok; - double res = TQInputDialog::getDouble( - "MyApp 3000", "Enter a decimal number:", 33.7, 0, - 1000, 2, &ok, this ); - if ( ok ) { - // user entered something and pressed OK - } else { - // user pressed Cancel - } - \endcode -*/ - -double TQInputDialog::getDouble( const TQString &caption, const TQString &label, - double value, double minValue, double maxValue, - int decimals, bool *ok, TQWidget *parent, - const char *name ) -{ - TQInputDialog dlg( label, parent, - name ? name : "qt_inputdlg_getdbl", TRUE, LineEdit ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg.setCaption( caption ); -#endif - dlg.lineEdit()->setValidator( new TQDoubleValidator( minValue, maxValue, decimals, dlg.lineEdit() ) ); - dlg.lineEdit()->setText( TQString::number( value, 'f', decimals ) ); - dlg.lineEdit()->selectAll(); - - bool accepted = ( dlg.exec() == TQDialog::Accepted ); - if ( ok ) - *ok = accepted; - return dlg.lineEdit()->text().toDouble(); -} - -/*! - Static convenience function to let the user select an item from a - string list. \a caption is the text which is displayed in the title - bar of the dialog. \a label is the text which is shown to the user (it - should say what should be entered). \a list is the - string list which is inserted into the combobox, and \a current is the number - of the item which should be the current item. If \a editable is TRUE - the user can enter their own text; if \a editable is FALSE the user - may only select one of the existing items. - - If \a ok is not-null \e *\a ok will be set to TRUE if the user - pressed OK and to FALSE if the user pressed Cancel. The dialog's - parent is \a parent; the dialog is called \a name. The dialog will - be modal. - - This function returns the text of the current item, or if \a - editable is TRUE, the current text of the combobox. - - Use this static function like this: - - \code - TQStringList lst; - lst << "First" << "Second" << "Third" << "Fourth" << "Fifth"; - bool ok; - TQString res = TQInputDialog::getItem( - "MyApp 3000", "Select an item:", lst, 1, TRUE, &ok, - this ); - if ( ok ) { - // user selected an item and pressed OK - } else { - // user pressed Cancel - } - \endcode -*/ - -TQString TQInputDialog::getItem( const TQString &caption, const TQString &label, const TQStringList &list, - int current, bool editable, - bool *ok, TQWidget *parent, const char *name ) -{ - TQInputDialog *dlg = new TQInputDialog( label, parent, name ? name : "qt_inputdlg_getitem", TRUE, editable ? EditableComboBox : ComboBox ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg->setCaption( caption ); -#endif - if ( editable ) { - dlg->editableComboBox()->insertStringList( list ); - dlg->editableComboBox()->setCurrentItem( current ); - } else { - dlg->comboBox()->insertStringList( list ); - dlg->comboBox()->setCurrentItem( current ); - } - - bool ok_ = FALSE; - TQString result; - ok_ = dlg->exec() == TQDialog::Accepted; - if ( ok ) - *ok = ok_; - if ( editable ) - result = dlg->editableComboBox()->currentText(); - else - result = dlg->comboBox()->currentText(); - - delete dlg; - return result; -} - -/*! - \internal - - This slot is invoked when the text is changed; the new text is passed - in \a s. -*/ - -void TQInputDialog::textChanged( const TQString &s ) -{ - bool on = TRUE; - - if ( d->lineEdit->validator() ) { - TQString str = d->lineEdit->text(); - int index = d->lineEdit->cursorPosition(); - on = ( d->lineEdit->validator()->validate(str, index) == - TQValidator::Acceptable ); - } else if ( type() != LineEdit ) { - on = !s.isEmpty(); - } - d->ok->setEnabled( on ); -} - -/*! - \internal -*/ - -void TQInputDialog::tryAccept() -{ - if ( !d->lineEdit->text().isEmpty() ) - accept(); -} - -#endif diff --git a/src/dialogs/qprintdialog.cpp b/src/dialogs/qprintdialog.cpp index 16c964f58..9096ff9f6 100644 --- a/src/dialogs/qprintdialog.cpp +++ b/src/dialogs/qprintdialog.cpp @@ -62,7 +62,7 @@ #include "tqstring.h" #include "tqregexp.h" #if !defined(TQT_NO_CUPS) || !defined(TQT_NO_NIS) -#include "ntqlibrary.h" +#include "tqlibrary.h" #endif #ifndef TQT_NO_NIS diff --git a/src/dialogs/qt_dialogs.pri b/src/dialogs/qt_dialogs.pri index 4957a1e70..9702afad1 100644 --- a/src/dialogs/qt_dialogs.pri +++ b/src/dialogs/qt_dialogs.pri @@ -12,7 +12,7 @@ dialogs { $$DIALOGS_H/tqprogressdialog.h \ $$DIALOGS_H/tqtabdialog.h \ $$DIALOGS_H/tqwizard.h \ - $$DIALOGS_H/ntqinputdialog.h + $$DIALOGS_H/tqinputdialog.h !embedded:mac:SOURCES += $$DIALOGS_CPP/tqfiledialog_mac.cpp $$DIALOGS_CPP/tqcolordialog_mac.cpp win32:SOURCES += $$DIALOGS_CPP/tqfiledialog_win.cpp @@ -28,5 +28,5 @@ dialogs { $$DIALOGS_CPP/tqprogressdialog.cpp \ $$DIALOGS_CPP/tqtabdialog.cpp \ $$DIALOGS_CPP/tqwizard.cpp \ - $$DIALOGS_CPP/qinputdialog.cpp + $$DIALOGS_CPP/tqinputdialog.cpp } diff --git a/src/dialogs/tqfiledialog.cpp b/src/dialogs/tqfiledialog.cpp index 6eb5006a6..77de59b62 100644 --- a/src/dialogs/tqfiledialog.cpp +++ b/src/dialogs/tqfiledialog.cpp @@ -70,7 +70,7 @@ #include "tqheader.h" #include "tqlabel.h" #include "tqlayout.h" -#include "ntqlibrary.h" +#include "tqlibrary.h" #include "tqlineedit.h" #include "tqlistbox.h" #include "tqlistview.h" diff --git a/src/dialogs/tqinputdialog.cpp b/src/dialogs/tqinputdialog.cpp new file mode 100644 index 000000000..b23bbaeaf --- /dev/null +++ b/src/dialogs/tqinputdialog.cpp @@ -0,0 +1,532 @@ +/**************************************************************************** +** +** Implementation of TQInputDialog class +** +** Created : 991212 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 "tqinputdialog.h" + +#ifndef TQT_NO_INPUTDIALOG + +#include "tqlayout.h" +#include "tqlabel.h" +#include "tqlineedit.h" +#include "tqpushbutton.h" +#include "tqspinbox.h" +#include "tqcombobox.h" +#include "tqwidgetstack.h" +#include "tqvalidator.h" +#include "ntqapplication.h" + +class TQInputDialogPrivate +{ +public: + friend class TQInputDialog; + TQLabel *label; + TQLineEdit *lineEdit; + TQSpinBox *spinBox; + TQComboBox *comboBox, *editComboBox; + TQPushButton *ok; + TQWidgetStack *stack; + TQInputDialog::Type type; +}; + +/*! + \class TQInputDialog + \brief The TQInputDialog class provides a simple convenience dialog to get a single value from the user. + \ingroup dialogs + \mainclass + + The input value can be a string, a number or an item from a list. A + label must be set to tell the user what they should enter. + + Four static convenience functions are provided: + getText(), getInteger(), getDouble() and getItem(). All the + functions can be used in a similar way, for example: + \code + bool ok; + TQString text = TQInputDialog::getText( + "MyApp 3000", "Enter your name:", TQLineEdit::Normal, + TQString::null, &ok, this ); + if ( ok && !text.isEmpty() ) { + // user entered something and pressed OK + } else { + // user entered nothing or pressed Cancel + } + \endcode + + \img inputdialogs.png Input Dialogs +*/ + +/*! + \enum TQInputDialog::Type + + This enum specifies the type of the dialog, i.e. what kind of data you + want the user to input: + + \value LineEdit A TQLineEdit is used for obtaining string or numeric + input. The TQLineEdit can be accessed using lineEdit(). + + \value SpinBox A TQSpinBox is used for obtaining integer input. + Use spinBox() to access the TQSpinBox. + + \value ComboBox A read-only TQComboBox is used to provide a fixed + list of choices from which the user can choose. + Use comboBox() to access the TQComboBox. + + \value EditableComboBox An editable TQComboBox is used to provide a fixed + list of choices from which the user can choose, but which also + allows the user to enter their own value instead. + Use editableComboBox() to access the TQComboBox. +*/ + +/*! + Constructs the dialog. The \a label is the text which is shown to the user + (it should tell the user what they are expected to enter). The \a parent + is the dialog's parent widget. The widget is called \a name. If \a + modal is TRUE (the default) the dialog will be modal. The \a type + parameter is used to specify which type of dialog to construct. + + \sa getText(), getInteger(), getDouble(), getItem() +*/ + +TQInputDialog::TQInputDialog( const TQString &label, TQWidget* parent, + const char* name, bool modal, Type type ) + : TQDialog( parent, name, modal ) +{ + d = new TQInputDialogPrivate; + d->lineEdit = 0; + d->spinBox = 0; + d->comboBox = 0; + + TQVBoxLayout *vbox = new TQVBoxLayout( this, 6, 6 ); + + d->label = new TQLabel( label, this, "qt_inputdlg_lbl" ); + vbox->addWidget( d->label ); + + d->stack = new TQWidgetStack( this, "qt_inputdlg_ws" ); + vbox->addWidget( d->stack ); + d->lineEdit = new TQLineEdit( d->stack, "qt_inputdlg_le" ); + d->spinBox = new TQSpinBox( d->stack, "qt_inputdlg_sb" ); + d->comboBox = new TQComboBox( FALSE, d->stack, "qt_inputdlg_cb" ); + d->editComboBox = new TQComboBox( TRUE, d->stack, "qt_inputdlg_editcb" ); + + TQHBoxLayout *hbox = new TQHBoxLayout( 6 ); + vbox->addLayout( hbox, AlignRight ); + + d->ok = new TQPushButton( tr( "OK" ), this, "qt_ok_btn" ); + d->ok->setDefault( TRUE ); + TQPushButton *cancel = new TQPushButton( tr( "Cancel" ), this, "qt_cancel_btn" ); + + TQSize bs = d->ok->sizeHint().expandedTo( cancel->sizeHint() ); + d->ok->setFixedSize( bs ); + cancel->setFixedSize( bs ); + + hbox->addStretch(); + hbox->addWidget( d->ok ); + hbox->addWidget( cancel ); + + connect( d->lineEdit, TQ_SIGNAL( returnPressed() ), + this, TQ_SLOT( tryAccept() ) ); + connect( d->lineEdit, TQ_SIGNAL( textChanged(const TQString&) ), + this, TQ_SLOT( textChanged(const TQString&) ) ); + + connect( d->ok, TQ_SIGNAL( clicked() ), this, TQ_SLOT( accept() ) ); + connect( cancel, TQ_SIGNAL( clicked() ), this, TQ_SLOT( reject() ) ); + + TQSize sh = sizeHint().expandedTo( TQSize(400, 10) ); + setType( type ); + resize( sh.width(), vbox->heightForWidth(sh.width()) ); +} + +/*! + Returns the line edit which is used in LineEdit mode. +*/ + +TQLineEdit *TQInputDialog::lineEdit() const +{ + return d->lineEdit; +} + +/*! + Returns the spinbox which is used in SpinBox mode. +*/ + +TQSpinBox *TQInputDialog::spinBox() const +{ + return d->spinBox; +} + +/*! + Returns the combobox which is used in ComboBox mode. +*/ + +TQComboBox *TQInputDialog::comboBox() const +{ + return d->comboBox; +} + +/*! + Returns the combobox which is used in EditableComboBox mode. +*/ + +TQComboBox *TQInputDialog::editableComboBox() const +{ + return d->editComboBox; +} + +/*! + Sets the input type of the dialog to \a t. +*/ + +void TQInputDialog::setType( Type t ) +{ + TQWidget *input = 0; + switch ( t ) { + case LineEdit: + input = d->lineEdit; + break; + case SpinBox: + input = d->spinBox; + break; + case ComboBox: + input = d->comboBox; + break; + case EditableComboBox: + input = d->editComboBox; + break; + default: +#if defined(QT_CHECK_STATE) + tqWarning( "TQInputDialog::setType: Invalid type" ); +#endif + break; + } + if ( input ) { + d->stack->raiseWidget( input ); + d->stack->setFixedHeight( input->sizeHint().height() ); + input->setFocus(); +#ifndef TQT_NO_ACCEL + d->label->setBuddy( input ); +#endif + } + + d->type = t; +} + +/*! + Returns the input type of the dialog. + + \sa setType() +*/ + +TQInputDialog::Type TQInputDialog::type() const +{ + return d->type; +} + +/*! + Destructor. +*/ + +TQInputDialog::~TQInputDialog() +{ + delete d; +} + +/*! + Static convenience function to get a string from the user. \a + caption is the text which is displayed in the title bar of the + dialog. \a label is the text which is shown to the user (it should + say what should be entered). \a text is the default text which is + placed in the line edit. The \a mode is the echo mode the line edit + will use. If \a ok is not-null \e *\a ok will be set to TRUE if the + user pressed OK and to FALSE if the user pressed Cancel. The + dialog's parent is \a parent; the dialog is called \a name. The + dialog will be modal. + + This function returns the text which has been entered in the line + edit. It will not return an empty string. + + Use this static function like this: + + \code + bool ok; + TQString text = TQInputDialog::getText( + "MyApp 3000", "Enter your name:", TQLineEdit::Normal, + TQString::null, &ok, this ); + if ( ok && !text.isEmpty() ) { + // user entered something and pressed OK + } else { + // user entered nothing or pressed Cancel + } + \endcode +*/ + +TQString TQInputDialog::getText( const TQString &caption, const TQString &label, + TQLineEdit::EchoMode mode, const TQString &text, + bool *ok, TQWidget *parent, const char *name ) +{ + TQInputDialog *dlg = new TQInputDialog( label, parent, + name ? name : "qt_inputdlg_gettext", + TRUE, LineEdit ); + +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg->setCaption( caption ); +#endif + dlg->lineEdit()->setText( text ); + dlg->lineEdit()->setEchoMode( mode ); + + bool ok_ = FALSE; + TQString result; + ok_ = dlg->exec() == TQDialog::Accepted; + if ( ok ) + *ok = ok_; + if ( ok_ ) + result = dlg->lineEdit()->text(); + + delete dlg; + return result; +} + +/*! + Static convenience function to get an integer input from the + user. \a caption is the text which is displayed in the title bar + of the dialog. \a label is the text which is shown to the user + (it should say what should be entered). \a value is the default + integer which the spinbox will be set to. \a minValue and \a + maxValue are the minimum and maximum values the user may choose, + and \a step is the amount by which the values change as the user + presses the arrow buttons to increment or decrement the value. + + If \a ok is not-null *\a ok will be set to TRUE if the user + pressed OK and to FALSE if the user pressed Cancel. The dialog's + parent is \a parent; the dialog is called \a name. The dialog will + be modal. + + This function returns the integer which has been entered by the user. + + Use this static function like this: + + \code + bool ok; + int res = TQInputDialog::getInteger( + "MyApp 3000", "Enter a number:", 22, 0, 1000, 2, + &ok, this ); + if ( ok ) { + // user entered something and pressed OK + } else { + // user pressed Cancel + } + \endcode +*/ + +int TQInputDialog::getInteger( const TQString &caption, const TQString &label, + int value, int minValue, int maxValue, int step, bool *ok, + TQWidget *parent, const char *name ) +{ + TQInputDialog *dlg = new TQInputDialog( label, parent, + name ? name : "qt_inputdlg_getint", + TRUE, SpinBox ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg->setCaption( caption ); +#endif + dlg->spinBox()->setRange( minValue, maxValue ); + dlg->spinBox()->setSteps( step, 0 ); + dlg->spinBox()->setValue( value ); + + bool ok_ = FALSE; + int result; + ok_ = dlg->exec() == TQDialog::Accepted; + if ( ok ) + *ok = ok_; + result = dlg->spinBox()->value(); + + delete dlg; + return result; +} + +/*! + Static convenience function to get a floating point number from + the user. \a caption is the text which is displayed in the title + bar of the dialog. \a label is the text which is shown to the user + (it should say what should be entered). \a value is the default + floating point number that the line edit will be set to. \a + minValue and \a maxValue are the minimum and maximum values the + user may choose, and \a decimals is the maximum number of decimal + places the number may have. + + If \a ok is not-null \e *\a ok will be set to TRUE if the user + pressed OK and to FALSE if the user pressed Cancel. The dialog's + parent is \a parent; the dialog is called \a name. The dialog will + be modal. + + This function returns the floating point number which has been + entered by the user. + + Use this static function like this: + + \code + bool ok; + double res = TQInputDialog::getDouble( + "MyApp 3000", "Enter a decimal number:", 33.7, 0, + 1000, 2, &ok, this ); + if ( ok ) { + // user entered something and pressed OK + } else { + // user pressed Cancel + } + \endcode +*/ + +double TQInputDialog::getDouble( const TQString &caption, const TQString &label, + double value, double minValue, double maxValue, + int decimals, bool *ok, TQWidget *parent, + const char *name ) +{ + TQInputDialog dlg( label, parent, + name ? name : "qt_inputdlg_getdbl", TRUE, LineEdit ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg.setCaption( caption ); +#endif + dlg.lineEdit()->setValidator( new TQDoubleValidator( minValue, maxValue, decimals, dlg.lineEdit() ) ); + dlg.lineEdit()->setText( TQString::number( value, 'f', decimals ) ); + dlg.lineEdit()->selectAll(); + + bool accepted = ( dlg.exec() == TQDialog::Accepted ); + if ( ok ) + *ok = accepted; + return dlg.lineEdit()->text().toDouble(); +} + +/*! + Static convenience function to let the user select an item from a + string list. \a caption is the text which is displayed in the title + bar of the dialog. \a label is the text which is shown to the user (it + should say what should be entered). \a list is the + string list which is inserted into the combobox, and \a current is the number + of the item which should be the current item. If \a editable is TRUE + the user can enter their own text; if \a editable is FALSE the user + may only select one of the existing items. + + If \a ok is not-null \e *\a ok will be set to TRUE if the user + pressed OK and to FALSE if the user pressed Cancel. The dialog's + parent is \a parent; the dialog is called \a name. The dialog will + be modal. + + This function returns the text of the current item, or if \a + editable is TRUE, the current text of the combobox. + + Use this static function like this: + + \code + TQStringList lst; + lst << "First" << "Second" << "Third" << "Fourth" << "Fifth"; + bool ok; + TQString res = TQInputDialog::getItem( + "MyApp 3000", "Select an item:", lst, 1, TRUE, &ok, + this ); + if ( ok ) { + // user selected an item and pressed OK + } else { + // user pressed Cancel + } + \endcode +*/ + +TQString TQInputDialog::getItem( const TQString &caption, const TQString &label, const TQStringList &list, + int current, bool editable, + bool *ok, TQWidget *parent, const char *name ) +{ + TQInputDialog *dlg = new TQInputDialog( label, parent, name ? name : "qt_inputdlg_getitem", TRUE, editable ? EditableComboBox : ComboBox ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg->setCaption( caption ); +#endif + if ( editable ) { + dlg->editableComboBox()->insertStringList( list ); + dlg->editableComboBox()->setCurrentItem( current ); + } else { + dlg->comboBox()->insertStringList( list ); + dlg->comboBox()->setCurrentItem( current ); + } + + bool ok_ = FALSE; + TQString result; + ok_ = dlg->exec() == TQDialog::Accepted; + if ( ok ) + *ok = ok_; + if ( editable ) + result = dlg->editableComboBox()->currentText(); + else + result = dlg->comboBox()->currentText(); + + delete dlg; + return result; +} + +/*! + \internal + + This slot is invoked when the text is changed; the new text is passed + in \a s. +*/ + +void TQInputDialog::textChanged( const TQString &s ) +{ + bool on = TRUE; + + if ( d->lineEdit->validator() ) { + TQString str = d->lineEdit->text(); + int index = d->lineEdit->cursorPosition(); + on = ( d->lineEdit->validator()->validate(str, index) == + TQValidator::Acceptable ); + } else if ( type() != LineEdit ) { + on = !s.isEmpty(); + } + d->ok->setEnabled( on ); +} + +/*! + \internal +*/ + +void TQInputDialog::tryAccept() +{ + if ( !d->lineEdit->text().isEmpty() ) + accept(); +} + +#endif diff --git a/src/dialogs/tqinputdialog.h b/src/dialogs/tqinputdialog.h new file mode 100644 index 000000000..67434b3ae --- /dev/null +++ b/src/dialogs/tqinputdialog.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Definition of TQInputDialog class +** +** Created : 991212 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQINPUTDIALOG_H +#define TQINPUTDIALOG_H + +#ifndef QT_H +#include "tqdialog.h" +#include "tqstring.h" +#include "tqlineedit.h" +#endif // QT_H + +#ifndef TQT_NO_INPUTDIALOG + +class TQSpinBox; +class TQComboBox; +class TQInputDialogPrivate; + +class TQ_EXPORT TQInputDialog : public TQDialog +{ + TQ_OBJECT + +private: + enum Type { LineEdit, SpinBox, ComboBox, EditableComboBox }; + + TQInputDialog( const TQString &label, TQWidget* parent=0, const char* name=0, + bool modal = TRUE, Type type = LineEdit ); //### 4.0: widget flag! + ~TQInputDialog(); + + TQLineEdit *lineEdit() const; + TQSpinBox *spinBox() const; + TQComboBox *comboBox() const; + TQComboBox *editableComboBox() const; + + void setType( Type t ); + Type type() const; + +public: + //### 4.0: widget flag! + static TQString getText( const TQString &caption, const TQString &label, TQLineEdit::EchoMode echo = TQLineEdit::Normal, + const TQString &text = TQString::null, bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); + static int getInteger( const TQString &caption, const TQString &label, int value = 0, int minValue = -2147483647, + int maxValue = 2147483647, + int step = 1, bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); + static double getDouble( const TQString &caption, const TQString &label, double value = 0, + double minValue = -2147483647, double maxValue = 2147483647, + int decimals = 1, bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); + static TQString getItem( const TQString &caption, const TQString &label, const TQStringList &list, + int current = 0, bool editable = TRUE, + bool *ok = 0, TQWidget *parent = 0, const char *name = 0 ); + +private slots: + void textChanged( const TQString &s ); + void tryAccept(); + +private: + TQInputDialogPrivate *d; + friend class TQInputDialogPrivate; /* to avoid 'has no friends' warnings... */ + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQInputDialog( const TQInputDialog & ); + TQInputDialog &operator=( const TQInputDialog & ); +#endif +}; + +#endif // TQT_NO_INPUTDIALOG + +#endif // TQINPUTDIALOG_H + diff --git a/src/inputmethod/ntqinputcontextfactory.h b/src/inputmethod/ntqinputcontextfactory.h deleted file mode 100644 index ddebf25b8..000000000 --- a/src/inputmethod/ntqinputcontextfactory.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** $Id: ntqinputcontextfactory.h,v 1.1.1.1 2004/05/11 11:16:49 daisuke Exp $ -** -** Definition of TQInputContextFactory class -** -** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef TQINPUTCONTEXTFACTORY_H -#define TQINPUTCONTEXTFACTORY_H - -#ifndef QT_H -#include "tqstringlist.h" -#endif // QT_H - -#ifndef TQT_NO_IM - -class TQInputContext; -class TQWidget; - -class TQ_EXPORT TQInputContextFactory -{ -public: - static TQStringList keys(); - static TQInputContext *create( const TQString &key, TQWidget *widget ); // should be a toplevel widget - static TQStringList languages( const TQString &key ); - static TQString displayName( const TQString &key ); - static TQString description( const TQString &key ); -}; -#endif //TQT_NO_IM - -#endif //TQINPUTCONTEXTFACTORY_H diff --git a/src/inputmethod/ntqinputcontextplugin.h b/src/inputmethod/ntqinputcontextplugin.h deleted file mode 100644 index a67d0b26a..000000000 --- a/src/inputmethod/ntqinputcontextplugin.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** $Id: ntqinputcontextplugin.h,v 1.2 2004/06/20 18:43:11 daisuke Exp $ -** -** Definition of TQInputContextPlugin class -** -** Created : 010920 -** -** Copyright (C) 2001 Trolltech AS. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef TQINPUTCONTEXTPLUGIN_H -#define TQINPUTCONTEXTPLUGIN_H - -#ifndef QT_H -#include "tqgplugin.h" -#include "tqstringlist.h" -#endif // QT_H - -#ifndef TQT_NO_IM -class TQInputContext; -class TQInputContextPluginPrivate; - -class TQ_EXPORT TQInputContextPlugin : public TQGPlugin -{ - TQ_OBJECT -public: - TQInputContextPlugin(); - ~TQInputContextPlugin(); - - virtual TQStringList keys() const = 0; - virtual TQInputContext *create( const TQString &key ) = 0; - virtual TQStringList languages( const TQString &key ) = 0; - virtual TQString displayName( const TQString &key ) = 0; - virtual TQString description( const TQString &key ) = 0; - -private: - TQInputContextPluginPrivate *d; -}; -#endif // TQT_NO_IM -#endif // TQINPUTCONTEXTPLUGIN_H diff --git a/src/inputmethod/qinputcontextfactory.cpp b/src/inputmethod/qinputcontextfactory.cpp deleted file mode 100644 index 63aff8375..000000000 --- a/src/inputmethod/qinputcontextfactory.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** $Id: qinputcontextfactory.cpp,v 1.2 2004/06/20 18:43:11 daisuke Exp $ -** -** Implementation of TQInputContextFactory class -** -** Created : 001103 -** -** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#include "qinputcontextinterface_p.h" // up here for GCC 2.7.* compatibility -#include "ntqinputcontextfactory.h" -#include "ntqinputcontext.h" - -#ifndef TQT_NO_IM - -#include "ntqapplication.h" - -#ifdef TQT_THREAD_SUPPORT -#include -#endif // TQT_THREAD_SUPPORT - -#include - -#include "tqcleanuphandler.h" -#include -#ifndef TQT_NO_COMPONENT - - -static TQPluginManager *manager = 0; -static TQSingleCleanupHandler< TQPluginManager > cleanup_manager; - -static void create_manager() -{ - if( manager ) // already created - return; - -#ifdef TQT_THREAD_SUPPORT - // protect manager creation - TQMutexLocker locker( tqt_global_mutexpool ? - tqt_global_mutexpool->get( &manager ) : 0); - - // we check the manager pointer again to make sure that another thread - // has not created the manager before us. - - if ( manager ) // already created - return; -#endif - - manager = new TQPluginManager( IID_QInputContextFactory, TQApplication::libraryPaths(), "/inputmethods", FALSE ); - - TQ_CHECK_PTR( manager ); - cleanup_manager.set( &manager ); -} - -#endif //TQT_NO_COMPONENT - - -/*! - This function generates the input context that has the identifier - name which is in agreement with \a key. \a widget is the client - widget of TQInputContext. \a widget may be null. -*/ -TQInputContext *TQInputContextFactory::create( const TQString& key, TQWidget *widget ) -{ - TQInputContext *ret = 0; - TQString inputcontext = key; -#ifndef TQT_NO_COMPONENT - // make sure the manager is created - create_manager(); - - TQInterfacePtr iface; - manager->queryInterface( inputcontext, &iface ); - - if ( iface ) { - ret = iface->create( inputcontext ); -#ifdef TQ_WS_X11 - if ( ret ) - ret->setHolderWidget( widget ); -#endif - } -#endif - return ret; -} - - -/*! - This function returns the list of the names input methods. - Only input methods included in default and placed under - $TQTDIR/plugins/inputmethods are listed. -*/ -TQStringList TQInputContextFactory::keys() -{ - TQStringList list; -#ifndef TQT_NO_COMPONENT - // make sure the manager is created - create_manager(); - - list = manager->featureList(); -#endif //TQT_NO_COMPONENT - - return list; -} - - -TQStringList TQInputContextFactory::languages( const TQString &key ) -{ - TQStringList result; -#ifndef TQT_NO_COMPONENT - // make sure the manager is created - create_manager(); - - TQInterfacePtr iface; - manager->queryInterface( key, &iface ); - - if ( iface ) - result = iface->languages( key ); -#endif //TQT_NO_COMPONENT - - return result; -} - - -TQString TQInputContextFactory::displayName( const TQString &key ) -{ - TQString result( "" ); -#ifndef TQT_NO_COMPONENT - // make sure the manager is created - create_manager(); - - TQInterfacePtr iface; - manager->queryInterface( key, &iface ); - - if ( iface ) - result = iface->displayName( key ); -#endif //TQT_NO_COMPONENT - - return result; -} - - -TQString TQInputContextFactory::description( const TQString &key ) -{ - TQString result( "" ); -#ifndef TQT_NO_COMPONENT - // make sure the manager is created - create_manager(); - - TQInterfacePtr iface; - manager->queryInterface( key, &iface ); - - if ( iface ) - result = iface->description( key ); -#endif //TQT_NO_COMPONENT - - return result; -} - -#endif // TQT_NO_IM diff --git a/src/inputmethod/qinputcontextinterface_p.h b/src/inputmethod/qinputcontextinterface_p.h deleted file mode 100644 index d42f81c50..000000000 --- a/src/inputmethod/qinputcontextinterface_p.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** $Id: qinputcontextinterface_p.h,v 1.2 2004/06/20 18:43:11 daisuke Exp $ -** -** ... -** -** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef TQINPUTCONTEXTINTERFACE_P_H -#define TQINPUTCONTEXTINTERFACE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. This header file may -// change from version to version without notice, or even be -// removed. -// -// We mean it. -// -// - -#ifndef QT_H -#include -#endif // QT_H - -#ifndef TQT_NO_IM -#ifndef TQT_NO_COMPONENT - -class TQWidget; -class TQInputContext; - -// old version interface in qt-x11-immodule-bc-qt3.3.2-20040623.diff: -// {6C2B9EDE-B63C-14c9-A729-3C7643739C4C} -// -// new version interface: -// {a5f5c63d-e044-11d8-9718-000d6077a78d} -// {b0bf3e59-e526-11d8-80da-000d6077a78d} -// {9ef05c7f-0272-11d9-846c-000d6077a78d} - -#ifndef IID_QInputContextFactory -//#define IID_QInputContextFactory TQUuid(0x6c2b9ede, 0xb63c, 0x14c9, 0xa7, 0x29, 0x3c, 0x76, 0x43, 0x73, 0x9c, 0x4c) -//#define IID_QInputContextFactory TQUuid(0xa5f5c63d, 0xe044, 0x11d8, 0x97, 0x18, 0x00, 0x0d, 0x60, 0x77, 0xa7, 0x8d) -//#define IID_QInputContextFactory TQUuid(0xb0bf3e59, 0xe526, 0x11d8, 0x80, 0xda, 0x00, 0x0d, 0x60, 0x77, 0xa7, 0x8d) -#define IID_QInputContextFactory TQUuid(0x9ef05c7f, 0x0272, 0x11d9, 0x84, 0x6c, 0x00, 0x0d, 0x60, 0x77, 0xa7, 0x8d) -#endif - -struct TQ_EXPORT TQInputContextFactoryInterface : public TQFeatureListInterface -{ - virtual TQInputContext *create( const TQString &key ) = 0; - virtual TQStringList languages( const TQString &key ) = 0; - virtual TQString displayName( const TQString &key ) = 0; - virtual TQString description( const TQString &key ) = 0; -}; - -#endif //TQT_NO_COMPONENT -#endif //TQT_NO_IM - -#endif //TQINPUTCONTEXTINTERFACE_P_H diff --git a/src/inputmethod/qinputcontextplugin.cpp b/src/inputmethod/qinputcontextplugin.cpp deleted file mode 100644 index 1e2a6701e..000000000 --- a/src/inputmethod/qinputcontextplugin.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** -** $Id: qinputcontextplugin.cpp,v 1.2 2004/06/20 18:43:11 daisuke Exp $ -** -** Implementation of TQInputContextPlugin class -** -** Created : 010920 -** -** Copyright (C) 2001 Trolltech AS. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#include "ntqinputcontextplugin.h" - -#ifndef TQT_NO_IM -#ifndef TQT_NO_COMPONENT - -#include "qinputcontextinterface_p.h" - -/*! - \class TQInputContextPlugin ntqinputcontextplugin.h - \brief The TQInputContextPlugin class provides an abstract base for custom TQInputContext plugins. - \reentrant - \ingroup plugins - - The input context plugin is a simple plugin interface that makes it - easy to create custom input contexts that can be loaded dynamically - into applications. - - Writing a input context plugin is achieved by subclassing this - base class, reimplementing the pure virtual functions keys(), - create(), languages(), displayName() description() and exporting - the class with the \c TQ_EXPORT_PLUGIN macro. See the \link - plugins-howto.html TQt Plugins documentation \endlink for details. - - \sa TQInputContext -*/ - -/*! - \fn TQStringList TQInputContextPlugin::keys() const - - Returns the list of TQInputContext keys this plugin provides. - - These keys are usually the class names of the custom input context - that are implemented in the plugin. - - Return value is the names to identify and specify input methods - for the input method switching mechanism and so on. The names have - to be consistent with TQInputContext::identifierName(). The names - have to consist of ASCII characters only. See also - TQInputContext::identifierName() for further information. - - \sa create(), displayName(), TQInputContext::identifierName() -*/ - -/*! - \fn TQInputContext* TQInputContextPlugin::create( const TQString& key ) - - Creates and returns a TQInputContext instance for the input context key \a key. - The input context key is usually the class name of the required input method. - - \sa keys() -*/ - -/*! - \fn TQStringList languages( const TQString &key ) - - Returns what languages are supported by the TQInputContext instance - specified by \a key. - - The languages are expressed as language code (e.g. "zh_CN", - "zh_TW", "zh_HK", "ja", "ko", ...). An input context that suports - multiple languages can return all supported languages as - TQStringList. The name has to be consistent with - TQInputContextPlugin::language(). - - This information may be used to optimize user interface. - - \sa TQInputContext::language() -*/ - -/*! - \fn TQString displayName( const TQString &key ) - - Returns a user friendly i18n-ized name of the TQInputContext - instance specified by \a key. This string may be appeared in a - menu and so on for users. - - There are two different names with different responsibility in the - input method domain. This function returns one of them. Another - name is called 'identifier name' to identify and specify input - methods for the input method switching mechanism and so on. - - Although tr( identifierName ) can provide user friendly i18n-ized - name without this function, the message catalog have to be managed - by TQt in the case. However, some sophisticated input method - framework manages their own message catalogs to provide this - i18n-ized name string. So we need this function rather than just - call tr() for identifier name. - - \sa keys(), TQInputContext::identifierName() -*/ - -/*! - \fn TQString description( const TQString &key ) - - Returns a i18n-ized brief description of the TQInputContext - instance specified by \a key. This string may be appeared in some - user interfaces. -*/ - - - -class TQInputContextPluginPrivate : public TQInputContextFactoryInterface -{ -public: - TQInputContextPluginPrivate( TQInputContextPlugin *p ) - : plugin( p ) - { - } - - virtual ~TQInputContextPluginPrivate(); - - TQRESULT queryInterface( const TQUuid &iid, TQUnknownInterface **iface ); - TQ_REFCOUNT; - - TQStringList featureList() const; - TQInputContext *create( const TQString &key ); - TQStringList languages( const TQString &key ); - TQString displayName( const TQString &key ); - TQString description( const TQString &key ); - -private: - TQInputContextPlugin *plugin; -}; - -TQRESULT TQInputContextPluginPrivate::queryInterface( const TQUuid &iid, TQUnknownInterface **iface ) -{ - *iface = 0; - - if ( iid == IID_QUnknown ) - *iface = this; - else if ( iid == IID_QFeatureList ) - *iface = this; - else if ( iid == IID_QInputContextFactory ) - *iface = this; - else - return TQE_NOINTERFACE; - - (*iface)->addRef(); - return TQS_OK; -} - -TQInputContextPluginPrivate::~TQInputContextPluginPrivate() -{ - delete plugin; -} - -TQStringList TQInputContextPluginPrivate::featureList() const -{ - return plugin->keys(); -} - -TQInputContext *TQInputContextPluginPrivate::create( const TQString &key ) -{ - return plugin->create( key ); -} - -TQStringList TQInputContextPluginPrivate::languages( const TQString &key ) -{ - return plugin->languages( key ); -} - -TQString TQInputContextPluginPrivate::displayName( const TQString &key ) -{ - return plugin->displayName( key ); -} - -TQString TQInputContextPluginPrivate::description( const TQString &key ) -{ - return plugin->description( key ); -} - - -/*! - Constructs a input context plugin. This is invoked automatically by the - \c TQ_EXPORT_PLUGIN macro. -*/ -TQInputContextPlugin::TQInputContextPlugin() - : TQGPlugin( d = new TQInputContextPluginPrivate( this ) ) -{ -} - -/*! - Destroys the input context plugin. - - You never have to call this explicitly. TQt destroys a plugin - automatically when it is no longer used. -*/ -TQInputContextPlugin::~TQInputContextPlugin() -{ - // don't delete d, as this is deleted by d -} - -#endif // TQT_NO_COMPONENT -#endif // TQT_NO_IM diff --git a/src/inputmethod/qt_inputmethod.pri b/src/inputmethod/qt_inputmethod.pri index b4f719350..59ccd37c5 100644 --- a/src/inputmethod/qt_inputmethod.pri +++ b/src/inputmethod/qt_inputmethod.pri @@ -2,9 +2,9 @@ inputmethod { INPUTMETHOD_P = inputmethod - HEADERS +=$$INPUTMETHOD_H/ntqinputcontextfactory.h \ - $$INPUTMETHOD_P/qinputcontextinterface_p.h \ - $$INPUTMETHOD_H/ntqinputcontextplugin.h - SOURCES +=$$INPUTMETHOD_CPP/qinputcontextfactory.cpp \ - $$INPUTMETHOD_CPP/qinputcontextplugin.cpp + HEADERS +=$$INPUTMETHOD_H/tqinputcontextfactory.h \ + $$INPUTMETHOD_P/tqinputcontextinterface_p.h \ + $$INPUTMETHOD_H/tqinputcontextplugin.h + SOURCES +=$$INPUTMETHOD_CPP/tqinputcontextfactory.cpp \ + $$INPUTMETHOD_CPP/tqinputcontextplugin.cpp } diff --git a/src/inputmethod/tqinputcontextfactory.cpp b/src/inputmethod/tqinputcontextfactory.cpp new file mode 100644 index 000000000..95fc40766 --- /dev/null +++ b/src/inputmethod/tqinputcontextfactory.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** $Id: tqinputcontextfactory.cpp,v 1.2 2004/06/20 18:43:11 daisuke Exp $ +** +** Implementation of TQInputContextFactory class +** +** Created : 001103 +** +** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "tqinputcontextinterface_p.h" // up here for GCC 2.7.* compatibility +#include "tqinputcontextfactory.h" +#include "tqinputcontext.h" + +#ifndef TQT_NO_IM + +#include "ntqapplication.h" + +#ifdef TQT_THREAD_SUPPORT +#include +#endif // TQT_THREAD_SUPPORT + +#include + +#include "tqcleanuphandler.h" +#include +#ifndef TQT_NO_COMPONENT + + +static TQPluginManager *manager = 0; +static TQSingleCleanupHandler< TQPluginManager > cleanup_manager; + +static void create_manager() +{ + if( manager ) // already created + return; + +#ifdef TQT_THREAD_SUPPORT + // protect manager creation + TQMutexLocker locker( tqt_global_mutexpool ? + tqt_global_mutexpool->get( &manager ) : 0); + + // we check the manager pointer again to make sure that another thread + // has not created the manager before us. + + if ( manager ) // already created + return; +#endif + + manager = new TQPluginManager( IID_QInputContextFactory, TQApplication::libraryPaths(), "/inputmethods", FALSE ); + + TQ_CHECK_PTR( manager ); + cleanup_manager.set( &manager ); +} + +#endif //TQT_NO_COMPONENT + + +/*! + This function generates the input context that has the identifier + name which is in agreement with \a key. \a widget is the client + widget of TQInputContext. \a widget may be null. +*/ +TQInputContext *TQInputContextFactory::create( const TQString& key, TQWidget *widget ) +{ + TQInputContext *ret = 0; + TQString inputcontext = key; +#ifndef TQT_NO_COMPONENT + // make sure the manager is created + create_manager(); + + TQInterfacePtr iface; + manager->queryInterface( inputcontext, &iface ); + + if ( iface ) { + ret = iface->create( inputcontext ); +#ifdef TQ_WS_X11 + if ( ret ) + ret->setHolderWidget( widget ); +#endif + } +#endif + return ret; +} + + +/*! + This function returns the list of the names input methods. + Only input methods included in default and placed under + $TQTDIR/plugins/inputmethods are listed. +*/ +TQStringList TQInputContextFactory::keys() +{ + TQStringList list; +#ifndef TQT_NO_COMPONENT + // make sure the manager is created + create_manager(); + + list = manager->featureList(); +#endif //TQT_NO_COMPONENT + + return list; +} + + +TQStringList TQInputContextFactory::languages( const TQString &key ) +{ + TQStringList result; +#ifndef TQT_NO_COMPONENT + // make sure the manager is created + create_manager(); + + TQInterfacePtr iface; + manager->queryInterface( key, &iface ); + + if ( iface ) + result = iface->languages( key ); +#endif //TQT_NO_COMPONENT + + return result; +} + + +TQString TQInputContextFactory::displayName( const TQString &key ) +{ + TQString result( "" ); +#ifndef TQT_NO_COMPONENT + // make sure the manager is created + create_manager(); + + TQInterfacePtr iface; + manager->queryInterface( key, &iface ); + + if ( iface ) + result = iface->displayName( key ); +#endif //TQT_NO_COMPONENT + + return result; +} + + +TQString TQInputContextFactory::description( const TQString &key ) +{ + TQString result( "" ); +#ifndef TQT_NO_COMPONENT + // make sure the manager is created + create_manager(); + + TQInterfacePtr iface; + manager->queryInterface( key, &iface ); + + if ( iface ) + result = iface->description( key ); +#endif //TQT_NO_COMPONENT + + return result; +} + +#endif // TQT_NO_IM diff --git a/src/inputmethod/tqinputcontextfactory.h b/src/inputmethod/tqinputcontextfactory.h new file mode 100644 index 000000000..84c3cae85 --- /dev/null +++ b/src/inputmethod/tqinputcontextfactory.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** $Id: tqinputcontextfactory.h,v 1.1.1.1 2004/05/11 11:16:49 daisuke Exp $ +** +** Definition of TQInputContextFactory class +** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef TQINPUTCONTEXTFACTORY_H +#define TQINPUTCONTEXTFACTORY_H + +#ifndef QT_H +#include "tqstringlist.h" +#endif // QT_H + +#ifndef TQT_NO_IM + +class TQInputContext; +class TQWidget; + +class TQ_EXPORT TQInputContextFactory +{ +public: + static TQStringList keys(); + static TQInputContext *create( const TQString &key, TQWidget *widget ); // should be a toplevel widget + static TQStringList languages( const TQString &key ); + static TQString displayName( const TQString &key ); + static TQString description( const TQString &key ); +}; +#endif //TQT_NO_IM + +#endif //TQINPUTCONTEXTFACTORY_H diff --git a/src/inputmethod/tqinputcontextinterface_p.h b/src/inputmethod/tqinputcontextinterface_p.h new file mode 100644 index 000000000..195be7fe9 --- /dev/null +++ b/src/inputmethod/tqinputcontextinterface_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** $Id: tqinputcontextinterface_p.h,v 1.2 2004/06/20 18:43:11 daisuke Exp $ +** +** ... +** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef TQINPUTCONTEXTINTERFACE_P_H +#define TQINPUTCONTEXTINTERFACE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. This header file may +// change from version to version without notice, or even be +// removed. +// +// We mean it. +// +// + +#ifndef QT_H +#include +#endif // QT_H + +#ifndef TQT_NO_IM +#ifndef TQT_NO_COMPONENT + +class TQWidget; +class TQInputContext; + +// old version interface in qt-x11-immodule-bc-qt3.3.2-20040623.diff: +// {6C2B9EDE-B63C-14c9-A729-3C7643739C4C} +// +// new version interface: +// {a5f5c63d-e044-11d8-9718-000d6077a78d} +// {b0bf3e59-e526-11d8-80da-000d6077a78d} +// {9ef05c7f-0272-11d9-846c-000d6077a78d} + +#ifndef IID_QInputContextFactory +//#define IID_QInputContextFactory TQUuid(0x6c2b9ede, 0xb63c, 0x14c9, 0xa7, 0x29, 0x3c, 0x76, 0x43, 0x73, 0x9c, 0x4c) +//#define IID_QInputContextFactory TQUuid(0xa5f5c63d, 0xe044, 0x11d8, 0x97, 0x18, 0x00, 0x0d, 0x60, 0x77, 0xa7, 0x8d) +//#define IID_QInputContextFactory TQUuid(0xb0bf3e59, 0xe526, 0x11d8, 0x80, 0xda, 0x00, 0x0d, 0x60, 0x77, 0xa7, 0x8d) +#define IID_QInputContextFactory TQUuid(0x9ef05c7f, 0x0272, 0x11d9, 0x84, 0x6c, 0x00, 0x0d, 0x60, 0x77, 0xa7, 0x8d) +#endif + +struct TQ_EXPORT TQInputContextFactoryInterface : public TQFeatureListInterface +{ + virtual TQInputContext *create( const TQString &key ) = 0; + virtual TQStringList languages( const TQString &key ) = 0; + virtual TQString displayName( const TQString &key ) = 0; + virtual TQString description( const TQString &key ) = 0; +}; + +#endif //TQT_NO_COMPONENT +#endif //TQT_NO_IM + +#endif //TQINPUTCONTEXTINTERFACE_P_H diff --git a/src/inputmethod/tqinputcontextplugin.cpp b/src/inputmethod/tqinputcontextplugin.cpp new file mode 100644 index 000000000..7acdc9300 --- /dev/null +++ b/src/inputmethod/tqinputcontextplugin.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** $Id: tqinputcontextplugin.cpp,v 1.2 2004/06/20 18:43:11 daisuke Exp $ +** +** Implementation of TQInputContextPlugin class +** +** Created : 010920 +** +** Copyright (C) 2001 Trolltech AS. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "tqinputcontextplugin.h" + +#ifndef TQT_NO_IM +#ifndef TQT_NO_COMPONENT + +#include "tqinputcontextinterface_p.h" + +/*! + \class TQInputContextPlugin tqinputcontextplugin.h + \brief The TQInputContextPlugin class provides an abstract base for custom TQInputContext plugins. + \reentrant + \ingroup plugins + + The input context plugin is a simple plugin interface that makes it + easy to create custom input contexts that can be loaded dynamically + into applications. + + Writing a input context plugin is achieved by subclassing this + base class, reimplementing the pure virtual functions keys(), + create(), languages(), displayName() description() and exporting + the class with the \c TQ_EXPORT_PLUGIN macro. See the \link + plugins-howto.html TQt Plugins documentation \endlink for details. + + \sa TQInputContext +*/ + +/*! + \fn TQStringList TQInputContextPlugin::keys() const + + Returns the list of TQInputContext keys this plugin provides. + + These keys are usually the class names of the custom input context + that are implemented in the plugin. + + Return value is the names to identify and specify input methods + for the input method switching mechanism and so on. The names have + to be consistent with TQInputContext::identifierName(). The names + have to consist of ASCII characters only. See also + TQInputContext::identifierName() for further information. + + \sa create(), displayName(), TQInputContext::identifierName() +*/ + +/*! + \fn TQInputContext* TQInputContextPlugin::create( const TQString& key ) + + Creates and returns a TQInputContext instance for the input context key \a key. + The input context key is usually the class name of the required input method. + + \sa keys() +*/ + +/*! + \fn TQStringList languages( const TQString &key ) + + Returns what languages are supported by the TQInputContext instance + specified by \a key. + + The languages are expressed as language code (e.g. "zh_CN", + "zh_TW", "zh_HK", "ja", "ko", ...). An input context that suports + multiple languages can return all supported languages as + TQStringList. The name has to be consistent with + TQInputContextPlugin::language(). + + This information may be used to optimize user interface. + + \sa TQInputContext::language() +*/ + +/*! + \fn TQString displayName( const TQString &key ) + + Returns a user friendly i18n-ized name of the TQInputContext + instance specified by \a key. This string may be appeared in a + menu and so on for users. + + There are two different names with different responsibility in the + input method domain. This function returns one of them. Another + name is called 'identifier name' to identify and specify input + methods for the input method switching mechanism and so on. + + Although tr( identifierName ) can provide user friendly i18n-ized + name without this function, the message catalog have to be managed + by TQt in the case. However, some sophisticated input method + framework manages their own message catalogs to provide this + i18n-ized name string. So we need this function rather than just + call tr() for identifier name. + + \sa keys(), TQInputContext::identifierName() +*/ + +/*! + \fn TQString description( const TQString &key ) + + Returns a i18n-ized brief description of the TQInputContext + instance specified by \a key. This string may be appeared in some + user interfaces. +*/ + + + +class TQInputContextPluginPrivate : public TQInputContextFactoryInterface +{ +public: + TQInputContextPluginPrivate( TQInputContextPlugin *p ) + : plugin( p ) + { + } + + virtual ~TQInputContextPluginPrivate(); + + TQRESULT queryInterface( const TQUuid &iid, TQUnknownInterface **iface ); + TQ_REFCOUNT; + + TQStringList featureList() const; + TQInputContext *create( const TQString &key ); + TQStringList languages( const TQString &key ); + TQString displayName( const TQString &key ); + TQString description( const TQString &key ); + +private: + TQInputContextPlugin *plugin; +}; + +TQRESULT TQInputContextPluginPrivate::queryInterface( const TQUuid &iid, TQUnknownInterface **iface ) +{ + *iface = 0; + + if ( iid == IID_QUnknown ) + *iface = this; + else if ( iid == IID_QFeatureList ) + *iface = this; + else if ( iid == IID_QInputContextFactory ) + *iface = this; + else + return TQE_NOINTERFACE; + + (*iface)->addRef(); + return TQS_OK; +} + +TQInputContextPluginPrivate::~TQInputContextPluginPrivate() +{ + delete plugin; +} + +TQStringList TQInputContextPluginPrivate::featureList() const +{ + return plugin->keys(); +} + +TQInputContext *TQInputContextPluginPrivate::create( const TQString &key ) +{ + return plugin->create( key ); +} + +TQStringList TQInputContextPluginPrivate::languages( const TQString &key ) +{ + return plugin->languages( key ); +} + +TQString TQInputContextPluginPrivate::displayName( const TQString &key ) +{ + return plugin->displayName( key ); +} + +TQString TQInputContextPluginPrivate::description( const TQString &key ) +{ + return plugin->description( key ); +} + + +/*! + Constructs a input context plugin. This is invoked automatically by the + \c TQ_EXPORT_PLUGIN macro. +*/ +TQInputContextPlugin::TQInputContextPlugin() + : TQGPlugin( d = new TQInputContextPluginPrivate( this ) ) +{ +} + +/*! + Destroys the input context plugin. + + You never have to call this explicitly. TQt destroys a plugin + automatically when it is no longer used. +*/ +TQInputContextPlugin::~TQInputContextPlugin() +{ + // don't delete d, as this is deleted by d +} + +#endif // TQT_NO_COMPONENT +#endif // TQT_NO_IM diff --git a/src/inputmethod/tqinputcontextplugin.h b/src/inputmethod/tqinputcontextplugin.h new file mode 100644 index 000000000..bacea5968 --- /dev/null +++ b/src/inputmethod/tqinputcontextplugin.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** $Id: tqinputcontextplugin.h,v 1.2 2004/06/20 18:43:11 daisuke Exp $ +** +** Definition of TQInputContextPlugin class +** +** Created : 010920 +** +** Copyright (C) 2001 Trolltech AS. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef TQINPUTCONTEXTPLUGIN_H +#define TQINPUTCONTEXTPLUGIN_H + +#ifndef QT_H +#include "tqgplugin.h" +#include "tqstringlist.h" +#endif // QT_H + +#ifndef TQT_NO_IM +class TQInputContext; +class TQInputContextPluginPrivate; + +class TQ_EXPORT TQInputContextPlugin : public TQGPlugin +{ + TQ_OBJECT +public: + TQInputContextPlugin(); + ~TQInputContextPlugin(); + + virtual TQStringList keys() const = 0; + virtual TQInputContext *create( const TQString &key ) = 0; + virtual TQStringList languages( const TQString &key ) = 0; + virtual TQString displayName( const TQString &key ) = 0; + virtual TQString description( const TQString &key ) = 0; + +private: + TQInputContextPluginPrivate *d; +}; +#endif // TQT_NO_IM +#endif // TQINPUTCONTEXTPLUGIN_H diff --git a/src/kernel/ntqinputcontext.h b/src/kernel/ntqinputcontext.h deleted file mode 100644 index 426aa796a..000000000 --- a/src/kernel/ntqinputcontext.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** $Id: ntqinputcontext.h,v 1.8 2004/06/22 06:47:30 daisuke Exp $ -** -** Definition of TQInputContext -** -** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef TQINPUTCONTEXT_H -#define TQINPUTCONTEXT_H - -#ifndef TQT_NO_IM - -#ifndef QT_H -#include "tqobject.h" -#include "tqglobal.h" -#include "tqevent.h" -#include "tqstring.h" -#include "tqptrlist.h" -#endif - -class TQWidget; -class TQFont; -class TQPopupMenu; -class TQInputContextPrivate; - - -struct TQInputContextMenu { - enum Action { - NoSeparator, - InsertSeparator - }; - TQString title; - TQPopupMenu *popup; -}; - - -class TQ_EXPORT TQInputContext : public TQObject -{ - TQ_OBJECT -public: - TQInputContext( TQObject *parent = 0 ); - virtual ~TQInputContext(); - - virtual TQString identifierName(); - virtual TQString language(); - -#if defined(TQ_WS_X11) - virtual bool x11FilterEvent( TQWidget *keywidget, XEvent *event ); -#endif // TQ_WS_X11 - virtual bool filterEvent( const TQEvent *event ); - virtual void reset(); - - virtual void setFocus(); - virtual void unsetFocus(); - virtual void setMicroFocus( int x, int y, int w, int h, TQFont *f = 0 ); - virtual void mouseHandler( int x, TQEvent::Type type, - TQt::ButtonState button, TQt::ButtonState state ); - virtual TQFont font() const; - virtual bool isComposing() const; - virtual bool isPreeditRelocationEnabled(); - - virtual TQPtrList *menus(); - void addMenusTo( TQPopupMenu *popup, TQInputContextMenu::Action action = TQInputContextMenu::InsertSeparator ); - -#if defined(TQ_WS_X11) - // these functions are not recommended for ordinary use - virtual TQWidget *focusWidget() const; - virtual TQWidget *holderWidget() const; - - // these functions must not be used by ordinary input method - virtual void setFocusWidget( TQWidget *w ); - virtual void setHolderWidget( TQWidget *w ); - virtual void releaseComposingWidget( TQWidget *w ); -#endif - -signals: - void deletionRequested(); - void imEventGenerated( TQObject *receiver, TQIMEvent *e ); - -protected: - virtual void sendIMEvent( TQEvent::Type type, - const TQString &text = TQString::null, - int cursorPosition = -1, int selLength = 0 ); - -private: - void sendIMEventInternal( TQEvent::Type type, - const TQString &text = TQString::null, - int cursorPosition = -1, int selLength = 0 ); - - TQInputContextPrivate *d; - - friend class TQWidget; - friend class TQInputContextFactory; - -private: // Disabled copy constructor and operator= - TQInputContext( const TQInputContext & ); - TQInputContext &operator=( const TQInputContext & ); - -}; - -#endif //Q_NO_IM - -#endif // TQINPUTCONTEXT_H diff --git a/src/kernel/ntqjpegio.h b/src/kernel/ntqjpegio.h deleted file mode 100644 index 10ae8d7cf..000000000 --- a/src/kernel/ntqjpegio.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Definition of JPEG TQImage IOHandler -** -** Created : 970621 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQJPEGIO_H -#define TQJPEGIO_H - -#include "tqglobal.h" - -#ifndef TQT_NO_IMAGEIO_JPEG - -void qInitJpegIO(); - -#endif // TQT_NO_IMAGEIO_JPEG - -#endif // TQJPEGIO_H diff --git a/src/kernel/ntqkeycode.h b/src/kernel/ntqkeycode.h deleted file mode 100644 index bca9305ba..000000000 --- a/src/kernel/ntqkeycode.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Definition of keyboard codes -** -** Created : 931030 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQKEYCODE_H -#define TQKEYCODE_H - -#ifndef QT_H -#include "ntqnamespace.h" -#endif // QT_H - -// all key codes are now in the TQt namespace class - -#endif // TQKEYCODE_H diff --git a/src/kernel/ntqkeysequence.h b/src/kernel/ntqkeysequence.h deleted file mode 100644 index e4800839d..000000000 --- a/src/kernel/ntqkeysequence.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Definition of TQKeySequence class -** -** Created : 0108007 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQKEYSEQUENCE_H -#define TQKEYSEQUENCE_H - -#ifndef QT_H -#ifndef QT_H -#include "ntqnamespace.h" -#include "tqstring.h" -#endif // QT_H -#endif - -#ifndef TQT_NO_ACCEL - -/***************************************************************************** - TQKeySequence stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM -class TQKeySequence; -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQKeySequence & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQKeySequence & ); -#endif - -class TQKeySequencePrivate; - -class TQ_EXPORT TQKeySequence : public TQt -{ -public: - TQKeySequence(); - TQKeySequence( const TQString& key ); - TQKeySequence( int key ); - TQKeySequence( int k1, int k2, int k3 = 0, int k4 = 0 ); - TQKeySequence( const TQKeySequence & ); - ~TQKeySequence(); - - uint count() const; - bool isEmpty() const; - TQt::SequenceMatch matches( const TQKeySequence & ) const; - - operator TQString() const; - operator int () const; - int operator[]( uint ) const; - TQKeySequence &operator=( const TQKeySequence & ); - bool operator==( const TQKeySequence& ) const; - bool operator!= ( const TQKeySequence& ) const; - -private: - static int decodeString( const TQString & ); - static TQString encodeString( int ); - int assign( TQString ); - void setKey( int key, int index ); - - TQKeySequencePrivate* d; - - friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQKeySequence & ); - friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQKeySequence & ); - friend class TQAccelManager; -}; - -#else - -class TQ_EXPORT TQKeySequence : public TQt -{ -public: - TQKeySequence() {} - TQKeySequence( int ) {} -}; - -#endif //TQT_NO_ACCEL - -#endif diff --git a/src/kernel/ntqnamespace.h b/src/kernel/ntqnamespace.h index c6bdd1b0d..f5ec7dd1d 100644 --- a/src/kernel/ntqnamespace.h +++ b/src/kernel/ntqnamespace.h @@ -335,7 +335,7 @@ public: }; #endif - // documented in qkeysequence.cpp + // documented in tqkeysequence.cpp enum SequenceMatch { NoMatch, PartialMatch, diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index e04574828..0a1ffc22b 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -28,7 +28,7 @@ #include "tqstring.h" #include "tqptrlist.h" #include "tqiodevice.h" -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #include "ntqwindowdefs.h" #include "tqgdict.h" #include "tqfont.h" @@ -114,13 +114,13 @@ #include "tqpicture.h" #include #include -#include +#include #include #include "tqlabel.h" #include "tqlayout.h" #include -#include -#include +#include +#include #include "tqscrollbar.h" #include "tqscrollview.h" #include "tqdir.h" @@ -302,7 +302,7 @@ #include "private/tqdialogbuttons_p.h" #include "private/tqwidgetinterface_p.h" #include "private/tqwidgetresizehandler_p.h" -#include "private/qlibrary_p.h" +#include "private/tqlibrary_p.h" #endif // Private headers diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index a4fded7f0..8f04514cf 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -61,7 +61,7 @@ #include "tqdir.h" #include "tqfileinfo.h" #ifdef TQ_WS_WIN -#include "qinputcontext_p.h" +#include "tqinputcontext_p.h" #endif #include "tqfontdata_p.h" diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index b611778d7..c1d8345b1 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -90,7 +90,7 @@ // Input method stuff - UNFINISHED #ifndef TQT_NO_IM -#include "ntqinputcontext.h" +#include "tqinputcontext.h" #endif // TQT_NO_IM #include "qinternal_p.h" // shared double buffer cleanup diff --git a/src/kernel/qinputcontext.cpp b/src/kernel/qinputcontext.cpp deleted file mode 100644 index 8693da969..000000000 --- a/src/kernel/qinputcontext.cpp +++ /dev/null @@ -1,849 +0,0 @@ -/**************************************************************************** -** $Id: qinputcontext.cpp,v 1.6 2004/06/22 06:47:30 daisuke Exp $ -** -** Implementation of TQInputContext class -** -** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** licenses for Unix/X11 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -//#define TQT_NO_IM_PREEDIT_RELOCATION - -#include "ntqinputcontext.h" - -#ifndef TQT_NO_IM - -#include "qplatformdefs.h" - -#include "ntqapplication.h" -#include "tqwidget.h" -#include "tqpopupmenu.h" - -#include -#include - -class TQInputContextPrivate -{ -public: - TQInputContextPrivate() - : holderWidget( 0 ), composingWidget( 0 ), hasFocus( FALSE ), - isComposing( FALSE ) -#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) - , preeditString( TQString::null ), - cursorPosition( -1 ), selLength ( 0 ) -#endif - {} - - TQWidget *holderWidget; // widget to which TQInputContext instance belongs. - TQWidget *composingWidget; - bool hasFocus; - bool isComposing; - - void updateComposingState( const TQString &text, - int newCursorPosition, int newSelLength ) { -#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) - preeditString = text; - cursorPosition = newCursorPosition; - selLength = newSelLength; -#endif - } - - void resetComposingState() { - isComposing = FALSE; -#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) - preeditString = TQString::null; - cursorPosition = -1; - selLength = 0; -#endif - } - -#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) - TQString preeditString; - int cursorPosition; - int selLength; -#endif -}; - - -// UPDATED COMMENT REQUIRED -- 2004-07-08 YamaKen -/*! - \class TQInputContext ntqinputcontext.h - \brief The TQInputContext class abstracts the input method dependent data and composing state. - - \ingroup i18n - - An input method is responsible to input complex text that cannot - be inputted via simple keymap. It converts a sequence of input - events (typically key events) into a text string through the input - method specific converting process. The class of the processes are - widely ranging from simple finite state machine to complex text - translator that pools a whole paragraph of a text with text - editing capability to perform grammar and semantic analysis. - - To abstract such different input method specific intermediate - information, TQt offers the TQInputContext as base class. The - concept is well known as 'input context' in the input method - domain. an input context is created for a text widget in response - to a demand. It is ensured that an input context is prepared for - an input method before input to a text widget. - - Multiple input contexts that is belonging to a single input method - may concurrently coexist. Suppose multi-window text editor. Each - text widget of window A and B holds different TQInputContext - instance which contains different state information such as - partially composed text. - - \section1 Groups of functions: - - \table - \header \i Context \i Functions - - \row \i Receiving information \i - x11FilterEvent(), - filterEvent(), - setMicroFocus(), - mouseHandler() - - \row \i Sending back composed text \i - sendIMEvent(), - - \row \i State change notification \i - setFocus(), - unsetFocus(), - reset() - - \row \i Context information \i - identifierName(), - language(), - font(), - isComposing(), - - \endtable - - - \section1 Sharing input context between text widgets - - Any input context can be shared between several text widgets to - reduce resource consumption. In ideal case, each text widgets - should be allocated dedicated input context. But some complex - input contexts require slightly heavy resource such as 100 - kilobytes of memory. It prevents quite many text widgets from - being used concurrently. - - To resolve such problem, we can share an input context. There is - one 'input context holder widget' per text widgets that shares - identical input context. In this model, the holder widget owns the - shared input context. Other text widgets access the input context - via TQApplication::locateICHolderWidget(). But the access - convention is transparently hidden into TQWidget, so developers are - not required to aware of it. - - What developer should know is only the mapping function - TQApplication::locateICHolderWidget(). It accepts a widget as - argument and returns its holder widget. Default implementation - returns the top-level widget of the widget as reasonable - assumption. But some applications should reimplement the function - to fit application specific usability. See - TQApplication::locateICHolderWidget() for further information. - - - \section1 Preedit preservation - - As described above, input contexts have wide variety of amount of - the state information in accordance with belonging input - method. It is ranging from 2-3 keystrokes of sequence in - deterministic input methods to hundreds of keystrokes with - semantic text refinement in complex input methods such as ordinary - Japanese input method. The difference requires the different reset - policies in losing input focus. - - The former simple input method case, users will prefer resetting - the context to back to the neutral state when something - happened. Suppose a web browsing. The user scroll the page by - scrollbar after he or she has typed a half of the valid key - sequence into a text widget. In the case, the input context should - be reset in losing focus when he or she has dragged the - scrollbar. He or she will be confused if the input context is - still preserved until focused back to the text widget because he - or she will restart typing with first key of the sequence as a - habitual operation. - - On the other hand, we should choose completely different policy - for the latter complex input method case. Suppose same situation - as above but he or she is using a complex input method. In the - case, he or she will be angry if the input context has been lost - when he or she has dragged the scrollbar because the input context - contained a valuably composed text made up by considerable input - cost. So we should not reset the input context in the case. And - the input context should be preserved until focused back to the - text widget. This behavior is named as 'preedit preservation'. - - The two policies can be switched by calling or not calling reset() - in unsetFocus(). Default implementation of unsetFocus() calls - reset() to fit the simple input methods. The implementation is - expressed as 'preedit preservation is disabled'. - - - \section1 Preedit relocation - - Although the most case of the preedit preservation problem for - complex input methods is resolved as described above, there is a - special case. Suppose the case that matches all of the following - conditions. - - \list - - \i a input focus has been moved from a text widget to another text - widget directly - - \i the input context is shared between the two text widgets - - \i preedit preservation is enabled for the input context - - \endlist - - In the case, there are the following two requirements that - contradicts each other. The input context sharing causes it. - - \list - - \i the input context has to be reset to prepare to input to the - newly focused text widget - - \i the input context has to be preserved until focused back to the - previous text widget - - \endlist - - A intrinsic feature named 'preedit relocation' is available to - compromise the requirements. If the feature is enabled for the - input context, it is simply moved to the new text widget with the - preedit string. The user continues the input on the new text - widget, or relocate it to another text widget. The preedit of - previous text widget is automatically cleared to back to the - neutral state of the widget. - - This strange behavior is just a compromise. As described in - previous section, complex input method user should not be exposed - to the risk losing the input context because it contains valuable - long text made up with considerable input cost. The user will - immediately focus back to the previous text widget to continue the - input in the correct text widget if the preedit relocation - occurred. The feature is mainly existing as safety. - - The feature properly works even if the focus is moved as - following. Input method developers are not required to be aware of - the relocation protocol since TQInputContext transparently handles - it. - - a text widget -> a non-text widget -> another text widget - - To enable the preedit relocation feature, the input context class - have to reimplement isPreeditRelocationEnabled() as returns TRUE. - The implementation requires that the preedit preservation is also - enabled since preedit relocation is a special case of the preedit - preservation. If the preedit relocation is disabled, the input - context is simply reset in the relocation case. - - - \section1 Input context instanciation - \section1 Input method switching - - \section1 Text widget implementor's guide - - Add following code fragment into createPopupMenu() to add input - method dependent submenus. - - \code - #ifndef TQT_NO_IM - TQInputContext *qic = getInputContext(); - if ( qic ) - qic->addMenusTo( popup ); - #endif - \endcode - - \sa TQInputContextPlugin, TQInputContextFactory, TQApplication::locateICHolderWidget(), TQApplication::defaultInputMethod() -*/ - - -/*! - Constructs an input context. - - holderWidget is set immediately after this constructor has been - returned on the X11 platform. -*/ -TQInputContext::TQInputContext( TQObject *parent ) - : TQObject( parent ) -{ - d = new TQInputContextPrivate; -} - - -/*! - Destroys the input context. -*/ -TQInputContext::~TQInputContext() -{ - delete d; -} - -#if defined(TQ_WS_X11) -/*! - \internal - Returns the owner of this input context. Ordinary input methods - should not call this function directly to keep platform - independence and flexible configuration possibility. - - The return value may differ from focusWidget() if the input - context is shared between several text widgets. - - \sa setHolderWidget(), focusWidget() -*/ -TQWidget *TQInputContext::holderWidget() const -{ - return d->holderWidget; -} - -/*! - \internal - Sets the owner of this input context. Ordinary input methods - must not call this function directly. - - \sa holderWidget() -*/ -void TQInputContext::setHolderWidget( TQWidget *w ) -{ - d->holderWidget = w; -} - -/*! - \internal - Returns the widget that has an input focus for this input - context. Ordinary input methods should not call this function - directly to keep platform independence and flexible configuration - possibility. - - The return value may differ from holderWidget() if the input - context is shared between several text widgets. - - \sa setFocusWidget(), holderWidget() -*/ -TQWidget *TQInputContext::focusWidget() const -{ - return d->hasFocus ? d->composingWidget : 0; -} - - -/*! - \internal - Sets the widget that has an input focus for this input - context. Ordinary input methods must not call this function - directly. - - \sa focusWidget() -*/ -void TQInputContext::setFocusWidget( TQWidget *w ) -{ - if ( w ) { - bool isFocusingBack = ( w == d->composingWidget ); - bool isPreeditRelocation = ( ! isFocusingBack && isComposing() && - d->composingWidget ); - // invoke sendIMEventInternal() rather than sendIMEvent() to - // avoid altering the composing state - if ( isPreeditRelocation == TRUE ) { - // clear preedit of previously focused text - // widget. preserved preedit may be exist even if - // isPreeditRelocationEnabled() == FALSE. - sendIMEventInternal( TQEvent::IMEnd ); - } - d->composingWidget = w; // changes recipient of TQIMEvent - if ( isPreeditRelocation == TRUE ) { -#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) - if ( isPreeditRelocationEnabled() ) { - // copy preedit state to the widget that gaining focus - sendIMEventInternal( TQEvent::IMStart ); - sendIMEventInternal( TQEvent::IMCompose, d->preeditString, - d->cursorPosition, d->selLength ); - } else -#endif - { - // reset input context when the shared context has - // focused on another text widget - reset(); - } - } - } - d->hasFocus = w ? TRUE : FALSE; -} - - -/*! - \internal - This function is called from TQWidget to keep input state - consistency. Ordinary input method must not call this function - directly. -*/ -void TQInputContext::releaseComposingWidget( TQWidget *w ) -{ - if ( d->composingWidget == w ) { - d->composingWidget = 0; - d->hasFocus = FALSE; - } -} -#endif // TQ_WS_X11 - -/*! - \internal - This function can be reimplemented in a subclass as returning TRUE - if you want making your input method enable the preedit - relocation. See the description for preedit relocation of - TQInputContext. - - /sa TQInputContext -*/ -bool TQInputContext::isPreeditRelocationEnabled() -{ - return FALSE; -} - -/*! - This function indicates whether IMStart event had been sent to the - text widget. It is ensured that an input context can send IMCompose - or IMEnd event safely if this function returned TRUE. - - The state is automatically being tracked through sendIMEvent(). - - \sa sendIMEvent() -*/ -bool TQInputContext::isComposing() const -{ - return d->isComposing; -} - - -/*! - This function can be reimplemented in a subclass to filter input - events. - - Return TRUE if the \a event has been consumed. Otherwise, the - unfiltered \a event will be forwarded to widgets as ordinary - way. Although the input events have accept() and ignore() - methods, leave it untouched. - - \a event is currently restricted to TQKeyEvent. But some input - method related events such as TQWheelEvent or TQTabletEvent may be - added in future. - - The filtering opportunity is always given to the input context as - soon as possible. It has to be taken place before any other key - event consumers such as eventfilters and accelerators because some - input methods require quite various key combination and - sequences. It often conflicts with accelerators and so on, so we - must give the input context the filtering opportunity first to - ensure all input methods work properly regardless of application - design. - - Ordinary input methods require discrete key events to work - properly, so TQt's key compression is always disabled for any input - contexts. - - \sa TQKeyEvent, x11FilterEvent() -*/ -bool TQInputContext::filterEvent( const TQEvent *event ) -{ - Q_UNUSED(event); - return FALSE; -} - - -/*! - \fn void TQInputContext::deletionRequested() - - Emit this signal when a fatal error has been caused in the input - context. The input context will be deleted by the owner which is - usually the holder widget. -*/ - -/*! - \fn void TQInputContext::imEventGenerated( TQObject *receiver, TQIMEvent *e ) - - \internal - This signal is emitted when the user has sent a TQIMEvent through - sendIMEvent(). Ordinary input methods should not emit this signal - directly. - - \a receiver is a platform dependent destination of the \a e. - - \sa TQIMEvent, sendIMEvent(), sendIMEventInternal(), -*/ - -/*! - \internal - Sends a TQIMEvent to the client via imEventGenerated() - signal. Ordinary input method should not call this function - directly. - - \sa TQIMEvent, TQIMComposeEvent, sendIMEvent(), imEventGenerated() -*/ -void TQInputContext::sendIMEventInternal( TQEvent::Type type, - const TQString &text, - int cursorPosition, int selLength ) -{ - TQObject *receiver = 0; - TQIMEvent *event = 0; - -#if defined(TQ_WS_X11) - receiver = d->composingWidget; -#endif - if ( ! receiver ) - return; - - if ( type == TQEvent::IMStart ) { - tqDebug( "sending IMStart with %d chars to %p", - text.length(), receiver ); - event = new TQIMEvent( type, text, cursorPosition ); - } else if ( type == TQEvent::IMEnd ) { - tqDebug( "sending IMEnd with %d chars to %p, text=%s", - text.length(), receiver, (const char*)text.local8Bit() ); - event = new TQIMEvent( type, text, cursorPosition ); - } else if ( type == TQEvent::IMCompose ) { - tqDebug( "sending IMCompose to %p with %d chars, cpos=%d, sellen=%d, text=%s", - receiver, text.length(), cursorPosition, selLength, - (const char*)text.local8Bit() ); - event = new TQIMComposeEvent( type, text, cursorPosition, selLength ); - } - - if ( event ) - emit imEventGenerated( receiver, event ); -} - - -/*! - Call this function to send TQIMEvent to the text widget. This - function constructs a TQIMEvent based on the arguments and send it - to the appropriate widget. Ordinary input method should not - reimplement this function. - - \a type is either \c TQEvent::IMStart or \c TQEvent::IMCompose or \c - TQEvent::IMEnd. You have to send a \c TQEvent::IMStart to start - composing, then send several \c TQEvent::IMCompose to update the - preedit of the widget, and finalize the composition with sending - \c TQEvent::IMEnd. - - \c TQEvent::IMStart should always be sent without arguments as: - \code - sendIMEvent( TQEvent::IMStart ) - \endcode - - And \c TQEvent::IMCompose can be sent without cursor: - \code - sendIMEvent( TQEvent::IMCompose, TQString( "a text" ) ) - \endcode - - Or optionally with cursor with \a cursorPosition: - \code - sendIMEvent( TQEvent::IMCompose, TQString( "a text with cursor" ), 12 ) - \endcode - Note that \a cursorPosition also specifies microfocus position. - - Or optionally with selection text: - \code - sendIMEvent( TQEvent::IMCompose, TQString( "a text with selection" ), 12, 9 ) - \endcode - \a cursorPosition and \a selLength must be within the \a text. The - \a cursorPosition also specifies microfocus position in the case: - - \c TQEvent::IMEnd can be sent without arguments to terminate the - composition with null string: - \code - sendIMEvent( TQEvent::IMEnd ) - \endcode - - Or optionally accepts \a text to commit a string: - \code - sendIMEvent( TQEvent::IMEnd, TQString( "a text" ) ) - \endcode - - \sa TQIMEvent, TQIMComposeEvent, setMicroFocus() -*/ -void TQInputContext::sendIMEvent( TQEvent::Type type, const TQString &text, - int cursorPosition, int selLength ) -{ -#if defined(TQ_WS_X11) - if ( !focusWidget() ) - return; -#endif - - if ( type == TQEvent::IMStart ) { - sendIMEventInternal( type, text, cursorPosition, selLength ); - d->isComposing = TRUE; - } else if ( type == TQEvent::IMEnd ) { - d->resetComposingState(); - sendIMEventInternal( type, text, cursorPosition, selLength ); - } else if ( type == TQEvent::IMCompose ) { - d->updateComposingState( text, cursorPosition, selLength ); - sendIMEventInternal( type, text, cursorPosition, selLength ); - } -} - - -/*! - This function can be reimplemented in a subclass to detect - that the input context has been focused on. - - The input context will receive input events through - x11FilterEvent() and filterEvent() after setFocus() until - unsetFocus() has been called. - - an input context is ensured that setFocus() is called exactly once - until unsetFocus() has been called even if preedit relocation has - occurred. This means that an input focus will survive between - several widgets that sharing the input context. - - On the X11 platform, focusWidget is already set before this - function has been called. - - \sa unsetFocus() -*/ -void TQInputContext::setFocus() -{ -} - - -/*! - This function can be reimplemented in a subclass to detect - that the input context has lost the focus. - - an input context is ensured that unsetFocus() is not called during - preedit relocation. This means that an input focus will survive - between several widgets that sharing the input context. - - Default implementation that calls reset() is sufficient for simple - input methods. You can override this function to alter the - behavior. For example, most Japanese input contexts should not be - reset on losing focus. The context sometimes contains a whole - paragraph and has minutes of lifetime different to ephemeral one - in other languages. The piled input context should be survived - until focused again since Japanese user naturally expects so. - - On the X11 platform, focusWidget is valid until this function has - been returned. - - \sa setFocus() -*/ -void TQInputContext::unsetFocus() -{ - reset(); -} - - -/*! - This function can be implemented in a subclass to handle - microfocus changes. - - 'microfocus' stands for the input method focus point in the - preedit (XIM "spot" point) for complex language input handling. It - can be used to place auxiliary GUI widgets such as candidate - selection window. - - \a x, \a y, \a w and \a h represents the position and size of the - cursor in the preedit string. \a f is the font on the location of - the cursor. -*/ -void TQInputContext::setMicroFocus( int x, int y, int w, int h, TQFont *f ) -{ - Q_UNUSED(x); - Q_UNUSED(y); - Q_UNUSED(w); - Q_UNUSED(h); - Q_UNUSED(f); -} - - -/*! - This function can be reimplemented in a subclass to handle mouse - presses/releases/doubleclicks/moves within the preedit text. You - can use the function to implement mouse-oriented user interface - such as text selection or popup menu for candidate selection. - - The parameter \a x is the offset within the string that was sent - with the IMCompose event. The alteration boundary of \a x is - ensured as character boundary of preedit string accurately. - - \a type is either \c TQEvent::MouseButtonPress or \c - TQEvent::MouseButtonRelease or \c TQEvent::MouseButtonDblClick or \c - TQEvent::MouseButtonMove. Refer \a button and \a state to determine - what operation has performed. - */ -void TQInputContext::mouseHandler( int x, TQEvent::Type type, - TQt::ButtonState button, - TQt::ButtonState state ) -{ - Q_UNUSED(x); - Q_UNUSED(button); - Q_UNUSED(state); - // Default behavior for simple ephemeral input contexts. Some - // complex input contexts should not be reset here. - if ( type == TQEvent::MouseButtonPress || - type == TQEvent::MouseButtonDblClick ) - reset(); -} - - -/*! - Returns the font of the current input widget - */ -TQFont TQInputContext::font() const -{ - if ( !focusWidget() ) - return TQApplication::font(); //### absolutely last resort - - return focusWidget()->font(); -} - - -/*! - This function can be reimplemented in a subclass to reset the - state of the input method. - - This function is called by several widgets to reset input - state. For example, a text widget call this function before - inserting a text to make widget ready to accept a text. - - Default implementation is sufficient for simple input method. You - can override this function to reset external input method engines - in complex input method. In the case, call TQInputContext::reset() - to ensure proper termination of inputting. - - You must not send any TQIMEvent except empty IMEnd event using - TQInputContext::reset() at reimplemented reset(). It will break - input state consistency. -*/ -void TQInputContext::reset() -{ - if ( isComposing() ) - sendIMEvent( TQEvent::IMEnd ); -} - - -/*! - This function must be implemented in any subclasses to return the - identifier name of the input method. - - Return value is the name to identify and specify input methods for - the input method switching mechanism and so on. The name has to be - consistent with TQInputContextPlugin::keys(). The name has to - consist of ASCII characters only. - - There are two different names with different responsibility in the - input method domain. This function returns one of them. Another - name is called 'display name' that stands for the name for - endusers appeared in a menu and so on. - - \sa TQInputContextPlugin::keys(), TQInputContextPlugin::displayName() -*/ -TQString TQInputContext::identifierName() -{ - return ""; -} - - -/*! - This function must be implemented in any subclasses to return a - language code (e.g. "zh_CN", "zh_TW", "zh_HK", "ja", "ko", ...) - of the input context. If the input context can handle multiple - languages, return the currently used one. The name has to be - consistent with TQInputContextPlugin::language(). - - This information will be used by language tagging feature in - TQIMEvent. It is required to distinguish unified han characters - correctly. It enables proper font and character code - handling. Suppose CJK-awared multilingual web browser - (that automatically modifies fonts in CJK-mixed text) and XML editor - (that automatically inserts lang attr). - - \sa TQInputContextPlugin::language() -*/ -TQString TQInputContext::language() -{ - return ""; -} - - -/*! - This function can be reimplemented in a subclass to provide input - method dependent popup menus. Return 0 if the menus are - unnecessary. - - Ownership of the object and children are transferred to the - caller, and the result must not be called - setAutoDelete(). TQInputContextMenu::title is used for label text - of the popup menu as submenu. - - \sa addMenusTo() -*/ -TQPtrList *TQInputContext::menus() -{ - return 0; -} - -/*! - Appends input method dependent submenus into \a popup. A separator - is also inserted into \a popup if \a action is InsertSeparator. - - This is an utility function only for convenience in limited - situation. This function is used by input context owner such as - text widgets to add the submenus to its own context menu. If you - want to insert the submenus in more flexible way, use - TQInputContext::menus() manually. \a popup is not restricted to - context menu of a text widget. - - \sa menus(), TQInputContextMenu::Action -*/ -void TQInputContext::addMenusTo( TQPopupMenu *popup, TQInputContextMenu::Action action ) -{ - if ( ! popup ) - return; - - TQPtrList *imMenus = menus(); - if ( imMenus ) { - if ( action == TQInputContextMenu::InsertSeparator ) - popup->insertSeparator(); - for ( TQPtrList::Iterator it = imMenus->begin(); - it != imMenus->end(); - ++it ) { - TQInputContextMenu *imMenu = *it; - popup->insertItem( imMenu->title, imMenu->popup ); - } - imMenus->clear(); - delete imMenus; - } -} - -#endif //Q_NO_IM diff --git a/src/kernel/qinputcontext_p.h b/src/kernel/qinputcontext_p.h deleted file mode 100644 index 37ba52b6c..000000000 --- a/src/kernel/qinputcontext_p.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Definition of ??? -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQINPUTCONTEXT_P_H -#define TQINPUTCONTEXT_P_H - - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of internal files. This header file may change from version to version -// without notice, or even be removed. -// -// We mean it. -// -// - -#include "tqglobal.h" - -class TQKeyEvent; -class TQWidget; -class TQFont; -class TQString; - - -#ifdef TQ_WS_X11 -#include "tqmemarray.h" -#include "ntqwindowdefs.h" -#include "qt_x11_p.h" -#endif - -#ifdef TQ_WS_WIN -#include "qt_windows.h" -#endif - -class TQInputContext -{ -public: -#ifdef TQ_WS_X11 - TQInputContext(TQWidget *); // should be a toplevel widget - ~TQInputContext(); - - void setFocus(); - void setComposePosition(int, int); - void setComposeArea(int, int, int, int); - void reset(); - - int lookupString(XKeyEvent *, TQCString &, KeySym *, Status *) const; - void setXFontSet(const TQFont &); - - void *ic; - TQString text; - TQWidget *focusWidget; - bool composing; - TQFont font; - XFontSet fontset; - TQMemArray selectedChars; -#endif // TQ_WS_X11 - -#ifdef TQ_WS_WIN - static void init(); - static void shutdown(); - - static void TranslateMessage( const MSG *msg); - static LRESULT DefWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ); - - static void setFont( const TQWidget *w, const TQFont & ); - static void setFocusHint( int x, int y, int w, int h, const TQWidget *widget ); - static bool startComposition(); - static bool endComposition( TQWidget *fw = 0 ); - static bool composition( LPARAM lparam ); - - static void accept( TQWidget *fw = 0 ); - static void enable( TQWidget *w, bool b ); -#endif -}; - -#endif // TQINPUTCONTEXT_P_H diff --git a/src/kernel/qinputcontext_x11.cpp b/src/kernel/qinputcontext_x11.cpp deleted file mode 100644 index 0a314dfbb..000000000 --- a/src/kernel/qinputcontext_x11.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQInputContext class -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 "ntqinputcontext.h" - -#ifndef TQT_NO_IM - -#include "qplatformdefs.h" - -#include "ntqapplication.h" -#include "tqwidget.h" - -#include "qt_x11_p.h" - -/*! - This function may be overridden only if input method is depending - on X11 and you need raw XEvent. Otherwise, this function must not. - - This function is designed to filter raw key events for XIM, but - other input methods may use this to implement some special - features such as distinguishing Shift_L and Shift_R. - - Return TRUE if the \a event has been consumed. Otherwise, the - unfiltered \a event will be translated into TQEvent and forwarded - to filterEvent(). Filtering at both x11FilterEvent() and - filterEvent() in single input method is allowed. - - \a keywidget is a client widget into which a text is inputted. \a - event is inputted XEvent. - - \sa filterEvent() -*/ -bool TQInputContext::x11FilterEvent( TQWidget *keywidget, XEvent *event ) -{ - Q_UNUSED(keywidget); - Q_UNUSED(event); - return FALSE; -} - -#endif //Q_NO_IM diff --git a/src/kernel/qjpegio.cpp b/src/kernel/qjpegio.cpp deleted file mode 100644 index 56b22fbbf..000000000 --- a/src/kernel/qjpegio.cpp +++ /dev/null @@ -1,595 +0,0 @@ -/**************************************************************************** -** -** Implementation of JPEG TQImage IOHandler -** -** Created : 990521 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 "tqimage.h" - -#ifndef TQT_NO_IMAGEIO_JPEG - -#include "tqiodevice.h" -#include "ntqjpegio.h" - -#include // jpeglib needs this to be pre-included -#include - - -// including jpeglib.h seems to be a little messy -extern "C" { -#define XMD_H // shut JPEGlib up -#if defined(Q_OS_UNIXWARE) -# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this -#endif -#include -#ifdef const -# undef const // remove crazy C hackery in jconfig.h -#endif -} - - -struct my_error_mgr : public jpeg_error_mgr { - jmp_buf setjmp_buffer; -}; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static -void my_error_exit (j_common_ptr cinfo) -{ - my_error_mgr* myerr = (my_error_mgr*) cinfo->err; - char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message)(cinfo, buffer); - tqWarning("%s", buffer); - longjmp(myerr->setjmp_buffer, 1); -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -static const int max_buf = 4096; - -struct my_jpeg_source_mgr : public jpeg_source_mgr { - // Nothing dynamic - cannot rely on destruction over longjump - TQImageIO* iio; - JOCTET buffer[max_buf]; - -public: - my_jpeg_source_mgr(TQImageIO* iio); -}; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static -void tqt_init_source(j_decompress_ptr) -{ -} - -static -boolean qt_fill_input_buffer(j_decompress_ptr cinfo) -{ - int num_read; - my_jpeg_source_mgr* src = (my_jpeg_source_mgr*)cinfo->src; - TQIODevice* dev = src->iio->ioDevice(); - src->next_input_byte = src->buffer; - num_read = dev->readBlock((char*)src->buffer, max_buf); - if ( num_read <= 0 ) { - // Insert a fake EOI marker - as per jpeglib recommendation - src->buffer[0] = (JOCTET) 0xFF; - src->buffer[1] = (JOCTET) JPEG_EOI; - src->bytes_in_buffer = 2; - } else { - src->bytes_in_buffer = num_read; - } -#if defined(Q_OS_UNIXWARE) - return B_TRUE; -#else - return TRUE; -#endif -} - -static -void qt_skip_input_data(j_decompress_ptr cinfo, long num_bytes) -{ - my_jpeg_source_mgr* src = (my_jpeg_source_mgr*)cinfo->src; - - // `dumb' implementation from jpeglib - - /* Just a dumb implementation for now. Could use fseek() except - * it doesn't work on pipes. Not clear that being smart is worth - * any trouble anyway --- large skips are infrequent. - */ - if (num_bytes > 0) { - while (num_bytes > (long) src->bytes_in_buffer) { - num_bytes -= (long) src->bytes_in_buffer; - (void) qt_fill_input_buffer(cinfo); - /* note we assume that qt_fill_input_buffer will never return FALSE, - * so suspension need not be handled. - */ - } - src->next_input_byte += (size_t) num_bytes; - src->bytes_in_buffer -= (size_t) num_bytes; - } -} - -static -void qt_term_source(j_decompress_ptr) -{ -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -inline my_jpeg_source_mgr::my_jpeg_source_mgr(TQImageIO* iioptr) -{ - jpeg_source_mgr::init_source = tqt_init_source; - jpeg_source_mgr::fill_input_buffer = qt_fill_input_buffer; - jpeg_source_mgr::skip_input_data = qt_skip_input_data; - jpeg_source_mgr::resync_to_restart = jpeg_resync_to_restart; - jpeg_source_mgr::term_source = qt_term_source; - iio = iioptr; - bytes_in_buffer = 0; - next_input_byte = buffer; -} - - -static -void scaleSize( int &reqW, int &reqH, int imgW, int imgH, TQImage::ScaleMode mode ) -{ - if ( mode == TQImage::ScaleFree ) - return; - int t1 = imgW * reqH; - int t2 = reqW * imgH; - if (( mode == TQImage::ScaleMin && (t1 > t2) ) || ( mode == TQImage::ScaleMax && (t1 < t2) )) - reqH = t2 / imgW; - else - reqW = t1 / imgH; -} - - -static -void read_jpeg_image(TQImageIO* iio) -{ - TQImage image; - - struct jpeg_decompress_struct cinfo; - - struct my_jpeg_source_mgr *iod_src = new my_jpeg_source_mgr(iio); - struct my_error_mgr jerr; - - cinfo.err = jpeg_std_error(&jerr); - jerr.error_exit = my_error_exit; - - jpeg_create_decompress(&cinfo); - - cinfo.src = iod_src; - - if (!setjmp(jerr.setjmp_buffer)) { -#if defined(Q_OS_UNIXWARE) - (void) jpeg_read_header(&cinfo, B_TRUE); -#else - (void) jpeg_read_header(&cinfo, TRUE); -#endif - - (void) jpeg_start_decompress(&cinfo); - - TQString params = iio->parameters(); - params.simplifyWhiteSpace(); - int sWidth = 0, sHeight = 0; - char sModeStr[1024] = ""; - TQImage::ScaleMode sMode; - - if ( params.contains( "GetHeaderInformation" ) ) { - - // Create TQImage's without allocating the data - if ( cinfo.output_components == 3 || cinfo.output_components == 4) { - image = TQImage( NULL, cinfo.output_width, cinfo.output_height, 32, NULL, 0, TQImage::IgnoreEndian ); - } else if ( cinfo.output_components == 1 ) { - image = TQImage( NULL, cinfo.output_width, cinfo.output_height, 8, NULL, 0, TQImage::IgnoreEndian ); - } else { - // Unsupported format - } - - - } else if ( params.contains( "Scale" ) ) { - sscanf( params.latin1(), "Scale( %i, %i, %1023s )", - &sWidth, &sHeight, sModeStr ); - - TQString sModeTQStr( sModeStr ); - if ( sModeTQStr == "ScaleFree" ) { - sMode = TQImage::ScaleFree; - } else if ( sModeTQStr == "ScaleMin" ) { - sMode = TQImage::ScaleMin; - } else if ( sModeTQStr == "ScaleMax" ) { - sMode = TQImage::ScaleMax; - } else { - tqDebug("read_jpeg_image: invalid scale mode \"%s\", see TQImage::ScaleMode documentation", sModeStr); - sMode = TQImage::ScaleFree; - } - -// tqDebug( "Parameters ask to scale the image to %i x %i ScaleMode: %s", sWidth, sHeight, sModeStr ); - scaleSize( sWidth, sHeight, cinfo.output_width, cinfo.output_height, sMode ); -// tqDebug( "Scaling the jpeg to %i x %i", sWidth, sHeight, sModeStr ); - - bool created = FALSE; - if ( cinfo.output_components == 3 || cinfo.output_components == 4) { - created = image.create( sWidth, sHeight, 32 ); - } else if ( cinfo.output_components == 1 ) { - created = image.create( sWidth, sHeight, 8, 256 ); - for (int i=0; i<256; i++) - image.setColor(i, tqRgb(i,i,i)); - } else { - // Unsupported format - } - if (!created) - image = TQImage(); - - if (!image.isNull()) { - TQImage tmpImage( cinfo.output_width, 1, 32 ); - uchar** inLines = tmpImage.jumpTable(); - uchar** outLines = image.jumpTable(); - while (cinfo.output_scanline < cinfo.output_height) { - int outputLine = sHeight * cinfo.output_scanline / cinfo.output_height; - (void) jpeg_read_scanlines(&cinfo, inLines, 1); - if ( cinfo.output_components == 3 ) { - uchar *in = inLines[0]; - TQRgb *out = (TQRgb*)outLines[outputLine]; - for (uint i=0; i32 bpp. - for (uint j=0; jsetImage(image); - iio->setStatus(image.isNull()); - } - - jpeg_destroy_decompress(&cinfo); - delete iod_src; -} - - -struct my_jpeg_destination_mgr : public jpeg_destination_mgr { - // Nothing dynamic - cannot rely on destruction over longjump - TQImageIO* iio; - JOCTET buffer[max_buf]; - -public: - my_jpeg_destination_mgr(TQImageIO*); -}; - - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static -void tqt_init_destination(j_compress_ptr) -{ -} - -static -void qt_exit_on_error(j_compress_ptr cinfo, TQIODevice* dev) -{ - if (dev->status() == IO_Ok) { - return; - } else { - // cinfo->err->msg_code = JERR_FILE_WRITE; - (*cinfo->err->error_exit)((j_common_ptr)cinfo); - } -} - -static -boolean qt_empty_output_buffer(j_compress_ptr cinfo) -{ - my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest; - TQIODevice* dev = dest->iio->ioDevice(); - - if ( dev->writeBlock( (char*)dest->buffer, max_buf ) != max_buf ) - qt_exit_on_error(cinfo, dev); - - dest->next_output_byte = dest->buffer; - dest->free_in_buffer = max_buf; - -#if defined(Q_OS_UNIXWARE) - return B_TRUE; -#else - return TRUE; -#endif -} - -static -void qt_term_destination(j_compress_ptr cinfo) -{ - my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest; - TQIODevice* dev = dest->iio->ioDevice(); - TQ_LONG n = max_buf - dest->free_in_buffer; - - if ( dev->writeBlock( (char*)dest->buffer, n ) != n ) - qt_exit_on_error(cinfo, dev); - - dev->flush(); - - qt_exit_on_error(cinfo, dev); -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -inline -my_jpeg_destination_mgr::my_jpeg_destination_mgr(TQImageIO* iioptr) -{ - jpeg_destination_mgr::init_destination = tqt_init_destination; - jpeg_destination_mgr::empty_output_buffer = qt_empty_output_buffer; - jpeg_destination_mgr::term_destination = qt_term_destination; - iio = iioptr; - next_output_byte = buffer; - free_in_buffer = max_buf; -} - - -static -void write_jpeg_image(TQImageIO* iio) -{ - TQImage image = iio->image(); - - struct jpeg_compress_struct cinfo; - JSAMPROW row_pointer[1]; - row_pointer[0] = 0; - - struct my_jpeg_destination_mgr *iod_dest = new my_jpeg_destination_mgr(iio); - struct my_error_mgr jerr; - - cinfo.err = jpeg_std_error(&jerr); - - jerr.error_exit = my_error_exit; - - if (!setjmp(jerr.setjmp_buffer)) { - jpeg_create_compress(&cinfo); - - cinfo.dest = iod_dest; - - cinfo.image_width = image.width(); - cinfo.image_height = image.height(); - - TQRgb* cmap=0; - bool gray=FALSE; - switch ( image.depth() ) { - case 1: - case 8: - cmap = image.colorTable(); - gray = TRUE; - int i; - for (i=image.numColors(); gray && i--; ) { - gray = gray & ( tqRed(cmap[i]) == tqGreen(cmap[i]) && - tqRed(cmap[i]) == tqBlue(cmap[i]) ); - } - cinfo.input_components = gray ? 1 : 3; - cinfo.in_color_space = gray ? JCS_GRAYSCALE : JCS_RGB; - break; - case 32: - cinfo.input_components = 3; - cinfo.in_color_space = JCS_RGB; - } - - jpeg_set_defaults(&cinfo); - - float diffInch = TQABS(image.dotsPerMeterX()*2.54/100. - tqRound(image.dotsPerMeterX()*2.54/100.)) - + TQABS(image.dotsPerMeterY()*2.54/100. - tqRound(image.dotsPerMeterY()*2.54/100.)); - float diffCm = (TQABS(image.dotsPerMeterX()/100. - tqRound(image.dotsPerMeterX()/100.)) - + TQABS(image.dotsPerMeterY()/100. - tqRound(image.dotsPerMeterY()/100.)))*2.54; - if (diffInch < diffCm) { - cinfo.density_unit = 1; // dots/inch - cinfo.X_density = tqRound(image.dotsPerMeterX()*2.54/100.); - cinfo.Y_density = tqRound(image.dotsPerMeterY()*2.54/100.); - } else { - cinfo.density_unit = 2; // dots/cm - cinfo.X_density = (image.dotsPerMeterX()+50) / 100; - cinfo.Y_density = (image.dotsPerMeterY()+50) / 100; - } - - int quality = iio->quality() >= 0 ? TQMIN(iio->quality(),100) : 75; -#if defined(Q_OS_UNIXWARE) - jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */); - jpeg_start_compress(&cinfo, B_TRUE); -#else - jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); - jpeg_start_compress(&cinfo, TRUE); -#endif - - row_pointer[0] = new uchar[cinfo.image_width*cinfo.input_components]; - int w = cinfo.image_width; - while (cinfo.next_scanline < cinfo.image_height) { - uchar *row = row_pointer[0]; - switch ( image.depth() ) { - case 1: - if (gray) { - uchar* data = image.scanLine(cinfo.next_scanline); - if ( image.bitOrder() == TQImage::LittleEndian ) { - for (int i=0; i> 3)) & (1 << (i & 7))); - row[i] = tqRed(cmap[bit]); - } - } else { - for (int i=0; i> 3)) & (1 << (7 -(i & 7)))); - row[i] = tqRed(cmap[bit]); - } - } - } else { - uchar* data = image.scanLine(cinfo.next_scanline); - if ( image.bitOrder() == TQImage::LittleEndian ) { - for (int i=0; i> 3)) & (1 << (i & 7))); - *row++ = tqRed(cmap[bit]); - *row++ = tqGreen(cmap[bit]); - *row++ = tqBlue(cmap[bit]); - } - } else { - for (int i=0; i> 3)) & (1 << (7 -(i & 7)))); - *row++ = tqRed(cmap[bit]); - *row++ = tqGreen(cmap[bit]); - *row++ = tqBlue(cmap[bit]); - } - } - } - break; - case 8: - if (gray) { - uchar* pix = image.scanLine(cinfo.next_scanline); - for (int i=0; isetStatus(0); - } - - delete iod_dest; - delete [] row_pointer[0]; -} - -void qInitJpegIO() -{ - // Not much to go on - just 3 bytes: 0xFF, M_SOI, 0xFF - // Even the third is not strictly specified as required. - TQImageIO::defineIOHandler("JPEG", "^\377\330\377", 0, read_jpeg_image, write_jpeg_image); -} - -#endif diff --git a/src/kernel/qkeysequence.cpp b/src/kernel/qkeysequence.cpp deleted file mode 100644 index 8fd7485b8..000000000 --- a/src/kernel/qkeysequence.cpp +++ /dev/null @@ -1,736 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQKeySequence class -** -** Created : 0108007 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 "ntqkeysequence.h" - -#ifndef TQT_NO_ACCEL - -#include "tqaccel.h" -#include "ntqshared.h" -#include "tqvaluelist.h" -#ifndef TQT_NO_REGEXP -# include "tqregexp.h" -#endif - -#ifdef TQ_WS_MAC -#define TQMAC_CTRL (TQString(TQChar(0x2318))) -#define TQMAC_META (TQString(TQChar(0x2303))) -#define TQMAC_ALT (TQString(TQChar(0x2325))) -#define TQMAC_SHIFT (TQString(TQChar(0x21E7))) -#endif - -/*! - \class TQKeySequence ntqkeysequence.h - \brief The TQKeySequence class encapsulates a key sequence as used - by accelerators. - - \ingroup misc - - A key sequence consists of up to four keyboard codes, each - optionally combined with modifiers, e.g. \c SHIFT, \c CTRL, \c - ALT, \c META, or \c UNICODE_ACCEL. For example, \c{CTRL + Key_P} - might be a sequence used as a shortcut for printing a document. - The key codes are listed in \c{ntqnamespace.h}. As an alternative, - use \c UNICODE_ACCEL with the unicode code point of the character. - For example, \c{UNICODE_ACCEL + 'A'} gives the same key sequence - as \c Key_A. - - Key sequences can be constructed either from an integer key code, - or from a human readable translatable string such as - "Ctrl+X,Alt+Space". A key sequence can be cast to a TQString to - obtain a human readable translated version of the sequence. - Translations are done in the "TQAccel" context. - - \sa TQAccel -*/ - -/*! - \enum TQt::SequenceMatch - - \value NoMatch Sequences have nothing in common - \value PartialMatch Sequences match partially, but are not complete - \value Identical Sequences do not differ -*/ - -static struct { - int key; - const char* name; -} keyname[] = { - { TQt::Key_Space, TQT_TRANSLATE_NOOP( "TQAccel", "Space" ) }, - { TQt::Key_Escape, TQT_TRANSLATE_NOOP( "TQAccel", "Esc" ) }, - { TQt::Key_Tab, TQT_TRANSLATE_NOOP( "TQAccel", "Tab" ) }, - { TQt::Key_Backtab, TQT_TRANSLATE_NOOP( "TQAccel", "Backtab" ) }, - { TQt::Key_Backspace, TQT_TRANSLATE_NOOP( "TQAccel", "Backspace" ) }, - { TQt::Key_Return, TQT_TRANSLATE_NOOP( "TQAccel", "Return" ) }, - { TQt::Key_Enter, TQT_TRANSLATE_NOOP( "TQAccel", "Enter" ) }, - { TQt::Key_Insert, TQT_TRANSLATE_NOOP( "TQAccel", "Ins" ) }, - { TQt::Key_Delete, TQT_TRANSLATE_NOOP( "TQAccel", "Del" ) }, - { TQt::Key_Pause, TQT_TRANSLATE_NOOP( "TQAccel", "Pause" ) }, - { TQt::Key_Print, TQT_TRANSLATE_NOOP( "TQAccel", "Print" ) }, - { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( "TQAccel", "SysReq" ) }, - { TQt::Key_Home, TQT_TRANSLATE_NOOP( "TQAccel", "Home" ) }, - { TQt::Key_End, TQT_TRANSLATE_NOOP( "TQAccel", "End" ) }, - { TQt::Key_Left, TQT_TRANSLATE_NOOP( "TQAccel", "Left" ) }, - { TQt::Key_Up, TQT_TRANSLATE_NOOP( "TQAccel", "Up" ) }, - { TQt::Key_Right, TQT_TRANSLATE_NOOP( "TQAccel", "Right" ) }, - { TQt::Key_Down, TQT_TRANSLATE_NOOP( "TQAccel", "Down" ) }, - { TQt::Key_Prior, TQT_TRANSLATE_NOOP( "TQAccel", "PgUp" ) }, - { TQt::Key_Next, TQT_TRANSLATE_NOOP( "TQAccel", "PgDown" ) }, - { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( "TQAccel", "CapsLock" ) }, - { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "NumLock" ) }, - { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( "TQAccel", "ScrollLock" ) }, - { TQt::Key_Menu, TQT_TRANSLATE_NOOP( "TQAccel", "Menu" ) }, - { TQt::Key_Help, TQT_TRANSLATE_NOOP( "TQAccel", "Help" ) }, - - // Multimedia keys - { TQt::Key_Back, TQT_TRANSLATE_NOOP( "TQAccel", "Back" ) }, - { TQt::Key_Forward, TQT_TRANSLATE_NOOP( "TQAccel", "Forward" ) }, - { TQt::Key_Stop, TQT_TRANSLATE_NOOP( "TQAccel", "Stop" ) }, - { TQt::Key_Refresh, TQT_TRANSLATE_NOOP( "TQAccel", "Refresh" ) }, - { TQt::Key_VolumeDown, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Down" ) }, - { TQt::Key_VolumeMute, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Mute" ) }, - { TQt::Key_VolumeUp, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Up" ) }, - { TQt::Key_BassBoost, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Boost" ) }, - { TQt::Key_BassUp, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Up" ) }, - { TQt::Key_BassDown, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Down" ) }, - { TQt::Key_TrebleUp, TQT_TRANSLATE_NOOP( "TQAccel", "Treble Up" ) }, - { TQt::Key_TrebleDown, TQT_TRANSLATE_NOOP( "TQAccel", "Treble Down" ) }, - { TQt::Key_MediaPlay, TQT_TRANSLATE_NOOP( "TQAccel", "Media Play" ) }, - { TQt::Key_MediaStop, TQT_TRANSLATE_NOOP( "TQAccel", "Media Stop" ) }, - { TQt::Key_MediaPrev, TQT_TRANSLATE_NOOP( "TQAccel", "Media Previous" ) }, - { TQt::Key_MediaNext, TQT_TRANSLATE_NOOP( "TQAccel", "Media Next" ) }, - { TQt::Key_MediaRecord, TQT_TRANSLATE_NOOP( "TQAccel", "Media Record" ) }, - { TQt::Key_HomePage, TQT_TRANSLATE_NOOP( "TQAccel", "Home" ) }, - { TQt::Key_Favorites, TQT_TRANSLATE_NOOP( "TQAccel", "Favorites" ) }, - { TQt::Key_Search, TQT_TRANSLATE_NOOP( "TQAccel", "Search" ) }, - { TQt::Key_Standby, TQT_TRANSLATE_NOOP( "TQAccel", "Standby" ) }, - { TQt::Key_OpenUrl, TQT_TRANSLATE_NOOP( "TQAccel", "Open URL" ) }, - { TQt::Key_LaunchMail, TQT_TRANSLATE_NOOP( "TQAccel", "Launch Mail" ) }, - { TQt::Key_LaunchMedia, TQT_TRANSLATE_NOOP( "TQAccel", "Launch Media" ) }, - { TQt::Key_Launch0, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (0)" ) }, - { TQt::Key_Launch1, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (1)" ) }, - { TQt::Key_Launch2, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (2)" ) }, - { TQt::Key_Launch3, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (3)" ) }, - { TQt::Key_Launch4, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (4)" ) }, - { TQt::Key_Launch5, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (5)" ) }, - { TQt::Key_Launch6, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (6)" ) }, - { TQt::Key_Launch7, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (7)" ) }, - { TQt::Key_Launch8, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (8)" ) }, - { TQt::Key_Launch9, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (9)" ) }, - { TQt::Key_LaunchA, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (A)" ) }, - { TQt::Key_LaunchB, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (B)" ) }, - { TQt::Key_LaunchC, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (C)" ) }, - { TQt::Key_LaunchD, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (D)" ) }, - { TQt::Key_LaunchE, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (E)" ) }, - { TQt::Key_LaunchF, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (F)" ) }, - { TQt::Key_MonBrightnessUp, TQT_TRANSLATE_NOOP( "TQAccel", "Monitor Brightness Up" ) }, - { TQt::Key_MonBrightnessDown, TQT_TRANSLATE_NOOP( "TQAccel", "Monitor Brightness Down" ) }, - { TQt::Key_KeyboardLightOnOff, TQT_TRANSLATE_NOOP( "TQAccel", "Keyboard Light On Off" ) }, - { TQt::Key_KeyboardBrightnessUp, TQT_TRANSLATE_NOOP( "TQAccel", "Keyboard Brightness Up" ) }, - { TQt::Key_KeyboardBrightnessDown, TQT_TRANSLATE_NOOP( "TQAccel", "Keyboard Brightness Down" ) }, - - // -------------------------------------------------------------- - // More consistent namings - { TQt::Key_Print, TQT_TRANSLATE_NOOP( "TQAccel", "Print Screen" ) }, - { TQt::Key_Prior, TQT_TRANSLATE_NOOP( "TQAccel", "Page Up" ) }, - { TQt::Key_Next, TQT_TRANSLATE_NOOP( "TQAccel", "Page Down" ) }, - { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( "TQAccel", "Caps Lock" ) }, - { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "Num Lock" ) }, - { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "Number Lock" ) }, - { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( "TQAccel", "Scroll Lock" ) }, - { TQt::Key_Insert, TQT_TRANSLATE_NOOP( "TQAccel", "Insert" ) }, - { TQt::Key_Delete, TQT_TRANSLATE_NOOP( "TQAccel", "Delete" ) }, - { TQt::Key_Escape, TQT_TRANSLATE_NOOP( "TQAccel", "Escape" ) }, - { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( "TQAccel", "System Request" ) }, - - { 0, 0 } -}; - - -class TQKeySequencePrivate : public TQShared -{ -public: - inline TQKeySequencePrivate() - { - key[0] = key[1] = key[2] = key[3] = 0; - } - inline TQKeySequencePrivate( TQKeySequencePrivate *copy ) - { - key[0] = copy->key[0]; - key[1] = copy->key[1]; - key[2] = copy->key[2]; - key[3] = copy->key[3]; - } - int key[4]; -}; - - -/*! - Constructs an empty key sequence. -*/ -TQKeySequence::TQKeySequence() -{ - d = new TQKeySequencePrivate(); - TQ_CHECK_PTR( d ); -} - -/*! - Creates a key sequence from the string \a key. For example - "Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl", - "Shift", "Alt" and "Meta" are recognized, as well as their - translated equivalents in the "TQAccel" context (using - TQObject::tr()). - - Multiple key codes (up to four) may be entered by separating them - with commas, e.g. "Alt+X,Ctrl+S,Q". - - This contructor is typically used with \link TQObject::tr() tr - \endlink(), so that accelerator keys can be replaced in - translations: - - \code - TQPopupMenu *file = new TQPopupMenu( this ); - file->insertItem( tr("&Open..."), this, TQ_SLOT(open()), - TQKeySequence( tr("Ctrl+O", "File|Open") ) ); - \endcode - - Note the \c "File|Open" translator comment. It is by no means - necessary, but it provides some context for the human translator. -*/ -TQKeySequence::TQKeySequence( const TQString& key ) -{ - d = new TQKeySequencePrivate(); - TQ_CHECK_PTR( d ); - assign( key ); -} - - -// ### BCI: Merge with constructor below for 4.0 -/*! - Constructs a key sequence that has a single \a key. - - The key codes are listed in \c{ntqnamespace.h} and can be - combined with modifiers, e.g. with \c SHIFT, \c CTRL, \c - ALT, \c META or \c UNICODE_ACCEL. -*/ -TQKeySequence::TQKeySequence( int key ) -{ - d = new TQKeySequencePrivate(); - TQ_CHECK_PTR( d ); - d->key[0] = key; -} - -/*! - Constructs a key sequence with up to 4 keys \a k1, \a k2, - \a k3 and \a k4. - - The key codes are listed in \c{ntqnamespace.h} and can be - combined with modifiers, e.g. with \c SHIFT, \c CTRL, \c - ALT, \c META or \c UNICODE_ACCEL. -*/ -TQKeySequence::TQKeySequence( int k1, int k2, int k3, int k4 ) -{ - d = new TQKeySequencePrivate(); - TQ_CHECK_PTR( d ); - d->key[0] = k1; - d->key[1] = k2; - d->key[2] = k3; - d->key[3] = k4; -} - -/*! - Copy constructor. Makes a copy of \a keysequence. - */ -TQKeySequence::TQKeySequence( const TQKeySequence& keysequence ) - : d( keysequence.d ) -{ - d->ref(); -} - - -/*! - Destroys the key sequence. - */ -TQKeySequence::~TQKeySequence() -{ - if ( d->deref() ) - delete d; -} - -/*! - \internal - KeySequences should never be modified, but rather just created. - Internally though we do need to modify to keep pace in event - delivery. -*/ - -void TQKeySequence::setKey( int key, int index ) -{ -#ifdef QT_CHECK_STATE - if ( 0 > index && 4 < index ) { - tqWarning( "TQKeySequence::setKey: index %u out of range", index ); - return; - } -#endif // QT_CHECK_STATE - - if ( 1 < d->count ) { - TQKeySequencePrivate *newd = new TQKeySequencePrivate( d ); - d->deref(); - d = newd; - } - d->key[index] = key; -} - -/*! - Returns the number of keys in the key sequence. - The maximum is 4. - */ -uint TQKeySequence::count() const -{ - if ( ! d->key[0] ) - return 0; - if ( ! d->key[1] ) - return 1; - if ( ! d->key[2] ) - return 2; - if ( ! d->key[3] ) - return 3; - return 4; -} - - -/*! - Returns TRUE if the key sequence is empty; otherwise returns - FALSE. -*/ -bool TQKeySequence::isEmpty() const -{ - return !d->key[0]; -} - - -/*! - Adds the string \a keyseq to the key sequence. \a keyseq may - contain up to four key codes, provided they are seperated by a - comma, e.g. "Alt+X,Ctrl+S,Z"). Returns the number of key codes - added. -*/ -int TQKeySequence::assign( TQString keyseq ) -{ - TQString part; - int n = 0; - int p = 0, diff = 0; - - // Run through the whole string, but stop - // if we have 4 keys before the end. - while ( keyseq.length() && n < 4 ) { - // We MUST use something to seperate each sequence, and space - // does not cut it, since some of the key names have space - // in them.. (Let's hope no one translate with a comma in it:) - p = keyseq.find( ',' ); - if ( -1 != p ) { - if ( ',' == keyseq[p+1] ) // e.g. 'Ctrl+,, Shift+,,' - p++; - if ( ' ' == keyseq[p+1] ) { // Space after comma - diff = 1; - p++; - } else if ( '\0' == keyseq[p+1] ) { // Last comma 'Ctrl+,' - p = -1; - } else { - diff = 0; - } - } - part = keyseq.left( -1==p?keyseq.length():p-diff ); - keyseq = keyseq.right( -1==p?0:keyseq.length() - ( p + 1 ) ); - d->key[n] = decodeString( part ); - n++; - } - return n; -} - -struct ModifKeyName { - ModifKeyName() { } - ModifKeyName(int q, TQString n) : qt_key(q), name(n) { } - int qt_key; - TQString name; -}; - -/*! - Constructs a single key from the string \str. - */ -int TQKeySequence::decodeString( const TQString& str ) -{ - int ret = 0; - TQString accel = str; - - TQValueList modifs; -#ifdef TQMAC_CTRL - modifs << ModifKeyName( CTRL, TQMAC_CTRL ); -#endif -#ifdef TQMAC_ALT - modifs << ModifKeyName( ALT, TQMAC_ALT ); -#endif -#ifdef TQMAC_META - modifs << ModifKeyName( META, TQMAC_META ); -#endif -#ifdef TQMAC_SHIFT - modifs << ModifKeyName( SHIFT, TQMAC_SHIFT ); -#endif - modifs << ModifKeyName( CTRL, "ctrl+" ) << ModifKeyName( CTRL, TQAccel::tr("Ctrl").lower().append('+') ); - modifs << ModifKeyName( SHIFT, "shift+" ) << ModifKeyName( SHIFT, TQAccel::tr("Shift").lower().append('+') ); - modifs << ModifKeyName( ALT, "alt+" ) << ModifKeyName( ALT, TQAccel::tr("Alt").lower().append('+') ); - modifs << ModifKeyName( META, "meta+" ) << ModifKeyName( ALT, TQAccel::tr("Meta").lower().append('+') ); - TQString sl = accel.lower(); - for( TQValueList::iterator it = modifs.begin(); it != modifs.end(); ++it ) { - if ( sl.contains( (*it).name ) ) { - ret |= (*it).qt_key; -#ifndef TQT_NO_REGEXP - accel.remove( TQRegExp(TQRegExp::escape((*it).name), FALSE) ); -#else - accel.remove( (*it).name ); -#endif - sl = accel.lower(); - } - } - - int p = accel.findRev( '+', str.length() - 2 ); // -2 so that Ctrl++ works - if( p > 0 ) - accel = accel.mid( p + 1 ); - - int fnum = 0; - if ( accel.length() == 1 ) { - char ltr = accel[0].upper().latin1(); - // We can only upper A-Z without problems. - if ( ltr < (char)Key_A || ltr > (char)Key_Z ) - ret |= accel[0].unicode(); - else - ret |= accel[0].upper().unicode(); - ret |= UNICODE_ACCEL; - } else if ( accel[0] == 'F' && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35) ) { - ret |= Key_F1 + fnum - 1; - } else { - // Check through translation table for the correct key name - // ...or fall back on english table. - bool found = FALSE; - for ( int tran = 0; tran < 2; tran++ ) { - for ( int i = 0; keyname[i].name; i++ ) { - if ( tran ? accel == TQAccel::tr(keyname[i].name) - : accel == keyname[i].name ) { - ret |= keyname[i].key; - found = TRUE; - break; - } - } - if(found) - break; - } - } - return ret; -} - - -/*! - Creates an accelerator string for \a key. For example, - CTRL+Key_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are - translated (using TQObject::tr()) in the "TQAccel" context. - */ -TQString TQKeySequence::encodeString( int key ) -{ - TQString s; -#if defined(Q_OS_MAC) - // On MAC the order is Meta, Alt, Shift, Control. - if ( (key & META) == META ) - s += TQMAC_META; - if ( (key & ALT) == ALT ) - s += TQMAC_ALT; - if ( (key & SHIFT) == SHIFT ) - s += TQMAC_SHIFT; - if ( (key & CTRL) == CTRL ) - s += TQMAC_CTRL; -#else - // On other systems the order is Meta, Control, Alt, Shift - if ( (key & META) == META ) - s += TQAccel::tr( "Meta" ); - if ( (key & CTRL) == CTRL ) { - if ( !s.isEmpty() ) - s += TQAccel::tr( "+" ); - s += TQAccel::tr( "Ctrl" ); - } - if ( (key & ALT) == ALT ) { - if ( !s.isEmpty() ) - s += TQAccel::tr( "+" ); - s += TQAccel::tr( "Alt" ); - } - if ( (key & SHIFT) == SHIFT ) { - if ( !s.isEmpty() ) - s += TQAccel::tr( "+" ); - s += TQAccel::tr( "Shift" ); - } -#endif - - - key &= ~(SHIFT | CTRL | ALT | META ); - TQString p; - - if ( (key & UNICODE_ACCEL) == UNICODE_ACCEL ) { - // Note: This character should NOT be upper()'ed, since - // the encoded string should indicate EXACTLY what the - // key represents! Hence a 'Ctrl+Shift+c' is posible to - // represent, but is clearly impossible to trigger... - p = TQChar(key & 0xffff); - } else if ( key >= Key_F1 && key <= Key_F35 ) { - p = TQAccel::tr( "F%1" ).arg(key - Key_F1 + 1); - } else if ( key > Key_Space && key <= Key_AsciiTilde ) { - p.sprintf( "%c", key ); - } else { - int i=0; - while (keyname[i].name) { - if ( key == keyname[i].key ) { - p = TQAccel::tr(keyname[i].name); - break; - } - ++i; - } - // If we can't find the actual translatable keyname, - // fall back on the unicode representation of it... - // Or else characters like Key_aring may not get displayed - // ( Really depends on you locale ) - if ( !keyname[i].name ) - // Note: This character should NOT be upper()'ed, see above! - p = TQChar(key & 0xffff); - } - -#ifndef Q_OS_MAC - if ( !s.isEmpty() ) - s += TQAccel::tr( "+" ); -#endif - - s += p; - return s; -} - -/*! - Matches the sequence with \a seq. Returns \c TQt::Identical if - successful, \c TQt::PartialMatch for matching but incomplete \a seq, - and \c TQt::NoMatch if the sequences have nothing in common. - Returns \c TQt::NoMatch if \a seq is shorter. -*/ -TQt::SequenceMatch TQKeySequence::matches( const TQKeySequence& seq ) const -{ - uint userN = count(), - seqN = seq.count(); - - if ( userN > seqN ) - return NoMatch; - - // If equal in length, we have a potential Identical sequence, - // else we already know it can only be partial. - SequenceMatch match = ( userN == seqN ? Identical : PartialMatch ); - - for ( uint i = 0; i < userN; i++ ) { - int userKey = (*this)[i], - sequenceKey = seq[i]; - - if ( (userKey & ~TQt::UNICODE_ACCEL) != - (sequenceKey & ~TQt::UNICODE_ACCEL) ) - return NoMatch; - } - return match; -} - - -/*! - Creates an accelerator string for the key sequence. - For instance CTRL+Key_O gives "Ctrl+O". If the key sequence has - multiple key codes they are returned comma-separated, e.g. - "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are - translated (using TQObject::tr()) in the "TQAccel" scope. If the key - sequence has no keys, TQString::null is returned. - - On Mac OS X, the string returned resembles the sequence that is shown in - the menubar. -*/ -TQKeySequence::operator TQString() const -{ - int end = count(); - if ( !end ) return TQString::null; - - TQString complete; - int i = 0; - while ( i < end ) { - complete += encodeString( d->key[i] ); - i++; - if ( i != end) - complete += ", "; - } - return complete; -} - - -/*! - \obsolete - For backward compatibility: returns the first keycode - as integer. If the key sequence is empty, 0 is returned. - */ -TQKeySequence::operator int () const -{ - if ( 1 <= count() ) - return d->key[0]; - return 0; -} - - -/*! - Returns a reference to the element at position \a index in the key - sequence. This can only be used to read an element. - */ -int TQKeySequence::operator[]( uint index ) const -{ -#ifdef QT_CHECK_STATE - if ( index > 4 ) { - tqWarning( "TQKeySequence::operator[]: index %u out of range", index ); - return 0; - } -#endif // QT_CHECK_STATE - return d->key[index]; -} - - -/*! - Assignment operator. Assigns \a keysequence to this - object. - */ -TQKeySequence &TQKeySequence::operator=( const TQKeySequence & keysequence ) -{ - keysequence.d->ref(); - if ( d->deref() ) - delete d; - d = keysequence.d; - return *this; -} - - -/*! - Returns TRUE if \a keysequence is equal to this key - sequence; otherwise returns FALSE. - */ - - -bool TQKeySequence::operator==( const TQKeySequence& keysequence ) const -{ - return ( (d->key[0]&~UNICODE_ACCEL) == (keysequence.d->key[0]&~UNICODE_ACCEL) && - (d->key[1]&~UNICODE_ACCEL) == (keysequence.d->key[1]&~UNICODE_ACCEL) && - (d->key[2]&~UNICODE_ACCEL) == (keysequence.d->key[2]&~UNICODE_ACCEL) && - (d->key[3]&~UNICODE_ACCEL) == (keysequence.d->key[3]&~UNICODE_ACCEL) ); -} - - -/*! - Returns TRUE if \a keysequence is not equal to this key sequence; - otherwise returns FALSE. -*/ -bool TQKeySequence::operator!= ( const TQKeySequence& keysequence ) const -{ - TQKeySequence *that = (TQKeySequence*)this; - return !( (*that) == keysequence ); -} - - -/***************************************************************************** - TQKeySequence stream functions - *****************************************************************************/ -#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO) -/*! - \relates TQKeySequence - - Writes the key sequence \a keysequence to the stream \a s. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ -TQDataStream &operator<<( TQDataStream &s, const TQKeySequence &keysequence ) -{ - TQValueList list; - list += keysequence.d->key[0]; - list += keysequence.d->key[1]; - list += keysequence.d->key[2]; - list += keysequence.d->key[3]; - s << list; - - return s; -} - - -/*! - \relates TQKeySequence - - Reads a key sequence from the stream \a s into the key sequence \a - keysequence. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ -TQDataStream &operator>>( TQDataStream &s, TQKeySequence &keysequence ) -{ - TQValueList list; - s >> list; - -#ifdef QT_CHECK_STATE - if ( 1 != list.count() && 4 != list.count() ) { - tqWarning( "Invalid TQKeySequence data in the datastream." ); - return s; - } -#endif - - if ( 1 == list.count() ) { - keysequence.d->key[0] = *list.at( 0 ); - keysequence.d->key[1] = - keysequence.d->key[2] = - keysequence.d->key[3] = 0; - } else { - keysequence.d->key[0] = *list.at( 0 ); - keysequence.d->key[1] = *list.at( 1 ); - keysequence.d->key[2] = *list.at( 2 ); - keysequence.d->key[3] = *list.at( 3 ); - } - return s; -} - -#endif //TQT_NO_DATASTREAM - -#endif //TQT_NO_ACCEL diff --git a/src/kernel/qscriptengine_x11.cpp b/src/kernel/qscriptengine_x11.cpp index 6c1190fb3..5d22fdf49 100644 --- a/src/kernel/qscriptengine_x11.cpp +++ b/src/kernel/qscriptengine_x11.cpp @@ -1900,7 +1900,7 @@ static void indic_attributes(int script, const TQString &text, int from, int len // -------------------------------------------------------------------------------------------------------------------------------------------- #include -#include +#include static void thaiWordBreaks(const TQChar *string, const int len, TQCharAttributes *attributes) diff --git a/src/kernel/qt_gfx.pri b/src/kernel/qt_gfx.pri index c66f3141e..fadd1277f 100644 --- a/src/kernel/qt_gfx.pri +++ b/src/kernel/qt_gfx.pri @@ -39,8 +39,8 @@ mng { else:DEFINES += TQT_NO_IMAGEIO_MNG #jpeg support.. -HEADERS += $$KERNEL_H/ntqjpegio.h -SOURCES += $$KERNEL_CPP/qjpegio.cpp +HEADERS += $$KERNEL_H/tqjpegio.h +SOURCES += $$KERNEL_CPP/tqjpegio.cpp jpeg { system-jpeg { unix:LIBS += -ljpeg diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index d52783f7c..03904d262 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -35,8 +35,8 @@ kernel { $$KERNEL_H/tqimage.h \ $$KERNEL_P/tqimageformatinterface_p.h \ $$KERNEL_H/tqimageformatplugin.h \ - $$KERNEL_H/ntqkeycode.h \ - $$KERNEL_H/ntqkeysequence.h \ + $$KERNEL_H/tqkeycode.h \ + $$KERNEL_H/tqkeysequence.h \ $$KERNEL_H/tqlayout.h \ $$KERNEL_P/tqlayoutengine_p.h \ $$KERNEL_H/tqtranslator.h \ @@ -100,9 +100,9 @@ kernel { inputmethod { unix:x11 { - HEADERS += $$KERNEL_H/ntqinputcontext.h + HEADERS += $$KERNEL_H/tqinputcontext.h } else { - HEADERS += $$KERNEL_P/qinputcontext_p.h + HEADERS += $$KERNEL_P/tqinputcontext_p.h } } @@ -118,7 +118,7 @@ kernel { $$KERNEL_CPP/qdnd_win.cpp \ $$KERNEL_CPP/tqeventloop_win.cpp \ $$KERNEL_CPP/tqfont_win.cpp \ - $$KERNEL_CPP/qinputcontext_win.cpp \ + $$KERNEL_CPP/tqinputcontext_win.cpp \ $$KERNEL_CPP/tqmime_win.cpp \ $$KERNEL_CPP/tqpixmap_win.cpp \ $$KERNEL_CPP/tqprinter_win.cpp \ @@ -140,8 +140,8 @@ kernel { $$KERNEL_CPP/qdnd_x11.cpp \ $$KERNEL_CPP/tqdesktopwidget_x11.cpp \ $$KERNEL_CPP/tqfont_x11.cpp \ - $$KERNEL_CPP/qinputcontext.cpp \ - $$KERNEL_CPP/qinputcontext_x11.cpp \ + $$KERNEL_CPP/tqinputcontext.cpp \ + $$KERNEL_CPP/tqinputcontext_x11.cpp \ $$KERNEL_CPP/tqmotifdnd_x11.cpp \ $$KERNEL_CPP/tqpixmap_x11.cpp \ $$KERNEL_CPP/tqpaintdevice_x11.cpp \ @@ -217,7 +217,7 @@ kernel { $$KERNEL_CPP/tqiconset.cpp \ $$KERNEL_CPP/tqimage.cpp \ $$KERNEL_CPP/tqimageformatplugin.cpp \ - $$KERNEL_CPP/qkeysequence.cpp \ + $$KERNEL_CPP/tqkeysequence.cpp \ $$KERNEL_CPP/tqlayout.cpp \ $$KERNEL_CPP/tqlayoutengine.cpp \ $$KERNEL_CPP/tqtranslator.cpp \ diff --git a/src/kernel/qvariant.cpp b/src/kernel/qvariant.cpp index ac94aea12..8f5768696 100644 --- a/src/kernel/qvariant.cpp +++ b/src/kernel/qvariant.cpp @@ -63,7 +63,7 @@ #include "tqsizepolicy.h" #include "ntqshared.h" #include "tqbitarray.h" -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #include "tqpen.h" #ifndef DBL_DIG diff --git a/src/kernel/tqaccel.h b/src/kernel/tqaccel.h index 22c2f80e1..c883ba2ff 100644 --- a/src/kernel/tqaccel.h +++ b/src/kernel/tqaccel.h @@ -43,7 +43,7 @@ #ifndef QT_H #include "tqobject.h" -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #endif // QT_H #ifndef TQT_NO_ACCEL diff --git a/src/kernel/tqimage.cpp b/src/kernel/tqimage.cpp index 6c1d1ffad..b71804321 100644 --- a/src/kernel/tqimage.cpp +++ b/src/kernel/tqimage.cpp @@ -48,7 +48,7 @@ #include "tqasyncimageio.h" #include "tqpngio.h" #include "ntqmngio.h" -#include "ntqjpegio.h" +#include "tqjpegio.h" #include "tqmap.h" #include #include "tqimageformatinterface_p.h" diff --git a/src/kernel/tqinputcontext.cpp b/src/kernel/tqinputcontext.cpp new file mode 100644 index 000000000..7d15aa0c7 --- /dev/null +++ b/src/kernel/tqinputcontext.cpp @@ -0,0 +1,849 @@ +/**************************************************************************** +** $Id: tqinputcontext.cpp,v 1.6 2004/06/22 06:47:30 daisuke Exp $ +** +** Implementation of TQInputContext class +** +** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** licenses for Unix/X11 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +//#define TQT_NO_IM_PREEDIT_RELOCATION + +#include "tqinputcontext.h" + +#ifndef TQT_NO_IM + +#include "qplatformdefs.h" + +#include "ntqapplication.h" +#include "tqwidget.h" +#include "tqpopupmenu.h" + +#include +#include + +class TQInputContextPrivate +{ +public: + TQInputContextPrivate() + : holderWidget( 0 ), composingWidget( 0 ), hasFocus( FALSE ), + isComposing( FALSE ) +#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) + , preeditString( TQString::null ), + cursorPosition( -1 ), selLength ( 0 ) +#endif + {} + + TQWidget *holderWidget; // widget to which TQInputContext instance belongs. + TQWidget *composingWidget; + bool hasFocus; + bool isComposing; + + void updateComposingState( const TQString &text, + int newCursorPosition, int newSelLength ) { +#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) + preeditString = text; + cursorPosition = newCursorPosition; + selLength = newSelLength; +#endif + } + + void resetComposingState() { + isComposing = FALSE; +#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) + preeditString = TQString::null; + cursorPosition = -1; + selLength = 0; +#endif + } + +#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) + TQString preeditString; + int cursorPosition; + int selLength; +#endif +}; + + +// UPDATED COMMENT REQUIRED -- 2004-07-08 YamaKen +/*! + \class TQInputContext tqinputcontext.h + \brief The TQInputContext class abstracts the input method dependent data and composing state. + + \ingroup i18n + + An input method is responsible to input complex text that cannot + be inputted via simple keymap. It converts a sequence of input + events (typically key events) into a text string through the input + method specific converting process. The class of the processes are + widely ranging from simple finite state machine to complex text + translator that pools a whole paragraph of a text with text + editing capability to perform grammar and semantic analysis. + + To abstract such different input method specific intermediate + information, TQt offers the TQInputContext as base class. The + concept is well known as 'input context' in the input method + domain. an input context is created for a text widget in response + to a demand. It is ensured that an input context is prepared for + an input method before input to a text widget. + + Multiple input contexts that is belonging to a single input method + may concurrently coexist. Suppose multi-window text editor. Each + text widget of window A and B holds different TQInputContext + instance which contains different state information such as + partially composed text. + + \section1 Groups of functions: + + \table + \header \i Context \i Functions + + \row \i Receiving information \i + x11FilterEvent(), + filterEvent(), + setMicroFocus(), + mouseHandler() + + \row \i Sending back composed text \i + sendIMEvent(), + + \row \i State change notification \i + setFocus(), + unsetFocus(), + reset() + + \row \i Context information \i + identifierName(), + language(), + font(), + isComposing(), + + \endtable + + + \section1 Sharing input context between text widgets + + Any input context can be shared between several text widgets to + reduce resource consumption. In ideal case, each text widgets + should be allocated dedicated input context. But some complex + input contexts require slightly heavy resource such as 100 + kilobytes of memory. It prevents quite many text widgets from + being used concurrently. + + To resolve such problem, we can share an input context. There is + one 'input context holder widget' per text widgets that shares + identical input context. In this model, the holder widget owns the + shared input context. Other text widgets access the input context + via TQApplication::locateICHolderWidget(). But the access + convention is transparently hidden into TQWidget, so developers are + not required to aware of it. + + What developer should know is only the mapping function + TQApplication::locateICHolderWidget(). It accepts a widget as + argument and returns its holder widget. Default implementation + returns the top-level widget of the widget as reasonable + assumption. But some applications should reimplement the function + to fit application specific usability. See + TQApplication::locateICHolderWidget() for further information. + + + \section1 Preedit preservation + + As described above, input contexts have wide variety of amount of + the state information in accordance with belonging input + method. It is ranging from 2-3 keystrokes of sequence in + deterministic input methods to hundreds of keystrokes with + semantic text refinement in complex input methods such as ordinary + Japanese input method. The difference requires the different reset + policies in losing input focus. + + The former simple input method case, users will prefer resetting + the context to back to the neutral state when something + happened. Suppose a web browsing. The user scroll the page by + scrollbar after he or she has typed a half of the valid key + sequence into a text widget. In the case, the input context should + be reset in losing focus when he or she has dragged the + scrollbar. He or she will be confused if the input context is + still preserved until focused back to the text widget because he + or she will restart typing with first key of the sequence as a + habitual operation. + + On the other hand, we should choose completely different policy + for the latter complex input method case. Suppose same situation + as above but he or she is using a complex input method. In the + case, he or she will be angry if the input context has been lost + when he or she has dragged the scrollbar because the input context + contained a valuably composed text made up by considerable input + cost. So we should not reset the input context in the case. And + the input context should be preserved until focused back to the + text widget. This behavior is named as 'preedit preservation'. + + The two policies can be switched by calling or not calling reset() + in unsetFocus(). Default implementation of unsetFocus() calls + reset() to fit the simple input methods. The implementation is + expressed as 'preedit preservation is disabled'. + + + \section1 Preedit relocation + + Although the most case of the preedit preservation problem for + complex input methods is resolved as described above, there is a + special case. Suppose the case that matches all of the following + conditions. + + \list + + \i a input focus has been moved from a text widget to another text + widget directly + + \i the input context is shared between the two text widgets + + \i preedit preservation is enabled for the input context + + \endlist + + In the case, there are the following two requirements that + contradicts each other. The input context sharing causes it. + + \list + + \i the input context has to be reset to prepare to input to the + newly focused text widget + + \i the input context has to be preserved until focused back to the + previous text widget + + \endlist + + A intrinsic feature named 'preedit relocation' is available to + compromise the requirements. If the feature is enabled for the + input context, it is simply moved to the new text widget with the + preedit string. The user continues the input on the new text + widget, or relocate it to another text widget. The preedit of + previous text widget is automatically cleared to back to the + neutral state of the widget. + + This strange behavior is just a compromise. As described in + previous section, complex input method user should not be exposed + to the risk losing the input context because it contains valuable + long text made up with considerable input cost. The user will + immediately focus back to the previous text widget to continue the + input in the correct text widget if the preedit relocation + occurred. The feature is mainly existing as safety. + + The feature properly works even if the focus is moved as + following. Input method developers are not required to be aware of + the relocation protocol since TQInputContext transparently handles + it. + + a text widget -> a non-text widget -> another text widget + + To enable the preedit relocation feature, the input context class + have to reimplement isPreeditRelocationEnabled() as returns TRUE. + The implementation requires that the preedit preservation is also + enabled since preedit relocation is a special case of the preedit + preservation. If the preedit relocation is disabled, the input + context is simply reset in the relocation case. + + + \section1 Input context instanciation + \section1 Input method switching + + \section1 Text widget implementor's guide + + Add following code fragment into createPopupMenu() to add input + method dependent submenus. + + \code + #ifndef TQT_NO_IM + TQInputContext *qic = getInputContext(); + if ( qic ) + qic->addMenusTo( popup ); + #endif + \endcode + + \sa TQInputContextPlugin, TQInputContextFactory, TQApplication::locateICHolderWidget(), TQApplication::defaultInputMethod() +*/ + + +/*! + Constructs an input context. + + holderWidget is set immediately after this constructor has been + returned on the X11 platform. +*/ +TQInputContext::TQInputContext( TQObject *parent ) + : TQObject( parent ) +{ + d = new TQInputContextPrivate; +} + + +/*! + Destroys the input context. +*/ +TQInputContext::~TQInputContext() +{ + delete d; +} + +#if defined(TQ_WS_X11) +/*! + \internal + Returns the owner of this input context. Ordinary input methods + should not call this function directly to keep platform + independence and flexible configuration possibility. + + The return value may differ from focusWidget() if the input + context is shared between several text widgets. + + \sa setHolderWidget(), focusWidget() +*/ +TQWidget *TQInputContext::holderWidget() const +{ + return d->holderWidget; +} + +/*! + \internal + Sets the owner of this input context. Ordinary input methods + must not call this function directly. + + \sa holderWidget() +*/ +void TQInputContext::setHolderWidget( TQWidget *w ) +{ + d->holderWidget = w; +} + +/*! + \internal + Returns the widget that has an input focus for this input + context. Ordinary input methods should not call this function + directly to keep platform independence and flexible configuration + possibility. + + The return value may differ from holderWidget() if the input + context is shared between several text widgets. + + \sa setFocusWidget(), holderWidget() +*/ +TQWidget *TQInputContext::focusWidget() const +{ + return d->hasFocus ? d->composingWidget : 0; +} + + +/*! + \internal + Sets the widget that has an input focus for this input + context. Ordinary input methods must not call this function + directly. + + \sa focusWidget() +*/ +void TQInputContext::setFocusWidget( TQWidget *w ) +{ + if ( w ) { + bool isFocusingBack = ( w == d->composingWidget ); + bool isPreeditRelocation = ( ! isFocusingBack && isComposing() && + d->composingWidget ); + // invoke sendIMEventInternal() rather than sendIMEvent() to + // avoid altering the composing state + if ( isPreeditRelocation == TRUE ) { + // clear preedit of previously focused text + // widget. preserved preedit may be exist even if + // isPreeditRelocationEnabled() == FALSE. + sendIMEventInternal( TQEvent::IMEnd ); + } + d->composingWidget = w; // changes recipient of TQIMEvent + if ( isPreeditRelocation == TRUE ) { +#if !defined(TQT_NO_IM_PREEDIT_RELOCATION) + if ( isPreeditRelocationEnabled() ) { + // copy preedit state to the widget that gaining focus + sendIMEventInternal( TQEvent::IMStart ); + sendIMEventInternal( TQEvent::IMCompose, d->preeditString, + d->cursorPosition, d->selLength ); + } else +#endif + { + // reset input context when the shared context has + // focused on another text widget + reset(); + } + } + } + d->hasFocus = w ? TRUE : FALSE; +} + + +/*! + \internal + This function is called from TQWidget to keep input state + consistency. Ordinary input method must not call this function + directly. +*/ +void TQInputContext::releaseComposingWidget( TQWidget *w ) +{ + if ( d->composingWidget == w ) { + d->composingWidget = 0; + d->hasFocus = FALSE; + } +} +#endif // TQ_WS_X11 + +/*! + \internal + This function can be reimplemented in a subclass as returning TRUE + if you want making your input method enable the preedit + relocation. See the description for preedit relocation of + TQInputContext. + + /sa TQInputContext +*/ +bool TQInputContext::isPreeditRelocationEnabled() +{ + return FALSE; +} + +/*! + This function indicates whether IMStart event had been sent to the + text widget. It is ensured that an input context can send IMCompose + or IMEnd event safely if this function returned TRUE. + + The state is automatically being tracked through sendIMEvent(). + + \sa sendIMEvent() +*/ +bool TQInputContext::isComposing() const +{ + return d->isComposing; +} + + +/*! + This function can be reimplemented in a subclass to filter input + events. + + Return TRUE if the \a event has been consumed. Otherwise, the + unfiltered \a event will be forwarded to widgets as ordinary + way. Although the input events have accept() and ignore() + methods, leave it untouched. + + \a event is currently restricted to TQKeyEvent. But some input + method related events such as TQWheelEvent or TQTabletEvent may be + added in future. + + The filtering opportunity is always given to the input context as + soon as possible. It has to be taken place before any other key + event consumers such as eventfilters and accelerators because some + input methods require quite various key combination and + sequences. It often conflicts with accelerators and so on, so we + must give the input context the filtering opportunity first to + ensure all input methods work properly regardless of application + design. + + Ordinary input methods require discrete key events to work + properly, so TQt's key compression is always disabled for any input + contexts. + + \sa TQKeyEvent, x11FilterEvent() +*/ +bool TQInputContext::filterEvent( const TQEvent *event ) +{ + Q_UNUSED(event); + return FALSE; +} + + +/*! + \fn void TQInputContext::deletionRequested() + + Emit this signal when a fatal error has been caused in the input + context. The input context will be deleted by the owner which is + usually the holder widget. +*/ + +/*! + \fn void TQInputContext::imEventGenerated( TQObject *receiver, TQIMEvent *e ) + + \internal + This signal is emitted when the user has sent a TQIMEvent through + sendIMEvent(). Ordinary input methods should not emit this signal + directly. + + \a receiver is a platform dependent destination of the \a e. + + \sa TQIMEvent, sendIMEvent(), sendIMEventInternal(), +*/ + +/*! + \internal + Sends a TQIMEvent to the client via imEventGenerated() + signal. Ordinary input method should not call this function + directly. + + \sa TQIMEvent, TQIMComposeEvent, sendIMEvent(), imEventGenerated() +*/ +void TQInputContext::sendIMEventInternal( TQEvent::Type type, + const TQString &text, + int cursorPosition, int selLength ) +{ + TQObject *receiver = 0; + TQIMEvent *event = 0; + +#if defined(TQ_WS_X11) + receiver = d->composingWidget; +#endif + if ( ! receiver ) + return; + + if ( type == TQEvent::IMStart ) { + tqDebug( "sending IMStart with %d chars to %p", + text.length(), receiver ); + event = new TQIMEvent( type, text, cursorPosition ); + } else if ( type == TQEvent::IMEnd ) { + tqDebug( "sending IMEnd with %d chars to %p, text=%s", + text.length(), receiver, (const char*)text.local8Bit() ); + event = new TQIMEvent( type, text, cursorPosition ); + } else if ( type == TQEvent::IMCompose ) { + tqDebug( "sending IMCompose to %p with %d chars, cpos=%d, sellen=%d, text=%s", + receiver, text.length(), cursorPosition, selLength, + (const char*)text.local8Bit() ); + event = new TQIMComposeEvent( type, text, cursorPosition, selLength ); + } + + if ( event ) + emit imEventGenerated( receiver, event ); +} + + +/*! + Call this function to send TQIMEvent to the text widget. This + function constructs a TQIMEvent based on the arguments and send it + to the appropriate widget. Ordinary input method should not + reimplement this function. + + \a type is either \c TQEvent::IMStart or \c TQEvent::IMCompose or \c + TQEvent::IMEnd. You have to send a \c TQEvent::IMStart to start + composing, then send several \c TQEvent::IMCompose to update the + preedit of the widget, and finalize the composition with sending + \c TQEvent::IMEnd. + + \c TQEvent::IMStart should always be sent without arguments as: + \code + sendIMEvent( TQEvent::IMStart ) + \endcode + + And \c TQEvent::IMCompose can be sent without cursor: + \code + sendIMEvent( TQEvent::IMCompose, TQString( "a text" ) ) + \endcode + + Or optionally with cursor with \a cursorPosition: + \code + sendIMEvent( TQEvent::IMCompose, TQString( "a text with cursor" ), 12 ) + \endcode + Note that \a cursorPosition also specifies microfocus position. + + Or optionally with selection text: + \code + sendIMEvent( TQEvent::IMCompose, TQString( "a text with selection" ), 12, 9 ) + \endcode + \a cursorPosition and \a selLength must be within the \a text. The + \a cursorPosition also specifies microfocus position in the case: + + \c TQEvent::IMEnd can be sent without arguments to terminate the + composition with null string: + \code + sendIMEvent( TQEvent::IMEnd ) + \endcode + + Or optionally accepts \a text to commit a string: + \code + sendIMEvent( TQEvent::IMEnd, TQString( "a text" ) ) + \endcode + + \sa TQIMEvent, TQIMComposeEvent, setMicroFocus() +*/ +void TQInputContext::sendIMEvent( TQEvent::Type type, const TQString &text, + int cursorPosition, int selLength ) +{ +#if defined(TQ_WS_X11) + if ( !focusWidget() ) + return; +#endif + + if ( type == TQEvent::IMStart ) { + sendIMEventInternal( type, text, cursorPosition, selLength ); + d->isComposing = TRUE; + } else if ( type == TQEvent::IMEnd ) { + d->resetComposingState(); + sendIMEventInternal( type, text, cursorPosition, selLength ); + } else if ( type == TQEvent::IMCompose ) { + d->updateComposingState( text, cursorPosition, selLength ); + sendIMEventInternal( type, text, cursorPosition, selLength ); + } +} + + +/*! + This function can be reimplemented in a subclass to detect + that the input context has been focused on. + + The input context will receive input events through + x11FilterEvent() and filterEvent() after setFocus() until + unsetFocus() has been called. + + an input context is ensured that setFocus() is called exactly once + until unsetFocus() has been called even if preedit relocation has + occurred. This means that an input focus will survive between + several widgets that sharing the input context. + + On the X11 platform, focusWidget is already set before this + function has been called. + + \sa unsetFocus() +*/ +void TQInputContext::setFocus() +{ +} + + +/*! + This function can be reimplemented in a subclass to detect + that the input context has lost the focus. + + an input context is ensured that unsetFocus() is not called during + preedit relocation. This means that an input focus will survive + between several widgets that sharing the input context. + + Default implementation that calls reset() is sufficient for simple + input methods. You can override this function to alter the + behavior. For example, most Japanese input contexts should not be + reset on losing focus. The context sometimes contains a whole + paragraph and has minutes of lifetime different to ephemeral one + in other languages. The piled input context should be survived + until focused again since Japanese user naturally expects so. + + On the X11 platform, focusWidget is valid until this function has + been returned. + + \sa setFocus() +*/ +void TQInputContext::unsetFocus() +{ + reset(); +} + + +/*! + This function can be implemented in a subclass to handle + microfocus changes. + + 'microfocus' stands for the input method focus point in the + preedit (XIM "spot" point) for complex language input handling. It + can be used to place auxiliary GUI widgets such as candidate + selection window. + + \a x, \a y, \a w and \a h represents the position and size of the + cursor in the preedit string. \a f is the font on the location of + the cursor. +*/ +void TQInputContext::setMicroFocus( int x, int y, int w, int h, TQFont *f ) +{ + Q_UNUSED(x); + Q_UNUSED(y); + Q_UNUSED(w); + Q_UNUSED(h); + Q_UNUSED(f); +} + + +/*! + This function can be reimplemented in a subclass to handle mouse + presses/releases/doubleclicks/moves within the preedit text. You + can use the function to implement mouse-oriented user interface + such as text selection or popup menu for candidate selection. + + The parameter \a x is the offset within the string that was sent + with the IMCompose event. The alteration boundary of \a x is + ensured as character boundary of preedit string accurately. + + \a type is either \c TQEvent::MouseButtonPress or \c + TQEvent::MouseButtonRelease or \c TQEvent::MouseButtonDblClick or \c + TQEvent::MouseButtonMove. Refer \a button and \a state to determine + what operation has performed. + */ +void TQInputContext::mouseHandler( int x, TQEvent::Type type, + TQt::ButtonState button, + TQt::ButtonState state ) +{ + Q_UNUSED(x); + Q_UNUSED(button); + Q_UNUSED(state); + // Default behavior for simple ephemeral input contexts. Some + // complex input contexts should not be reset here. + if ( type == TQEvent::MouseButtonPress || + type == TQEvent::MouseButtonDblClick ) + reset(); +} + + +/*! + Returns the font of the current input widget + */ +TQFont TQInputContext::font() const +{ + if ( !focusWidget() ) + return TQApplication::font(); //### absolutely last resort + + return focusWidget()->font(); +} + + +/*! + This function can be reimplemented in a subclass to reset the + state of the input method. + + This function is called by several widgets to reset input + state. For example, a text widget call this function before + inserting a text to make widget ready to accept a text. + + Default implementation is sufficient for simple input method. You + can override this function to reset external input method engines + in complex input method. In the case, call TQInputContext::reset() + to ensure proper termination of inputting. + + You must not send any TQIMEvent except empty IMEnd event using + TQInputContext::reset() at reimplemented reset(). It will break + input state consistency. +*/ +void TQInputContext::reset() +{ + if ( isComposing() ) + sendIMEvent( TQEvent::IMEnd ); +} + + +/*! + This function must be implemented in any subclasses to return the + identifier name of the input method. + + Return value is the name to identify and specify input methods for + the input method switching mechanism and so on. The name has to be + consistent with TQInputContextPlugin::keys(). The name has to + consist of ASCII characters only. + + There are two different names with different responsibility in the + input method domain. This function returns one of them. Another + name is called 'display name' that stands for the name for + endusers appeared in a menu and so on. + + \sa TQInputContextPlugin::keys(), TQInputContextPlugin::displayName() +*/ +TQString TQInputContext::identifierName() +{ + return ""; +} + + +/*! + This function must be implemented in any subclasses to return a + language code (e.g. "zh_CN", "zh_TW", "zh_HK", "ja", "ko", ...) + of the input context. If the input context can handle multiple + languages, return the currently used one. The name has to be + consistent with TQInputContextPlugin::language(). + + This information will be used by language tagging feature in + TQIMEvent. It is required to distinguish unified han characters + correctly. It enables proper font and character code + handling. Suppose CJK-awared multilingual web browser + (that automatically modifies fonts in CJK-mixed text) and XML editor + (that automatically inserts lang attr). + + \sa TQInputContextPlugin::language() +*/ +TQString TQInputContext::language() +{ + return ""; +} + + +/*! + This function can be reimplemented in a subclass to provide input + method dependent popup menus. Return 0 if the menus are + unnecessary. + + Ownership of the object and children are transferred to the + caller, and the result must not be called + setAutoDelete(). TQInputContextMenu::title is used for label text + of the popup menu as submenu. + + \sa addMenusTo() +*/ +TQPtrList *TQInputContext::menus() +{ + return 0; +} + +/*! + Appends input method dependent submenus into \a popup. A separator + is also inserted into \a popup if \a action is InsertSeparator. + + This is an utility function only for convenience in limited + situation. This function is used by input context owner such as + text widgets to add the submenus to its own context menu. If you + want to insert the submenus in more flexible way, use + TQInputContext::menus() manually. \a popup is not restricted to + context menu of a text widget. + + \sa menus(), TQInputContextMenu::Action +*/ +void TQInputContext::addMenusTo( TQPopupMenu *popup, TQInputContextMenu::Action action ) +{ + if ( ! popup ) + return; + + TQPtrList *imMenus = menus(); + if ( imMenus ) { + if ( action == TQInputContextMenu::InsertSeparator ) + popup->insertSeparator(); + for ( TQPtrList::Iterator it = imMenus->begin(); + it != imMenus->end(); + ++it ) { + TQInputContextMenu *imMenu = *it; + popup->insertItem( imMenu->title, imMenu->popup ); + } + imMenus->clear(); + delete imMenus; + } +} + +#endif //Q_NO_IM diff --git a/src/kernel/tqinputcontext.h b/src/kernel/tqinputcontext.h new file mode 100644 index 000000000..06f72f206 --- /dev/null +++ b/src/kernel/tqinputcontext.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** $Id: tqinputcontext.h,v 1.8 2004/06/22 06:47:30 daisuke Exp $ +** +** Definition of TQInputContext +** +** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef TQINPUTCONTEXT_H +#define TQINPUTCONTEXT_H + +#ifndef TQT_NO_IM + +#ifndef QT_H +#include "tqobject.h" +#include "tqglobal.h" +#include "tqevent.h" +#include "tqstring.h" +#include "tqptrlist.h" +#endif + +class TQWidget; +class TQFont; +class TQPopupMenu; +class TQInputContextPrivate; + + +struct TQInputContextMenu { + enum Action { + NoSeparator, + InsertSeparator + }; + TQString title; + TQPopupMenu *popup; +}; + + +class TQ_EXPORT TQInputContext : public TQObject +{ + TQ_OBJECT +public: + TQInputContext( TQObject *parent = 0 ); + virtual ~TQInputContext(); + + virtual TQString identifierName(); + virtual TQString language(); + +#if defined(TQ_WS_X11) + virtual bool x11FilterEvent( TQWidget *keywidget, XEvent *event ); +#endif // TQ_WS_X11 + virtual bool filterEvent( const TQEvent *event ); + virtual void reset(); + + virtual void setFocus(); + virtual void unsetFocus(); + virtual void setMicroFocus( int x, int y, int w, int h, TQFont *f = 0 ); + virtual void mouseHandler( int x, TQEvent::Type type, + TQt::ButtonState button, TQt::ButtonState state ); + virtual TQFont font() const; + virtual bool isComposing() const; + virtual bool isPreeditRelocationEnabled(); + + virtual TQPtrList *menus(); + void addMenusTo( TQPopupMenu *popup, TQInputContextMenu::Action action = TQInputContextMenu::InsertSeparator ); + +#if defined(TQ_WS_X11) + // these functions are not recommended for ordinary use + virtual TQWidget *focusWidget() const; + virtual TQWidget *holderWidget() const; + + // these functions must not be used by ordinary input method + virtual void setFocusWidget( TQWidget *w ); + virtual void setHolderWidget( TQWidget *w ); + virtual void releaseComposingWidget( TQWidget *w ); +#endif + +signals: + void deletionRequested(); + void imEventGenerated( TQObject *receiver, TQIMEvent *e ); + +protected: + virtual void sendIMEvent( TQEvent::Type type, + const TQString &text = TQString::null, + int cursorPosition = -1, int selLength = 0 ); + +private: + void sendIMEventInternal( TQEvent::Type type, + const TQString &text = TQString::null, + int cursorPosition = -1, int selLength = 0 ); + + TQInputContextPrivate *d; + + friend class TQWidget; + friend class TQInputContextFactory; + +private: // Disabled copy constructor and operator= + TQInputContext( const TQInputContext & ); + TQInputContext &operator=( const TQInputContext & ); + +}; + +#endif //Q_NO_IM + +#endif // TQINPUTCONTEXT_H diff --git a/src/kernel/tqinputcontext_p.h b/src/kernel/tqinputcontext_p.h new file mode 100644 index 000000000..37ba52b6c --- /dev/null +++ b/src/kernel/tqinputcontext_p.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Definition of ??? +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQINPUTCONTEXT_P_H +#define TQINPUTCONTEXT_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of internal files. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// +// + +#include "tqglobal.h" + +class TQKeyEvent; +class TQWidget; +class TQFont; +class TQString; + + +#ifdef TQ_WS_X11 +#include "tqmemarray.h" +#include "ntqwindowdefs.h" +#include "qt_x11_p.h" +#endif + +#ifdef TQ_WS_WIN +#include "qt_windows.h" +#endif + +class TQInputContext +{ +public: +#ifdef TQ_WS_X11 + TQInputContext(TQWidget *); // should be a toplevel widget + ~TQInputContext(); + + void setFocus(); + void setComposePosition(int, int); + void setComposeArea(int, int, int, int); + void reset(); + + int lookupString(XKeyEvent *, TQCString &, KeySym *, Status *) const; + void setXFontSet(const TQFont &); + + void *ic; + TQString text; + TQWidget *focusWidget; + bool composing; + TQFont font; + XFontSet fontset; + TQMemArray selectedChars; +#endif // TQ_WS_X11 + +#ifdef TQ_WS_WIN + static void init(); + static void shutdown(); + + static void TranslateMessage( const MSG *msg); + static LRESULT DefWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ); + + static void setFont( const TQWidget *w, const TQFont & ); + static void setFocusHint( int x, int y, int w, int h, const TQWidget *widget ); + static bool startComposition(); + static bool endComposition( TQWidget *fw = 0 ); + static bool composition( LPARAM lparam ); + + static void accept( TQWidget *fw = 0 ); + static void enable( TQWidget *w, bool b ); +#endif +}; + +#endif // TQINPUTCONTEXT_P_H diff --git a/src/kernel/tqinputcontext_x11.cpp b/src/kernel/tqinputcontext_x11.cpp new file mode 100644 index 000000000..d0f8699b3 --- /dev/null +++ b/src/kernel/tqinputcontext_x11.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Implementation of TQInputContext class +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 "tqinputcontext.h" + +#ifndef TQT_NO_IM + +#include "qplatformdefs.h" + +#include "ntqapplication.h" +#include "tqwidget.h" + +#include "qt_x11_p.h" + +/*! + This function may be overridden only if input method is depending + on X11 and you need raw XEvent. Otherwise, this function must not. + + This function is designed to filter raw key events for XIM, but + other input methods may use this to implement some special + features such as distinguishing Shift_L and Shift_R. + + Return TRUE if the \a event has been consumed. Otherwise, the + unfiltered \a event will be translated into TQEvent and forwarded + to filterEvent(). Filtering at both x11FilterEvent() and + filterEvent() in single input method is allowed. + + \a keywidget is a client widget into which a text is inputted. \a + event is inputted XEvent. + + \sa filterEvent() +*/ +bool TQInputContext::x11FilterEvent( TQWidget *keywidget, XEvent *event ) +{ + Q_UNUSED(keywidget); + Q_UNUSED(event); + return FALSE; +} + +#endif //Q_NO_IM diff --git a/src/kernel/tqjpegio.cpp b/src/kernel/tqjpegio.cpp new file mode 100644 index 000000000..f76aad44d --- /dev/null +++ b/src/kernel/tqjpegio.cpp @@ -0,0 +1,595 @@ +/**************************************************************************** +** +** Implementation of JPEG TQImage IOHandler +** +** Created : 990521 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 "tqimage.h" + +#ifndef TQT_NO_IMAGEIO_JPEG + +#include "tqiodevice.h" +#include "tqjpegio.h" + +#include // jpeglib needs this to be pre-included +#include + + +// including jpeglib.h seems to be a little messy +extern "C" { +#define XMD_H // shut JPEGlib up +#if defined(Q_OS_UNIXWARE) +# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this +#endif +#include +#ifdef const +# undef const // remove crazy C hackery in jconfig.h +#endif +} + + +struct my_error_mgr : public jpeg_error_mgr { + jmp_buf setjmp_buffer; +}; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static +void my_error_exit (j_common_ptr cinfo) +{ + my_error_mgr* myerr = (my_error_mgr*) cinfo->err; + char buffer[JMSG_LENGTH_MAX]; + (*cinfo->err->format_message)(cinfo, buffer); + tqWarning("%s", buffer); + longjmp(myerr->setjmp_buffer, 1); +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +static const int max_buf = 4096; + +struct my_jpeg_source_mgr : public jpeg_source_mgr { + // Nothing dynamic - cannot rely on destruction over longjump + TQImageIO* iio; + JOCTET buffer[max_buf]; + +public: + my_jpeg_source_mgr(TQImageIO* iio); +}; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static +void tqt_init_source(j_decompress_ptr) +{ +} + +static +boolean qt_fill_input_buffer(j_decompress_ptr cinfo) +{ + int num_read; + my_jpeg_source_mgr* src = (my_jpeg_source_mgr*)cinfo->src; + TQIODevice* dev = src->iio->ioDevice(); + src->next_input_byte = src->buffer; + num_read = dev->readBlock((char*)src->buffer, max_buf); + if ( num_read <= 0 ) { + // Insert a fake EOI marker - as per jpeglib recommendation + src->buffer[0] = (JOCTET) 0xFF; + src->buffer[1] = (JOCTET) JPEG_EOI; + src->bytes_in_buffer = 2; + } else { + src->bytes_in_buffer = num_read; + } +#if defined(Q_OS_UNIXWARE) + return B_TRUE; +#else + return TRUE; +#endif +} + +static +void qt_skip_input_data(j_decompress_ptr cinfo, long num_bytes) +{ + my_jpeg_source_mgr* src = (my_jpeg_source_mgr*)cinfo->src; + + // `dumb' implementation from jpeglib + + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if (num_bytes > 0) { + while (num_bytes > (long) src->bytes_in_buffer) { + num_bytes -= (long) src->bytes_in_buffer; + (void) qt_fill_input_buffer(cinfo); + /* note we assume that qt_fill_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->next_input_byte += (size_t) num_bytes; + src->bytes_in_buffer -= (size_t) num_bytes; + } +} + +static +void qt_term_source(j_decompress_ptr) +{ +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +inline my_jpeg_source_mgr::my_jpeg_source_mgr(TQImageIO* iioptr) +{ + jpeg_source_mgr::init_source = tqt_init_source; + jpeg_source_mgr::fill_input_buffer = qt_fill_input_buffer; + jpeg_source_mgr::skip_input_data = qt_skip_input_data; + jpeg_source_mgr::resync_to_restart = jpeg_resync_to_restart; + jpeg_source_mgr::term_source = qt_term_source; + iio = iioptr; + bytes_in_buffer = 0; + next_input_byte = buffer; +} + + +static +void scaleSize( int &reqW, int &reqH, int imgW, int imgH, TQImage::ScaleMode mode ) +{ + if ( mode == TQImage::ScaleFree ) + return; + int t1 = imgW * reqH; + int t2 = reqW * imgH; + if (( mode == TQImage::ScaleMin && (t1 > t2) ) || ( mode == TQImage::ScaleMax && (t1 < t2) )) + reqH = t2 / imgW; + else + reqW = t1 / imgH; +} + + +static +void read_jpeg_image(TQImageIO* iio) +{ + TQImage image; + + struct jpeg_decompress_struct cinfo; + + struct my_jpeg_source_mgr *iod_src = new my_jpeg_source_mgr(iio); + struct my_error_mgr jerr; + + cinfo.err = jpeg_std_error(&jerr); + jerr.error_exit = my_error_exit; + + jpeg_create_decompress(&cinfo); + + cinfo.src = iod_src; + + if (!setjmp(jerr.setjmp_buffer)) { +#if defined(Q_OS_UNIXWARE) + (void) jpeg_read_header(&cinfo, B_TRUE); +#else + (void) jpeg_read_header(&cinfo, TRUE); +#endif + + (void) jpeg_start_decompress(&cinfo); + + TQString params = iio->parameters(); + params.simplifyWhiteSpace(); + int sWidth = 0, sHeight = 0; + char sModeStr[1024] = ""; + TQImage::ScaleMode sMode; + + if ( params.contains( "GetHeaderInformation" ) ) { + + // Create TQImage's without allocating the data + if ( cinfo.output_components == 3 || cinfo.output_components == 4) { + image = TQImage( NULL, cinfo.output_width, cinfo.output_height, 32, NULL, 0, TQImage::IgnoreEndian ); + } else if ( cinfo.output_components == 1 ) { + image = TQImage( NULL, cinfo.output_width, cinfo.output_height, 8, NULL, 0, TQImage::IgnoreEndian ); + } else { + // Unsupported format + } + + + } else if ( params.contains( "Scale" ) ) { + sscanf( params.latin1(), "Scale( %i, %i, %1023s )", + &sWidth, &sHeight, sModeStr ); + + TQString sModeTQStr( sModeStr ); + if ( sModeTQStr == "ScaleFree" ) { + sMode = TQImage::ScaleFree; + } else if ( sModeTQStr == "ScaleMin" ) { + sMode = TQImage::ScaleMin; + } else if ( sModeTQStr == "ScaleMax" ) { + sMode = TQImage::ScaleMax; + } else { + tqDebug("read_jpeg_image: invalid scale mode \"%s\", see TQImage::ScaleMode documentation", sModeStr); + sMode = TQImage::ScaleFree; + } + +// tqDebug( "Parameters ask to scale the image to %i x %i ScaleMode: %s", sWidth, sHeight, sModeStr ); + scaleSize( sWidth, sHeight, cinfo.output_width, cinfo.output_height, sMode ); +// tqDebug( "Scaling the jpeg to %i x %i", sWidth, sHeight, sModeStr ); + + bool created = FALSE; + if ( cinfo.output_components == 3 || cinfo.output_components == 4) { + created = image.create( sWidth, sHeight, 32 ); + } else if ( cinfo.output_components == 1 ) { + created = image.create( sWidth, sHeight, 8, 256 ); + for (int i=0; i<256; i++) + image.setColor(i, tqRgb(i,i,i)); + } else { + // Unsupported format + } + if (!created) + image = TQImage(); + + if (!image.isNull()) { + TQImage tmpImage( cinfo.output_width, 1, 32 ); + uchar** inLines = tmpImage.jumpTable(); + uchar** outLines = image.jumpTable(); + while (cinfo.output_scanline < cinfo.output_height) { + int outputLine = sHeight * cinfo.output_scanline / cinfo.output_height; + (void) jpeg_read_scanlines(&cinfo, inLines, 1); + if ( cinfo.output_components == 3 ) { + uchar *in = inLines[0]; + TQRgb *out = (TQRgb*)outLines[outputLine]; + for (uint i=0; i32 bpp. + for (uint j=0; jsetImage(image); + iio->setStatus(image.isNull()); + } + + jpeg_destroy_decompress(&cinfo); + delete iod_src; +} + + +struct my_jpeg_destination_mgr : public jpeg_destination_mgr { + // Nothing dynamic - cannot rely on destruction over longjump + TQImageIO* iio; + JOCTET buffer[max_buf]; + +public: + my_jpeg_destination_mgr(TQImageIO*); +}; + + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static +void tqt_init_destination(j_compress_ptr) +{ +} + +static +void qt_exit_on_error(j_compress_ptr cinfo, TQIODevice* dev) +{ + if (dev->status() == IO_Ok) { + return; + } else { + // cinfo->err->msg_code = JERR_FILE_WRITE; + (*cinfo->err->error_exit)((j_common_ptr)cinfo); + } +} + +static +boolean qt_empty_output_buffer(j_compress_ptr cinfo) +{ + my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest; + TQIODevice* dev = dest->iio->ioDevice(); + + if ( dev->writeBlock( (char*)dest->buffer, max_buf ) != max_buf ) + qt_exit_on_error(cinfo, dev); + + dest->next_output_byte = dest->buffer; + dest->free_in_buffer = max_buf; + +#if defined(Q_OS_UNIXWARE) + return B_TRUE; +#else + return TRUE; +#endif +} + +static +void qt_term_destination(j_compress_ptr cinfo) +{ + my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest; + TQIODevice* dev = dest->iio->ioDevice(); + TQ_LONG n = max_buf - dest->free_in_buffer; + + if ( dev->writeBlock( (char*)dest->buffer, n ) != n ) + qt_exit_on_error(cinfo, dev); + + dev->flush(); + + qt_exit_on_error(cinfo, dev); +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +inline +my_jpeg_destination_mgr::my_jpeg_destination_mgr(TQImageIO* iioptr) +{ + jpeg_destination_mgr::init_destination = tqt_init_destination; + jpeg_destination_mgr::empty_output_buffer = qt_empty_output_buffer; + jpeg_destination_mgr::term_destination = qt_term_destination; + iio = iioptr; + next_output_byte = buffer; + free_in_buffer = max_buf; +} + + +static +void write_jpeg_image(TQImageIO* iio) +{ + TQImage image = iio->image(); + + struct jpeg_compress_struct cinfo; + JSAMPROW row_pointer[1]; + row_pointer[0] = 0; + + struct my_jpeg_destination_mgr *iod_dest = new my_jpeg_destination_mgr(iio); + struct my_error_mgr jerr; + + cinfo.err = jpeg_std_error(&jerr); + + jerr.error_exit = my_error_exit; + + if (!setjmp(jerr.setjmp_buffer)) { + jpeg_create_compress(&cinfo); + + cinfo.dest = iod_dest; + + cinfo.image_width = image.width(); + cinfo.image_height = image.height(); + + TQRgb* cmap=0; + bool gray=FALSE; + switch ( image.depth() ) { + case 1: + case 8: + cmap = image.colorTable(); + gray = TRUE; + int i; + for (i=image.numColors(); gray && i--; ) { + gray = gray & ( tqRed(cmap[i]) == tqGreen(cmap[i]) && + tqRed(cmap[i]) == tqBlue(cmap[i]) ); + } + cinfo.input_components = gray ? 1 : 3; + cinfo.in_color_space = gray ? JCS_GRAYSCALE : JCS_RGB; + break; + case 32: + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + } + + jpeg_set_defaults(&cinfo); + + float diffInch = TQABS(image.dotsPerMeterX()*2.54/100. - tqRound(image.dotsPerMeterX()*2.54/100.)) + + TQABS(image.dotsPerMeterY()*2.54/100. - tqRound(image.dotsPerMeterY()*2.54/100.)); + float diffCm = (TQABS(image.dotsPerMeterX()/100. - tqRound(image.dotsPerMeterX()/100.)) + + TQABS(image.dotsPerMeterY()/100. - tqRound(image.dotsPerMeterY()/100.)))*2.54; + if (diffInch < diffCm) { + cinfo.density_unit = 1; // dots/inch + cinfo.X_density = tqRound(image.dotsPerMeterX()*2.54/100.); + cinfo.Y_density = tqRound(image.dotsPerMeterY()*2.54/100.); + } else { + cinfo.density_unit = 2; // dots/cm + cinfo.X_density = (image.dotsPerMeterX()+50) / 100; + cinfo.Y_density = (image.dotsPerMeterY()+50) / 100; + } + + int quality = iio->quality() >= 0 ? TQMIN(iio->quality(),100) : 75; +#if defined(Q_OS_UNIXWARE) + jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */); + jpeg_start_compress(&cinfo, B_TRUE); +#else + jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); + jpeg_start_compress(&cinfo, TRUE); +#endif + + row_pointer[0] = new uchar[cinfo.image_width*cinfo.input_components]; + int w = cinfo.image_width; + while (cinfo.next_scanline < cinfo.image_height) { + uchar *row = row_pointer[0]; + switch ( image.depth() ) { + case 1: + if (gray) { + uchar* data = image.scanLine(cinfo.next_scanline); + if ( image.bitOrder() == TQImage::LittleEndian ) { + for (int i=0; i> 3)) & (1 << (i & 7))); + row[i] = tqRed(cmap[bit]); + } + } else { + for (int i=0; i> 3)) & (1 << (7 -(i & 7)))); + row[i] = tqRed(cmap[bit]); + } + } + } else { + uchar* data = image.scanLine(cinfo.next_scanline); + if ( image.bitOrder() == TQImage::LittleEndian ) { + for (int i=0; i> 3)) & (1 << (i & 7))); + *row++ = tqRed(cmap[bit]); + *row++ = tqGreen(cmap[bit]); + *row++ = tqBlue(cmap[bit]); + } + } else { + for (int i=0; i> 3)) & (1 << (7 -(i & 7)))); + *row++ = tqRed(cmap[bit]); + *row++ = tqGreen(cmap[bit]); + *row++ = tqBlue(cmap[bit]); + } + } + } + break; + case 8: + if (gray) { + uchar* pix = image.scanLine(cinfo.next_scanline); + for (int i=0; isetStatus(0); + } + + delete iod_dest; + delete [] row_pointer[0]; +} + +void qInitJpegIO() +{ + // Not much to go on - just 3 bytes: 0xFF, M_SOI, 0xFF + // Even the third is not strictly specified as required. + TQImageIO::defineIOHandler("JPEG", "^\377\330\377", 0, read_jpeg_image, write_jpeg_image); +} + +#endif diff --git a/src/kernel/tqjpegio.h b/src/kernel/tqjpegio.h new file mode 100644 index 000000000..10ae8d7cf --- /dev/null +++ b/src/kernel/tqjpegio.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Definition of JPEG TQImage IOHandler +** +** Created : 970621 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQJPEGIO_H +#define TQJPEGIO_H + +#include "tqglobal.h" + +#ifndef TQT_NO_IMAGEIO_JPEG + +void qInitJpegIO(); + +#endif // TQT_NO_IMAGEIO_JPEG + +#endif // TQJPEGIO_H diff --git a/src/kernel/tqkeycode.h b/src/kernel/tqkeycode.h new file mode 100644 index 000000000..bca9305ba --- /dev/null +++ b/src/kernel/tqkeycode.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Definition of keyboard codes +** +** Created : 931030 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQKEYCODE_H +#define TQKEYCODE_H + +#ifndef QT_H +#include "ntqnamespace.h" +#endif // QT_H + +// all key codes are now in the TQt namespace class + +#endif // TQKEYCODE_H diff --git a/src/kernel/tqkeysequence.cpp b/src/kernel/tqkeysequence.cpp new file mode 100644 index 000000000..94ba5cf53 --- /dev/null +++ b/src/kernel/tqkeysequence.cpp @@ -0,0 +1,736 @@ +/**************************************************************************** +** +** Implementation of TQKeySequence class +** +** Created : 0108007 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 "tqkeysequence.h" + +#ifndef TQT_NO_ACCEL + +#include "tqaccel.h" +#include "ntqshared.h" +#include "tqvaluelist.h" +#ifndef TQT_NO_REGEXP +# include "tqregexp.h" +#endif + +#ifdef TQ_WS_MAC +#define TQMAC_CTRL (TQString(TQChar(0x2318))) +#define TQMAC_META (TQString(TQChar(0x2303))) +#define TQMAC_ALT (TQString(TQChar(0x2325))) +#define TQMAC_SHIFT (TQString(TQChar(0x21E7))) +#endif + +/*! + \class TQKeySequence tqkeysequence.h + \brief The TQKeySequence class encapsulates a key sequence as used + by accelerators. + + \ingroup misc + + A key sequence consists of up to four keyboard codes, each + optionally combined with modifiers, e.g. \c SHIFT, \c CTRL, \c + ALT, \c META, or \c UNICODE_ACCEL. For example, \c{CTRL + Key_P} + might be a sequence used as a shortcut for printing a document. + The key codes are listed in \c{ntqnamespace.h}. As an alternative, + use \c UNICODE_ACCEL with the unicode code point of the character. + For example, \c{UNICODE_ACCEL + 'A'} gives the same key sequence + as \c Key_A. + + Key sequences can be constructed either from an integer key code, + or from a human readable translatable string such as + "Ctrl+X,Alt+Space". A key sequence can be cast to a TQString to + obtain a human readable translated version of the sequence. + Translations are done in the "TQAccel" context. + + \sa TQAccel +*/ + +/*! + \enum TQt::SequenceMatch + + \value NoMatch Sequences have nothing in common + \value PartialMatch Sequences match partially, but are not complete + \value Identical Sequences do not differ +*/ + +static struct { + int key; + const char* name; +} keyname[] = { + { TQt::Key_Space, TQT_TRANSLATE_NOOP( "TQAccel", "Space" ) }, + { TQt::Key_Escape, TQT_TRANSLATE_NOOP( "TQAccel", "Esc" ) }, + { TQt::Key_Tab, TQT_TRANSLATE_NOOP( "TQAccel", "Tab" ) }, + { TQt::Key_Backtab, TQT_TRANSLATE_NOOP( "TQAccel", "Backtab" ) }, + { TQt::Key_Backspace, TQT_TRANSLATE_NOOP( "TQAccel", "Backspace" ) }, + { TQt::Key_Return, TQT_TRANSLATE_NOOP( "TQAccel", "Return" ) }, + { TQt::Key_Enter, TQT_TRANSLATE_NOOP( "TQAccel", "Enter" ) }, + { TQt::Key_Insert, TQT_TRANSLATE_NOOP( "TQAccel", "Ins" ) }, + { TQt::Key_Delete, TQT_TRANSLATE_NOOP( "TQAccel", "Del" ) }, + { TQt::Key_Pause, TQT_TRANSLATE_NOOP( "TQAccel", "Pause" ) }, + { TQt::Key_Print, TQT_TRANSLATE_NOOP( "TQAccel", "Print" ) }, + { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( "TQAccel", "SysReq" ) }, + { TQt::Key_Home, TQT_TRANSLATE_NOOP( "TQAccel", "Home" ) }, + { TQt::Key_End, TQT_TRANSLATE_NOOP( "TQAccel", "End" ) }, + { TQt::Key_Left, TQT_TRANSLATE_NOOP( "TQAccel", "Left" ) }, + { TQt::Key_Up, TQT_TRANSLATE_NOOP( "TQAccel", "Up" ) }, + { TQt::Key_Right, TQT_TRANSLATE_NOOP( "TQAccel", "Right" ) }, + { TQt::Key_Down, TQT_TRANSLATE_NOOP( "TQAccel", "Down" ) }, + { TQt::Key_Prior, TQT_TRANSLATE_NOOP( "TQAccel", "PgUp" ) }, + { TQt::Key_Next, TQT_TRANSLATE_NOOP( "TQAccel", "PgDown" ) }, + { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( "TQAccel", "CapsLock" ) }, + { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "NumLock" ) }, + { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( "TQAccel", "ScrollLock" ) }, + { TQt::Key_Menu, TQT_TRANSLATE_NOOP( "TQAccel", "Menu" ) }, + { TQt::Key_Help, TQT_TRANSLATE_NOOP( "TQAccel", "Help" ) }, + + // Multimedia keys + { TQt::Key_Back, TQT_TRANSLATE_NOOP( "TQAccel", "Back" ) }, + { TQt::Key_Forward, TQT_TRANSLATE_NOOP( "TQAccel", "Forward" ) }, + { TQt::Key_Stop, TQT_TRANSLATE_NOOP( "TQAccel", "Stop" ) }, + { TQt::Key_Refresh, TQT_TRANSLATE_NOOP( "TQAccel", "Refresh" ) }, + { TQt::Key_VolumeDown, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Down" ) }, + { TQt::Key_VolumeMute, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Mute" ) }, + { TQt::Key_VolumeUp, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Up" ) }, + { TQt::Key_BassBoost, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Boost" ) }, + { TQt::Key_BassUp, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Up" ) }, + { TQt::Key_BassDown, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Down" ) }, + { TQt::Key_TrebleUp, TQT_TRANSLATE_NOOP( "TQAccel", "Treble Up" ) }, + { TQt::Key_TrebleDown, TQT_TRANSLATE_NOOP( "TQAccel", "Treble Down" ) }, + { TQt::Key_MediaPlay, TQT_TRANSLATE_NOOP( "TQAccel", "Media Play" ) }, + { TQt::Key_MediaStop, TQT_TRANSLATE_NOOP( "TQAccel", "Media Stop" ) }, + { TQt::Key_MediaPrev, TQT_TRANSLATE_NOOP( "TQAccel", "Media Previous" ) }, + { TQt::Key_MediaNext, TQT_TRANSLATE_NOOP( "TQAccel", "Media Next" ) }, + { TQt::Key_MediaRecord, TQT_TRANSLATE_NOOP( "TQAccel", "Media Record" ) }, + { TQt::Key_HomePage, TQT_TRANSLATE_NOOP( "TQAccel", "Home" ) }, + { TQt::Key_Favorites, TQT_TRANSLATE_NOOP( "TQAccel", "Favorites" ) }, + { TQt::Key_Search, TQT_TRANSLATE_NOOP( "TQAccel", "Search" ) }, + { TQt::Key_Standby, TQT_TRANSLATE_NOOP( "TQAccel", "Standby" ) }, + { TQt::Key_OpenUrl, TQT_TRANSLATE_NOOP( "TQAccel", "Open URL" ) }, + { TQt::Key_LaunchMail, TQT_TRANSLATE_NOOP( "TQAccel", "Launch Mail" ) }, + { TQt::Key_LaunchMedia, TQT_TRANSLATE_NOOP( "TQAccel", "Launch Media" ) }, + { TQt::Key_Launch0, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (0)" ) }, + { TQt::Key_Launch1, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (1)" ) }, + { TQt::Key_Launch2, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (2)" ) }, + { TQt::Key_Launch3, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (3)" ) }, + { TQt::Key_Launch4, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (4)" ) }, + { TQt::Key_Launch5, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (5)" ) }, + { TQt::Key_Launch6, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (6)" ) }, + { TQt::Key_Launch7, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (7)" ) }, + { TQt::Key_Launch8, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (8)" ) }, + { TQt::Key_Launch9, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (9)" ) }, + { TQt::Key_LaunchA, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (A)" ) }, + { TQt::Key_LaunchB, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (B)" ) }, + { TQt::Key_LaunchC, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (C)" ) }, + { TQt::Key_LaunchD, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (D)" ) }, + { TQt::Key_LaunchE, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (E)" ) }, + { TQt::Key_LaunchF, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (F)" ) }, + { TQt::Key_MonBrightnessUp, TQT_TRANSLATE_NOOP( "TQAccel", "Monitor Brightness Up" ) }, + { TQt::Key_MonBrightnessDown, TQT_TRANSLATE_NOOP( "TQAccel", "Monitor Brightness Down" ) }, + { TQt::Key_KeyboardLightOnOff, TQT_TRANSLATE_NOOP( "TQAccel", "Keyboard Light On Off" ) }, + { TQt::Key_KeyboardBrightnessUp, TQT_TRANSLATE_NOOP( "TQAccel", "Keyboard Brightness Up" ) }, + { TQt::Key_KeyboardBrightnessDown, TQT_TRANSLATE_NOOP( "TQAccel", "Keyboard Brightness Down" ) }, + + // -------------------------------------------------------------- + // More consistent namings + { TQt::Key_Print, TQT_TRANSLATE_NOOP( "TQAccel", "Print Screen" ) }, + { TQt::Key_Prior, TQT_TRANSLATE_NOOP( "TQAccel", "Page Up" ) }, + { TQt::Key_Next, TQT_TRANSLATE_NOOP( "TQAccel", "Page Down" ) }, + { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( "TQAccel", "Caps Lock" ) }, + { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "Num Lock" ) }, + { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "Number Lock" ) }, + { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( "TQAccel", "Scroll Lock" ) }, + { TQt::Key_Insert, TQT_TRANSLATE_NOOP( "TQAccel", "Insert" ) }, + { TQt::Key_Delete, TQT_TRANSLATE_NOOP( "TQAccel", "Delete" ) }, + { TQt::Key_Escape, TQT_TRANSLATE_NOOP( "TQAccel", "Escape" ) }, + { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( "TQAccel", "System Request" ) }, + + { 0, 0 } +}; + + +class TQKeySequencePrivate : public TQShared +{ +public: + inline TQKeySequencePrivate() + { + key[0] = key[1] = key[2] = key[3] = 0; + } + inline TQKeySequencePrivate( TQKeySequencePrivate *copy ) + { + key[0] = copy->key[0]; + key[1] = copy->key[1]; + key[2] = copy->key[2]; + key[3] = copy->key[3]; + } + int key[4]; +}; + + +/*! + Constructs an empty key sequence. +*/ +TQKeySequence::TQKeySequence() +{ + d = new TQKeySequencePrivate(); + TQ_CHECK_PTR( d ); +} + +/*! + Creates a key sequence from the string \a key. For example + "Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl", + "Shift", "Alt" and "Meta" are recognized, as well as their + translated equivalents in the "TQAccel" context (using + TQObject::tr()). + + Multiple key codes (up to four) may be entered by separating them + with commas, e.g. "Alt+X,Ctrl+S,Q". + + This contructor is typically used with \link TQObject::tr() tr + \endlink(), so that accelerator keys can be replaced in + translations: + + \code + TQPopupMenu *file = new TQPopupMenu( this ); + file->insertItem( tr("&Open..."), this, TQ_SLOT(open()), + TQKeySequence( tr("Ctrl+O", "File|Open") ) ); + \endcode + + Note the \c "File|Open" translator comment. It is by no means + necessary, but it provides some context for the human translator. +*/ +TQKeySequence::TQKeySequence( const TQString& key ) +{ + d = new TQKeySequencePrivate(); + TQ_CHECK_PTR( d ); + assign( key ); +} + + +// ### BCI: Merge with constructor below for 4.0 +/*! + Constructs a key sequence that has a single \a key. + + The key codes are listed in \c{ntqnamespace.h} and can be + combined with modifiers, e.g. with \c SHIFT, \c CTRL, \c + ALT, \c META or \c UNICODE_ACCEL. +*/ +TQKeySequence::TQKeySequence( int key ) +{ + d = new TQKeySequencePrivate(); + TQ_CHECK_PTR( d ); + d->key[0] = key; +} + +/*! + Constructs a key sequence with up to 4 keys \a k1, \a k2, + \a k3 and \a k4. + + The key codes are listed in \c{ntqnamespace.h} and can be + combined with modifiers, e.g. with \c SHIFT, \c CTRL, \c + ALT, \c META or \c UNICODE_ACCEL. +*/ +TQKeySequence::TQKeySequence( int k1, int k2, int k3, int k4 ) +{ + d = new TQKeySequencePrivate(); + TQ_CHECK_PTR( d ); + d->key[0] = k1; + d->key[1] = k2; + d->key[2] = k3; + d->key[3] = k4; +} + +/*! + Copy constructor. Makes a copy of \a keysequence. + */ +TQKeySequence::TQKeySequence( const TQKeySequence& keysequence ) + : d( keysequence.d ) +{ + d->ref(); +} + + +/*! + Destroys the key sequence. + */ +TQKeySequence::~TQKeySequence() +{ + if ( d->deref() ) + delete d; +} + +/*! + \internal + KeySequences should never be modified, but rather just created. + Internally though we do need to modify to keep pace in event + delivery. +*/ + +void TQKeySequence::setKey( int key, int index ) +{ +#ifdef QT_CHECK_STATE + if ( 0 > index && 4 < index ) { + tqWarning( "TQKeySequence::setKey: index %u out of range", index ); + return; + } +#endif // QT_CHECK_STATE + + if ( 1 < d->count ) { + TQKeySequencePrivate *newd = new TQKeySequencePrivate( d ); + d->deref(); + d = newd; + } + d->key[index] = key; +} + +/*! + Returns the number of keys in the key sequence. + The maximum is 4. + */ +uint TQKeySequence::count() const +{ + if ( ! d->key[0] ) + return 0; + if ( ! d->key[1] ) + return 1; + if ( ! d->key[2] ) + return 2; + if ( ! d->key[3] ) + return 3; + return 4; +} + + +/*! + Returns TRUE if the key sequence is empty; otherwise returns + FALSE. +*/ +bool TQKeySequence::isEmpty() const +{ + return !d->key[0]; +} + + +/*! + Adds the string \a keyseq to the key sequence. \a keyseq may + contain up to four key codes, provided they are seperated by a + comma, e.g. "Alt+X,Ctrl+S,Z"). Returns the number of key codes + added. +*/ +int TQKeySequence::assign( TQString keyseq ) +{ + TQString part; + int n = 0; + int p = 0, diff = 0; + + // Run through the whole string, but stop + // if we have 4 keys before the end. + while ( keyseq.length() && n < 4 ) { + // We MUST use something to seperate each sequence, and space + // does not cut it, since some of the key names have space + // in them.. (Let's hope no one translate with a comma in it:) + p = keyseq.find( ',' ); + if ( -1 != p ) { + if ( ',' == keyseq[p+1] ) // e.g. 'Ctrl+,, Shift+,,' + p++; + if ( ' ' == keyseq[p+1] ) { // Space after comma + diff = 1; + p++; + } else if ( '\0' == keyseq[p+1] ) { // Last comma 'Ctrl+,' + p = -1; + } else { + diff = 0; + } + } + part = keyseq.left( -1==p?keyseq.length():p-diff ); + keyseq = keyseq.right( -1==p?0:keyseq.length() - ( p + 1 ) ); + d->key[n] = decodeString( part ); + n++; + } + return n; +} + +struct ModifKeyName { + ModifKeyName() { } + ModifKeyName(int q, TQString n) : qt_key(q), name(n) { } + int qt_key; + TQString name; +}; + +/*! + Constructs a single key from the string \str. + */ +int TQKeySequence::decodeString( const TQString& str ) +{ + int ret = 0; + TQString accel = str; + + TQValueList modifs; +#ifdef TQMAC_CTRL + modifs << ModifKeyName( CTRL, TQMAC_CTRL ); +#endif +#ifdef TQMAC_ALT + modifs << ModifKeyName( ALT, TQMAC_ALT ); +#endif +#ifdef TQMAC_META + modifs << ModifKeyName( META, TQMAC_META ); +#endif +#ifdef TQMAC_SHIFT + modifs << ModifKeyName( SHIFT, TQMAC_SHIFT ); +#endif + modifs << ModifKeyName( CTRL, "ctrl+" ) << ModifKeyName( CTRL, TQAccel::tr("Ctrl").lower().append('+') ); + modifs << ModifKeyName( SHIFT, "shift+" ) << ModifKeyName( SHIFT, TQAccel::tr("Shift").lower().append('+') ); + modifs << ModifKeyName( ALT, "alt+" ) << ModifKeyName( ALT, TQAccel::tr("Alt").lower().append('+') ); + modifs << ModifKeyName( META, "meta+" ) << ModifKeyName( ALT, TQAccel::tr("Meta").lower().append('+') ); + TQString sl = accel.lower(); + for( TQValueList::iterator it = modifs.begin(); it != modifs.end(); ++it ) { + if ( sl.contains( (*it).name ) ) { + ret |= (*it).qt_key; +#ifndef TQT_NO_REGEXP + accel.remove( TQRegExp(TQRegExp::escape((*it).name), FALSE) ); +#else + accel.remove( (*it).name ); +#endif + sl = accel.lower(); + } + } + + int p = accel.findRev( '+', str.length() - 2 ); // -2 so that Ctrl++ works + if( p > 0 ) + accel = accel.mid( p + 1 ); + + int fnum = 0; + if ( accel.length() == 1 ) { + char ltr = accel[0].upper().latin1(); + // We can only upper A-Z without problems. + if ( ltr < (char)Key_A || ltr > (char)Key_Z ) + ret |= accel[0].unicode(); + else + ret |= accel[0].upper().unicode(); + ret |= UNICODE_ACCEL; + } else if ( accel[0] == 'F' && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35) ) { + ret |= Key_F1 + fnum - 1; + } else { + // Check through translation table for the correct key name + // ...or fall back on english table. + bool found = FALSE; + for ( int tran = 0; tran < 2; tran++ ) { + for ( int i = 0; keyname[i].name; i++ ) { + if ( tran ? accel == TQAccel::tr(keyname[i].name) + : accel == keyname[i].name ) { + ret |= keyname[i].key; + found = TRUE; + break; + } + } + if(found) + break; + } + } + return ret; +} + + +/*! + Creates an accelerator string for \a key. For example, + CTRL+Key_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are + translated (using TQObject::tr()) in the "TQAccel" context. + */ +TQString TQKeySequence::encodeString( int key ) +{ + TQString s; +#if defined(Q_OS_MAC) + // On MAC the order is Meta, Alt, Shift, Control. + if ( (key & META) == META ) + s += TQMAC_META; + if ( (key & ALT) == ALT ) + s += TQMAC_ALT; + if ( (key & SHIFT) == SHIFT ) + s += TQMAC_SHIFT; + if ( (key & CTRL) == CTRL ) + s += TQMAC_CTRL; +#else + // On other systems the order is Meta, Control, Alt, Shift + if ( (key & META) == META ) + s += TQAccel::tr( "Meta" ); + if ( (key & CTRL) == CTRL ) { + if ( !s.isEmpty() ) + s += TQAccel::tr( "+" ); + s += TQAccel::tr( "Ctrl" ); + } + if ( (key & ALT) == ALT ) { + if ( !s.isEmpty() ) + s += TQAccel::tr( "+" ); + s += TQAccel::tr( "Alt" ); + } + if ( (key & SHIFT) == SHIFT ) { + if ( !s.isEmpty() ) + s += TQAccel::tr( "+" ); + s += TQAccel::tr( "Shift" ); + } +#endif + + + key &= ~(SHIFT | CTRL | ALT | META ); + TQString p; + + if ( (key & UNICODE_ACCEL) == UNICODE_ACCEL ) { + // Note: This character should NOT be upper()'ed, since + // the encoded string should indicate EXACTLY what the + // key represents! Hence a 'Ctrl+Shift+c' is posible to + // represent, but is clearly impossible to trigger... + p = TQChar(key & 0xffff); + } else if ( key >= Key_F1 && key <= Key_F35 ) { + p = TQAccel::tr( "F%1" ).arg(key - Key_F1 + 1); + } else if ( key > Key_Space && key <= Key_AsciiTilde ) { + p.sprintf( "%c", key ); + } else { + int i=0; + while (keyname[i].name) { + if ( key == keyname[i].key ) { + p = TQAccel::tr(keyname[i].name); + break; + } + ++i; + } + // If we can't find the actual translatable keyname, + // fall back on the unicode representation of it... + // Or else characters like Key_aring may not get displayed + // ( Really depends on you locale ) + if ( !keyname[i].name ) + // Note: This character should NOT be upper()'ed, see above! + p = TQChar(key & 0xffff); + } + +#ifndef Q_OS_MAC + if ( !s.isEmpty() ) + s += TQAccel::tr( "+" ); +#endif + + s += p; + return s; +} + +/*! + Matches the sequence with \a seq. Returns \c TQt::Identical if + successful, \c TQt::PartialMatch for matching but incomplete \a seq, + and \c TQt::NoMatch if the sequences have nothing in common. + Returns \c TQt::NoMatch if \a seq is shorter. +*/ +TQt::SequenceMatch TQKeySequence::matches( const TQKeySequence& seq ) const +{ + uint userN = count(), + seqN = seq.count(); + + if ( userN > seqN ) + return NoMatch; + + // If equal in length, we have a potential Identical sequence, + // else we already know it can only be partial. + SequenceMatch match = ( userN == seqN ? Identical : PartialMatch ); + + for ( uint i = 0; i < userN; i++ ) { + int userKey = (*this)[i], + sequenceKey = seq[i]; + + if ( (userKey & ~TQt::UNICODE_ACCEL) != + (sequenceKey & ~TQt::UNICODE_ACCEL) ) + return NoMatch; + } + return match; +} + + +/*! + Creates an accelerator string for the key sequence. + For instance CTRL+Key_O gives "Ctrl+O". If the key sequence has + multiple key codes they are returned comma-separated, e.g. + "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are + translated (using TQObject::tr()) in the "TQAccel" scope. If the key + sequence has no keys, TQString::null is returned. + + On Mac OS X, the string returned resembles the sequence that is shown in + the menubar. +*/ +TQKeySequence::operator TQString() const +{ + int end = count(); + if ( !end ) return TQString::null; + + TQString complete; + int i = 0; + while ( i < end ) { + complete += encodeString( d->key[i] ); + i++; + if ( i != end) + complete += ", "; + } + return complete; +} + + +/*! + \obsolete + For backward compatibility: returns the first keycode + as integer. If the key sequence is empty, 0 is returned. + */ +TQKeySequence::operator int () const +{ + if ( 1 <= count() ) + return d->key[0]; + return 0; +} + + +/*! + Returns a reference to the element at position \a index in the key + sequence. This can only be used to read an element. + */ +int TQKeySequence::operator[]( uint index ) const +{ +#ifdef QT_CHECK_STATE + if ( index > 4 ) { + tqWarning( "TQKeySequence::operator[]: index %u out of range", index ); + return 0; + } +#endif // QT_CHECK_STATE + return d->key[index]; +} + + +/*! + Assignment operator. Assigns \a keysequence to this + object. + */ +TQKeySequence &TQKeySequence::operator=( const TQKeySequence & keysequence ) +{ + keysequence.d->ref(); + if ( d->deref() ) + delete d; + d = keysequence.d; + return *this; +} + + +/*! + Returns TRUE if \a keysequence is equal to this key + sequence; otherwise returns FALSE. + */ + + +bool TQKeySequence::operator==( const TQKeySequence& keysequence ) const +{ + return ( (d->key[0]&~UNICODE_ACCEL) == (keysequence.d->key[0]&~UNICODE_ACCEL) && + (d->key[1]&~UNICODE_ACCEL) == (keysequence.d->key[1]&~UNICODE_ACCEL) && + (d->key[2]&~UNICODE_ACCEL) == (keysequence.d->key[2]&~UNICODE_ACCEL) && + (d->key[3]&~UNICODE_ACCEL) == (keysequence.d->key[3]&~UNICODE_ACCEL) ); +} + + +/*! + Returns TRUE if \a keysequence is not equal to this key sequence; + otherwise returns FALSE. +*/ +bool TQKeySequence::operator!= ( const TQKeySequence& keysequence ) const +{ + TQKeySequence *that = (TQKeySequence*)this; + return !( (*that) == keysequence ); +} + + +/***************************************************************************** + TQKeySequence stream functions + *****************************************************************************/ +#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO) +/*! + \relates TQKeySequence + + Writes the key sequence \a keysequence to the stream \a s. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ +TQDataStream &operator<<( TQDataStream &s, const TQKeySequence &keysequence ) +{ + TQValueList list; + list += keysequence.d->key[0]; + list += keysequence.d->key[1]; + list += keysequence.d->key[2]; + list += keysequence.d->key[3]; + s << list; + + return s; +} + + +/*! + \relates TQKeySequence + + Reads a key sequence from the stream \a s into the key sequence \a + keysequence. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ +TQDataStream &operator>>( TQDataStream &s, TQKeySequence &keysequence ) +{ + TQValueList list; + s >> list; + +#ifdef QT_CHECK_STATE + if ( 1 != list.count() && 4 != list.count() ) { + tqWarning( "Invalid TQKeySequence data in the datastream." ); + return s; + } +#endif + + if ( 1 == list.count() ) { + keysequence.d->key[0] = *list.at( 0 ); + keysequence.d->key[1] = + keysequence.d->key[2] = + keysequence.d->key[3] = 0; + } else { + keysequence.d->key[0] = *list.at( 0 ); + keysequence.d->key[1] = *list.at( 1 ); + keysequence.d->key[2] = *list.at( 2 ); + keysequence.d->key[3] = *list.at( 3 ); + } + return s; +} + +#endif //TQT_NO_DATASTREAM + +#endif //TQT_NO_ACCEL diff --git a/src/kernel/tqkeysequence.h b/src/kernel/tqkeysequence.h new file mode 100644 index 000000000..e4800839d --- /dev/null +++ b/src/kernel/tqkeysequence.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Definition of TQKeySequence class +** +** Created : 0108007 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQKEYSEQUENCE_H +#define TQKEYSEQUENCE_H + +#ifndef QT_H +#ifndef QT_H +#include "ntqnamespace.h" +#include "tqstring.h" +#endif // QT_H +#endif + +#ifndef TQT_NO_ACCEL + +/***************************************************************************** + TQKeySequence stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM +class TQKeySequence; +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQKeySequence & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQKeySequence & ); +#endif + +class TQKeySequencePrivate; + +class TQ_EXPORT TQKeySequence : public TQt +{ +public: + TQKeySequence(); + TQKeySequence( const TQString& key ); + TQKeySequence( int key ); + TQKeySequence( int k1, int k2, int k3 = 0, int k4 = 0 ); + TQKeySequence( const TQKeySequence & ); + ~TQKeySequence(); + + uint count() const; + bool isEmpty() const; + TQt::SequenceMatch matches( const TQKeySequence & ) const; + + operator TQString() const; + operator int () const; + int operator[]( uint ) const; + TQKeySequence &operator=( const TQKeySequence & ); + bool operator==( const TQKeySequence& ) const; + bool operator!= ( const TQKeySequence& ) const; + +private: + static int decodeString( const TQString & ); + static TQString encodeString( int ); + int assign( TQString ); + void setKey( int key, int index ); + + TQKeySequencePrivate* d; + + friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQKeySequence & ); + friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQKeySequence & ); + friend class TQAccelManager; +}; + +#else + +class TQ_EXPORT TQKeySequence : public TQt +{ +public: + TQKeySequence() {} + TQKeySequence( int ) {} +}; + +#endif //TQT_NO_ACCEL + +#endif diff --git a/src/kernel/tqttdeintegration_x11.cpp b/src/kernel/tqttdeintegration_x11.cpp index 6bd89a390..0b8e794c2 100644 --- a/src/kernel/tqttdeintegration_x11.cpp +++ b/src/kernel/tqttdeintegration_x11.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index d0e37df41..4aa4a09ed 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -64,7 +64,7 @@ #endif #if defined(TQ_WS_WIN) #include "qt_windows.h" -#include "qinputcontext_p.h" +#include "tqinputcontext_p.h" #endif #include "tqfontdata_p.h" diff --git a/src/kernel/tqwidget_x11.cpp b/src/kernel/tqwidget_x11.cpp index bccd0110b..b7136818f 100644 --- a/src/kernel/tqwidget_x11.cpp +++ b/src/kernel/tqwidget_x11.cpp @@ -66,8 +66,8 @@ bool qt_wstate_iconified( WId ); void qt_updated_rootinfo(); #ifndef TQT_NO_IM -#include "ntqinputcontext.h" -#include "ntqinputcontextfactory.h" +#include "tqinputcontext.h" +#include "tqinputcontextfactory.h" #endif // Paint event clipping magic diff --git a/src/libqt.map b/src/libqt.map index 81a903a16..1e75da0c0 100644 --- a/src/libqt.map +++ b/src/libqt.map @@ -43,7 +43,7 @@ TQFontDef::*; TQFontStruct::*; TQFont*Codec::*; - QInputContext::* + TQInputContext::* }; TT_*; TTO_*; diff --git a/src/opengl/tqgl_x11.cpp b/src/opengl/tqgl_x11.cpp index e3fdfc504..cf82fe355 100644 --- a/src/opengl/tqgl_x11.cpp +++ b/src/opengl/tqgl_x11.cpp @@ -74,7 +74,7 @@ extern "C" { #include "tqgl_x11_p.h" #ifdef QT_DLOPEN_OPENGL -#include "ntqlibrary.h" +#include "tqlibrary.h" extern "C" { _glCallLists qt_glCallLists; diff --git a/src/tools/ntqlibrary.h b/src/tools/ntqlibrary.h deleted file mode 100644 index d8b5f4ba5..000000000 --- a/src/tools/ntqlibrary.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Definition of TQLibrary class -** -** Created : 000101 -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQLIBRARY_H -#define TQLIBRARY_H - -#ifndef QT_H -#include "tqstring.h" -#endif // QT_H - -#ifndef TQT_NO_LIBRARY - -class TQLibraryPrivate; - -class TQ_EXPORT TQLibrary -{ -public: - TQLibrary( const TQString& filename ); - virtual ~TQLibrary(); - - void *resolve( const char* ); - static void *resolve( const TQString &filename, const char * ); - - bool load(); - virtual bool unload(); - bool isLoaded() const; - - bool autoUnload() const; - void setAutoUnload( bool enable ); - - TQString library() const; - -private: - TQLibraryPrivate *d; - - TQString libfile; - uint aunload : 1; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQLibrary( const TQLibrary & ); - TQLibrary &operator=( const TQLibrary & ); -#endif -}; - -#define Q_DEFINED_QLIBRARY -#include "ntqwinexport.h" -#endif //TQT_NO_LIBRARY -#endif //TQLIBRARY_H diff --git a/src/tools/qcomlibrary_p.h b/src/tools/qcomlibrary_p.h index f738aff52..ede724194 100644 --- a/src/tools/qcomlibrary_p.h +++ b/src/tools/qcomlibrary_p.h @@ -53,7 +53,7 @@ #ifndef QT_H #include "qcom_p.h" -#include "ntqlibrary.h" +#include "tqlibrary.h" #endif // QT_H #ifndef TQT_NO_COMPONENT diff --git a/src/tools/qlibrary.cpp b/src/tools/qlibrary.cpp deleted file mode 100644 index 6b586fcdf..000000000 --- a/src/tools/qlibrary.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQLibrary class -** -** Created : 000101 -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 "qplatformdefs.h" -#include -#include -#include - -#ifndef TQT_NO_LIBRARY - -// uncomment this to get error messages -//#define QT_DEBUG_COMPONENT 1 -// uncomment this to get error and success messages -//#define QT_DEBUG_COMPONENT 2 - -#ifndef QT_DEBUG_COMPONENT -# if defined(QT_DEBUG) -# define QT_DEBUG_COMPONENT 1 -# endif -#endif - -#if (defined(TQ_WS_WIN) && !defined(QT_MAKEDLL)) \ - || (defined(Q_OS_FREEBSD) && defined(Q_CC_INTEL)) \ - || (defined(Q_OS_IRIX) && defined(Q_CC_GNU)) -#define TQT_NO_LIBRARY_UNLOAD -#endif - -TQLibraryPrivate::TQLibraryPrivate( TQLibrary *lib ) - : pHnd( 0 ), library( lib ) -{ -} - - -/*! - \class TQLibrary ntqlibrary.h - \reentrant - \brief The TQLibrary class provides a wrapper for handling shared libraries. - - \mainclass - \ingroup plugins - - An instance of a TQLibrary object can handle a single shared - library and provide access to the functionality in the library in - a platform independent way. If the library is a component server, - TQLibrary provides access to the exported component and can - directly query this component for interfaces. - - TQLibrary ensures that the shared library is loaded and stays in - memory whilst it is in use. TQLibrary can also unload the library - on destruction and release unused resources. - - A typical use of TQLibrary is to resolve an exported symbol in a - shared object, and to call the function that this symbol - represents. This is called "explicit linking" in contrast to - "implicit linking", which is done by the link step in the build - process when linking an executable against a library. - - The following code snippet loads a library, resolves the symbol - "mysymbol", and calls the function if everything succeeded. If - something went wrong, e.g. the library file does not exist or the - symbol is not defined, the function pointer will be 0 and won't be - called. When the TQLibrary object is destroyed the library will be - unloaded, making all references to memory allocated in the library - invalid. - - \code - typedef void (*MyPrototype)(); - MyPrototype myFunction; - - TQLibrary myLib( "mylib" ); - myFunction = (MyPrototype) myLib.resolve( "mysymbol" ); - if ( myFunction ) { - myFunction(); - } - \endcode -*/ - -/*! - Creates a TQLibrary object for the shared library \a filename. The - library will be unloaded in the destructor. - - Note that \a filename does not need to include the (platform specific) - file extension, so calling - \code - TQLibrary lib( "mylib" ); - \endcode - is equivalent to calling - \code - TQLibrary lib( "mylib.dll" ); - \endcode - on Windows, and - \code - TQLibrary lib( "libmylib.so" ); - \endcode - on Unix. Specifying the extension is not recommended, since - doing so introduces a platform dependency. - - If \a filename does not include a path, the library loader will - look for the file in the platform specific search paths. - - \sa load() unload(), setAutoUnload() -*/ -TQLibrary::TQLibrary( const TQString& filename ) - : libfile( filename ), aunload( TRUE ) -{ - libfile.replace( '\\', '/' ); - d = new TQLibraryPrivate( this ); -} - -/*! - Deletes the TQLibrary object. - - The library will be unloaded if autoUnload() is TRUE (the - default), otherwise it stays in memory until the application - exits. - - \sa unload(), setAutoUnload() -*/ -TQLibrary::~TQLibrary() -{ - if ( autoUnload() ) - unload(); - - delete d; -} - -/*! - Returns the address of the exported symbol \a symb. The library is - loaded if necessary. The function returns 0 if the symbol could - not be resolved or the library could not be loaded. - - \code - typedef int (*avgProc)( int, int ); - - avgProc avg = (avgProc) library->resolve( "avg" ); - if ( avg ) - return avg( 5, 8 ); - else - return -1; - \endcode - - The symbol must be exported as a C-function from the library. This - requires the \c {extern "C"} notation if the library is compiled - with a C++ compiler. On Windows you also have to explicitly export - the function from the DLL using the \c {__declspec(dllexport)} - compiler directive. - - \code - extern "C" MY_EXPORT_MACRO int avg(int a, int b) - { - return (a + b) / 2; - } - \endcode - - with \c MY_EXPORT defined as - - \code - #ifdef TQ_WS_WIN - # define MY_EXPORT __declspec(dllexport) - #else - # define MY_EXPORT - #endif - \endcode - - On Darwin and Mac OS X this function uses code from dlcompat, part of the - OpenDarwin project. - - \legalese - - Copyright (c) 2002 Jorge Acereda and Peter O'Gorman - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -void *TQLibrary::resolve( const char* symb ) -{ - if ( !d->pHnd ) - load(); - if ( !d->pHnd ) - return 0; - - void *address = d->resolveSymbol( symb ); - - return address; -} - -/*! - \overload - - Loads the library \a filename and returns the address of the - exported symbol \a symb. Note that like the constructor, \a - filename does not need to include the (platform specific) file - extension. The library remains loaded until the process exits. - - The function returns 0 if the symbol could not be resolved or the - library could not be loaded. - - This function is useful only if you want to resolve a single - symbol, e.g. a function pointer from a specific library once: - - \code - typedef void (*FunctionType)(); - static FunctionType *ptrFunction = 0; - static bool triedResolve = FALSE; - if ( !ptrFunction && !triedResolve ) - ptrFunction = TQLibrary::resolve( "mylib", "mysymb" ); - - if ( ptrFunction ) - ptrFunction(); - else - ... - \endcode - - If you want to resolve multiple symbols, use a TQLibrary object and - call the non-static version of resolve(). - - \sa resolve() -*/ -void *TQLibrary::resolve( const TQString &filename, const char *symb ) -{ - TQLibrary lib( filename ); - lib.setAutoUnload( FALSE ); - return lib.resolve( symb ); -} - -/*! - Returns TRUE if the library is loaded; otherwise returns FALSE. - - \sa unload() -*/ -bool TQLibrary::isLoaded() const -{ - return d->pHnd != 0; -} - -/*! - Loads the library. Since resolve() always calls this function - before resolving any symbols it is not necessary to call it - explicitly. In some situations you might want the library loaded - in advance, in which case you would use this function. - - On Darwin and Mac OS X this function uses code from dlcompat, part of the - OpenDarwin project. - - \legalese - - Copyright (c) 2002 Jorge Acereda and Peter O'Gorman - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -bool TQLibrary::load() -{ - if (libfile.isEmpty()) - return FALSE; - return d->loadLibrary(); -} - -/*! - Unloads the library and returns TRUE if the library could be - unloaded; otherwise returns FALSE. - - This function is called by the destructor if autoUnload() is - enabled. - - \sa resolve() -*/ -bool TQLibrary::unload() -{ - if ( !d->pHnd ) - return TRUE; - -#if !defined(TQT_NO_LIBRARY_UNLOAD) - if ( !d->freeLibrary() ) { -# if defined(QT_DEBUG_COMPONENT) - tqWarning( "%s could not be unloaded", (const char*) TQFile::encodeName(library()) ); -# endif - return FALSE; - } - -# if defined(QT_DEBUG_COMPONENT) && QT_DEBUG_COMPONENT == 2 - tqWarning( "%s has been unloaded", (const char*) TQFile::encodeName(library()) ); -# endif - d->pHnd = 0; -#endif - return TRUE; -} - -/*! - Returns TRUE if the library will be automatically unloaded when - this wrapper object is destructed; otherwise returns FALSE. The - default is TRUE. - - \sa setAutoUnload() -*/ -bool TQLibrary::autoUnload() const -{ - return (bool)aunload; -} - -/*! - If \a enabled is TRUE (the default), the wrapper object is set to - automatically unload the library upon destruction. If \a enabled - is FALSE, the wrapper object is not unloaded unless you explicitly - call unload(). - - \sa autoUnload() -*/ -void TQLibrary::setAutoUnload( bool enabled ) -{ - aunload = enabled; -} - -/*! - Returns the filename of the shared library this TQLibrary object - handles, including the platform specific file extension. - - For example: - \code - TQLibrary lib( "mylib" ); - TQString str = lib.library(); - \endcode - will set \e str to "mylib.dll" on Windows, and "libmylib.so" on Linux. -*/ -TQString TQLibrary::library() const -{ - if ( libfile.isEmpty() ) - return libfile; - - TQString filename = libfile; - -#if defined(TQ_WS_WIN) - if ( filename.findRev( '.' ) <= filename.findRev( '/' ) ) - filename += ".dll"; -#else - TQStringList filters = ""; -#ifdef Q_OS_MACX - filters << ".so"; - filters << ".bundle"; - filters << ".dylib"; //the last one is also the default one.. -#elif defined(Q_OS_HPUX) - filters << ".sl"; -#else - filters << ".so"; -#endif - for(TQStringList::Iterator it = filters.begin(); TRUE; ) { - TQString filter = (*it); - ++it; - - if(TQFile::exists(filename + filter)) { - filename += filter; - break; - } else if(!filter.isEmpty()) { - TQString tmpfilename = filename; - const int x = tmpfilename.findRev( "/" ); - if ( x != -1 ) { - TQString path = tmpfilename.left( x + 1 ); - TQString file = tmpfilename.right( tmpfilename.length() - x - 1 ); - tmpfilename = TQString( "%1lib%2" ).arg( path ).arg( file ); - } else { - tmpfilename = TQString( "lib%1" ).arg( filename ); - } - if ( !filename.contains(".so") ) - tmpfilename += filter; - if(TQFile::exists(tmpfilename) || it == filters.end()) { - filename = tmpfilename; - break; - } - } - } -#endif - return filename; -} -#endif //TQT_NO_LIBRARY diff --git a/src/tools/qlibrary_p.h b/src/tools/qlibrary_p.h deleted file mode 100644 index 0a687b1ca..000000000 --- a/src/tools/qlibrary_p.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Definition of an internal TQLibrary class -** -** Created : 000101 -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 TQLIBRARY_P_H -#define TQLIBRARY_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of the TQLibrary class. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// -// - -#include "ntqlibrary.h" - -#ifndef TQT_NO_LIBRARY - -#ifndef QT_H -#include "ntqwindowdefs.h" -#endif // QT_H - -class TQLibraryPrivate -{ -public: - TQLibraryPrivate( TQLibrary *lib ); - -#ifdef TQ_WS_WIN - HINSTANCE pHnd; -#else - void *pHnd; -#endif - - bool loadLibrary(); - bool freeLibrary(); - void *resolveSymbol( const char * ); - -private: - TQLibrary *library; -}; - -#endif // TQT_NO_LIBRARY -#endif // TQLIBRARY_P_H diff --git a/src/tools/qlibrary_unix.cpp b/src/tools/qlibrary_unix.cpp deleted file mode 100644 index 8c08772ac..000000000 --- a/src/tools/qlibrary_unix.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQLibraryPrivate class -** -** Created : 000101 -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** 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 requirements 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 sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. 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 "qplatformdefs.h" -#include "private/qlibrary_p.h" - -#ifndef TQT_NO_LIBRARY - -#if defined(QT_AOUT_UNDERSCORE) -#include -#endif - -/* - The platform dependent implementations of - - loadLibrary - - freeLibrary - - resolveSymbol - - It's not too hard to guess what the functions do. -*/ - -#if defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit - -bool TQLibraryPrivate::loadLibrary() -{ - if ( pHnd ) - return TRUE; - - TQString filename = library->library(); - - pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); -#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) - if ( !pHnd ) - tqWarning( "%s: failed to load library!", filename.latin1() ); -#endif - return pHnd != 0; -} - -bool TQLibraryPrivate::freeLibrary() -{ - if ( !pHnd ) - return TRUE; - - if ( shl_unload( (shl_t)pHnd ) ) { -#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) - TQString filename = library->library(); - tqWarning( "%s: Failed to unload library!", filename.latin1() ); -#endif - return FALSE; - } - pHnd = 0; - return TRUE; -} - -void* TQLibraryPrivate::resolveSymbol( const char* symbol ) -{ - if ( !pHnd ) - return 0; - - void* address = 0; - if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, &address ) < 0 ) { -#if defined(QT_DEBUG_COMPONENT) - TQString filename = library->library(); - tqWarning( "%s: couldn't resolve symbol \"%s\"", filename.latin1(), symbol ); -#endif - } - return address; -} - -#else // POSIX -#include -#ifndef DL_PREFIX //for mac dlcompat -# define DL_PREFIX(x) x -#endif - -bool TQLibraryPrivate::loadLibrary() -{ - if ( pHnd ) - return TRUE; - - TQString filename = library->library(); - - pHnd = DL_PREFIX(dlopen)( filename.latin1(), RTLD_LAZY ); -#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) - if ( !pHnd ) - tqWarning( "%s", DL_PREFIX(dlerror)() ); -#endif - return pHnd != 0; -} - -bool TQLibraryPrivate::freeLibrary() -{ - if ( !pHnd ) - return TRUE; - - if ( DL_PREFIX(dlclose)( pHnd ) ) { -#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) - tqWarning( "%s", DL_PREFIX(dlerror)() ); -#endif - return FALSE; - } - - pHnd = 0; - return TRUE; -} - -void* TQLibraryPrivate::resolveSymbol( const char* symbol ) -{ - if ( !pHnd ) - return 0; - -#if defined(QT_AOUT_UNDERSCORE) - // older a.out systems add an underscore in front of symbols - char* undrscr_symbol = new char[strlen(symbol)+2]; - undrscr_symbol[0] = '_'; - strcpy(undrscr_symbol+1, symbol); - void* address = DL_PREFIX(dlsym)( pHnd, undrscr_symbol ); - delete [] undrscr_symbol; -#else - void* address = DL_PREFIX(dlsym)( pHnd, symbol ); -#endif -#if defined(QT_DEBUG_COMPONENT) - const char* error = DL_PREFIX(dlerror)(); - if ( error ) - tqWarning( "%s", error ); -#endif - return address; -} - -#endif // POSIX - -#endif diff --git a/src/tools/qt_tools.pri b/src/tools/qt_tools.pri index ba4e5dd79..03bf94e37 100644 --- a/src/tools/qt_tools.pri +++ b/src/tools/qt_tools.pri @@ -31,8 +31,8 @@ tools { $$TOOLS_H/tqintcache.h \ $$TOOLS_H/tqintdict.h \ $$TOOLS_H/tqiodevice.h \ - $$TOOLS_H/ntqlibrary.h \ - $$TOOLS_P/qlibrary_p.h \ + $$TOOLS_H/tqlibrary.h \ + $$TOOLS_P/tqlibrary_p.h \ $$TOOLS_H/tqlocale.h \ $$TOOLS_P/tqlocale_p.h \ $$TOOLS_H/tqptrlist.h \ @@ -70,7 +70,7 @@ tools { win32:SOURCES += $$TOOLS_CPP/tqdir_win.cpp \ $$TOOLS_CPP/tqfile_win.cpp \ $$TOOLS_CPP/tqfileinfo_win.cpp \ - $$TOOLS_CPP/qlibrary_win.cpp \ + $$TOOLS_CPP/tqlibrary_win.cpp \ $$TOOLS_CPP/tqsettings_win.cpp \ $$TOOLS_CPP/tqmutex_win.cpp \ $$TOOLS_CPP/tqwaitcondition_win.cpp \ @@ -103,7 +103,7 @@ tools { SOURCES+=3rdparty/dlcompat/dlfcn.c INCLUDEPATH+=3rdparty/dlcompat } - unix:SOURCES += $$TOOLS_CPP/qlibrary_unix.cpp + unix:SOURCES += $$TOOLS_CPP/tqlibrary_unix.cpp SOURCES += $$TOOLS_CPP/tqbitarray.cpp \ $$TOOLS_CPP/tqbuffer.cpp \ @@ -124,7 +124,7 @@ tools { $$TOOLS_CPP/tqgpluginmanager.cpp \ $$TOOLS_CPP/tqgvector.cpp \ $$TOOLS_CPP/tqiodevice.cpp \ - $$TOOLS_CPP/qlibrary.cpp \ + $$TOOLS_CPP/tqlibrary.cpp \ $$TOOLS_CPP/tqlocale.cpp \ $$TOOLS_CPP/tqmap.cpp \ $$TOOLS_CPP/tqmutexpool.cpp \ diff --git a/src/tools/qwinexport.cpp b/src/tools/qwinexport.cpp index 79c651b3c..d1a2bce22 100644 --- a/src/tools/qwinexport.cpp +++ b/src/tools/qwinexport.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/tools/tqfeatures.txt b/src/tools/tqfeatures.txt index 5e7c9c267..ef466fd36 100644 --- a/src/tools/tqfeatures.txt +++ b/src/tools/tqfeatures.txt @@ -1030,7 +1030,7 @@ SeeAlso: ??? Feature: INPUTDIALOG Section: Widgets Requires: DIALOG COMBOBOX LABEL PUSHBUTTON SPINBOX WIDGETSTACK LAYOUT -Name: QInputDialog +Name: TQInputDialog SeeAlso: ??? Feature: ERRORMESSAGE diff --git a/src/tools/tqgpluginmanager_p.h b/src/tools/tqgpluginmanager_p.h index 069b7e27a..7b713990c 100644 --- a/src/tools/tqgpluginmanager_p.h +++ b/src/tools/tqgpluginmanager_p.h @@ -41,7 +41,7 @@ #ifndef QT_H #include "tqdict.h" -#include "ntqlibrary.h" +#include "tqlibrary.h" #include "ntquuid.h" #include "tqstringlist.h" #include "qcom_p.h" diff --git a/src/tools/tqlibrary.cpp b/src/tools/tqlibrary.cpp new file mode 100644 index 000000000..05ceee649 --- /dev/null +++ b/src/tools/tqlibrary.cpp @@ -0,0 +1,443 @@ +/**************************************************************************** +** +** Implementation of TQLibrary class +** +** Created : 000101 +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 "qplatformdefs.h" +#include +#include +#include + +#ifndef TQT_NO_LIBRARY + +// uncomment this to get error messages +//#define QT_DEBUG_COMPONENT 1 +// uncomment this to get error and success messages +//#define QT_DEBUG_COMPONENT 2 + +#ifndef QT_DEBUG_COMPONENT +# if defined(QT_DEBUG) +# define QT_DEBUG_COMPONENT 1 +# endif +#endif + +#if (defined(TQ_WS_WIN) && !defined(QT_MAKEDLL)) \ + || (defined(Q_OS_FREEBSD) && defined(Q_CC_INTEL)) \ + || (defined(Q_OS_IRIX) && defined(Q_CC_GNU)) +#define TQT_NO_LIBRARY_UNLOAD +#endif + +TQLibraryPrivate::TQLibraryPrivate( TQLibrary *lib ) + : pHnd( 0 ), library( lib ) +{ +} + + +/*! + \class TQLibrary tqlibrary.h + \reentrant + \brief The TQLibrary class provides a wrapper for handling shared libraries. + + \mainclass + \ingroup plugins + + An instance of a TQLibrary object can handle a single shared + library and provide access to the functionality in the library in + a platform independent way. If the library is a component server, + TQLibrary provides access to the exported component and can + directly query this component for interfaces. + + TQLibrary ensures that the shared library is loaded and stays in + memory whilst it is in use. TQLibrary can also unload the library + on destruction and release unused resources. + + A typical use of TQLibrary is to resolve an exported symbol in a + shared object, and to call the function that this symbol + represents. This is called "explicit linking" in contrast to + "implicit linking", which is done by the link step in the build + process when linking an executable against a library. + + The following code snippet loads a library, resolves the symbol + "mysymbol", and calls the function if everything succeeded. If + something went wrong, e.g. the library file does not exist or the + symbol is not defined, the function pointer will be 0 and won't be + called. When the TQLibrary object is destroyed the library will be + unloaded, making all references to memory allocated in the library + invalid. + + \code + typedef void (*MyPrototype)(); + MyPrototype myFunction; + + TQLibrary myLib( "mylib" ); + myFunction = (MyPrototype) myLib.resolve( "mysymbol" ); + if ( myFunction ) { + myFunction(); + } + \endcode +*/ + +/*! + Creates a TQLibrary object for the shared library \a filename. The + library will be unloaded in the destructor. + + Note that \a filename does not need to include the (platform specific) + file extension, so calling + \code + TQLibrary lib( "mylib" ); + \endcode + is equivalent to calling + \code + TQLibrary lib( "mylib.dll" ); + \endcode + on Windows, and + \code + TQLibrary lib( "libmylib.so" ); + \endcode + on Unix. Specifying the extension is not recommended, since + doing so introduces a platform dependency. + + If \a filename does not include a path, the library loader will + look for the file in the platform specific search paths. + + \sa load() unload(), setAutoUnload() +*/ +TQLibrary::TQLibrary( const TQString& filename ) + : libfile( filename ), aunload( TRUE ) +{ + libfile.replace( '\\', '/' ); + d = new TQLibraryPrivate( this ); +} + +/*! + Deletes the TQLibrary object. + + The library will be unloaded if autoUnload() is TRUE (the + default), otherwise it stays in memory until the application + exits. + + \sa unload(), setAutoUnload() +*/ +TQLibrary::~TQLibrary() +{ + if ( autoUnload() ) + unload(); + + delete d; +} + +/*! + Returns the address of the exported symbol \a symb. The library is + loaded if necessary. The function returns 0 if the symbol could + not be resolved or the library could not be loaded. + + \code + typedef int (*avgProc)( int, int ); + + avgProc avg = (avgProc) library->resolve( "avg" ); + if ( avg ) + return avg( 5, 8 ); + else + return -1; + \endcode + + The symbol must be exported as a C-function from the library. This + requires the \c {extern "C"} notation if the library is compiled + with a C++ compiler. On Windows you also have to explicitly export + the function from the DLL using the \c {__declspec(dllexport)} + compiler directive. + + \code + extern "C" MY_EXPORT_MACRO int avg(int a, int b) + { + return (a + b) / 2; + } + \endcode + + with \c MY_EXPORT defined as + + \code + #ifdef TQ_WS_WIN + # define MY_EXPORT __declspec(dllexport) + #else + # define MY_EXPORT + #endif + \endcode + + On Darwin and Mac OS X this function uses code from dlcompat, part of the + OpenDarwin project. + + \legalese + + Copyright (c) 2002 Jorge Acereda and Peter O'Gorman + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +void *TQLibrary::resolve( const char* symb ) +{ + if ( !d->pHnd ) + load(); + if ( !d->pHnd ) + return 0; + + void *address = d->resolveSymbol( symb ); + + return address; +} + +/*! + \overload + + Loads the library \a filename and returns the address of the + exported symbol \a symb. Note that like the constructor, \a + filename does not need to include the (platform specific) file + extension. The library remains loaded until the process exits. + + The function returns 0 if the symbol could not be resolved or the + library could not be loaded. + + This function is useful only if you want to resolve a single + symbol, e.g. a function pointer from a specific library once: + + \code + typedef void (*FunctionType)(); + static FunctionType *ptrFunction = 0; + static bool triedResolve = FALSE; + if ( !ptrFunction && !triedResolve ) + ptrFunction = TQLibrary::resolve( "mylib", "mysymb" ); + + if ( ptrFunction ) + ptrFunction(); + else + ... + \endcode + + If you want to resolve multiple symbols, use a TQLibrary object and + call the non-static version of resolve(). + + \sa resolve() +*/ +void *TQLibrary::resolve( const TQString &filename, const char *symb ) +{ + TQLibrary lib( filename ); + lib.setAutoUnload( FALSE ); + return lib.resolve( symb ); +} + +/*! + Returns TRUE if the library is loaded; otherwise returns FALSE. + + \sa unload() +*/ +bool TQLibrary::isLoaded() const +{ + return d->pHnd != 0; +} + +/*! + Loads the library. Since resolve() always calls this function + before resolving any symbols it is not necessary to call it + explicitly. In some situations you might want the library loaded + in advance, in which case you would use this function. + + On Darwin and Mac OS X this function uses code from dlcompat, part of the + OpenDarwin project. + + \legalese + + Copyright (c) 2002 Jorge Acereda and Peter O'Gorman + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +bool TQLibrary::load() +{ + if (libfile.isEmpty()) + return FALSE; + return d->loadLibrary(); +} + +/*! + Unloads the library and returns TRUE if the library could be + unloaded; otherwise returns FALSE. + + This function is called by the destructor if autoUnload() is + enabled. + + \sa resolve() +*/ +bool TQLibrary::unload() +{ + if ( !d->pHnd ) + return TRUE; + +#if !defined(TQT_NO_LIBRARY_UNLOAD) + if ( !d->freeLibrary() ) { +# if defined(QT_DEBUG_COMPONENT) + tqWarning( "%s could not be unloaded", (const char*) TQFile::encodeName(library()) ); +# endif + return FALSE; + } + +# if defined(QT_DEBUG_COMPONENT) && QT_DEBUG_COMPONENT == 2 + tqWarning( "%s has been unloaded", (const char*) TQFile::encodeName(library()) ); +# endif + d->pHnd = 0; +#endif + return TRUE; +} + +/*! + Returns TRUE if the library will be automatically unloaded when + this wrapper object is destructed; otherwise returns FALSE. The + default is TRUE. + + \sa setAutoUnload() +*/ +bool TQLibrary::autoUnload() const +{ + return (bool)aunload; +} + +/*! + If \a enabled is TRUE (the default), the wrapper object is set to + automatically unload the library upon destruction. If \a enabled + is FALSE, the wrapper object is not unloaded unless you explicitly + call unload(). + + \sa autoUnload() +*/ +void TQLibrary::setAutoUnload( bool enabled ) +{ + aunload = enabled; +} + +/*! + Returns the filename of the shared library this TQLibrary object + handles, including the platform specific file extension. + + For example: + \code + TQLibrary lib( "mylib" ); + TQString str = lib.library(); + \endcode + will set \e str to "mylib.dll" on Windows, and "libmylib.so" on Linux. +*/ +TQString TQLibrary::library() const +{ + if ( libfile.isEmpty() ) + return libfile; + + TQString filename = libfile; + +#if defined(TQ_WS_WIN) + if ( filename.findRev( '.' ) <= filename.findRev( '/' ) ) + filename += ".dll"; +#else + TQStringList filters = ""; +#ifdef Q_OS_MACX + filters << ".so"; + filters << ".bundle"; + filters << ".dylib"; //the last one is also the default one.. +#elif defined(Q_OS_HPUX) + filters << ".sl"; +#else + filters << ".so"; +#endif + for(TQStringList::Iterator it = filters.begin(); TRUE; ) { + TQString filter = (*it); + ++it; + + if(TQFile::exists(filename + filter)) { + filename += filter; + break; + } else if(!filter.isEmpty()) { + TQString tmpfilename = filename; + const int x = tmpfilename.findRev( "/" ); + if ( x != -1 ) { + TQString path = tmpfilename.left( x + 1 ); + TQString file = tmpfilename.right( tmpfilename.length() - x - 1 ); + tmpfilename = TQString( "%1lib%2" ).arg( path ).arg( file ); + } else { + tmpfilename = TQString( "lib%1" ).arg( filename ); + } + if ( !filename.contains(".so") ) + tmpfilename += filter; + if(TQFile::exists(tmpfilename) || it == filters.end()) { + filename = tmpfilename; + break; + } + } + } +#endif + return filename; +} +#endif //TQT_NO_LIBRARY diff --git a/src/tools/tqlibrary.h b/src/tools/tqlibrary.h new file mode 100644 index 000000000..d8b5f4ba5 --- /dev/null +++ b/src/tools/tqlibrary.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Definition of TQLibrary class +** +** Created : 000101 +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQLIBRARY_H +#define TQLIBRARY_H + +#ifndef QT_H +#include "tqstring.h" +#endif // QT_H + +#ifndef TQT_NO_LIBRARY + +class TQLibraryPrivate; + +class TQ_EXPORT TQLibrary +{ +public: + TQLibrary( const TQString& filename ); + virtual ~TQLibrary(); + + void *resolve( const char* ); + static void *resolve( const TQString &filename, const char * ); + + bool load(); + virtual bool unload(); + bool isLoaded() const; + + bool autoUnload() const; + void setAutoUnload( bool enable ); + + TQString library() const; + +private: + TQLibraryPrivate *d; + + TQString libfile; + uint aunload : 1; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQLibrary( const TQLibrary & ); + TQLibrary &operator=( const TQLibrary & ); +#endif +}; + +#define Q_DEFINED_QLIBRARY +#include "ntqwinexport.h" +#endif //TQT_NO_LIBRARY +#endif //TQLIBRARY_H diff --git a/src/tools/tqlibrary_p.h b/src/tools/tqlibrary_p.h new file mode 100644 index 000000000..1ae03c601 --- /dev/null +++ b/src/tools/tqlibrary_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Definition of an internal TQLibrary class +** +** Created : 000101 +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 TQLIBRARY_P_H +#define TQLIBRARY_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of the TQLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// +// + +#include "tqlibrary.h" + +#ifndef TQT_NO_LIBRARY + +#ifndef QT_H +#include "ntqwindowdefs.h" +#endif // QT_H + +class TQLibraryPrivate +{ +public: + TQLibraryPrivate( TQLibrary *lib ); + +#ifdef TQ_WS_WIN + HINSTANCE pHnd; +#else + void *pHnd; +#endif + + bool loadLibrary(); + bool freeLibrary(); + void *resolveSymbol( const char * ); + +private: + TQLibrary *library; +}; + +#endif // TQT_NO_LIBRARY +#endif // TQLIBRARY_P_H diff --git a/src/tools/tqlibrary_unix.cpp b/src/tools/tqlibrary_unix.cpp new file mode 100644 index 000000000..c541625d9 --- /dev/null +++ b/src/tools/tqlibrary_unix.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Implementation of TQLibraryPrivate class +** +** Created : 000101 +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** 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 requirements 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 sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. 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 "qplatformdefs.h" +#include "private/tqlibrary_p.h" + +#ifndef TQT_NO_LIBRARY + +#if defined(QT_AOUT_UNDERSCORE) +#include +#endif + +/* + The platform dependent implementations of + - loadLibrary + - freeLibrary + - resolveSymbol + + It's not too hard to guess what the functions do. +*/ + +#if defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit + +bool TQLibraryPrivate::loadLibrary() +{ + if ( pHnd ) + return TRUE; + + TQString filename = library->library(); + + pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); +#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) + if ( !pHnd ) + tqWarning( "%s: failed to load library!", filename.latin1() ); +#endif + return pHnd != 0; +} + +bool TQLibraryPrivate::freeLibrary() +{ + if ( !pHnd ) + return TRUE; + + if ( shl_unload( (shl_t)pHnd ) ) { +#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) + TQString filename = library->library(); + tqWarning( "%s: Failed to unload library!", filename.latin1() ); +#endif + return FALSE; + } + pHnd = 0; + return TRUE; +} + +void* TQLibraryPrivate::resolveSymbol( const char* symbol ) +{ + if ( !pHnd ) + return 0; + + void* address = 0; + if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, &address ) < 0 ) { +#if defined(QT_DEBUG_COMPONENT) + TQString filename = library->library(); + tqWarning( "%s: couldn't resolve symbol \"%s\"", filename.latin1(), symbol ); +#endif + } + return address; +} + +#else // POSIX +#include +#ifndef DL_PREFIX //for mac dlcompat +# define DL_PREFIX(x) x +#endif + +bool TQLibraryPrivate::loadLibrary() +{ + if ( pHnd ) + return TRUE; + + TQString filename = library->library(); + + pHnd = DL_PREFIX(dlopen)( filename.latin1(), RTLD_LAZY ); +#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) + if ( !pHnd ) + tqWarning( "%s", DL_PREFIX(dlerror)() ); +#endif + return pHnd != 0; +} + +bool TQLibraryPrivate::freeLibrary() +{ + if ( !pHnd ) + return TRUE; + + if ( DL_PREFIX(dlclose)( pHnd ) ) { +#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) + tqWarning( "%s", DL_PREFIX(dlerror)() ); +#endif + return FALSE; + } + + pHnd = 0; + return TRUE; +} + +void* TQLibraryPrivate::resolveSymbol( const char* symbol ) +{ + if ( !pHnd ) + return 0; + +#if defined(QT_AOUT_UNDERSCORE) + // older a.out systems add an underscore in front of symbols + char* undrscr_symbol = new char[strlen(symbol)+2]; + undrscr_symbol[0] = '_'; + strcpy(undrscr_symbol+1, symbol); + void* address = DL_PREFIX(dlsym)( pHnd, undrscr_symbol ); + delete [] undrscr_symbol; +#else + void* address = DL_PREFIX(dlsym)( pHnd, symbol ); +#endif +#if defined(QT_DEBUG_COMPONENT) + const char* error = DL_PREFIX(dlerror)(); + if ( error ) + tqWarning( "%s", error ); +#endif + return address; +} + +#endif // POSIX + +#endif diff --git a/src/tools/tqsettings.cpp b/src/tools/tqsettings.cpp index a2ef55da7..18638b571 100644 --- a/src/tools/tqsettings.cpp +++ b/src/tools/tqsettings.cpp @@ -448,7 +448,7 @@ void TQSettingsHeading::parseLine(TQTextStream &stream) #ifdef TQ_WS_WIN // for homedirpath reading from registry #include "qt_windows.h" -#include "ntqlibrary.h" +#include "tqlibrary.h" #ifndef CSIDL_APPDATA #define CSIDL_APPDATA 0x001a // \Application Data diff --git a/src/widgets/tqaction.h b/src/widgets/tqaction.h index e45129341..809e55034 100644 --- a/src/widgets/tqaction.h +++ b/src/widgets/tqaction.h @@ -45,7 +45,7 @@ #include "tqobject.h" #include "tqiconset.h" #include "tqstring.h" -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #endif // QT_H #ifndef TQT_NO_ACTION diff --git a/src/widgets/tqbutton.h b/src/widgets/tqbutton.h index 5683e44b7..52b4f6597 100644 --- a/src/widgets/tqbutton.h +++ b/src/widgets/tqbutton.h @@ -43,7 +43,7 @@ #ifndef QT_H #include "tqwidget.h" -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #endif // QT_H #ifndef TQT_NO_BUTTON diff --git a/src/widgets/tqlineedit.cpp b/src/widgets/tqlineedit.cpp index 7cced4e9c..150e7f1d6 100644 --- a/src/widgets/tqlineedit.cpp +++ b/src/widgets/tqlineedit.cpp @@ -43,7 +43,7 @@ // Keep this position to avoid patch rejection #ifndef TQT_NO_IM -#include "ntqinputcontext.h" +#include "tqinputcontext.h" #endif #include "tqpainter.h" @@ -71,7 +71,7 @@ #endif #ifndef TQT_NO_ACCEL -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #define ACCEL_KEY(k) "\t" + TQString(TQKeySequence( TQt::CTRL | TQt::Key_ ## k )) #else #define ACCEL_KEY(k) "\t" + TQString("Ctrl+" #k) diff --git a/src/widgets/tqmenudata.h b/src/widgets/tqmenudata.h index b5e92cb6a..24e5d9788 100644 --- a/src/widgets/tqmenudata.h +++ b/src/widgets/tqmenudata.h @@ -44,7 +44,7 @@ #ifndef QT_H #include "tqglobal.h" #include "tqiconset.h" // conversion TQPixmap->TQIconset -#include "ntqkeysequence.h" +#include "tqkeysequence.h" #include "tqstring.h" #include "tqsignal.h" #include "tqfont.h" diff --git a/src/widgets/tqtextedit.cpp b/src/widgets/tqtextedit.cpp index 135c981cc..54dc1b2db 100644 --- a/src/widgets/tqtextedit.cpp +++ b/src/widgets/tqtextedit.cpp @@ -44,7 +44,7 @@ // Keep this position to avoid patch rejection #ifndef TQT_NO_IM -#include "ntqinputcontext.h" +#include "tqinputcontext.h" #endif #include "../kernel/qrichtext_p.h" @@ -79,7 +79,7 @@ #include #ifndef TQT_NO_ACCEL -#include +#include #define ACCEL_KEY(k) "\t" + TQString(TQKeySequence( TQt::CTRL | TQt::Key_ ## k )) #else #define ACCEL_KEY(k) "\t" + TQString("Ctrl+" #k) -- cgit v1.2.3