1 #ifndef ATASKS_H_
2 #define ATASKS_H_
3 
4 #include "ywindow.h"
5 #include "ytimer.h"
6 #include "yaction.h"
7 #include "ypopup.h"
8 
9 class TaskPane;
10 class TaskButton;
11 class TaskBarApp;
12 class IAppletContainer;
13 class ClientData;
14 class YMenu;
15 
16 class TaskBarApp {
17 public:
18     TaskBarApp(ClientData* frame, TaskButton* button);
19     virtual ~TaskBarApp();
20 
21     void activate() const;
getFrame()22     ClientData* getFrame() const { return fFrame; }
button()23     TaskButton* button() const { return fButton; }
24 
25     void setShown(bool show);
26     bool getShown() const;
27 
28     int getOrder() const;
29     void setFlash(bool urgent);
30     void setToolTip(const mstring& tip);
31     void repaint();
32 
33     mstring getTitle();
34     mstring getIconTitle();
35 
36 private:
37     ClientData* fFrame;
38     TaskButton* fButton;
39     bool fShown;
40 };
41 
42 class TaskButton:
43     public YWindow,
44     private YTimerListener,
45     private YPopDownListener,
46     private YActionListener
47 {
48 public:
49     TaskButton(TaskPane* taskPane);
50     virtual ~TaskButton();
51 
deselect()52     void deselect() { selected = 0; }
53     void setShown(TaskBarApp* app, bool show);
54     bool getShown();
55     virtual bool isFocusTraversable();
56     virtual void updateToolTip();
57 
58     virtual void paint(Graphics& g, const YRect& r);
59     virtual void handleButton(const XButtonEvent& button);
60     virtual void handleClick(const XButtonEvent& up, int count);
61     virtual void handleCrossing(const XCrossingEvent& crossing);
62     virtual void handleDNDEnter();
63     virtual void handleDNDLeave();
64     virtual bool handleBeginDrag(const XButtonEvent&, const XMotionEvent&);
65     virtual void handleExpose(const XExposeEvent& expose);
66     virtual void configure(const YRect2& r);
67     virtual void repaint();
68     virtual void actionPerformed(YAction action, unsigned modifiers);
69     virtual void handlePopDown(YPopupWindow *popup);
70 
71     void popupGroup();
72     void activate() const;
73     void addApp(TaskBarApp* app);
74     void remove(TaskBarApp* tapp);
75     void setFlash(bool urgent);
flashing()76     bool flashing() const { return fFlashing; }
77     int getOrder() const;
78     int getCount() const;
79 
80     TaskBarApp* getNextShown(TaskBarApp* tapp) const;
81     TaskBarApp* getPrevShown(TaskBarApp* tapp) const;
getActive()82     TaskBarApp* getActive() const { return fActive; }
getFrame()83     ClientData* getFrame() const { return fActive->getFrame(); }
taskPane()84     TaskPane* taskPane() const { return fTaskPane; }
grouping()85     int grouping() const { return fTaskGrouping; }
86     int estimate();
87     static unsigned maxHeight();
88 
89 private:
90     TaskPane* fTaskPane;
91     TaskBarApp* fActive;
92     const int fTaskGrouping;
93     bool fRepainted;
94     bool fShown;
95     bool fFlashing;
96     bool fFlashOn;
97     timeval fFlashStart;
98     int selected;
99     lazy<YTimer> fFlashTimer;
100     lazy<YTimer> fRaiseTimer;
101 
102     typedef YArray<TaskBarApp*> GroupType;
103     typedef GroupType::IterType IterGroup;
104     GroupType fGroup;
105     lazy<YMenu> fMenu;
106 
107     virtual bool handleTimer(YTimer* t);
108     YFont getFont();
109     static YFont getNormalFont();
110     static YFont getActiveFont();
111 };
112 
113 class TaskPane: public YWindow, private YTimerListener {
114 public:
115     TaskPane(IAppletContainer* taskBar, YWindow* parent);
116     ~TaskPane();
117 
118     void insert(TaskBarApp* tapp);
119     void remove(TaskBarApp* tapp);
120     void insert(TaskButton* task);
121     void remove(TaskButton* task);
122     TaskBarApp* addApp(ClientData* frame);
123     TaskBarApp* findApp(ClientData* frame);
124     TaskBarApp* getActiveApp();
125     TaskBarApp* predecessor(TaskBarApp* tapp);
126     TaskBarApp* successor(TaskBarApp* tapp);
127     TaskButton* getActiveButton();
128 
129     static unsigned maxHeight();
130     void relayout(bool force = false);
131     void relayoutNow(bool force = false);
132 
133     virtual void configure(const YRect2& r);
134     virtual void handleClick(const XButtonEvent& up, int count);
135     virtual void handleMotion(const XMotionEvent& motion);
136     virtual void handleButton(const XButtonEvent& button);
137     virtual void handleExpose(const XExposeEvent& expose);
138     virtual void paint(Graphics& g, const YRect& r);
139 
140     void startDrag(TaskButton* drag, int byMouse, int sx, int sy);
141     void processDrag(int mx, int my);
142     void endDrag();
dragging()143     TaskButton* dragging() const { return fDragging; }
144 
145     void switchToPrev();
146     void switchToNext();
147     void movePrev();
148     void moveNext();
149 
grouping()150     int grouping() const { return fTaskGrouping; }
151     void regroup();
152 
153 private:
154     IAppletContainer* fTaskBar;
155 
156     typedef YObjectArray<TaskBarApp> AppsType;
157     typedef AppsType::IterType IterApps;
158     AppsType fApps;
159     typedef YObjectArray<TaskButton> TaskType;
160     typedef TaskType::IterType IterTask;
161     TaskType fTasks;
162 
163     lazy<YTimer> fRelayoutTimer;
164     virtual bool handleTimer(YTimer* t);
165 
166     TaskButton* fDragging;
167     int fDragX;
168     int fDragY;
169 
170     bool fNeedRelayout;
171     bool fForceImmediate;
172     int fTaskGrouping;
173 };
174 
175 #endif
176 
177 // vim: set sw=4 ts=4 et:
178