aboutsummaryrefslogtreecommitdiff
path: root/src/Toolbar.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Toolbar.cc')
-rw-r--r--src/Toolbar.cc95
1 files changed, 80 insertions, 15 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 6ca42c1..035fdd6 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -599,6 +599,8 @@ void Toolbar::update(FbTk::Subject *subj) {
599 599
600void Toolbar::setPlacement(Toolbar::Placement where) { 600void Toolbar::setPlacement(Toolbar::Placement where) {
601 // disable vertical toolbar 601 // disable vertical toolbar
602
603/*
602 switch (where) { 604 switch (where) {
603 case LEFTTOP: 605 case LEFTTOP:
604 case LEFTCENTER: 606 case LEFTCENTER:
@@ -611,6 +613,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
611 default: 613 default:
612 break; 614 break;
613 } 615 }
616*/
614 617
615 *m_rc_placement = where; 618 *m_rc_placement = where;
616 int head_x = 0, 619 int head_x = 0,
@@ -626,6 +629,10 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
626 head_h = screen().getHeadHeight(head); 629 head_h = screen().getHeadHeight(head);
627 } 630 }
628 631
632 FbTk::Orientation was_orient = FbTk::ROT0;
633 if (!m_item_list.empty())
634 was_orient = m_item_list.front()->orientation(); // all save orient (for rendering)
635
629 int bevel_width = theme().bevelWidth(); 636 int bevel_width = theme().bevelWidth();
630 int border_width = theme().border().width(); 637 int border_width = theme().border().width();
631 638
@@ -657,6 +664,8 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
657 if (bevel_width <= border_width) 664 if (bevel_width <= border_width)
658 bevel_width = border_width + 1; 665 bevel_width = border_width + 1;
659 666
667 FbTk::Orientation orient = FbTk::ROT0;
668
660 switch (where) { 669 switch (where) {
661 case TOPLEFT: 670 case TOPLEFT:
662 frame.x = head_x; 671 frame.x = head_x;
@@ -703,7 +712,6 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
703 break; 712 break;
704 713
705 case BOTTOMCENTER: // default is BOTTOMCENTER 714 case BOTTOMCENTER: // default is BOTTOMCENTER
706 default:
707 frame.x = head_x + (head_w - frame.width) / 2 - border_width; 715 frame.x = head_x + (head_w - frame.width) / 2 - border_width;
708 frame.y = head_y + head_h - frame.height - border_width*2; 716 frame.y = head_y + head_h - frame.height - border_width*2;
709 frame.x_hidden = frame.x; 717 frame.x_hidden = frame.x;
@@ -712,6 +720,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
712 m_shape->setPlaces(Shape::TOPRIGHT | Shape::TOPLEFT); 720 m_shape->setPlaces(Shape::TOPRIGHT | Shape::TOPLEFT);
713 break; 721 break;
714 case LEFTCENTER: 722 case LEFTCENTER:
723 orient = FbTk::ROT90;
715 frame.x = head_x; 724 frame.x = head_x;
716 frame.y = head_y + (head_h - frame.height)/2 - border_width; 725 frame.y = head_y + (head_h - frame.height)/2 - border_width;
717 frame.x_hidden = frame.x - frame.width + bevel_width + border_width; 726 frame.x_hidden = frame.x - frame.width + bevel_width + border_width;
@@ -720,6 +729,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
720 m_shape->setPlaces(Shape::TOPRIGHT | Shape::BOTTOMRIGHT); 729 m_shape->setPlaces(Shape::TOPRIGHT | Shape::BOTTOMRIGHT);
721 break; 730 break;
722 case LEFTTOP: 731 case LEFTTOP:
732 orient = FbTk::ROT90;
723 frame.x = head_x; 733 frame.x = head_x;
724 frame.y = head_y; 734 frame.y = head_y;
725 frame.x_hidden = frame.x - frame.width + bevel_width + border_width; 735 frame.x_hidden = frame.x - frame.width + bevel_width + border_width;
@@ -728,6 +738,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
728 m_shape->setPlaces(Shape::TOPRIGHT | Shape::BOTTOMRIGHT); 738 m_shape->setPlaces(Shape::TOPRIGHT | Shape::BOTTOMRIGHT);
729 break; 739 break;
730 case LEFTBOTTOM: 740 case LEFTBOTTOM:
741 orient = FbTk::ROT90;
731 frame.x = head_x; 742 frame.x = head_x;
732 frame.y = head_y + head_h - frame.height - border_width*2; 743 frame.y = head_y + head_h - frame.height - border_width*2;
733 frame.x_hidden = frame.x - frame.width + bevel_width + border_width; 744 frame.x_hidden = frame.x - frame.width + bevel_width + border_width;
@@ -736,6 +747,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
736 m_shape->setPlaces(Shape::TOPRIGHT | Shape::BOTTOMRIGHT); 747 m_shape->setPlaces(Shape::TOPRIGHT | Shape::BOTTOMRIGHT);
737 break; 748 break;
738 case RIGHTCENTER: 749 case RIGHTCENTER:
750 orient = FbTk::ROT270;
739 frame.x = head_x + head_w - frame.width - border_width*2; 751 frame.x = head_x + head_w - frame.width - border_width*2;
740 frame.y = head_y + (head_h - frame.height)/2 - border_width; 752 frame.y = head_y + (head_h - frame.height)/2 - border_width;
741 frame.x_hidden = frame.x + frame.width - bevel_width - border_width; 753 frame.x_hidden = frame.x + frame.width - bevel_width - border_width;
@@ -744,6 +756,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
744 m_shape->setPlaces(Shape::TOPLEFT | Shape::BOTTOMLEFT); 756 m_shape->setPlaces(Shape::TOPLEFT | Shape::BOTTOMLEFT);
745 break; 757 break;
746 case RIGHTTOP: 758 case RIGHTTOP:
759 orient = FbTk::ROT270;
747 frame.x = head_x + head_w - frame.width - border_width*2; 760 frame.x = head_x + head_w - frame.width - border_width*2;
748 frame.y = head_y; 761 frame.y = head_y;
749 frame.x_hidden = frame.x + frame.width - bevel_width - border_width; 762 frame.x_hidden = frame.x + frame.width - bevel_width - border_width;
@@ -752,6 +765,7 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
752 m_shape->setPlaces(Shape::TOPLEFT | Shape::BOTTOMLEFT); 765 m_shape->setPlaces(Shape::TOPLEFT | Shape::BOTTOMLEFT);
753 break; 766 break;
754 case RIGHTBOTTOM: 767 case RIGHTBOTTOM:
768 orient = FbTk::ROT270;
755 frame.x = head_x + head_w - frame.width - border_width*2; 769 frame.x = head_x + head_w - frame.width - border_width*2;
756 frame.y = head_y + head_h - frame.height - border_width*2; 770 frame.y = head_y + head_h - frame.height - border_width*2;
757 frame.x_hidden = frame.x + frame.width - bevel_width - border_width; 771 frame.x_hidden = frame.x + frame.width - bevel_width - border_width;
@@ -760,6 +774,19 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
760 m_shape->setPlaces(Shape::TOPLEFT | Shape::BOTTOMLEFT); 774 m_shape->setPlaces(Shape::TOPLEFT | Shape::BOTTOMLEFT);
761 break; 775 break;
762 } 776 }
777
778 if (was_orient != orient) {
779 // hide for all this moving around
780 if (*m_rc_visible)
781 frame.window.hide();
782 ItemList::iterator item_it = m_item_list.begin();
783 ItemList::iterator item_it_end = m_item_list.end();
784 for (; item_it != item_it_end; ++item_it) {
785 (*item_it)->setOrientation(orient);
786 }
787 if (*m_rc_visible)
788 frame.window.show();
789 }
763} 790}
764 791
765void Toolbar::updateVisibleState() { 792void Toolbar::updateVisibleState() {
@@ -920,6 +947,22 @@ void Toolbar::rearrangeItems() {
920 m_item_list.empty()) 947 m_item_list.empty())
921 return; 948 return;
922 949
950 FbTk::Orientation orient = FbTk::ROT0;
951 switch (placement()) {
952 case LEFTTOP:
953 case LEFTCENTER:
954 case LEFTBOTTOM:
955 orient = FbTk::ROT90;
956 break;
957 case RIGHTTOP:
958 case RIGHTCENTER:
959 case RIGHTBOTTOM:
960 orient = FbTk::ROT270;
961 break;
962 default:
963 orient = FbTk::ROT0;
964 }
965
923 // lock this 966 // lock this
924 m_resize_lock = true; 967 m_resize_lock = true;
925 // calculate size for fixed items 968 // calculate size for fixed items
@@ -931,6 +974,12 @@ void Toolbar::rearrangeItems() {
931 int relative_items = 0; 974 int relative_items = 0;
932 int last_bw = 0; // we show the largest border of adjoining items 975 int last_bw = 0; // we show the largest border of adjoining items
933 bool first = true; 976 bool first = true;
977
978 unsigned int width = this->width(), height = this->height();
979 unsigned int tmpw, tmph;
980 int tmpx, tmpy;
981 FbTk::translateSize(orient, width, height);
982
934 for (; item_it != item_it_end; ++item_it) { 983 for (; item_it != item_it_end; ++item_it) {
935 if (!(*item_it)->active()) 984 if (!(*item_it)->active())
936 continue; 985 continue;
@@ -953,12 +1002,16 @@ void Toolbar::rearrangeItems() {
953 1002
954 last_bw = borderW; 1003 last_bw = borderW;
955 1004
1005 tmpw = (*item_it)->width();
1006 tmph = (*item_it)->height();
1007 FbTk::translateSize(orient, tmpw, tmph);
1008
956 if ((*item_it)->type() == ToolbarItem::FIXED) { 1009 if ((*item_it)->type() == ToolbarItem::FIXED) {
957 fixed_width += (*item_it)->width(); 1010 fixed_width += tmpw;
958 fixed_items++; 1011 fixed_items++;
959 } else if ((*item_it)->type() == ToolbarItem::SQUARE) { 1012 } else if ((*item_it)->type() == ToolbarItem::SQUARE) {
960 fixed_width += height() - 2*bevel_width; 1013 fixed_width += tmph;
961 if (bevel_width != 0) fixed_width -= 2*borderW; 1014 //if (bevel_width != 0) fixed_width -= 2*borderW;
962 fixed_items++; 1015 fixed_items++;
963 } else { 1016 } else {
964 relative_items++; 1017 relative_items++;
@@ -969,13 +1022,13 @@ void Toolbar::rearrangeItems() {
969 int relative_width = 0; 1022 int relative_width = 0;
970 int rounding_error = 0; 1023 int rounding_error = 0;
971 if (fixed_items == 0) // no fixed items, then the rest is the entire width 1024 if (fixed_items == 0) // no fixed items, then the rest is the entire width
972 relative_width = width(); 1025 relative_width = width;
973 else { 1026 else {
974 if (relative_items == 0) 1027 if (relative_items == 0)
975 relative_width = 0; 1028 relative_width = 0;
976 else { // size left after fixed items / number of relative items 1029 else { // size left after fixed items / number of relative items
977 relative_width = (width() - fixed_width)/relative_items; 1030 relative_width = (width - fixed_width)/relative_items;
978 rounding_error = width() - fixed_width - relative_items*(relative_width); 1031 rounding_error = width - fixed_width - relative_items*(relative_width);
979 } 1032 }
980 } 1033 }
981 1034
@@ -991,7 +1044,9 @@ void Toolbar::rearrangeItems() {
991 if (!(*item_it)->active()) { 1044 if (!(*item_it)->active()) {
992 (*item_it)->hide(); 1045 (*item_it)->hide();
993 // make sure it still gets told the toolbar height 1046 // make sure it still gets told the toolbar height
994 (*item_it)->resize(1, height()-2*(bevel_width+borderW)); // width of 0 changes to 1 anyway 1047 tmpw = 1; tmph = height - 2*(bevel_width+borderW);
1048 FbTk::translateSize(orient, tmpw, tmph);
1049 (*item_it)->resize(tmpw, tmph); // width of 0 changes to 1 anyway
995 continue; 1050 continue;
996 } 1051 }
997 int offset = bevel_width; 1052 int offset = bevel_width;
@@ -1007,25 +1062,35 @@ void Toolbar::rearrangeItems() {
1007 } 1062 }
1008 last_bw = borderW; 1063 last_bw = borderW;
1009 1064
1065 int tmpx = next_x + offset,
1066 tmpy = offset;
1067
1010 if ((*item_it)->type() == ToolbarItem::RELATIVE) { 1068 if ((*item_it)->type() == ToolbarItem::RELATIVE) {
1011 int extra = 0; 1069 int extra = 0;
1012 if (rounding_error != 0) { // distribute rounding error over all relatives 1070 if (rounding_error != 0) { // distribute rounding error over all relatives
1013 extra = 1; 1071 extra = 1;
1014 --rounding_error; 1072 --rounding_error;
1015 } 1073 }
1016 (*item_it)->moveResize(next_x + offset, offset, extra + relative_width, height() - size_offset); 1074 tmpw = extra + relative_width;
1075 tmph = height - size_offset;
1017 } else if ((*item_it)->type() == ToolbarItem::SQUARE) { 1076 } else if ((*item_it)->type() == ToolbarItem::SQUARE) {
1018 (*item_it)->moveResize(next_x + offset, offset, 1077 tmpw = tmph = height - size_offset;
1019 height() - size_offset, height() - size_offset);
1020 } else { // fixed size 1078 } else { // fixed size
1021 (*item_it)->moveResize(next_x + offset, offset, 1079 unsigned int itemw = (*item_it)->width(), itemh = (*item_it)->height();
1022 (*item_it)->width(), height() - size_offset); 1080 FbTk::translateSize(orient, itemw, itemh);
1081 tmpw = itemw;
1082 tmph = height - size_offset;
1023 } 1083 }
1024 (*item_it)->show(); 1084 next_x += tmpw + bevel_width;
1025 next_x += (*item_it)->width() + bevel_width;
1026 if (bevel_width != 0) 1085 if (bevel_width != 0)
1027 next_x += 2*borderW; 1086 next_x += 2*borderW;
1028 1087
1088 FbTk::translateCoords(orient, tmpx, tmpy, width, height);
1089 FbTk::translatePosition(orient, tmpx, tmpy, tmpw, tmph, borderW);
1090 FbTk::translateSize(orient, tmpw, tmph);
1091 (*item_it)->moveResize(tmpx, tmpy, tmpw, tmph);
1092 (*item_it)->show();
1093
1029 } 1094 }
1030 // unlock 1095 // unlock
1031 m_resize_lock = false; 1096 m_resize_lock = false;