aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-01-12 18:04:39 (GMT)
committerfluxgen <fluxgen>2003-01-12 18:04:39 (GMT)
commit66206cb19c39a002fe30211c2168d9cdd1098b53 (patch)
tree4665b00f4b4a130fbe5c03b8cfc0f8cecb25d6ca /src
parent57a53674bc402a475635db1f26bc868a0952a74a (diff)
downloadfluxbox-66206cb19c39a002fe30211c2168d9cdd1098b53.zip
fluxbox-66206cb19c39a002fe30211c2168d9cdd1098b53.tar.bz2
changed Toolbarmenu to FbTk Menu
Diffstat (limited to 'src')
-rw-r--r--src/Toolbar.cc301
-rw-r--r--src/Toolbar.hh64
2 files changed, 44 insertions, 321 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 8e72f0f..0d0cbdf 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Toolbar.cc,v 1.53 2003/01/09 18:42:32 fluxgen Exp $ 25// $Id: Toolbar.cc,v 1.54 2003/01/12 18:04:39 fluxgen Exp $
26 26
27#include "Toolbar.hh" 27#include "Toolbar.hh"
28 28
@@ -74,6 +74,41 @@
74 74
75using namespace std; 75using namespace std;
76 76
77namespace {
78class SetToolbarPlacementCmd: public FbTk::Command {
79 explicit SetToolbarPlacementCmd(Toolbar &tbar, Toolbar::Placement place):m_tbar(tbar), m_place(place) { }
80 void execute() {
81 m_tbar.setPlacement(m_place);
82 }
83private:
84 Toolbar &m_tbar;
85 Toolbar::Placement m_place;
86};
87
88void setupMenus(Toolbar &tbar) {
89 I18n *i18n = I18n::instance();
90 using namespace FBNLS;
91 FbTk::Menu &menu = tbar.menu();
92 menu.setLabel(i18n->getMessage(
93 ToolbarSet, ToolbarToolbarTitle,
94 "Toolbar"));
95 menu.setInternalMenu();
96
97 using namespace FbTk;
98 // add items
99 menu.insert("Toolbar width percent...");
100
101 RefCount<Command> start_edit(new SimpleCommand<Toolbar>(tbar, &Toolbar::edit));
102 menu.insert(i18n->getMessage(
103 ToolbarSet, ToolbarEditWkspcName,
104 "Edit current workspace name"),
105 start_edit);
106
107 menu.update();
108}
109
110}; // end anonymous
111
77// toolbar frame 112// toolbar frame
78Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num): 113Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num):
79 window(screen_num, // screen (parent) 114 window(screen_num, // screen (parent)
@@ -146,10 +181,12 @@ Toolbar::Toolbar(BScreen *scrn, size_t width):
146 image_ctrl(*scrn->getImageControl()), 181 image_ctrl(*scrn->getImageControl()),
147 clock_timer(this), // get the clock updating every minute 182 clock_timer(this), // get the clock updating every minute
148 hide_timer(&hide_handler), 183 hide_timer(&hide_handler),
149 m_toolbarmenu(*this), 184 m_toolbarmenu(*scrn->menuTheme(), scrn->getScreenNumber(), *scrn->getImageControl()),
150 m_theme(scrn->getScreenNumber()), 185 m_theme(scrn->getScreenNumber()),
151 m_place(BOTTOMCENTER) { 186 m_place(BOTTOMCENTER) {
152 187
188 setupMenus(*this);
189
153 // geometry settings 190 // geometry settings
154 frame.width = width; 191 frame.width = width;
155 frame.height = frame.label_h = 10; 192 frame.height = frame.label_h = 10;
@@ -849,16 +886,6 @@ void Toolbar::keyPressEvent(XKeyEvent &ke) {
849 screen()->getCurrentWorkspace()->setName(new_workspace_name.c_str()); 886 screen()->getCurrentWorkspace()->setName(new_workspace_name.c_str());
850 887
851 new_workspace_name.erase(); //erase temporary workspace name 888 new_workspace_name.erase(); //erase temporary workspace name
852
853 screen()->getCurrentWorkspace()->menu().hide();
854 screen()->getWorkspacemenu()->
855 remove(screen()->getCurrentWorkspace()->workspaceID() + 2);
856 screen()->getWorkspacemenu()->
857 insert(screen()->getCurrentWorkspace()->name().c_str(),
858 &screen()->getCurrentWorkspace()->menu(),
859 screen()->getCurrentWorkspace()->workspaceID() + 2);
860 screen()->getWorkspacemenu()->update();
861
862 reconfigure(); 889 reconfigure();
863 //save workspace names 890 //save workspace names
864 Fluxbox::instance()->save_rc(); 891 Fluxbox::instance()->save_rc();
@@ -914,24 +941,8 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
914 941
915 m_place = where; 942 m_place = where;
916 943
917#ifdef XINERAMA
918 int head = (screen->hasXinerama())
919 ? screen->getToolbarOnHead()
920 : -1;
921
922 if (head >= 0) { // toolbar on head nr, if -1 then over ALL heads
923 head_x = screen()->getHeadX(head);
924 head_y = screen()->getHeadY(head);
925 head_w = screen()->getHeadWidth(head);
926 head_h = screen()->getHeadHeight(head);
927 } else {
928 head_w = screen->getWidth();
929 head_h = screen->getHeight();
930 }
931#else // !XINERAMA
932 head_w = screen()->getWidth(); 944 head_w = screen()->getWidth();
933 head_h = screen()->getHeight(); 945 head_h = screen()->getHeight();
934#endif // XINERAMA
935 946
936 frame.width = head_w * screen()->getToolbarWidthPercent() / 100; 947 frame.width = head_w * screen()->getToolbarWidthPercent() / 100;
937 frame.height = m_theme.font().height(); 948 frame.height = m_theme.font().height();
@@ -1057,237 +1068,3 @@ void Toolbar::HideHandler::timeout() {
1057 toolbar->frame.window.move(toolbar->frame.x, toolbar->frame.y); 1068 toolbar->frame.window.move(toolbar->frame.x, toolbar->frame.y);
1058 } 1069 }
1059} 1070}
1060
1061
1062Toolbarmenu::Toolbarmenu(Toolbar &tb) : Basemenu(tb.screen()), m_toolbar(tb),
1063 m_placementmenu(*this) {
1064
1065 I18n *i18n = I18n::instance();
1066 using namespace FBNLS;
1067 setLabel(i18n->getMessage(
1068 ToolbarSet, ToolbarToolbarTitle,
1069 "Toolbar"));
1070 setInternalMenu();
1071
1072#ifdef XINERAMA
1073 if (m_toolbar.screen()->hasXinerama()) { // only create if we need it
1074 m_headmenu.reset(new Headmenu(this));
1075 }
1076#endif // XINERAMA
1077
1078 insert(i18n->getMessage(
1079 CommonSet, CommonPlacementTitle,
1080 "Placement"),
1081 &m_placementmenu);
1082
1083 if (m_headmenu.get()) { //TODO: NLS
1084 insert(i18n->getMessage(0, 0, "Place on Head"), m_headmenu.get());
1085 }
1086
1087 insert(i18n->getMessage(
1088 CommonSet, CommonAlwaysOnTop,
1089 "Always on top"),
1090 1);
1091 insert(i18n->getMessage(
1092 CommonSet, CommonAutoHide,
1093 "Auto hide"),
1094 2);
1095 insert(i18n->getMessage(
1096 ToolbarSet, ToolbarEditWkspcName,
1097 "Edit current workspace name"),
1098 3);
1099
1100 update();
1101
1102 if (m_toolbar.isOnTop())
1103 setItemSelected(1, true);
1104 if (m_toolbar.doAutoHide())
1105 setItemSelected(2, true);
1106}
1107
1108
1109Toolbarmenu::~Toolbarmenu() {
1110
1111}
1112
1113
1114void Toolbarmenu::itemSelected(int button, unsigned int index) {
1115 if (button == 1) {
1116 BasemenuItem *item = find(index);
1117 if (item == 0)
1118 return;
1119
1120 switch (item->function()) {
1121 case 1: {// always on top
1122 bool change = ((m_toolbar.isOnTop()) ? false : true);
1123 m_toolbar.on_top = change;
1124 screen()->saveToolbarOnTop(m_toolbar.on_top);
1125 setItemSelected(1, change);
1126
1127 if (m_toolbar.isOnTop())
1128 m_toolbar.screen()->raiseWindows(Workspace::Stack());
1129
1130 Fluxbox::instance()->save_rc();
1131 break;
1132 }
1133
1134 case 2: { // auto hide
1135 bool change = ((m_toolbar.doAutoHide()) ? false : true);
1136 m_toolbar.do_auto_hide = change;
1137 screen()->saveToolbarAutoHide(m_toolbar.do_auto_hide);
1138 setItemSelected(2, change);
1139
1140#ifdef SLIT
1141 m_toolbar.screen()->getSlit()->reposition();
1142#endif // SLIT
1143 Fluxbox::instance()->save_rc();
1144 break;
1145 }
1146
1147 case 3: // edit current workspace name
1148 m_toolbar.edit(); //set edit mode
1149 hide(); //dont show menu while editing name
1150
1151 break;
1152 }
1153 }
1154}
1155
1156
1157void Toolbarmenu::internal_hide() {
1158 Basemenu::internal_hide();
1159 if (m_toolbar.doAutoHide() && ! m_toolbar.isEditing())
1160 m_toolbar.hide_handler.timeout();
1161}
1162
1163
1164void Toolbarmenu::reconfigure() {
1165 m_placementmenu.reconfigure();
1166
1167 if (m_headmenu.get()) {
1168 m_headmenu->reconfigure();
1169 }
1170
1171 Basemenu::reconfigure();
1172}
1173
1174//TODO: fix placement
1175Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu &tm)
1176 : Basemenu(tm.m_toolbar.screen()), m_toolbarmenu(tm) {
1177
1178 I18n *i18n = I18n::instance();
1179 using namespace FBNLS;
1180 setLabel(i18n->getMessage(
1181 ToolbarSet, ToolbarToolbarPlacement,
1182 "Toolbar Placement"));
1183 setInternalMenu();
1184 setMinimumSublevels(5);
1185
1186 insert("Left Top", Toolbar::LEFTTOP);
1187 insert("Left Center", Toolbar::LEFTCENTER);
1188 insert("Left Bottom", Toolbar::LEFTBOTTOM);
1189
1190 insert(i18n->getMessage(
1191 CommonSet, CommonPlacementTopLeft,
1192 "Top Left"),
1193 Toolbar::TOPLEFT);
1194 insert("");
1195
1196 insert(i18n->getMessage(
1197 CommonSet, CommonPlacementBottomLeft,
1198 "Bottom Left"),
1199 Toolbar::BOTTOMLEFT);
1200 insert(i18n->getMessage(
1201 CommonSet, CommonPlacementTopCenter,
1202 "Top Center"),
1203 Toolbar::TOPCENTER);
1204 insert("");
1205 insert(i18n->getMessage(
1206 CommonSet, CommonPlacementBottomCenter,
1207 "Bottom Center"),
1208 Toolbar::BOTTOMCENTER);
1209 insert(i18n->getMessage(
1210 CommonSet, CommonPlacementTopRight,
1211 "Top Right"),
1212 Toolbar::TOPRIGHT);
1213 insert("");
1214 insert(i18n->getMessage(
1215 CommonSet, CommonPlacementBottomRight,
1216 "Bottom Right"),
1217 Toolbar::BOTTOMRIGHT);
1218
1219 insert("Right Top", Toolbar::RIGHTTOP);
1220 insert("Right Center", Toolbar::RIGHTCENTER);
1221 insert("Right Bottom", Toolbar::RIGHTBOTTOM);
1222 update();
1223}
1224
1225
1226void Toolbarmenu::Placementmenu::itemSelected(int button, unsigned int index) {
1227 if (button == 1) {
1228 BasemenuItem *item = find(index);
1229 if (! item)
1230 return;
1231
1232 m_toolbarmenu.m_toolbar.screen()->saveToolbarPlacement(
1233 static_cast<Toolbar::Placement>(item->function()));
1234 m_toolbarmenu.m_toolbar.setPlacement(static_cast<Toolbar::Placement>(item->function()));
1235 hide();
1236 m_toolbarmenu.m_toolbar.reconfigure();
1237
1238#ifdef SLIT
1239 // reposition the slit as well to make sure it doesn't intersect the
1240 // toolbar
1241 m_toolbarmenu.m_toolbar.screen()->getSlit()->reposition();
1242#endif // SLIT
1243 Fluxbox::instance()->save_rc();
1244 }
1245}
1246
1247#ifdef XINERAMA
1248
1249Toolbarmenu::Headmenu::Headmenu(Toolbarmenu &tm)
1250 : Basemenu(tm.m_toolbar.screen()), m_toolbarmenu(tm) {
1251
1252 I18n *i18n = I18n::instance();
1253
1254 setLabel(i18n->getMessage(0, 0, "Place on Head")); //TODO: NLS
1255 setInternalMenu();
1256
1257 int numHeads = toolbarmenu->toolbar->screen->getNumHeads();
1258 // fill menu with head entries
1259 for (int i = 0; i < numHeads; i++) {
1260 char headName[32];
1261 sprintf(headName, "Head %i", i+1); //TODO: NLS
1262 insert(i18n->getMessage(0, 0, headName), i);
1263 }
1264
1265 insert(i18n->getMessage(0, 0, "All Heads"), -1); //TODO: NLS
1266
1267 update();
1268}
1269
1270
1271void Toolbarmenu::Headmenu::itemSelected(int button, unsigned int index) {
1272 if (button == 1) {
1273 BasemenuItem *item = find(index);
1274 if (! item)
1275 return;
1276
1277 screen()->saveToolbarOnHead(
1278 static_cast<int>(item->function()));
1279
1280 hide();
1281 m_toolbarmenu.m_toolbar.reconfigure();
1282
1283
1284#ifdef SLIT
1285 // reposition the slit as well to make sure it doesn't intersect the
1286 // toolbar
1287 m_toolbarmenu.m_toolbar.screen()->getSlit()->reposition();
1288#endif // SLIT
1289 Fluxbox::instance()->save_rc();
1290 }
1291}
1292
1293#endif // XINERAMA
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index b32aea1..bf93d44 100644
--- a/src/Toolbar.hh
+++ b/src/Toolbar.hh
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Toolbar.hh,v 1.19 2003/01/09 22:10:53 fluxgen Exp $ 25// $Id: Toolbar.hh,v 1.20 2003/01/12 18:03:24 fluxgen Exp $
26 26
27#ifndef TOOLBAR_HH 27#ifndef TOOLBAR_HH
28#define TOOLBAR_HH 28#define TOOLBAR_HH
@@ -42,58 +42,6 @@ class Toolbar;
42namespace FbTk { 42namespace FbTk {
43class ImageControl; 43class ImageControl;
44}; 44};
45/**
46 Menu for toolbar.
47 @see Toolbar
48*/
49class Toolbarmenu:public Basemenu {
50public:
51 explicit Toolbarmenu(Toolbar &tb);
52 ~Toolbarmenu();
53
54 inline const Basemenu *headmenu() const { return m_headmenu.get(); }
55
56 inline Basemenu *placementmenu() { return &m_placementmenu; }
57 inline const Basemenu *placementmenu() const { return &m_placementmenu; }
58
59 void reconfigure();
60
61protected:
62 virtual void itemSelected(int button, unsigned int index);
63 virtual void internal_hide();
64
65private:
66 class Placementmenu : public Basemenu {
67 public:
68 Placementmenu(Toolbarmenu &tm);
69 protected:
70 virtual void itemSelected(int button, unsigned int index);
71 private:
72 Toolbarmenu &m_toolbarmenu;
73 };
74 friend class Placementmenu;
75
76 class Headmenu : public Basemenu {
77 public:
78 Headmenu(Toolbarmenu &tm);
79 protected:
80 virtual void itemSelected(int button, unsigned int index);
81 private:
82 Toolbarmenu &m_toolbarmenu;
83 };
84 std::auto_ptr<Headmenu> m_headmenu;
85 friend class Headmenu;
86
87
88 Toolbar &m_toolbar;
89 Placementmenu m_placementmenu;
90
91
92 friend class Toolbar;
93
94};
95
96
97 45
98/// The toolbar. 46/// The toolbar.
99/** 47/**
@@ -122,7 +70,9 @@ public:
122 /// remove icon from iconbar 70 /// remove icon from iconbar
123 void delIcon(FluxboxWindow *w); 71 void delIcon(FluxboxWindow *w);
124 72
125 inline const Toolbarmenu &menu() const { return m_toolbarmenu; } 73 inline const FbTk::Menu &menu() const { return m_toolbarmenu; }
74 inline FbTk::Menu &menu() { return m_toolbarmenu; }
75
126 /// are we in workspacename editing? 76 /// are we in workspacename editing?
127 inline bool isEditing() const { return editing; } 77 inline bool isEditing() const { return editing; }
128 /// always on top? 78 /// always on top?
@@ -200,7 +150,7 @@ private:
200 FbTk::ImageControl &image_ctrl; 150 FbTk::ImageControl &image_ctrl;
201 FbTk::Timer clock_timer; ///< timer to update clock 151 FbTk::Timer clock_timer; ///< timer to update clock
202 FbTk::Timer hide_timer; ///< timer to for auto hide toolbar 152 FbTk::Timer hide_timer; ///< timer to for auto hide toolbar
203 Toolbarmenu m_toolbarmenu; 153 FbTk::Menu m_toolbarmenu;
204 std::auto_ptr<IconBar> m_iconbar; 154 std::auto_ptr<IconBar> m_iconbar;
205 155
206 std::string new_workspace_name; ///< temp variable in edit workspace name mode 156 std::string new_workspace_name; ///< temp variable in edit workspace name mode
@@ -209,10 +159,6 @@ private:
209 Placement m_place; 159 Placement m_place;
210 160
211 friend class HideHandler; 161 friend class HideHandler;
212 friend class Toolbarmenu;
213 friend class Toolbarmenu::Placementmenu;
214
215 friend class Toolbarmenu::Headmenu;
216}; 162};
217 163
218 164