2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "KWQScrollView.h"
30 #include "KWQSignal.h"
31 #include "KWQString.h"
32 #include "KWQValueList.h"
39 KWQListBoxItem(const QString &s, bool isLabel) : string(s), isGroupLabel(isLabel) { }
42 class QListBox : public QScrollView {
44 enum SelectionMode { Single, Extended };
46 QListBox(QWidget *parent);
49 QSize sizeForNumberOfLines(int numLines) const;
51 uint count() const { return _items.count(); }
53 void setSelectionMode(SelectionMode);
56 void appendItem(const QString &s) { appendItem(s, false); }
57 void appendGroupLabel(const QString &s) { appendItem(s, true); }
58 void doneAppendingItems();
60 void setSelected(int, bool);
61 bool isSelected(int) const;
63 void setEnabled(bool enabled);
66 const KWQListBoxItem &itemAtIndex(int index) const { return _items[index]; }
68 void setWritingDirection(QPainter::TextDirection);
70 bool changingSelection() { return _changingSelection; }
71 void clicked() { _clicked.call(); }
72 void selectionChanged() { _selectionChanged.call(); }
74 virtual FocusPolicy focusPolicy() const;
75 virtual bool checksDescendantsForFocus() const;
78 void appendItem(const QString &, bool isLabel);
80 // A vector<QString> or QValueVector<QString> might be more efficient for large lists.
81 QValueList<KWQListBoxItem> _items;
83 bool _changingSelection;
87 mutable bool _widthGood;
90 KWQSignal _selectionChanged;