summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/ListBox.h
blob: 6d94d747058f02644e9a762ce42198da51359439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    ListBox ActiveWindow class
*/

#ifndef ListBox_h
#define ListBox_h

#include "Types.h"
#include "ScrollWindow.h"
#include "List.h"

// +--------------------------------------------------------------------+

class Bitmap;
class ListBox;
class ListBoxCell;
class ListBoxItem;
class ListBoxColumn;

// +--------------------------------------------------------------------+

class ListBox : public ScrollWindow
{
public:
    enum SORT   {  LIST_SORT_NUMERIC_DESCENDING = -2,
        LIST_SORT_ALPHA_DESCENDING,
        LIST_SORT_NONE,
        LIST_SORT_ALPHA_ASCENDING,
        LIST_SORT_NUMERIC_ASCENDING,
        LIST_SORT_NEVER
    };

    enum ALIGN  {  LIST_ALIGN_LEFT   = DT_LEFT,
        LIST_ALIGN_CENTER = DT_CENTER,
        LIST_ALIGN_RIGHT  = DT_RIGHT
    };

    enum STYLE  {  LIST_ITEM_STYLE_PLAIN,
        LIST_ITEM_STYLE_BOX,
        LIST_ITEM_STYLE_FILLED_BOX
    };

    ListBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid);
    ListBox(Screen* s,       int ax, int ay, int aw, int ah, DWORD aid);
    virtual ~ListBox();

    // Operations:
    virtual void      DrawContent(const Rect& ctrl_rect);

    // Event Target Interface:
    virtual int       OnMouseMove(int x, int y);
    virtual int       OnLButtonDown(int x, int y);
    virtual int       OnLButtonUp(int x, int y);
    virtual int       OnMouseWheel(int wheel);
    virtual int       OnClick();

    virtual int       OnKeyDown(int vk, int flags);

    // pseudo-events:
    virtual int       OnDragStart(int x, int y);
    virtual int       OnDragDrop(int x, int y, ActiveWindow* source);

    // Property accessors:
    int            NumItems();
    int            NumColumns();

    Text           GetItemText(int index);
    void           SetItemText(int index, const char* text);
    DWORD          GetItemData(int index);
    void           SetItemData(int index, DWORD data);
    Bitmap*        GetItemImage(int index);
    void           SetItemImage(int index, Bitmap* img);
    Color          GetItemColor(int index);
    void           SetItemColor(int index, Color c);

    Text           GetItemText(int index, int column);
    void           SetItemText(int index, int column, const char* text);
    DWORD          GetItemData(int index, int column);
    void           SetItemData(int index, int column, DWORD data);
    Bitmap*        GetItemImage(int index, int column);
    void           SetItemImage(int index, int column, Bitmap* img);

    int            AddItem(const char* text);
    int            AddImage(Bitmap* img);
    int            AddItemWithData(const char* text, int data);
    void           InsertItem(int index, const char* text);
    void           InsertItemWithData(int index, const char* text, int data);
    void           ClearItems();
    void           RemoveItem(int index);
    void           RemoveSelectedItems();

    void           AddColumn(const char* title,
    int width,
    int align = ListBox::LIST_ALIGN_LEFT,
    int sort  = ListBox::LIST_SORT_NONE);

    Text           GetColumnTitle(int index);
    void           SetColumnTitle(int index, const char* title);
    int            GetColumnWidth(int index);
    void           SetColumnWidth(int index, int width);
    int            GetColumnAlign(int index);
    void           SetColumnAlign(int index, int align);
    int            GetColumnSort(int index);
    void           SetColumnSort(int index, int sort);
    Color          GetColumnColor(int index);
    void           SetColumnColor(int index, Color c);

    Color          GetItemColor(int index, int column);

    int            GetMultiSelect();
    void           SetMultiSelect(int nNewValue);
    bool           GetShowHeadings();
    void           SetShowHeadings(bool nNewValue);
    Color          GetSelectedColor();
    void           SetSelectedColor(Color c);

    int            GetItemStyle() const;
    void           SetItemStyle(int style);
    int            GetSelectedStyle() const;
    void           SetSelectedStyle(int style);

    bool           IsSelected(int index);
    void           SetSelected(int index, bool bNewValue=true);
    void           ClearSelection();

    int            GetSortColumn();
    void           SetSortColumn(int col_index);
    int            GetSortCriteria();
    void           SetSortCriteria(SORT sort);
    void           SortItems();
    void           SizeColumns();

    // read-only:
    virtual int    GetListIndex();
    virtual int    GetLineCount();
    virtual int    GetSelCount();
    virtual int    GetSelection();
    virtual Text   GetSelectedItem();

protected:
    int            IndexFromPoint(int x, int y) const;

    // properties:
    List<ListBoxItem>    items;
    List<ListBoxColumn>  columns;

    bool           show_headings;
    int            multiselect;
    int            list_index;
    int            selcount;

    Color          selected_color;

    int            sort_column;
    int            item_style;
    int            seln_style;
};

#endif  // ListBox_h