📄 unixsite.cpp
字号:
points[3].x = points[0].x;
points[3].y = points[0].y;
XFillPolygon( dis, m_ScrollVertButtonB, tmpGC, points, 4, Convex, CoordModeOrigin);
}
//Draw Left Horizontal arrow.
if( m_ScrollHorizButtonL )
{
points[0].x = SCROLL_BAR_WIDTH-offset;
points[0].y = offset;
points[1].x = SCROLL_BAR_WIDTH-offset;
points[1].y = SCROLL_BAR_WIDTH-offset;
points[2].x = offset;
points[2].y = SCROLL_BAR_WIDTH/2;
points[3].x = points[0].x;
points[3].y = points[0].y;
XFillPolygon( dis, m_ScrollHorizButtonL, tmpGC, points, 4, Convex, CoordModeOrigin);
}
//Draw Right Horizontal arrow.
if( m_ScrollHorizButtonR )
{
points[0].x = offset;
points[0].y = SCROLL_BAR_WIDTH-offset;
points[1].x = offset;
points[1].y = offset;
points[2].x = SCROLL_BAR_WIDTH-offset;
points[2].y = SCROLL_BAR_WIDTH/2;
points[3].x = points[0].x;
points[3].y = points[0].y;
XFillPolygon( dis, m_ScrollHorizButtonR, tmpGC, points, 4, Convex, CoordModeOrigin);
}
//Free the GC and go.
XFreeGC( dis, tmpGC );
}
BOOL CHXUnixSite::_InButton( HXxPoint& pt, int x, int y )
{
BOOL retVal =FALSE;
if( x>= pt.x && x< pt.x+SCROLL_BAR_WIDTH && y>=pt.y && y<pt.y+SCROLL_BAR_WIDTH )
retVal=TRUE;
else
retVal=FALSE;
return retVal;
}
void CHXUnixSite::_CreateHorizScrollBar()
{
HX_ASSERT( m_ScrollHorizButtonL == 0 );
HX_ASSERT( m_ScrollHorizButtonR == 0 );
HXxSize mySize;
HXxWindow* pParentWindow = NULL;
if(GetParentSite())
{
pParentWindow = GetParentSite()->GetWindow();
}
if(pParentWindow)
{
GetParentSite()->GetSize(mySize);
}
HX_ASSERT( pParentWindow );
HX_ASSERT( pParentWindow->window != 0 );
if( m_ScrollVertButtonB )
{
// if the other bar already exists, don't overlap it!
mySize.cx -= SCROLL_BAR_WIDTH;
}
m_ptScrollHorizPosL.x = m_topleft.x;
m_ptScrollHorizPosL.y = m_topleft.y+mySize.cy-SCROLL_BAR_WIDTH;
#ifndef _ARROWS_SIDE_BY_SIDE
m_ptScrollHorizPosR.x = m_topleft.x+mySize.cx-SCROLL_BAR_WIDTH;
#else
m_ptScrollHorizPosR.x = m_topleft.x+SCROLL_BAR_WIDTH;
#endif
m_ptScrollHorizPosR.y = m_topleft.y+mySize.cy-SCROLL_BAR_WIDTH;
Display* dis = (Display*)GetWindow()->display;
Pixel blackPixel = BlackPixel( dis, DefaultScreen(dis) );
Pixel greyPixel = blackPixel;
Colormap cmap = HXGetXColormap((Display*)GetWindow()->display,
(Window)GetWindow()->window);
XColor color;
XParseColor(dis, cmap, "gray", &color);
HXFindBestXColor(dis, cmap, &color);
greyPixel = color.pixel;
m_ScrollHorizButtonL = XCreateSimpleWindow( (Display*)GetWindow()->display,
(Window)pParentWindow->window,
m_ptScrollHorizPosL.x, m_ptScrollHorizPosL.y,
SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH,
1,
blackPixel,
greyPixel
);
m_ScrollHorizButtonR = XCreateSimpleWindow( (Display*)GetWindow()->display,
(Window)pParentWindow->window,
m_ptScrollHorizPosR.x, m_ptScrollHorizPosR.y,
SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH,
1,
blackPixel,
greyPixel
);
HX_ASSERT( m_ScrollHorizButtonR && m_ScrollHorizButtonL );
}
void CHXUnixSite::_CreateVertScrollBar()
{
HX_ASSERT( m_ScrollVertButtonB == 0 );
HX_ASSERT( m_ScrollVertButtonT == 0 );
HXxSize mySize;
HXxWindow* pParentWindow = NULL;
if(GetParentSite())
{
pParentWindow = GetParentSite()->GetWindow();
}
if(pParentWindow)
{
GetParentSite()->GetSize(mySize);
}
HX_ASSERT( pParentWindow );
HX_ASSERT( pParentWindow->window != 0 );
if( m_ScrollHorizButtonR )
{
// if the other bar already exists, don't overlap it!
mySize.cy -= SCROLL_BAR_WIDTH;
}
m_ptScrollVertPosT.x = m_topleft.x+mySize.cx-SCROLL_BAR_WIDTH;
m_ptScrollVertPosT.y = m_topleft.y;
m_ptScrollVertPosB.x = m_topleft.x+mySize.cx-SCROLL_BAR_WIDTH;
#ifndef _ARROWS_SIDE_BY_SIDE
m_ptScrollVertPosB.y = m_topleft.y+mySize.cy-SCROLL_BAR_WIDTH;
#else
m_ptScrollVertPosB.y = m_topleft.y+SCROLL_BAR_WIDTH;
#endif
Display* dis = (Display*)GetWindow()->display;
Pixel blackPixel = BlackPixel( dis, DefaultScreen(dis) );
Pixel greyPixel = blackPixel;
Colormap cmap = HXGetXColormap((Display*)GetWindow()->display,
(Window)GetWindow()->window);
XColor color;
XParseColor(dis, cmap, "gray", &color);
HXFindBestXColor(dis, cmap, &color);
greyPixel = color.pixel;
HX_ASSERT( GetWindow() );
m_ScrollVertButtonT = XCreateSimpleWindow( (Display*)GetWindow()->display,
(Window)pParentWindow->window,
m_ptScrollVertPosT.x, m_ptScrollVertPosT.y,
SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH,
1,
blackPixel,
greyPixel
);
m_ScrollVertButtonB = XCreateSimpleWindow( (Display*)GetWindow()->display,
(Window)pParentWindow->window,
m_ptScrollVertPosB.x, m_ptScrollVertPosB.y,
SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH,
1,
blackPixel,
greyPixel
);
HX_ASSERT( m_ScrollVertButtonB && m_ScrollVertButtonT );
}
//
// Inherited CHXBaseSite methods.
//
void CHXUnixSite::_NeedWindowedSite()
{
#ifdef _DEBUG
fprintf( stderr, "CHXUnixSite::_NeedWindowedSite do something here....\n" );
#endif
//Nothing to do on unix....
}
void CHXUnixSite::_AttachWindow()
{
void* pDummy=NULL;
if(!z_mapSiteToWindow.Lookup((void*)this, pDummy))
{
z_mapSiteToWindow.SetAt((void*)this, (void*)m_pWindow);
}
//Set the display variable.
if( m_pWindow->display == NULL )
{
HX_ASSERT(zm_display);
m_pWindow->display = zm_display;
}
//Now that we have a window be sure to init the CUnixRootSurf.
//this lets it set up the display, colormap, etc.
((CUnixRootSurf*)m_pRootSurface)->Init();
}
void CHXUnixSite::_DetachWindow()
{
//Nothing to do on unix....
}
void* CHXUnixSite::_Create(void* pParentWindow, UINT32 style)
{
HRESULT result = HXR_OK;
if( m_pWindow && m_pWindow->window )
{
HX_ASSERT( "We already have created a window"==NULL);
return NULL;
}
if (pParentWindow==NULL || style)
{
m_bIsChildWindow = FALSE;
}
else
{
m_bIsChildWindow = TRUE;
}
if( _OpenXDisplay(NULL) != HXR_OK )
{
return NULL;
}
return (void*)CreateXWindow((Window)pParentWindow);
}
void CHXUnixSite::_Destroy(HXxWindow* pWindow)
{
_DestroySliders();
XDestroyWindow( (Display*)pWindow->display, (Window)pWindow->window );
}
void CHXUnixSite::_SetSize(HXxSize size)
{
HX_ASSERT( m_pWindow && m_pWindow->display && m_pWindow->window);
//The scroll bars get resized also...
_DestroySliders();
XResizeWindow((Display*) m_pWindow->display,
(Window) m_pWindow->window,
size.cx,
size.cy);
}
void CHXUnixSite::_SetPosition(HXxPoint position)
{
HX_ASSERT( m_pWindow && m_pWindow->display && m_pWindow->window);
_DestroyScrollButtons();
XMoveWindow((Display*)m_pWindow->display,
(Window)m_pWindow->window,
position.x,
position.y);
}
void CHXUnixSite::_DamageRect(HXxRect rect)
{
if(GetWindow())
{
m_bDamaged = TRUE;
}
return;
}
void CHXUnixSite::_DamageRegion(HXxRegion rect)
{
if(GetWindow())
{
m_bDamaged = TRUE;
}
return;
}
void CHXUnixSite::_SendOSUpdateMessage()
{
//We need to redraw our window here, m_pWindow.
}
void CHXUnixSite::_ShowSite(BOOL bShow)
{
if( bShow )
{
_MapScrollButtons();
}
else
{
_UnmapScrollButtons();
}
//do nothing....
}
BOOL CHXUnixSite::_AtSystemTime()
{
return TRUE;
}
void CHXUnixSite::_GetDeviceCaps( void* hdc,
UINT16& uBitsPerPixel,
UINT16& uHorzRes,
UINT16& uVertRes )
{
Screen* pScreen = NULL;
HXxWindow* pWin = GetWindow();
HX_ASSERT( pWin );
if( pWin )
{
Display* dis = (Display*)pWin->display;
HX_ASSERT( dis );
if( dis )
{
pScreen = DefaultScreenOfDisplay((Display*)GetWindow()->display);
uBitsPerPixel = pScreen->root_depth;
uHorzRes = pScreen->width;
uVertRes = pScreen->height;
}
}
}
void CHXUnixSite::_GetWindowRect(HXxRect* destRect)
{
HX_ASSERT( "Doesn't seem to be used anywhere"==NULL );
}
void CHXUnixSite::_DestroySliders()
{
_DestroyScrollButtons();
}
void CHXUnixSite::_ForwardUpdateEvent(HXxEvent* pEvent)
{
GC gc = NULL;
AddRef();
HX_ASSERT(GetWindow()->window);
HX_ASSERT(m_pUser);
if(m_bIsChildWindow)
{
//Create a clip region that excludes our higher z-order
//siblings and is clipped to our parent.
if( !m_bRegionIsValid )
{
RecomputeClip();
}
// The problem is that regions are locked to the origin so we
// will need to reverse shift the region before we set the
// origin of the graph port! get the GC from the video surface
gc = ((CUnixRootSurf*)m_pRootSurface)->GetGC();
HX_ASSERT( gc );
//Actually setup our clip region
XSetRegion( (Display*)GetWindow()->display, gc, (Region) m_Region );
}
XEvent* pXEvent = (XEvent*) pEvent->param2;
XExposeEvent* exposeEvent = (XExposeEvent*) pXEvent;
// get the rect for this site with respect to our parent
HXRECTANGLE exposedRect = { exposeEvent->x,
exposeEvent->y,
exposeEvent->width,
exposeEvent->height };
HXREGION* exposedRegion = HXCreateRegion();
HXUnionRectWithRegion(&exposedRect, exposedRegion, exposedRegion);
// does the site intersect the current clipping region?
HXREGION* resultRegion = HXCreateRegion();
HXIntersectRegion(exposedRegion, m_Region, resultRegion);
BOOL bSiteIntersectsExposed = (HXEmptyRegion(resultRegion)==FALSE);
HXDestroyRegion(resultRegion);
HXDestroyRegion(exposedRegion);
// if the exposed region intersects the sites clipping region
if(bSiteIntersectsExposed)
{
m_pUser->HandleEvent(pEvent);
}
//If the user doesn't handle the standard update event then send
//them the cross platform HX_SURFACE_UPDATE event don't damage the
//original event structure
if(!pEvent->handled && m_pUser )
{
HX_ASSERT(GetWindow());
HXxEvent event;
event.event = HX_SURFACE_UPDATE;
event.window = GetWindow()->window;
event.param1 = m_pVideoSurface;
event.param2 = GetWindow();
event.result = 0;
event.handled = FALSE;
m_pUser->HandleEvent(&event);
pEvent->handled = event.handled;
}
//reset the gc to use no region
if(m_bIsChildWindow && gc)
{
XSetClipMask((Display*) GetWindow()->display, gc, None);
}
//Handle the drawing of our arrows...
_DrawArrows();
//Now do all our children....
CHXMapPtrToPtr::Iterator i = m_ChildrenMap.Begin();
for(;i!=m_ChildrenMap.End();++i)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -