comparison dwtestoo.cpp @ 2930:d8117d36ed27

C++: Add Page 4 - Container to dwtestoo. Had to rename ListBoxes G/SetText() to G/SetListText(). Since TextEntry has the same names but with different signatures. Thought it should be able to differentiate, but it errored as ambiguous. Also make ListSelect unsigned int since it should never be negative.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 30 Dec 2022 12:15:19 +0000
parents 2ab97b349958
children 30c1f37713b6
comparison
equal deleted inserted replaced
2929:2ab97b349958 2930:d8117d36ed27
389 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); 389 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
390 390
391 return menu; 391 return menu;
392 } 392 }
393 393
394 DW::ComboBox *ColorCombobox(void)
395 {
396 DW::ComboBox *combobox = new DW::ComboBox("DW_CLR_DEFAULT");
397
398 combobox->Append("DW_CLR_DEFAULT");
399 combobox->Append("DW_CLR_BLACK");
400 combobox->Append("DW_CLR_DARKRED");
401 combobox->Append("DW_CLR_DARKGREEN");
402 combobox->Append("DW_CLR_BROWN");
403 combobox->Append("DW_CLR_DARKBLUE");
404 combobox->Append("DW_CLR_DARKPINK");
405 combobox->Append("DW_CLR_DARKCYAN");
406 combobox->Append("DW_CLR_PALEGRAY");
407 combobox->Append("DW_CLR_DARKGRAY");
408 combobox->Append("DW_CLR_RED");
409 combobox->Append("DW_CLR_GREEN");
410 combobox->Append("DW_CLR_YELLOW");
411 combobox->Append("DW_CLR_BLUE");
412 combobox->Append("DW_CLR_PINK");
413 combobox->Append("DW_CLR_CYAN");
414 combobox->Append("DW_CLR_WHITE");
415 return combobox;
416 }
417
418 unsigned long ComboboxColor(const char *colortext)
419 {
420 unsigned long color = DW_CLR_DEFAULT;
421
422 if(strcmp(colortext, "DW_CLR_BLACK") == 0)
423 color = DW_CLR_BLACK;
424 else if(strcmp(colortext, "DW_CLR_DARKRED") == 0)
425 color = DW_CLR_DARKRED;
426 else if(strcmp(colortext, "DW_CLR_DARKGREEN") == 0)
427 color = DW_CLR_DARKGREEN;
428 else if(strcmp(colortext, "DW_CLR_BROWN") == 0)
429 color = DW_CLR_BROWN;
430 else if(strcmp(colortext, "DW_CLR_DARKBLUE") == 0)
431 color = DW_CLR_DARKBLUE;
432 else if(strcmp(colortext, "DW_CLR_DARKPINK") == 0)
433 color = DW_CLR_DARKPINK;
434 else if(strcmp(colortext, "DW_CLR_DARKCYAN") == 0)
435 color = DW_CLR_DARKCYAN;
436 else if(strcmp(colortext, "DW_CLR_PALEGRAY") == 0)
437 color = DW_CLR_PALEGRAY;
438 else if(strcmp(colortext, "DW_CLR_DARKGRAY") == 0)
439 color = DW_CLR_DARKGRAY;
440 else if(strcmp(colortext, "DW_CLR_RED") == 0)
441 color = DW_CLR_RED;
442 else if(strcmp(colortext, "DW_CLR_GREEN") == 0)
443 color = DW_CLR_GREEN;
444 else if(strcmp(colortext, "DW_CLR_YELLOW") == 0)
445 color = DW_CLR_YELLOW;
446 else if(strcmp(colortext, "DW_CLR_BLUE") == 0)
447 color = DW_CLR_BLUE;
448 else if(strcmp(colortext, "DW_CLR_PINK") == 0)
449 color = DW_CLR_PINK;
450 else if(strcmp(colortext, "DW_CLR_CYAN") == 0)
451 color = DW_CLR_CYAN;
452 else if(strcmp(colortext, "DW_CLR_WHITE") == 0)
453 color = DW_CLR_WHITE;
454
455 return color;
456 }
457
458 void MLESetFont(DW::MLE *mle, int fontsize, char *fontname)
459 {
460 char font[101] = {0};
461
462 if(fontname)
463 snprintf(font, 100, "%d.%s", fontsize, fontname);
464 mle->SetFont(fontname ? font : NULL);
465 }
466
394 // Add the menus to the window 467 // Add the menus to the window
395 void CreateMenus() { 468 void CreateMenus() {
396 // Setup the menu 469 // Setup the menu
397 DW::MenuBar *menubar = this->MenuBarNew(); 470 DW::MenuBar *menubar = this->MenuBarNew();
398 471
951 }); 1024 });
952 print->Run(0); 1025 print->Run(0);
953 return TRUE; 1026 return TRUE;
954 }); 1027 });
955 1028
956 rendcombo->ConnectListSelect([this](int index) -> int 1029 rendcombo->ConnectListSelect([this](unsigned int index) -> int
957 { 1030 {
958 if(index != this->render_type) 1031 if(index != this->render_type)
959 { 1032 {
960 if(index == DRAW_FILE) 1033 if(index == DRAW_FILE)
961 { 1034 {
1016 }); 1089 });
1017 tree->ConnectItemSelect([tree_status](HTREEITEM item, char *text, void *itemdata) 1090 tree->ConnectItemSelect([tree_status](HTREEITEM item, char *text, void *itemdata)
1018 { 1091 {
1019 char buf[201] = {0}; 1092 char buf[201] = {0};
1020 1093
1021 snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Item Data: %x", DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata)); 1094 snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Itemdata: %x", DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata));
1022 tree_status->SetText(buf); 1095 tree_status->SetText(buf);
1023 return FALSE; 1096 return FALSE;
1024 }); 1097 });
1025 1098
1026 HTREEITEM t1 = tree->Insert("tree folder 1", foldericon, DW_NULL, DW_INT_TO_POINTER(1)); 1099 HTREEITEM t1 = tree->Insert("tree folder 1", foldericon, DW_NULL, DW_INT_TO_POINTER(1));
1043 DW::Text *text = new DW::Text("Tree widget not available."); 1116 DW::Text *text = new DW::Text("Tree widget not available.");
1044 notebookbox->PackStart(text, 500, 200, TRUE, TRUE, 1); 1117 notebookbox->PackStart(text, 500, 200, TRUE, TRUE, 1);
1045 } 1118 }
1046 } 1119 }
1047 1120
1121 // Page 4 - Container
1122 void CreateContainer(DW::Box *notebookbox)
1123 {
1124 char buffer[101] = {0};
1125 CTIME time;
1126 CDATE date;
1127
1128 // create a box to pack into the notebook page
1129 DW::Box *containerbox = new DW::Box(DW_HORZ, 2);
1130 notebookbox->PackStart(containerbox, 500, 200, TRUE, TRUE, 0);
1131
1132 // Add a word wrap checkbox
1133 DW::Box *hbox = new DW::Box(DW_HORZ, 0);
1134
1135 DW::CheckBox *checkbox = new DW::CheckBox("Word wrap");
1136 hbox->PackStart(checkbox, FALSE, TRUE, 1);
1137 DW::Text *text = new DW::Text("Foreground:");
1138 text->SetStyle(DW_DT_VCENTER);
1139 hbox->PackStart(text, FALSE, TRUE, 1);
1140 DW::ComboBox *mlefore = ColorCombobox();
1141 hbox->PackStart(mlefore, 150, DW_SIZE_AUTO, TRUE, FALSE, 1);
1142 text = new DW::Text("Background:");
1143 text->SetStyle(DW_DT_VCENTER);
1144 hbox->PackStart(text, FALSE, TRUE, 1);
1145 DW::ComboBox *mleback = ColorCombobox();
1146 hbox->PackStart(mleback, 150, DW_SIZE_AUTO, TRUE, FALSE, 1);
1147 checkbox->Set(TRUE);
1148 text = new DW::Text("Font:");
1149 text->SetStyle(DW_DT_VCENTER);
1150 hbox->PackStart(text, FALSE, TRUE, 1);
1151 DW::SpinButton *fontsize = new DW::SpinButton("9");
1152 hbox->PackStart(fontsize, FALSE, FALSE, 1);
1153 fontsize->SetLimits(100, 5);
1154 fontsize->SetPos(9);
1155 DW::ComboBox *fontname = new DW::ComboBox("Default");
1156 fontname->Append("Default");
1157 fontname->Append("Arial");
1158 fontname->Append("Geneva");
1159 fontname->Append("Verdana");
1160 fontname->Append("Helvetica");
1161 fontname->Append("DejaVu Sans");
1162 fontname->Append("Times New Roman");
1163 fontname->Append("Times New Roman Bold");
1164 fontname->Append("Times New Roman Italic");
1165 fontname->Append("Times New Roman Bold Italic");
1166 hbox->PackStart(fontname, 150, DW_SIZE_AUTO, TRUE, FALSE, 1);
1167 notebookbox->PackStart(hbox, TRUE, FALSE, 1);
1168
1169 // now a container area under this box
1170 DW::Filesystem *container = new DW::Filesystem(TRUE);
1171 notebookbox->PackStart(container, 500, 200, TRUE, FALSE, 1);
1172
1173 // and a status area to see whats going on
1174 DW::StatusText *container_status = new DW::StatusText();
1175 notebookbox->PackStart(container_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1);
1176
1177 const char *titles[] = { "Type", "Size", "Time", "Date" };
1178 unsigned long flags[4] = { DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
1179 DW_CFA_ULONG | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
1180 DW_CFA_TIME | DW_CFA_CENTER | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
1181 DW_CFA_DATE | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR };
1182
1183
1184 container->SetColumnTitle("Test");
1185 container->Setup(flags, titles, 4);
1186 container->SetStripe(DW_CLR_DEFAULT, DW_CLR_DEFAULT);
1187 container->Alloc(3);
1188
1189 for(int z=0;z<3;z++)
1190 {
1191 char names[101] = {0};
1192 HICN thisicon = (z == 0 ? foldericon : fileicon);
1193
1194 snprintf(names, 100, "We can now allocate from the stack: Item: %d", z);
1195 unsigned long size = z*100;
1196 snprintf(buffer, 100, "Filename %d", z+1);
1197 container->SetFile(z, buffer, thisicon);
1198 container->SetItem(0, z, &thisicon);
1199 container->SetItem(1, z, &size);
1200
1201 time.seconds = z+10;
1202 time.minutes = z+10;
1203 time.hours = z+10;
1204 container->SetItem(2, z, &time);
1205
1206 date.day = z+10;
1207 date.month = z+10;
1208 date.year = z+2000;
1209 container->SetItem(3, z, &date);
1210
1211 container->SetRowTitle(z, names);
1212 container->SetRowData(z, DW_INT_TO_POINTER(z));
1213 }
1214
1215 container->Insert();
1216
1217 container->Alloc(1);
1218 container->SetFile(0, "Yikes", foldericon);
1219 unsigned long size = 324;
1220 container->SetItem(0, 0, &foldericon);
1221 container->SetItem(1, 0, &size);
1222 container->SetItem(2, 0, &time);
1223 container->SetItem(3, 0, &date);
1224 container->SetRowTitle(0, "Extra");
1225
1226 container->Insert();
1227 container->Optimize();
1228
1229 DW::MLE *container_mle = new DW::MLE();
1230 containerbox->PackStart(container_mle, 500, 200, TRUE, TRUE, 0);
1231
1232 mle_point = container_mle->Import("", -1);
1233 snprintf(buffer, 100, "[%d]", mle_point);
1234 mle_point = container_mle->Import(buffer, mle_point);
1235 snprintf(buffer, 100, "[%d]abczxydefijkl", mle_point);
1236 mle_point = container_mle->Import(buffer, mle_point);
1237 container_mle->Delete(9, 3);
1238 mle_point = container_mle->Import("gh", 12);
1239 unsigned long newpoint;
1240 container_mle->GetSize(&newpoint, NULL);
1241 mle_point = (int)newpoint;
1242 snprintf(buffer, 100, "[%d]\r\n\r\n", mle_point);
1243 mle_point = container_mle->Import(buffer, mle_point);
1244 container_mle->SetCursor(mle_point);
1245
1246 // connect our event trappers...
1247 container->ConnectItemEnter([container_status](char *text, void *itemdata) -> int
1248 {
1249 char buf[201] = {0};
1250
1251 snprintf(buf, 200, "DW_SIGNAL_ITEM_ENTER: Text: %s Itemdata: %x", text, DW_POINTER_TO_UINT(itemdata));
1252 container_status->SetText(buf);
1253 return FALSE;
1254 });
1255
1256 container->ConnectItemContext([this, container_status](char *text, int x, int y, void *itemdata) -> int
1257 {
1258 char buf[201] = {0};
1259 DW::Menu *popupmenu = ItemContextMenu(container_status, "Item context menu clicked.");
1260
1261 snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d Itemdata: %x", text, x, y, DW_POINTER_TO_UINT(itemdata));
1262 container_status->SetText(buf);
1263 popupmenu->Popup(this, x, y);
1264 return FALSE;
1265 });
1266
1267 container->ConnectItemSelect([this, container_mle, container, container_status](HTREEITEM item, char *text, void *itemdata) -> int
1268 {
1269 char buf[201] = {0};
1270
1271 snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Itemdata: %x",
1272 DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata));
1273 container_status->SetText(buf);
1274 snprintf(buf, 200, "\r\nDW_SIGNAL_ITEM_SELECT: Item: %x Text: %s Itemdata: %x\r\n",
1275 DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata));
1276 this->mle_point = container_mle->Import(buf, mle_point);
1277 char *str = container->QueryStart(DW_CRA_SELECTED);
1278 while(str)
1279 {
1280 snprintf(buf, 200, "Selected: %s\r\n", str);
1281 mle_point = container_mle->Import(buf, mle_point);
1282 this->app->Free(str);
1283 str = container->QueryNext(DW_CRA_SELECTED);
1284 }
1285 // Make the last inserted point the cursor location
1286 container_mle->SetCursor(mle_point);
1287 // set the details of item 0 to new data
1288 this->app->Debug("In cb: icon: %x\n", DW_POINTER_TO_INT(fileicon));
1289 container->ChangeFile(0, "new data", fileicon);
1290 unsigned long size = 999;
1291 this->app->Debug("In cb: icon: %x\n", DW_POINTER_TO_INT(fileicon));
1292 container->ChangeItem(1, 0, &size);
1293 return FALSE;
1294 });
1295
1296 container->ConnectColumnClick([container, container_status](int column_num) -> int
1297 {
1298 const char *type_string = "Filename";
1299
1300 if(column_num != 0)
1301 {
1302 int column_type = container->GetColumnType(column_num-1);
1303
1304 if(column_type == DW_CFA_STRING)
1305 type_string = "String";
1306 else if(column_type == DW_CFA_ULONG)
1307 type_string ="ULong";
1308 else if(column_type == DW_CFA_DATE)
1309 type_string = "Date";
1310 else if(column_type == DW_CFA_TIME)
1311 type_string ="Time";
1312 else if(column_type == DW_CFA_BITMAPORICON)
1313 type_string = "BitmapOrIcon";
1314 else
1315 type_string = "Unknown";
1316 }
1317 char buf[201] = {0};
1318 snprintf(buf, 200, "DW_SIGNAL_COLUMN_CLICK: Column: %d Type: %s", column_num, type_string);
1319 container_status->SetText(buf);
1320 return FALSE;
1321 });
1322
1323 mlefore->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int
1324 {
1325 char colortext[101] = {0};
1326 ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT;
1327
1328 mlefore->GetListText(pos, colortext, 100);
1329 fore = ComboboxColor(colortext);
1330 char *text = mleback->GetText();
1331
1332 if(text && *text)
1333 {
1334 back = ComboboxColor(text);
1335 this->app->Free(text);
1336 }
1337 container_mle->SetColor(fore, back);
1338 return FALSE;
1339 });
1340
1341 mleback->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int
1342 {
1343 char colortext[101] = {0};
1344 ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT;
1345
1346 mleback->GetListText(pos, colortext, 100);
1347 back = ComboboxColor(colortext);
1348 char *text = mlefore->GetText();
1349
1350 if(text && *text)
1351 {
1352 fore = ComboboxColor(text);
1353 this->app->Free(text);
1354 }
1355 container_mle->SetColor(fore, back);
1356 return FALSE;
1357 });
1358
1359 fontname->ConnectListSelect([this, fontname, fontsize, container_mle](unsigned int pos) -> int
1360 {
1361 char font[101] = {0};
1362
1363 fontname->GetListText(pos, font, 100);
1364 MLESetFont(container_mle, (int)fontsize->GetPos(), strcmp(font, "Default") == 0 ? NULL : font);
1365 return FALSE;
1366 });
1367
1368 fontsize->ConnectValueChanged([this, fontname, container_mle](int size) -> int
1369 {
1370 char *font = fontname->GetText();
1371
1372 if(font)
1373 {
1374 MLESetFont(container_mle, size, strcmp(font, "Default") == 0 ? NULL : font);
1375 this->app->Free(font);
1376 }
1377 else
1378 MLESetFont(container_mle, size, NULL);
1379 return FALSE;
1380 });
1381 }
1382
1048 public: 1383 public:
1049 // Constructor creates the application 1384 // Constructor creates the application
1050 DWTest(const char *title): DW::Window(title) { 1385 DWTest(const char *title): DW::Window(title) {
1051 char fileiconpath[1025] = "file"; 1386 char fileiconpath[1025] = "file";
1052 char foldericonpath[1025] = "folder"; 1387 char foldericonpath[1025] = "folder";
1127 notebookbox = new DW::Box(DW_VERT, 5); 1462 notebookbox = new DW::Box(DW_VERT, 5);
1128 CreateTree(notebookbox); 1463 CreateTree(notebookbox);
1129 notebookpage = notebook->PageNew(); 1464 notebookpage = notebook->PageNew();
1130 notebook->Pack(notebookpage, notebookbox); 1465 notebook->Pack(notebookpage, notebookbox);
1131 notebook->PageSetText(notebookpage, "tree"); 1466 notebook->PageSetText(notebookpage, "tree");
1467
1468 // Create Notebook Page 4 - Container
1469 notebookbox = new DW::Box(DW_VERT, 5);
1470 CreateContainer(notebookbox);
1471 notebookpage = notebook->PageNew();
1472 notebook->Pack(notebookpage, notebookbox);
1473 notebook->PageSetText(notebookpage, "container");
1132 1474
1133 // Finalize the window 1475 // Finalize the window
1134 this->SetSize(640, 550); 1476 this->SetSize(640, 550);
1135 1477
1136 timer = new DW::Timer(2000, [this]() -> int 1478 timer = new DW::Timer(2000, [this]() -> int