summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/klistbox.cpp
Unidiff
Diffstat (limited to 'microkde/kdeui/klistbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/klistbox.cpp314
1 files changed, 314 insertions, 0 deletions
diff --git a/microkde/kdeui/klistbox.cpp b/microkde/kdeui/klistbox.cpp
new file mode 100644
index 0000000..c65b892
--- a/dev/null
+++ b/microkde/kdeui/klistbox.cpp
@@ -0,0 +1,314 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18#include <qtimer.h>
19
20#include <kglobalsettings.h>
21//US#include <kcursor.h>
22#include <kapplication.h>
23//US#include <kipc.h>
24#include <kdebug.h>
25
26#include "klistbox.h"
27
28#ifdef Q_WS_X11
29#include <X11/Xlib.h>
30#endif
31#ifdef _WIN32_
32#define Q_WS_QWS
33#endif
34KListBox::KListBox( QWidget *parent, const char *name, WFlags f )
35 : QListBox( parent, name, f )
36{
37 connect( this, SIGNAL( onViewport() ),
38 this, SLOT( slotOnViewport() ) );
39 connect( this, SIGNAL( onItem( QListBoxItem * ) ),
40 this, SLOT( slotOnItem( QListBoxItem * ) ) );
41
42 connect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *,
43 const QPoint & ) ),
44 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *,
45 const QPoint & ) ) );
46/*US
47
48 slotSettingsChanged(KApplication::SETTINGS_MOUSE);
49 if (kapp)
50 {
51 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) );
52 kapp->addKipcEventMask( KIPC::SettingsChanged );
53 }
54*/
55 m_pCurrentItem = 0L;
56//US set single to true
57 m_bUseSingle = true;
58 m_pAutoSelect = new QTimer( this );
59 connect( m_pAutoSelect, SIGNAL( timeout() ),
60 this, SLOT( slotAutoSelect() ) );
61}
62
63void KListBox::slotOnItem( QListBoxItem *item )
64{
65/*US
66 if ( item && m_bChangeCursorOverItem && m_bUseSingle )
67 viewport()->setCursor( KCursor().handCursor() );
68*/
69 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
70 m_pAutoSelect->start( m_autoSelectDelay, true );
71 m_pCurrentItem = item;
72 }
73}
74
75void KListBox::slotOnViewport()
76{
77/*US
78 if ( m_bChangeCursorOverItem )
79 viewport()->unsetCursor();
80*/
81 m_pAutoSelect->stop();
82 m_pCurrentItem = 0L;
83}
84
85
86/*US
87void KListBox::slotSettingsChanged(int category)
88{
89 if (category != KApplication::SETTINGS_MOUSE)
90 return;
91
92 m_bUseSingle = KGlobalSettings::singleClick();
93 m_bUseSingle = true;
94
95 disconnect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *,
96 const QPoint & ) ),
97 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *,
98 const QPoint & ) ) );
99// disconnect( this, SIGNAL( doubleClicked( QListBoxItem *,
100 // const QPoint & ) ),
101 // this, SLOT( slotExecute( QListBoxItem *,
102 // const QPoint & ) ) );
103
104 if( m_bUseSingle )
105 {
106 connect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *,
107 const QPoint & ) ),
108 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *,
109 const QPoint & ) ) );
110 }
111 else
112 {
113// connect( this, SIGNAL( doubleClicked( QListBoxItem *,
114 // const QPoint & ) ),
115// this, SLOT( slotExecute( QListBoxItem *,
116 // const QPoint & ) ) );
117 }
118
119 m_bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
120 m_autoSelectDelay = KGlobalSettings::autoSelectDelay();
121
122 if( !m_bUseSingle || !m_bChangeCursorOverItem )
123 viewport()->unsetCursor();
124
125}
126*/
127void KListBox::slotAutoSelect()
128{
129 // check that the item still exists
130 if( index( m_pCurrentItem ) == -1 )
131 return;
132
133 //Give this widget the keyboard focus.
134 if( !hasFocus() )
135 setFocus();
136
137#ifdef Q_WS_X11 //FIXME
138 Window root;
139 Window child;
140 int root_x, root_y, win_x, win_y;
141 uint keybstate;
142 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
143 &root_x, &root_y, &win_x, &win_y, &keybstate );
144#endif
145
146 QListBoxItem* previousItem = item( currentItem() );
147 setCurrentItem( m_pCurrentItem );
148
149 if( m_pCurrentItem ) {
150#ifndef Q_WS_QWS //FIXME
151 //Shift pressed?
152 if( (keybstate & ShiftMask) ) {
153#endif
154 bool block = signalsBlocked();
155 blockSignals( true );
156
157#ifndef Q_WS_QWS //FIXME
158 //No Ctrl? Then clear before!
159 if( !(keybstate & ControlMask) )
160 clearSelection();
161#endif
162
163//US in my QT version it is called isSelected() So what is right?
164//US bool select = !m_pCurrentItem->isSelected();
165 bool select = !m_pCurrentItem->selected();
166 bool update = viewport()->isUpdatesEnabled();
167 viewport()->setUpdatesEnabled( false );
168
169 bool down = index( previousItem ) < index( m_pCurrentItem );
170 QListBoxItem* it = down ? previousItem : m_pCurrentItem;
171 for (;it ; it = it->next() ) {
172 if ( down && it == m_pCurrentItem ) {
173 setSelected( m_pCurrentItem, select );
174 break;
175 }
176 if ( !down && it == previousItem ) {
177 setSelected( previousItem, select );
178 break;
179 }
180 setSelected( it, select );
181 }
182
183 blockSignals( block );
184 viewport()->setUpdatesEnabled( update );
185 triggerUpdate( false );
186
187 emit selectionChanged();
188
189 if( selectionMode() == QListBox::Single )
190 emit selectionChanged( m_pCurrentItem );
191 }
192#ifndef Q_WS_QWS //FIXME
193 else if( (keybstate & ControlMask) )
194 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() );
195#endif
196 else {
197 bool block = signalsBlocked();
198 blockSignals( true );
199
200//US in my QT version it is called isSelected() So what is right?
201//US if( !m_pCurrentItem->isSelected() )
202 if( !m_pCurrentItem->selected() )
203 clearSelection();
204
205 blockSignals( block );
206
207 setSelected( m_pCurrentItem, true );
208 }
209#ifndef Q_WS_QWS //FIXME
210 }
211 else
212 kdDebug() << "Thats not supposed to happen!!!!" << endl;
213#endif
214}
215
216void KListBox::emitExecute( QListBoxItem *item, const QPoint &pos )
217{
218#ifdef Q_WS_X11 //FIXME
219 Window root;
220 Window child;
221 int root_x, root_y, win_x, win_y;
222 uint keybstate;
223 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
224 &root_x, &root_y, &win_x, &win_y, &keybstate );
225#endif
226
227 m_pAutoSelect->stop();
228
229#ifndef Q_WS_QWS //FIXME
230 //Dont emit executed if in SC mode and Shift or Ctrl are pressed
231 if( !( m_bUseSingle && ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) {
232#endif
233 emit executed( item );
234 emit executed( item, pos );
235#ifndef Q_WS_QWS //FIXME
236 }
237#endif
238}
239
240//
241// 2000-16-01 Espen Sand
242// This widget is used in dialogs. It should ignore
243// F1 (and combinations) and Escape since these are used
244// to start help or close the dialog. This functionality
245// should be done in QListView but it is not (at least now)
246//
247void KListBox::keyPressEvent(QKeyEvent *e)
248{
249 if( e->key() == Key_Escape )
250 {
251 e->ignore();
252 }
253 else if( e->key() == Key_F1 )
254 {
255 e->ignore();
256 }
257 else
258 {
259 QListBox::keyPressEvent(e);
260 }
261}
262
263void KListBox::focusOutEvent( QFocusEvent *fe )
264{
265 m_pAutoSelect->stop();
266
267 QListBox::focusOutEvent( fe );
268}
269
270void KListBox::leaveEvent( QEvent *e )
271{
272 m_pAutoSelect->stop();
273
274 QListBox::leaveEvent( e );
275}
276
277void KListBox::contentsMousePressEvent( QMouseEvent *e )
278{
279 if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) {
280 bool block = signalsBlocked();
281 blockSignals( true );
282
283 clearSelection();
284
285 blockSignals( block );
286 }
287
288 QListBox::contentsMousePressEvent( e );
289}
290
291void KListBox::contentsMouseDoubleClickEvent ( QMouseEvent * e )
292{
293 QListBox::contentsMouseDoubleClickEvent( e );
294
295 QListBoxItem* item = itemAt( e->pos() );
296
297 if( item ) {
298 emit doubleClicked( item, e->globalPos() );
299
300 if( (e->button() == LeftButton) && !m_bUseSingle )
301 emitExecute( item, e->globalPos() );
302 }
303}
304
305void KListBox::slotMouseButtonClicked( int btn, QListBoxItem *item, const QPoint &pos )
306{
307 if( (btn == LeftButton) && item )
308 emitExecute( item, pos );
309}
310
311void KListBox::virtual_hook( int, void* )
312{ /*BASE::virtual_hook( id, data );*/ }
313
314//US #include "klistbox.moc"