aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-04-23 00:17:51 (GMT)
committerfluxgen <fluxgen>2003-04-23 00:17:51 (GMT)
commitbb97e86a3a9b78a30a7a0b0efb9de70706a6cdb1 (patch)
treeeb019ca9290b4c384f3da597e871182aae316cf8
parent29dec75f5ddb309b98c50ad33b19423f251826aa (diff)
downloadfluxbox_pavel-bb97e86a3a9b78a30a7a0b0efb9de70706a6cdb1.zip
fluxbox_pavel-bb97e86a3a9b78a30a7a0b0efb9de70706a6cdb1.tar.bz2
minor cleaning
-rw-r--r--src/Toolbar.cc162
1 files changed, 82 insertions, 80 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 6471804..58bf1c4 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.72 2003/04/16 13:43:44 rathnor Exp $ 25// $Id: Toolbar.cc,v 1.73 2003/04/23 00:17:51 fluxgen Exp $
26 26
27#include "Toolbar.hh" 27#include "Toolbar.hh"
28 28
@@ -108,6 +108,7 @@ void setupMenus(Toolbar &tbar) {
108 tbar.screen().getToolbarWidthPercentResource(), 108 tbar.screen().getToolbarWidthPercentResource(),
109 0, 100); // min/max value 109 0, 100); // min/max value
110 110
111
111 FbTk::RefCount<FbTk::Command> reconfig_toolbar(new FbTk:: 112 FbTk::RefCount<FbTk::Command> reconfig_toolbar(new FbTk::
112 SimpleCommand<Toolbar> 113 SimpleCommand<Toolbar>
113 (tbar, &Toolbar::reconfigure)); 114 (tbar, &Toolbar::reconfigure));
@@ -119,12 +120,10 @@ void setupMenus(Toolbar &tbar) {
119 toolbar_menuitem_macro->add(save_resources); 120 toolbar_menuitem_macro->add(save_resources);
120 121
121 FbTk::RefCount<FbTk::Command> reconfig_toolbar_and_save_resource(toolbar_menuitem_macro); 122 FbTk::RefCount<FbTk::Command> reconfig_toolbar_and_save_resource(toolbar_menuitem_macro);
122
123 toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); 123 toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource);
124 124
125 tbar.menu().insert(toolbar_menuitem); 125 tbar.menu().insert(toolbar_menuitem);
126 126
127
128 menu.setInternalMenu(); 127 menu.setInternalMenu();
129 128
130 menu.insert("Layer...", &tbar.layermenu()); 129 menu.insert("Layer...", &tbar.layermenu());
@@ -193,16 +192,16 @@ Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num):
193 0, 0, // pos 192 0, 0, // pos
194 1, 1, // size 193 1, 1, // size
195 // event mask 194 // event mask
196 ButtonPressMask | ButtonReleaseMask | 195 ButtonPressMask | ButtonReleaseMask |
197 ExposureMask | 196 ExposureMask |
198 EnterWindowMask | LeaveWindowMask), 197 EnterWindowMask | LeaveWindowMask),
199 clock(window, //parent 198 clock(window, //parent
200 0, 0, // pos 199 0, 0, // pos
201 1, 1, // size 200 1, 1, // size
202 // event mask 201 // event mask
203 ButtonPressMask | ButtonReleaseMask | 202 ButtonPressMask | ButtonReleaseMask |
204 ExposureMask | 203 ExposureMask |
205 EnterWindowMask | LeaveWindowMask), 204 EnterWindowMask | LeaveWindowMask),
206 psbutton(ArrowButton::LEFT, // arrow type 205 psbutton(ArrowButton::LEFT, // arrow type
207 window, // parent 206 window, // parent
208 0, 0, // pos 207 0, 0, // pos
@@ -220,15 +219,15 @@ Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num):
220 0, 0, // pos 219 0, 0, // pos
221 1, 1), // size 220 1, 1), // size
222 hour(-1), // start with invalid number to force update 221 hour(-1), // start with invalid number to force update
223 minute(-1) 222 minute(-1) {
224 223
225{
226 FbTk::EventManager &evm = *FbTk::EventManager::instance(); 224 FbTk::EventManager &evm = *FbTk::EventManager::instance();
227 // add windows to eventmanager 225 // add windows to eventmanager
228 evm.add(evh, window); 226 evm.add(evh, window);
229 evm.add(evh, workspace_label); 227 evm.add(evh, workspace_label);
230 evm.add(evh, window_label); 228 evm.add(evh, window_label);
231 evm.add(evh, clock); 229 evm.add(evh, clock);
230
232} 231}
233 232
234Toolbar::Frame::~Frame() { 233Toolbar::Frame::~Frame() {
@@ -263,7 +262,6 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
263 m_themelistener(*this), 262 m_themelistener(*this),
264 m_layeritem(frame.window, layer) { 263 m_layeritem(frame.window, layer) {
265 264
266
267 // we need to get notified when the theme is reloaded 265 // we need to get notified when the theme is reloaded
268 m_theme.addListener(m_themelistener); 266 m_theme.addListener(m_themelistener);
269 267
@@ -435,12 +433,16 @@ void Toolbar::reconfigure() {
435 433
436 I18n *i18n = I18n::instance(); 434 I18n *i18n = I18n::instance();
437 frame.clock_w = m_theme.font().textWidth( 435 frame.clock_w = m_theme.font().textWidth(
438 i18n->getMessage( 436 i18n->
439 FBNLS::ToolbarSet, FBNLS::ToolbarNoStrftimeLength, 437 getMessage(
440 "00:00000"), 438 FBNLS::ToolbarSet,
441 strlen(i18n->getMessage( 439 FBNLS::ToolbarNoStrftimeLength,
442 FBNLS::ToolbarSet, FBNLS::ToolbarNoStrftimeLength, 440 "00:00000"),
443 "00:00000"))) + (frame.bevel_w * 4); 441 strlen(i18n->
442 getMessage(
443 FBNLS::ToolbarSet,
444 FBNLS::ToolbarNoStrftimeLength,
445 "00:00000"))) + (frame.bevel_w * 4);
444 446
445#endif // HAVE_STRFTIME 447#endif // HAVE_STRFTIME
446 448
@@ -744,6 +746,7 @@ void Toolbar::checkClock(bool redraw, bool date) {
744 dy = frame.clock.height() - dx; 746 dy = frame.clock.height() - dx;
745 dx = tmp; 747 dx = tmp;
746 } 748 }
749 frame.clock.clear();
747 m_theme.font().drawText( 750 m_theme.font().drawText(
748 frame.clock.window(), 751 frame.clock.window(),
749 screen().getScreenNumber(), 752 screen().getScreenNumber(),
@@ -800,9 +803,9 @@ void Toolbar::redrawWorkspaceLabel(bool redraw) {
800 size_t textlen = screen().getCurrentWorkspace()->name().size(); 803 size_t textlen = screen().getCurrentWorkspace()->name().size();
801 unsigned int newlen = textlen; 804 unsigned int newlen = textlen;
802 int dx = FbTk::doAlignment(frame.workspace_label_w, frame.bevel_w, 805 int dx = FbTk::doAlignment(frame.workspace_label_w, frame.bevel_w,
803 m_theme.justify(), 806 m_theme.justify(),
804 m_theme.font(), 807 m_theme.font(),
805 text, textlen, newlen); 808 text, textlen, newlen);
806 int dy = 1 + m_theme.font().ascent(); 809 int dy = 1 + m_theme.font().ascent();
807 if (m_theme.font().isRotated()) { 810 if (m_theme.font().isRotated()) {
808 int tmp = dy; 811 int tmp = dy;
@@ -810,11 +813,12 @@ void Toolbar::redrawWorkspaceLabel(bool redraw) {
810 dx = tmp; 813 dx = tmp;
811 } 814 }
812 m_theme.font().drawText( 815 m_theme.font().drawText(
813 frame.workspace_label.window(), 816 frame.workspace_label.window(),
814 screen().getScreenNumber(), 817 screen().getScreenNumber(),
815 m_theme.labelTextGC(), 818 m_theme.labelTextGC(),
816 text, newlen, 819 text, newlen,
817 dx, dy); 820 dx, dy);
821
818} 822}
819 823
820void Toolbar::edit() { 824void Toolbar::edit() {
@@ -910,7 +914,8 @@ void Toolbar::buttonReleaseEvent(XButtonEvent &re) {
910 FbTk::Menu *menu = screen().getWorkspacemenu(); 914 FbTk::Menu *menu = screen().getWorkspacemenu();
911 //move the workspace label and make it visible 915 //move the workspace label and make it visible
912 menu->move(re.x_root, re.y_root); 916 menu->move(re.x_root, re.y_root);
913 // make sure the entire menu is visible (TODO: this is repeated by other menus, make a function!) 917 // make sure the entire menu is visible
918 //!!TODO: this is repeated by other menus, make a function!)
914 int newx = menu->x(); // new x position of menu 919 int newx = menu->x(); // new x position of menu
915 int newy = menu->y(); // new y position of menu 920 int newy = menu->y(); // new y position of menu
916 if (menu->x() < 0) 921 if (menu->x() < 0)
@@ -977,68 +982,65 @@ void Toolbar::exposeEvent(XExposeEvent &ee) {
977 982
978 983
979void Toolbar::keyPressEvent(XKeyEvent &ke) { 984void Toolbar::keyPressEvent(XKeyEvent &ke) {
980 if (ke.window == frame.workspace_label && editing) { 985 if (ke.window != frame.workspace_label.window() || !editing)
986 return;
981 987
982 KeySym ks; 988 KeySym ks;
983 char keychar[1]; 989 char keychar[1];
984 XLookupString(&ke, keychar, 1, &ks, 0); 990 XLookupString(&ke, keychar, 1, &ks, 0);
985 991
986 if (ks == XK_Return || ks == XK_Escape) { 992 if (ks == XK_Return || ks == XK_Escape) {
993 editing = false;
994 Fluxbox * const fluxbox = Fluxbox::instance();
995 fluxbox->setNoFocus(false);
996 if (fluxbox->getFocusedWindow()) {
997 fluxbox->getFocusedWindow()->setInputFocus();
998 fluxbox->getFocusedWindow()->setFocusFlag(true);
999 } else
1000 XSetInputFocus(display, PointerRoot, None, CurrentTime);
987 1001
1002 if (ks == XK_Return) //change workspace name if keypress = Return
1003 screen().getCurrentWorkspace()->setName(new_workspace_name.c_str());
988 1004
989 editing = false; 1005 new_workspace_name.erase(); //erase temporary workspace name
990 Fluxbox * const fluxbox = Fluxbox::instance(); 1006 reconfigure();
991 fluxbox->setNoFocus(false); 1007 //save workspace names
992 if (fluxbox->getFocusedWindow()) { 1008 Fluxbox::instance()->save_rc();
993 fluxbox->getFocusedWindow()->setInputFocus();
994 fluxbox->getFocusedWindow()->setFocusFlag(true);
995 } else
996 XSetInputFocus(display, PointerRoot, None, CurrentTime);
997
998 if (ks == XK_Return) //change workspace name if keypress = Return
999 screen().getCurrentWorkspace()->setName(new_workspace_name.c_str());
1000 1009
1001 new_workspace_name.erase(); //erase temporary workspace name 1010 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) {
1002 reconfigure();
1003 //save workspace names
1004 Fluxbox::instance()->save_rc();
1005 1011
1006 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { 1012 if (ks == XK_BackSpace && new_workspace_name.size())
1013 new_workspace_name.erase(new_workspace_name.size()-1);
1014 else
1015 new_workspace_name += keychar[0];
1007 1016
1008 if (ks == XK_BackSpace && new_workspace_name.size())
1009 new_workspace_name.erase(new_workspace_name.size()-1);
1010 else
1011 new_workspace_name += keychar[0];
1012 1017
1018 frame.workspace_label.clear();
1019 int l = new_workspace_name.size(), tw, x;
1013 1020
1014 frame.workspace_label.clear(); 1021 tw = m_theme.font().textWidth(new_workspace_name.c_str(), l);
1015 int l = new_workspace_name.size(), tw, x; 1022 x = (frame.workspace_label_w - tw) / 2;
1016 1023
1017 tw = m_theme.font().textWidth(new_workspace_name.c_str(), l); 1024 if (x < (signed) frame.bevel_w)
1018 x = (frame.workspace_label_w - tw) / 2; 1025 x = frame.bevel_w;
1026 int dy = 1 + m_theme.font().ascent();
1027 if (m_theme.font().isRotated()) {
1028 int tmp = dy;
1029 dy = frame.workspace_label_w - x;
1030 x = tmp;
1031 }
1019 1032
1020 if (x < (signed) frame.bevel_w) 1033 m_theme.font().drawText(
1021 x = frame.bevel_w; 1034 frame.workspace_label.window(),
1022 int dy = 1 + m_theme.font().ascent(); 1035 screen().getScreenNumber(),
1023 if (m_theme.font().isRotated()) { 1036 screen().getWindowStyle()->l_text_focus_gc,
1024 int tmp = dy; 1037 new_workspace_name.c_str(), l,
1025 dy = frame.workspace_label_w - x; 1038 x, dy);
1026 x = tmp;
1027 }
1028 1039
1029 m_theme.font().drawText( 1040 XDrawRectangle(display, frame.workspace_label.window(),
1030 frame.workspace_label.window(), 1041 screen().getWindowStyle()->l_text_focus_gc, x + tw, 0, 1,
1031 screen().getScreenNumber(), 1042 frame.label_h - 1);
1032 screen().getWindowStyle()->l_text_focus_gc, 1043 }
1033 new_workspace_name.c_str(), l,
1034 x, dy);
1035
1036 XDrawRectangle(display, frame.workspace_label.window(),
1037 screen().getWindowStyle()->l_text_focus_gc, x + tw, 0, 1,
1038 frame.label_h - 1);
1039 }
1040
1041 }
1042} 1044}
1043 1045
1044 1046