Mercurial > dwindows
comparison dwtestoo.cpp @ 2961:b9bd130f438a
C++: Step 3 of the std::string transition.
Convert the class overrides to use std::string instead of char*.
Implement functions that take arrays of strings to std::vector<std::string>.
Begin converting dwtestoo to use std::string instead of C style strings.
Temporarily rename C style Connect functions to have a C at the end.
It isn't clear to me why, but clang is telling me they are ambiguous.
Even though the lambda explicitly specifies std::string it can't decide
between the std::string or char* versions of the functions.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 23 Feb 2023 15:24:36 +0000 |
parents | 1dabe9c6c67b |
children | e6072eb914ce |
comparison
equal
deleted
inserted
replaced
2960:1dabe9c6c67b | 2961:b9bd130f438a |
---|---|
411 combobox->Append("DW_CLR_CYAN"); | 411 combobox->Append("DW_CLR_CYAN"); |
412 combobox->Append("DW_CLR_WHITE"); | 412 combobox->Append("DW_CLR_WHITE"); |
413 return combobox; | 413 return combobox; |
414 } | 414 } |
415 | 415 |
416 unsigned long ComboboxColor(const char *colortext) { | 416 unsigned long ComboboxColor(std::string colortext) { |
417 unsigned long color = DW_CLR_DEFAULT; | 417 unsigned long color = DW_CLR_DEFAULT; |
418 | 418 |
419 if(strcmp(colortext, "DW_CLR_BLACK") == 0) | 419 if(colortext.compare("DW_CLR_BLACK") == 0) |
420 color = DW_CLR_BLACK; | 420 color = DW_CLR_BLACK; |
421 else if(strcmp(colortext, "DW_CLR_DARKRED") == 0) | 421 else if(colortext.compare("DW_CLR_DARKRED") == 0) |
422 color = DW_CLR_DARKRED; | 422 color = DW_CLR_DARKRED; |
423 else if(strcmp(colortext, "DW_CLR_DARKGREEN") == 0) | 423 else if(colortext.compare("DW_CLR_DARKGREEN") == 0) |
424 color = DW_CLR_DARKGREEN; | 424 color = DW_CLR_DARKGREEN; |
425 else if(strcmp(colortext, "DW_CLR_BROWN") == 0) | 425 else if(colortext.compare("DW_CLR_BROWN") == 0) |
426 color = DW_CLR_BROWN; | 426 color = DW_CLR_BROWN; |
427 else if(strcmp(colortext, "DW_CLR_DARKBLUE") == 0) | 427 else if(colortext.compare("DW_CLR_DARKBLUE") == 0) |
428 color = DW_CLR_DARKBLUE; | 428 color = DW_CLR_DARKBLUE; |
429 else if(strcmp(colortext, "DW_CLR_DARKPINK") == 0) | 429 else if(colortext.compare("DW_CLR_DARKPINK") == 0) |
430 color = DW_CLR_DARKPINK; | 430 color = DW_CLR_DARKPINK; |
431 else if(strcmp(colortext, "DW_CLR_DARKCYAN") == 0) | 431 else if(colortext.compare("DW_CLR_DARKCYAN") == 0) |
432 color = DW_CLR_DARKCYAN; | 432 color = DW_CLR_DARKCYAN; |
433 else if(strcmp(colortext, "DW_CLR_PALEGRAY") == 0) | 433 else if(colortext.compare("DW_CLR_PALEGRAY") == 0) |
434 color = DW_CLR_PALEGRAY; | 434 color = DW_CLR_PALEGRAY; |
435 else if(strcmp(colortext, "DW_CLR_DARKGRAY") == 0) | 435 else if(colortext.compare("DW_CLR_DARKGRAY") == 0) |
436 color = DW_CLR_DARKGRAY; | 436 color = DW_CLR_DARKGRAY; |
437 else if(strcmp(colortext, "DW_CLR_RED") == 0) | 437 else if(colortext.compare("DW_CLR_RED") == 0) |
438 color = DW_CLR_RED; | 438 color = DW_CLR_RED; |
439 else if(strcmp(colortext, "DW_CLR_GREEN") == 0) | 439 else if(colortext.compare("DW_CLR_GREEN") == 0) |
440 color = DW_CLR_GREEN; | 440 color = DW_CLR_GREEN; |
441 else if(strcmp(colortext, "DW_CLR_YELLOW") == 0) | 441 else if(colortext.compare("DW_CLR_YELLOW") == 0) |
442 color = DW_CLR_YELLOW; | 442 color = DW_CLR_YELLOW; |
443 else if(strcmp(colortext, "DW_CLR_BLUE") == 0) | 443 else if(colortext.compare("DW_CLR_BLUE") == 0) |
444 color = DW_CLR_BLUE; | 444 color = DW_CLR_BLUE; |
445 else if(strcmp(colortext, "DW_CLR_PINK") == 0) | 445 else if(colortext.compare("DW_CLR_PINK") == 0) |
446 color = DW_CLR_PINK; | 446 color = DW_CLR_PINK; |
447 else if(strcmp(colortext, "DW_CLR_CYAN") == 0) | 447 else if(colortext.compare("DW_CLR_CYAN") == 0) |
448 color = DW_CLR_CYAN; | 448 color = DW_CLR_CYAN; |
449 else if(strcmp(colortext, "DW_CLR_WHITE") == 0) | 449 else if(colortext.compare("DW_CLR_WHITE") == 0) |
450 color = DW_CLR_WHITE; | 450 color = DW_CLR_WHITE; |
451 | 451 |
452 return color; | 452 return color; |
453 } | 453 } |
454 | 454 |
455 void MLESetFont(DW::MLE *mle, int fontsize, char *fontname) { | 455 void MLESetFont(DW::MLE *mle, int fontsize, std::string fontname) { |
456 char font[151] = {0}; | 456 if(fontname.size() && fontsize > 0) { |
457 | 457 mle->SetFont(std::to_string(fontsize) + "." + fontname); |
458 if(fontname) | 458 } |
459 snprintf(font, 150, "%d.%s", fontsize, fontname); | 459 mle->SetFont(NULL); |
460 mle->SetFont(fontname ? font : NULL); | |
461 } | 460 } |
462 | 461 |
463 // Thread and Event functions | 462 // Thread and Event functions |
464 void UpdateMLE(DW::MLE *threadmle, const char *text, DW::Mutex *mutex) { | 463 void UpdateMLE(DW::MLE *threadmle, const char *text, DW::Mutex *mutex) { |
465 static unsigned int pos = 0; | 464 static unsigned int pos = 0; |
754 this->app->Debug("Folder picked: %s\n", tmp ? tmp : "None"); | 753 this->app->Debug("Folder picked: %s\n", tmp ? tmp : "None"); |
755 return FALSE; | 754 return FALSE; |
756 }); | 755 }); |
757 | 756 |
758 copybutton->ConnectClicked([this, copypastefield, entryfield]() -> int { | 757 copybutton->ConnectClicked([this, copypastefield, entryfield]() -> int { |
759 char *test = copypastefield->GetCText(); | 758 std::string test = copypastefield->GetText(); |
760 | 759 |
761 if(test) { | 760 if(test.size()) { |
762 this->app->SetClipboard(test); | 761 this->app->SetClipboard(test); |
763 this->app->Free(test); | |
764 } | 762 } |
765 entryfield->SetFocus(); | 763 entryfield->SetFocus(); |
766 return TRUE; | 764 return TRUE; |
767 }); | 765 }); |
768 | 766 |
769 pastebutton->ConnectClicked([this, copypastefield]() -> int | 767 pastebutton->ConnectClicked([this, copypastefield]() -> int |
770 { | 768 { |
771 char *test = this->app->GetCClipboard(); | 769 std::string test = this->app->GetClipboard(); |
772 if(test) { | 770 if(test.size()) { |
773 copypastefield->SetText(test); | 771 copypastefield->SetText(test); |
774 this->app->Free(test); | |
775 } | 772 } |
776 return TRUE; | 773 return TRUE; |
777 }); | 774 }); |
778 | 775 |
779 okbutton->ConnectClicked([this]() -> int | 776 okbutton->ConnectClicked([this]() -> int |
915 image = new DW::Pixmap(render1, "image/test"); | 912 image = new DW::Pixmap(render1, "image/test"); |
916 if(!image || !image->GetHPIXMAP()) | 913 if(!image || !image->GetHPIXMAP()) |
917 image = new DW::Pixmap(render1, "~/test"); | 914 image = new DW::Pixmap(render1, "~/test"); |
918 if(!image || !image->GetHPIXMAP()) | 915 if(!image || !image->GetHPIXMAP()) |
919 { | 916 { |
920 char *appdir = app->GetCDir(); | 917 std::string appdir = app->GetDir(); |
921 char pathbuff[1025] = {0}; | 918 appdir.append(std::string(1, DW_DIR_SEPARATOR)); |
922 int pos = (int)strlen(appdir); | 919 appdir.append("test"); |
923 | 920 image = new DW::Pixmap(render1, appdir); |
924 strncpy(pathbuff, appdir, 1024); | |
925 pathbuff[pos] = DW_DIR_SEPARATOR; | |
926 pos++; | |
927 strncpy(&pathbuff[pos], "test", 1024-pos); | |
928 image = new DW::Pixmap(render1, pathbuff); | |
929 } | 921 } |
930 if(image) | 922 if(image) |
931 image->SetTransparentColor(DW_CLR_WHITE); | 923 image->SetTransparentColor(DW_CLR_WHITE); |
932 | 924 |
933 app->MessageBox(utf8string ? utf8string : "DWTest", DW_MB_OK|DW_MB_INFORMATION, "Width: %d Height: %d\n", font_width, font_height); | 925 app->MessageBox(utf8string ? utf8string : "DWTest", DW_MB_OK|DW_MB_INFORMATION, "Width: %d Height: %d\n", font_width, font_height); |
1180 // and a status area to see whats going on | 1172 // and a status area to see whats going on |
1181 DW::StatusText *tree_status = new DW::StatusText(); | 1173 DW::StatusText *tree_status = new DW::StatusText(); |
1182 notebookbox->PackStart(tree_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); | 1174 notebookbox->PackStart(tree_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); |
1183 | 1175 |
1184 // set up our signal trappers... | 1176 // set up our signal trappers... |
1185 tree->ConnectItemContext([this, tree_status](char *text, int x, int y, void *data) -> int | 1177 tree->ConnectItemContext([this, tree_status](std::string text, int x, int y, void *data) -> int |
1186 { | 1178 { |
1187 char buf[201] = {0}; | |
1188 DW::Menu *popupmenu = ItemContextMenu(tree_status, "Item context menu clicked."); | 1179 DW::Menu *popupmenu = ItemContextMenu(tree_status, "Item context menu clicked."); |
1189 | 1180 std::string buf = "DW_SIGNAL_ITEM_CONTEXT: Text: " + text + " x: " + std::to_string(x) + " y: " + std::to_string(y); |
1190 snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d", text, x, y); | |
1191 tree_status->SetText(buf); | 1181 tree_status->SetText(buf); |
1192 popupmenu->Popup(this, x, y); | 1182 popupmenu->Popup(this, x, y); |
1193 return FALSE; | 1183 return FALSE; |
1194 }); | 1184 }); |
1195 tree->ConnectItemSelect([tree_status](HTREEITEM item, char *text, void *itemdata) | 1185 tree->ConnectItemSelect([tree_status](HTREEITEM item, std::string text, void *itemdata) |
1196 { | 1186 { |
1197 char buf[201] = {0}; | 1187 std::string sitem = std::to_string(DW_POINTER_TO_UINT(item)); |
1198 | 1188 std::string sitemdata = std::to_string(DW_POINTER_TO_UINT(itemdata)); |
1199 snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Itemdata: %x", DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata)); | 1189 std::string buf = "DW_SIGNAL_ITEM_SELECT: Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata; |
1200 tree_status->SetText(buf); | 1190 tree_status->SetText(buf); |
1201 return FALSE; | 1191 return FALSE; |
1202 }); | 1192 }); |
1203 | 1193 |
1204 HTREEITEM t1 = tree->Insert("tree folder 1", foldericon, DW_NULL, DW_INT_TO_POINTER(1)); | 1194 HTREEITEM t1 = tree->Insert("tree folder 1", foldericon, DW_NULL, DW_INT_TO_POINTER(1)); |
1209 tree->Insert("tree file 4", fileicon, t2, DW_INT_TO_POINTER(6)); | 1199 tree->Insert("tree file 4", fileicon, t2, DW_INT_TO_POINTER(6)); |
1210 tree->Change(t1, "tree folder 1", foldericon); | 1200 tree->Change(t1, "tree folder 1", foldericon); |
1211 tree->Change(t2, "tree folder 2", foldericon); | 1201 tree->Change(t2, "tree folder 2", foldericon); |
1212 tree->SetData(t2, DW_INT_TO_POINTER(100)); | 1202 tree->SetData(t2, DW_INT_TO_POINTER(100)); |
1213 tree->Expand(t1); | 1203 tree->Expand(t1); |
1214 char *title = tree->GetCTitle(t1); | 1204 int t1data = DW_POINTER_TO_INT(tree->GetData(t1)); |
1215 this->app->Debug("t1 title \"%s\" data %d t2 data %d\n", title, DW_POINTER_TO_INT(tree->GetData(t1)), | 1205 int t2data = DW_POINTER_TO_INT(tree->GetData(t2)); |
1216 DW_POINTER_TO_INT(tree->GetData(t2))); | 1206 std::string message = "t1 title \"" + tree->GetTitle(t1) + "\" data " + std::to_string(t1data) + " t2 data " + std::to_string(t2data) + "\n"; |
1217 this->app->Free(title); | 1207 |
1208 this->app->Debug(message); | |
1218 } | 1209 } |
1219 else | 1210 else |
1220 { | 1211 { |
1221 DW::Text *text = new DW::Text("Tree widget not available."); | 1212 DW::Text *text = new DW::Text("Tree widget not available."); |
1222 notebookbox->PackStart(text, 500, 200, TRUE, TRUE, 1); | 1213 notebookbox->PackStart(text, 500, 200, TRUE, TRUE, 1); |
1276 | 1267 |
1277 // and a status area to see whats going on | 1268 // and a status area to see whats going on |
1278 DW::StatusText *container_status = new DW::StatusText(); | 1269 DW::StatusText *container_status = new DW::StatusText(); |
1279 notebookbox->PackStart(container_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); | 1270 notebookbox->PackStart(container_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); |
1280 | 1271 |
1281 const char *titles[] = { "Type", "Size", "Time", "Date" }; | 1272 std::vector<std::string> titles = { "Type", "Size", "Time", "Date" }; |
1282 unsigned long flags[4] = { DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, | 1273 std::vector<unsigned long> flags = { |
1283 DW_CFA_ULONG | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, | 1274 DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, |
1284 DW_CFA_TIME | DW_CFA_CENTER | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, | 1275 DW_CFA_ULONG | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, |
1285 DW_CFA_DATE | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR }; | 1276 DW_CFA_TIME | DW_CFA_CENTER | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, |
1277 DW_CFA_DATE | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR }; | |
1286 | 1278 |
1287 | 1279 |
1288 container->SetColumnTitle("Test"); | 1280 container->SetColumnTitle("Test"); |
1289 container->Setup(flags, titles, 4); | 1281 container->Setup(flags, titles); |
1290 container->SetStripe(DW_CLR_DEFAULT, DW_CLR_DEFAULT); | 1282 container->SetStripe(DW_CLR_DEFAULT, DW_CLR_DEFAULT); |
1291 container->Alloc(3); | 1283 container->Alloc(3); |
1292 | 1284 |
1293 for(int z=0;z<3;z++) | 1285 for(int z=0;z<3;z++) |
1294 { | 1286 { |
1346 snprintf(buffer, 100, "[%d]\r\n\r\n", mle_point); | 1338 snprintf(buffer, 100, "[%d]\r\n\r\n", mle_point); |
1347 mle_point = container_mle->Import(buffer, mle_point); | 1339 mle_point = container_mle->Import(buffer, mle_point); |
1348 container_mle->SetCursor(mle_point); | 1340 container_mle->SetCursor(mle_point); |
1349 | 1341 |
1350 // connect our event trappers... | 1342 // connect our event trappers... |
1351 container->ConnectItemEnter([container_status](char *text, void *itemdata) -> int | 1343 container->ConnectItemEnter([container_status](std::string text, void *itemdata) -> int |
1352 { | 1344 { |
1353 char buf[201] = {0}; | 1345 std::string buf = "DW_SIGNAL_ITEM_ENTER: Text: " + text + "Itemdata: " + std::to_string(DW_POINTER_TO_UINT(itemdata)); |
1354 | |
1355 snprintf(buf, 200, "DW_SIGNAL_ITEM_ENTER: Text: %s Itemdata: %x", text, DW_POINTER_TO_UINT(itemdata)); | |
1356 container_status->SetText(buf); | 1346 container_status->SetText(buf); |
1357 return FALSE; | 1347 return FALSE; |
1358 }); | 1348 }); |
1359 | 1349 |
1360 container->ConnectItemContext([this, container_status](char *text, int x, int y, void *itemdata) -> int | 1350 container->ConnectItemContext([this, container_status](std::string text, int x, int y, void *itemdata) -> int |
1361 { | 1351 { |
1362 char buf[201] = {0}; | |
1363 DW::Menu *popupmenu = ItemContextMenu(container_status, "Item context menu clicked."); | 1352 DW::Menu *popupmenu = ItemContextMenu(container_status, "Item context menu clicked."); |
1364 | 1353 std::string buf = "DW_SIGNAL_ITEM_CONTEXT: Text: " + text + " x: " + std::to_string(x) + " y: " + |
1365 snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d Itemdata: %x", text, x, y, DW_POINTER_TO_UINT(itemdata)); | 1354 std::to_string(y) + " Itemdata: " + std::to_string(DW_POINTER_TO_UINT(itemdata)); |
1355 | |
1366 container_status->SetText(buf); | 1356 container_status->SetText(buf); |
1367 popupmenu->Popup(this, x, y); | 1357 popupmenu->Popup(this, x, y); |
1368 return FALSE; | 1358 return FALSE; |
1369 }); | 1359 }); |
1370 | 1360 |
1371 container->ConnectItemSelect([this, container_mle, container, container_status](HTREEITEM item, char *text, void *itemdata) -> int | 1361 container->ConnectItemSelect([this, container_mle, container, container_status](HTREEITEM item, std::string text, void *itemdata) -> int |
1372 { | 1362 { |
1373 char buf[201] = {0}; | 1363 std::string sitemdata = std::to_string(DW_POINTER_TO_UINT(itemdata)); |
1374 | 1364 std::string sitem = std::to_string(DW_POINTER_TO_UINT(item)); |
1375 snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Itemdata: %x", | 1365 std::string buf = "DW_SIGNAL_ITEM_SELECT:Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata; |
1376 DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata)); | |
1377 container_status->SetText(buf); | 1366 container_status->SetText(buf); |
1378 snprintf(buf, 200, "\r\nDW_SIGNAL_ITEM_SELECT: Item: %x Text: %s Itemdata: %x\r\n", | 1367 buf = "\r\nDW_SIGNAL_ITEM_SELECT: Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata + "\r\n"; |
1379 DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata)); | |
1380 this->mle_point = container_mle->Import(buf, mle_point); | 1368 this->mle_point = container_mle->Import(buf, mle_point); |
1381 char *str = container->QueryStart(DW_CRA_SELECTED); | 1369 std::string str = container->QueryStart(DW_CRA_SELECTED); |
1382 while(str) | 1370 while(str.size()) |
1383 { | 1371 { |
1384 snprintf(buf, 200, "Selected: %s\r\n", str); | 1372 std::string buf = "Selected: " + str + "%s\r\n"; |
1385 mle_point = container_mle->Import(buf, mle_point); | 1373 mle_point = container_mle->Import(buf, mle_point); |
1386 this->app->Free(str); | |
1387 str = container->QueryNext(DW_CRA_SELECTED); | 1374 str = container->QueryNext(DW_CRA_SELECTED); |
1388 } | 1375 } |
1389 // Make the last inserted point the cursor location | 1376 // Make the last inserted point the cursor location |
1390 container_mle->SetCursor(mle_point); | 1377 container_mle->SetCursor(mle_point); |
1391 // set the details of item 0 to new data | 1378 // set the details of item 0 to new data |
1424 return FALSE; | 1411 return FALSE; |
1425 }); | 1412 }); |
1426 | 1413 |
1427 mlefore->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int | 1414 mlefore->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int |
1428 { | 1415 { |
1429 char colortext[101] = {0}; | |
1430 ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT; | 1416 ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT; |
1431 | 1417 |
1432 mlefore->GetListText(pos, colortext, 100); | 1418 std::string colortext = mlefore->GetListText(pos); |
1433 fore = ComboboxColor(colortext); | 1419 fore = ComboboxColor(colortext); |
1434 char *text = mleback->GetCText(); | 1420 std::string text = mleback->GetText(); |
1435 | 1421 |
1436 if(text && *text) | 1422 if(text.size()) { |
1437 { | |
1438 back = ComboboxColor(text); | 1423 back = ComboboxColor(text); |
1439 this->app->Free(text); | |
1440 } | 1424 } |
1441 container_mle->SetColor(fore, back); | 1425 container_mle->SetColor(fore, back); |
1442 return FALSE; | 1426 return FALSE; |
1443 }); | 1427 }); |
1444 | 1428 |
1445 mleback->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int | 1429 mleback->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int |
1446 { | 1430 { |
1447 char colortext[101] = {0}; | |
1448 ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT; | 1431 ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT; |
1449 | 1432 |
1450 mleback->GetListText(pos, colortext, 100); | 1433 std::string colortext = mleback->GetListText(pos); |
1451 back = ComboboxColor(colortext); | 1434 back = ComboboxColor(colortext); |
1452 char *text = mlefore->GetCText(); | 1435 std::string text = mlefore->GetText(); |
1453 | 1436 |
1454 if(text && *text) | 1437 if(text.size()) { |
1455 { | |
1456 fore = ComboboxColor(text); | 1438 fore = ComboboxColor(text); |
1457 this->app->Free(text); | |
1458 } | 1439 } |
1459 container_mle->SetColor(fore, back); | 1440 container_mle->SetColor(fore, back); |
1460 return FALSE; | 1441 return FALSE; |
1461 }); | 1442 }); |
1462 | 1443 |
1463 fontname->ConnectListSelect([this, fontname, fontsize, container_mle](unsigned int pos) -> int | 1444 fontname->ConnectListSelect([this, fontname, fontsize, container_mle](unsigned int pos) -> int |
1464 { | 1445 { |
1465 char font[101] = {0}; | 1446 std::string font = fontname->GetListText(pos); |
1466 | 1447 MLESetFont(container_mle, (int)fontsize->GetPos(), font.compare("Default") == 0 ? NULL : font); |
1467 fontname->GetListText(pos, font, 100); | |
1468 MLESetFont(container_mle, (int)fontsize->GetPos(), strcmp(font, "Default") == 0 ? NULL : font); | |
1469 return FALSE; | 1448 return FALSE; |
1470 }); | 1449 }); |
1471 | 1450 |
1472 fontsize->ConnectValueChanged([this, fontname, container_mle](int size) -> int | 1451 fontsize->ConnectValueChanged([this, fontname, container_mle](int size) -> int |
1473 { | 1452 { |
1474 char *font = fontname->GetCText(); | 1453 std::string font = fontname->GetText(); |
1475 | 1454 |
1476 if(font) | 1455 if(font.size()) { |
1477 { | 1456 MLESetFont(container_mle, size, font.compare("Default") == 0 ? NULL : font); |
1478 MLESetFont(container_mle, size, strcmp(font, "Default") == 0 ? NULL : font); | |
1479 this->app->Free(font); | |
1480 } | 1457 } |
1481 else | 1458 else |
1482 MLESetFont(container_mle, size, NULL); | 1459 MLESetFont(container_mle, size, NULL); |
1483 return FALSE; | 1460 return FALSE; |
1484 }); | 1461 }); |
1695 hbox->PackStart(0, 5, 1, FALSE, FALSE, 0); | 1672 hbox->PackStart(0, 5, 1, FALSE, FALSE, 0); |
1696 hbox->PackStart(javascript, TRUE, FALSE, 0); | 1673 hbox->PackStart(javascript, TRUE, FALSE, 0); |
1697 | 1674 |
1698 button = new DW::Button("Run"); | 1675 button = new DW::Button("Run"); |
1699 hbox->PackStart(button, FALSE, FALSE, 0); | 1676 hbox->PackStart(button, FALSE, FALSE, 0); |
1700 button->ConnectClicked([this, javascript, html]() -> int | 1677 button->ConnectClicked([javascript, html]() -> int |
1701 { | 1678 { |
1702 char *script = javascript->GetCText(); | 1679 std::string script = javascript->GetText(); |
1703 | 1680 |
1704 html->JavascriptRun(script); | 1681 if(script.size()) { |
1705 this->app->Free(script); | 1682 html->JavascriptRun(script); |
1683 } | |
1706 return FALSE; | 1684 return FALSE; |
1707 }); | 1685 }); |
1708 javascript->ClickDefault(button); | 1686 javascript->ClickDefault(button); |
1709 | 1687 |
1710 notebookbox->PackStart(html, 0, 100, TRUE, TRUE, 0); | 1688 notebookbox->PackStart(html, 0, 100, TRUE, TRUE, 0); |
1711 html->URL("https://dbsoft.org/dw_help.php"); | 1689 html->URL("https://dbsoft.org/dw_help.php"); |
1712 DW::StatusText *htmlstatus = new DW::StatusText("HTML status loading..."); | 1690 DW::StatusText *htmlstatus = new DW::StatusText("HTML status loading..."); |
1713 notebookbox->PackStart(htmlstatus, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); | 1691 notebookbox->PackStart(htmlstatus, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); |
1714 | 1692 |
1715 // Connect the signal handlers | 1693 // Connect the signal handlers |
1716 html->ConnectChanged([htmlstatus](int status, char *url) -> int | 1694 html->ConnectChanged([htmlstatus](int status, std::string url) -> int |
1717 { | 1695 { |
1718 const char *statusnames[] = { "none", "started", "redirect", "loading", "complete", NULL }; | 1696 std::vector<std::string> statusnames = { "none", "started", "redirect", "loading", "complete" }; |
1719 | 1697 |
1720 if(htmlstatus && url && status < 5) | 1698 if(htmlstatus && status < 5) { |
1721 { | 1699 htmlstatus->SetText("Status " + statusnames[status] + ": " + url); |
1722 int length = (int)strlen(url) + (int)strlen(statusnames[status]) + 10; | |
1723 char *text = (char *)calloc(1, length+1); | |
1724 | |
1725 snprintf(text, length, "Status %s: %s", statusnames[status], url); | |
1726 htmlstatus->SetText(text); | |
1727 free(text); | |
1728 } | 1700 } |
1729 return FALSE; | 1701 return FALSE; |
1730 }); | 1702 }); |
1731 | 1703 |
1732 html->ConnectResult([this](int status, char *result, void *script_data) | 1704 html->ConnectResult([this](int status, std::string result, void *script_data) |
1733 { | 1705 { |
1734 this->app->MessageBox("Javascript Result", DW_MB_OK | (status ? DW_MB_ERROR : DW_MB_INFORMATION), | 1706 this->app->MessageBox("Javascript Result", DW_MB_OK | (status ? DW_MB_ERROR : DW_MB_INFORMATION), |
1735 result ? result : "Javascript result is not a string value"); | 1707 result.size() ? result : "Javascript result is not a string value"); |
1736 return TRUE; | 1708 return TRUE; |
1737 }); | 1709 }); |
1738 } | 1710 } |
1739 else | 1711 else |
1740 { | 1712 { |
1842 #ifdef PLATFORMFOLDER | 1814 #ifdef PLATFORMFOLDER |
1843 // In case we are running from the build directory... | 1815 // In case we are running from the build directory... |
1844 // also check the appropriate platform subfolder | 1816 // also check the appropriate platform subfolder |
1845 if(!foldericon) | 1817 if(!foldericon) |
1846 { | 1818 { |
1847 strncpy(foldericonpath, PLATFORMFOLDER "folder", 1024); | 1819 foldericonpath = std::string(PLATFORMFOLDER) + "folder"; |
1848 foldericon = app->LoadIcon(foldericonpath); | 1820 foldericon = app->LoadIcon(foldericonpath); |
1849 } | 1821 } |
1850 if(!fileicon) | 1822 if(!fileicon) |
1851 { | 1823 { |
1852 strncpy(fileiconpath, PLATFORMFOLDER "file", 1024); | 1824 fileiconpath = std::string(PLATFORMFOLDER) + "file"; |
1853 fileicon = app->LoadIcon(fileiconpath); | 1825 fileicon = app->LoadIcon(fileiconpath); |
1854 } | 1826 } |
1855 #endif | 1827 #endif |
1856 | 1828 |
1857 // Finally try from the platform application directory | 1829 // Finally try from the platform application directory |
1858 if(!foldericon && !fileicon) | 1830 if(!foldericon && !fileicon) |
1859 { | 1831 { |
1860 char *appdir = app->GetCDir(); | 1832 std::string appdir = app->GetDir(); |
1861 char pathbuff[1025] = {0}; | 1833 |
1862 int pos = (int)strlen(appdir); | 1834 appdir.append(std::string(1, DW_DIR_SEPARATOR)); |
1863 | 1835 std::string folderpath = appdir + "folder"; |
1864 strncpy(pathbuff, appdir, 1024); | 1836 foldericon = app->LoadIcon(folderpath); |
1865 pathbuff[pos] = DW_DIR_SEPARATOR; | |
1866 pos++; | |
1867 strncpy(&pathbuff[pos], "folder", 1024-pos); | |
1868 foldericon = app->LoadIcon(pathbuff); | |
1869 if(foldericon) | 1837 if(foldericon) |
1870 strncpy(foldericonpath, pathbuff, 1025); | 1838 foldericonpath = folderpath; |
1871 strncpy(&pathbuff[pos], "file", 1024-pos); | 1839 std::string filepath = appdir + "file"; |
1872 fileicon = app->LoadIcon(pathbuff); | 1840 fileicon = app->LoadIcon(filepath); |
1873 if(fileicon) | 1841 if(fileicon) |
1874 strncpy(fileiconpath, pathbuff, 1025); | 1842 fileiconpath = filepath; |
1875 } | 1843 } |
1876 | 1844 |
1877 DW::Notebook *notebook = new DW::Notebook(); | 1845 DW::Notebook *notebook = new DW::Notebook(); |
1878 notebookbox->PackStart(notebook, TRUE, TRUE, 0); | 1846 notebookbox->PackStart(notebook, TRUE, TRUE, 0); |
1879 notebook->ConnectSwitchPage([this](unsigned long page_num) -> int | 1847 notebook->ConnectSwitchPage([this](unsigned long page_num) -> int |
1980 int finished = FALSE, ready = 0; | 1948 int finished = FALSE, ready = 0; |
1981 | 1949 |
1982 // Miscellaneous | 1950 // Miscellaneous |
1983 int menu_enabled = TRUE; | 1951 int menu_enabled = TRUE; |
1984 HICN fileicon, foldericon; | 1952 HICN fileicon, foldericon; |
1985 char fileiconpath[1025] = "file"; | 1953 std::string fileiconpath = "file"; |
1986 char foldericonpath[1025] = "folder"; | 1954 std::string foldericonpath = "folder"; |
1987 | 1955 |
1988 | 1956 |
1989 int OnDelete() override { | 1957 int OnDelete() override { |
1990 if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { | 1958 if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { |
1991 app->MainQuit(); | 1959 app->MainQuit(); |