📄 aeeimagectl.c
字号:
pme->m_dwProps = dwProps;
}
/*===========================================================================
Public Method - Returns the flags/properties for the analog clock. See AEEAClock.h
===========================================================================*/
static uint32 ImageCtl_GetProperties(IImageCtl * po)
{
ImageCtl * pme = (ImageCtl *)po;
return(pme->m_dwProps);
}
/*===========================================================================
Private Method - Called from IImage when an update is necessary. Note that
we set a flag here. This keeps us from Public Method - Sets the redraw callback.
===========================================================================*/
static void ImageCtl_RedrawCB(ImageCtl * pme)
{
PFNNOTIFY pfn = pme->m_pfnRedraw;
// Note - Because we actually call out of the code, we protect it with an AddRef/Release.
// While this adds a bit of code, it protects us in case they yank the object from under us...
if(pfn){
pme->m_pfnRedraw = NULL;
pme->m_nRefs++;
pfn(pme->m_pRedraw);
if(ImageCtl_Release((IImageCtl *)pme))
pme->m_pfnRedraw = pfn;
}
else
ImageCtl_Redraw((IImageCtl *)pme);
}
/*===========================================================================
Public Method - Sets the redraw callback.
===========================================================================*/
static void ImageCtl_SetRedraw(IImageCtl * po,PFNNOTIFY pfn,void * pUser)
{
ImageCtl * pme = (ImageCtl *)po;
pme->m_pfnRedraw = pfn;
pme->m_pRedraw = pUser;
if(pme->m_pImage)
IIMAGE_SetParm(pme->m_pImage,IPARM_REDRAW,(int)(pfn ? ImageCtl_RedrawCB : NULL),(int)pme);
}
/*===========================================================================
Private Method - Resets the image for the control.
===========================================================================*/
static void ImageCtl_SetImage(IImageCtl * po, IImage * pi)
{
ImageCtl * pme = (ImageCtl *)po;
aee_releaseobj((void **)(&pme->m_pImage));
MEMSET(&pme->m_ii, 0, sizeof(pme->m_ii));
pme->m_xOffset = pme->m_yOffset = 0;
pme->m_pImage = pi;
if(pi)
IIMAGE_AddRef(pi);
ImageCtl_CheckScroll(pme);
}
/*=====================================================================
Local Method - Draws a standard menu scroll bar
======================================================================*/
static void ImageCtl_DrawScrollBar(ImageCtl * pme,boolean bVertical)
{
IDisplay * pd = pme->m_pDisplay;
AEERect rctFrame, rctThumb;
if( !ImageCtl_GetScrollBarRects(pme, &rctFrame, &rctThumb, bVertical) ){
IDISPLAY_DrawFrame(pd, &rctFrame, AEE_FT_BOX, CLR_SYS_SCROLLBAR);
IDISPLAY_FillRect(pd, &rctThumb, CLR_SYS_SCROLLBAR_FILL);
}
}
/*=====================================================================
Local Method - Gets the rect for the specified SB thumb and container
======================================================================*/
static int ImageCtl_GetScrollBarRects(ImageCtl * pme,AEERect * prcFrame, AEERect * prcThumb, boolean bVertical)
{
ImageCtl_CheckScroll(pme);
if(pme->m_bActive){
AEERect rc;
int nRange, nPos, nScrollRange, nLen,cx,nSB,nAdjust;
int nScrollItem,x,y,cy,nItems,nPageItems;
rc = pme->m_rc;
nSB = pme->m_nSBWidth;
if(bVertical){
if( !pme->m_bScrollY ){
return EFAILED;
}
nItems = pme->m_ii.cy;
nPageItems = rc.dy;
nScrollItem = pme->m_yOffset;
x = (rc.x + rc.dx - nSB);
y = rc.y;
cy = rc.dy;
if(pme->m_bScrollX){
cy -= (pme->m_nSBWidth - 1);
nPageItems -= pme->m_nSBWidth;
}
cx = nSB;
SETAEERECT(&rc, x, y , nSB, cy);
}
else{
if( !pme->m_bScrollX ){
return EFAILED;
}
nItems = pme->m_ii.cxFrame;
nPageItems = rc.dx;
nScrollItem = pme->m_xOffset;
x = rc.x;
y = (rc.y + rc.dy - nSB);
cx = rc.dx;
if(pme->m_bScrollY){
cx -= (pme->m_nSBWidth - 1);
nPageItems -= pme->m_nSBWidth;
}
cy = nSB;
SETAEERECT(&rc, x, y , cx, nSB);
}
*prcFrame = rc;
nAdjust = IDISPLAY_DrawFrame(pme->m_pDisplay, NULL, AEE_FT_BOX, CLR_SYS_SCROLLBAR);
y += nAdjust;
x += nAdjust;
nAdjust <<= 1;
cy -= nAdjust;
cx -= nAdjust;
if(bVertical)
nRange = cy ;
else
nRange = cx;
nScrollRange = nItems - nPageItems;
nLen = nRange/(nItems/nPageItems);
nPos = (nScrollItem*(nRange-nLen))/nScrollRange;
if(nLen < 2)
nLen = 2;
if(bVertical){
if(nPos + nLen > cy)
nPos = cy - nLen;
prcThumb->x = x;
prcThumb->dx = cx;
prcThumb->y = y + nPos;
prcThumb->dy = nLen;
}
else{
if(nPos + nLen > cx)
nPos = cx - nLen;
prcThumb->x = x + nPos;
prcThumb->dx = nLen;
prcThumb->y = y;
prcThumb->dy = cy;
}
return AEE_SUCCESS;
}
return EFAILED;
}
/*=====================================================================
Local Method - Determines whether we are scrolling
======================================================================*/
static void ImageCtl_CheckScroll(ImageCtl * pme)
{
int cx,cy,nSB = 0;
boolean bScrollX = FALSE, bScrollY = FALSE;
AEERect rc = pme->m_rc;
if(pme->m_pImage){
if(pme->m_bActive){
nSB = pme->m_nSBWidth;
if(pme->m_dwProps & CP_BORDER)
nSB++;
}
else{
if(pme->m_dwProps & CP_BORDER)
nSB = 2;
}
IIMAGE_GetInfo(pme->m_pImage,&pme->m_ii);
cx = rc.dx;
cy = rc.dy;
// See if we need a vertical scrollbar...
if(pme->m_ii.cy > rc.dy){
bScrollY = TRUE;
cx -= nSB; // scrollbar on right - decrease cx available...
}
// See if we need a horizontal scrollbar...
if(pme->m_ii.cxFrame > rc.dx){
bScrollX = TRUE;
cy -= nSB; // scrollbar on bottom - decrease cy available...
}
IIMAGE_SetParm(pme->m_pImage, IPARM_SIZE, cx, cy);
pme->m_ptViewSize.x = cx;
pme->m_ptViewSize.y = cy;
}
pme->m_bScrollY = bScrollY;
pme->m_bScrollX = bScrollX;
}
/*=====================================================================
Local Method - Timer for pen held down scrolling outside of thumb
======================================================================*/
static void ImageCtl_ScrollTimerCB(ImageCtl * pme)
{
pme->m_ptTracker.cbFlags &= ~PTRCK_GEN_TMRSET;
ImageCtl_ScrollByPos(pme, ((pme->m_ptTracker.cbHit & PTRCK_HIT_BELOW) ? 1 : -1), pme->m_ptTracker.ptPosition.x, pme->m_ptTracker.ptPosition.y);
}
/*=====================================================================
Local Method - Scrolls text in the ImageCtl by direction and point
in a non-thumb area.
======================================================================*/
static boolean ImageCtl_ScrollByPos(ImageCtl * pme, int nDir, int16 wXPos, int16 wYPos)
{
AEERect rctFrame, rctThumb;
boolean bVSBHit = ((pme->m_ptTracker.cbHit & PTRCK_HIT_VSCRL) ? TRUE : FALSE);
if( !ImageCtl_GetScrollBarRects(pme, &rctFrame, &rctThumb, bVSBHit) ){
boolean bMoved = FALSE;
// First check if it is within the scollbar's bounds
if( PT_IN_RECT(wXPos, wYPos, rctFrame) ){
// Then if in the segment expected
if( nDir > 0 ){
// Already bound by SB Frame, so just check proper direction
if( (bVSBHit && wYPos > (rctThumb.y+rctThumb.dy))
|| (!bVSBHit && wXPos > (rctThumb.x+rctThumb.dx)) ){
if( bVSBHit ){
pme->m_yOffset += pme->m_ptViewSize.y;
if( pme->m_yOffset > (pme->m_ii.cy - pme->m_ptViewSize.y) ){
pme->m_yOffset = pme->m_ii.cy - pme->m_ptViewSize.y;
}
}else{
pme->m_xOffset += pme->m_ptViewSize.x;
if( pme->m_xOffset > (pme->m_ii.cx - pme->m_ptViewSize.x) ){
pme->m_xOffset = pme->m_ii.cx - pme->m_ptViewSize.x;
}
}
bMoved = TRUE;
}
}else{
if( (bVSBHit && wYPos < rctThumb.y)
|| (!bVSBHit && wXPos < rctThumb.x) ){
if( bVSBHit ){
pme->m_yOffset -= pme->m_ptViewSize.y;
if( pme->m_yOffset < 0 ){
pme->m_yOffset = 0;
}
}else{
pme->m_xOffset -= pme->m_ptViewSize.x;
if( pme->m_xOffset < 0 ){
pme->m_xOffset = 0;
}
}
bMoved = TRUE;
}
}
if( bMoved ){
ISHELL_SetTimer(pme->m_pShell, pme->m_arPenRepeat.dwRate, (PFNNOTIFY)ImageCtl_ScrollTimerCB, (void *)pme);
pme->m_ptTracker.cbFlags |= PTRCK_GEN_TMRSET;
IIMAGE_SetParm(pme->m_pImage, IPARM_OFFSET, pme->m_xOffset, pme->m_yOffset);
ImageCtl_RedrawCB(pme);
return TRUE;
}
}
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -