aboutsummaryrefslogtreecommitdiff
path: root/src/Toolbar.cc
diff options
context:
space:
mode:
authorrathnor <rathnor>2004-08-25 17:16:40 (GMT)
committerrathnor <rathnor>2004-08-25 17:16:40 (GMT)
commit5337fc6640efbe911682568b6281850fd322e4bb (patch)
treeb2a722b45550cee7dc612b113ddebd9395841ab7 /src/Toolbar.cc
parentf32969d4e5a18bddd426b481824eb50902cba5de (diff)
downloadfluxbox-5337fc6640efbe911682568b6281850fd322e4bb.zip
fluxbox-5337fc6640efbe911682568b6281850fd322e4bb.tar.bz2
fix up theming of the toolbar
Diffstat (limited to 'src/Toolbar.cc')
-rw-r--r--src/Toolbar.cc98
1 files changed, 67 insertions, 31 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index caa3eca..082a7f2 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.147 2004/07/14 23:39:29 fluxgen Exp $ 25// $Id: Toolbar.cc,v 1.148 2004/08/25 17:16:40 rathnor Exp $
26 26
27#include "Toolbar.hh" 27#include "Toolbar.hh"
28 28
@@ -63,11 +63,8 @@
63#include <X11/keysym.h> 63#include <X11/keysym.h>
64 64
65#include <cstring> 65#include <cstring>
66#include <cstdio>
67#include <iterator> 66#include <iterator>
68 67
69#include <iostream>
70
71using namespace std; 68using namespace std;
72 69
73template<> 70template<>
@@ -248,9 +245,6 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, size_t width):
248 frame.bevel_w = 1; 245 frame.bevel_w = 1;
249 frame.grab_x = frame.grab_y = 0; 246 frame.grab_x = frame.grab_y = 0;
250 247
251 // set antialias on themes
252 m_tool_factory.updateThemes();
253
254 // setup hide timer 248 // setup hide timer
255 m_hide_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay()); 249 m_hide_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay());
256 FbTk::RefCount<FbTk::Command> toggle_hidden(new FbTk::SimpleCommand<Toolbar>(*this, &Toolbar::toggleHidden)); 250 FbTk::RefCount<FbTk::Command> toggle_hidden(new FbTk::SimpleCommand<Toolbar>(*this, &Toolbar::toggleHidden));
@@ -457,6 +451,11 @@ void Toolbar::reconfigure() {
457 if (theme().shape() && m_shape.get()) 451 if (theme().shape() && m_shape.get())
458 m_shape->update(); 452 m_shape->update();
459 453
454 ItemList::iterator item_it = m_item_list.begin();
455 ItemList::iterator item_it_end = m_item_list.end();
456 for (item_it = m_item_list.begin(); item_it != item_it_end; ++item_it) {
457 (*item_it)->renderTheme();
458 }
460 459
461 rearrangeItems(); 460 rearrangeItems();
462 461
@@ -554,12 +553,14 @@ void Toolbar::exposeEvent(XExposeEvent &ee) {
554 553
555void Toolbar::handleEvent(XEvent &event) { 554void Toolbar::handleEvent(XEvent &event) {
556 /* Commented out by Simon 16jun04, since it causes LOTS of rearrangeItems 555 /* Commented out by Simon 16jun04, since it causes LOTS of rearrangeItems
557 particularly on startup. Can't figure out why this is needed. 556 particularly on startup. This was needed to resize when tool changes its own
557 size, but it has too many side effects. Use the resizeSig in ToolbarItem instead.
558
558 if (event.type == ConfigureNotify && 559 if (event.type == ConfigureNotify &&
559 event.xconfigure.window != window().window()) { 560 event.xconfigure.window != window().window()) {
560 rearrangeItems(); 561 rearrangeItems();
561 } 562 }
562 */ 563*/
563} 564}
564 565
565void Toolbar::update(FbTk::Subject *subj) { 566void Toolbar::update(FbTk::Subject *subj) {
@@ -870,16 +871,24 @@ void Toolbar::saveOnHead(int head) {
870 reconfigure(); 871 reconfigure();
871} 872}
872 873
874/*
875 * Place items next to each other, with a bevel width between,
876 * above and below each item. BUT, if there is no bevel width, then
877 * borders should be merged for evenness.
878 */
879
873void Toolbar::rearrangeItems() { 880void Toolbar::rearrangeItems() {
874 if (m_resize_lock || screen().isShuttingdown() || 881 if (m_resize_lock || screen().isShuttingdown() ||
875 m_item_list.empty()) 882 m_item_list.empty())
876 return; 883 return;
884
877 // lock this 885 // lock this
878 m_resize_lock = true; 886 m_resize_lock = true;
879 // calculate size for fixed items 887 // calculate size for fixed items
880 ItemList::iterator item_it = m_item_list.begin(); 888 ItemList::iterator item_it = m_item_list.begin();
881 ItemList::iterator item_it_end = m_item_list.end(); 889 ItemList::iterator item_it_end = m_item_list.end();
882 int fixed_width = 0; // combined size of all fixed items 890 int bevel_width = theme().bevelWidth();
891 int fixed_width = bevel_width; // combined size of all fixed items
883 int fixed_items = 0; // number of fixed items 892 int fixed_items = 0; // number of fixed items
884 int relative_items = 0; 893 int relative_items = 0;
885 int last_bw = 0; // we show the largest border of adjoining items 894 int last_bw = 0; // we show the largest border of adjoining items
@@ -888,20 +897,32 @@ void Toolbar::rearrangeItems() {
888 if (!(*item_it)->active()) 897 if (!(*item_it)->active())
889 continue; 898 continue;
890 899
891 if (!first) { 900 int borderW = (*item_it)->borderWidth();
892 if ((*item_it)->borderWidth() > last_bw) 901
893 fixed_width += (*item_it)->borderWidth(); 902 if (bevel_width > 0) {
894 else 903 // the bevel and border are fixed whether relative or not
895 fixed_width += last_bw; 904 fixed_width += bevel_width + 2*borderW;
896 } else 905 } else {
906 if (!first) {
907 if (borderW > last_bw)
908 fixed_width += borderW;
909 else
910 fixed_width += last_bw;
911 } else {
897 first = false; 912 first = false;
913 }
914 }
898 915
899 last_bw = (*item_it)->borderWidth(); 916 last_bw = borderW;
900 917
901 if ((*item_it)->type() == ToolbarItem::FIXED) { 918 if ((*item_it)->type() == ToolbarItem::FIXED) {
902 fixed_width += (*item_it)->width(); 919 fixed_width += (*item_it)->width();
903 fixed_items++; 920 fixed_items++;
904 } else if ((*item_it)->type() == ToolbarItem::RELATIVE) { 921 } else if ((*item_it)->type() == ToolbarItem::SQUARE) {
922 fixed_width += height() - 2*bevel_width;
923 if (bevel_width != 0) fixed_width -= 2*borderW;
924 fixed_items++;
925 } else {
905 relative_items++; 926 relative_items++;
906 } 927 }
907 } 928 }
@@ -916,26 +937,36 @@ void Toolbar::rearrangeItems() {
916 relative_width = 0; 937 relative_width = 0;
917 else { // size left after fixed items / number of relative items 938 else { // size left after fixed items / number of relative items
918 relative_width = (width() - fixed_width)/relative_items; 939 relative_width = (width() - fixed_width)/relative_items;
919 rounding_error = width() - fixed_width - relative_items*relative_width; 940 rounding_error = width() - fixed_width - relative_items*(relative_width);
920 } 941 }
921 } 942 }
943
922 // now move and resize the items 944 // now move and resize the items
923 // borderWidth added back on straight away 945 // borderWidth added back on straight away
924 int next_x = -m_item_list.front()->borderWidth(); // list isn't empty 946 int next_x = -m_item_list.front()->borderWidth(); // list isn't empty
947 if (bevel_width != 0)
948 next_x = 0;
949
925 last_bw = 0; 950 last_bw = 0;
926 for (item_it = m_item_list.begin(); item_it != item_it_end; ++item_it) { 951 for (item_it = m_item_list.begin(); item_it != item_it_end; ++item_it) {
952 int borderW = (*item_it)->borderWidth();
927 if (!(*item_it)->active()) { 953 if (!(*item_it)->active()) {
928 (*item_it)->hide(); 954 (*item_it)->hide();
929 // make sure it still gets told the toolbar height 955 // make sure it still gets told the toolbar height
930 (*item_it)->resize(1, height()); // width of 0 changes to 1 anyway 956 (*item_it)->resize(1, height()-2*(bevel_width+borderW)); // width of 0 changes to 1 anyway
931 continue; 957 continue;
932 } 958 }
933 int borderW = (*item_it)->borderWidth(); 959 int offset = bevel_width;
934 960 int size_offset = 2*(borderW + bevel_width);
935 if (borderW > last_bw) 961
936 next_x += borderW; 962 if (bevel_width == 0) {
937 else 963 offset = -borderW;
938 next_x += last_bw; 964 size_offset = 0;
965 if (borderW > last_bw)
966 next_x += borderW;
967 else
968 next_x += last_bw;
969 }
939 last_bw = borderW; 970 last_bw = borderW;
940 971
941 if ((*item_it)->type() == ToolbarItem::RELATIVE) { 972 if ((*item_it)->type() == ToolbarItem::RELATIVE) {
@@ -944,14 +975,19 @@ void Toolbar::rearrangeItems() {
944 extra = 1; 975 extra = 1;
945 --rounding_error; 976 --rounding_error;
946 } 977 }
947 978 (*item_it)->moveResize(next_x + offset, offset, extra + relative_width, height() - size_offset);
948 (*item_it)->moveResize(next_x - borderW, -borderW, extra + relative_width, height()); 979 } else if ((*item_it)->type() == ToolbarItem::SQUARE) {
980 (*item_it)->moveResize(next_x + offset, offset,
981 height() - size_offset, height() - size_offset);
949 } else { // fixed size 982 } else { // fixed size
950 (*item_it)->moveResize(next_x - borderW, -borderW, 983 (*item_it)->moveResize(next_x + offset, offset,
951 (*item_it)->width(), height()); 984 (*item_it)->width(), height() - size_offset);
952 } 985 }
953 (*item_it)->show(); 986 (*item_it)->show();
954 next_x += (*item_it)->width(); 987 next_x += (*item_it)->width() + bevel_width;
988 if (bevel_width != 0)
989 next_x += 2*borderW;
990
955 } 991 }
956 // unlock 992 // unlock
957 m_resize_lock = false; 993 m_resize_lock = false;