============================================================================= EditAlignText()
| 2736 | // EditAlignText() |
| 2737 | // |
| 2738 | void EditAlignText ( HWND hwnd, int nMode ) |
| 2739 | { |
| 2740 | #define BUFSIZE_ALIGN 1024 |
| 2741 | int mbcp; |
| 2742 | BOOL bModified = FALSE; |
| 2743 | int iSelStart = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 ); |
| 2744 | int iSelEnd = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ); |
| 2745 | int iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 ); |
| 2746 | int iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 ); |
| 2747 | if ( SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 ) == SC_CP_UTF8 ) { |
| 2748 | mbcp = CP_UTF8; |
| 2749 | } else { |
| 2750 | mbcp = CP_ACP; |
| 2751 | } |
| 2752 | if ( SC_SEL_RECTANGLE != SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) { |
| 2753 | int iLine; |
| 2754 | int iMinIndent = BUFSIZE_ALIGN; |
| 2755 | int iMaxLength = 0; |
| 2756 | int iLineStart = ( int ) SendMessage ( hwnd, SCI_LINEFROMPOSITION, ( WPARAM ) iSelStart, 0 ); |
| 2757 | int iLineEnd = ( int ) SendMessage ( hwnd, SCI_LINEFROMPOSITION, ( WPARAM ) iSelEnd, 0 ); |
| 2758 | if ( iSelEnd <= SendMessage ( hwnd, SCI_POSITIONFROMLINE, ( WPARAM ) iLineEnd, 0 ) ) { |
| 2759 | if ( iLineEnd - iLineStart >= 1 ) { |
| 2760 | iLineEnd--; |
| 2761 | } |
| 2762 | } |
| 2763 | for ( iLine = iLineStart; iLine <= iLineEnd; iLine++ ) { |
| 2764 | int iLineEndPos = ( int ) SendMessage ( hwnd, SCI_GETLINEENDPOSITION, ( WPARAM ) iLine, 0 ); |
| 2765 | int iLineIndentPos = ( int ) SendMessage ( hwnd, SCI_GETLINEINDENTPOSITION, ( WPARAM ) iLine, 0 ); |
| 2766 | if ( iLineIndentPos != iLineEndPos ) { |
| 2767 | int iIndentCol = ( int ) SendMessage ( hwnd, SCI_GETLINEINDENTATION, ( WPARAM ) iLine, 0 ); |
| 2768 | int iEndCol; |
| 2769 | char ch; |
| 2770 | int iTail; |
| 2771 | iTail = iLineEndPos - 1; |
| 2772 | ch = ( char ) SendMessage ( hwnd, SCI_GETCHARAT, ( WPARAM ) iTail, 0 ); |
| 2773 | while ( iTail >= iLineStart && ( ch == ' ' || ch == '\t' ) ) { |
| 2774 | iTail--; |
| 2775 | ch = ( char ) SendMessage ( hwnd, SCI_GETCHARAT, ( WPARAM ) iTail, 0 ); |
| 2776 | iLineEndPos--; |
| 2777 | } |
| 2778 | iEndCol = ( int ) SendMessage ( hwnd, SCI_GETCOLUMN, ( WPARAM ) iLineEndPos, 0 ); |
| 2779 | iMinIndent = min ( iMinIndent, iIndentCol ); |
| 2780 | iMaxLength = max ( iMaxLength, iEndCol ); |
| 2781 | } |
| 2782 | } |
| 2783 | if ( iMaxLength < BUFSIZE_ALIGN ) { |
| 2784 | for ( iLine = iLineStart; iLine <= iLineEnd; iLine++ ) { |
| 2785 | int iIndentPos = ( int ) SendMessage ( hwnd, SCI_GETLINEINDENTPOSITION, ( WPARAM ) iLine, 0 ); |
| 2786 | int iEndPos = ( int ) SendMessage ( hwnd, SCI_GETLINEENDPOSITION, ( WPARAM ) iLine, 0 ); |
| 2787 | if ( iIndentPos == iEndPos && iEndPos > 0 ) { |
| 2788 | if ( !bModified ) { |
| 2789 | SendMessage ( hwnd, SCI_BEGINUNDOACTION, 0, 0 ); |
| 2790 | bModified = TRUE; |
| 2791 | } |
| 2792 | SendMessage ( hwnd, SCI_SETTARGETSTART, ( WPARAM ) SendMessage ( hwnd, SCI_POSITIONFROMLINE, ( WPARAM ) iLine, 0 ), 0 ); |
| 2793 | SendMessage ( hwnd, SCI_SETTARGETEND, ( WPARAM ) iEndPos, 0 ); |
| 2794 | SendMessage ( hwnd, SCI_REPLACETARGET, 0, ( LPARAM ) "" ); |
| 2795 | } else { |