1 // FbDesk.cc
2 // Copyright (c) 2002-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21 
22 // $Id$
23 
24 #ifndef FBDESK_HH
25 #define FBDESK_HH
26 
27 
28 #include "InputField.hh"
29 #include "Icon.hh"
30 #include "IconConfig.hh"
31 
32 #include "FbTk/Font.hh"
33 #include "FbTk/Resource.hh"
34 #include "FbTk/EventHandler.hh"
35 #include "FbTk/NotCopyable.hh"
36 #include "FbTk/Menu.hh"
37 #include "FbTk/MenuTheme.hh"
38 #include "FbTk/ImageControl.hh"
39 
40 
41 #include <string>
42 #include <list>
43 
44 namespace FbDesk {
45 
46 class FbDesk:private FbTk::NotCopyable, public FbTk::EventHandler {
47 public:
48     explicit FbDesk(const char *config_filename=0);
49     ~FbDesk();
50 
51     bool load(const std::string &config_filename);
52 
53     /// event loop
54     void handleEvent(XEvent &event);
55     void buttonPressEvent(XButtonEvent &ev);
56     void buttonReleaseEvent(XButtonEvent &ev);
57     void exposeEvent(XExposeEvent &ee);
58     void motionNotifyEvent(XMotionEvent &ev);
59     void clientMessageEvent(XClientMessageEvent &ev);
60     /// execute command
61     void execute(const std::string &commando) const;
font()62     FbTk::Font &font() { return m_font; }
63 
64 private:
65     void updateIcons();
66     void loadTheme();
67     Icon *findIcon(Window w);
68     bool loadIcons(const std::string &filename);
69     bool saveIcons(const std::string &filename) const;
70     void deleteIcons();
71     void reloadConfig();
72 
73     /// create a new icon with default values
74     void createIcon();
75     /// delete last selected icon
76     void deleteLastIcon();
77     /// initiate iconmenu
78     void setupIconMenu();
79     void setCommandFromInput();
80     void setLabelFromInput();
81     void setIconLabel();
82     void setIconCommand();
83     void updateAlpha();
84     void lockPositions();
85 
86     FbTk::Font m_font;
87     typedef std::list<Icon *> IconList;
88     IconList m_iconlist;
89 
90     Icon *m_selected_icon; ///< current icon selected for motion
91     Icon *m_last_icon; ///< last icon selected
92 
93     std::string m_config_filename;
94     int m_button_pos_x, m_button_pos_y;
95     int m_screen_width, m_screen_height;
96 
97     unsigned int m_grid_width, m_grid_height;
98     FbTk::MenuTheme m_menutheme;
99     FbTk::ImageControl m_imagectrl;
100     FbTk::Menu m_iconmenu;
101     InputField m_inputfield;
102 
103     /// the text color
104     FbTk::Color m_textcolor;
105     /// the background color the text label
106     FbTk::Color m_text_background_color;
107 
108     FbTk::ResourceManager m_resmanager;
109     FbTk::Resource<std::string> m_themefile;
110     FbTk::Resource<int> m_doubleclick_interval;
111     FbTk::Resource<std::string> m_iconfile;
112     // TODO: some of these should probably be moved to IconConfig
113     FbTk::Resource<std::string> m_fontname;
114     FbTk::Resource<std::string> m_textcolorname;
115     FbTk::Resource<std::string> m_textbackgroundname;
116     FbTk::Resource<int> m_grid_snap_x, m_grid_snap_y;
117     FbTk::Resource<Icon::TextPlacement> m_textplacement;
118     FbTk::Resource<int> m_text_alpha, m_icon_alpha;
119     FbTk::Resource<bool> m_lock_positions;
120     IconConfig m_icon_config;
121 };
122 
123 } // end namespace FbDesk
124 
125 #endif // FBDESK_HH
126