| 810 | } |
| 811 | |
| 812 | void Widget::getTextIconInfo( |
| 813 | gfx::Rect* box, |
| 814 | gfx::Rect* text, |
| 815 | gfx::Rect* icon, |
| 816 | int icon_align, int icon_w, int icon_h) |
| 817 | { |
| 818 | #define SETRECT(r) \ |
| 819 | if (r) { \ |
| 820 | r->x = r##_x; \ |
| 821 | r->y = r##_y; \ |
| 822 | r->w = r##_w; \ |
| 823 | r->h = r##_h; \ |
| 824 | } |
| 825 | |
| 826 | gfx::Rect bounds = clientBounds(); |
| 827 | int box_x, box_y, box_w, box_h, icon_x, icon_y; |
| 828 | int text_x, text_y, text_w, text_h; |
| 829 | |
| 830 | text_x = text_y = 0; |
| 831 | |
| 832 | // Size of the text |
| 833 | if (hasText()) { |
| 834 | text_w = textWidth(); |
| 835 | text_h = textHeight(); |
| 836 | } |
| 837 | else { |
| 838 | text_w = text_h = 0; |
| 839 | } |
| 840 | |
| 841 | // Box size |
| 842 | if (icon_align & CENTER) { // With the icon in the center |
| 843 | if (icon_align & MIDDLE) { // With the icon inside the text |
| 844 | box_w = MAX(icon_w, text_w); |
| 845 | box_h = MAX(icon_h, text_h); |
| 846 | } |
| 847 | // With the icon in the top or bottom |
| 848 | else { |
| 849 | box_w = MAX(icon_w, text_w); |
| 850 | box_h = icon_h + (hasText() ? childSpacing(): 0) + text_h; |
| 851 | } |
| 852 | } |
| 853 | // With the icon in left or right that doesn't care by now |
| 854 | else { |
| 855 | box_w = icon_w + (hasText() ? childSpacing(): 0) + text_w; |
| 856 | box_h = MAX(icon_h, text_h); |
| 857 | } |
| 858 | |
| 859 | // Box position |
| 860 | if (align() & RIGHT) |
| 861 | box_x = bounds.x2() - box_w - border().right(); |
| 862 | else if (align() & CENTER) |
| 863 | box_x = (bounds.x+bounds.x2())/2 - box_w/2; |
| 864 | else |
| 865 | box_x = bounds.x + border().left(); |
| 866 | |
| 867 | if (align() & BOTTOM) |
| 868 | box_y = bounds.y2() - box_h - border().bottom(); |
| 869 | else if (align() & MIDDLE) |
no test coverage detected