[futurebasic] Re: [FB] Re: [FB^3] Focus Ring emulation in FB^3

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2000 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Sat, 07 Oct 2000 19:51:44 +0200

Ken Shmidheiser wrote:

> Concerning my feeble attempt at Focus Ring emulation...
>
> ...Robert Covington adds simplicity:
>
> >I didn't like the flicker, so deleted your extra edit fields
> >and just used some quickdraw rects.
> >Little simpler for people's like me. Using FRAMEROUNDRECT
> >may result in an appearance more to the original.
>
> Simple is good. This is probably much closer to Apple's solution in
> Appearance Manager. For instance, Appearance Mananger windows use an
> extra quickdraw rect around them to give the neat shadowed  3-D look.
>
> ...tedd adds reason:
>
> >You might try placing your DIM vars only option to ON.
>
> Opps, my apologies for the sloppy dimensioning directly attributable
> to 5 a.m. mind fog!
>
> ...Alain adds elegance:
>
> >That's a cool one. However, may I suggest an enhancement
> >to your code so that it could be easily incorporated
> >in other programs.
>
> >As you wrote it, each field has its own function.
> >That tends to be not so cool when you've got a lot
> >of Edit Fields. Here is a reworked piece of code
> >that uses a single function to perform the job.
>
> A unified focus access function was my next project. No only has
> Alain spared me time and pain, but he has done it right where I would
> have stumbled along. One interesting anomaly in Alain's code: If you
> click on an EDIT FIELD and keep the mouse button depressed, slide the
> cursor out of the window and use the menu to turn off the focus ring,
> the ring will remain highlighted.
>

OK, one solution is to add a fixFocus FN called from inside the main
event loop, this is less elegant but it seems to work.

1 - I have added another global variable (gLastFocus) to keep track of
the last targeted Edit Field.

2 - I have slightly modified the focusEF FN (also using the Toolbox
for a little gain in speed, notice that the cursor changes are
handled) like this:

CLEAR LOCAL MODE
LOCAL FN focusEF(theField,frameIt,theColor AS PTR TO RGBColor)
DIM focusRect  AS RECT
DIM focusField AS INT
DIM @ teH      AS HANDLE
DIM fieldH     AS HANDLE

theField   = USR ABS(theField)
focusField = theField + 100

LONG IF theField
IF TEHANDLE(-theField) < 1 THEN EXIT FN
LONG IF frameIt
fieldH = [WNDBLK + WINDOW(WINDOW(_activeWnd))*16 + 4]
WHILE fieldH
LONG IF fieldH..4% != theField
FN focusEF(fieldH..4%,_false,_nil)
XELSE
CALL RGBForeColor(#theColor)
teH = TEHANDLE(theField)
focusRect;8 = @teH..TEdestRect%
focusRect.left   -= 2
focusRect.top    -= 2
focusRect.right  += 2
focusRect.bottom += 2
EDIT FIELD focusField,,@focusRect,197
CALL ForeColor(_blackColor)
EDIT FIELD theField,,@teH..TEdestRect%,2,2
CALL SetCursor(#[FN GetCursor(_iBeamCursor)])
END IF
fieldH = [[fieldH]]
WEND
XELSE
EDIT FIELD CLOSE focusField
END IF
XELSE
fieldH = [WNDBLK + WINDOW(WINDOW(_activeWnd))*16 + 4]
WHILE fieldH
FN focusEF(fieldH..4%,_false,_nil)
fieldH = [[fieldH]]
WEND
CALL InitCursor
END IF
END FN = theField

3 - I have added the fixFocus FN just below

LOCAL FN fixFocus
DIM mousePt AS POINT
DIM @ teH   AS HANDLE

teH = TEHANDLE(USR ABS(gLastFocus))
LONG IF teH
CALL GetMouse(mousePt)
LONG IF FN PtInRect(mousePt,#@teH..TEViewRect%) = _false
gLastFocus = FN focusEF(gLastFocus,_false,_nil)
CALL InitCursor
END IF
END IF

END FN

4 - I have altered the _cursOver case clause like this:

CASE _cursOver
SELECT id%
CASE < 0
IF gUserWantsFocus THEN gLastFocus = FN focusEF(id%,_true,gFocusColor)
CASE ELSE
IF gUserWantsFocus THEN gLastFocus = FN focusEF(_nil,_false,_nil)
END SELECT

5 - And finally I have added just below the HANDLEEVENTS statement the
following line:

IF gLastFocus THEN FN fixFocus

As I said, it seems to work except when I enter very slowly any of the fields


>
> With the fertile minds here, let's just scrap Appearance Manager and
> write our own FB^3-compliant clone!
>
> Thanks as always.
>

Thank to you too for feeding us.

Do you know a way to grab the focus color set by the user?
Perhaps it should be better to use rectangles like it was suggested,
in that case you will have to deal with foreground and background
colors I guess. I'm not sure this will be easier.

Cheers

Alain