00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ToolFactory.hh"
00025
00026
00027 #include "ButtonTool.hh"
00028 #include "ClockTool.hh"
00029 #include "SystemTray.hh"
00030 #include "IconbarTool.hh"
00031 #include "WorkspaceNameTool.hh"
00032 #include "ArrowButton.hh"
00033
00034
00035 #include "IconbarTheme.hh"
00036 #include "WorkspaceNameTheme.hh"
00037 #include "ButtonTheme.hh"
00038
00039 #include "CommandParser.hh"
00040 #include "Screen.hh"
00041 #include "Toolbar.hh"
00042 #include "fluxbox.hh"
00043
00044 #include "FbTk/FbWindow.hh"
00045
00046 namespace {
00047 class ShowMenuAboveToolbar: public FbTk::Command {
00048 public:
00049 explicit ShowMenuAboveToolbar(Toolbar &tbar):m_tbar(tbar) { }
00050 void execute() {
00051 m_tbar.screen().hideMenus();
00052
00053 const XEvent &event = Fluxbox::instance()->lastEvent();
00054 int x = event.xbutton.x_root - (m_tbar.menu().width() / 2);
00055 int y = event.xbutton.y_root - (m_tbar.menu().height() / 2);
00056
00057 if (x < 0)
00058 x = 0;
00059 else if (x + m_tbar.menu().width() > m_tbar.screen().width())
00060 x = m_tbar.screen().width() - m_tbar.menu().width();
00061
00062 if (y < 0)
00063 y = 0;
00064 else if (y + m_tbar.menu().height() > m_tbar.screen().height())
00065 y = m_tbar.screen().height() - m_tbar.menu().height();
00066
00067 m_tbar.menu().move(x, y);
00068 m_tbar.menu().show();
00069 }
00070 private:
00071 Toolbar &m_tbar;
00072 };
00073
00074 };
00075
00076 ToolFactory::ToolFactory(BScreen &screen):m_screen(screen),
00077 m_clock_theme(screen.screenNumber(), "toolbar.clock", "Toolbar.Clock"),
00078 m_button_theme(new ButtonTheme(screen.screenNumber(), "toolbar.button", "Toolbar.Button")),
00079 m_workspace_theme(new WorkspaceNameTheme(screen.screenNumber(), "toolbar.workspace", "Toolbar.Workspace")),
00080 m_iconbar_theme(screen.screenNumber(), "toolbar.iconbar", "Toolbar.Iconbar") {
00081
00082 }
00083
00084 ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &parent, Toolbar &tbar) {
00085
00086 unsigned int button_size = 24;
00087 if (tbar.theme().buttonSize() > 0)
00088 button_size = tbar.theme().buttonSize();
00089
00090 if (name == "workspacename") {
00091 WorkspaceNameTool *item = new WorkspaceNameTool(parent,
00092 *m_workspace_theme, screen());
00093 using namespace FbTk;
00094 RefCount<Command> showmenu(new ShowMenuAboveToolbar(tbar));
00095 item->button().setOnClick(showmenu);
00096 return item;
00097 } else if (name == "iconbar") {
00098 return new IconbarTool(parent, m_iconbar_theme,
00099 screen(), tbar.menu());
00100 } else if (name == "systemtray") {
00101 return new SystemTray(parent);
00102 } else if (name == "clock") {
00103 return new ClockTool(parent, m_clock_theme, screen(), tbar.menu());
00104 } else if (name == "nextworkspace" ||
00105 name == "prevworkspace") {
00106
00107 FbTk::RefCount<FbTk::Command> cmd(CommandParser::instance().parseLine(name));
00108 if (*cmd == 0)
00109 return 0;
00110
00111 ArrowButton::Type arrow_type = ArrowButton::LEFT;
00112 if (name == "nextworkspace")
00113 arrow_type = ArrowButton::RIGHT;
00114
00115 ArrowButton *win = new ArrowButton(arrow_type, parent,
00116 0, 0,
00117 button_size, button_size);
00118 win->setOnClick(cmd);
00119 return new ButtonTool(win, ToolbarItem::FIXED,
00120 dynamic_cast<ButtonTheme &>(*m_button_theme),
00121 screen().imageControl());
00122
00123 } else if (name == "nextwindow" ||
00124 name == "prevwindow") {
00125
00126 FbTk::RefCount<FbTk::Command> cmd(CommandParser::instance().parseLine(name));
00127 if (*cmd == 0)
00128 return 0;
00129
00130 ArrowButton::Type arrow_type = ArrowButton::LEFT;
00131 if (name == "nextwindow")
00132 arrow_type = ArrowButton::RIGHT;
00133
00134 ArrowButton *win = new ArrowButton(arrow_type, parent,
00135 0, 0,
00136 button_size, button_size);
00137 win->setOnClick(cmd);
00138 return new ButtonTool(win, ToolbarItem::FIXED,
00139 dynamic_cast<ButtonTheme &>(*m_button_theme),
00140 screen().imageControl());
00141
00142 }
00143
00144 return 0;
00145 }
00146
00147 void ToolFactory::updateThemes() {
00148 m_clock_theme.setAntialias(screen().antialias());
00149 m_iconbar_theme.setAntialias(screen().antialias());
00150 m_button_theme->setAntialias(screen().antialias());
00151 m_workspace_theme->setAntialias(screen().antialias());
00152 }
00153
00154
00155 int ToolFactory::maxFontHeight() const {
00156 unsigned int max_height = 0;
00157 if (max_height < m_clock_theme.font().height())
00158 max_height = m_clock_theme.font().height();
00159
00160 if (max_height < m_iconbar_theme.focusedText().font().height())
00161 max_height = m_iconbar_theme.focusedText().font().height();
00162
00163 if (max_height < m_iconbar_theme.unfocusedText().font().height())
00164 max_height = m_iconbar_theme.unfocusedText().font().height();
00165
00166 if (max_height < m_workspace_theme->font().height())
00167 max_height = m_workspace_theme->font().height();
00168
00169 return max_height;
00170 }
00171