comparison dwtestoo.cpp @ 2963:531d36ebf37a

C++: Step 5 of the std::string transition. Hopefully the last step. Move to using std::string and std::vector for almost everything we can. Only the the file read buffer is still using C style basic character buffers. Undecided if I want to move that to std::string so considering it done for now. Add /EHsc to the compiler options for Visual C to use std::vector::push_back.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 25 Feb 2023 22:24:18 +0000
parents e6072eb914ce
children 2d9521396112
comparison
equal deleted inserted replaced
2962:e6072eb914ce 2963:531d36ebf37a
356 // Trigger expose event 356 // Trigger expose event
357 render1->Redraw(); 357 render1->Redraw();
358 render2->Redraw(); 358 render2->Redraw();
359 } 359 }
360 360
361 DW::Menu *ItemContextMenu(DW::StatusText *status_text, const char *text) { 361 DW::Menu *ItemContextMenu(DW::StatusText *status_text, std::string text) {
362 DW::Menu *menu = new DW::Menu(); 362 DW::Menu *menu = new DW::Menu();
363 DW::Menu *submenu = new DW::Menu(); 363 DW::Menu *submenu = new DW::Menu();
364 DW::MenuItem *menuitem = submenu->AppendItem("File", 0L, TRUE); 364 DW::MenuItem *menuitem = submenu->AppendItem("File", 0L, TRUE);
365 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); 365 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
366 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); 366 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
458 } 458 }
459 mle->SetFont(NULL); 459 mle->SetFont(NULL);
460 } 460 }
461 461
462 // Thread and Event functions 462 // Thread and Event functions
463 void UpdateMLE(DW::MLE *threadmle, const char *text, DW::Mutex *mutex) { 463 void UpdateMLE(DW::MLE *threadmle, std::string text, DW::Mutex *mutex) {
464 static unsigned int pos = 0; 464 static unsigned int pos = 0;
465 465
466 // Protect pos from being changed by different threads 466 // Protect pos from being changed by different threads
467 if(mutex) 467 if(mutex)
468 mutex->Lock(); 468 mutex->Lock();
471 if(mutex) 471 if(mutex)
472 mutex->Unlock(); 472 mutex->Unlock();
473 } 473 }
474 474
475 void RunThread(int threadnum, DW::Mutex *mutex, DW::Event *controlevent, DW::Event *workevent, DW::MLE *threadmle) { 475 void RunThread(int threadnum, DW::Mutex *mutex, DW::Event *controlevent, DW::Event *workevent, DW::MLE *threadmle) {
476 char buf[BUF_SIZE+1] = {0}; 476 std::string buf;
477 477
478 snprintf(buf, BUF_SIZE, "Thread %d started.\r\n", threadnum); 478 buf = "Thread " + std::to_string(threadnum) + " started.\r\n";
479 UpdateMLE(threadmle, buf, mutex); 479 UpdateMLE(threadmle, buf, mutex);
480 480
481 // Increment the ready count while protected by mutex 481 // Increment the ready count while protected by mutex
482 mutex->Lock(); 482 mutex->Lock();
483 ready++; 483 ready++;
491 { 491 {
492 int result = workevent->Wait(2000); 492 int result = workevent->Wait(2000);
493 493
494 if(result == DW_ERROR_TIMEOUT) 494 if(result == DW_ERROR_TIMEOUT)
495 { 495 {
496 snprintf(buf, BUF_SIZE, "Thread %d timeout waiting for event.\r\n", threadnum); 496 buf = "Thread " + std::to_string(threadnum) + " timeout waiting for event.\r\n";
497 UpdateMLE(threadmle, buf, mutex); 497 UpdateMLE(threadmle, buf, mutex);
498 } 498 }
499 else if(result == DW_ERROR_NONE) 499 else if(result == DW_ERROR_NONE)
500 { 500 {
501 snprintf(buf, BUF_SIZE, "Thread %d doing some work.\r\n", threadnum); 501 buf = "Thread " + std::to_string(threadnum) + " doing some work.\r\n";
502 UpdateMLE(threadmle, buf, mutex); 502 UpdateMLE(threadmle, buf, mutex);
503 // Pretend to do some work 503 // Pretend to do some work
504 app->MainSleep(1000 * threadnum); 504 app->MainSleep(1000 * threadnum);
505 505
506 // Increment the ready count while protected by mutex 506 // Increment the ready count while protected by mutex
507 mutex->Lock(); 507 mutex->Lock();
508 ready++; 508 ready++;
509 snprintf(buf, BUF_SIZE, "Thread %d work done. ready=%d", threadnum, ready); 509 buf = "Thread " + std::to_string(threadnum) + " work done. ready=" + std::to_string(ready);
510 // If all 4 threads have incrememted the ready count... 510 // If all 4 threads have incrememted the ready count...
511 // Post the control event semaphore so things will get started. 511 // Post the control event semaphore so things will get started.
512 if(ready == 4) 512 if(ready == 4)
513 { 513 {
514 controlevent->Post(); 514 controlevent->Post();
515 strcat(buf, " Control posted."); 515 buf += " Control posted.";
516 } 516 }
517 mutex->Unlock(); 517 mutex->Unlock();
518 strcat(buf, "\r\n"); 518 buf += "\r\n";
519 UpdateMLE(threadmle, buf, mutex); 519 UpdateMLE(threadmle, buf, mutex);
520 } 520 }
521 else 521 else
522 { 522 {
523 snprintf(buf, BUF_SIZE, "Thread %d error %d.\r\n", threadnum, result); 523 buf = "Thread " + std::to_string(threadnum) + " error " + std::to_string(result) + ".\r\n";
524 UpdateMLE(threadmle, buf, mutex); 524 UpdateMLE(threadmle, buf, mutex);
525 app->MainSleep(10000); 525 app->MainSleep(10000);
526 } 526 }
527 } 527 }
528 snprintf(buf, BUF_SIZE, "Thread %d finished.\r\n", threadnum); 528 buf = "Thread " + std::to_string(threadnum) + " finished.\r\n";
529 UpdateMLE(threadmle, buf, mutex); 529 UpdateMLE(threadmle, buf, mutex);
530 } 530 }
531 531
532 void ControlThread(DW::Mutex *mutex, DW::Event *controlevent, DW::Event *workevent, DW::MLE *threadmle) { 532 void ControlThread(DW::Mutex *mutex, DW::Event *controlevent, DW::Event *workevent, DW::MLE *threadmle) {
533 int inprogress = 5; 533 int inprogress = 5;
534 char buf[BUF_SIZE+1] = {0}; 534 std::string buf;
535 535
536 while(inprogress) 536 while(inprogress)
537 { 537 {
538 int result = controlevent->Wait(2000); 538 int result = controlevent->Wait(2000);
539 539
544 else if(result == DW_ERROR_NONE) 544 else if(result == DW_ERROR_NONE)
545 { 545 {
546 // Reset the control event 546 // Reset the control event
547 controlevent->Reset(); 547 controlevent->Reset();
548 ready = 0; 548 ready = 0;
549 snprintf(buf, BUF_SIZE, "Control thread starting worker threads. Inprogress=%d\r\n", inprogress); 549 buf = "Control thread starting worker threads. Inprogress=" + std::to_string(inprogress) + "\r\n";
550 UpdateMLE(threadmle, buf, mutex); 550 UpdateMLE(threadmle, buf, mutex);
551 // Start the work threads 551 // Start the work threads
552 workevent->Post(); 552 workevent->Post();
553 app->MainSleep(100); 553 app->MainSleep(100);
554 // Reset the work event 554 // Reset the work event
555 workevent->Reset(); 555 workevent->Reset();
556 inprogress--; 556 inprogress--;
557 } 557 }
558 else 558 else
559 { 559 {
560 snprintf(buf, BUF_SIZE, "Control thread error %d.\r\n", result); 560 buf = "Control thread error " + std::to_string(result) + ".\r\n";
561 UpdateMLE(threadmle, buf, mutex); 561 UpdateMLE(threadmle, buf, mutex);
562 app->MainSleep(10000); 562 app->MainSleep(10000);
563 } 563 }
564 } 564 }
565 // Tell the other threads we are done 565 // Tell the other threads we are done
719 { 719 {
720 char *tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN); 720 char *tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN);
721 if(tmp) 721 if(tmp)
722 { 722 {
723 char *errors = ReadFile(tmp); 723 char *errors = ReadFile(tmp);
724 const char *title = "New file load"; 724 std::string title = "New file load";
725 const char *image = "image/test.png"; 725 std::string image = "image/test.png";
726 DW::Notification *notification; 726 DW::Notification *notification;
727 727
728 if(errors) 728 if(errors)
729 notification = new DW::Notification(title, image, APP_TITLE " failed to load the file into the file browser."); 729 notification = new DW::Notification(title, image, std::string(APP_TITLE) + " failed to load the file into the file browser.");
730 else 730 else
731 notification = new DW::Notification(title, image, APP_TITLE " loaded the file into the file browser on the Render tab, with \"File Display\" selected from the drop down list."); 731 notification = new DW::Notification(title, image, std::string(APP_TITLE) + " loaded the file into the file browser on the Render tab, with \"File Display\" selected from the drop down list.");
732 732
733 if(current_file) 733 if(current_file)
734 this->app->Free(current_file); 734 this->app->Free(current_file);
735 current_file = tmp; 735 current_file = tmp;
736 entryfield->SetText(current_file); 736 entryfield->SetText(current_file);
1001 return FALSE; 1001 return FALSE;
1002 }); 1002 });
1003 1003
1004 hscrollbar->ConnectValueChanged([this, status1](int value) -> int 1004 hscrollbar->ConnectValueChanged([this, status1](int value) -> int
1005 { 1005 {
1006 char tmpbuf[101] = {0}; 1006 std::string buf = "Row:" + std::to_string(current_row) + " Col:" + std::to_string(current_col) + " Lines:" + std::to_string(num_lines) + " Cols:" + std::to_string(max_linewidth);
1007 1007
1008 this->current_col = value; 1008 this->current_col = value;
1009 snprintf(tmpbuf, 100, "Row:%d Col:%d Lines:%d Cols:%d", current_row,current_col,num_lines,max_linewidth); 1009 status1->SetText(buf);
1010 status1->SetText(tmpbuf);
1011 this->RenderDraw(); 1010 this->RenderDraw();
1012 return TRUE; 1011 return TRUE;
1013 }); 1012 });
1014 1013
1015 vscrollbar->ConnectValueChanged([this, status1](int value) -> int 1014 vscrollbar->ConnectValueChanged([this, status1](int value) -> int
1016 { 1015 {
1017 char tmpbuf[101] = {0}; 1016 std::string buf = "Row:" + std::to_string(current_row) + " Col:" + std::to_string(current_col) + " Lines:" + std::to_string(num_lines) + " Cols:" + std::to_string(max_linewidth);
1018 1017
1019 this->current_row = value; 1018 this->current_row = value;
1020 snprintf(tmpbuf, 100, "Row:%d Col:%d Lines:%d Cols:%d", current_row,current_col,num_lines,max_linewidth); 1019 status1->SetText(buf);
1021 status1->SetText(tmpbuf);
1022 this->RenderDraw(); 1020 this->RenderDraw();
1023 return TRUE; 1021 return TRUE;
1024 }); 1022 });
1025 1023
1026 render2->ConnectMotionNotify([status2](int x, int y, int buttonmask) -> int 1024 render2->ConnectMotionNotify([status2](int x, int y, int buttonmask) -> int
1027 { 1025 {
1028 char buf[201] = {0}; 1026 std::string buf = "motion_notify: " + std::to_string(x) + "x" + std::to_string(y) + " buttons " + std::to_string(buttonmask);
1029 1027
1030 snprintf(buf, 200, "motion_notify: %dx%d buttons %d", x, y, buttonmask);
1031 status2->SetText(buf); 1028 status2->SetText(buf);
1032 return FALSE; 1029 return FALSE;
1033 }); 1030 });
1034 1031
1035 render2->ConnectButtonPress([status2](int x, int y, int buttonmask) -> int 1032 render2->ConnectButtonPress([status2](int x, int y, int buttonmask) -> int
1036 { 1033 {
1037 char buf[201] = {0}; 1034 std::string buf = "button_press: " + std::to_string(x) + "x" + std::to_string(y) + " buttons " + std::to_string(buttonmask);
1038 1035
1039 snprintf(buf, 200, "button_press: %dx%d buttons %d", x, y, buttonmask);
1040 status2->SetText(buf); 1036 status2->SetText(buf);
1041 return FALSE; 1037 return FALSE;
1042 }); 1038 });
1043 1039
1044 render2->ConnectConfigure([this](int width, int height) -> int 1040 render2->ConnectConfigure([this](int width, int height) -> int
1108 this->DrawFile(0, 0, nrows, fheight, pixmap); 1104 this->DrawFile(0, 0, nrows, fheight, pixmap);
1109 } 1105 }
1110 else 1106 else
1111 { 1107 {
1112 // We don't have a file so center an error message on the page 1108 // We don't have a file so center an error message on the page
1113 const char *text = "No file currently selected!"; 1109 std::string text = "No file currently selected!";
1114 int posx, posy; 1110 int posx, posy;
1115 1111
1116 pixmap->GetTextExtents(text, &fwidth, &fheight); 1112 pixmap->GetTextExtents(text, &fwidth, &fheight);
1117 1113
1118 posx = (int)(pixmap->GetWidth() - fwidth)/2; 1114 posx = (int)(pixmap->GetWidth() - fwidth)/2;
1218 } 1214 }
1219 } 1215 }
1220 1216
1221 // Page 4 - Container 1217 // Page 4 - Container
1222 void CreateContainer(DW::Box *notebookbox) { 1218 void CreateContainer(DW::Box *notebookbox) {
1223 char buffer[101] = {0};
1224 CTIME time; 1219 CTIME time;
1225 CDATE date; 1220 CDATE date;
1226 1221
1227 // create a box to pack into the notebook page 1222 // create a box to pack into the notebook page
1228 DW::Box *containerbox = new DW::Box(DW_HORZ, 2); 1223 DW::Box *containerbox = new DW::Box(DW_HORZ, 2);
1286 container->SetStripe(DW_CLR_DEFAULT, DW_CLR_DEFAULT); 1281 container->SetStripe(DW_CLR_DEFAULT, DW_CLR_DEFAULT);
1287 container->Alloc(3); 1282 container->Alloc(3);
1288 1283
1289 for(int z=0;z<3;z++) 1284 for(int z=0;z<3;z++)
1290 { 1285 {
1291 char names[101] = {0}; 1286 std::string names = "We can now allocate from the stack: Item: " + std::to_string(z);
1292 HICN thisicon = (z == 0 ? foldericon : fileicon); 1287 HICN thisicon = (z == 0 ? foldericon : fileicon);
1293 1288
1294 snprintf(names, 100, "We can now allocate from the stack: Item: %d", z);
1295 unsigned long size = z*100; 1289 unsigned long size = z*100;
1296 snprintf(buffer, 100, "Filename %d", z+1); 1290 container->SetFile(z, "Filename " + std::to_string(z+1), thisicon);
1297 container->SetFile(z, buffer, thisicon);
1298 container->SetItem(0, z, &thisicon); 1291 container->SetItem(0, z, &thisicon);
1299 container->SetItem(1, z, &size); 1292 container->SetItem(1, z, &size);
1300 1293
1301 time.seconds = z+10; 1294 time.seconds = z+10;
1302 time.minutes = z+10; 1295 time.minutes = z+10;
1328 1321
1329 DW::MLE *container_mle = new DW::MLE(); 1322 DW::MLE *container_mle = new DW::MLE();
1330 containerbox->PackStart(container_mle, 500, 200, TRUE, TRUE, 0); 1323 containerbox->PackStart(container_mle, 500, 200, TRUE, TRUE, 0);
1331 1324
1332 mle_point = container_mle->Import("", -1); 1325 mle_point = container_mle->Import("", -1);
1333 snprintf(buffer, 100, "[%d]", mle_point); 1326 mle_point = container_mle->Import("[" + std::to_string(mle_point) + "]", mle_point);
1334 mle_point = container_mle->Import(buffer, mle_point); 1327 mle_point = container_mle->Import("[" + std::to_string(mle_point) + "]abczxydefijkl", mle_point);
1335 snprintf(buffer, 100, "[%d]abczxydefijkl", mle_point);
1336 mle_point = container_mle->Import(buffer, mle_point);
1337 container_mle->Delete(9, 3); 1328 container_mle->Delete(9, 3);
1338 mle_point = container_mle->Import("gh", 12); 1329 mle_point = container_mle->Import("gh", 12);
1339 unsigned long newpoint; 1330 unsigned long newpoint;
1340 container_mle->GetSize(&newpoint, NULL); 1331 container_mle->GetSize(&newpoint, NULL);
1341 mle_point = (int)newpoint; 1332 mle_point = (int)newpoint;
1342 snprintf(buffer, 100, "[%d]\r\n\r\n", mle_point); 1333 mle_point = container_mle->Import("[" + std::to_string(mle_point) + "]\r\n\r\n", mle_point);
1343 mle_point = container_mle->Import(buffer, mle_point);
1344 container_mle->SetCursor(mle_point); 1334 container_mle->SetCursor(mle_point);
1345 1335
1346 // connect our event trappers... 1336 // connect our event trappers...
1347 container->ConnectItemEnter([container_status](std::string text, void *itemdata) -> int 1337 container->ConnectItemEnter([container_status](std::string text, void *itemdata) -> int
1348 { 1338 {
1388 return FALSE; 1378 return FALSE;
1389 }); 1379 });
1390 1380
1391 container->ConnectColumnClick([container, container_status](int column_num) -> int 1381 container->ConnectColumnClick([container, container_status](int column_num) -> int
1392 { 1382 {
1393 const char *type_string = "Filename"; 1383 std::string type_string = "Filename";
1394 1384
1395 if(column_num != 0) 1385 if(column_num != 0)
1396 { 1386 {
1397 int column_type = container->GetColumnType(column_num-1); 1387 int column_type = container->GetColumnType(column_num-1);
1398 1388
1407 else if(column_type == DW_CFA_BITMAPORICON) 1397 else if(column_type == DW_CFA_BITMAPORICON)
1408 type_string = "BitmapOrIcon"; 1398 type_string = "BitmapOrIcon";
1409 else 1399 else
1410 type_string = "Unknown"; 1400 type_string = "Unknown";
1411 } 1401 }
1412 char buf[201] = {0}; 1402 std::string buf = "DW_SIGNAL_COLUMN_CLICK: Column: " + std::to_string(column_num) + " Type: " + type_string;
1413 snprintf(buf, 200, "DW_SIGNAL_COLUMN_CLICK: Column: %d Type: %s", column_num, type_string);
1414 container_status->SetText(buf); 1403 container_status->SetText(buf);
1415 return FALSE; 1404 return FALSE;
1416 }); 1405 });
1417 1406
1418 mlefore->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int 1407 mlefore->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int
1554 return FALSE; 1543 return FALSE;
1555 }); 1544 });
1556 1545
1557 // add LOTS of items 1546 // add LOTS of items
1558 app->Debug("before appending 500 items to combobox using DW::ListBox::ListAppend()\n"); 1547 app->Debug("before appending 500 items to combobox using DW::ListBox::ListAppend()\n");
1559 char **text = (char **)malloc(500*sizeof(char *)); 1548 std::vector<std::string> text;
1560 for(int i = 0; i < 500; i++) 1549 for(int i = 0; i < 500; i++)
1561 { 1550 {
1562 text[i] = (char *)calloc(1, 50); 1551 text.push_back("item " + std::to_string(i));
1563 snprintf(text[i], 50, "item %d", i);
1564 } 1552 }
1565 combobox2->ListAppend(text, 500); 1553 combobox2->ListAppend(text);
1566 app->Debug("after appending 500 items to combobox\n"); 1554 app->Debug("after appending 500 items to combobox\n");
1567 for(int i = 0; i < 500; i++)
1568 {
1569 free(text[i]);
1570 }
1571 free(text);
1572 // now insert a couple of items 1555 // now insert a couple of items
1573 combobox2->Insert("inserted item 2", 2); 1556 combobox2->Insert("inserted item 2", 2);
1574 combobox2->Insert("inserted item 5", 5); 1557 combobox2->Insert("inserted item 5", 5);
1575 // make a spinbutton 1558 // make a spinbutton
1576 DW::SpinButton *spinbutton = new DW::SpinButton(); 1559 DW::SpinButton *spinbutton = new DW::SpinButton();
1591 DW::Percent *percent = new DW::Percent(); 1574 DW::Percent *percent = new DW::Percent();
1592 combox->PackStart(percent, TRUE, FALSE, 0); 1575 combox->PackStart(percent, TRUE, FALSE, 0);
1593 1576
1594 topbutton->ConnectClicked([this, combobox1, combobox2, spinbutton, cal]() -> int 1577 topbutton->ConnectClicked([this, combobox1, combobox2, spinbutton, cal]() -> int
1595 { 1578 {
1596 char buf1[101] = {0};
1597 char buf2[101] = {0};
1598 char buf3[501] = {0};
1599
1600 unsigned int idx = combobox1->Selected(); 1579 unsigned int idx = combobox1->Selected();
1601 combobox1->GetListText(idx, buf1, 100); 1580 std::string buf1 = combobox1->GetListText(idx);
1602 idx = combobox2->Selected(); 1581 idx = combobox2->Selected();
1603 combobox2->GetListText(idx, buf2, 100); 1582 std::string buf2 = combobox2->GetListText(idx);
1604 unsigned int y,m,d; 1583 unsigned int y,m,d;
1605 cal->GetDate(&y, &m, &d); 1584 cal->GetDate(&y, &m, &d);
1606 long spvalue = spinbutton->GetPos(); 1585 long spvalue = spinbutton->GetPos();
1607 int len = snprintf(buf3, 500, "spinbutton: %ld\ncombobox1: \"%s\"\ncombobox2: \"%s\"\ncalendar: %d-%d-%d", 1586 std::string buf3 = "spinbutton: " + std::to_string(spvalue) + "\ncombobox1: \"" + buf1 +
1608 spvalue, 1587 "\"\ncombobox2: \"" + buf2 + "\"\ncalendar: " + std::to_string(y) + "-" +
1609 buf1, buf2, 1588 std::to_string(m) + "-" + std::to_string(d);
1610 y, m, d);
1611 this->app->MessageBox("Values", DW_MB_OK | DW_MB_INFORMATION, buf3); 1589 this->app->MessageBox("Values", DW_MB_OK | DW_MB_INFORMATION, buf3);
1612 this->app->SetClipboard(buf3, len); 1590 this->app->SetClipboard(buf3);
1613 return 0; 1591 return 0;
1614 }); 1592 });
1615 1593
1616 perbutton->ConnectClicked([percent]() -> int 1594 perbutton->ConnectClicked([percent]() -> int
1617 { 1595 {
1719 } 1697 }
1720 } 1698 }
1721 1699
1722 // Page 7 - ScrollBox 1700 // Page 7 - ScrollBox
1723 void CreateScrollBox(DW::Box *notebookbox) { 1701 void CreateScrollBox(DW::Box *notebookbox) {
1724 char buf[101] = {0};
1725
1726 // create a box to pack into the notebook page 1702 // create a box to pack into the notebook page
1727 DW::ScrollBox *scrollbox = new DW::ScrollBox(DW_VERT, 0); 1703 DW::ScrollBox *scrollbox = new DW::ScrollBox(DW_VERT, 0);
1728 notebookbox->PackStart(scrollbox, 0, 0, TRUE, TRUE, 1); 1704 notebookbox->PackStart(scrollbox, 0, 0, TRUE, TRUE, 1);
1729 1705
1730 DW::Button *adjbutton = new DW::Button("Show Adjustments", 0); 1706 DW::Button *adjbutton = new DW::Button("Show Adjustments", 0);
1739 1715
1740 for(int i = 0; i < MAX_WIDGETS; i++) 1716 for(int i = 0; i < MAX_WIDGETS; i++)
1741 { 1717 {
1742 DW::Box *tmpbox = new DW::Box(DW_HORZ, 0); 1718 DW::Box *tmpbox = new DW::Box(DW_HORZ, 0);
1743 scrollbox->PackStart(tmpbox, 0, 0, TRUE, FALSE, 2); 1719 scrollbox->PackStart(tmpbox, 0, 0, TRUE, FALSE, 2);
1744 snprintf(buf, 100, "Label %d", i); 1720 DW::Text *label = new DW::Text("Label " + std::to_string(i));
1745 DW::Text *label = new DW::Text(buf );
1746 tmpbox->PackStart(label, 0, DW_SIZE_AUTO, TRUE, FALSE, 0); 1721 tmpbox->PackStart(label, 0, DW_SIZE_AUTO, TRUE, FALSE, 0);
1747 snprintf(buf, 100, "Entry %d", i); 1722 DW::Entryfield *entry = new DW::Entryfield("Entry " + std::to_string(i) , i);
1748 DW::Entryfield *entry = new DW::Entryfield(buf , i);
1749 tmpbox->PackStart(entry, 0, DW_SIZE_AUTO, TRUE, FALSE, 0); 1723 tmpbox->PackStart(entry, 0, DW_SIZE_AUTO, TRUE, FALSE, 0);
1750 } 1724 }
1751 } 1725 }
1752 1726
1753 // Page 8 - Thread and Event 1727 // Page 8 - Thread and Event
1798 return FALSE; 1772 return FALSE;
1799 }); 1773 });
1800 } 1774 }
1801 public: 1775 public:
1802 // Constructor creates the application 1776 // Constructor creates the application
1803 DWTest(const char *title): DW::Window(title) { 1777 DWTest(std::string title): DW::Window(title) {
1804 // Get our application singleton 1778 // Get our application singleton
1805 app = DW::App::Init(); 1779 app = DW::App::Init();
1806 1780
1807 // Add menus to the window 1781 // Add menus to the window
1808 CreateMenus(); 1782 CreateMenus();
1965 return TRUE; 1939 return TRUE;
1966 } 1940 }
1967 }; 1941 };
1968 1942
1969 // Pretty list of features corresponding to the DWFEATURE enum in dw.h 1943 // Pretty list of features corresponding to the DWFEATURE enum in dw.h
1970 const char *DWFeatureList[] = { 1944 std::vector<std::string> DWFeatureList = {
1971 "Supports the HTML Widget", 1945 "Supports the HTML Widget",
1972 "Supports the DW_SIGNAL_HTML_RESULT callback", 1946 "Supports the DW_SIGNAL_HTML_RESULT callback",
1973 "Supports custom window border sizes", 1947 "Supports custom window border sizes",
1974 "Supports window frame transparency", 1948 "Supports window frame transparency",
1975 "Supports Dark Mode user interface", 1949 "Supports Dark Mode user interface",
1982 "Supports UTF8 encoded Unicode text", 1956 "Supports UTF8 encoded Unicode text",
1983 "Supports Rich Edit based MLE control (Windows)", 1957 "Supports Rich Edit based MLE control (Windows)",
1984 "Supports icons in the taskbar or similar system widget", 1958 "Supports icons in the taskbar or similar system widget",
1985 "Supports the Tree Widget", 1959 "Supports the Tree Widget",
1986 "Supports arbitrary window placement", 1960 "Supports arbitrary window placement",
1987 "Supports alternate container view modes", 1961 "Supports alternate container view modes"
1988 NULL }; 1962 };
1989 1963
1990 // Let's demonstrate the functionality of this library. :) 1964 // Let's demonstrate the functionality of this library. :)
1991 int dwmain(int argc, char* argv[]) 1965 int dwmain(int argc, char* argv[])
1992 { 1966 {
1993 // Initialize the Dynamic Windows engine 1967 // Initialize the Dynamic Windows engine
2005 // Test all the features and display the results 1979 // Test all the features and display the results
2006 for(int intfeat=DW_FEATURE_HTML; intfeat<DW_FEATURE_MAX; intfeat++) 1980 for(int intfeat=DW_FEATURE_HTML; intfeat<DW_FEATURE_MAX; intfeat++)
2007 { 1981 {
2008 DWFEATURE feat = static_cast<DWFEATURE>(intfeat); 1982 DWFEATURE feat = static_cast<DWFEATURE>(intfeat);
2009 int result = app->GetFeature(feat); 1983 int result = app->GetFeature(feat);
2010 const char *status = "Unsupported"; 1984 std::string status = "Unsupported";
2011 1985
2012 if(result == 0) 1986 if(result == 0)
2013 status = "Disabled"; 1987 status = "Disabled";
2014 else if(result > 0) 1988 else if(result > 0)
2015 status = "Enabled"; 1989 status = "Enabled";
2016 1990
2017 app->Debug("%s: %s (%d)\n", DWFeatureList[feat], status, result); 1991 app->Debug(DWFeatureList[intfeat] + ": " + status + " (" + std::to_string(result) + ")\n");
2018 } 1992 }
2019 1993
2020 DWTest *window = new DWTest("dwindows test UTF8 中国語 (繁体) cañón"); 1994 DWTest *window = new DWTest("dwindows test UTF8 中国語 (繁体) cañón");
2021 window->Show(); 1995 window->Show();
2022 1996