From: Amilcar A. Camargo on
Hi Everybody,

Some weeks ago there was a thread about using PathCompactPath to show
'compacted' paths in SLE. Today i share with all of you my class that allows to
edit the full text but, once entered, shows it in a 'compacted' way so the user
can understand what's inside.

[BEGIN PASTE]

CLASS SlePath INHERIT SingleLineEdit
// shows 'compacted' paths
//
// Author.......: Amilcar Camargo
// Date.........: 15-Jul-2007

METHOD Dispatch( oEv ) CLASS SIAAPSlePath
// Event handler, overrides where necessary
//
LOCAL uMsg := oEv:Message AS LONG
LOCAL wParam := oEv:wParam AS DWORD
LOCAL lParam := oEv:lParam AS LONG

DO CASE
CASE uMsg == WM_PAINT
IF GetFocus() <> SELF:Handle()
SELF:ExposeEx( oEv )
RETURN 0L
ENDIF

CASE uMsg == WM_ERASEBKGND
IF SELF:PaintBackground( PTR( _CAST, wParam ) )
SELF:EventReturnValue := 1L
RETURN 1L
ENDIF

ENDCASE

RETURN SUPER:Dispatch( oEv )

METHOD ExposeEx( uEvent ) CLASS SIAAPSlePath
// Paints out compacted path
//
LOCAL sPStru IS _winPAINTSTRUCT
LOCAL hDC AS PTR
LOCAL hWnd AS PTR
LOCAL iLen AS LONG
LOCAL iSaveDC AS INT
LOCAL pText AS PTR
LOCAL hFont AS PTR
LOCAL dwColor AS DWORD
LOCAL sRect IS _winRECT

hWnd := SELF:Handle()

// Check if there is a need to repaint
IF GetUpdateRect( hWnd, NULL_PTR, FALSE )

hDC := BeginPaint( hWnd, @sPStru )
IF hDC <> NULL_PTR

// save dc status
iSaveDC := SaveDC( hWnd )

// our area
GetClientRect( hWnd, @sRect )

// Erase background
IF sPStru.fErase
SendMessage( hWnd, WM_ERASEBKGND, DWORD( _CAST,hDC ), 0L )
ENDIF

// Is there something to display
iLen := SendMessage( hWnd, WM_GETTEXTLENGTH, 0, 0L )
IF iLen > 0
pText := MemAlloc( MAX_PATH )
IF pText <> NULL_PTR
// Get foreground color
IF SELF:TextColor <> NULL_OBJECT
dwColor := SELF:TextColor:ColorRef
ELSE
dwColor := GetSysColor( COLOR_WINDOWTEXT )
ENDIF

// Get text font
// Use <oFont> to avoid creating a default font
IF SELF:oFont <> NULL_OBJECT
hFont := SELF:oFont:Handle()
ELSE
hFont := GetStockObject( DEFAULT_GUI_FONT )
ENDIF

MemClear( pText, MAX_PATH )
SendMessage( hWnd, ;
WM_GETTEXT, ;
MAX_PATH, ;
LONG(_CAST, ;
pText ) )
SetTextColor( hDC, dwColor )
SelectObject( hDC, hFont )
PathCompactPath( hDC, pText, sRect.right - sRect.left - 2 )
TextOut( hDC, 0, 1, pText, LONG( _CAST, PszLen( pText ) ) )
MemFree( pText )
ENDIF
ENDIF

// Restore DC
RestoreDC( hWnd, iSaveDC )

ENDIF

// close painting cicle
EndPaint( hWnd, @sPStru )
SELF:EventReturnValue := 1L
ENDIF

RETURN NIL

METHOD PaintBackground( uDC ) CLASS SIAAPSlePath
// Background erase
//
LOCAL lRet AS LOGIC
LOCAL hDC AS PTR
LOCAL sRect IS _winRECT
LOCAL hBrush AS PTR

lRet := TRUE
hDC := uDC
GetClientRect( SELF:Handle(), @sRect )

IF SELF:oControlBackground <> NULL_OBJECT
hBrush := SELF:oControlBackground:Handle()
ELSE
hBrush := PTR( _CAST, COLOR_WINDOW + 1 )
ENDIF
FillRect( hDC, @sRect, hBrush )

RETURN lRet


[END PASTE]

Hope this is of help to somebody.

Best regards,
Amilcar A. Camargo F.
Guatemala, C. A.
From: Amilcar A. Camargo on
Upss!!

Copy/Paste error: Replace all SIAAPSlePath with just SlePath

Sorry

On Mon, 28 Sep 2009 16:43:03 -0600, Amilcar A. Camargo
<amilcarcamargo(a)gmail.com> wrote:

>Hi Everybody,
>
>Some weeks ago there was a thread about using PathCompactPath to show
>'compacted' paths in SLE. Today i share with all of you my class that allows to
>edit the full text but, once entered, shows it in a 'compacted' way so the user
>can understand what's inside.
Amilcar A. Camargo F.
Guatemala, C. A.
From: Karl Faller on
Amilcar,
thx for sharing.
Did try it, first adding
_DLL FUNC PathCompactPath( hDC AS PTR, pText AS PSZ, dwPix AS DWORD);
AS PSZ PASCAL:shlwapi.PathCompactPathA

to satisfy the compiler - is that correct?

Then made a Standard MDI, added a dlg, added a sle, using class
SlePath and showing like:

METHOD Start() CLASS App
LOCAL oMainWindow AS StandardShellWindow
LOCAL oD AS pdlg_SlePathTest
oMainWindow := StandardShellWindow{SELF}
oMainWindow:Show(SHOWCENTERED)
oD := pdlg_SlePathTest{oMainWindow}
oD:SLE:TextValue:= "C:\asdf\0123456\asdf\1234"
oD:Show()
SELF:Exec()
RETURN NIL

Runs, but no ellipsis shown...

Obviously i miss s/th, but what?

TIA
Karl
From: Amilcar A. Camargo on
Hi Karl,

On Tue, 29 Sep 2009 19:27:21 +0200, Karl Faller
<k.faller_withoutthat_(a)onlinehome.de> wrote:

>Amilcar,
>thx for sharing.
>Did try it, first adding
>_DLL FUNC PathCompactPath( hDC AS PTR, pText AS PSZ, dwPix AS DWORD);
>AS PSZ PASCAL:shlwapi.PathCompactPathA

That's correct. I missed this in my posting. Thx for correcting.

>to satisfy the compiler - is that correct?
>
>Then made a Standard MDI, added a dlg, added a sle, using class
>SlePath and showing like:
>
>METHOD Start() CLASS App
>LOCAL oMainWindow AS StandardShellWindow
>LOCAL oD AS pdlg_SlePathTest
>oMainWindow := StandardShellWindow{SELF}
>oMainWindow:Show(SHOWCENTERED)
>oD := pdlg_SlePathTest{oMainWindow}
>oD:SLE:TextValue:= "C:\asdf\0123456\asdf\1234"
>oD:Show()
>SELF:Exec()
>RETURN NIL
>
>Runs, but no ellipsis shown...

How many controls are in the dialog? The ellipsis should show when you step out
from the control (or when it does not have focus). When it has focus, it
behaves normally.

Regards,
Amilcar A. Camargo F.
Guatemala, C. A.
From: Karl Faller on
Amilcar,
>How many controls are in the dialog? The ellipsis should show when you step out
>from the control (or when it does not have focus). When it has focus, it
>behaves normally.
<Argh> - that was it - lazy as i am i had put only the one sle onto
the dlg and neglected to try to understand what i read in the code ;-)
Added some buttons, and now is all fine.

HAND
Karl