You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
8.1 KiB
234 lines
8.1 KiB
13 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#ifndef _KACCELBASE_H
|
||
|
#define _KACCELBASE_H
|
||
|
|
||
13 years ago
|
#include <tqmap.h>
|
||
|
#include <tqptrvector.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqvaluevector.h>
|
||
|
#include <tqvaluelist.h>
|
||
13 years ago
|
|
||
|
#include "kaccelaction.h"
|
||
|
#include "kkeyserver_x11.h"
|
||
|
|
||
13 years ago
|
class TQPopupMenu;
|
||
|
class TQWidget;
|
||
13 years ago
|
|
||
|
//----------------------------------------------------
|
||
|
|
||
12 years ago
|
class TDEAccelBasePrivate;
|
||
13 years ago
|
/**
|
||
|
* Handle keyboard accelerators.
|
||
|
*
|
||
|
* Allow an user to configure
|
||
|
* key bindings through application configuration files or through the
|
||
|
* @ref KKeyChooser GUI.
|
||
|
*
|
||
12 years ago
|
* A @ref TDEAccel contains a list of accelerator items. Each accelerator item
|
||
13 years ago
|
* consists of an action name and a keyboard code combined with modifiers
|
||
|
* (Shift, Ctrl and Alt.)
|
||
|
*
|
||
|
* For example, "Ctrl+P" could be a shortcut for printing a document. The key
|
||
|
* codes are listed in ckey.h. "Print" could be the action name for printing.
|
||
|
* The action name identifies the key binding in configuration files and the
|
||
|
* @ref KKeyChooser GUI.
|
||
|
*
|
||
|
* When pressed, an accelerator key calls the slot to which it has been
|
||
|
* connected. Accelerator items can be connected so that a key will activate
|
||
|
* two different slots.
|
||
|
*
|
||
12 years ago
|
* A TDEAccel object handles key events sent to its parent widget and to all
|
||
13 years ago
|
* children of this parent widget.
|
||
|
*
|
||
|
* Key binding reconfiguration during run time can be prevented by specifying
|
||
|
* that an accelerator item is not configurable when it is inserted. A special
|
||
|
* group of non-configurable key bindings are known as the
|
||
|
* standard accelerators.
|
||
|
*
|
||
|
* The standard accelerators appear repeatedly in applications for
|
||
|
* standard document actions such as printing and saving. Convenience methods are
|
||
|
* available to insert and connect these accelerators which are configurable on
|
||
|
* a desktop-wide basis.
|
||
|
*
|
||
|
* It is possible for a user to choose to have no key associated with
|
||
|
* an action.
|
||
|
*
|
||
|
* The translated first argument for @ref insertItem() is used only
|
||
|
* in the configuration dialog.
|
||
|
*<pre>
|
||
12 years ago
|
* TDEAccel *a = new TDEAccel( myWindow );
|
||
13 years ago
|
* // Insert an action "Scroll Up" which is associated with the "Up" key:
|
||
|
* a->insertItem( i18n("Scroll up"), "Scroll Up", "Up" );
|
||
|
* // Insert an action "Scroll Down" which is not associated with any key:
|
||
|
* a->insertItem( i18n("Scroll down"), "Scroll Down", 0);
|
||
|
* a->connectItem( "Scroll up", myWindow, SLOT( scrollUp() ) );
|
||
12 years ago
|
* // a->insertStdItem( TDEStdAccel::Print ); //not necessary, since it
|
||
13 years ago
|
* // is done automatially with the
|
||
|
* // connect below!
|
||
12 years ago
|
* a->connectItem(TDEStdAccel::Print, myWindow, SLOT( printDoc() ) );
|
||
13 years ago
|
*
|
||
|
* a->readSettings();
|
||
|
*</pre>
|
||
|
*
|
||
|
* If a shortcut has a menu entry as well, you could insert them like
|
||
12 years ago
|
* this. The example is again the @ref TDEStdAccel::Print from above.
|
||
13 years ago
|
*
|
||
|
* <pre>
|
||
|
* int id;
|
||
|
* id = popup->insertItem("&Print",this, SLOT(printDoc()));
|
||
12 years ago
|
* a->changeMenuAccel(popup, id, TDEStdAccel::Print );
|
||
13 years ago
|
* </pre>
|
||
|
*
|
||
|
* If you want a somewhat "exotic" name for your standard print action, like
|
||
|
* id = popup->insertItem(i18n("Print &Document"),this, SLOT(printDoc()));
|
||
|
* it might be a good idea to insert the standard action before as
|
||
12 years ago
|
* a->insertStdItem( TDEStdAccel::Print, i18n("Print Document") )
|
||
13 years ago
|
* as well, so that the user can easily find the corresponding function.
|
||
|
*
|
||
|
* This technique works for other actions as well. Your "scroll up" function
|
||
|
* in a menu could be done with
|
||
|
*
|
||
|
* <pre>
|
||
|
* id = popup->insertItem(i18n"Scroll &up",this, SLOT(scrollUp()));
|
||
|
* a->changeMenuAccel(popup, id, "Scroll Up" );
|
||
|
* </pre>
|
||
|
*
|
||
|
* Please keep the order right: First insert all functions in the
|
||
|
* acceleratior, then call a -> @ref readSettings() and @em then build your
|
||
|
* menu structure.
|
||
|
*
|
||
|
* @short Configurable key binding support.
|
||
|
* @version $Id: kaccelbase.h,v 1.20 2002/03/03 21:20:25 lunakl Exp $
|
||
|
*/
|
||
|
|
||
12 years ago
|
class TDEAccelBase
|
||
13 years ago
|
{
|
||
|
public:
|
||
|
enum Init { QT_KEYS = 0x00, NATIVE_KEYS = 0x01 };
|
||
|
enum Signal { KEYCODE_CHANGED };
|
||
|
|
||
12 years ago
|
TDEAccelBase( int fInitCode );
|
||
|
virtual ~TDEAccelBase();
|
||
13 years ago
|
|
||
|
uint actionCount() const;
|
||
12 years ago
|
TDEAccelActions& actions();
|
||
13 years ago
|
bool isEnabled() const;
|
||
|
|
||
12 years ago
|
TDEAccelAction* actionPtr( const TQString& sAction );
|
||
|
const TDEAccelAction* actionPtr( const TQString& sAction ) const;
|
||
|
TDEAccelAction* actionPtr( const KKey& key );
|
||
|
TDEAccelAction* actionPtr( const KKeyServer::Key& key );
|
||
13 years ago
|
|
||
13 years ago
|
const TQString& configGroup() const { return m_sConfigGroup; }
|
||
|
void setConfigGroup( const TQString& group );
|
||
13 years ago
|
void setConfigGlobal( bool global );
|
||
|
virtual void setEnabled( bool bEnabled ) = 0;
|
||
|
bool getAutoUpdate() { return m_bAutoUpdate; }
|
||
|
// return value of AutoUpdate flag before this call.
|
||
|
bool setAutoUpdate( bool bAuto );
|
||
|
|
||
|
// Procedures for manipulating Actions.
|
||
|
//void clearActions();
|
||
|
|
||
12 years ago
|
TDEAccelAction* insert( const TQString& sName, const TQString& sDesc );
|
||
|
TDEAccelAction* insert(
|
||
13 years ago
|
const TQString& sAction, const TQString& sDesc, const TQString& sHelp,
|
||
12 years ago
|
const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4,
|
||
13 years ago
|
const TQObject* pObjSlot, const char* psMethodSlot,
|
||
13 years ago
|
bool bConfigurable = true, bool bEnabled = true );
|
||
13 years ago
|
bool remove( const TQString& sAction );
|
||
|
bool setActionSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot );
|
||
13 years ago
|
|
||
|
bool updateConnections();
|
||
|
|
||
12 years ago
|
bool setShortcut( const TQString& sAction, const TDEShortcut& cut );
|
||
13 years ago
|
|
||
|
// Modify individual Action sub-items
|
||
13 years ago
|
bool setActionEnabled( const TQString& sAction, bool bEnable );
|
||
13 years ago
|
|
||
|
/**
|
||
|
* Read all key associations from @p config, or (if @p config
|
||
|
* is zero) from the application's configuration file
|
||
12 years ago
|
* @ref TDEGlobal::config().
|
||
13 years ago
|
*
|
||
|
* The group in which the configuration is stored can be
|
||
|
* set with @ref setConfigGroup().
|
||
|
*/
|
||
12 years ago
|
void readSettings( TDEConfigBase* pConfig = 0 );
|
||
13 years ago
|
|
||
|
/**
|
||
|
* Write the current configurable associations to @p config,
|
||
|
* or (if @p config is zero) to the application's
|
||
|
* configuration file.
|
||
|
*/
|
||
12 years ago
|
void writeSettings( TDEConfigBase* pConfig = 0 ) const;
|
||
13 years ago
|
|
||
13 years ago
|
TQPopupMenu* createPopupMenu( TQWidget* pParent, const KKeySequence& );
|
||
13 years ago
|
|
||
|
// Protected methods
|
||
|
protected:
|
||
12 years ago
|
void slotRemoveAction( TDEAccelAction* );
|
||
13 years ago
|
|
||
13 years ago
|
void createKeyList( TQValueVector<struct X>& rgKeys );
|
||
12 years ago
|
bool insertConnection( TDEAccelAction* );
|
||
|
bool removeConnection( TDEAccelAction* );
|
||
13 years ago
|
|
||
|
virtual bool emitSignal( Signal ) = 0;
|
||
12 years ago
|
virtual bool connectKey( TDEAccelAction&, const KKeyServer::Key& ) = 0;
|
||
13 years ago
|
virtual bool connectKey( const KKeyServer::Key& ) = 0;
|
||
12 years ago
|
virtual bool disconnectKey( TDEAccelAction&, const KKeyServer::Key& ) = 0;
|
||
13 years ago
|
virtual bool disconnectKey( const KKeyServer::Key& ) = 0;
|
||
|
|
||
|
protected:
|
||
|
struct ActionInfo
|
||
|
{
|
||
12 years ago
|
TDEAccelAction* pAction;
|
||
13 years ago
|
uint iSeq, iVariation;
|
||
|
//ActionInfo* pInfoNext; // nil if only one action uses this key.
|
||
|
|
||
|
ActionInfo() { pAction = 0; iSeq = 0xffff; iVariation = 0xffff; }
|
||
12 years ago
|
ActionInfo( TDEAccelAction* _pAction, uint _iSeq, uint _iVariation )
|
||
13 years ago
|
{ pAction = _pAction; iSeq = _iSeq; iVariation = _iVariation; }
|
||
|
};
|
||
13 years ago
|
typedef TQMap<KKeyServer::Key, ActionInfo> KKeyToActionMap;
|
||
13 years ago
|
|
||
12 years ago
|
TDEAccelActions m_rgActions;
|
||
13 years ago
|
KKeyToActionMap m_mapKeyToAction;
|
||
12 years ago
|
TQValueList<TDEAccelAction*> m_rgActionsNonUnique;
|
||
13 years ago
|
bool m_bNativeKeys; // Use native key codes instead of TQt codes
|
||
13 years ago
|
bool m_bEnabled;
|
||
|
bool m_bConfigIsGlobal;
|
||
13 years ago
|
TQString m_sConfigGroup;
|
||
13 years ago
|
bool m_bAutoUpdate;
|
||
12 years ago
|
TDEAccelAction* mtemp_pActionRemoving;
|
||
13 years ago
|
|
||
|
private:
|
||
12 years ago
|
TDEAccelBase& operator =( const TDEAccelBase& );
|
||
13 years ago
|
|
||
12 years ago
|
friend class TDEAccelActions;
|
||
13 years ago
|
protected:
|
||
|
virtual void virtual_hook( int id, void* data );
|
||
|
private:
|
||
12 years ago
|
TDEAccelBasePrivate* d;
|
||
13 years ago
|
};
|
||
|
|
||
|
#endif // _KACCELBASE_H
|