13 #include "../../gfx.h"
15 #if GFX_USE_GWIN && !GWIN_NEED_WINDOWMANAGER
21 #include "gwin_class.h"
24 #define MIN_WIN_WIDTH 1
25 #define MIN_WIN_HEIGHT 1
33 void _gwmDeinit(
void) {
44 void _gwinFlushRedraws(GRedrawMethod how) {
52 static void getLock(
GHandle gh) {
56 static void exitLock(
GHandle gh) {
61 #define getLock(gh) gfxMutexEnter(&gmutex)
62 #define exitLock(gh) gfxMutexExit(&gmutex)
66 if ((gh->
flags & GWIN_FLG_SYSVISIBLE)) {
71 }
else if ((gh->
flags & GWIN_FLG_BGREDRAW)) {
78 }
else if ((gh->
flags & GWIN_FLG_BGREDRAW)) {
83 gh->
flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
86 gBool _gwinDrawStart(
GHandle gh) {
87 if (!(gh->
flags & GWIN_FLG_SYSVISIBLE))
101 if (!(gh->
flags & GWIN_FLG_VISIBLE)) {
102 gh->
flags |= (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE|GWIN_FLG_BGREDRAW);
106 if ((gh->
flags & GWIN_FLG_VISIBLE)) {
107 gh->
flags &= ~(GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE);
108 gh->
flags |= GWIN_FLG_BGREDRAW;
116 if (!(gh->
flags & GWIN_FLG_ENABLED)) {
117 gh->
flags |= (GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
121 if ((gh->
flags & GWIN_FLG_ENABLED)) {
122 gh->
flags &= ~(GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
129 gh->
x = x; gh->
y = y;
130 if (gh->
x < 0) gh->
x = 0;
131 if (gh->
y < 0) gh->
y = 0;
141 if (gh->
width < MIN_WIN_WIDTH) { gh->
width = MIN_WIN_WIDTH; }
142 if (gh->
height < MIN_WIN_HEIGHT) { gh->
height = MIN_WIN_HEIGHT; }
153 #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
155 #include "gwin_class.h"
162 extern const GWindowManager GNullWindowManager;
163 GWindowManager * _GWINwm;
164 gBool _gwinFlashState;
167 #if GWIN_NEED_FLASHING
170 #if !GWIN_REDRAW_IMMEDIATE
171 static GTimer RedrawTimer;
172 static void RedrawTimerFn(
void *param);
174 static volatile gU8 RedrawPending;
175 #define DOREDRAW_INVISIBLES 0x01
176 #define DOREDRAW_VISIBLES 0x02
177 #define DOREDRAW_FLASHRUNNING 0x04
187 gfxQueueASyncInit(&_GWINList);
188 #if GWIN_NEED_FLASHING
191 #if !GWIN_REDRAW_IMMEDIATE
193 gtimerStart(&RedrawTimer, RedrawTimerFn, 0, gTrue, gDelayForever);
195 _GWINwm = (GWindowManager *)&GNullWindowManager;
196 _GWINwm->vmt->Init();
199 void _gwmDeinit(
void)
206 _GWINwm->vmt->DeInit();
207 #if !GWIN_REDRAW_IMMEDIATE
210 gfxQueueASyncDeinit(&_GWINList);
214 #if GWIN_REDRAW_IMMEDIATE
215 #define TriggerRedraw(void) _gwinFlushRedraws(REDRAW_NOWAIT);
217 #define TriggerRedraw() gtimerJab(&RedrawTimer);
219 static void RedrawTimerFn(
void *param) {
221 _gwinFlushRedraws(REDRAW_NOWAIT);
225 void _gwinFlushRedraws(GRedrawMethod how) {
233 if (how == REDRAW_WAIT)
235 else if (how == REDRAW_NOWAIT && !
gfxSemWait(&gwinsem, gDelayNone))
240 while ((RedrawPending & DOREDRAW_INVISIBLES)) {
241 RedrawPending &= ~DOREDRAW_INVISIBLES;
244 if ((gh->
flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) != GWIN_FLG_NEEDREDRAW)
250 _GWINwm->vmt->Redraw(gh);
253 _GWINwm->vmt->Redraw(gh);
257 #if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP
258 if (how == REDRAW_NOWAIT) {
259 RedrawPending |= DOREDRAW_INVISIBLES;
268 while ((RedrawPending & DOREDRAW_VISIBLES)) {
269 RedrawPending &= ~DOREDRAW_VISIBLES;
272 if ((gh->
flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) != (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE))
278 _GWINwm->vmt->Redraw(gh);
281 _GWINwm->vmt->Redraw(gh);
285 #if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP
286 if (how == REDRAW_NOWAIT) {
288 if ((gh->
flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) == (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) {
289 RedrawPending |= DOREDRAW_VISIBLES;
300 #if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP
305 if (how == REDRAW_WAIT || how == REDRAW_NOWAIT)
311 if (!(gh->
flags & GWIN_FLG_SYSVISIBLE))
315 gh->
flags |= GWIN_FLG_NEEDREDRAW;
316 RedrawPending |= DOREDRAW_VISIBLES;
322 #if GWIN_NEED_CONTAINERS
323 void _gwinRippleVisibility(
void) {
328 switch(gh->
flags & (GWIN_FLG_SYSVISIBLE|GWIN_FLG_VISIBLE)) {
329 case GWIN_FLG_VISIBLE:
330 if (!gh->parent || (gh->parent->
flags & GWIN_FLG_SYSVISIBLE)) {
332 gh->
flags |= (GWIN_FLG_SYSVISIBLE|GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
337 RedrawPending |= DOREDRAW_VISIBLES;
340 case (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE):
341 if (!gh->parent || (gh->parent->
flags & GWIN_FLG_SYSVISIBLE))
345 gh->
flags &= ~GWIN_FLG_SYSVISIBLE;
351 case GWIN_FLG_SYSVISIBLE:
353 gh->
flags &= ~GWIN_FLG_SYSVISIBLE;
354 if (!gh->parent || (gh->parent->
flags & GWIN_FLG_SYSVISIBLE)) {
356 gh->
flags |= (GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
361 RedrawPending |= DOREDRAW_INVISIBLES;
369 gBool _gwinDrawStart(
GHandle gh) {
372 if (!(gh->
flags & GWIN_FLG_SYSVISIBLE))
379 if (!(gh->
flags & GWIN_FLG_SYSVISIBLE)) {
391 void _gwinDrawEnd(
GHandle gh) {
398 _gwinFlushRedraws(REDRAW_INSESSION);
405 #if GWIN_NEED_CONTAINERS
407 gh->parent = pInit->parent;
410 if (gh->parent && (!(gh->parent->
flags & GWIN_FLG_CONTAINER) || gh->
display != gh->parent->
display))
415 if (!_GWINwm->vmt->Add(gh, pInit))
418 #if GWIN_NEED_CONTAINERS
429 gwm = (GWindowManager *)&GNullWindowManager;
430 if (_GWINwm != gwm) {
431 _GWINwm->vmt->DeInit();
433 _GWINwm->vmt->Init();
439 if (!(gh->
flags & GWIN_FLG_SYSVISIBLE))
443 gh->
flags |= GWIN_FLG_NEEDREDRAW;
444 RedrawPending |= DOREDRAW_VISIBLES;
447 _gwinFlushRedraws(REDRAW_WAIT);
450 #if GWIN_NEED_CONTAINERS
454 gh->
flags |= GWIN_FLG_VISIBLE;
457 gh->
flags &= ~GWIN_FLG_VISIBLE;
461 _gwinRippleVisibility();
468 if (!(gh->
flags & GWIN_FLG_VISIBLE)) {
469 gh->
flags |= (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE|GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
474 RedrawPending |= DOREDRAW_VISIBLES;
478 if ((gh->
flags & GWIN_FLG_VISIBLE)) {
479 gh->
flags &= ~(GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE);
480 gh->
flags |= (GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
485 RedrawPending |= DOREDRAW_INVISIBLES;
492 #if GWIN_NEED_CONTAINERS
497 gh->
flags |= GWIN_FLG_ENABLED;
500 if (!(gh->
flags & GWIN_FLG_SYSENABLED) && (!gh->parent || (gh->parent->
flags & GWIN_FLG_SYSENABLED))) {
503 if ((gh->
flags & (GWIN_FLG_SYSENABLED|GWIN_FLG_ENABLED)) == GWIN_FLG_ENABLED && (!gh->parent || (gh->parent->
flags & GWIN_FLG_SYSENABLED))) {
504 gh->
flags |= GWIN_FLG_SYSENABLED;
514 gh->
flags &= ~GWIN_FLG_ENABLED;
517 if ((gh->
flags & GWIN_FLG_SYSENABLED)) {
520 if ((gh->
flags & GWIN_FLG_SYSENABLED) && (!(gh->
flags & GWIN_FLG_ENABLED) || (gh->parent && !(gh->parent->
flags & GWIN_FLG_SYSENABLED)))) {
521 gh->
flags &= ~GWIN_FLG_SYSENABLED;
535 if (!(gh->
flags & GWIN_FLG_ENABLED)) {
536 gh->
flags |= (GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
544 if ((gh->
flags & GWIN_FLG_ENABLED)) {
545 gh->
flags &= ~(GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
557 _GWINwm->vmt->Move(gh, x, y);
561 _GWINwm->vmt->Size(gh, width, height);
565 _GWINwm->vmt->MinMax(gh, minmax);
569 _GWINwm->vmt->Raise(gh);
573 if (gh->
flags & GWIN_FLG_MINIMIZED)
574 return GWIN_MINIMIZE;
575 if (gh->
flags & GWIN_FLG_MAXIMIZED)
576 return GWIN_MAXIMIZE;
589 #if GWIN_NEED_CONTAINERS
596 if (!(gh->
flags & GWIN_FLG_SYSVISIBLE))
600 gh->
flags |= GWIN_FLG_BGREDRAW;
607 return gh ? (
GHandle)gfxQueueASyncNext(&gh->wmq) : (
GHandle)gfxQueueASyncPeek(&_GWINList);
610 #if GWIN_NEED_FLASHING
611 static void FlashTimerFn(
void *param) {
616 RedrawPending &= ~DOREDRAW_FLASHRUNNING;
619 _gwinFlashState = !_gwinFlashState;
622 for(gh = (
GHandle)gfxQueueASyncPeek(&_GWINList); gh; gh = (
GHandle)gfxQueueASyncNext(&gh->wmq)) {
623 if ((gh->
flags & GWIN_FLG_FLASHING)) {
624 RedrawPending |= DOREDRAW_FLASHRUNNING;
630 if (!(RedrawPending & DOREDRAW_FLASHRUNNING))
638 gh->
flags |= GWIN_FLG_FLASHING;
641 if (!(RedrawPending & DOREDRAW_FLASHRUNNING)) {
642 RedrawPending |= DOREDRAW_FLASHRUNNING;
645 _gwinFlashState = gFalse;
651 }
else if ((gh->
flags & GWIN_FLG_FLASHING)) {
652 gh->
flags &= ~GWIN_FLG_FLASHING;
661 if ((gw->
g.
flags & GWIN_FLG_FLASHING) && _gwinFlashState) {
682 #define GWIN_FLG_PARENTREVEAL (GWIN_FIRST_WM_FLAG << 0)
685 #define MIN_WIN_WIDTH 3
686 #define MIN_WIN_HEIGHT 3
689 static void WM_Init(
void);
690 static void WM_DeInit(
void);
692 static void WM_Delete(
GHandle gh);
693 static void WM_Redraw(
GHandle gh);
696 static void WM_Raise(
GHandle gh);
699 static const gwmVMT GNullWindowManagerVMT = {
711 const GWindowManager GNullWindowManager = {
712 &GNullWindowManagerVMT,
715 static void WM_Init(
void) {
724 static void WM_DeInit(
void) {
733 gfxQueueASyncPut(&_GWINList, &gh->wmq);
736 gh->
width = MIN_WIN_WIDTH; gh->
height = MIN_WIN_HEIGHT;
738 WM_Move(gh, pInit->
x, pInit->
y);
743 static void WM_Delete(
GHandle gh) {
746 gfxQueueASyncRemove(&_GWINList, &gh->wmq);
750 static void WM_Redraw(
GHandle gh) {
754 gh->
flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL);
756 #if GWIN_NEED_CONTAINERS
759 if ((flags & GWIN_FLG_SYSVISIBLE)) {
762 else if ((flags & GWIN_FLG_BGREDRAW)) {
771 #if GWIN_NEED_CONTAINERS
775 if ((flags & (GWIN_FLG_CONTAINER|GWIN_FLG_PARENTREVEAL)) == GWIN_FLG_CONTAINER) {
786 if ((flags & GWIN_FLG_BGREDRAW)) {
789 #if GWIN_NEED_CONTAINERS
797 if ((gh->
flags & GWIN_FLG_NEEDREDRAW))
801 gh->
flags |= (GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL);
811 if ((gx->
flags & GWIN_FLG_SYSVISIBLE)
829 #if GWIN_NEED_CONTAINERS
832 v = gh->parent->
x + gh->parent->
width - ((
const gcontainerVMT *)gh->parent->
vmt)->RightBorder(gh->parent);
833 if (gh->
x+w > v) w = v - gh->
x;
835 if (gh->
y+h > v) h = v - gh->
y;
841 if (gh->
x+w > v) w = v - gh->
x;
843 if (gh->
y+h > v) h = v - gh->
y;
846 if (w < MIN_WIN_WIDTH) w = MIN_WIN_WIDTH;
847 if (h < MIN_WIN_HEIGHT) h = MIN_WIN_HEIGHT;
854 if ((gh->
flags & GWIN_FLG_SYSVISIBLE)) {
864 _gwinFlushRedraws(REDRAW_WAIT);
869 #if GWIN_NEED_CONTAINERS
871 if ((gh->
flags & GWIN_FLG_CONTAINER)) {
886 #if GWIN_NEED_CONTAINERS
888 if ((gh->
flags & GWIN_FLG_CONTAINER)) {
902 #if GWIN_NEED_CONTAINERS
929 #if GWIN_NEED_CONTAINERS
932 x += gh->parent->
x + ((
const gcontainerVMT *)gh->parent->
vmt)->LeftBorder(gh->parent);
933 y += gh->parent->
y + ((
const gcontainerVMT *)gh->parent->
vmt)->TopBorder(gh->parent);
938 if (gh->
x == x && gh->
y == y)
942 if ((gh->
flags & GWIN_FLG_SYSVISIBLE)) {
945 _gwinFlushRedraws(REDRAW_WAIT);
948 u = gh->
x; gh->
x = x;
949 v = gh->
y; gh->
y = y;
951 #if GWIN_NEED_CONTAINERS
953 if ((gh->
flags & GWIN_FLG_CONTAINER)) {
964 u = gh->
x; gh->
x = x;
965 v = gh->
y; gh->
y = y;
967 #if GWIN_NEED_CONTAINERS
969 if ((gh->
flags & GWIN_FLG_CONTAINER)) {
981 (void)gh; (void) minmax;
985 static void WM_Raise(
GHandle gh) {
991 gfxQueueASyncRemove(&_GWINList, &gh->wmq);
992 gfxQueueASyncPut(&_GWINList, &gh->wmq);
994 #if GWIN_NEED_CONTAINERS
996 if ((gh->
flags & GWIN_FLG_CONTAINER)) {
1004 if ((gx->
flags & GWIN_FLG_CONTAINER)) {
1007 if (child->parent == gx) {
1009 gfxQueueASyncRemove(&_GWINList, &child->wmq);
1010 gfxQueueASyncPut(&_GWINList, &child->wmq);
GHandle gwinGetFirstChild(GHandle gh)
Get the first child window.
GHandle gwinGetSibling(GHandle gh)
Get the next child window in the z-order.
#define gdispGUnsetClip(g)
Reset the clip area to the full screen.
void gdispGSetClip(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy)
Clip all drawing to the defined area.
gCoord gdispGGetWidth(GDisplay *g)
Get the display width in pixels.
void gdispGFillArea(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gColor color)
Fill an area with a color.
gCoord gdispGGetHeight(GDisplay *g)
Get the display height in pixels.
gI16 gCoord
The type for a coordinate or length on the screen.
void gfxSemSignal(gSem *psem)
Signal a semaphore.
void gfxMutexExit(gMutex *pmutex)
Exit the critical code region protected by the mutex.
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxMutexEnter(gMutex *pmutex)
Enter the critical code region protected by the mutex.
void gfxMutexInit(gMutex *pmutex)
Initialise a mutex to protect a region of code from other threads.
void gfxSemDestroy(gSem *psem)
Destroy a Counted Semaphore.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxMutexDestroy(gMutex *pmutex)
Destroy a Mutex.
void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, gBool periodic, gDelay millisec)
Set a timer going or alter its properties if it is already going.
void gtimerInit(GTimer *pt)
Initialise a timer.
void gtimerDeinit(GTimer *pt)
Deinitialise a timer.
void gtimerStop(GTimer *pt)
Stop a timer (periodic or otherwise)
#define GWIN_FLASHING_PERIOD
What is the period for the flashing timer.
void gwinRedrawDisplay(GDisplay *g, gBool preserve)
Redraw a display.
void gwinRaise(GHandle gh)
Raise a window to the top of the z-order.
void gwinRedraw(GHandle gh)
Redraw a window.
void gwinDestroy(GHandle gh)
Destroy a window (of any type). Releases any dynamically allocated memory.
void gwinSetVisible(GHandle gh, gBool visible)
Sets whether a window is visible or not.
void gwinSetFlashing(GHandle gh, gBool flash)
Set a window or widget to flash.
GHandle gwinGetNextWindow(GHandle gh)
Get the next window in the z-order.
gColor gwinGetDefaultBgColor(void)
Get the default background color for all new GWIN windows.
GWindowMinMax
A window's minimized, maximized or normal size.
void gwinSetEnabled(GHandle gh, gBool enabled)
Enable or disable a window.
GWindowMinMax gwinGetMinMax(GHandle gh)
Get the Minimized/Maximized state of a window.
void gwinResize(GHandle gh, gCoord width, gCoord height)
Resize a window.
void gwinMove(GHandle gh, gCoord x, gCoord y)
Move a window.
void gwinSetWindowManager(struct GWindowManager *gwm)
Set the window manager for the GWIN system.
void gwinSetMinMax(GHandle gh, GWindowMinMax minmax)
Minimize, Maximize or Restore a window.
The structure to initialise a GWIN.
A window object structure.
const struct gwinVMT * vmt
The Virtual Method Table for a container.
void(* AfterClear)(GWindowObject *gh)
void(* Redraw)(GWindowObject *gh)
The Virtual Method Table for a window manager.