Пример #1
0
// the update function
void TSRGuiFileBrowser::Update()
{
    m_bEntered = false;
    TSRGuiComponent::Update();
    m_VScrollBar.Update();
    m_HScrollBar.Update();

    if ( m_bIsUnderMouse )
    {
        // scrolling up
        if ( m_VScrollBar.m_ButtonA.m_bIsHolded )
        {
            m_VScrollBar.ScrollUp();
            Refresh();
        }

        // scrolling down
        if ( m_VScrollBar.m_ButtonB.m_bIsHolded )
        {
            m_VScrollBar.ScrollDown();
            Refresh();
        }

        // scrolling right
        if ( m_HScrollBar.m_ButtonB.m_bIsHolded )
        {
            m_HScrollBar.ScrollDown();
            Refresh();
        }

        // scrolling left
        if ( m_HScrollBar.m_ButtonA.m_bIsHolded )
        {
            m_HScrollBar.ScrollUp();
            Refresh();
        }

        // the Z of the mouse moves up and down too
        if ( Mouse()->m_DeltaZ )
        {
            if ( Mouse()->m_DeltaZ > 0 )
            {
                m_VScrollBar.ScrollUp();
            }
            else
            {
                m_VScrollBar.ScrollDown();
            }

            Refresh();
        }



        // updating the colors in case of being under mouse or not
        for ( unsigned int i = 0; i < m_DirectoryItems.size(); i++ )
        {
            TSRGuiStaticText* pCurrItem = m_DirectoryItems[ i ];
            pCurrItem->Update();

            if ( pCurrItem->m_bIsUnderMouse )
            {
                pCurrItem->m_TextColor = m_HotColor;
            }
            else
            {
                pCurrItem->m_TextColor = m_FolderColor;
            }
        }
        for ( unsigned int i = 0; i < m_FileItems.size(); i++ )
        {
            TSRGuiStaticText* pCurrItem = m_FileItems[ i ];
            pCurrItem->Update();

            if ( pCurrItem->m_bIsUnderMouse )
            {
                pCurrItem->m_TextColor = m_HotColor;
            }
            else
            {
                pCurrItem->m_TextColor = m_FileColor;
            }
        }

    }




    // only a double click can make something happens
    if ( IsDblClicked() )
    {
        // if a directory is double clicked
        for ( unsigned int i = 0; i < m_DirectoryItems.size(); i++ )
        {
            if ( m_DirectoryItems[ i ]->IsDblClicked() )
            {
                int indexOffset = m_VScrollBar.m_StartIndex;

                const char* newSubPath = m_FoldersNames[ i + indexOffset ].c_str();

                // if it . or .., change the path accordingly
                if ( newSubPath[ 0 ] == '.' )
                {
                    if ( newSubPath[ 1 ] == '.' )
                    {
                        UpOneLevel( m_Path );
                    }
                }
                // otherwise just append and move to a new path
                else
                {
                    sprintf( m_Path, "%s%s\\", m_Path,newSubPath );
                }
                SetPath( m_Path );
                return;
            }
        }



        //if a file is double clicked, entered becomes true and it becomes ready for reading for just one frame
        for ( unsigned int i = 0; i < m_FileItems.size(); i++ )
        {
            if ( m_FileItems[ i ]->IsDblClicked() )
            {
                unsigned int indexOffset = 0;
                if ( m_VScrollBar.m_StartIndex >= ( int ) m_FoldersNames.size() )
                {
                    indexOffset = ( int ) ( m_VScrollBar.m_StartIndex - m_FoldersNames.size() );
                }
                const char* newSubPath = m_FilesNames[ i + indexOffset ].c_str();
                sprintf( m_FileName, "%s%s", m_Path, newSubPath );
                m_bEntered = true;
                return;
            }
        }
    }
}
Пример #2
0
BOOL CTreeFileCtrl::PreTranslateMessage(MSG* pMsg) 
{
  // When an item is being edited make sure the edit control
  // receives certain important key strokes
  if (GetEditControl())
  {
    ::TranslateMessage(pMsg);
    ::DispatchMessage(pMsg);
    return TRUE; // DO NOT process further
  }

  //Context menu via the keyboard
	if ((((pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) && // If we hit a key and
    	(pMsg->wParam == VK_F10) && (GetKeyState(VK_SHIFT) & ~1)) != 0) ||   // it's Shift+F10 OR
		  (pMsg->message == WM_CONTEXTMENU))						                   	   // Natural keyboard key
	{
		CRect rect;
		GetItemRect(GetSelectedItem(), rect, TRUE);
		ClientToScreen(rect);
		OnContextMenu(NULL, rect.CenterPoint());
		return TRUE;
	}
  //Hitting the Escape key, Cancelling drag & drop
	else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE && IsDragging())
  {
    EndDragging(TRUE);
    return TRUE;
  }
  //Hitting the Alt-Enter key combination, show the properties sheet 
	else if (pMsg->message == WM_SYSKEYDOWN && pMsg->wParam == VK_RETURN)
  {
    OnFileProperties();
    return TRUE;
  }
  //Hitting the Enter key, open the item
	else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
  {
    OnFileOpen();
    return TRUE;
  }
  //Hitting the delete key, delete the item
  else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_DELETE)
  {
    OnFileDelete();
    return TRUE;
  }
  //hitting the backspace key, go to the parent folder
  else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_BACK)
  {
    UpOneLevel();
    return TRUE;
  }
  //hitting the F2 key, being in-place editing of an item
  else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F2)
  {
    OnFileRename();
    return TRUE;
  }
  //hitting the F5 key, force a refresh of the whole tree
  else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5)
  {
    OnViewRefresh();
    return TRUE;
  }

  //Let the parent class do its thing
	return CTreeCtrl::PreTranslateMessage(pMsg);
}