summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-08 18:04:46 -0400
committerPietro Gagliardi <[email protected]>2015-04-08 18:04:46 -0400
commit06c2bb7c25a1612e8e98bdded498ecca4be359d0 (patch)
treed5dea8278e43edc1308753bed4e0db52850defc1
parent7b104667ab49b62e19f115fd33274936e087d892 (diff)
Fixed initial (and future) window redraw issues on Windows.
-rw-r--r--new/container_windows.c16
-rw-r--r--new/newcontrol_windows.c12
-rw-r--r--new/stack.c11
-rw-r--r--new/uipriv.h2
-rw-r--r--new/window_windows.c3
5 files changed, 36 insertions, 8 deletions
diff --git a/new/container_windows.c b/new/container_windows.c
index 2056653..20d7d8d 100644
--- a/new/container_windows.c
+++ b/new/container_windows.c
@@ -82,3 +82,19 @@ void resize(uiControl *control, HWND parent, RECT r)
logLastError("error releasing DC in resize()");
(*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
}
+
+void updateParent(uintptr_t h)
+{
+ HWND hwnd;
+ RECT r;
+
+ if (h == 0) // no parent
+ return;
+ hwnd = (HWND) h;
+ // TODO is there a better way?
+ if (GetWindowRect(hwnd, &r) == 0)
+ logLastError("error getting window rect for dummy move in updateParent()");
+ if (MoveWindow(hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
+ logLastError("error moving window in updateParent()");
+ // TODO invalidate rect?
+}
diff --git a/new/newcontrol_windows.c b/new/newcontrol_windows.c
index 98956fa..1293f5a 100644
--- a/new/newcontrol_windows.c
+++ b/new/newcontrol_windows.c
@@ -12,6 +12,7 @@ struct uiSingleHWNDControl {
void *onCommandNotifyDestroyData;
void (*preferredSize)(uiControl *, int, int, LONG, intmax_t *, intmax_t *);
void *data;
+ uintptr_t parent;
};
#define S(c) ((uiSingleHWNDControl *) (c))
@@ -28,10 +29,17 @@ static uintptr_t singleHandle(uiControl *c)
return (uintptr_t) (S(c)->hwnd);
}
-static void singleSetParent(uiControl *c, uintptr_t parentHWND)
+static void singleSetParent(uiControl *c, uintptr_t parent)
{
- if (SetParent(S(c)->hwnd, (HWND) parentHWND) == NULL)
+ uiSingleHWNDControl *s = S(c);
+ uintptr_t oldparent;
+
+ oldparent = s->parent;
+ s->parent = parent;
+ if (SetParent(s->hwnd, (HWND) (s->parent)) == NULL)
logLastError("error changing control parent in singleSetParent()");
+ updateParent(oldparent);
+ updateParent(s->parent);
}
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
diff --git a/new/stack.c b/new/stack.c
index 45fcf54..fa28e59 100644
--- a/new/stack.c
+++ b/new/stack.c
@@ -38,11 +38,16 @@ static uintptr_t stackHandle(uiControl *c)
static void stackSetParent(uiControl *c, uintptr_t parent)
{
+ stack *s = S(c);
uintmax_t i;
+ uintptr_t oldparent;
- S(c)->parent = parent;
+ oldparent = s->parent;
+ s->parent = parent;
for (i = 0; i < S(c)->len; i++)
- (*(S(c)->controls[i]->setParent))(S(c)->controls[i], S(c)->parent);
+ (*(s->controls[i]->setParent))(s->controls[i], s->parent);
+ updateParent(oldparent);
+ updateParent(s->parent);
}
static uiSize stackPreferredSize(uiControl *c, uiSizing *d)
@@ -213,5 +218,5 @@ void uiStackAdd(uiControl *st, uiControl *c, int stretchy)
if (s->parent != 0)
(*(s->controls[s->len]->setParent))(s->controls[s->len], s->parent);
s->len++;
- // TODO queue reposition
+ updateParent(s->parent);
}
diff --git a/new/uipriv.h b/new/uipriv.h
index b8f5835..a12fbdc 100644
--- a/new/uipriv.h
+++ b/new/uipriv.h
@@ -25,3 +25,5 @@ extern void *uiAlloc(size_t, const char *);
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T ))
extern void *uiRealloc(void *, size_t, const char *);
extern void uiFree(void *);
+
+extern void updateParent(uintptr_t);
diff --git a/new/window_windows.c b/new/window_windows.c
index d68843b..7bbb895 100644
--- a/new/window_windows.c
+++ b/new/window_windows.c
@@ -1,9 +1,6 @@
// 6 april 2015
#include "uipriv_windows.h"
-// TODOs:
-// - child not set to fit initial size
-
struct uiWindow {
HWND hwnd;
uiControl *child;