📄 framewin.c
字号:
/*
*********************************************************************************************************
* uC/GUI V3.98
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
* 礐/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File : FRAMEWIN.c
Purpose : Implementation of framewindow widget
---------------------------END-OF-HEADER------------------------------
*/
#include <stdlib.h>
#include <string.h>
#include "FRAMEWIN_Private.h"
#include "GUI_Protected.h"
#include "WM_Intern.h"
#if GUI_WINSUPPORT
/******************************************************************
*
* Config defaults
*
*******************************************************************
*/
/* Support for 3D effects */
#ifndef FRAMEWIN_CLIENTCOLOR_DEFAULT
#define FRAMEWIN_CLIENTCOLOR_DEFAULT 0xc0c0c0
#endif
/* Default for top frame size */
#ifndef FRAMEWIN_TITLEHEIGHT_DEFAULT
#define FRAMEWIN_TITLEHEIGHT_DEFAULT 0
#endif
/* Default for left/right/top/bottom frame size */
#ifndef FRAMEWIN_BORDER_DEFAULT
#define FRAMEWIN_BORDER_DEFAULT 3
#endif
/* Default for inner frame size */
#ifndef FRAMEWIN_IBORDER_DEFAULT
#define FRAMEWIN_IBORDER_DEFAULT 1
#endif
/* Default font */
#ifndef FRAMEWIN_DEFAULT_FONT
#if WIDGET_USE_SCHEME_SMALL
#define FRAMEWIN_DEFAULT_FONT &GUI_Font8_1
#elif WIDGET_USE_SCHEME_MEDIUM
#define FRAMEWIN_DEFAULT_FONT &GUI_Font13_1
#elif WIDGET_USE_SCHEME_LARGE
#define FRAMEWIN_DEFAULT_FONT &GUI_Font16_1
#endif
#endif
/* Default barcolor when framewin is active */
#ifndef FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT
#define FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT 0xFF0000
#endif
/* Default barcolor when framewin is inactive */
#ifndef FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT
#define FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT 0x404040
#endif
/* Default framecolor */
#ifndef FRAMEWIN_FRAMECOLOR_DEFAULT
#define FRAMEWIN_FRAMECOLOR_DEFAULT 0xAAAAAA
#endif
/* Default textcolor when framewin is active */
#ifndef FRAMEWIN_TEXTCOLOR0_DEFAULT
#define FRAMEWIN_TEXTCOLOR0_DEFAULT GUI_WHITE
#endif
/* Default textcolor when framewin is inactive */
#ifndef FRAMEWIN_TEXTCOLOR1_DEFAULT
#define FRAMEWIN_TEXTCOLOR1_DEFAULT GUI_WHITE
#endif
/* Default text alignment */
#ifndef FRAMEWIN_TEXTALIGN_DEFAULT
#define FRAMEWIN_TEXTALIGN_DEFAULT GUI_TA_LEFT
#endif
/*********************************************************************
*
* public data, defaults (internal use only)
*
**********************************************************************
*/
FRAMEWIN_PROPS FRAMEWIN__DefaultProps = {
FRAMEWIN_DEFAULT_FONT,
FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT,
FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT,
FRAMEWIN_TEXTCOLOR0_DEFAULT,
FRAMEWIN_TEXTCOLOR1_DEFAULT,
FRAMEWIN_CLIENTCOLOR_DEFAULT,
FRAMEWIN_TITLEHEIGHT_DEFAULT,
FRAMEWIN_BORDER_DEFAULT,
FRAMEWIN_IBORDER_DEFAULT,
FRAMEWIN_TEXTALIGN_DEFAULT
};
/*********************************************************************
*
* static data
*
**********************************************************************
*/
static I16 FRAMEWIN__MinVisibility = 5;
/*********************************************************************
*
* Static routines
*
**********************************************************************
*/
/*********************************************************************
*
* _SetActive
*/
static void _SetActive(FRAMEWIN_Handle hObj, int State) {
FRAMEWIN_Obj* pObj;
pObj = FRAMEWIN_H2P(hObj);
if (State && !(pObj->Flags & FRAMEWIN_SF_ACTIVE)) {
pObj->Flags |= FRAMEWIN_CF_ACTIVE;
FRAMEWIN_Invalidate(hObj);
} else if (!State && (pObj->Flags & FRAMEWIN_SF_ACTIVE)) {
pObj->Flags &= ~FRAMEWIN_CF_ACTIVE;
FRAMEWIN_Invalidate(hObj);
}
}
/*********************************************************************
*
* _OnTouch
*/
static void _OnTouch(FRAMEWIN_Handle hWin, FRAMEWIN_Obj* pObj, WM_MESSAGE* pMsg) {
const GUI_PID_STATE* pState;
pState = (const GUI_PID_STATE*)pMsg->Data.p;
if (pMsg->Data.p) { /* Something happened in our area (pressed or released) */
if (pState->Pressed) {
if (!(pObj->Flags & FRAMEWIN_SF_ACTIVE)) {
WM_SetFocus(hWin);
}
WM_BringToTop(hWin);
if (pObj->Flags & FRAMEWIN_SF_MOVEABLE) {
int LimitTop;
#if (FRAMEWIN_ALLOW_DRAG_ON_FRAME)
LimitTop = 0;
#else
POSITIONS Pos;
FRAMEWIN__CalcPositions(pObj, &Pos);
LimitTop = pObj->Props.BorderSize + Pos.TitleHeight - 1 + pObj->Props.IBorderSize;
if ((pState->y <= LimitTop) || WM_HasCaptured(hWin))
#endif
{
if ((pObj->Flags & FRAMEWIN_SF_MAXIMIZED) == 0) {
WM_SetCaptureMove(hWin, pState, FRAMEWIN__MinVisibility, LimitTop);
}
}
}
}
}
}
/*********************************************************************
*
* _Paint (Frame)
*
*/
static void _Paint(FRAMEWIN_Obj* pObj) {
WM_HWIN hWin = WM_GetActiveWindow();
const char* pText = NULL;
int xsize = WM_GetWindowSizeX(hWin);
int ysize = WM_GetWindowSizeY(hWin);
int BorderSize = pObj->Props.BorderSize;
int y0, Index;
POSITIONS Pos;
GUI_RECT r, rText;
/* Perform computations */
FRAMEWIN__CalcPositions(pObj, &Pos);
Index = (pObj->Flags & FRAMEWIN_SF_ACTIVE) ? 1 : 0;
if (pObj->hText) {
pText = (const char*) GUI_ALLOC_h2p(pObj->hText);
}
r.x0 = Pos.rClient.x0;
r.x1 = Pos.rClient.x1;
r.y0 = Pos.rTitleText.y0;
r.y1 = Pos.rTitleText.y1;
Pos.rTitleText.y0++;
Pos.rTitleText.x0++;
Pos.rTitleText.x1--;
GUI_SetFont(pObj->Props.pFont);
GUI__CalcTextRect(pText, &Pos.rTitleText, &rText, pObj->Props.TextAlign);
y0 = Pos.TitleHeight + BorderSize;
/* Perform drawing operations */
WM_ITERATE_START(NULL) {
/* Draw Title */
LCD_SetBkColor(pObj->Props.aBarColor[Index]);
LCD_SetColor(pObj->Props.aTextColor[Index]);
WIDGET__FillStringInRect(pText, &r, &Pos.rTitleText, &rText);
/* Draw Frame */
LCD_SetColor(FRAMEWIN_FRAMECOLOR_DEFAULT);
GUI_FillRect(0, 0, xsize-1, BorderSize-1);
GUI_FillRect(0, 0, Pos.rClient.x0-1, ysize-1);
GUI_FillRect(Pos.rClient.x1+1, 0, xsize-1, ysize-1);
GUI_FillRect(0, Pos.rClient.y1+1, xsize-1, ysize-1);
GUI_FillRect(0, y0, xsize - 1, y0 + pObj->Props.IBorderSize - 1);
/* Draw the 3D effect (if configured) */
if (pObj->Props.BorderSize >= 2) {
WIDGET_EFFECT_3D_DrawUp(); /* pObj->Widget.pEffect->pfDrawUp(); */
}
} WM_ITERATE_END();
}
/*********************************************************************
*
* _OnChildHasFocus
*
* Function:
* A child has received or lost the focus.
* The basic idea is to make sure the framewindow is active if a
* descendant has the focus.
* If the focus travels from one desc. to an other, there is no need
* to make the framewindow inactive and active again.
* Avoiding this complicates the code a litlle, but avoids flicker
* and waste of CPU load.
*
*/
static void _OnChildHasFocus(FRAMEWIN_Handle hWin, FRAMEWIN_Obj* pObj, WM_MESSAGE *pMsg) {
if (pMsg->Data.p) {
const WM_NOTIFY_CHILD_HAS_FOCUS_INFO * pInfo = (const WM_NOTIFY_CHILD_HAS_FOCUS_INFO *)pMsg->Data.p;
int IsDesc = WM__IsAncestorOrSelf(pInfo->hNew, hWin);
if (IsDesc) { /* A child has received the focus, Framewindow needs to be activated */
_SetActive(hWin, 1);
} else { /* A child has lost the focus, we need to deactivate */
_SetActive(hWin, 0);
/* Remember the child which had the focus so we can reactive this child */
if (WM__IsAncestor(pInfo->hOld, hWin)) {
pObj->hFocussedChild = pInfo->hOld;
}
}
}
}
/*********************************************************************
*
* Client Callback
*/
static void FRAMEWIN__cbClient(WM_MESSAGE* pMsg) {
WM_HWIN hWin, hParent;
FRAMEWIN_Obj * pObj;
WM_CALLBACK * cb;
hWin = pMsg->hWin;
hParent = WM_GetParent(pMsg->hWin);
pObj = (FRAMEWIN_Obj *)GUI_ALLOC_h2p(hParent); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
cb = pObj->cb;
switch (pMsg->MsgId) {
case WM_PAINT:
if (pObj->Props.ClientColor != GUI_INVALID_COLOR) {
LCD_SetBkColor(pObj->Props.ClientColor);
GUI_Clear();
}
/* Give the user callback a chance to draw.
* Note that we can not run into the bottom part, as this passes the parents handle
*/
if (cb) {
WM_MESSAGE Msg;
Msg = *pMsg;
Msg.hWin = hWin;
(*cb)(&Msg);
}
return;
case WM_SET_FOCUS:
if (pMsg->Data.v) { /* Focus received */
if (pObj->hFocussedChild && (pObj->hFocussedChild != hWin)) {
WM_SetFocus(pObj->hFocussedChild);
} else {
pObj->hFocussedChild = WM_SetFocusOnNextChild(hWin);
}
pMsg->Data.v = 0; /* Focus change accepted */
}
return;
case WM_GET_ACCEPT_FOCUS:
WIDGET_HandleActive(hParent, pMsg);
return;
case WM_KEY:
if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt > 0) {
int Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key;
switch (Key) {
case GUI_KEY_BACKTAB:
pObj->hFocussedChild = WM_SetFocusOnPrevChild(hWin);
return;
case GUI_KEY_TAB:
pObj->hFocussedChild = WM_SetFocusOnNextChild(hWin);
return;
}
}
break; /* Send to parent by not doing anything */
case WM_GET_BKCOLOR:
pMsg->Data.Color = pObj->Props.ClientColor;
return; /* Message handled */
case WM_GET_INSIDE_RECT: /* This should not be passed to parent ... (We do not want parents coordinates)*/
case WM_GET_ID: /* This should not be passed to parent ... (Possible recursion problem)*/
case WM_GET_CLIENT_WINDOW: /* return handle to client window. For most windows, there is no seperate client window, so it is the same handle */
WM_DefaultProc(pMsg);
return; /* We are done ! */
}
/* Call user callback. Note that the user callback gets the handle of the Framewindow itself, NOT the Client. */
if (cb) {
pMsg->hWin = hParent;
(*cb)(pMsg);
} else {
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -