summaryrefslogtreecommitdiff
path: root/libopie2/qt3/opiecore/ocompletionbase.cpp
Unidiff
Diffstat (limited to 'libopie2/qt3/opiecore/ocompletionbase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/qt3/opiecore/ocompletionbase.cpp171
1 files changed, 171 insertions, 0 deletions
diff --git a/libopie2/qt3/opiecore/ocompletionbase.cpp b/libopie2/qt3/opiecore/ocompletionbase.cpp
new file mode 100644
index 0000000..6ff129a
--- a/dev/null
+++ b/libopie2/qt3/opiecore/ocompletionbase.cpp
@@ -0,0 +1,171 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Inspired by the KDE completion classes which are
6 Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org>
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31*/
32
33#include <opie2/ocompletion.h>
34#include <opie2/ocompletionbase.h>
35
36OCompletionBase::OCompletionBase()
37{
38 m_delegate = 0L;
39 // Assign the default completion type to use.
40 m_iCompletionMode = OGlobalSettings::completionMode();
41
42 // Initialize all key-bindings to 0 by default so that
43 // the event filter will use the global settings.
44 useGlobalKeyBindings();
45
46 // By default we initialize everything to false.
47 // All the variables would be setup properly when
48 // the appropriate member functions are called.
49 setup( false, false, false );
50}
51
52OCompletionBase::~OCompletionBase()
53{
54 if( m_bAutoDelCompObj && m_pCompObj )
55 {
56 delete m_pCompObj;
57 }
58}
59
60void OCompletionBase::setDelegate( OCompletionBase *delegate )
61{
62 m_delegate = delegate;
63
64 if ( m_delegate ) {
65 m_delegate->m_bAutoDelCompObj = m_bAutoDelCompObj;
66 m_delegate->m_bHandleSignals = m_bHandleSignals;
67 m_delegate->m_bEmitSignals = m_bEmitSignals;
68 m_delegate->m_iCompletionMode = m_iCompletionMode;
69 m_delegate->m_keyMap = m_keyMap;
70 }
71}
72
73OCompletion* OCompletionBase::completionObject( bool hsig )
74{
75 if ( m_delegate )
76 return m_delegate->completionObject( hsig );
77
78 if ( !m_pCompObj )
79 {
80 setCompletionObject( new OCompletion(), hsig );
81 m_bAutoDelCompObj = true;
82 }
83 return m_pCompObj;
84}
85
86void OCompletionBase::setCompletionObject( OCompletion* compObj, bool hsig )
87{
88 if ( m_delegate ) {
89 m_delegate->setCompletionObject( compObj, hsig );
90 return;
91 }
92
93 if ( m_bAutoDelCompObj && compObj != m_pCompObj )
94 delete m_pCompObj;
95
96 m_pCompObj = compObj;
97
98 // We emit rotation and completion signals
99 // if completion object is not NULL.
100 setup( false, hsig, !m_pCompObj.isNull() );
101}
102
103// BC: Inline this function and possibly rename it to setHandleEvents??? (DA)
104void OCompletionBase::setHandleSignals( bool handle )
105{
106 if ( m_delegate )
107 m_delegate->setHandleSignals( handle );
108 else
109 m_bHandleSignals = handle;
110}
111
112void OCompletionBase::setCompletionMode( OGlobalSettings::Completion mode )
113{
114 if ( m_delegate ) {
115 m_delegate->setCompletionMode( mode );
116 return;
117 }
118
119 m_iCompletionMode = mode;
120 // Always sync up OCompletion mode with ours as long as we
121 // are performing completions.
122 if( m_pCompObj && m_iCompletionMode != OGlobalSettings::CompletionNone )
123 m_pCompObj->setCompletionMode( m_iCompletionMode );
124}
125
126bool OCompletionBase::setKeyBinding( KeyBindingType item, const OShortcut& cut )
127{
128 if ( m_delegate )
129 return m_delegate->setKeyBinding( item, cut );
130
131
132 if( !cut.isNull() )
133 {
134 for( KeyBindingMap::Iterator it = m_keyMap.begin(); it != m_keyMap.end(); ++it )
135 if( it.data() == cut ) return false;
136 }
137 m_keyMap.replace( item, cut );
138 return true;
139}
140
141void OCompletionBase::useGlobalKeyBindings()
142{
143
144/*
145
146 if ( m_delegate ) {
147 m_delegate->useGlobalKeyBindings();
148 return;
149 }
150
151 m_keyMap.clear();
152 m_keyMap.insert( TextCompletion, 0 );
153 m_keyMap.insert( PrevCompletionMatch, 0 );
154 m_keyMap.insert( NextCompletionMatch, 0 );
155 m_keyMap.insert( SubstringCompletion, 0 );
156
157*/
158
159}
160
161void OCompletionBase::setup( bool autodel, bool hsig, bool esig )
162{
163 if ( m_delegate ) {
164 m_delegate->setup( autodel, hsig, esig );
165 return;
166 }
167
168 m_bAutoDelCompObj = autodel;
169 m_bHandleSignals = hsig;
170 m_bEmitSignals = esig;
171}