Page 1 of 1

Find previous focus.

Posted: Tue Jul 19, 2011 6:38 am
by jdsoft
Hello,

Here i am again...
There are 2 dialogs. (seperate thread, not the same GetList)
1 dialog contains Dc_Xbpget's
Another dialog contains only pushbuttons (keyboard) ALWAYSONTOP.
The input focus is on any Dc_Xbpget (can be any of many)

If i click on a button in the 2nd dialog then:
1. The first dialog goes out of focus.
2. The input field goes out of focus.
3. My 2nd window gets focus.
4. My pushbutton ACTION is executed.

In my pushbutton ACTION i want to send a key (for example a "A") to the Dc_Xbpget that had the previous focus (in the other dialog), and set focus to that Dc_Xbpget. If possible, without flickering......

Is the someone that has an ingenious solution for this.

Regards,
Jack Duijf.

P.s. My goal is to have a generic touchscreen keyboard for any of the dialogs in my application.

Re: Find previous focus.

Posted: Tue Jul 19, 2011 11:44 am
by rdonnay
Jack -

I added some new code to _DCCLASS.PRG to make this possible.

Here is what you need to do:

1. Add the following 3 lines of code to the DC_XbaseParts:setOrig() method just before the return.

Code: Select all

IF _IsEditControl(oXbp)
  oXbp:setInputFocus := DC_MergeBlocks(oXbp:setInputFocus,{||DC_LastInputFocus(oXbp)})
ENDIF
2. Add the following new functions to _DCCLASS.PRG:

Code: Select all

FUNCTION DC_LastInputFocus( oXbp )

STATIC soFocus := nil

IF Valtype(oXbp) == 'O'
  soFocus := oXbp
ENDIF

RETURN soFocus

* -------------

STATIC FUNCTION _IsEditControl( oXbp )

IF Valtype(oXbp) # 'O'
  RETURN .f.
ENDIF

RETURN oXbp:isDerivedFrom('DC_XbpGet') .OR. ;
       oXbp:isDerivedFrom('DC_XbpSle') .OR. ;
       oXbp:isDerivedFrom('DC_XbpRadioButton') .OR. ;
       oXbp:isDerivedFrom('DC_XbpComboBox') .OR. ;
       oXbp:isDerivedFrom('DC_XbpListBox') .OR. ;
       oXbp:isDerivedFrom('DC_XbpCheckBox') .OR. ;
       oXbp:isDerivedFrom('DC_XbpSpinButton') .OR. ;
       oXbp:isDerivedFrom('DC_XbpMle') .OR. ;
       oXbp:isDerivedFrom('DC_Xbp3State')

Now here is the test code I used:

Code: Select all

#INCLUDE "dcdialog.ch"
#INCLUDE "appevent.CH"

FUNCTION Main()

LOCAL GetList[0], aGets[10], i

AFill( aGets,Space(10) )

FOR i := 1 TO Len(aGets)
  @ i,1 DCGET aGets[i]
NEXT

DCREAD GUI FIT SETAPPWINDOW ;
   EVAL {|oDlg,oThread|oThread := Thread():new(), Sleep(5), oThread:start({||Keyboard()})}
            
RETURN nil

* ----------

PROC appsys ; RETURN

* ----------

FUNCTION Keyboard()

LOCAL GetList[0], i, nCol := 0

FOR i := 65 TO 65+25
  nCol += 3
  @ 0,nCol DCPUSHBUTTON CAPTION Chr(i) SIZE 3 ;
      ACTION ActionBlock(i)
NEXT

DCREAD GUI FIT TITLE 'Keyboard'

RETURN nil

* ----------

STATIC FUNCTION ActionBlock( i )

RETURN {|o| o := DC_LastInputFocus(), o:keyboard(i), o:getData() }

Re: Find previous focus.

Posted: Tue Jul 19, 2011 2:40 pm
by jdsoft
Hello Roger,

Thank you, this does almost the things i want.
This is a huge step forward. I need to fiddle a bit with my code get get it right.

Regards,
Jack Duijf

Re: Find previous focus.

Posted: Wed Jul 20, 2011 12:49 am
by hz_scotty
hello Roger!

Can you please post the new/changed _DCCLASS.PRG
(there are several place where the changes must be made)

thanks

Re: Find previous focus.

Posted: Wed Jul 20, 2011 9:03 am
by Zdeno Bielik
Hi Roger,

please, can you also add any method/function for saving and then restoring position in GET when loosing focus and restoring focus from another running thread/window or apps when it was selected via Alt+Tab or from TaskBar, Desktop etc.

Regards
Zdeno

s pozdravom

zdeno bielik
ace system, spol. s r.o.
štiavnická 18
949 01 nitra
http://www.acesystem.sk
tel: 0904 – 328 888
... s nami dostávate vždy viac

Re: Find previous focus.

Posted: Wed Jul 20, 2011 9:24 am
by rdonnay
please, can you also add any method/function for saving and then restoring position in GET when loosing focus and restoring focus from another running thread/window or apps when it was selected via Alt+Tab or from TaskBar, Desktop etc.
That feature was put into eXpress++ several years ago.
It automatically restores focus to the last object that had focus when clicking back on the parent window.

Re: Find previous focus.

Posted: Wed Jul 20, 2011 9:26 am
by rdonnay
Can you please post the new/changed _DCCLASS.PRG
File is attached.

Re: Find previous focus.

Posted: Wed Jul 20, 2011 9:54 am
by Zdeno Bielik
rdonnay wrote:
position in GET

It automatically restores focus to the last object that had focus when clicking back on the parent window.
Roger,

yes, previosly last active get object is restored and focus is set on it, but cursor is always set on first position instead of that, what position was when object did lost focus.

Zdeno

s pozdravom

zdeno bielik
ace system, spol. s r.o.
štiavnická 18
949 01 nitra
http://www.acesystem.sk
tel: 0904 – 328 888
... s nami dostávate vždy viac