@@ -352,6 +352,19 @@ class Surface {
352
352
353
353
operator WINDOW *() { return m_window; }
354
354
355
+ Surface SubSurface (Rect bounds) {
356
+ Surface subSurface;
357
+ if (is_pad (m_window))
358
+ subSurface.m_window =
359
+ ::subpad (m_window, bounds.size.height, bounds.size.width,
360
+ bounds.origin.y, bounds.origin.x);
361
+ else
362
+ subSurface.m_window =
363
+ ::derwin (m_window, bounds.size.height, bounds.size.width,
364
+ bounds.origin.y, bounds.origin.x);
365
+ return subSurface;
366
+ }
367
+
355
368
// Copy a region of the surface to another surface.
356
369
void CopyToSurface (Surface &target, Point source_origin, Point target_origin,
357
370
Size size) {
@@ -1025,7 +1038,7 @@ class FieldDelegate {
1025
1038
// Draw the field in the given subpad surface. The surface have a height that
1026
1039
// is equal to the height returned by FieldDelegateGetHeight(). If the field
1027
1040
// is selected in the form window, then is_selected will be true.
1028
- virtual void FieldDelegateDraw (SubPad &surface, bool is_selected) = 0;
1041
+ virtual void FieldDelegateDraw (Surface &surface, bool is_selected) = 0;
1029
1042
1030
1043
// Handle the key that wasn't handled by the form window or a container field.
1031
1044
virtual HandleCharResult FieldDelegateHandleChar (int key) {
@@ -1112,7 +1125,7 @@ class TextFieldDelegate : public FieldDelegate {
1112
1125
1113
1126
int GetContentLength () { return m_content.length (); }
1114
1127
1115
- void DrawContent (SubPad &surface, bool is_selected) {
1128
+ void DrawContent (Surface &surface, bool is_selected) {
1116
1129
surface.MoveCursor (0 , 0 );
1117
1130
const char *text = m_content.c_str () + m_first_visibile_char;
1118
1131
surface.PutCString (text, surface.GetWidth ());
@@ -1131,17 +1144,17 @@ class TextFieldDelegate : public FieldDelegate {
1131
1144
surface.AttributeOff (A_REVERSE);
1132
1145
}
1133
1146
1134
- void DrawField (SubPad &surface, bool is_selected) {
1147
+ void DrawField (Surface &surface, bool is_selected) {
1135
1148
surface.TitledBox (m_label.c_str ());
1136
1149
1137
1150
Rect content_bounds = surface.GetFrame ();
1138
1151
content_bounds.Inset (1 , 1 );
1139
- SubPad content_surface = SubPad ( surface, content_bounds);
1152
+ Surface content_surface = surface. SubSurface ( content_bounds);
1140
1153
1141
1154
DrawContent (content_surface, is_selected);
1142
1155
}
1143
1156
1144
- void DrawError (SubPad &surface) {
1157
+ void DrawError (Surface &surface) {
1145
1158
if (!FieldDelegateHasError ())
1146
1159
return ;
1147
1160
surface.MoveCursor (0 , 0 );
@@ -1152,12 +1165,12 @@ class TextFieldDelegate : public FieldDelegate {
1152
1165
surface.AttributeOff (COLOR_PAIR (RedOnBlack));
1153
1166
}
1154
1167
1155
- void FieldDelegateDraw (SubPad &surface, bool is_selected) override {
1168
+ void FieldDelegateDraw (Surface &surface, bool is_selected) override {
1156
1169
Rect frame = surface.GetFrame ();
1157
1170
Rect field_bounds, error_bounds;
1158
1171
frame.HorizontalSplit (GetFieldHeight (), field_bounds, error_bounds);
1159
- SubPad field_surface = SubPad ( surface, field_bounds);
1160
- SubPad error_surface = SubPad ( surface, error_bounds);
1172
+ Surface field_surface = surface. SubSurface ( field_bounds);
1173
+ Surface error_surface = surface. SubSurface ( error_bounds);
1161
1174
1162
1175
DrawField (field_surface, is_selected);
1163
1176
DrawError (error_surface);
@@ -1406,7 +1419,7 @@ class BooleanFieldDelegate : public FieldDelegate {
1406
1419
// Boolean fields are have a single line.
1407
1420
int FieldDelegateGetHeight () override { return 1 ; }
1408
1421
1409
- void FieldDelegateDraw (SubPad &surface, bool is_selected) override {
1422
+ void FieldDelegateDraw (Surface &surface, bool is_selected) override {
1410
1423
surface.MoveCursor (0 , 0 );
1411
1424
surface.PutChar (' [' );
1412
1425
if (is_selected)
@@ -1486,7 +1499,7 @@ class ChoicesFieldDelegate : public FieldDelegate {
1486
1499
return std::min (index, GetNumberOfChoices ()) - 1 ;
1487
1500
}
1488
1501
1489
- void DrawContent (SubPad &surface, bool is_selected) {
1502
+ void DrawContent (Surface &surface, bool is_selected) {
1490
1503
int choices_to_draw = GetLastVisibleChoice () - m_first_visibile_choice + 1 ;
1491
1504
for (int i = 0 ; i < choices_to_draw; i++) {
1492
1505
surface.MoveCursor (0 , i);
@@ -1502,14 +1515,14 @@ class ChoicesFieldDelegate : public FieldDelegate {
1502
1515
}
1503
1516
}
1504
1517
1505
- void FieldDelegateDraw (SubPad &surface, bool is_selected) override {
1518
+ void FieldDelegateDraw (Surface &surface, bool is_selected) override {
1506
1519
UpdateScrolling ();
1507
1520
1508
1521
surface.TitledBox (m_label.c_str ());
1509
1522
1510
1523
Rect content_bounds = surface.GetFrame ();
1511
1524
content_bounds.Inset (1 , 1 );
1512
- SubPad content_surface = SubPad ( surface, content_bounds);
1525
+ Surface content_surface = surface. SubSurface ( content_bounds);
1513
1526
1514
1527
DrawContent (content_surface, is_selected);
1515
1528
}
@@ -1684,7 +1697,7 @@ template <class T> class ListFieldDelegate : public FieldDelegate {
1684
1697
return context;
1685
1698
}
1686
1699
1687
- void DrawRemoveButton (SubPad &surface, int highlight) {
1700
+ void DrawRemoveButton (Surface &surface, int highlight) {
1688
1701
surface.MoveCursor (1 , surface.GetHeight () / 2 );
1689
1702
if (highlight)
1690
1703
surface.AttributeOn (A_REVERSE);
@@ -1693,7 +1706,7 @@ template <class T> class ListFieldDelegate : public FieldDelegate {
1693
1706
surface.AttributeOff (A_REVERSE);
1694
1707
}
1695
1708
1696
- void DrawFields (SubPad &surface, bool is_selected) {
1709
+ void DrawFields (Surface &surface, bool is_selected) {
1697
1710
int line = 0 ;
1698
1711
int width = surface.GetWidth ();
1699
1712
for (int i = 0 ; i < GetNumberOfFields (); i++) {
@@ -1702,8 +1715,8 @@ template <class T> class ListFieldDelegate : public FieldDelegate {
1702
1715
Rect field_bounds, remove_button_bounds;
1703
1716
bounds.VerticalSplit (bounds.size .width - sizeof (" [Remove]" ),
1704
1717
field_bounds, remove_button_bounds);
1705
- SubPad field_surface = SubPad ( surface, field_bounds);
1706
- SubPad remove_button_surface = SubPad ( surface, remove_button_bounds);
1718
+ Surface field_surface = surface. SubSurface ( field_bounds);
1719
+ Surface remove_button_surface = surface. SubSurface ( remove_button_bounds);
1707
1720
1708
1721
bool is_element_selected = m_selection_index == i && is_selected;
1709
1722
bool is_field_selected =
@@ -1718,7 +1731,7 @@ template <class T> class ListFieldDelegate : public FieldDelegate {
1718
1731
}
1719
1732
}
1720
1733
1721
- void DrawNewButton (SubPad &surface, bool is_selected) {
1734
+ void DrawNewButton (Surface &surface, bool is_selected) {
1722
1735
const char *button_text = " [New]" ;
1723
1736
int x = (surface.GetWidth () - sizeof (button_text) - 1 ) / 2 ;
1724
1737
surface.MoveCursor (x, 0 );
@@ -1731,16 +1744,16 @@ template <class T> class ListFieldDelegate : public FieldDelegate {
1731
1744
surface.AttributeOff (A_REVERSE);
1732
1745
}
1733
1746
1734
- void FieldDelegateDraw (SubPad &surface, bool is_selected) override {
1747
+ void FieldDelegateDraw (Surface &surface, bool is_selected) override {
1735
1748
surface.TitledBox (m_label.c_str ());
1736
1749
1737
1750
Rect content_bounds = surface.GetFrame ();
1738
1751
content_bounds.Inset (1 , 1 );
1739
1752
Rect fields_bounds, new_button_bounds;
1740
1753
content_bounds.HorizontalSplit (content_bounds.size .height - 1 ,
1741
1754
fields_bounds, new_button_bounds);
1742
- SubPad fields_surface = SubPad ( surface, fields_bounds);
1743
- SubPad new_button_surface = SubPad ( surface, new_button_bounds);
1755
+ Surface fields_surface = surface. SubSurface ( fields_bounds);
1756
+ Surface new_button_surface = surface. SubSurface ( new_button_bounds);
1744
1757
1745
1758
DrawFields (fields_surface, is_selected);
1746
1759
DrawNewButton (new_button_surface, is_selected);
@@ -1936,12 +1949,12 @@ class MappingFieldDelegate : public FieldDelegate {
1936
1949
m_value_field.FieldDelegateGetHeight ());
1937
1950
}
1938
1951
1939
- void DrawArrow (SubPad &surface) {
1952
+ void DrawArrow (Surface &surface) {
1940
1953
surface.MoveCursor (0 , 1 );
1941
1954
surface.PutChar (ACS_RARROW);
1942
1955
}
1943
1956
1944
- void FieldDelegateDraw (SubPad &surface, bool is_selected) override {
1957
+ void FieldDelegateDraw (Surface &surface, bool is_selected) override {
1945
1958
Rect bounds = surface.GetFrame ();
1946
1959
Rect key_field_bounds, arrow_and_value_field_bounds;
1947
1960
bounds.VerticalSplit (bounds.size .width / 2 , key_field_bounds,
@@ -1950,9 +1963,9 @@ class MappingFieldDelegate : public FieldDelegate {
1950
1963
arrow_and_value_field_bounds.VerticalSplit (1 , arrow_bounds,
1951
1964
value_field_bounds);
1952
1965
1953
- SubPad key_field_surface = SubPad ( surface, key_field_bounds);
1954
- SubPad arrow_surface = SubPad ( surface, arrow_bounds);
1955
- SubPad value_field_surface = SubPad ( surface, value_field_bounds);
1966
+ Surface key_field_surface = surface. SubSurface ( key_field_bounds);
1967
+ Surface arrow_surface = surface. SubSurface ( arrow_bounds);
1968
+ Surface value_field_surface = surface. SubSurface ( value_field_bounds);
1956
1969
1957
1970
bool key_is_selected =
1958
1971
m_selection_type == SelectionType::Key && is_selected;
@@ -2088,7 +2101,7 @@ class FormAction {
2088
2101
}
2089
2102
2090
2103
// Draw a centered [Label].
2091
- void Draw (SubPad &surface, bool is_selected) {
2104
+ void Draw (Surface &surface, bool is_selected) {
2092
2105
int x = (surface.GetWidth () - m_label.length ()) / 2 ;
2093
2106
surface.MoveCursor (x, 0 );
2094
2107
if (is_selected)
@@ -2357,7 +2370,7 @@ class FormWindowDelegate : public WindowDelegate {
2357
2370
return context;
2358
2371
}
2359
2372
2360
- void UpdateScrolling (DerivedWindow &surface) {
2373
+ void UpdateScrolling (Surface &surface) {
2361
2374
ScrollContext context = GetScrollContext ();
2362
2375
int content_height = GetContentHeight ();
2363
2376
int surface_height = surface.GetHeight ();
@@ -2381,7 +2394,7 @@ class FormWindowDelegate : public WindowDelegate {
2381
2394
}
2382
2395
}
2383
2396
2384
- void DrawError (SubPad &surface) {
2397
+ void DrawError (Surface &surface) {
2385
2398
if (!m_delegate_sp->HasError ())
2386
2399
return ;
2387
2400
surface.MoveCursor (0 , 0 );
@@ -2395,7 +2408,7 @@ class FormWindowDelegate : public WindowDelegate {
2395
2408
surface.HorizontalLine (surface.GetWidth ());
2396
2409
}
2397
2410
2398
- void DrawFields (SubPad &surface) {
2411
+ void DrawFields (Surface &surface) {
2399
2412
int line = 0 ;
2400
2413
int width = surface.GetWidth ();
2401
2414
bool a_field_is_selected = m_selection_type == SelectionType::Field;
@@ -2406,13 +2419,13 @@ class FormWindowDelegate : public WindowDelegate {
2406
2419
bool is_field_selected = a_field_is_selected && m_selection_index == i;
2407
2420
int height = field->FieldDelegateGetHeight ();
2408
2421
Rect bounds = Rect (Point (0 , line), Size (width, height));
2409
- SubPad field_surface = SubPad ( surface, bounds);
2422
+ Surface field_surface = surface. SubSurface ( bounds);
2410
2423
field->FieldDelegateDraw (field_surface, is_field_selected);
2411
2424
line += height;
2412
2425
}
2413
2426
}
2414
2427
2415
- void DrawActions (SubPad &surface) {
2428
+ void DrawActions (Surface &surface) {
2416
2429
int number_of_actions = m_delegate_sp->GetNumberOfActions ();
2417
2430
int width = surface.GetWidth () / number_of_actions;
2418
2431
bool an_action_is_selected = m_selection_type == SelectionType::Action;
@@ -2421,19 +2434,19 @@ class FormWindowDelegate : public WindowDelegate {
2421
2434
bool is_action_selected = an_action_is_selected && m_selection_index == i;
2422
2435
FormAction &action = m_delegate_sp->GetAction (i);
2423
2436
Rect bounds = Rect (Point (x, 0 ), Size (width, 1 ));
2424
- SubPad action_surface = SubPad ( surface, bounds);
2437
+ Surface action_surface = surface. SubSurface ( bounds);
2425
2438
action.Draw (action_surface, is_action_selected);
2426
2439
x += width;
2427
2440
}
2428
2441
}
2429
2442
2430
- void DrawElements (SubPad &surface) {
2443
+ void DrawElements (Surface &surface) {
2431
2444
Rect frame = surface.GetFrame ();
2432
2445
Rect fields_bounds, actions_bounds;
2433
2446
frame.HorizontalSplit (surface.GetHeight () - GetActionsHeight (),
2434
2447
fields_bounds, actions_bounds);
2435
- SubPad fields_surface = SubPad ( surface, fields_bounds);
2436
- SubPad actions_surface = SubPad ( surface, actions_bounds);
2448
+ Surface fields_surface = surface. SubSurface ( fields_bounds);
2449
+ Surface actions_surface = surface. SubSurface ( actions_bounds);
2437
2450
2438
2451
DrawFields (fields_surface);
2439
2452
DrawActions (actions_surface);
@@ -2442,7 +2455,7 @@ class FormWindowDelegate : public WindowDelegate {
2442
2455
// Contents are first drawn on a pad. Then a subset of that pad is copied to
2443
2456
// the derived window starting at the first visible line. This essentially
2444
2457
// provides scrolling functionality.
2445
- void DrawContent (DerivedWindow &surface) {
2458
+ void DrawContent (Surface &surface) {
2446
2459
UpdateScrolling (surface);
2447
2460
2448
2461
int width = surface.GetWidth ();
@@ -2452,8 +2465,8 @@ class FormWindowDelegate : public WindowDelegate {
2452
2465
Rect frame = pad.GetFrame ();
2453
2466
Rect error_bounds, elements_bounds;
2454
2467
frame.HorizontalSplit (GetErrorHeight (), error_bounds, elements_bounds);
2455
- SubPad error_surface = SubPad ( pad, error_bounds);
2456
- SubPad elements_surface = SubPad ( pad, elements_bounds);
2468
+ Surface error_surface = pad. SubSurface ( error_bounds);
2469
+ Surface elements_surface = pad. SubSurface ( elements_bounds);
2457
2470
2458
2471
DrawError (error_surface);
2459
2472
DrawElements (elements_surface);
@@ -2473,7 +2486,7 @@ class FormWindowDelegate : public WindowDelegate {
2473
2486
2474
2487
Rect content_bounds = window.GetFrame ();
2475
2488
content_bounds.Inset (2 , 2 );
2476
- DerivedWindow content_surface = DerivedWindow ( window, content_bounds);
2489
+ Surface content_surface = window. SubSurface ( content_bounds);
2477
2490
2478
2491
DrawContent (content_surface);
2479
2492
return true ;
0 commit comments