/*========================================================================= * CPAPopTB : Implementation of PopUpToolBar. * This is a part of the PCA project. * * Version 1.0 * Creation date 26/06/96 * Revision date * * * (c) Ubi Studios 1996 *=======================================================================*/ #include "stdafx.h" #ifdef ACTIVE_EDITOR #include "acp_base.h" #include "geo.h" #include "gli.h" #include "itf/CPAPopTB.hpp" #include "itf/DEVMulti.hpp" #include "itf/DEVViewp.hpp" #include "itf/CPAProj.hpp" BOOL g_bMouseLocked = FALSE; ///////////////////////////////////////////////////////////////////////////// // CPA_PopUpToolBar CPA_PopUpToolBar::CPA_PopUpToolBar() { m_bMousePickedButton = FALSE; m_lNbButtonsTotal = 0; m_lNbFamilies = 0; m_bCurrentButtonAlone = FALSE; m_bDefined = FALSE; m_bJustPressed = FALSE; m_bAllreadyCreated = FALSE; } CPA_PopUpToolBar::~CPA_PopUpToolBar() { } // copy constructor : the toolbar is built and defines, but not created CPA_PopUpToolBar::CPA_PopUpToolBar(CPA_PopUpToolBar &r_src) { long k; m_bMousePickedButton = FALSE; m_bCurrentButtonAlone = FALSE; m_bJustPressed = FALSE; m_lNbButtonsTotal = r_src.m_lNbButtonsTotal; m_lIdResource = r_src.m_lIdResource; m_lIdEndFamily = r_src.m_lIdEndFamily; m_lButtonSizeX = r_src.m_lButtonSizeX; m_lButtonSizeY = r_src.m_lButtonSizeY; m_lIdCurrentButton = r_src.m_lIdCurrentButton; m_lNbFamilies = r_src.m_lNbFamilies; for (k=0; kszText,m_a_stButtons[lButtonIndex].szTipText); return TRUE; } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// // tells the toolbarcontrol how many buttons there are, and draw the visible ones. long CPA_PopUpToolBar::CreateToolBarCtrl(CWnd *p_WndParent, CPoint org) { TBBUTTON a_stTBBut[C_MAX_POPUPTOOLBAR_FAMILY]; long iBitmap; long i; Create(CCS_NODIVIDER | CBRS_TOOLTIPS| TBSTYLE_TOOLTIPS | WS_CLIPSIBLINGS | WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC, CRect(org.x,org.y,20,50), p_WndParent, m_lIdResource); SetButtonSize(CSize(m_lButtonSizeX,m_lButtonSizeY)); SetBitmapSize(CSize(m_lButtonSizeX,m_lButtonSizeY)); iBitmap = AddBitmap(m_lNbButtonsTotal, m_lIdResource); // sets buttons bitmaps for (i = 0; i < m_lNbButtonsTotal; i++) m_a_stButtons[i].lIndexBitmap = i + iBitmap; if (!m_bAllreadyCreated) { // sets buttons initial state for ( i = 0; i < m_lNbFamilies; i++) m_a_lButtonsInTBIndex[i] = GetIndex(m_a_lInitialStates[i]); // sets buttons initial permissions for (i = 0; i < m_lNbButtonsTotal; i++) m_a_stButtons[i].bPermit = m_a_bInitialPermissions[i]; } m_bAllreadyCreated = TRUE; // add buttons for ( i = 0; i < m_lNbFamilies; i++) { if (IsStandAlone(m_a_stButtons[m_a_lButtonsInTBIndex[i]].lId)) ASSERT(m_a_stButtons[m_a_lButtonsInTBIndex[i]].bPermit); ASSERT(IsAMode(m_a_stButtons[m_a_lButtonsInTBIndex[i]].lId)); a_stTBBut[i].fsState = (m_a_stButtons[m_a_lButtonsInTBIndex[i]].bPermit)? TBSTATE_ENABLED : TBSTATE_INDETERMINATE ; // button state a_stTBBut[i].fsStyle = TBSTYLE_BUTTON; // button style--see below a_stTBBut[i].dwData = NULL; // application-defined value a_stTBBut[i].iString = NULL; // zero-based index of button label string a_stTBBut[i].iBitmap = m_a_stButtons[m_a_lButtonsInTBIndex[i]].lIndexBitmap; a_stTBBut[i].idCommand = m_a_lInitialStates[i]; } AddButtons( m_lNbFamilies, a_stTBBut ); RECT stButtonRect; GetItemRect(0,&stButtonRect); MoveWindow ( org.x, org.y, (stButtonRect.right - stButtonRect.left + 1) * m_lNbFamilies, (stButtonRect.bottom - stButtonRect.top + 2) ); return 0; } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// // returns the family number of the given button; // return -1 if button couldn't be found // the family number is also the zero-based position of the button in the toolbar long CPA_PopUpToolBar::GetFamily(long lIdButton) { long i,lfamily; ASSERT (lIdButton != m_lIdEndFamily); lfamily = 0; for (i=0; i=0) && (lFamily < m_lNbFamilies)); lNbButtons = 0; lFamilyIndex = m_a_lFamiliesIndex[lFamily]; while(m_a_stButtons[lFamilyIndex++].lId != m_lIdEndFamily) lNbButtons++; ASSERT(lNbButtons != 0); return lNbButtons; } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// // choose, in the given family, an available button that is different // from the given one. long CPA_PopUpToolBar::GetOtherAvailableButtonInFamily(long lIdButton, BOOL a_bPermissions[], long lFamily) { UINT i; int k; // get teh family of the button if (lFamily == -1) { lFamily = GetFamily(lIdButton); } ASSERT(lFamily != -1); // let's see if the initial button of the family suits if (a_bPermissions == NULL) { if ((m_a_lInitialStates[lFamily] != lIdButton) && (m_a_stButtons[GetIndex(m_a_lInitialStates[lFamily])].bPermit) && (m_a_stButtons[GetIndex(m_a_lInitialStates[lFamily])].bIsAMode)) return m_a_lInitialStates[lFamily]; } else { if ((m_a_lInitialStates[lFamily] != lIdButton) && (a_bPermissions[GetIndex(m_a_lInitialStates[lFamily])]) && (m_a_stButtons[GetIndex(m_a_lInitialStates[lFamily])].bIsAMode)) return m_a_lInitialStates[lFamily]; } // get the index of the family k = m_a_lFamiliesIndex[lFamily]; // k is the index of the first button of the family for ( i = k; i < (unsigned int) m_lNbButtonsTotal; i++) // scan all buttons of the family { if (m_a_stButtons[i].lId == m_lIdEndFamily) return -1; // couldn't find a button if (a_bPermissions == NULL) { if ((m_a_stButtons[i].lId != lIdButton) && (m_a_stButtons[i].bPermit) && (m_a_stButtons[i].bIsAMode)) return m_a_stButtons[i].lId; } else { if ((m_a_stButtons[i].lId != lIdButton) && (a_bPermissions[i]) && (m_a_stButtons[i].bIsAMode)) return m_a_stButtons[i].lId; } } return -1; } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// // fill in the toolbar buttons with all datas int CPA_PopUpToolBar::Define(tdstButtonDef a_stButtonDef[], long lNbButtons, long lIdResource, long lIdEndFamily, long lSizeX, long lSizeY) { long k; ASSERT((lNbButtons > 0) && (lNbButtons <= C_MAX_POPUPTOOLBAR_BUTTONS)); m_lNbButtonsTotal = lNbButtons; m_lIdResource = lIdResource; m_lIdEndFamily = lIdEndFamily; m_lButtonSizeX = lSizeX; m_lButtonSizeY = lSizeY; // fills in the button array, and // Count the number of Families // a family of buttons is registered if the last button has // the m_lIdEndFamily ID !!!! m_lNbFamilies = 0; m_a_lFamiliesIndex[0] = 0; // the first family begins at button 0; for (k = 0; k < m_lNbButtonsTotal; k++) { m_a_stButtons[k].lId = a_stButtonDef[k].lId; m_a_stButtons[k].bPermit = (a_stButtonDef[k].lId != m_lIdEndFamily); m_a_bInitialPermissions[k] = (a_stButtonDef[k].lId != m_lIdEndFamily); m_a_stButtons[k].bVisible = TRUE; m_a_stButtons[k].bIsAMode = a_stButtonDef[k].bIsAMode; strcpy(m_a_stButtons[k].szTipText,a_stButtonDef[k].szTip); if (m_a_stButtons[k].lId == m_lIdEndFamily) { ASSERT(m_lNbFamilies < C_MAX_POPUPTOOLBAR_FAMILY-1); // separator => one more family m_lNbFamilies++; m_a_lFamiliesIndex[m_lNbFamilies] = k+1; } } // init : now, sets which buttons are to be displayed : the first one of // each family for (k=0; k 1) ; m_oWndButton.CreateWndButton(this, lx, ly, a_stButtonsFamily, lNbButtonsFamily, lIndexInTB, m_lNbButtonsTotal, m_lIdResource); } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // CPA_PopUpToolBar message handlers ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// void CPA_PopUpToolBar::OnLButtonDown(UINT nFlags, CPoint oPoint) { int i; BOOL b; CToolBarCtrl::OnLButtonDown(nFlags, oPoint); m_lIdCurrentButton = -1; for (i = 0; i < m_lNbFamilies; i++) { b = IsButtonPressed(m_a_stButtons[m_a_lButtonsInTBIndex[i]].lId); if ((b != 0) && (b != -1)) { m_lIdCurrentButton = m_a_stButtons[m_a_lButtonsInTBIndex[i]].lId; break; } } // here, i = the index of the pressed button in the toolbar if(m_lIdCurrentButton != -1) { PressButton(m_lIdCurrentButton, TRUE); m_bMousePickedButton = TRUE; if (GetNbButtonsTotalInFamily(i) == 1) { // we have only one button in this family... m_bCurrentButtonAlone = TRUE; } else { m_bCurrentButtonAlone = FALSE; OnButton(m_lIdCurrentButton, nFlags, i); } } m_bJustPressed = TRUE; } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// void CPA_PopUpToolBar::OnLButtonUp(UINT nFlags, CPoint oPoint) { BOOL bButtonPressed; if (m_bMousePickedButton) bButtonPressed = IsButtonPressed(m_lIdCurrentButton); if (m_bMousePickedButton) { if (m_bCurrentButtonAlone == TRUE) // case with no sub-toolbar { if (bButtonPressed) { m_bCurrentButtonAlone = FALSE; m_bMousePickedButton = FALSE; CToolBarCtrl::OnLButtonUp(nFlags, oPoint); return; } } else // case with sub-toolbar { long lIdChosenButton; m_bCurrentButtonAlone = FALSE; m_bMousePickedButton = FALSE; CToolBarCtrl::OnLButtonUp(nFlags, oPoint); PressButton(m_lIdCurrentButton,FALSE); lIdChosenButton = m_oWndButton.GetChosenButtonId(); if (lIdChosenButton != 0) { SetButton(lIdChosenButton); GetParent()->SendMessage(WM_COMMAND, lIdChosenButton); } } } else { CToolBarCtrl::OnLButtonUp(nFlags, oPoint); } } ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////// void CPA_PopUpToolBar::OnMouseMove(UINT nFlags, CPoint oPoint) { CToolBarCtrl::OnMouseMove(nFlags,oPoint); // for tooltips!!! } #endif // ACTIVE_EDITOR