comparison dwtestoo.cpp @ 2931:30c1f37713b6

C++: Add page 5 - Buttons to dwtestoo.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 30 Dec 2022 14:35:45 +0000
parents d8117d36ed27
children 3f660f47a45f
comparison
equal deleted inserted replaced
2930:d8117d36ed27 2931:30c1f37713b6
1378 MLESetFont(container_mle, size, NULL); 1378 MLESetFont(container_mle, size, NULL);
1379 return FALSE; 1379 return FALSE;
1380 }); 1380 });
1381 } 1381 }
1382 1382
1383 // Page 5 - Buttons
1384 void CreateButtons(DW::Box *notebookbox)
1385 {
1386 // create a box to pack into the notebook page
1387 DW::Box *buttonsbox = new DW::Box(DW_VERT, 2);
1388 notebookbox->PackStart(buttonsbox, 25, 200, TRUE, TRUE, 0);
1389 buttonsbox->SetColor(DW_CLR_RED, DW_CLR_RED);
1390
1391 DW::Box *calbox = new DW::Box(DW_HORZ, 0);
1392 notebookbox->PackStart(calbox, 0, 0, TRUE, FALSE, 1);
1393 DW::Calendar *cal = new DW::Calendar();
1394 calbox->PackStart(cal, TRUE, FALSE, 0);
1395
1396 cal->SetDate(2019, 4, 30);
1397
1398 // Create our file toolbar boxes...
1399 DW::Box *buttonboxperm = new DW::Box(DW_VERT, 0);
1400 buttonsbox->PackStart(buttonboxperm, 25, 0, FALSE, TRUE, 2);
1401 buttonboxperm->SetColor(DW_CLR_WHITE, DW_CLR_WHITE);
1402 DW::BitmapButton *topbutton = new DW::BitmapButton("Top Button", fileiconpath);
1403 buttonboxperm->PackStart(topbutton, 100, 30, FALSE, FALSE, 0 );
1404 buttonboxperm->PackStart(DW_NOHWND, 25, 5, FALSE, FALSE, 0);
1405 DW::BitmapButton *iconbutton = new DW::BitmapButton( "Folder Icon", foldericonpath);
1406 buttonsbox->PackStart(iconbutton, 25, 25, FALSE, FALSE, 0);
1407 iconbutton->ConnectClicked([this, iconbutton]() -> int
1408 {
1409 static int isfoldericon = 0;
1410
1411 isfoldericon = !isfoldericon;
1412 if(isfoldericon)
1413 {
1414 iconbutton->Set(this->fileiconpath);
1415 iconbutton->SetTooltip("File Icon");
1416 }
1417 else
1418 {
1419 iconbutton->Set(this->foldericonpath);
1420 iconbutton->SetTooltip("Folder Icon");
1421 }
1422 return FALSE;
1423 });
1424
1425 DW::Box *filetoolbarbox = new DW::Box(DW_VERT, 0);
1426 buttonboxperm->PackStart(filetoolbarbox, 0, 0, TRUE, TRUE, 0);
1427
1428 DW::BitmapButton *button = new DW::BitmapButton("Empty image. Should be under Top button", 0, "junk");
1429 filetoolbarbox->PackStart(button, 25, 25, FALSE, FALSE, 0);
1430 button->ConnectClicked([buttonsbox]() -> int
1431 {
1432 buttonsbox->SetColor(DW_CLR_RED, DW_CLR_RED);
1433 return TRUE;
1434 });
1435 filetoolbarbox->PackStart(DW_NOHWND, 25, 5, FALSE, FALSE, 0);
1436
1437 button = new DW::BitmapButton("A borderless bitmapbitton", 0, foldericonpath);
1438 filetoolbarbox->PackStart(button, 25, 25, FALSE, FALSE, 0);
1439 button->ConnectClicked([buttonsbox]() -> int
1440 {
1441 buttonsbox->SetColor(DW_CLR_YELLOW, DW_CLR_YELLOW);
1442 return TRUE;
1443 });
1444 filetoolbarbox->PackStart(DW_NOHWND, 25, 5, FALSE, FALSE, 0);
1445 button->SetStyle(DW_BS_NOBORDER);
1446
1447 DW::BitmapButton *perbutton = new DW::BitmapButton("A button from data", 0, foldericonpath);
1448 filetoolbarbox->PackStart(perbutton, 25, 25, FALSE, FALSE, 0);
1449 filetoolbarbox->PackStart(DW_NOHWND, 25, 5, FALSE, FALSE, 0 );
1450
1451 // make a combobox
1452 DW::Box *combox = new DW::Box(DW_VERT, 2);
1453 notebookbox->PackStart(combox, 25, 200, TRUE, FALSE, 0);
1454 DW::ComboBox *combobox1 = new DW::ComboBox("fred");
1455 combobox1->Append("fred");
1456 combox->PackStart(combobox1, TRUE, FALSE, 0);
1457
1458 int iteration = 0;
1459 combobox1->ConnectListSelect([this, &iteration](unsigned int index) -> int
1460 {
1461 this->app->Debug("got combobox_select_event for index: %d, iteration: %d\n", index, iteration++);
1462 return FALSE;
1463 });
1464
1465 DW::ComboBox *combobox2 = new DW::ComboBox("joe");
1466 combox->PackStart(combobox2, TRUE, FALSE, 0);
1467 combobox2->ConnectListSelect([this, &iteration](unsigned int index) -> int
1468 {
1469 this->app->Debug("got combobox_select_event for index: %d, iteration: %d\n", index, iteration++);
1470 return FALSE;
1471 });
1472
1473 // add LOTS of items
1474 app->Debug("before appending 500 items to combobox using dw_listbox_list_append()\n");
1475 char **text = (char **)malloc(500*sizeof(char *));
1476 for(int i = 0; i < 500; i++)
1477 {
1478 text[i] = (char *)calloc(1, 50);
1479 snprintf(text[i], 50, "item %d", i);
1480 }
1481 combobox2->ListAppend(text, 500);
1482 app->Debug("after appending 500 items to combobox\n");
1483 for(int i = 0; i < 500; i++)
1484 {
1485 free(text[i]);
1486 }
1487 free(text);
1488 // now insert a couple of items
1489 combobox2->Insert("inserted item 2", 2);
1490 combobox2->Insert("inserted item 5", 5);
1491 /* make a spinbutton */
1492 DW::SpinButton *spinbutton = new DW::SpinButton();
1493 combox->PackStart(spinbutton, TRUE, FALSE, 0);
1494 spinbutton->SetLimits(100, 1);
1495 spinbutton->SetPos(30);
1496
1497 spinbutton->ConnectValueChanged([this](int value) -> int
1498 {
1499 this->app->MessageBox("DWTest", DW_MB_OK, "New value from spinbutton: %d\n", value);
1500 return TRUE;
1501 });
1502 /// make a slider
1503 DW::Slider *slider = new DW::Slider(FALSE, 11, 0);
1504 combox->PackStart(slider, TRUE, FALSE, 0);
1505
1506 // make a percent
1507 DW::Percent *percent = new DW::Percent();
1508 combox->PackStart(percent, TRUE, FALSE, 0);
1509
1510 topbutton->ConnectClicked([this, combobox1, combobox2, spinbutton, cal]() -> int
1511 {
1512 char buf1[101] = {0};
1513 char buf2[101] = {0};
1514 char buf3[501] = {0};
1515
1516 unsigned int idx = combobox1->Selected();
1517 combobox1->GetListText(idx, buf1, 100);
1518 idx = combobox2->Selected();
1519 combobox2->GetListText(idx, buf2, 100);
1520 unsigned int y,m,d;
1521 cal->GetDate(&y, &m, &d);
1522 long spvalue = spinbutton->GetPos();
1523 int len = snprintf(buf3, 500, "spinbutton: %ld\ncombobox1: \"%s\"\ncombobox2: \"%s\"\ncalendar: %d-%d-%d",
1524 spvalue,
1525 buf1, buf2,
1526 y, m, d);
1527 this->app->MessageBox("Values", DW_MB_OK | DW_MB_INFORMATION, buf3);
1528 this->app->SetClipboard(buf3, len);
1529 return 0;
1530 });
1531
1532 perbutton->ConnectClicked([percent]() -> int
1533 {
1534 percent->SetPos(DW_PERCENT_INDETERMINATE);
1535 return TRUE;
1536 });
1537
1538 slider->ConnectValueChanged([percent](int value) -> int
1539 {
1540 percent->SetPos(value * 10);
1541 return TRUE;
1542 });
1543 }
1383 public: 1544 public:
1384 // Constructor creates the application 1545 // Constructor creates the application
1385 DWTest(const char *title): DW::Window(title) { 1546 DWTest(const char *title): DW::Window(title) {
1386 char fileiconpath[1025] = "file";
1387 char foldericonpath[1025] = "folder";
1388
1389 // Get our application singleton 1547 // Get our application singleton
1390 app = DW::App::Init(); 1548 app = DW::App::Init();
1391 1549
1392 // Add menus to the window 1550 // Add menus to the window
1393 CreateMenus(); 1551 CreateMenus();
1470 CreateContainer(notebookbox); 1628 CreateContainer(notebookbox);
1471 notebookpage = notebook->PageNew(); 1629 notebookpage = notebook->PageNew();
1472 notebook->Pack(notebookpage, notebookbox); 1630 notebook->Pack(notebookpage, notebookbox);
1473 notebook->PageSetText(notebookpage, "container"); 1631 notebook->PageSetText(notebookpage, "container");
1474 1632
1633 // Create Notebook Page 5 - Buttons
1634 notebookbox = new DW::Box(DW_VERT, 5);
1635 CreateButtons(notebookbox);
1636 notebookpage = notebook->PageNew();
1637 notebook->Pack(notebookpage, notebookbox);
1638 notebook->PageSetText(notebookpage, "buttons");
1639
1475 // Finalize the window 1640 // Finalize the window
1476 this->SetSize(640, 550); 1641 this->SetSize(640, 550);
1477 1642
1478 timer = new DW::Timer(2000, [this]() -> int 1643 timer = new DW::Timer(2000, [this]() -> int
1479 { 1644 {
1500 1665
1501 int font_width = 8, font_height=12; 1666 int font_width = 8, font_height=12;
1502 int rows=10,width1=6,cols=80; 1667 int rows=10,width1=6,cols=80;
1503 int num_lines=0, max_linewidth=0; 1668 int num_lines=0, max_linewidth=0;
1504 int current_row=0,current_col=0; 1669 int current_row=0,current_col=0;
1505 int render_type = SHAPES_DOUBLE_BUFFERED; 1670 unsigned int render_type = SHAPES_DOUBLE_BUFFERED;
1506 1671
1507 char **lp; 1672 char **lp;
1508 char *current_file = NULL; 1673 char *current_file = NULL;
1509 1674
1510 // Page 4 1675 // Page 4
1511 int mle_point=-1; 1676 int mle_point=-1;
1512 1677
1513 // Miscellaneous 1678 // Miscellaneous
1514 int menu_enabled = TRUE; 1679 int menu_enabled = TRUE;
1515 HICN fileicon,foldericon; 1680 HICN fileicon, foldericon;
1681 char fileiconpath[1025] = "file";
1682 char foldericonpath[1025] = "folder";
1683
1516 1684
1517 int OnDelete() override { 1685 int OnDelete() override {
1518 if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { 1686 if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) {
1519 app->MainQuit(); 1687 app->MainQuit();
1520 } 1688 }