]> git.neil.brown.name Git - edlib.git/commitdiff
popup: switch to embedded-data pattern.
authorNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 10:31:13 +0000 (20:31 +1000)
committerNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 10:31:13 +0000 (20:31 +1000)
Signed-off-by: NeilBrown <neil@brown.name>
lib-popup.c
lib-tile.c

index 6cbb667309fec09b56a116f3e791567704ce3408..e0f4067a0c3f92dda191aef1294216914486d88a 100644 (file)
 #include <stdio.h>
 #include <memory.h>
 
+#define PANE_DATA_TYPE struct popup_info
 #include "core.h"
 
-static struct map *popup_map;
-DEF_LOOKUP_CMD(popup_handle, popup_map);
-
 struct popup_info {
        struct pane     *target safe;
        struct pane     *parent_popup;
        char            *style safe;
        struct command  *done;
 };
+#include "core-pane.h"
+
+static struct map *popup_map;
+DEF_LOOKUP_CMD(popup_handle, popup_map);
 
 static int line_height(struct pane *p safe, int scale)
 {
@@ -139,15 +141,8 @@ DEF_CMD(popup_close)
                pane_focus(ppi->target);
        command_put(ppi->done);
        ppi->done = NULL;
-       return 1;
-}
-
-DEF_CMD(popup_free)
-{
-       struct popup_info *ppi = ci->home->data;
-
        free(ppi->style);
-       unalloc(ppi, pane);
+       ppi->style = "";
        return 1;
 }
 
@@ -468,7 +463,7 @@ DEF_CMD(popup_attach)
         * r  - allow recursive popup
         * t  - temp pane, disappears when it loses focus
         */
-       struct pane *root, *p;
+       struct pane *root, *p, *parent;
        struct popup_info *ppi;
        const char *style = ci->str;
        char *in_popup;
@@ -494,24 +489,26 @@ DEF_CMD(popup_attach)
        if (!root)
                return Efallthrough;
 
-       alloc(ppi, pane);
-       ppi->done = NULL;
-       ppi->target = ci->focus;
-
        /* If focus is already a popup, make this popup higher */
        p = pane_my_child(root, ci->focus);
        if (p && p->z > 0)
                z = p->z + 1;
 
-       ppi->parent_popup = NULL;
+       parent = NULL;
        if (strchr(style, 'P')) {
-               ppi->parent_popup = root;
+               parent = root;
                root = root->parent;
        }
 
-       p = pane_register(root, z + 1, &popup_handle.c, ppi);
+       p = pane_register(root, z + 1, &popup_handle.c);
        if (!p)
                return Efail;
+       ppi = p->data;
+       ppi->done = NULL;
+       ppi->target = ci->focus;
+
+       ppi->parent_popup = parent;
+
        ppi->style = strdup(style);
        popup_set_style(p);
        xy = pane_mapxy(ci->focus, root, ci->x, ci->y, True);
@@ -550,7 +547,6 @@ void edlib_init(struct pane *ed safe)
        popup_map = key_alloc();
 
        key_add(popup_map, "Close", &popup_close);
-       key_add(popup_map, "Free", &popup_free);
        key_add(popup_map, "Notify:Close", &popup_notify_close);
        key_add(popup_map, "Abort", &popup_abort);
        key_add(popup_map, "popup:style", &popup_style);
index ed5a6aa9cc0bffc02f02769904d00f59979f6811..683c06653ae50556a4d5433c3d6f83935227cf29 100644 (file)
@@ -19,6 +19,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+/* Note that we don't use PANE_DATA_TYPE because the tileinfo
+ * moves between panes sometimes.
+ */
 #include "core.h"
 
 struct tileinfo {