aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-23 22:38:34 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-23 22:38:34 (GMT)
commit67c31b49bdeab40fea37719cd6cfa06b37507e3e (patch)
tree8458f649ea6c1d716d9baa5635d8dc7616180582
parent63d9d695be8156530fabf1d2e033225bfa71bab1 (diff)
downloadfluxbox-67c31b49bdeab40fea37719cd6cfa06b37507e3e.zip
fluxbox-67c31b49bdeab40fea37719cd6cfa06b37507e3e.tar.bz2
Refactor Toolbar.cc, less noise
-rw-r--r--src/Toolbar.cc228
1 files changed, 80 insertions, 148 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index f7b0163..933c217 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -24,10 +24,7 @@
24 24
25#include "Toolbar.hh" 25#include "Toolbar.hh"
26 26
27// tool
28#include "ToolbarItem.hh" 27#include "ToolbarItem.hh"
29
30// themes
31#include "ToolbarTheme.hh" 28#include "ToolbarTheme.hh"
32 29
33#include "fluxbox.hh" 30#include "fluxbox.hh"
@@ -37,9 +34,9 @@
37#include "WindowCmd.hh" 34#include "WindowCmd.hh"
38 35
39#include "Strut.hh" 36#include "Strut.hh"
40#include "FbTk/CommandParser.hh"
41#include "Layer.hh" 37#include "Layer.hh"
42 38
39#include "FbTk/CommandParser.hh"
43#include "FbTk/I18n.hh" 40#include "FbTk/I18n.hh"
44#include "FbTk/ImageControl.hh" 41#include "FbTk/ImageControl.hh"
45#include "FbTk/TextUtils.hh" 42#include "FbTk/TextUtils.hh"
@@ -76,24 +73,25 @@ using FbTk::STLUtil::forAll;
76 73
77namespace { 74namespace {
78 75
79struct ToolbarPlacementString { 76const struct {
80 Toolbar::Placement placement; 77 Toolbar::Placement placement;
81 const char* str; 78 const char* str;
82}; 79 FbTk::Orientation orient;
83 80 unsigned int shape;
84const ToolbarPlacementString placement_strings[] = { 81} _values[] = {
85 { Toolbar::TOPLEFT, "TopLeft" }, 82 { /* unused */ },
86 { Toolbar::TOPCENTER, "TopCenter" }, 83 { Toolbar::TOPLEFT, "TopLeft", FbTk::ROT0, FbTk::Shape::BOTTOMRIGHT | FbTk::Shape::BOTTOMLEFT},
87 { Toolbar::TOPRIGHT, "TopRight" }, 84 { Toolbar::TOPCENTER, "TopCenter", FbTk::ROT0, FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT},
88 { Toolbar::BOTTOMLEFT, "BottomLeft" }, 85 { Toolbar::TOPRIGHT, "TopRight", FbTk::ROT0, FbTk::Shape::BOTTOMRIGHT | FbTk::Shape::BOTTOMLEFT},
89 { Toolbar::BOTTOMCENTER, "BottomCenter" }, 86 { Toolbar::BOTTOMLEFT, "BottomLeft", FbTk::ROT0, FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT},
90 { Toolbar::BOTTOMRIGHT, "BottomRight" }, 87 { Toolbar::BOTTOMCENTER, "BottomCenter", FbTk::ROT0, FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT},
91 { Toolbar::LEFTBOTTOM, "LeftBottom" }, 88 { Toolbar::BOTTOMRIGHT, "BottomRight", FbTk::ROT0, FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT},
92 { Toolbar::LEFTCENTER, "LeftCenter" }, 89 { Toolbar::LEFTBOTTOM, "LeftBottom", FbTk::ROT270, FbTk::Shape::TOPRIGHT | FbTk::Shape::BOTTOMRIGHT},
93 { Toolbar::LEFTTOP, "LeftTop" }, 90 { Toolbar::LEFTCENTER, "LeftCenter", FbTk::ROT270, FbTk::Shape::TOPRIGHT | FbTk::Shape::BOTTOMRIGHT},
94 { Toolbar::RIGHTBOTTOM, "RightBottom" }, 91 { Toolbar::LEFTTOP, "LeftTop", FbTk::ROT270, FbTk::Shape::TOPRIGHT | FbTk::Shape::BOTTOMRIGHT},
95 { Toolbar::RIGHTCENTER, "RightCenter" }, 92 { Toolbar::RIGHTBOTTOM, "RightBottom", FbTk::ROT90, FbTk::Shape::TOPLEFT | FbTk::Shape::BOTTOMLEFT},
96 { Toolbar::RIGHTTOP, "RightTop" } 93 { Toolbar::RIGHTCENTER, "RightCenter", FbTk::ROT90, FbTk::Shape::TOPLEFT | FbTk::Shape::BOTTOMLEFT},
94 { Toolbar::RIGHTTOP, "RightTop", FbTk::ROT90, FbTk::Shape::TOPLEFT | FbTk::Shape::BOTTOMLEFT},
97}; 95};
98 96
99} 97}
@@ -106,17 +104,17 @@ getString() const {
106 104
107 size_t i = (m_value == FbTk::Util::clamp(m_value, Toolbar::TOPLEFT, Toolbar::RIGHTTOP) 105 size_t i = (m_value == FbTk::Util::clamp(m_value, Toolbar::TOPLEFT, Toolbar::RIGHTTOP)
108 ? m_value 106 ? m_value
109 : Toolbar::DEFAULT) - Toolbar::TOPLEFT; 107 : Toolbar::DEFAULT);
110 return placement_strings[i].str; 108 return _values[i].str;
111} 109}
112 110
113template<> 111template<>
114void FbTk::Resource<Toolbar::Placement>:: 112void FbTk::Resource<Toolbar::Placement>::
115setFromString(const char *strval) { 113setFromString(const char *strval) {
116 size_t i; 114 size_t i;
117 for (i = 0; i < sizeof(placement_strings)/sizeof(ToolbarPlacementString); ++i) { 115 for (i = 1; i < sizeof(_values)/sizeof(_values[0]); ++i) {
118 if (strcasecmp(strval, placement_strings[i].str) == 0) { 116 if (strcasecmp(strval, _values[i].str) == 0) {
119 m_value = placement_strings[i].placement; 117 m_value = _values[i].placement;
120 return; 118 return;
121 } 119 }
122 } 120 }
@@ -312,27 +310,30 @@ void Toolbar::updateStrut() {
312 } 310 }
313 311
314 // request area on screen 312 // request area on screen
313 int w = static_cast<int>(width());
314 int h = static_cast<int>(height());
315 int bw = theme()->border().width();
315 int top = 0, bottom = 0, left = 0, right = 0; 316 int top = 0, bottom = 0, left = 0, right = 0;
316 switch (placement()) { 317 switch (placement()) {
317 case TOPLEFT: 318 case TOPLEFT:
318 case TOPCENTER: 319 case TOPCENTER:
319 case TOPRIGHT: 320 case TOPRIGHT:
320 top = height() + 2 * theme()->border().width(); 321 top = h + 2 * bw;
321 break; 322 break;
322 case BOTTOMLEFT: 323 case BOTTOMLEFT:
323 case BOTTOMCENTER: 324 case BOTTOMCENTER:
324 case BOTTOMRIGHT: 325 case BOTTOMRIGHT:
325 bottom = height() + 2 * theme()->border().width(); 326 bottom = h + 2 * bw;
326 break; 327 break;
327 case RIGHTTOP: 328 case RIGHTTOP:
328 case RIGHTCENTER: 329 case RIGHTCENTER:
329 case RIGHTBOTTOM: 330 case RIGHTBOTTOM:
330 right = width() + 2 * theme()->border().width(); 331 right = w + 2 * bw;
331 break; 332 break;
332 case LEFTTOP: 333 case LEFTTOP:
333 case LEFTCENTER: 334 case LEFTCENTER:
334 case LEFTBOTTOM: 335 case LEFTBOTTOM:
335 left = width() + 2 * theme()->border().width(); 336 left = w + 2 * bw;
336 break; 337 break;
337 }; 338 };
338 m_strut = screen().requestStrut(getOnHead(), left, right, top, bottom); 339 m_strut = screen().requestStrut(getOnHead(), left, right, top, bottom);
@@ -590,10 +591,10 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
590 // disable vertical toolbar 591 // disable vertical toolbar
591 592
592 *m_rc_placement = where; 593 *m_rc_placement = where;
593 int head_x = 0, 594 int head_x = 0;
594 head_y = 0, 595 int head_y = 0;
595 head_w = screen().width(), 596 int head_w = screen().width();
596 head_h = screen().height(); 597 int head_h = screen().height();
597 598
598 if (screen().hasXinerama()) { 599 if (screen().hasXinerama()) {
599 int head = *m_rc_on_head; 600 int head = *m_rc_on_head;
@@ -603,9 +604,11 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
603 head_h = screen().getHeadHeight(head); 604 head_h = screen().getHeadHeight(head);
604 } 605 }
605 606
606 int border_width = theme()->border().width(); 607 int bw = theme()->border().width();
608 int pixel = (bw == 0 ? 1 : 0); // So we get at least one pixel visible in hidden mode
609
610 frame.width = (head_w - 2*bw) * (*m_rc_width_percent) / 100;
607 611
608 frame.width = (head_w - 2*border_width) * (*m_rc_width_percent) / 100;
609 //!! TODO: change this 612 //!! TODO: change this
610 // max height of each toolbar items font... 613 // max height of each toolbar items font...
611 unsigned int max_height = m_tool_factory.maxFontHeight() + 2; 614 unsigned int max_height = m_tool_factory.maxFontHeight() + 2;
@@ -617,7 +620,6 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
617 max_height = *m_rc_height; 620 max_height = *m_rc_height;
618 621
619 frame.height = max_height; 622 frame.height = max_height;
620
621 frame.height += (frame.bevel_w * 2); 623 frame.height += (frame.bevel_w * 2);
622 624
623 // should we flipp sizes? 625 // should we flipp sizes?
@@ -628,117 +630,64 @@ void Toolbar::setPlacement(Toolbar::Placement where) {
628 } // else horizontal toolbar 630 } // else horizontal toolbar
629 631
630 632
631 // So we get at least one pixel visible in hidden mode 633 frame.x = head_x;
632 int pixel = (border_width == 0 ? 1 : 0); 634 frame.y = head_y;
633 635 frame.x_hidden = head_x;
634 FbTk::Orientation orient = FbTk::ROT0; 636 frame.y_hidden = head_y;
637 FbTk::Orientation orient = _values[where].orient;
638 if (m_shape.get())
639 m_shape->setPlaces(_values[where].shape);
635 640
636 switch (where) { 641 switch (where) {
637 case TOPLEFT: 642 case TOPLEFT:
638 frame.x = head_x; 643 frame.y_hidden += pixel - bw - frame.height;
639 frame.y = head_y;
640 frame.x_hidden = head_x;
641 frame.y_hidden = head_y - border_width - frame.height + pixel;
642 if (m_shape.get())
643 m_shape->setPlaces(FbTk::Shape::BOTTOMRIGHT | FbTk::Shape::BOTTOMLEFT);
644 break; 644 break;
645
646 case BOTTOMLEFT: 645 case BOTTOMLEFT:
647 frame.x = head_x; 646 frame.y += head_h - static_cast<int>(frame.height) - 2*bw;
648 frame.y = head_y + head_h - frame.height - border_width*2; 647 frame.y_hidden += head_h - bw - pixel;
649 frame.x_hidden = head_x;
650 frame.y_hidden = head_y + head_h - border_width - pixel;
651 if (m_shape.get())
652 m_shape->setPlaces(FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT);
653 break; 648 break;
654
655 case TOPCENTER: 649 case TOPCENTER:
656 frame.x = head_x + (head_w - frame.width) / 2 - border_width; 650 frame.x += (head_w - static_cast<int>(frame.width))/2 - bw;
657 frame.y = head_y; 651 frame.y_hidden += pixel - bw - static_cast<int>(frame.height);
658 frame.x_hidden = frame.x;
659 frame.y_hidden = head_y - border_width - frame.height + pixel;
660 if (m_shape.get())
661 m_shape->setPlaces(FbTk::Shape::BOTTOMRIGHT | FbTk::Shape::BOTTOMLEFT);
662 break; 652 break;
663 case TOPRIGHT: 653 case TOPRIGHT:
664 frame.x = head_x + head_w - frame.width - border_width*2; 654 frame.x += head_w - static_cast<int>(frame.width) - bw*2;
665 frame.y = head_y; 655 frame.y_hidden += pixel - bw - static_cast<int>(frame.height);
666 frame.x_hidden = frame.x;
667 frame.y_hidden = head_y - border_width - frame.height + pixel;
668 if (m_shape.get())
669 m_shape->setPlaces(FbTk::Shape::BOTTOMRIGHT | FbTk::Shape::BOTTOMLEFT);
670 break; 656 break;
671
672 case BOTTOMRIGHT: 657 case BOTTOMRIGHT:
673 frame.x = head_x + head_w - frame.width - border_width*2; 658 frame.x += head_w - static_cast<int>(frame.width) - bw*2;
674 frame.y = head_y + head_h - frame.height - border_width*2; 659 frame.y += head_h - static_cast<int>(frame.height) - bw*2;
675 frame.x_hidden = frame.x; 660 frame.y_hidden += head_h - bw - pixel;
676 frame.y_hidden = head_y + head_h - border_width - pixel;
677 if (m_shape.get())
678 m_shape->setPlaces(FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT);
679 break; 661 break;
680
681 case BOTTOMCENTER: // default is BOTTOMCENTER 662 case BOTTOMCENTER: // default is BOTTOMCENTER
682 frame.x = head_x + (head_w - frame.width) / 2 - border_width; 663 frame.x += (head_w - static_cast<int>(frame.width))/2 - bw;
683 frame.y = head_y + head_h - frame.height - border_width*2; 664 frame.y += head_h - static_cast<int>(frame.height) - bw*2;
684 frame.x_hidden = frame.x; 665 frame.y_hidden += head_h - bw - pixel;
685 frame.y_hidden = head_y + head_h - border_width - pixel;
686 if (m_shape.get())
687 m_shape->setPlaces(FbTk::Shape::TOPRIGHT | FbTk::Shape::TOPLEFT);
688 break; 666 break;
689 case LEFTCENTER: 667 case LEFTCENTER:
690 orient = FbTk::ROT270; 668 frame.y += (head_h - static_cast<int>(frame.height))/2 - bw;
691 frame.x = head_x; 669 frame.x_hidden += pixel - static_cast<int>(frame.width) - bw;
692 frame.y = head_y + (head_h - frame.height)/2 - border_width;
693 frame.x_hidden = frame.x - frame.width - border_width + pixel;
694 frame.y_hidden = frame.y;
695 if (m_shape.get())
696 m_shape->setPlaces(FbTk::Shape::TOPRIGHT | FbTk::Shape::BOTTOMRIGHT);
697 break; 670 break;
698 case LEFTTOP: 671 case LEFTTOP:
699 orient = FbTk::ROT270; 672 frame.x_hidden += pixel - static_cast<int>(frame.width) - bw;
700 frame.x = head_x;
701 frame.y = head_y;
702 frame.x_hidden = frame.x - frame.width - border_width + pixel;
703 frame.y_hidden = frame.y;
704 if (m_shape.get())
705 m_shape->setPlaces(FbTk::Shape::TOPRIGHT | FbTk::Shape::BOTTOMRIGHT);
706 break; 673 break;
707 case LEFTBOTTOM: 674 case LEFTBOTTOM:
708 orient = FbTk::ROT270; 675 frame.y = head_h - static_cast<int>(frame.height) - bw*2;
709 frame.x = head_x; 676 frame.x_hidden += pixel - static_cast<int>(frame.width) - bw;
710 frame.y = head_y + head_h - frame.height - border_width*2;
711 frame.x_hidden = frame.x - frame.width - border_width + pixel;
712 frame.y_hidden = frame.y;
713 if (m_shape.get())
714 m_shape->setPlaces(FbTk::Shape::TOPRIGHT | FbTk::Shape::BOTTOMRIGHT);
715 break; 677 break;
716 case RIGHTCENTER: 678 case RIGHTCENTER:
717 orient = FbTk::ROT90; 679 frame.x += head_w - static_cast<int>(frame.width) - bw*2;
718 frame.x = head_x + head_w - frame.width - border_width*2; 680 frame.y += (head_h - static_cast<int>(frame.height))/2 * bw;
719 frame.y = head_y + (head_h - frame.height)/2 - border_width; 681 frame.x_hidden += static_cast<int>(frame.width) + bw - pixel;
720 frame.x_hidden = frame.x + frame.width + border_width - pixel;
721 frame.y_hidden = frame.y;
722 if (m_shape.get())
723 m_shape->setPlaces(FbTk::Shape::TOPLEFT | FbTk::Shape::BOTTOMLEFT);
724 break; 682 break;
725 case RIGHTTOP: 683 case RIGHTTOP:
726 orient = FbTk::ROT90; 684 frame.x += head_w - static_cast<int>(frame.width) - bw*2;
727 frame.x = head_x + head_w - frame.width - border_width*2; 685 frame.x_hidden += static_cast<int>(frame.width) + bw - pixel;
728 frame.y = head_y;
729 frame.x_hidden = frame.x + frame.width + border_width - pixel;
730 frame.y_hidden = frame.y;
731 if (m_shape.get())
732 m_shape->setPlaces(FbTk::Shape::TOPLEFT | FbTk::Shape::BOTTOMLEFT);
733 break; 686 break;
734 case RIGHTBOTTOM: 687 case RIGHTBOTTOM:
735 orient = FbTk::ROT90; 688 frame.x += head_w - static_cast<int>(frame.width) - bw*2;
736 frame.x = head_x + head_w - frame.width - border_width*2; 689 frame.y += head_h - static_cast<int>(frame.height) - bw*2;
737 frame.y = head_y + head_h - frame.height - border_width*2; 690 frame.x_hidden += static_cast<int>(frame.width) + bw - pixel;
738 frame.x_hidden = frame.x + frame.width + border_width - pixel;
739 frame.y_hidden = frame.y;
740 if (m_shape.get())
741 m_shape->setPlaces(FbTk::Shape::TOPLEFT | FbTk::Shape::BOTTOMLEFT);
742 break; 691 break;
743 } 692 }
744 693
@@ -809,7 +758,6 @@ void Toolbar::setupMenus(bool skip_new_placement) {
809 758
810 toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); 759 toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource);
811 menu().insertItem(toolbar_menuitem); 760 menu().insertItem(toolbar_menuitem);
812
813 menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, 761 menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,
814 "Maximize Over", 762 "Maximize Over",
815 "Maximize over this thing when maximizing"), 763 "Maximize over this thing when maximizing"),
@@ -832,12 +780,11 @@ void Toolbar::setupMenus(bool skip_new_placement) {
832 780
833 // menu is 3 wide, 5 down 781 // menu is 3 wide, 5 down
834 if (!skip_new_placement) { 782 if (!skip_new_placement) {
835 struct PlacementP { 783
784 static const struct {
836 const FbTk::FbString label; 785 const FbTk::FbString label;
837 Toolbar::Placement placement; 786 Toolbar::Placement placement;
838 }; 787 } pm[] = {
839
840 static const PlacementP place_menu[] = {
841 { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), Toolbar::TOPLEFT}, 788 { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), Toolbar::TOPLEFT},
842 { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), Toolbar::LEFTTOP}, 789 { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), Toolbar::LEFTTOP},
843 { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), Toolbar::LEFTCENTER}, 790 { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), Toolbar::LEFTCENTER},
@@ -857,14 +804,13 @@ void Toolbar::setupMenus(bool skip_new_placement) {
857 804
858 placementMenu().setMinimumColumns(3); 805 placementMenu().setMinimumColumns(3);
859 // create items in sub menu 806 // create items in sub menu
860 for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { 807 for (size_t i=0; i< sizeof(pm)/sizeof(pm[0]); ++i) {
861 const PlacementP& p = place_menu[i]; 808 if (pm[i].label == "") {
862 if (p.label == "") { 809 placementMenu().insert(pm[i].label);
863 placementMenu().insert(p.label);
864 placementMenu().setItemEnabled(i, false); 810 placementMenu().setItemEnabled(i, false);
865 } else 811 } else
866 placementMenu().insertItem(new PlaceToolbarMenuItem(p.label, *this, 812 placementMenu().insertItem(new PlaceToolbarMenuItem(pm[i].label, *this,
867 p.placement)); 813 pm[i].placement));
868 } 814 }
869 } 815 }
870 816
@@ -905,21 +851,7 @@ void Toolbar::rearrangeItems() {
905 m_item_list.empty()) 851 m_item_list.empty())
906 return; 852 return;
907 853
908 FbTk::Orientation orient = FbTk::ROT0; 854 FbTk::Orientation orient = _values[placement()].orient;
909 switch (placement()) {
910 case LEFTTOP:
911 case LEFTCENTER:
912 case LEFTBOTTOM:
913 orient = FbTk::ROT270;
914 break;
915 case RIGHTTOP:
916 case RIGHTCENTER:
917 case RIGHTBOTTOM:
918 orient = FbTk::ROT90;
919 break;
920 default:
921 orient = FbTk::ROT0;
922 }
923 855
924 // lock this 856 // lock this
925 m_resize_lock = true; 857 m_resize_lock = true;