00001 #include "bctitle.h"
00002 #include "bcpot.h"
00003 #include "bcslider.h"
00004 #include "bcwidgetgrid.h"
00005
00006
00007 BC_WidgetGrid::BC_WidgetGrid(int x1, int y1, int x2, int y2,int cgs,int rgs){
00008 x_l = x1;
00009 y_t = y1;
00010 x_r = x2;
00011 y_b = y2;
00012 rowgaps = rgs;
00013 colgaps = cgs;
00014
00015 for (int r = 0; r < BC_WG_Rows; r++)
00016 for (int c = 0; c < BC_WG_Cols; c++) {
00017 widget_types[r][c] = BC_WT_NONE;
00018 widget_valign[r][c] = VALIGN_CENTER;
00019 widget_halign[r][c] = HALIGN_LEFT;
00020 }
00021 }
00022
00023 BC_RelocatableWidget * BC_WidgetGrid::add(BC_RelocatableWidget *h, int row, int column) {
00024 widget_types[row][column] = BC_WT_RelocatableWidget;
00025 widget_widgs[row][column] = h;
00026 return(h);
00027 }
00028
00029 int BC_WidgetGrid::getw_h(int row, int column) {
00030 switch (widget_types[row][column]) {
00031 case BC_WT_NONE:
00032 return(0);
00033 case BC_WT_RelocatableWidget:
00034 return(widget_widgs[row][column]->get_h());
00035 }
00036 }
00037
00038 int BC_WidgetGrid::getw_w(int row, int column) {
00039 switch (widget_types[row][column]) {
00040 case BC_WT_NONE:
00041 return(0);
00042 case BC_WT_RelocatableWidget:
00043 return(widget_widgs[row][column]->get_w());
00044 }
00045 }
00046
00047 void BC_WidgetGrid::setw_position(int row,int column,int x, int y) {
00048 switch (widget_types[row][column]) {
00049 case BC_WT_NONE:
00050 break;
00051 case BC_WT_RelocatableWidget:
00052 widget_widgs[row][column]->reposition_widget(x,y);
00053 break;
00054 }
00055 }
00056
00057 void BC_WidgetGrid::clear_widget(int row, int column){
00058 widget_types[row][column] = BC_WT_NONE;
00059 }
00060
00061 int BC_WidgetGrid::guess_x(int colno){
00062 calculate_maxs();
00063 int x = x_l;
00064 for (int i = 0; i < colno; i++)
00065 x += maxw[i] + colgaps;
00066 return (x);
00067 }
00068
00069 int BC_WidgetGrid::guess_y(int colno){
00070 calculate_maxs();
00071 int y = y_t;
00072 for (int i = 0; i < colno; i++)
00073 y += maxh[i] + rowgaps;
00074 return (y);
00075 }
00076
00077 int BC_WidgetGrid::get_w_wm(){
00078 return (x_l + get_w() + x_r);
00079 }
00080
00081
00082 int BC_WidgetGrid::get_w(){
00083 calculate_maxs();
00084 int x = 0;
00085 for (int i = 0; i < BC_WG_Cols; i++)
00086 if (maxw[i] > 0)
00087 x += maxw[i] + colgaps;
00088 return (x);
00089 }
00090
00091 int BC_WidgetGrid::get_h_wm(){
00092 return (y_t + get_h() + y_b);
00093 }
00094
00095 int BC_WidgetGrid::get_h(){
00096 calculate_maxs();
00097 int y = 0;
00098 for (int i = 0; i < BC_WG_Rows; i++)
00099 if (maxh[i] > 0)
00100 y += maxh[i] + rowgaps;
00101 return (y);
00102 }
00103
00104 void BC_WidgetGrid::set_align(int r,int c,int va, int ha){
00105 widget_valign[r][c] = va;
00106 widget_halign[r][c] = ha;
00107 }
00108
00109 int BC_WidgetGrid::reposition_widget(int x, int y, int w1, int h){
00110 x_l = x;
00111 y_t = y;
00112 move_widgets();
00113 return(0);
00114 }
00115
00116 void BC_WidgetGrid::move_widgets(){
00117 calculate_maxs();
00118 int r,c,x,y;
00119 int xn,yn;
00120 y = y_t;
00121 for (r = 0; r < BC_WG_Rows; r++) {
00122 x = x_l;
00123 for (c = 0; c < BC_WG_Cols; c++) {
00124 switch (widget_valign[r][c]){
00125 case VALIGN_TOP:
00126 yn = y;
00127 break;
00128 case VALIGN_CENTER:
00129 yn = y + (maxh[r] - getw_h(r,c))/2;
00130 break;
00131 case VALIGN_BOTTOM:
00132 yn = y + (maxh[r] - getw_h(r,c));
00133 break;
00134 }
00135
00136 switch (widget_halign[r][c]){
00137 case HALIGN_LEFT:
00138 xn = x;
00139 break;
00140 case HALIGN_CENTER:
00141 xn = x + (maxw[c] - getw_w(r,c))/2;
00142 break;
00143 case HALIGN_RIGHT:
00144 xn = x + (maxw[c] - getw_w(r,c));
00145 break;
00146 }
00147 setw_position(r,c,xn,yn);
00148 x += colgaps + maxw[c];
00149 }
00150 y += rowgaps + maxh[r];
00151 }
00152 }
00153
00154 void BC_WidgetGrid::calculate_maxs(){
00155 int r,c;
00156 for (r = 0; r < BC_WG_Rows; r++) {
00157 maxh[r] = 0;
00158 for (c = 0; c < BC_WG_Cols; c++) {
00159 if (getw_h(r,c) > maxh[r])
00160 maxh[r] = getw_h(r,c);
00161 }
00162 }
00163 for (c = 0; c < BC_WG_Cols; c++) {
00164 maxw[c] = 0;
00165 for (r = 0; r < BC_WG_Rows; r++) {
00166 if (getw_w(r,c) > maxw[c])
00167 maxw[c] = getw_w(r,c);
00168 }
00169 }
00170 }
00171
00172 void BC_WidgetGrid::print(){
00173 printf("\nWidget Grid: Widths: x_l=%d y_t=%d x_r=%d y_b=%d\n",x_l,y_t,x_r,y_b);
00174 calculate_maxs();
00175 for (int r = 0; r < BC_WG_Rows; r++) {
00176 for (int c = 0; c < BC_WG_Cols; c++) {
00177 printf("%d,%d\t",getw_w(r,c),getw_h(r,c));
00178 }
00179 printf("MAX: %d\n",maxh[r]);
00180 }
00181 printf("---------------------------------------------\n");
00182 for (int c = 0; c < BC_WG_Cols; c++)
00183 printf("%d\t",maxw[c]);
00184 printf("\n\n");
00185
00186 }