50 //static char defaultTranslations[] = "<BtnDown>: mousedown()\n"; |
50 //static char defaultTranslations[] = "<BtnDown>: mousedown()\n"; |
51 static char defaultTranslations[] = "\ |
51 static char defaultTranslations[] = "\ |
52 <EnterWindow>: getfocus()\n\ |
52 <EnterWindow>: getfocus()\n\ |
53 <LeaveWindow>: loosefocus()\n"; |
53 <LeaveWindow>: loosefocus()\n"; |
54 |
54 |
|
55 static XtResource resources[] = |
|
56 { |
|
57 { |
|
58 gridColumnSpacing, |
|
59 gridColumnSpacing, |
|
60 XmRDimension, |
|
61 sizeof (Dimension), |
|
62 XtOffsetOf( GridRec, |
|
63 mywidget.columnspacing), |
|
64 XmRImmediate, |
|
65 (XtPointer) 0 |
|
66 }, |
|
67 { |
|
68 gridRowSpacing, |
|
69 gridRowSpacing, |
|
70 XmRDimension, |
|
71 sizeof (Dimension), |
|
72 XtOffsetOf( GridRec, |
|
73 mywidget.rowspacing), |
|
74 XmRImmediate, |
|
75 (XtPointer) 0 |
|
76 }, |
|
77 { |
|
78 gridMargin, |
|
79 gridMargin, |
|
80 XmRDimension, |
|
81 sizeof (Dimension), |
|
82 XtOffsetOf( GridRec, |
|
83 mywidget.margin), |
|
84 XmRImmediate, |
|
85 (XtPointer) 0 |
|
86 } |
|
87 }; |
55 |
88 |
56 ///* |
89 ///* |
57 static XtResource constraints[] = |
90 static XtResource constraints[] = |
58 { |
91 { |
59 { |
92 { |
173 sizeof (Boolean), |
206 sizeof (Boolean), |
174 XtOffsetOf( GridConstraintRec, |
207 XtOffsetOf( GridConstraintRec, |
175 grid.vfill), |
208 grid.vfill), |
176 XmRImmediate, |
209 XmRImmediate, |
177 (XtPointer) 0 |
210 (XtPointer) 0 |
178 } |
211 }, |
179 |
212 { |
|
213 gridMinWidth, |
|
214 gridMinWidth, |
|
215 XmRDimension, |
|
216 sizeof (Dimension), |
|
217 XtOffsetOf( GridConstraintRec, |
|
218 grid.min_width), |
|
219 XmRImmediate, |
|
220 (XtPointer) 0 |
|
221 } |
180 }; |
222 }; |
181 //*/ |
223 //*/ |
182 //static XtResource constraints[] = {}; |
|
183 |
224 |
184 GridClassRec gridClassRec = { |
225 GridClassRec gridClassRec = { |
185 // Core Class |
226 // Core Class |
186 { |
227 { |
187 //(WidgetClass)&constraintClassRec, // superclass |
228 //(WidgetClass)&constraintClassRec, // superclass |
188 (WidgetClass)&xmManagerClassRec, |
229 (WidgetClass)&xmManagerClassRec, |
189 "Grid", // class_name |
230 "Grid", // class_name |
190 sizeof(GridRec), // widget_size |
231 sizeof(GridRec), // widget_size |
191 grid_class_initialize, // class_initialize |
232 grid_class_initialize, // class_initialize |
192 NULL, // class_part_initialize |
233 NULL, // class_part_initialize |
193 FALSE, // class_inited |
234 FALSE, // class_inited |
194 (XtInitProc)grid_initialize, // initialize |
235 (XtInitProc)grid_initialize, // initialize |
195 NULL, // initialize_hook |
236 NULL, // initialize_hook |
196 grid_realize, // realize |
237 grid_realize, // realize |
197 actionslist, // actions |
238 actionslist, // actions |
198 XtNumber(actionslist), // num_actions |
239 XtNumber(actionslist), // num_actions |
199 NULL, // resources |
240 resources, // resources |
200 0, // num_resources |
241 XtNumber(resources), // num_resources |
201 NULLQUARK, // xrm_class |
242 NULLQUARK, // xrm_class |
202 True, // compress_motion |
243 True, // compress_motion |
203 True, // compress_exposure |
244 True, // compress_exposure |
204 True, // compress_enterleave |
245 True, // compress_enterleave |
205 False, // visible_interest |
246 False, // visible_interest |
365 int num_cols_expanding = 0; |
406 int num_cols_expanding = 0; |
366 int num_rows_expanding = 0; |
407 int num_rows_expanding = 0; |
367 int req_width = 0; |
408 int req_width = 0; |
368 int req_height = 0; |
409 int req_height = 0; |
369 |
410 |
|
411 //printf("container width: %d\n", (int)w->core.width); |
|
412 |
370 // calculate the minimum size requirements for all columns and rows |
413 // calculate the minimum size requirements for all columns and rows |
371 // we need to run this 2 times: for widgets without colspan/rowspan first |
414 // we need to run this 2 times: for widgets without colspan/rowspan first |
372 // and then again for colspan/rowspan > 1 |
415 // and then again for colspan/rowspan > 1 |
373 int span_max = 1; |
416 int span_max = 1; |
374 for(int r=0;r<2;r++) { |
417 for(int r=0;r<2;r++) { |
375 for(int i=0;i<w->composite.num_children;i++) { |
418 for(int i=0;i<w->composite.num_children;i++) { |
376 Widget child = w->composite.children[i]; |
419 Widget child = w->composite.children[i]; |
377 GridConstraintRec *constraints = child->core.constraints; |
420 GridConstraintRec *constraints = child->core.constraints; |
|
421 if(constraints->grid.pref_width == 0) { |
|
422 constraints->grid.pref_width = child->core.width; |
|
423 } |
|
424 if(constraints->grid.pref_height == 0) { |
|
425 constraints->grid.pref_height = child->core.height; |
|
426 } |
|
427 if(constraints->grid.pref_width < constraints->grid.min_width) { |
|
428 constraints->grid.pref_width = constraints->grid.min_width; |
|
429 } |
378 |
430 |
379 if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) { |
431 if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) { |
380 continue; |
432 continue; |
381 } |
433 } |
382 |
434 |
476 } |
528 } |
477 req_height += rows[i].size; |
529 req_height += rows[i].size; |
478 } |
530 } |
479 |
531 |
480 if(req_width > 0 && req_height > 0) { |
532 if(req_width > 0 && req_height > 0) { |
|
533 // add col/row spacing |
|
534 req_width += (ncols-1)*w->mywidget.columnspacing; |
|
535 req_height += (nrows-1)*w->mywidget.rowspacing; |
|
536 |
481 Widget parent = w->core.parent; |
537 Widget parent = w->core.parent; |
482 Dimension rwidth = req_width; |
538 Dimension rwidth = req_width; |
483 Dimension rheight = req_height; |
539 Dimension rheight = req_height; |
484 if(rwidth < w->core.width) { |
540 if(rwidth < w->core.width) { |
485 //rwidth = w->core.width; |
541 //rwidth = w->core.width; |
489 } |
545 } |
490 |
546 |
491 if(!w->mywidget.sizerequest) { |
547 if(!w->mywidget.sizerequest) { |
492 Dimension actual_width, actual_height; |
548 Dimension actual_width, actual_height; |
493 w->mywidget.sizerequest = TRUE; |
549 w->mywidget.sizerequest = TRUE; |
|
550 |
|
551 //XtWidgetGeometry request; |
|
552 //request.width = req_width; |
|
553 //request.request_mode = CWWidth; |
|
554 //XtWidgetGeometry reply; |
|
555 //XtGeometryResult result = XtMakeGeometryRequest((Widget)w, &request, &reply); |
|
556 |
494 XtMakeResizeRequest((Widget)w, req_width, req_height, &actual_width, &actual_height); |
557 XtMakeResizeRequest((Widget)w, req_width, req_height, &actual_width, &actual_height); |
495 w->mywidget.sizerequest = FALSE; |
558 w->mywidget.sizerequest = FALSE; |
496 //printf("size request: %d %d\n", (int)actual_width, (int)actual_height); |
559 //printf("size request: %d %d\n", (int)actual_width, (int)actual_height); |
497 } |
560 } |
498 |
561 |
499 |
562 |
500 |
563 |
501 } |
564 } |
502 |
565 |
|
566 // how much space can we add to each expanding col/row |
503 int hexpand = 0; |
567 int hexpand = 0; |
504 int width_diff = (int)w->core.width - req_width; |
568 int width_diff = (int)w->core.width - req_width; |
505 int hexpand2 = 0; |
569 int hexpand2 = 0; |
506 if(width_diff > 0 && num_cols_expanding > 0) { |
570 if(width_diff > 0 && num_cols_expanding > 0) { |
507 hexpand = width_diff / num_cols_expanding; |
571 hexpand = width_diff / num_cols_expanding; |
548 if(constraints->grid.hfill) { |
612 if(constraints->grid.hfill) { |
549 if(constraints->grid.colspan > 1) { |
613 if(constraints->grid.colspan > 1) { |
550 Dimension cwidth = 0; |
614 Dimension cwidth = 0; |
551 for(int j=0;j<constraints->grid.colspan;j++) { |
615 for(int j=0;j<constraints->grid.colspan;j++) { |
552 if(constraints->grid.x+j < ncols) { |
616 if(constraints->grid.x+j < ncols) { |
553 cwidth += cols[constraints->grid.x+j].size; |
617 cwidth += cols[constraints->grid.x+j].size + (j > 0 ? w->mywidget.columnspacing : 0); |
554 } |
618 } |
555 } |
619 } |
556 width = cwidth; |
620 width = cwidth; |
557 } else { |
621 } else { |
558 width = c.size; |
622 width = c.size - w->mywidget.columnspacing; |
559 } |
623 } |
560 } |
624 } |
561 if(constraints->grid.vfill) { |
625 if(constraints->grid.vfill) { |
562 if(constraints->grid.rowspan > 1) { |
626 if(constraints->grid.rowspan > 1) { |
563 Dimension cheight = 0; |
627 Dimension cheight = 0; |
564 for(int j=0;j<constraints->grid.rowspan;j++) { |
628 for(int j=0;j<constraints->grid.rowspan;j++) { |
565 if(constraints->grid.y+j < nrows) { |
629 if(constraints->grid.y+j < nrows) { |
566 cheight += rows[constraints->grid.y+j].size; |
630 cheight += rows[constraints->grid.y+j].size + (j > 0 ? w->mywidget.rowspacing : 0); |
567 } |
631 } |
568 } |
632 } |
569 height = cheight; |
633 height = cheight; |
570 } else { |
634 } else { |
571 height = r.size; |
635 height = r.size - w->mywidget.rowspacing; |
572 } |
636 } |
573 } |
637 } |
574 |
638 |
575 XtConfigureWidget(child, x, y, width, height, child->core.border_width); |
639 if(width > 0 && height > 0) { |
|
640 XtConfigureWidget(child, x, y, width, height, child->core.border_width); |
|
641 } |
576 //printf("child %d %d - %d %d\n", (int)child->core.x, (int)child->core.y, (int)child->core.width, (int)child->core.height); |
642 //printf("child %d %d - %d %d\n", (int)child->core.x, (int)child->core.y, (int)child->core.width, (int)child->core.height); |
577 } |
643 } |
578 |
644 |
579 free(cols); |
645 free(cols); |
580 free(rows); |
646 free(rows); |