📄 guicontrolbar.cpp
字号:
m_pDockSite->UnlockWindowUpdate();
}
else
CControlBar::OnLButtonDown(nFlags, point);
}
void CGuiControlBar::OnMouseMove( UINT nHitTest, CPoint point)
{
if(m_bTracking)
{
if (GetCapture() != this)
{
//StopTracking(FALSE);
m_bTracking=FALSE;
}
OnInvertTracker(m_rcBorder);
//nuevos tama駉s de la ventana
if (IsVert())
{
if (m_SideMove==HTLEFT || m_SideMove==HTRIGHT)
{
m_rcBorder.left=point.x;
m_rcBorder.right=m_rcBorder.left+4;
}
else
{
m_rcBorder.top=point.y+26;
m_rcBorder.bottom=m_rcBorder.top+4;
}
}
else
{
if (m_SideMove==HTBOTTOM || m_SideMove==HTTOP)
{
m_rcBorder.top=point.y+26;
m_rcBorder.bottom=m_rcBorder.top+4;
}
else
{
m_rcBorder.left=point.x;
m_rcBorder.right=m_rcBorder.left+4;
}
}
//--------------------------------------------------
//se hacen iguales todos los tama駉s
ClientToScreen(&point);
GetParentFrame()->ScreenToClient(&point);
m_ptActualPos=point;
OnInvertTracker(m_rcBorder);
//SetEqualWidth();
//-----------------------------------------------
}
}
//depende de la posicion se hace igual el tamanio del ancho o alto
void CGuiControlBar::SetEqualWidth()
{
int nFirstPos=GetFirstPos();
for (int nPos = nFirstPos; nPos <= m_Last; nPos++)
{
CGuiControlBar* pBar = GetGuiControlBar(nPos);
if (pBar== NULL) continue;
if (IsHorz())
pBar->m_sizeHorz.cy=m_sizeHorz.cy;//rcDockBar.Height();
else
pBar->m_sizeVert.cx=m_sizeVert.cx;
}
}
int CGuiControlBar::GetHiWid()
{
CRect rcWin;
rcWin=GetDockRect();
if (IsVert())
return rcWin.Height() ;
else
return rcWin.Width() ;
}
//espero que funcione el truco
//la idea es trabajar con coordenadas screen las dimensiones de los bordes del
//dockBar, mas no con los movimientos internos.
void CGuiControlBar::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CPoint ptTemp=point;
ClientToScreen(&ptTemp);
if (m_bTracking)
{
ReleaseCapture();
m_bTracking=FALSE;
OnInvertTracker(m_rcBorder);
m_pDockSite->UnlockWindowUpdate();
if (ptTemp ==m_ptStartPos) return;
if (IsVert())
{
if (m_SideMove==HTLEFT)
m_sizeVert.cx-=point.x;
else if(m_SideMove==HTRIGHT)
m_sizeVert.cx=point.x;
else if(m_SideMove==HTTOP)
AjustReDinSize(point);
}
else
{
if (m_SideMove==HTBOTTOM)
{
if (point.y < 0)
m_sizeHorz.cy+=abs(point.y);
else
m_sizeHorz.cy=point.y;
}
else if (m_SideMove==HTTOP)
{
if (point.y < 0)
m_sizeHorz.cy+=abs(point.y)-12;
else
m_sizeHorz.cy-=abs(point.y)+12;
}
else if (m_SideMove==HTRIGHT)
AjustReDinSize(point);
}
SetEqualWidth();
}
m_pDockSite->DelayRecalcLayout();
}
//ajusta las ventanas a redimencionarlas verticalmente
//se decrementa las anteriores ventanas a la actual y se
//incrementan las posteriores.
void CGuiControlBar::AjustReDinSize(CPoint point)
{
int nFirstPos=GetFirstPos();
int nLastPos=GetLastPos();
int m_ThisPos=m_pDockBar->FindBar(this);
ClientToScreen(&point);
//si la diferencia es negativa esta barra crece la anterior a esta disminuye
int nDif=0;
BOOL bGrow=FALSE;
if (IsVert())
{
nDif=m_ptStartPos.y- point.y;
if (nDif > 0)
bGrow=TRUE;
if (bGrow)
m_sizeVert.cy+=abs(nDif)+4;
else
m_sizeVert.cy-=abs(nDif);
if (nFirstPos == m_ThisPos)
return;
}
else
{
nDif=m_ptStartPos.x- point.x;
if (nDif < 0)
bGrow=TRUE;
if (bGrow)
m_sizeHorz.cx+=abs(nDif);
else
m_sizeHorz.cx-=abs(nDif);
if (nLastPos == m_ThisPos)
return;
}
if (IsVert())
AjustVert(bGrow,nDif);
else
AjustHorz(bGrow,nDif);
RecalWindowPos();
}
void CGuiControlBar::AjustVert(BOOL bGrow,int nDif)
{
int nFirstPos=GetFirstPos();
int nLastPos=GetLastPos();
int m_ThisPos=m_pDockBar->FindBar(this);
if(m_SideMove==HTTOP)
{
//Esta ventana crece las anteriores reducen su tama駉
if (bGrow)
{
for (int i=m_ThisPos-1; i > 0; i--)
{
CGuiControlBar* pBar = GetGuiControlBar(i);
if (pBar== NULL) return;
if(IsVert())
{
if (pBar->m_sizeVert.cy-abs(nDif) < pBar->m_sizeMinV.cy)
{
pBar->m_sizeVert.cy=pBar->m_sizeMinV.cy;
continue;
}
else
{
pBar->m_sizeVert.cy-=abs(nDif);
break;
}
}
}//for
}//bGrow
else //este disminuye la anterior crece
{
if (m_ThisPos-1 > 0)
{
CGuiControlBar* pBar = GetGuiControlBar(m_ThisPos-1);
if (pBar== NULL) return;
pBar->m_sizeVert.cy+=abs(nDif);
if(m_sizeVert.cy > m_sizeMinV.cy)
return;
else
pBar->m_sizeVert.cy-=m_sizeMinV.cy;
}
for (int i=m_ThisPos+1; i >= m_Last; i++)
{
CGuiControlBar* pBar = GetGuiControlBar(i);
if (pBar== NULL) return;
if(IsVert())
{
if (pBar->m_sizeVert.cy-abs(nDif) < pBar->m_sizeMinV.cy)
continue;
else
{
pBar->m_sizeVert.cy-=abs(nDif);
return;
}
}
}//for
}
}
}
void CGuiControlBar::AjustHorz(BOOL bGrow,int nDif)
{
int nFirstPos=GetFirstPos();
int nLastPos=GetLastPos();
int m_ThisPos=m_pDockBar->FindBar(this);
if(m_SideMove==HTRIGHT)
{
//Esta ventana crece las anteriores reducen su tama駉
if (bGrow)
{
for (int i=m_ThisPos+1; i <= nLastPos; i++)
{
CGuiControlBar* pBar = GetGuiControlBar(i);
if (pBar== NULL) return;
if(IsHorz())
{
if (pBar->m_sizeHorz.cx-abs(nDif) < pBar->m_sizeMinH.cx)
{
pBar->m_sizeHorz.cx=pBar->m_sizeMinH.cx;
continue;
}
else
{
pBar->m_sizeHorz.cx-=abs(nDif);
break;
}
}
}//for
}//bGrow
else //este disminuye la anterior crece
{
if (m_ThisPos+1 <= m_Last)
{
CGuiControlBar* pBar = GetGuiControlBar(m_ThisPos+1);
if (pBar== NULL) return;
pBar->m_sizeHorz.cx+=abs(nDif);
if(m_sizeHorz.cx > m_sizeMinH.cx)
return;
else
pBar->m_sizeHorz.cx+=abs(nDif);
}
for (int i=m_ThisPos-1; i >0; i--)
{
CGuiControlBar* pBar = GetGuiControlBar(i);
if (pBar== NULL) return;
if(IsHorz())
{
if (pBar->m_sizeHorz.cx-abs(nDif) < pBar->m_sizeMinH.cx)
continue;
else
{
pBar->m_sizeHorz.cx-=abs(nDif);
return;
}
}
}//for
}
}
}
//----------------------------------------------------
//OnActiveWindow retira o asigna el foco a la ventana
void CGuiControlBar::OnActiveWindow()
{
POSITION pos = m_pDockSite->m_listControlBars.GetHeadPosition();
while (pos != NULL)
{
CDockBar* pDockBar = (CDockBar*)m_pDockSite->m_listControlBars.GetNext(pos);
if (pDockBar->IsDockBar() && pDockBar->IsWindowVisible() &&
(!pDockBar->m_bFloating ))
{
int nNumBars=(int)pDockBar->m_arrBars.GetSize();
for(int i=0; i< nNumBars;i++)
{
CGuiControlBar* pBar = (CGuiControlBar*) pDockBar->m_arrBars[i];
if (HIWORD(pBar) == NULL) continue;
if (!pBar->IsVisible()) continue;
if (!pBar->IsKindOf(RUNTIME_CLASS(CGuiControlBar))) continue;
if (pBar != this)
{
pBar->m_bOldActive=FALSE;
pBar->m_bActive=FALSE;
pBar->m_bForcepaint=TRUE;
pBar->SendMessage(WM_NCPAINT);
pBar->m_bForcepaint=FALSE;
}
else
{
m_bOldActive=m_bActive;
m_bActive=TRUE;
m_bForcepaint=TRUE;
SendMessage(WM_NCPAINT);
m_bForcepaint=FALSE;
}
}
}
}
}
void CGuiControlBar::ActiveCaption()
{
CWnd* pFocus=SetFocus();
if(pFocus->GetSafeHwnd())
IsChild(pFocus);
m_bForcepaint=TRUE;
OnActiveWindow();
m_bForcepaint=FALSE;
}
void CGuiControlBar::OnNcRButtonDown(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bTracking /*|| IsFloating()*/)
return;
// ScreenToScreen (&point);
CMenu m_menu;
if (m_MenuContext!=NULL)
{
m_menu.LoadMenu(m_MenuContext);
CMenu* m_SubMenu = m_menu.GetSubMenu(0);
m_SubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
point.x, point.y-2, AfxGetMainWnd());
Invalidate();
UpdateWindow();
}
CWnd::OnNcLButtonDown(nHitTest, point);
}
void CGuiControlBar::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bTracking /*|| IsFloating()*/)
return;
m_ptStartPos=point;
if( nHitTest == HTCAPTION || nHitTest == HTCLOSE)
ActiveCaption();
//---------para el boton----
if( nHitTest == HTCLOSE)
{
m_stateBtn=PRESS;
SendMessage(WM_NCPAINT);
SetTimer(1,100,0);
return;
}
//--------------------------
if (m_pDockBar != NULL)
{
if (HTCAPTION == nHitTest)
{
m_pDockContext->StartDrag(point);
m_sizeHorzt=m_sizeHorz;
m_sizeVertt=m_sizeVert;
}
if(!m_bTracking)
{
if(m_rcBorder.PtInRect(point))
{
m_pDockSite->LockWindowUpdate();
OnInvertTracker(m_rcBorder);
m_ptStartPos=point;
SetCapture();
SetFocus();
m_bTracking=TRUE;
m_sizeHorzt=m_sizeHorz;
m_sizeVertt=m_sizeVert;
}
}
}
//other bug fixed
// CWnd::OnNcLButtonDown(nHitTest, point);
}
void CGuiControlBar::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rc;
//------------------ para el boton
CRect rcT=m_rcCloseBtn;
ClientToScreen(rcT);
point.y+=23;
point.x+=5;
if (rcT.PtInRect(point))
{
if (m_stateBtn ==PRESS)
{
m_stateBtn=NORMAL;
KillTimer(1);
GetDockingFrame()->ShowControlBar(this, FALSE, FALSE);
}
//SendMessage(WM_NCPAINT);
m_pDockSite->DelayRecalcLayout();
return;
}
//-------------------para el boton
m_pDockSite->DelayRecalcLayout();
}
void CGuiControlBar::OnNcPaint()
{
// TODO: Add your message handler code here
// Do not call CControlBar::OnNcPaint() for painting messages
// Tomo la misma rutina que se desarrolla para la clase
// CGuiToolBarWnd.
CRect rcWindow;
CRect rcClient;
CWindowDC dc(this);
CDC m_dc; //contexto de dispositivo en memoria
CBitmap m_bitmap;
//la idea es tomar el area de la ventana y area cliente , luego debemos
//igualar el area de coordenadas de ventana al cliente
GetWindowRect(&rcWindow);
GetClientRect(&rcClient);
ScreenToClient(rcWindow);
rcClient.OffsetRect(-rcWindow.TopLeft());
rcWindow.OffsetRect(-rcWindow.TopLeft());
m_dc.CreateCompatibleDC(&dc);
m_bitmap.CreateCompatibleBitmap(&dc,rcWindow.Width(),rcWindow.Height());
CBitmap *m_OldBitmap=m_dc.SelectObject(&m_bitmap);
//aqui debe utilizarse la brocha que define GuiDrawLayer, si no hacemos la siguiente
//linea usted vera un horrible color negro, a cambio del dibujo.
CBrush cb;
cb.CreateSolidBrush(m_clrFondo);
m_dc.FillRect(rcWindow, &cb);
DrawGripper(&m_dc,&rcWindow);
dc.IntersectClipRect(rcWindow);
dc.ExcludeClipRect(rcClient);//asi evitamos el parpadeo
dc.BitBlt(rcWindow.left,rcWindow.top,rcWindow.Width(),rcWindow.Height(),&m_dc,0,0,SRCCOPY);
ReleaseDC(&dc);
m_dc.SelectObject(m_OldBitmap);
m_bitmap.DeleteObject();
m_dc.DeleteDC();
}
void CGuiControlBar::DrawGripper(CDC* pDC,CRect* rc)
{
CRect gripper = rc;
gripper.top =3;
gripper.left+=4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -