Mercurial > dwindows
comparison dwtestoo.cpp @ 2929:2ab97b349958
C++: Add Page 3 - Tree to dwtestoo.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 30 Dec 2022 09:35:00 +0000 |
parents | 102b96d77f89 |
children | d8117d36ed27 |
comparison
equal
deleted
inserted
replaced
2928:102b96d77f89 | 2929:2ab97b349958 |
---|---|
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) | |
362 { | |
363 DW::Menu *menu = new DW::Menu(); | |
364 DW::Menu *submenu = new DW::Menu(); | |
365 DW::MenuItem *menuitem = submenu->AppendItem("File", 0L, TRUE); | |
366 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
367 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
368 menuitem = submenu->AppendItem("Date", 0L, TRUE); | |
369 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
370 menuitem = submenu->AppendItem("Size", 0L, TRUE); | |
371 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
372 menuitem = submenu->AppendItem("None", 0L, TRUE); | |
373 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
374 | |
375 menuitem = submenu->AppendItem("Sort", submenu); | |
376 | |
377 menuitem = submenu->AppendItem("Make Directory"); | |
378 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
379 | |
380 menuitem = submenu->AppendItem(DW_MENU_SEPARATOR); | |
381 menuitem = submenu->AppendItem("Rename Entry"); | |
382 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
383 | |
384 menuitem = submenu->AppendItem("Delete Entry"); | |
385 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
386 | |
387 menuitem = submenu->AppendItem(DW_MENU_SEPARATOR); | |
388 menuitem = submenu->AppendItem("View File"); | |
389 menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; }); | |
390 | |
391 return menu; | |
392 } | |
393 | |
361 // Add the menus to the window | 394 // Add the menus to the window |
362 void CreateMenus() { | 395 void CreateMenus() { |
363 // Setup the menu | 396 // Setup the menu |
364 DW::MenuBar *menubar = this->MenuBarNew(); | 397 DW::MenuBar *menubar = this->MenuBarNew(); |
365 | 398 |
595 this->current_color = this->app->ColorChoose(this->current_color); | 628 this->current_color = this->app->ColorChoose(this->current_color); |
596 return FALSE; | 629 return FALSE; |
597 }); | 630 }); |
598 } | 631 } |
599 | 632 |
633 // Notebook page 2 | |
600 void CreateRender(DW::Box *notebookbox) { | 634 void CreateRender(DW::Box *notebookbox) { |
601 int vscrollbarwidth, hscrollbarheight; | 635 int vscrollbarwidth, hscrollbarheight; |
602 wchar_t widestring[100] = L"DWTest Wide"; | 636 wchar_t widestring[100] = L"DWTest Wide"; |
603 char *utf8string = dw_wchar_to_utf8(widestring); | 637 char *utf8string = dw_wchar_to_utf8(widestring); |
604 | 638 |
944 return FALSE; | 978 return FALSE; |
945 }); | 979 }); |
946 | 980 |
947 app->TaskBarInsert(render1, fileicon, "DWTest"); | 981 app->TaskBarInsert(render1, fileicon, "DWTest"); |
948 } | 982 } |
983 | |
984 // Notebook page 3 | |
985 void CreateTree(DW::Box *notebookbox) | |
986 { | |
987 // create a box to pack into the notebook page | |
988 DW::ListBox *listbox = new DW::ListBox(TRUE); | |
989 notebookbox->PackStart(listbox, 500, 200, TRUE, TRUE, 0); | |
990 listbox->Append("Test 1"); | |
991 listbox->Append("Test 2"); | |
992 listbox->Append("Test 3"); | |
993 listbox->Append("Test 4"); | |
994 listbox->Append("Test 5"); | |
995 | |
996 // now a tree area under this box | |
997 DW::Tree *tree = new DW::Tree(); | |
998 if(tree->GetHWND()) | |
999 { | |
1000 notebookbox->PackStart(tree, 500, 200, TRUE, TRUE, 1); | |
1001 | |
1002 /* and a status area to see whats going on */ | |
1003 DW::StatusText *tree_status = new DW::StatusText(); | |
1004 notebookbox->PackStart(tree_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1); | |
1005 | |
1006 // set up our signal trappers... | |
1007 tree->ConnectItemContext([this, tree_status](char *text, int x, int y, void *data) -> int | |
1008 { | |
1009 char buf[201] = {0}; | |
1010 DW::Menu *popupmenu = ItemContextMenu(tree_status, "Item context menu clicked."); | |
1011 | |
1012 snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d", text, x, y); | |
1013 tree_status->SetText(buf); | |
1014 popupmenu->Popup(this, x, y); | |
1015 return FALSE; | |
1016 }); | |
1017 tree->ConnectItemSelect([tree_status](HTREEITEM item, char *text, void *itemdata) | |
1018 { | |
1019 char buf[201] = {0}; | |
1020 | |
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)); | |
1022 tree_status->SetText(buf); | |
1023 return FALSE; | |
1024 }); | |
1025 | |
1026 HTREEITEM t1 = tree->Insert("tree folder 1", foldericon, DW_NULL, DW_INT_TO_POINTER(1)); | |
1027 HTREEITEM t2 = tree->Insert("tree folder 2", foldericon, DW_NULL, DW_INT_TO_POINTER(2)); | |
1028 tree->Insert("tree file 1", fileicon, t1, DW_INT_TO_POINTER(3)); | |
1029 tree->Insert("tree file 2", fileicon, t1, DW_INT_TO_POINTER(4)); | |
1030 tree->Insert("tree file 3", fileicon, t2, DW_INT_TO_POINTER(5)); | |
1031 tree->Insert("tree file 4", fileicon, t2, DW_INT_TO_POINTER(6)); | |
1032 tree->Change(t1, "tree folder 1", foldericon); | |
1033 tree->Change(t2, "tree folder 2", foldericon); | |
1034 tree->SetData(t2, DW_INT_TO_POINTER(100)); | |
1035 tree->Expand(t1); | |
1036 char *title = tree->GetTitle(t1); | |
1037 this->app->Debug("t1 title \"%s\" data %d t2 data %d\n", title, DW_POINTER_TO_INT(tree->GetData(t1)), | |
1038 DW_POINTER_TO_INT(tree->GetData(t2))); | |
1039 this->app->Free(title); | |
1040 } | |
1041 else | |
1042 { | |
1043 DW::Text *text = new DW::Text("Tree widget not available."); | |
1044 notebookbox->PackStart(text, 500, 200, TRUE, TRUE, 1); | |
1045 } | |
1046 } | |
1047 | |
949 public: | 1048 public: |
950 // Constructor creates the application | 1049 // Constructor creates the application |
951 DWTest(const char *title): DW::Window(title) { | 1050 DWTest(const char *title): DW::Window(title) { |
952 char fileiconpath[1025] = "file"; | 1051 char fileiconpath[1025] = "file"; |
953 char foldericonpath[1025] = "folder"; | 1052 char foldericonpath[1025] = "folder"; |
1021 notebookbox = new DW::Box(DW_VERT, 5); | 1120 notebookbox = new DW::Box(DW_VERT, 5); |
1022 CreateRender(notebookbox); | 1121 CreateRender(notebookbox); |
1023 notebookpage = notebook->PageNew(); | 1122 notebookpage = notebook->PageNew(); |
1024 notebook->Pack(notebookpage, notebookbox); | 1123 notebook->Pack(notebookpage, notebookbox); |
1025 notebook->PageSetText(notebookpage, "render"); | 1124 notebook->PageSetText(notebookpage, "render"); |
1125 | |
1126 // Create Notebook Page 3 - Tree | |
1127 notebookbox = new DW::Box(DW_VERT, 5); | |
1128 CreateTree(notebookbox); | |
1129 notebookpage = notebook->PageNew(); | |
1130 notebook->Pack(notebookpage, notebookbox); | |
1131 notebook->PageSetText(notebookpage, "tree"); | |
1026 | 1132 |
1027 // Finalize the window | 1133 // Finalize the window |
1028 this->SetSize(640, 550); | 1134 this->SetSize(640, 550); |
1029 | 1135 |
1030 timer = new DW::Timer(2000, [this]() -> int | 1136 timer = new DW::Timer(2000, [this]() -> int |