libede:FileSystemBox : added navigateFolders feature and NotifyNodeOpen
[ede] / explorer / src / NotificationBox.ec
1 /*
2 public import "ecere"
3
4 static class MsgLine : struct
5 {
6    MsgLine prev, next;
7    char * string;
8    int len;
9 };
10
11 public class NotificationBox : Window
12 {
13    background = activeBorder;
14    borderStyle = contour;
15    //hasClose = true;
16    //tabCycle = true;
17    
18    AutoDestroyThread autoDestroy { box = this };
19
20 public:
21    property char * contents
22    {
23       set
24       {
25          FreeLines();
26          if(value)
27          {
28             int len = strlen(value);
29             int start = 0;
30             int c;
31             for(c = 0; c <= len; c++)
32             {
33                if(c == len || value[c] == '\n')
34                {
35                   MsgLine line { };
36                   lines.Add(line);
37                   if(line)
38                   {
39                      line.len = c - start;
40                      line.string = new char[line.len+1];
41                      CopyBytes(line.string, value + start, line.len);
42                      line.string[line.len] = '\0';
43                      start = c+1;
44                   }
45                }
46             }
47          }
48       }
49    };
50    Seconds delay;
51    GuiApplication app;
52    Window reactivate;
53
54 private:
55    OldList lines;
56    int totalWidth, totalHeight, lineHeight;
57
58    ~NotificationBox()
59    {
60       FreeLines();
61    }
62
63    */
64    /*
65    bool ButtonActivate(Window control, bool active, Window previous)
66    {
67       control.isDefault = true;
68       return true;
69    }
70    */
71    /*
72
73    bool OnPostCreate()
74    {
75       if(!delay)
76          autoDestroy.delay = 1;
77       else
78          autoDestroy.delay = delay;
79       autoDestroy.app = app;
80       autoDestroy.Create();
81       return true;
82    }
83
84    */
85    /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
86    {
87       if(reactivate)
88          reactivate.Activate();
89       return true;
90    }*/
91    /*
92
93    bool OnResizing(int *w, int *h)
94    {
95       *w = Max(*w, Max(totalWidth, 144) + 24);
96
97       *h = Max(*h, Max(totalHeight, 33));// + 40);
98       return true;
99    }
100
101    void OnRedraw(Surface surface)
102    {
103       MsgLine line;
104       //int y = (clientSize.h - 33 - totalHeight) / 2;
105       int y = (clientSize.h - totalHeight) / 2;
106       for(line = lines.first; line; line = line.next)
107       {
108          surface.WriteText((clientSize.w - totalWidth) / 2, y, line.string, line.len);
109          y += lineHeight;
110       }
111    }
112
113    bool OnLoadGraphics()
114    {
115       MsgLine line;
116
117       totalHeight = 0;
118       for(line = lines.first; line; line = line.next)
119       {
120          Size size;
121          if(!line.string[0])
122             display.FontExtent(fontObject, " ", 1, (int *)&size.w, (int *)&size.h);
123          else
124             display.FontExtent(fontObject, line.string, strlen(line.string), (int *)&size.w, (int *)&size.h);
125          if(size.h)
126             lineHeight = size.h;
127          totalWidth = Max(totalWidth, size.w);
128          totalHeight += size.h;
129       }
130       return true;
131    }
132
133    void FreeLines()
134    {
135       MsgLine line;
136       for(line = lines.first; line; line = line.next)
137          delete line.string;
138       lines.Free(null);
139    }
140 };
141
142 class AutoDestroyThread : Thread
143 {
144    GuiApplication app;
145    NotificationBox box;
146    Seconds delay;
147
148    unsigned int Main()
149    {
150       int c;
151       int r = 5;
152       int w, h;
153       Sleep(delay);
154       app.Lock();
155          w = box.size.w;
156          h = box.size.h;
157       app.Unlock();
158       for(c = 0; c < r; c--)
159       {
160          //int vw = w / r;
161          int vh = h / r / 2 - c * h / (r * 2);
162          app.Lock();
163             //box.position.x += vw / 2;
164             box.position.y += vh / 2;
165             //box.size.w -= vw;
166             box.size.h -= vh;
167             box.Update(null);
168          app.Unlock();
169          Sleep(0.5 / r);
170       }
171       app.Lock();
172          box.Destroy(0);
173       app.Unlock();
174       return 0;
175    }
176 }
177
178 */