⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listboxex.cpp

📁 用bcg库编写的java IDE 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//                notification message that applies to this window.
//
// PARAMETER(S):
//                nMessage:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Message identifier
//
//                wParam:
//                   TYPE:          WPARAM
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Message wParam
//
//                lParam:
//                   TYPE:          LPARAM
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Message lParam
//
//                pLResult:
//                   TYPE:          LRESULT
//                   MODE:          In
//                   MECHANISM:     By variable
//                   DESCRIPTION:   A pointer to a value to be returned from 
//                                  the parent抯 window procedure. 
//
// RETURN:        None.
//
// NOTES:         Copied from the MFC implementation, with some changes regarding the
//                editing improvement.
//+*/
BOOL CListBoxEx::OnChildNotify( UINT     nMessage, 
                                WPARAM   wParam, 
                                LPARAM   lParam, 
                                LRESULT *pLResult )
{
   if ( nMessage == g_DragListMsg )
   {
      ASSERT( pLResult != NULL );
      if ( m_iEdited == -1 && m_bAllowDrag )
      {
         LPDRAGLISTINFO pInfo = (LPDRAGLISTINFO)lParam;
         ASSERT( pInfo != NULL );
         switch ( pInfo->uNotification )
         {
            case DL_BEGINDRAG:
               TRACE( "Begin Dragging\n" );
               // Removed from the MFC implementation
               //*pLResult = BeginDrag(pInfo->ptCursor);
               *pLResult = TRUE;
               m_bAddedNullString = TRUE;
               AddString("");   // add an empty string at the end
               break;

            case DL_CANCELDRAG:
               TRACE( "Cancel Drag\n" );
               CancelDrag( pInfo->ptCursor );
               if( m_bAddedNullString ) {
                    m_bAddedNullString = FALSE;
                    DeleteString(GetCount()-1);
               }
               break;

            case DL_DRAGGING:
               TRACE( "Dragging\n" );
               *pLResult = Dragging( pInfo->ptCursor );
               break;

            case DL_DROPPED:
               TRACE( "Dropped\n" );
               Dropped( GetCurSel(), pInfo->ptCursor );
               if( m_bAddedNullString ) {
                    m_bAddedNullString = FALSE;
                    DeleteString(GetCount()-1);
               }
               break;
         }
      }
      else
      {
         *pLResult = FALSE;
      }

      return TRUE;  // Message handled
   }

   return CListBox::OnChildNotify( nMessage, wParam, lParam, pLResult );
   
} // CListBoxEx::OnChildNotify


///*-
// FUNCTION NAME: CListBoxEx::OnKeyDown
//
// DESCRIPTION:   Called when it receives a WM_KEYDOWN message.
//
// PARAMETER(S):
//                nChar:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Character identifier
//
//                nRepCnt:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Repetition count
//
//                nFlags:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Flags
//
// RETURN:        None.
//
// NOTES:         None.
//+*/
void CListBoxEx::OnKeyDown( UINT nChar, 
                            UINT nRepCnt, 
                            UINT nFlags )
{
   CDragListBox::OnKeyDown( nChar, nRepCnt, nFlags );

   if ( (nChar == VK_F2)    &&
        (m_iSelected != -1) &&
        m_bAllowEditing     &&
        (OnBeginEditing( m_iSelected ) != FALSE) )
   {
      // Begin Editing
      BeginEditing( m_iSelected );
   }
   else
   if( nChar == VK_DELETE )
   {
      DeleteSelected();
   }
   else
   if( nChar == VK_INSERT )
   {
      EditNew();
   }
   
} // CListBoxEx::OnKeyDown


///*-
// FUNCTION NAME: CListBoxEx::OnSysKeyDown
//
// DESCRIPTION:   Called when it receives a WM_SYSKEYDOWN message.
//
// PARAMETER(S):
//                nChar:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Character identifier
//
//                nRepCnt:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Repetition count
//
//                nFlags:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Flags
//
// RETURN:        None.
//
// NOTES:         None.
//+*/
void CListBoxEx::OnSysKeyDown( UINT nChar, 
                               UINT nRepCnt, 
                               UINT nFlags )
{
   if ( ALT_KEY_PRESSED( nFlags ) &&
        m_bAllowDrag )
   {
      switch ( nChar )
      {
         case VK_UP:
         case VK_LEFT:

            MoveItemUp( GetCurSel() );
            break;

         case VK_DOWN:
         case VK_RIGHT:

            MoveItemDown( GetCurSel() );
            break;
      }
   }

   CDragListBox::OnSysKeyDown( nChar, nRepCnt, nFlags );
} // CListBoxEx::OnSysKeyDown


///*-
// FUNCTION NAME: CListBoxEx::OnLButtonDown
//
// DESCRIPTION:   Called when it receives a WM_LBUTTONDOWN message.
//
// PARAMETER(S):
//                nFlags:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Flags
//
//                point:
//                   TYPE:          CPoint class
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Point of action
//
// RETURN:        None.
//
// NOTES:         None.
//+*/
void CListBoxEx::OnLButtonDown( UINT   nFlags, 
                                CPoint point )
{
   int     iItem;
   
   ClientToScreen( &point );
   iItem = ItemFromPt( point, FALSE );
   TRACE1( "LButtonDown: %d\n", iItem );

   if ( iItem != -1 )
   {
      if ( m_iSelected != iItem )
      {
         // Update info
         m_iSelected = iItem;
      }
   }

   CDragListBox::OnLButtonDown( nFlags, point );
} // CListBoxEx::OnLButtonDown


///*-
// FUNCTION NAME: CListBoxEx::OnLButtonDblClk
//
// DESCRIPTION:   Called when it receives a WM_LBUTTONDBLCLICK message.
//
// PARAMETER(S):
//                nFlags:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Flags
//
//                point:
//                   TYPE:          CPoint class
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Point of action
//
// RETURN:        None.
//
// NOTES:         None.
//+*/
void CListBoxEx::OnLButtonDblClk( UINT   nFlags, 
                                  CPoint point )
{
   CDragListBox::OnLButtonDblClk( nFlags, point );

   if ( m_bAllowEditing )
   {
      int     iItem;
   
      ClientToScreen( &point );
      iItem = ItemFromPt( point, FALSE );
      TRACE1( "LButtonDblClk: %d\n", iItem );

      if ( (iItem != -1)      && 
           m_bAllowEditing    &&
           (OnBeginEditing( iItem ) != FALSE) )
      {
         // Begin Editing
         BeginEditing( iItem );
      }
   }
} // CListBoxEx::OnLButtonDblClk


///*-
// FUNCTION NAME: CListBoxEx::OnLButtonUp
//
// DESCRIPTION:   Called when it receives a WM_LBUTTONUP message.
//
// PARAMETER(S):
//                nFlags:
//                   TYPE:          unsigned int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Flags
//
//                point:
//                   TYPE:          CPoint class
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Point of action
//
// RETURN:        None.
//
// NOTES:         None.
//+*/
void CListBoxEx::OnLButtonUp( UINT   nFlags, 
                              CPoint point )
{
   CDragListBox::OnLButtonUp( nFlags, point );
} // CListBoxEx::OnLButtonUp



               ///////////////////////////////////////////////
               //               Overridables                //
               ///////////////////////////////////////////////



///*-
// FUNCTION NAME: CListBoxEx::OnBeginEditing
//
// DESCRIPTION:   Called when the item editing phase has been started.
//
// PARAMETER(S):
//                iItem:
//                   TYPE:          int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Zero-based index of the item.
//
// RETURN:        TRUE if the editing action can be performed. FALSE otherwise.
//
// NOTES:         None.
//+*/
BOOL CListBoxEx::OnBeginEditing( int iItem )
{
   UNUSED_ALWAYS( iItem );
   return TRUE;
} // CListBoxEx::OnBeginEditing


///*-
// FUNCTION NAME: CListBoxEx::OnEndEditing
//
// DESCRIPTION:   Called when the item editing phase has ended.
//
// PARAMETER(S):
//                iItem:
//                   TYPE:          int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Zero-based index of the item.
//
//                fCancel:
//                   TYPE:          int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   If the editing was canceled, this parameter is 
//                                  TRUE. Otherwise, it is FALSE.
//
// RETURN:        TRUE to set the item's label to the edited text. 
//                Return FALSE to reject the edited text and revert to 
//                the original label.
//
// NOTES:         None.
//+*/
BOOL CListBoxEx::OnEndEditing( int  iItem,
                               BOOL fCanceled )
{
   UNUSED_ALWAYS( iItem );
   UNUSED_ALWAYS( fCanceled );

   return TRUE;
} // CListBoxEx::OnEndEditing


///*-
// FUNCTION NAME: CListBoxEx::OnBrowseButton
//
// DESCRIPTION:   Called when the browse button on the item is pressed.
//
// PARAMETER(S):
//                iItem:
//                   TYPE:          int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Zero-based index of the item.
//
// RETURN:        None.
//
// NOTES:         None.
//+*/
void CListBoxEx::OnBrowseButton( int iItem )
{
   UNUSED_ALWAYS( iItem );
} // CListBoxEx::OnMoreButtonPressed



               ///////////////////////////////////////////////
               //             Public functions              //
               ///////////////////////////////////////////////



///*-
// FUNCTION NAME: CListBoxEx::BeginEditing
//
// DESCRIPTION:   Set the edit style
//
// PARAMETER(S):
//                iItem:
//                   TYPE:          int
//                   MODE:          In
//                   MECHANISM:     By value
//                   DESCRIPTION:   Item index. If -1, editing is for the currently
//                                  selected item.
//
// RETURN:        None.
//
// NOTES:         This method does not call the OnBeginEditing function.
//+*/
void CListBoxEx::BeginEditing( int iItem )
{
   if ( m_bAllowEditing &&
       (m_iEdited == -1) )
   {
      if ( iItem == -1 )
      {
         iItem = m_iSelected;
      }
      else
      if ( iItem > GetCount()-1 ) 
      {
         iItem = GetCount();
         AddString( "" );
      }

      // Make it the current selection
      SetCurSel( iItem );
      m_iSelected = iItem;

      // Save item index
      m_iEdited = iItem;

      // Retrieve item text
      CString strItemText;
      GetText( iItem, strItemText );

      // Cache edit/button rectangles
      GetItemRect( iItem, m_rcEdit );
      m_rcButton.CopyRect( m_rcEdit );

      // Adjust for the edit and the button
      m_rcEdit.left += 5;
      if ( m_dwEditStyle & LBEX_EDITBUTTON )
      {
         m_rcEdit.right -= 30;
      }
      else
      {
         m_rcEdit.right -= 5;
      }
      m_rcEdit.InflateRect( 0, 2 );

      // Initialize the edit control with the item text
      m_pEdit->SetWindowText( strItemText );

      // Show the edit control
      m_pEdit->Show( m_rcEdit );

      if ( m_dwEditStyle & LBEX_EDITBUTTON )
      {
         m_rcButton.left = m_rcEdit.right;
         m_rcButton.right -= 5;
         m_rcButton.InflateRect( 0, 2 );
         m_pBrowseButton->Show( m_rcButton );
      }
   }
} // CListBoxEx::BeginEditing()s


///*-
// FUNCTION NAME: CListBoxEx::EditNew

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -