changeset 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
files dw.hpp dwtestoo.cpp
diffstat 2 files changed, 116 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dw.hpp	Fri Dec 30 04:15:27 2022 +0000
+++ b/dw.hpp	Fri Dec 30 09:35:00 2022 +0000
@@ -153,6 +153,7 @@
             return classptr->_ConnectClickedOld(classptr);
         return classptr->OnClicked(); }
 protected:
+    virtual ~Clickable() {}
     void Setup() {
 #ifdef DW_LAMBDA
         _ConnectClicked = 0;
@@ -585,6 +586,7 @@
 class Drawable
 {
 public:
+    virtual ~Drawable() { }
     virtual void DrawPoint(int x, int y) = 0;
     virtual void DrawLine(int x1, int y1, int x2, int y2) = 0;
     virtual void DrawPolygon(int flags, int npoints, int x[], int y[]) = 0;
@@ -595,9 +597,9 @@
     virtual int BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight) = 0;
     virtual void BitBlt(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc) = 0;
     virtual void BitBlt(int xdest, int ydest, int width, int height, Pixmap *srcp, int xsrc, int ysrc) = 0;
-    void SetColor(unsigned long fore, unsigned long back) { dw_color_foreground_set(fore); dw_color_background_set(back); }    
-    void SetBackgroundColor(unsigned long back) { dw_color_background_set(back); }  
-    void SetForegroundColor(unsigned long fore) { dw_color_foreground_set(fore); }      
+    void SetColor(unsigned long fore, unsigned long back) { dw_color_foreground_set(fore); dw_color_background_set(back); }
+    void SetBackgroundColor(unsigned long back) { dw_color_background_set(back); }
+    void SetForegroundColor(unsigned long fore) { dw_color_foreground_set(fore); }
 };
 
 class Render : public Drawable, public Widget
@@ -1701,7 +1703,11 @@
     HTREEITEM GetParent(HTREEITEM item) { return dw_tree_get_parent(hwnd, item); }
     char *GetTitle(HTREEITEM item) { return dw_tree_get_title(hwnd, item); }
     HTREEITEM Insert(const char *title, HICN icon, HTREEITEM parent, void *itemdata) { return dw_tree_insert(hwnd, title, icon, parent, itemdata); }
-    HTREEITEM Insert(const char *title, HTREEITEM item, HICN icon, HTREEITEM parent, void *itemdata) { return dw_tree_insert_after(hwnd, item, title, icon, parent, itemdata); }
+    HTREEITEM Insert(const char *title, HICN icon, HTREEITEM parent) { return dw_tree_insert(hwnd, title, icon, parent, NULL); }
+    HTREEITEM Insert(const char *title, HICN icon) { return dw_tree_insert(hwnd, title, icon, 0, NULL); }
+    HTREEITEM InsertAfter(const char *title, HTREEITEM item, HICN icon, HTREEITEM parent, void *itemdata) { return dw_tree_insert_after(hwnd, item, title, icon, parent, itemdata); }
+    HTREEITEM InsertAfter(const char *title, HTREEITEM item, HICN icon, HTREEITEM parent) { return dw_tree_insert_after(hwnd, item, title, icon, parent, NULL); }
+    HTREEITEM InsertAfter(const char *title, HTREEITEM item, HICN icon) { return dw_tree_insert_after(hwnd, item, title, icon, 0, NULL); }
     void Change(HTREEITEM item, const char *title, HICN icon) { dw_tree_item_change(hwnd, item, title, icon); }
     void Collapse(HTREEITEM item) { dw_tree_item_collapse(hwnd, item); }
     void Delete(HTREEITEM item) { dw_tree_item_delete(hwnd, item); }
--- a/dwtestoo.cpp	Fri Dec 30 04:15:27 2022 +0000
+++ b/dwtestoo.cpp	Fri Dec 30 09:35:00 2022 +0000
@@ -358,6 +358,39 @@
         render2->Redraw();
     }
 
+    DW::Menu *ItemContextMenu(DW::StatusText *status_text, const char *text)
+    {
+        DW::Menu *menu = new DW::Menu();
+        DW::Menu *submenu = new DW::Menu();
+        DW::MenuItem *menuitem = submenu->AppendItem("File", 0L, TRUE);
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+        menuitem = submenu->AppendItem("Date", 0L, TRUE);
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+        menuitem = submenu->AppendItem("Size", 0L, TRUE);
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+        menuitem = submenu->AppendItem("None", 0L, TRUE);
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+
+        menuitem = submenu->AppendItem("Sort", submenu);
+
+        menuitem = submenu->AppendItem("Make Directory");
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+
+        menuitem = submenu->AppendItem(DW_MENU_SEPARATOR);
+        menuitem = submenu->AppendItem("Rename Entry");
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+
+        menuitem = submenu->AppendItem("Delete Entry");
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+
+        menuitem = submenu->AppendItem(DW_MENU_SEPARATOR);
+        menuitem = submenu->AppendItem("View File");
+        menuitem->ConnectClicked([status_text, text]() -> int { status_text->SetText(text); return TRUE; });
+
+        return menu;
+    }
+
     // Add the menus to the window
     void CreateMenus() {
         // Setup the menu
@@ -597,6 +630,7 @@
         });
     }
 
+    // Notebook page 2
     void CreateRender(DW::Box *notebookbox) {
         int vscrollbarwidth, hscrollbarheight;
         wchar_t widestring[100] = L"DWTest Wide";
@@ -946,6 +980,71 @@
 
         app->TaskBarInsert(render1, fileicon, "DWTest");
     }
+
+    // Notebook page 3
+    void CreateTree(DW::Box *notebookbox)
+    {
+        // create a box to pack into the notebook page
+        DW::ListBox *listbox = new DW::ListBox(TRUE);
+        notebookbox->PackStart(listbox, 500, 200, TRUE, TRUE, 0);
+        listbox->Append("Test 1");
+        listbox->Append("Test 2");
+        listbox->Append("Test 3");
+        listbox->Append("Test 4");
+        listbox->Append("Test 5");
+
+        // now a tree area under this box 
+        DW::Tree *tree = new DW::Tree();
+        if(tree->GetHWND())
+        {
+            notebookbox->PackStart(tree, 500, 200, TRUE, TRUE, 1);
+
+            /* and a status area to see whats going on */
+            DW::StatusText *tree_status = new DW::StatusText();
+            notebookbox->PackStart(tree_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1);
+
+            // set up our signal trappers...
+            tree->ConnectItemContext([this, tree_status](char *text, int x, int y, void *data) -> int
+            {
+                char buf[201] = {0};
+                DW::Menu *popupmenu = ItemContextMenu(tree_status, "Item context menu clicked.");
+
+                snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d", text, x, y);
+                tree_status->SetText(buf);
+                popupmenu->Popup(this, x, y);
+                return FALSE;
+            });
+            tree->ConnectItemSelect([tree_status](HTREEITEM item, char *text, void *itemdata)
+            {
+                char buf[201] = {0};
+
+                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));
+                tree_status->SetText(buf);
+                return FALSE;
+            });
+
+            HTREEITEM t1 = tree->Insert("tree folder 1", foldericon, DW_NULL, DW_INT_TO_POINTER(1));
+            HTREEITEM t2 = tree->Insert("tree folder 2", foldericon, DW_NULL, DW_INT_TO_POINTER(2));
+            tree->Insert("tree file 1", fileicon, t1, DW_INT_TO_POINTER(3));
+            tree->Insert("tree file 2", fileicon, t1, DW_INT_TO_POINTER(4));
+            tree->Insert("tree file 3", fileicon, t2, DW_INT_TO_POINTER(5));
+            tree->Insert("tree file 4", fileicon, t2, DW_INT_TO_POINTER(6));
+            tree->Change(t1, "tree folder 1", foldericon);
+            tree->Change(t2, "tree folder 2", foldericon);
+            tree->SetData(t2, DW_INT_TO_POINTER(100));
+            tree->Expand(t1);
+            char *title = tree->GetTitle(t1);
+            this->app->Debug("t1 title \"%s\" data %d t2 data %d\n", title, DW_POINTER_TO_INT(tree->GetData(t1)),
+                     DW_POINTER_TO_INT(tree->GetData(t2)));
+            this->app->Free(title);
+        }
+        else
+        {
+            DW::Text *text = new DW::Text("Tree widget not available.");
+            notebookbox->PackStart(text, 500, 200, TRUE, TRUE, 1);
+        }
+    }
+
 public:
     // Constructor creates the application
     DWTest(const char *title): DW::Window(title) {
@@ -1024,6 +1123,13 @@
         notebook->Pack(notebookpage, notebookbox);
         notebook->PageSetText(notebookpage, "render");
 
+        // Create Notebook Page 3 - Tree
+        notebookbox = new DW::Box(DW_VERT, 5);
+        CreateTree(notebookbox);
+        notebookpage = notebook->PageNew();
+        notebook->Pack(notebookpage, notebookbox);
+        notebook->PageSetText(notebookpage, "tree");
+
         // Finalize the window
         this->SetSize(640, 550);