?? framewin.c
字號:
/*
*********************************************************************************************************
* uC/GUI
* 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 : Framewindow for emWin GSC
---------------------------END-OF-HEADER------------------------------
*/
#include <stdlib.h>
#include <string.h>
#include "FRAMEWIN.h"
#include "WIDGET.h"
#include "GProtect.h"
#if GUI_WINSUPPORT
/*
*****************************************************************
* *
* Config defaults *
* *
*****************************************************************
*/
/* Support for 3D effects */
#ifndef FRAMEWIN_USE_3D
#define FRAMEWIN_USE_3D 1
#endif
#ifndef FRAMEWIN_CLIENTCOLOR_DEFAULT
#define FRAMEWIN_CLIENTCOLOR_DEFAULT GUI_LIGHTGRAY
#endif
/* Default for top frame size */
#ifndef FRAMEWIN_CAPTIONSIZE_DEFAULT
#define FRAMEWIN_CAPTIONSIZE_DEFAULT (HZSIZEY+2)
#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
#ifndef FRAMEWIN_DEFAULT_FONT
#define FRAMEWIN_DEFAULT_FONT &GUI_Font16B_1
#endif
#ifndef FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT
#define FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT 0xff0000
#endif
#ifndef FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT
#define FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT 0x404040
#endif
#ifndef FRAMEWIN_FRAMECOLOR_DEFAULT
#define FRAMEWIN_FRAMECOLOR_DEFAULT 0xaaaaaa
#endif
/************************************************************
*
* Object definition
*
*************************************************************
*/
typedef struct {
WIDGET Widget;
GUI_COLOR BarColor[2];
GUI_COLOR TextColor;
WM_CALLBACK* cb;
WM_HWIN hClient;
GUI_POINT CapturePoint;
const GUI_FONT* pFont;
GUI_RECT rClient;
GUI_COLOR ClientColor;
const char* pText;
I16 XOff, YOff;
I16 FrameSize;
I16 TitleHeight;
I16 TextAlign;
U16 Flags;
WM_HWIN hFocussedChild; /* Handle to focussed child .. default none (0) */
// char HasFocus;
} FRAMEWIN_Obj;
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static const GUI_FONT* _pDefaultFont = FRAMEWIN_DEFAULT_FONT;
static GUI_COLOR _aBarColor[2] = {
FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT,
FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT
};
static GUI_COLOR _DefaultClientColor = FRAMEWIN_CLIENTCOLOR_DEFAULT;
static int _DefaultCaptionSize = FRAMEWIN_CAPTIONSIZE_DEFAULT;
static int _DefaultBorderSize = FRAMEWIN_BORDER_DEFAULT;
/*
********************************************************************
* *
* Macros for internal use *
* *
********************************************************************
*/
#define FRAMEWIN_H2P(h) (FRAMEWIN_Obj*) WM_HMEM2Ptr(h)
/*
********************************************************************
* *
* Static routines *
* *
********************************************************************
*/
static void _OnTouch(FRAMEWIN_Handle hWin, FRAMEWIN_Obj* pObj, WM_MESSAGE* pMsg) {
GUI_TOUCH_tState* pState;
pState = (GUI_TOUCH_tState*)pMsg->Data.p;
if (pMsg->Data.p) { // Something happened in our area (pressed or released)
if (pState->Pressed) {
WM_SetFocus(hWin);
WM_BringToTop(hWin);
if (pObj->Flags & FRAMEWIN_SF_MOVEABLE) {
if (!WM_HasCaptured(hWin)) {
WM_SetCapture(hWin, 1);
pObj->CapturePoint.x = pState->x;
pObj->CapturePoint.y = pState->y;
} else {
int dx, dy;
dx = pState->x - pObj->CapturePoint.x;
dy = pState->y - pObj->CapturePoint.y;
WM_MoveWindow(hWin, dx, dy);
}
}
}
}
}
static void _Paint(FRAMEWIN_Obj* pObj) {
WM_HWIN hWin = WM_GetActiveWindow();
int xsize = WM_GetWindowSizeX(hWin);
int ysize = WM_GetWindowSizeY(hWin);
int FrameSize = pObj->FrameSize;
int YSizeOfFont=GUI_GetYSizeOfFont (pObj->pFont);
GUI_RECT rClient; GUI_GetClientRect(&rClient);
GUI_SetFont(pObj->pFont);
// Draw Title
GUI_SetBkColor((pObj->Widget.State & WIDGET_STATE_CHILD_HAS_FOCUS) ? pObj->BarColor[1] : pObj->BarColor[0]);
GUI_SetColor (pObj->TextColor);
GUI_SetTextAlign(pObj->TextAlign);
GUI_ClearRect(FrameSize,FrameSize, xsize-1-FrameSize, FrameSize+pObj->rClient.y0-1);
GUI_DispStringAt( pObj->pText,
FrameSize+pObj->XOff,
FrameSize+pObj->YOff);
// Draw Frame
GUI_SetColor (FRAMEWIN_FRAMECOLOR_DEFAULT); // pObj->BarColor[1]
GUI_FillRect (0, 0, xsize-1, FrameSize-1);
GUI_FillRect (0, 0, pObj->rClient.x0-1, ysize-1);
GUI_FillRect (pObj->rClient.x1+1, 0, xsize-1, ysize-1);
GUI_FillRect (0, pObj->rClient.y1+1, xsize-1, ysize-1);
GUI_FillRect (0, pObj->TitleHeight+FrameSize,
xsize-1, pObj->TitleHeight+2*FrameSize-1);
// Draw Client area
WM_SetUserClipArea(&pObj->rClient);
//GUI_SetBkColor(pObj->ClientColor);
//GUI_Clear();
WM_SetUserClipArea(NULL);
// Draw the 3D effect (if configured)
#if FRAMEWIN_USE_3D
WIDGET_EFFECT_3D_DrawUp();
#endif
}
static void CalcPositions( FRAMEWIN_Handle hObj) {
if (hObj) {
FRAMEWIN_Obj * pObj = FRAMEWIN_H2P(hObj);
int TitleHeight;
int FontSize = GUI_GetYSizeOfFont(pObj->pFont);
int xsize = WM_GetWindowSizeX(hObj);
int ysize = WM_GetWindowSizeY(hObj);
TitleHeight = _DefaultCaptionSize;
// Make sure defaults are o.k. for us
if (FontSize + 2 >= TitleHeight)
TitleHeight = FontSize + 2;
// Set object properties accordingly
pObj->rClient.x0 = _DefaultBorderSize;
pObj->rClient.x1 = xsize - _DefaultBorderSize - 1;
pObj->rClient.y0 = _DefaultBorderSize + FRAMEWIN_IBORDER_DEFAULT + TitleHeight;
pObj->rClient.y1 = ysize - _DefaultBorderSize - 1;
pObj->FrameSize = _DefaultBorderSize;
pObj->TitleHeight = TitleHeight;
if (pObj->hClient) {
WM_MoveTo (pObj->hClient,
pObj->rClient.x0 + pObj->Widget.Win.Rect.x0,
pObj->rClient.y0 + pObj->Widget.Win.Rect.y0);
WM_SetSize(pObj->hClient,
pObj->rClient.x1 - pObj->rClient.x0 + 1,
pObj->rClient.y1 - pObj->rClient.y0 + 1);
}
}
}
/*********************************************************************
*
* Framewin Callback
*/
static void _FRAMEWIN_Callback (WM_MESSAGE *pMsg) {
FRAMEWIN_Handle hWin = (FRAMEWIN_Handle)(pMsg->hWin);
FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hWin);
GUI_RECT* pRect = (GUI_RECT*)(pMsg->Data.p);
switch (pMsg->MsgId) {
case WM_PAINT:
_Paint(pObj);
break;
case WM_TOUCH:
_OnTouch(hWin, pObj, pMsg);
return; // Return here ... Message handled
case WM_GETCLIENTRECT:
*pRect = pObj->rClient;
return; // Return here ... Message handled
case WM_GETCLIENTRECT_ABS: // Do not seperate from WM_GETCLIENTRECT !!!
*pRect = pObj->rClient;
GUI_MoveRect(pRect, pObj->Widget.Win.Rect.x0, pObj->Widget.Win.Rect.y0);
return; // Return here ... Message handled
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
pMsg->Data.v = pObj->hClient;
return; // Return here ... Message handled
case WM_GET_FOCUSSED_CHILD:
pMsg->Data.v = pObj->hFocussedChild;
return; // Return here ... Message handled
case WM_SET_FOCUS:
if (pMsg->Data.v == 1) {
WM_SetFocus(pObj->hFocussedChild);
} else {
WM_SetFocus(0);
}
return;
}
// Let widget handle the standard messages
if (WIDGET_HandleActive(hWin, pMsg) == 0) {
return;
}
WM_DefaultProc(pMsg);
}
/*********************************************************************
*
* Client Callback
*/
static void FRAMEWIN__cbClient(WM_MESSAGE* pMsg) {
WM_HWIN hWin = pMsg->hWin;
WM_HWIN hParent = WM_GetParent(pMsg->hWin);
FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hParent);
WM_CALLBACK* cb = pObj->cb;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -