2013-06-07 16:27:59 +00:00
|
|
|
/*
|
2013-06-15 11:09:02 +00:00
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
2013-06-07 16:27:59 +00:00
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/license.html
|
2013-06-07 16:27:59 +00:00
|
|
|
*/
|
|
|
|
|
2014-08-20 07:42:53 +00:00
|
|
|
/**
|
|
|
|
* @file src/gwin/gwin_wm.c
|
|
|
|
* @brief GWIN sub-system window manager code
|
|
|
|
*/
|
|
|
|
|
2015-11-21 09:27:08 +00:00
|
|
|
#include "../../gfx.h"
|
2013-06-07 16:27:59 +00:00
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
#if GFX_USE_GWIN && !GWIN_NEED_WINDOWMANAGER
|
|
|
|
/**
|
|
|
|
* A really nasty default implementation for the simplest of systems
|
|
|
|
*/
|
2013-06-07 16:27:59 +00:00
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
|
2014-08-20 07:42:53 +00:00
|
|
|
#include "gwin_class.h"
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Needed if there is no window manager
|
|
|
|
#define MIN_WIN_WIDTH 1
|
|
|
|
#define MIN_WIN_HEIGHT 1
|
|
|
|
|
|
|
|
static gfxMutex gmutex;
|
|
|
|
|
|
|
|
void _gwmInit(void) {
|
|
|
|
gfxMutexInit(&gmutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _gwmDeinit(void) {
|
|
|
|
gfxMutexDestroy(&gmutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_t _gwinWMAdd(GHandle gh, const GWindowInit *pInit) {
|
|
|
|
gh->x = gh->y = gh->width = gh->height = 0;
|
|
|
|
gwinMove(gh, pInit->x, pInit->y);
|
|
|
|
gwinResize(gh, pInit->width, pInit->height);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
void _gwinFlushRedraws(GRedrawMethod how) {
|
|
|
|
(void) how;
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// We are always flushed
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if GDISP_NEED_CLIP
|
|
|
|
static void getLock(GHandle gh) {
|
|
|
|
gfxMutexEnter(&gmutex);
|
|
|
|
gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height);
|
|
|
|
}
|
|
|
|
static void exitLock(GHandle gh) {
|
|
|
|
gdispGUnsetClip(gh->display);
|
|
|
|
gfxMutexExit(&gmutex);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define getLock(gh) gfxMutexEnter(&gmutex)
|
|
|
|
#define exitLock(gh) gfxMutexExit(&gmutex)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void _gwinUpdate(GHandle gh) {
|
|
|
|
if ((gh->flags & GWIN_FLG_SYSVISIBLE)) {
|
|
|
|
if (gh->vmt->Redraw) {
|
|
|
|
getLock(gh);
|
|
|
|
gh->vmt->Redraw(gh);
|
|
|
|
exitLock(gh);
|
|
|
|
} else if ((gh->flags & GWIN_FLG_BGREDRAW)) {
|
|
|
|
getLock(gh);
|
|
|
|
gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor);
|
|
|
|
exitLock(gh);
|
|
|
|
if (gh->vmt->AfterClear)
|
|
|
|
gh->vmt->AfterClear(gh);
|
|
|
|
}
|
|
|
|
} else if ((gh->flags & GWIN_FLG_BGREDRAW)) {
|
|
|
|
getLock(gh);
|
|
|
|
gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gwinGetDefaultBgColor());
|
|
|
|
exitLock(gh);
|
|
|
|
}
|
|
|
|
gh->flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_t _gwinDrawStart(GHandle gh) {
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSVISIBLE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
getLock(gh);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _gwinDrawEnd(GHandle gh) {
|
|
|
|
(void) gh;
|
|
|
|
exitLock(gh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinSetVisible(GHandle gh, bool_t visible) {
|
|
|
|
if (visible) {
|
|
|
|
if (!(gh->flags & GWIN_FLG_VISIBLE)) {
|
|
|
|
gh->flags |= (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE|GWIN_FLG_BGREDRAW);
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((gh->flags & GWIN_FLG_VISIBLE)) {
|
|
|
|
gh->flags &= ~(GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE);
|
|
|
|
gh->flags |= GWIN_FLG_BGREDRAW;
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinSetEnabled(GHandle gh, bool_t enabled) {
|
|
|
|
if (enabled) {
|
|
|
|
if (!(gh->flags & GWIN_FLG_ENABLED)) {
|
|
|
|
gh->flags |= (GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((gh->flags & GWIN_FLG_ENABLED)) {
|
|
|
|
gh->flags &= ~(GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinMove(GHandle gh, coord_t x, coord_t y) {
|
|
|
|
gh->x = x; gh->y = y;
|
|
|
|
if (gh->x < 0) gh->x = 0;
|
|
|
|
if (gh->y < 0) gh->y = 0;
|
|
|
|
if (gh->x > gdispGGetWidth(gh->display)-MIN_WIN_WIDTH) gh->x = gdispGGetWidth(gh->display)-MIN_WIN_WIDTH;
|
|
|
|
if (gh->y > gdispGGetHeight(gh->display)-MIN_WIN_HEIGHT) gh->y = gdispGGetHeight(gh->display)-MIN_WIN_HEIGHT;
|
|
|
|
if (gh->x+gh->width > gdispGGetWidth(gh->display)) gh->width = gdispGGetWidth(gh->display) - gh->x;
|
|
|
|
if (gh->y+gh->height > gdispGGetHeight(gh->display)) gh->height = gdispGGetHeight(gh->display) - gh->y;
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinResize(GHandle gh, coord_t width, coord_t height) {
|
|
|
|
gh->width = width; gh->height = height;
|
|
|
|
if (gh->width < MIN_WIN_WIDTH) { gh->width = MIN_WIN_WIDTH; }
|
|
|
|
if (gh->height < MIN_WIN_HEIGHT) { gh->height = MIN_WIN_HEIGHT; }
|
|
|
|
if (gh->x+gh->width > gdispGGetWidth(gh->display)) gh->width = gdispGGetWidth(gh->display) - gh->x;
|
|
|
|
if (gh->y+gh->height > gdispGGetHeight(gh->display)) gh->height = gdispGGetHeight(gh->display) - gh->y;
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinRedraw(GHandle gh) {
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-07 16:27:59 +00:00
|
|
|
|
|
|
|
#if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
|
|
|
|
|
2014-08-20 07:42:53 +00:00
|
|
|
#include "gwin_class.h"
|
2013-06-07 16:27:59 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------
|
|
|
|
* Data
|
|
|
|
*-----------------------------------------------*/
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
// The default window manager
|
|
|
|
extern const GWindowManager GNullWindowManager;
|
2014-05-21 23:35:36 +00:00
|
|
|
GWindowManager * _GWINwm;
|
2015-01-25 07:40:34 +00:00
|
|
|
bool_t _gwinFlashState;
|
2014-05-21 23:35:36 +00:00
|
|
|
static gfxSem gwinsem;
|
|
|
|
static gfxQueueASync _GWINList;
|
2015-01-25 07:40:34 +00:00
|
|
|
#if GWIN_NEED_FLASHING
|
|
|
|
static GTimer FlashTimer;
|
|
|
|
#endif
|
2014-05-21 23:35:36 +00:00
|
|
|
#if !GWIN_REDRAW_IMMEDIATE
|
|
|
|
static GTimer RedrawTimer;
|
|
|
|
static void RedrawTimerFn(void *param);
|
2013-11-17 10:25:02 +00:00
|
|
|
#endif
|
2014-05-21 23:35:36 +00:00
|
|
|
static volatile uint8_t RedrawPending;
|
|
|
|
#define DOREDRAW_INVISIBLES 0x01
|
|
|
|
#define DOREDRAW_VISIBLES 0x02
|
2015-01-25 07:40:34 +00:00
|
|
|
#define DOREDRAW_FLASHRUNNING 0x04
|
2014-05-21 23:35:36 +00:00
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------
|
|
|
|
* Window Routines
|
|
|
|
*-----------------------------------------------*/
|
|
|
|
|
2014-02-02 18:24:43 +00:00
|
|
|
void _gwmInit(void)
|
|
|
|
{
|
2014-05-21 03:02:00 +00:00
|
|
|
gfxSemInit(&gwinsem, 1, 1);
|
2013-07-07 09:40:37 +00:00
|
|
|
gfxQueueASyncInit(&_GWINList);
|
2015-01-25 07:40:34 +00:00
|
|
|
#if GWIN_NEED_FLASHING
|
|
|
|
gtimerInit(&FlashTimer);
|
|
|
|
#endif
|
2014-05-21 23:35:36 +00:00
|
|
|
#if !GWIN_REDRAW_IMMEDIATE
|
2013-11-17 10:25:02 +00:00
|
|
|
gtimerInit(&RedrawTimer);
|
2014-05-21 03:02:00 +00:00
|
|
|
gtimerStart(&RedrawTimer, RedrawTimerFn, 0, TRUE, TIME_INFINITE);
|
2013-11-17 10:25:02 +00:00
|
|
|
#endif
|
2014-05-21 03:02:00 +00:00
|
|
|
_GWINwm = (GWindowManager *)&GNullWindowManager;
|
|
|
|
_GWINwm->vmt->Init();
|
2013-07-07 09:40:37 +00:00
|
|
|
}
|
|
|
|
|
2014-02-02 18:24:43 +00:00
|
|
|
void _gwmDeinit(void)
|
|
|
|
{
|
2014-05-21 03:02:00 +00:00
|
|
|
GHandle gh;
|
|
|
|
|
|
|
|
while((gh = gwinGetNextWindow(0)))
|
|
|
|
gwinDestroy(gh);
|
|
|
|
|
|
|
|
_GWINwm->vmt->DeInit();
|
2014-05-21 23:35:36 +00:00
|
|
|
#if !GWIN_REDRAW_IMMEDIATE
|
2014-05-21 03:02:00 +00:00
|
|
|
gtimerDeinit(&RedrawTimer);
|
|
|
|
#endif
|
|
|
|
gfxQueueASyncDeinit(&_GWINList);
|
|
|
|
gfxSemDestroy(&gwinsem);
|
|
|
|
}
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
#if GWIN_REDRAW_IMMEDIATE
|
|
|
|
#define TriggerRedraw(void) _gwinFlushRedraws(REDRAW_NOWAIT);
|
|
|
|
#else
|
2014-05-21 03:02:00 +00:00
|
|
|
#define TriggerRedraw() gtimerJab(&RedrawTimer);
|
|
|
|
|
|
|
|
static void RedrawTimerFn(void *param) {
|
|
|
|
(void) param;
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinFlushRedraws(REDRAW_NOWAIT);
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
void _gwinFlushRedraws(GRedrawMethod how) {
|
2014-05-21 03:02:00 +00:00
|
|
|
GHandle gh;
|
|
|
|
|
|
|
|
// Do we really need to do anything?
|
|
|
|
if (!RedrawPending)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Obtain the drawing lock
|
2014-05-21 23:35:36 +00:00
|
|
|
if (how == REDRAW_WAIT)
|
2014-05-21 03:02:00 +00:00
|
|
|
gfxSemWait(&gwinsem, TIME_INFINITE);
|
2014-05-21 23:35:36 +00:00
|
|
|
else if (how == REDRAW_NOWAIT && !gfxSemWait(&gwinsem, TIME_IMMEDIATE))
|
2014-05-21 03:02:00 +00:00
|
|
|
// Someone is drawing - They will do the redraw when they are finished
|
|
|
|
return;
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
// Do loss of visibility first
|
|
|
|
while ((RedrawPending & DOREDRAW_INVISIBLES)) {
|
|
|
|
RedrawPending &= ~DOREDRAW_INVISIBLES; // Catch new requests
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) {
|
2014-05-21 23:35:36 +00:00
|
|
|
if ((gh->flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) != GWIN_FLG_NEEDREDRAW)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Do the redraw
|
|
|
|
#if GDISP_NEED_CLIP
|
|
|
|
gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height);
|
|
|
|
_GWINwm->vmt->Redraw(gh);
|
|
|
|
gdispGUnsetClip(gh->display);
|
|
|
|
#else
|
|
|
|
_GWINwm->vmt->Redraw(gh);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Postpone further redraws
|
|
|
|
#if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP
|
|
|
|
if (how == REDRAW_NOWAIT) {
|
|
|
|
RedrawPending |= DOREDRAW_INVISIBLES;
|
|
|
|
TriggerRedraw();
|
|
|
|
goto releaselock;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the visible windows next
|
|
|
|
while ((RedrawPending & DOREDRAW_VISIBLES)) {
|
|
|
|
RedrawPending &= ~DOREDRAW_VISIBLES; // Catch new requests
|
|
|
|
|
|
|
|
for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) {
|
|
|
|
if ((gh->flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) != (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE))
|
2014-05-21 03:02:00 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Do the redraw
|
|
|
|
#if GDISP_NEED_CLIP
|
|
|
|
gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height);
|
|
|
|
_GWINwm->vmt->Redraw(gh);
|
|
|
|
gdispGUnsetClip(gh->display);
|
|
|
|
#else
|
|
|
|
_GWINwm->vmt->Redraw(gh);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Postpone further redraws (if there are any and the options are set right)
|
2014-05-21 23:35:36 +00:00
|
|
|
#if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP
|
|
|
|
if (how == REDRAW_NOWAIT) {
|
2014-05-21 03:02:00 +00:00
|
|
|
while((gh = gwinGetNextWindow(gh))) {
|
2014-05-21 23:35:36 +00:00
|
|
|
if ((gh->flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) == (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) {
|
|
|
|
RedrawPending |= DOREDRAW_VISIBLES;
|
|
|
|
TriggerRedraw();
|
2014-05-21 03:02:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-05-21 23:35:36 +00:00
|
|
|
goto releaselock;
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
#if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP
|
|
|
|
releaselock:
|
|
|
|
#endif
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
// Release the lock
|
2014-05-21 23:35:36 +00:00
|
|
|
if (how == REDRAW_WAIT || how == REDRAW_NOWAIT)
|
|
|
|
gfxSemSignal(&gwinsem);
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _gwinUpdate(GHandle gh) {
|
|
|
|
// Only redraw if visible
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSVISIBLE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Mark for redraw
|
|
|
|
gh->flags |= GWIN_FLG_NEEDREDRAW;
|
2014-05-21 23:35:36 +00:00
|
|
|
RedrawPending |= DOREDRAW_VISIBLES;
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Asynchronous redraw
|
|
|
|
TriggerRedraw();
|
|
|
|
}
|
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
void _gwinRippleVisibility(void) {
|
|
|
|
GHandle gh;
|
|
|
|
|
|
|
|
// Check each window's visibility is consistent with its parents
|
|
|
|
for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) {
|
|
|
|
switch(gh->flags & (GWIN_FLG_SYSVISIBLE|GWIN_FLG_VISIBLE)) {
|
|
|
|
case GWIN_FLG_VISIBLE:
|
|
|
|
if (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSVISIBLE)) {
|
|
|
|
// We have been made visible
|
|
|
|
gh->flags |= (GWIN_FLG_SYSVISIBLE|GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// Do we want to grab the focus
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
RedrawPending |= DOREDRAW_VISIBLES;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE):
|
|
|
|
if (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSVISIBLE))
|
|
|
|
break;
|
2015-08-16 11:53:47 +00:00
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
// Parent has been made invisible
|
|
|
|
gh->flags &= ~GWIN_FLG_SYSVISIBLE;
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// No focus for us anymore
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
break;
|
|
|
|
case GWIN_FLG_SYSVISIBLE:
|
|
|
|
// We have been made invisible
|
|
|
|
gh->flags &= ~GWIN_FLG_SYSVISIBLE;
|
|
|
|
if (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSVISIBLE)) {
|
|
|
|
// The parent is visible so we must clear the area we took
|
|
|
|
gh->flags |= (GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// No focus for us anymore
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
RedrawPending |= DOREDRAW_INVISIBLES;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
bool_t _gwinDrawStart(GHandle gh) {
|
|
|
|
// This test should occur inside the lock. We do this
|
|
|
|
// here as well as an early out (more efficient).
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSVISIBLE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// Obtain the drawing lock
|
|
|
|
gfxSemWait(&gwinsem, TIME_INFINITE);
|
|
|
|
|
|
|
|
// Re-test visibility as we may have waited a while
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) {
|
|
|
|
_gwinDrawEnd(gh);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK - we are ready to draw.
|
|
|
|
#if GDISP_NEED_CLIP
|
|
|
|
gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height);
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _gwinDrawEnd(GHandle gh) {
|
|
|
|
// Ensure there is no clip set
|
|
|
|
#if GDISP_NEED_CLIP
|
|
|
|
gdispGUnsetClip(gh->display);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Look for something to redraw
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinFlushRedraws(REDRAW_INSESSION);
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Release the lock
|
|
|
|
gfxSemSignal(&gwinsem);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_t _gwinWMAdd(GHandle gh, const GWindowInit *pInit) {
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Save the parent
|
|
|
|
gh->parent = pInit->parent;
|
|
|
|
|
|
|
|
// Ensure the display is consistent with any parents
|
|
|
|
if (gh->parent && (!(gh->parent->flags & GWIN_FLG_CONTAINER) || gh->display != gh->parent->display))
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Add to the window manager
|
|
|
|
if (!_GWINwm->vmt->Add(gh, pInit))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Notify the parent it has been added
|
|
|
|
if (gh->parent && ((gcontainerVMT *)gh->parent->vmt)->NotifyAdd)
|
|
|
|
((gcontainerVMT *)gh->parent->vmt)->NotifyAdd(gh->parent, gh);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return TRUE;
|
2014-02-02 18:24:43 +00:00
|
|
|
}
|
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
void gwinSetWindowManager(struct GWindowManager *gwm) {
|
|
|
|
if (!gwm)
|
|
|
|
gwm = (GWindowManager *)&GNullWindowManager;
|
|
|
|
if (_GWINwm != gwm) {
|
|
|
|
_GWINwm->vmt->DeInit();
|
|
|
|
_GWINwm = gwm;
|
|
|
|
_GWINwm->vmt->Init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
void gwinRedraw(GHandle gh) {
|
|
|
|
// Only redraw if visible
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSVISIBLE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Mark for redraw
|
|
|
|
gh->flags |= GWIN_FLG_NEEDREDRAW;
|
2014-05-21 23:35:36 +00:00
|
|
|
RedrawPending |= DOREDRAW_VISIBLES;
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Synchronous redraw
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinFlushRedraws(REDRAW_WAIT);
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
void gwinSetVisible(GHandle gh, bool_t visible) {
|
|
|
|
if (visible) {
|
|
|
|
// Mark us as visible
|
|
|
|
gh->flags |= GWIN_FLG_VISIBLE;
|
|
|
|
} else {
|
|
|
|
// Mark us as not visible
|
|
|
|
gh->flags &= ~GWIN_FLG_VISIBLE;
|
|
|
|
}
|
2015-01-03 08:44:27 +00:00
|
|
|
|
|
|
|
// Fix everything up
|
|
|
|
_gwinRippleVisibility();
|
|
|
|
if (RedrawPending)
|
|
|
|
TriggerRedraw();
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void gwinSetVisible(GHandle gh, bool_t visible) {
|
|
|
|
if (visible) {
|
|
|
|
if (!(gh->flags & GWIN_FLG_VISIBLE)) {
|
|
|
|
gh->flags |= (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE|GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// Do we want to grab the focus
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
RedrawPending |= DOREDRAW_VISIBLES;
|
2014-05-21 03:02:00 +00:00
|
|
|
TriggerRedraw();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((gh->flags & GWIN_FLG_VISIBLE)) {
|
|
|
|
gh->flags &= ~(GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE);
|
|
|
|
gh->flags |= (GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW);
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// No focus for us anymore
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
RedrawPending |= DOREDRAW_INVISIBLES;
|
2014-05-21 03:02:00 +00:00
|
|
|
TriggerRedraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// These two sub-functions set/clear system enable recursively.
|
|
|
|
void gwinSetEnabled(GHandle gh, bool_t enabled) {
|
|
|
|
if (enabled) {
|
|
|
|
// Mark us as enabled
|
|
|
|
gh->flags |= GWIN_FLG_ENABLED;
|
|
|
|
|
|
|
|
// Do we change our real enabled state
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSENABLED) && (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSENABLED))) {
|
|
|
|
// Check each window's enabled state is consistent with its parents
|
|
|
|
for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) {
|
|
|
|
if ((gh->flags & (GWIN_FLG_SYSENABLED|GWIN_FLG_ENABLED)) == GWIN_FLG_ENABLED && (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSENABLED))) {
|
|
|
|
gh->flags |= GWIN_FLG_SYSENABLED; // Fix it
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// Do we want to grab the focus
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinUpdate(gh);
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gh->flags &= ~GWIN_FLG_ENABLED;
|
|
|
|
|
|
|
|
// Do we need to change our real enabled state
|
|
|
|
if ((gh->flags & GWIN_FLG_SYSENABLED)) {
|
|
|
|
// Check each window's visibility is consistent with its parents
|
|
|
|
for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) {
|
|
|
|
if ((gh->flags & GWIN_FLG_SYSENABLED) && (!(gh->flags & GWIN_FLG_ENABLED) || (gh->parent && !(gh->parent->flags & GWIN_FLG_SYSENABLED)))) {
|
|
|
|
gh->flags &= ~GWIN_FLG_SYSENABLED; // Fix it
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// No focus for us anymore
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinUpdate(gh);
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void gwinSetEnabled(GHandle gh, bool_t enabled) {
|
|
|
|
if (enabled) {
|
|
|
|
if (!(gh->flags & GWIN_FLG_ENABLED)) {
|
|
|
|
gh->flags |= (GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// Do we want to grab the focus
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((gh->flags & GWIN_FLG_ENABLED)) {
|
|
|
|
gh->flags &= ~(GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED);
|
2015-08-16 11:53:47 +00:00
|
|
|
|
|
|
|
// No focus for us anymore
|
|
|
|
_gwinFixFocus(gh);
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void gwinMove(GHandle gh, coord_t x, coord_t y) {
|
|
|
|
_GWINwm->vmt->Move(gh, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinResize(GHandle gh, coord_t width, coord_t height) {
|
|
|
|
_GWINwm->vmt->Size(gh, width, height);
|
|
|
|
}
|
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
void gwinSetMinMax(GHandle gh, GWindowMinMax minmax) {
|
|
|
|
_GWINwm->vmt->MinMax(gh, minmax);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinRaise(GHandle gh) {
|
|
|
|
_GWINwm->vmt->Raise(gh);
|
|
|
|
}
|
|
|
|
|
|
|
|
GWindowMinMax gwinGetMinMax(GHandle gh) {
|
|
|
|
if (gh->flags & GWIN_FLG_MINIMIZED)
|
|
|
|
return GWIN_MINIMIZE;
|
|
|
|
if (gh->flags & GWIN_FLG_MAXIMIZED)
|
|
|
|
return GWIN_MAXIMIZE;
|
|
|
|
return GWIN_NORMAL;
|
|
|
|
}
|
|
|
|
|
2013-11-15 16:01:16 +00:00
|
|
|
void gwinRedrawDisplay(GDisplay *g, bool_t preserve) {
|
2014-05-21 03:02:00 +00:00
|
|
|
GHandle gh;
|
2013-11-15 16:01:16 +00:00
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) {
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Skip if it is for a different display
|
|
|
|
if (g && gh->display != g)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Skip if it is not a top level window (parents internally take care of their children)
|
|
|
|
if (gh->parent)
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Only visible windows are to be redrawn
|
|
|
|
if (!(gh->flags & GWIN_FLG_SYSVISIBLE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!preserve)
|
|
|
|
gh->flags |= GWIN_FLG_BGREDRAW;
|
|
|
|
|
|
|
|
_gwinUpdate(gh);
|
2013-11-15 16:01:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
GHandle gwinGetNextWindow(GHandle gh) {
|
|
|
|
return gh ? (GHandle)gfxQueueASyncNext(&gh->wmq) : (GHandle)gfxQueueASyncPeek(&_GWINList);
|
|
|
|
}
|
|
|
|
|
2015-01-25 07:40:34 +00:00
|
|
|
#if GWIN_NEED_FLASHING
|
|
|
|
static void FlashTimerFn(void *param) {
|
|
|
|
GHandle gh;
|
|
|
|
(void) param;
|
|
|
|
|
|
|
|
// Assume we will be stopping
|
|
|
|
RedrawPending &= ~DOREDRAW_FLASHRUNNING;
|
|
|
|
|
|
|
|
// Swap the flash state
|
|
|
|
_gwinFlashState = !_gwinFlashState;
|
|
|
|
|
|
|
|
// Redraw all flashing windows
|
|
|
|
for(gh = (GHandle)gfxQueueASyncPeek(&_GWINList); gh; gh = (GHandle)gfxQueueASyncNext(&gh->wmq)) {
|
|
|
|
if ((gh->flags & GWIN_FLG_FLASHING)) {
|
|
|
|
RedrawPending |= DOREDRAW_FLASHRUNNING;
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have no flashers left?
|
|
|
|
if (!(RedrawPending & DOREDRAW_FLASHRUNNING))
|
|
|
|
gtimerStop(&FlashTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gwinSetFlashing(GHandle gh, bool_t flash) {
|
|
|
|
|
|
|
|
// Start flashing?
|
|
|
|
if (flash) {
|
|
|
|
gh->flags |= GWIN_FLG_FLASHING; // A redraw will occur on the next flash period.
|
|
|
|
|
|
|
|
// Start the flash timer if needed
|
|
|
|
if (!(RedrawPending & DOREDRAW_FLASHRUNNING)) {
|
|
|
|
RedrawPending |= DOREDRAW_FLASHRUNNING;
|
|
|
|
|
|
|
|
// Ensure we start the timer with flash bit on
|
|
|
|
_gwinFlashState = FALSE;
|
|
|
|
FlashTimerFn(0); // First flash
|
|
|
|
gtimerStart(&FlashTimer, FlashTimerFn, 0, TRUE, GWIN_FLASHING_PERIOD); // Subsequent flashes
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop flashing?
|
|
|
|
} else if ((gh->flags & GWIN_FLG_FLASHING)) {
|
|
|
|
gh->flags &= ~GWIN_FLG_FLASHING;
|
|
|
|
// We need to manually redraw as the timer is now turned off for this window
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if GWIN_NEED_WIDGET
|
|
|
|
const GColorSet *_gwinGetFlashedColor(GWidgetObject *gw, const GColorSet *pcol, bool_t flashOffState) {
|
|
|
|
// Does the flashing state affect the current colors?
|
|
|
|
if ((gw->g.flags & GWIN_FLG_FLASHING) && _gwinFlashState) {
|
|
|
|
|
|
|
|
// For a pressed state show an unpressed state
|
|
|
|
if (pcol == &gw->pstyle->pressed)
|
|
|
|
pcol = &gw->pstyle->enabled;
|
|
|
|
|
|
|
|
// For a non-pressed state (if allowed) show a pressed state
|
|
|
|
else if (flashOffState && pcol == &gw->pstyle->enabled)
|
|
|
|
pcol = &gw->pstyle->pressed;
|
|
|
|
}
|
|
|
|
return pcol;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-06-07 16:27:59 +00:00
|
|
|
/*-----------------------------------------------
|
2014-05-09 11:34:12 +00:00
|
|
|
* "Null" Window Manager Routines
|
2013-06-07 16:27:59 +00:00
|
|
|
*-----------------------------------------------*/
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
// This is a parent reveal operation
|
|
|
|
#define GWIN_FLG_PARENTREVEAL (GWIN_FIRST_WM_FLAG << 0)
|
|
|
|
|
|
|
|
// Minimum dimensions
|
|
|
|
#define MIN_WIN_WIDTH 3
|
|
|
|
#define MIN_WIN_HEIGHT 3
|
|
|
|
|
|
|
|
|
|
|
|
static void WM_Init(void);
|
|
|
|
static void WM_DeInit(void);
|
|
|
|
static bool_t WM_Add(GHandle gh, const GWindowInit *pInit);
|
|
|
|
static void WM_Delete(GHandle gh);
|
|
|
|
static void WM_Redraw(GHandle gh);
|
|
|
|
static void WM_Size(GHandle gh, coord_t w, coord_t h);
|
|
|
|
static void WM_Move(GHandle gh, coord_t x, coord_t y);
|
|
|
|
static void WM_Raise(GHandle gh);
|
|
|
|
static void WM_MinMax(GHandle gh, GWindowMinMax minmax);
|
|
|
|
|
|
|
|
static const gwmVMT GNullWindowManagerVMT = {
|
|
|
|
WM_Init,
|
|
|
|
WM_DeInit,
|
|
|
|
WM_Add,
|
|
|
|
WM_Delete,
|
|
|
|
WM_Redraw,
|
|
|
|
WM_Size,
|
|
|
|
WM_Move,
|
|
|
|
WM_Raise,
|
|
|
|
WM_MinMax,
|
|
|
|
};
|
|
|
|
|
|
|
|
const GWindowManager GNullWindowManager = {
|
|
|
|
&GNullWindowManagerVMT,
|
|
|
|
};
|
|
|
|
|
2013-06-07 16:27:59 +00:00
|
|
|
static void WM_Init(void) {
|
|
|
|
// We don't need to do anything here.
|
|
|
|
// A full window manager would move the windows around, add borders etc
|
|
|
|
|
|
|
|
// clear the screen
|
|
|
|
// cycle through the windows already defined displaying them
|
|
|
|
// or cut all the window areas out of the screen and clear the remainder
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WM_DeInit(void) {
|
|
|
|
// We don't need to do anything here.
|
|
|
|
// A full window manager would remove any borders etc
|
|
|
|
}
|
|
|
|
|
2013-07-03 14:20:32 +00:00
|
|
|
static bool_t WM_Add(GHandle gh, const GWindowInit *pInit) {
|
2014-05-09 11:34:12 +00:00
|
|
|
// Note the window will not currently be marked as visible
|
2013-07-03 14:20:32 +00:00
|
|
|
|
2014-05-09 11:34:12 +00:00
|
|
|
// Put it on the end of the queue
|
2013-06-07 16:27:59 +00:00
|
|
|
gfxQueueASyncPut(&_GWINList, &gh->wmq);
|
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
// Make sure the size/position is valid - prefer position over size.
|
|
|
|
gh->width = MIN_WIN_WIDTH; gh->height = MIN_WIN_HEIGHT;
|
|
|
|
gh->x = gh->y = 0;
|
|
|
|
WM_Move(gh, pInit->x, pInit->y);
|
|
|
|
WM_Size(gh, pInit->width, pInit->height);
|
2013-06-07 16:27:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WM_Delete(GHandle gh) {
|
2014-05-09 11:34:12 +00:00
|
|
|
// Remove it from the window list
|
2013-06-07 16:27:59 +00:00
|
|
|
gfxQueueASyncRemove(&_GWINList, &gh->wmq);
|
|
|
|
}
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
static void WM_Redraw(GHandle gh) {
|
2014-05-09 15:11:30 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
redo_redraw:
|
|
|
|
#endif
|
|
|
|
if ((gh->flags & GWIN_FLG_SYSVISIBLE)) {
|
2014-05-21 03:02:00 +00:00
|
|
|
if (gh->vmt->Redraw)
|
2013-06-07 16:27:59 +00:00
|
|
|
gh->vmt->Redraw(gh);
|
2014-05-21 03:02:00 +00:00
|
|
|
else if ((gh->flags & GWIN_FLG_BGREDRAW)) {
|
|
|
|
// We can't redraw but we want full coverage so just clear the area
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor);
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Only do an after clear if this is not a parent reveal
|
|
|
|
if (!(gh->flags & GWIN_FLG_PARENTREVEAL) && gh->vmt->AfterClear)
|
2013-11-15 16:01:16 +00:00
|
|
|
gh->vmt->AfterClear(gh);
|
|
|
|
}
|
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
2014-05-21 03:02:00 +00:00
|
|
|
// If this is container but not a parent reveal, mark any visible children for redraw
|
|
|
|
// We redraw our children here as we have overwritten them in redrawing the parent
|
2015-01-03 08:44:27 +00:00
|
|
|
// as GDISP/GWIN doesn't support complex clipping regions.
|
2014-05-21 03:02:00 +00:00
|
|
|
if ((gh->flags & (GWIN_FLG_CONTAINER|GWIN_FLG_PARENTREVEAL)) == GWIN_FLG_CONTAINER) {
|
2015-01-03 08:44:27 +00:00
|
|
|
|
|
|
|
// Container redraw is done
|
|
|
|
gh->flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL);
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
for(gh = gwinGetFirstChild(gh); gh; gh = gwinGetSibling(gh))
|
|
|
|
_gwinUpdate(gh);
|
2015-01-03 08:44:27 +00:00
|
|
|
return;
|
2014-05-09 15:11:30 +00:00
|
|
|
}
|
2013-11-15 16:01:16 +00:00
|
|
|
#endif
|
2015-01-03 08:44:27 +00:00
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
} else {
|
|
|
|
if ((gh->flags & GWIN_FLG_BGREDRAW)) {
|
2014-08-16 12:51:59 +00:00
|
|
|
GHandle gx;
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
if (gh->parent) {
|
|
|
|
// Child redraw is done
|
|
|
|
gh->flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL);
|
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
// Get the parent to redraw the area
|
|
|
|
gh = gh->parent;
|
2015-01-03 08:44:27 +00:00
|
|
|
|
|
|
|
// The parent is already marked for redraw - don't do it now.
|
|
|
|
if ((gh->flags & GWIN_FLG_NEEDREDRAW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Use the existing clipping region and redraw now
|
2014-05-21 03:02:00 +00:00
|
|
|
gh->flags |= (GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL);
|
|
|
|
goto redo_redraw;
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-16 12:51:59 +00:00
|
|
|
|
|
|
|
// Clear the area to the background color
|
2014-05-21 03:02:00 +00:00
|
|
|
gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gwinGetDefaultBgColor());
|
2014-08-16 12:51:59 +00:00
|
|
|
|
|
|
|
// Now loop over all windows looking for overlaps. Redraw them if they overlap the newly exposed area.
|
|
|
|
for(gx = gwinGetNextWindow(0); gx; gx = gwinGetNextWindow(gx)) {
|
|
|
|
if ((gx->flags & GWIN_FLG_SYSVISIBLE)
|
|
|
|
&& gx->display == gh->display
|
|
|
|
&& gx->x < gh->x+gh->width && gx->y < gh->y+gh->height && gx->x+gx->width >= gh->x && gx->y+gx->height >= gh->y) {
|
|
|
|
if (gx->vmt->Redraw)
|
|
|
|
gx->vmt->Redraw(gx);
|
|
|
|
else
|
|
|
|
// We can't redraw this window but we want full coverage so just clear the area
|
|
|
|
gdispGFillArea(gx->display, gx->x, gx->y, gx->width, gx->height, gx->bgcolor);
|
|
|
|
}
|
|
|
|
}
|
2014-05-21 03:02:00 +00:00
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
}
|
2013-11-15 16:01:16 +00:00
|
|
|
}
|
2015-01-03 08:44:27 +00:00
|
|
|
|
|
|
|
// Redraw is done
|
|
|
|
gh->flags &= ~(GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW|GWIN_FLG_PARENTREVEAL);
|
2013-06-07 16:27:59 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
static void WM_Size(GHandle gh, coord_t w, coord_t h) {
|
2014-05-11 10:11:16 +00:00
|
|
|
coord_t v;
|
2014-05-10 08:20:05 +00:00
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
2014-05-10 08:20:05 +00:00
|
|
|
if (gh->parent) {
|
|
|
|
// Clip to the container
|
2014-05-11 10:11:16 +00:00
|
|
|
v = gh->parent->x + gh->parent->width - ((const gcontainerVMT *)gh->parent->vmt)->RightBorder(gh->parent);
|
|
|
|
if (gh->x+w > v) w = v - gh->x;
|
|
|
|
v = gh->parent->y + gh->parent->height - ((const gcontainerVMT *)gh->parent->vmt)->BottomBorder(gh->parent);
|
|
|
|
if (gh->y+h > v) h = v - gh->y;
|
2014-05-10 08:20:05 +00:00
|
|
|
}
|
2014-05-09 15:11:30 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-10 08:20:05 +00:00
|
|
|
// Clip to the screen
|
2014-05-11 10:11:16 +00:00
|
|
|
v = gdispGGetWidth(gh->display);
|
|
|
|
if (gh->x+w > v) w = v - gh->x;
|
|
|
|
v = gdispGGetHeight(gh->display);
|
|
|
|
if (gh->y+h > v) h = v - gh->y;
|
|
|
|
|
|
|
|
// Give it a minimum size
|
|
|
|
if (w < MIN_WIN_WIDTH) w = MIN_WIN_WIDTH;
|
|
|
|
if (h < MIN_WIN_HEIGHT) h = MIN_WIN_HEIGHT;
|
2013-07-03 14:20:32 +00:00
|
|
|
|
|
|
|
// If there has been no resize just exit
|
2014-05-09 15:11:30 +00:00
|
|
|
if (gh->width == w && gh->height == h)
|
2013-07-03 14:20:32 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-21 03:02:00 +00:00
|
|
|
// Set the new size and redraw
|
2014-05-09 15:11:30 +00:00
|
|
|
if ((gh->flags & GWIN_FLG_SYSVISIBLE)) {
|
2014-05-21 03:02:00 +00:00
|
|
|
if (w >= gh->width && h >= gh->height) {
|
|
|
|
|
|
|
|
// The new size is larger - just redraw
|
|
|
|
gh->width = w; gh->height = h;
|
|
|
|
_gwinUpdate(gh);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// We need to make this window invisible and ensure that has been drawn
|
|
|
|
gwinSetVisible(gh, FALSE);
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinFlushRedraws(REDRAW_WAIT);
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Resize
|
|
|
|
gh->width = w; gh->height = h;
|
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Any children outside the new area need to be moved
|
|
|
|
if ((gh->flags & GWIN_FLG_CONTAINER)) {
|
|
|
|
GHandle child;
|
|
|
|
|
|
|
|
// Move to their old relative location. THe WM_Move() will adjust as necessary
|
|
|
|
for(child = gwinGetFirstChild(gh); child; child = gwinGetSibling(child))
|
2015-01-03 08:44:27 +00:00
|
|
|
WM_Move(child, child->x-gh->x-((const gcontainerVMT *)gh->vmt)->LeftBorder(gh), child->y-gh->y-((const gcontainerVMT *)gh->vmt)->TopBorder(gh));
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Mark it visible again in its new location
|
|
|
|
gwinSetVisible(gh, TRUE);
|
|
|
|
}
|
2014-05-09 15:11:30 +00:00
|
|
|
} else {
|
|
|
|
gh->width = w; gh->height = h;
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Any children outside the new area need to be moved
|
|
|
|
if ((gh->flags & GWIN_FLG_CONTAINER)) {
|
|
|
|
GHandle child;
|
|
|
|
|
|
|
|
// Move to their old relative location. THe WM_Move() will adjust as necessary
|
|
|
|
for(child = gwinGetFirstChild(gh); child; child = gwinGetSibling(child))
|
2015-01-03 08:44:27 +00:00
|
|
|
WM_Move(child, child->x-gh->x-((const gcontainerVMT *)gh->vmt)->LeftBorder(gh), child->y-gh->y-((const gcontainerVMT *)gh->vmt)->TopBorder(gh));
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-11-15 16:01:16 +00:00
|
|
|
}
|
2014-05-09 15:11:30 +00:00
|
|
|
}
|
2013-07-03 14:20:32 +00:00
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
static void WM_Move(GHandle gh, coord_t x, coord_t y) {
|
2015-01-03 08:44:27 +00:00
|
|
|
coord_t u, v;
|
2014-05-11 10:11:16 +00:00
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
2014-05-10 08:20:05 +00:00
|
|
|
if (gh->parent) {
|
2014-05-11 10:11:16 +00:00
|
|
|
// Clip to the parent size
|
2015-01-03 08:44:27 +00:00
|
|
|
u = gh->parent->width - ((const gcontainerVMT *)gh->parent->vmt)->LeftBorder(gh->parent) - ((const gcontainerVMT *)gh->parent->vmt)->RightBorder(gh->parent);
|
2014-05-11 10:11:16 +00:00
|
|
|
v = gh->parent->height - ((const gcontainerVMT *)gh->parent->vmt)->TopBorder(gh->parent) - ((const gcontainerVMT *)gh->parent->vmt)->BottomBorder(gh->parent);
|
2015-01-03 08:44:27 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// Clip to the screen
|
|
|
|
u = gdispGGetWidth(gh->display);
|
|
|
|
v = gdispGGetHeight(gh->display);
|
|
|
|
}
|
2014-05-10 08:20:05 +00:00
|
|
|
|
2015-01-03 08:44:27 +00:00
|
|
|
// Make sure we are positioned in the appropriate area
|
|
|
|
if (x+gh->width > u) x = u-gh->width;
|
|
|
|
if (x < 0) x = 0;
|
|
|
|
if (y+gh->height > v) y = v-gh->height;
|
|
|
|
if (y < 0) y = 0;
|
|
|
|
|
|
|
|
// Make sure we don't overflow the appropriate area
|
|
|
|
u -= x;
|
|
|
|
v -= y;
|
|
|
|
if (gh->width < u) u = gh->width;
|
|
|
|
if (gh->height < v) v = gh->height;
|
|
|
|
if (u != gh->width || v != gh->height)
|
|
|
|
WM_Size(gh, u, v);
|
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
if (gh->parent) {
|
|
|
|
// Convert to a screen relative position
|
2014-05-11 10:11:16 +00:00
|
|
|
x += gh->parent->x + ((const gcontainerVMT *)gh->parent->vmt)->LeftBorder(gh->parent);
|
|
|
|
y += gh->parent->y + ((const gcontainerVMT *)gh->parent->vmt)->TopBorder(gh->parent);
|
2014-05-10 08:20:05 +00:00
|
|
|
}
|
2014-05-09 15:11:30 +00:00
|
|
|
#endif
|
2013-07-03 14:20:32 +00:00
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
// If there has been no move just exit
|
|
|
|
if (gh->x == x && gh->y == y)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Clear the old area and then redraw
|
|
|
|
if ((gh->flags & GWIN_FLG_SYSVISIBLE)) {
|
2014-05-21 03:02:00 +00:00
|
|
|
// We need to make this window invisible and ensure that has been drawn
|
|
|
|
gwinSetVisible(gh, FALSE);
|
2014-05-21 23:35:36 +00:00
|
|
|
_gwinFlushRedraws(REDRAW_WAIT);
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
// Do the move
|
2015-01-03 08:44:27 +00:00
|
|
|
u = gh->x; gh->x = x;
|
|
|
|
v = gh->y; gh->y = y;
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Any children need to be moved
|
|
|
|
if ((gh->flags & GWIN_FLG_CONTAINER)) {
|
|
|
|
GHandle child;
|
|
|
|
|
|
|
|
// Move to their old relative location. THe WM_Move() will adjust as necessary
|
|
|
|
for(child = gwinGetFirstChild(gh); child; child = gwinGetSibling(child))
|
2015-01-03 08:44:27 +00:00
|
|
|
WM_Move(child, child->x-u-((const gcontainerVMT *)gh->vmt)->LeftBorder(gh), child->y-v-((const gcontainerVMT *)gh->vmt)->TopBorder(gh));
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gwinSetVisible(gh, TRUE);
|
2014-05-09 15:11:30 +00:00
|
|
|
} else {
|
2015-01-03 08:44:27 +00:00
|
|
|
u = gh->x; gh->x = x;
|
|
|
|
v = gh->y; gh->y = y;
|
2014-05-21 03:02:00 +00:00
|
|
|
|
|
|
|
#if GWIN_NEED_CONTAINERS
|
|
|
|
// Any children need to be moved
|
|
|
|
if ((gh->flags & GWIN_FLG_CONTAINER)) {
|
|
|
|
GHandle child;
|
|
|
|
|
|
|
|
// Move to their old relative location. THe WM_Move() will adjust as necessary
|
|
|
|
for(child = gwinGetFirstChild(gh); child; child = gwinGetSibling(child))
|
2015-01-03 08:44:27 +00:00
|
|
|
WM_Move(child, child->x-u-((const gcontainerVMT *)gh->vmt)->LeftBorder(gh), child->y-v-((const gcontainerVMT *)gh->vmt)->TopBorder(gh));
|
2014-05-21 03:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-05-09 15:11:30 +00:00
|
|
|
}
|
2013-06-07 16:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WM_MinMax(GHandle gh, GWindowMinMax minmax) {
|
|
|
|
(void)gh; (void) minmax;
|
|
|
|
// We don't support minimising, maximising or restoring
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WM_Raise(GHandle gh) {
|
|
|
|
// Take it off the list and then put it back on top
|
|
|
|
// The order of the list then reflects the z-order.
|
2014-05-09 15:11:30 +00:00
|
|
|
|
2013-06-07 16:27:59 +00:00
|
|
|
gfxQueueASyncRemove(&_GWINList, &gh->wmq);
|
|
|
|
gfxQueueASyncPut(&_GWINList, &gh->wmq);
|
|
|
|
|
2016-07-25 09:26:28 +00:00
|
|
|
#if GWIN_NEED_CONTAINERS
|
2016-07-25 15:03:27 +00:00
|
|
|
// Any children need to be raised too
|
2016-07-25 09:26:28 +00:00
|
|
|
if ((gh->flags & GWIN_FLG_CONTAINER)) {
|
2016-07-28 06:34:34 +00:00
|
|
|
GHandle gx;
|
2016-07-25 09:26:28 +00:00
|
|
|
GHandle child;
|
|
|
|
bool_t restart;
|
|
|
|
|
2016-07-25 15:03:27 +00:00
|
|
|
// Raise the children too
|
|
|
|
// Note: Children can also have their own children so after each move we have to start again.
|
|
|
|
for (gx = gwinGetNextWindow(0); gx; gx = gwinGetNextWindow(gx)) {
|
|
|
|
if ((gx->flags & GWIN_FLG_CONTAINER)) {
|
2016-07-25 09:26:28 +00:00
|
|
|
restart = FALSE;
|
2016-07-25 15:03:27 +00:00
|
|
|
for (child = gwinGetNextWindow(0); child && child != gx; child = gwinGetNextWindow(child)) {
|
|
|
|
if (child->parent == gx) {
|
|
|
|
// Oops - this child is behind its parent. Move it to the front.
|
2016-07-25 09:26:28 +00:00
|
|
|
gfxQueueASyncRemove(&_GWINList, &child->wmq);
|
|
|
|
gfxQueueASyncPut(&_GWINList, &child->wmq);
|
2016-07-25 15:03:27 +00:00
|
|
|
|
|
|
|
// Restart at the front of the list for this parent container as we have moved this child
|
|
|
|
// to the end of the list. We also need to restart everything once this container is done.
|
|
|
|
child = 0;
|
2016-07-25 09:26:28 +00:00
|
|
|
restart = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (restart)
|
2016-07-25 15:03:27 +00:00
|
|
|
gx = 0;
|
2016-07-25 09:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-07 16:27:59 +00:00
|
|
|
// Redraw the window
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate(gh);
|
2014-05-09 15:11:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 16:27:59 +00:00
|
|
|
#endif /* GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER */
|
|
|
|
/** @} */
|