Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ocompletionbase.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
00005                              Inspired by the KDE completion classes which are
00006                              Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org>
00007               =.
00008             .=l.
00009            .>+-=
00010  _;:,     .>    :=|.         This program is free software; you can
00011 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00012 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00013 .="- .-=="i,     .._         License as published by the Free Software
00014  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00015      ._= =}       :          or (at your option) any later version.
00016     .%`+i>       _;_.
00017     .i_,=:_.      -<s.       This program is distributed in the hope that
00018      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00019     : ..    .:,     . . .    without even the implied warranty of
00020     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00021   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00022 ..}^=.=       =       ;      Library General Public License for more
00023 ++=   -.     .`     .:       details.
00024  :     =  ...= . :.=-
00025  -.   .:....=;==+<;          You should have received a copy of the GNU
00026   -_. . .   )=.  =           Library General Public License along with
00027     --        :-=`           this library; see the file COPYING.LIB.
00028                              If not, write to the Free Software Foundation,
00029                              Inc., 59 Temple Place - Suite 330,
00030                              Boston, MA 02111-1307, USA.
00031 */
00032 
00033 #include <opie2/ocompletion.h>
00034 #include <opie2/ocompletionbase.h>
00035 
00036 OCompletionBase::OCompletionBase()
00037 {
00038     m_delegate = 0L;
00039     // Assign the default completion type to use.
00040     m_iCompletionMode = OGlobalSettings::completionMode();
00041 
00042     // Initialize all key-bindings to 0 by default so that
00043     // the event filter will use the global settings.
00044     useGlobalKeyBindings();
00045 
00046     // By default we initialize everything to false.
00047     // All the variables would be setup properly when
00048     // the appropriate member functions are called.
00049     setup( false, false, false );
00050 }
00051 
00052 OCompletionBase::~OCompletionBase()
00053 {
00054     if( m_bAutoDelCompObj && m_pCompObj )
00055     {
00056         delete m_pCompObj;
00057     }
00058 }
00059 
00060 void OCompletionBase::setDelegate( OCompletionBase *delegate )
00061 {
00062     m_delegate = delegate;
00063 
00064     if ( m_delegate ) {
00065         m_delegate->m_bAutoDelCompObj = m_bAutoDelCompObj;
00066         m_delegate->m_bHandleSignals  = m_bHandleSignals;
00067         m_delegate->m_bEmitSignals    = m_bEmitSignals;
00068         m_delegate->m_iCompletionMode = m_iCompletionMode;
00069         m_delegate->m_keyMap          = m_keyMap;
00070     }
00071 }
00072 
00073 OCompletion* OCompletionBase::completionObject( bool hsig )
00074 {
00075     if ( m_delegate )
00076         return m_delegate->completionObject( hsig );
00077     
00078     if ( !m_pCompObj )
00079     {
00080         setCompletionObject( new OCompletion(), hsig );
00081         m_bAutoDelCompObj = true;
00082     }
00083     return m_pCompObj;
00084 }
00085 
00086 void OCompletionBase::setCompletionObject( OCompletion* compObj, bool hsig )
00087 {
00088     if ( m_delegate ) {
00089         m_delegate->setCompletionObject( compObj, hsig );
00090         return;
00091     }
00092     
00093     if ( m_bAutoDelCompObj && compObj != m_pCompObj )
00094         delete m_pCompObj;
00095 
00096     m_pCompObj = compObj;
00097 
00098     // We emit rotation and completion signals
00099     // if completion object is not NULL.
00100     setup( false, hsig, !m_pCompObj.isNull() );
00101 }
00102 
00103 // BC: Inline this function and possibly rename it to setHandleEvents??? (DA)
00104 void OCompletionBase::setHandleSignals( bool handle )
00105 {
00106     if ( m_delegate )
00107         m_delegate->setHandleSignals( handle );
00108     else
00109         m_bHandleSignals = handle;
00110 }
00111 
00112 void OCompletionBase::setCompletionMode( OGlobalSettings::Completion mode )
00113 {
00114     if ( m_delegate ) {
00115         m_delegate->setCompletionMode( mode );
00116         return;
00117     }
00118     
00119     m_iCompletionMode = mode;
00120     // Always sync up OCompletion mode with ours as long as we
00121     // are performing completions.
00122     if( m_pCompObj && m_iCompletionMode != OGlobalSettings::CompletionNone )
00123         m_pCompObj->setCompletionMode( m_iCompletionMode );
00124 }
00125 
00126 bool OCompletionBase::setKeyBinding( KeyBindingType item, const OShortcut& cut )
00127 {
00128     if ( m_delegate )
00129         return m_delegate->setKeyBinding( item, cut );
00130 
00131 
00132     if( !cut.isNull() )
00133     {
00134         for( KeyBindingMap::Iterator it = m_keyMap.begin(); it != m_keyMap.end(); ++it )
00135             if( it.data() == cut )  return false;
00136     }
00137     m_keyMap.replace( item, cut );
00138     return true;
00139 }
00140 
00141 void OCompletionBase::useGlobalKeyBindings()
00142 {
00143 
00144 /*    
00145 
00146     if ( m_delegate ) {
00147         m_delegate->useGlobalKeyBindings();
00148         return;
00149     }
00150     
00151     m_keyMap.clear();
00152     m_keyMap.insert( TextCompletion, 0 );
00153     m_keyMap.insert( PrevCompletionMatch, 0 );
00154     m_keyMap.insert( NextCompletionMatch, 0 );
00155     m_keyMap.insert( SubstringCompletion, 0 );
00156 
00157 */
00158     
00159 }
00160 
00161 void OCompletionBase::setup( bool autodel, bool hsig, bool esig )
00162 {
00163     if ( m_delegate ) {
00164         m_delegate->setup( autodel, hsig, esig );
00165         return;
00166     }
00167     
00168     m_bAutoDelCompObj = autodel;
00169     m_bHandleSignals = hsig;
00170     m_bEmitSignals = esig;
00171 }

Generated on Sat Nov 5 16:16:28 2005 for OPIE by  doxygen 1.4.2