-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEDE_FileIconView.h
210 lines (167 loc) · 5.25 KB
/
EDE_FileIconView.h
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* $Id$
*
* EDE FileView class
* Part of edelib.
* Copyright (c) 2005-2007 EDE Authors.
*
* This program is licenced under terms of the
* GNU General Public Licence version 2 or newer.
* See COPYING for details.
*/
#ifndef EDE_FileIconView_H
#define EDE_FileIconView_H
#include <edelib/String.h>
//#include "EDE_FileView.h"
// comment this to use edelib::ExpandableGroup
//#define USE_FLU_WRAP_GROUP
#ifdef USE_FLU_WRAP_GROUP
#include "Flu_Wrap_Group.h"
#else
#include <edelib/ExpandableGroup.h>
#endif
#ifdef USE_FLU_WRAP_GROUP
class FileIconView : public Flu_Wrap_Group {
#else
class FileIconView : public edelib::ExpandableGroup {
#endif
private:
// private vars for handling selection and focus
// because group doesn't do it
int focused;
int* m_selected;
// callbacks
rename_callback_type* rename_callback_;
paste_callback_type* paste_callback_;
Fl_Callback* context_callback_;
// selection box
int select_x1,select_y1,select_x2,select_y2;
// Find the widget corresponding to real path (encoded in user_data())
Fl_Widget* find_icon(edelib::String realpath) {
for (int i=0; i<children(); i++) {
Fl_Widget* w = child(i);
char *tmp = (char*)w->user_data();
if (realpath==tmp) return w;
}
return 0;
}
// EditBox is displayed when renaming a file
// We subclass Fl_Input so we can handle keyboard events
class EditBox : public Fl_Input {
public:
EditBox(int x, int y, int w, int h, const char* label = 0) : Fl_Input(x,y,w,h,label) {}
int handle (int e);
}* editbox_;
int editbox_row;
// show editbox at specified row and make the row "invisible" (bgcolor same as fgcolor)
void show_editbox(int row);
void hide_editbox();
// This is called to actually rename file (when user presses Enter in editbox)
void finish_rename();
// Try various names and sizes for icons
Fl_Image* try_icon(edelib::String icon_name);
public:
FileIconView(int X, int Y, int W, int H, char*label=0);
// Methods for manipulating items
// They are named similarly to Browser methods, except that they take
// struct FileItem (defined in EDE_FileView.h)
// NOTE: For compatibility with Fl_Browser-based views, row is 1..children()
// as opposed to Fl_Group methods that use 0..children()-1
// This is a fltk bug
void insert(int row, FileItem *item);
void add(FileItem *item) { insert(children()+1, item); }
void remove(FileItem *item);
void remove(int row);
void update(FileItem *item);
// This method is needed because update() uses path to find item in list
void update_path(const char* oldpath,const char* newpath);
// Make row look "disabled" (actually we use it for cut operation)
void gray(int row) {
if (row<1 || row>children()) return;
Fl_Button* b = (Fl_Button*)child(row-1);
// FIXME this also means that item can't be selected
b->deactivate();
}
void ungray(int row) {
if (row<1 || row>children()) return;
Fl_Button* b = (Fl_Button*)child(row-1);
b->activate();
}
// Callback when user renames a file (takes const char* filename)
void rename_callback(rename_callback_type* cb) { rename_callback_ = cb; }
// Callback that is called by FL_PASTE event (such as drag&drop)
// (takes const char* paste_target /e.g. target directory or 0 for current directory/)
void paste_callback(paste_callback_type* cb) { paste_callback_ = cb; }
// Callback that is called on right mouse click (for e.g. context menu)
void context_callback(Fl_Callback* cb) { context_callback_ = cb; }
// Item real path (user_data)
const char* path(int row) {
if (row<1 || row>children()) return 0;
Fl_Widget* w = child(row-1);
return (const char*)w->user_data();
}
// Is item selected?
int selected(int row) {
if (row<1 || row>children()) return 0;
int i=0;
while(m_selected[i]!=0)
if (m_selected[i++]==row) return 1;
return 0;
}
// Select item (if value==1) or unselect (if value==0)
void select(int row, int value);
// Return nr. of widget that has keyboard focus
int get_focus() {
Fl_Widget* focus = Fl::focus();
int i = find(focus); // a Fl_Group method
if (i<children()) return i+1;
else return 0;
}
// Set keyboard focus to given item
void set_focus(int row) {
if (row<1 || row>children()) return;
Fl_Widget* w = child(row-1);
w->take_focus();
show_item(row);
focused=row;
}
// Scroll the view until item becomes visible
void show_item(int row);
// Overloaded handle() method
// it's currently a bit messy, see implementation comments for details
int handle(int e);
// Override draw() for selection box
void draw() {
#ifdef USE_FLU_WRAP_GROUP
Flu_Wrap_Group::draw();
#else
edelib::ExpandableGroup::draw();
#endif
if (select_x1>0 && select_y1>0) {
fl_color(33);
fl_line_style(FL_DASH);
fl_line(select_x1,select_y1,select_x1,select_y2);
fl_line(select_x1,select_y2,select_x2,select_y2);
fl_line(select_x2,select_y2,select_x2,select_y1);
fl_line(select_x2,select_y1,select_x1,select_y1);
fl_line_style(0);
}
}
// Override clear so that we can empty selected & focused values
void clear() {
focused=0;
if (m_selected) free(m_selected);
m_selected = 0;
#ifdef USE_FLU_WRAP_GROUP
Flu_Wrap_Group::clear();
scroll_to_beginning(); // move scrollbar to top
#else
edelib::ExpandableGroup::clear();
#endif
}
void start_rename() {
show_editbox(get_focus());
}
};
#endif
/* $Id */