FOCUS handlig with MDI

This forum is for eXpress++ general support.
Post Reply
Message
Author
Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

FOCUS handlig with MDI

#1 Post by Janko »

Roger,

I am having problems with FOCUS handlig in the MDI :

Code: Select all

 #INCLUDE "dcdialog.ch"

FUNCTION TestnaOkna()

LOCAL GetList[0] ,i


PRIVATE aRRW, nW ,oWindowB

m->aRRw:={}
m->nW:=1

@ 0,10 DCPUSHBUTTON CAPTION 'Novo okno' ;
  SIZE 20,3 ;
  ACTION {||m->nW++, WindowB()}

DCREAD GUI FIT TITLE 'Window A' //EVAL {|o|M->oWindowA := o, WindowB()}


for i:=1 to len(m->arrW)

   IF Valtype(M->arrW[i,1]) == 'O'
     M->arrW[i,1]:destroy()
   ENDIF

next

//wtf 'stop' pause

RETURN nil

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

FUNCTION WindowB()

LOCAL GetList[0], GetOptions, oDlg, nnW:=m->nW

@ 0,0 DCSAY 'This is Window B  '+strZero(nnW,4)  SAYSIZE 0 FONT '9.Arial Bold'

DCGETOPTIONS WINDOWROW 700 WINDOWCOL 900

DCREAD GUI FIT TITLE 'Window B '+strZero(m->nW,4) ;
   OPTIONS GetOptions ;
   PARENT @oDlg ;
   EXIT

aaDD(m->aRRw,{oDlg,nnW})

oDlg:close := {|a,b,o|o:destroy(),M->aRRW[nnW,1] := nil }


RETURN nil

Program is creating multiple WindowsB from windowA and if FOCUS is not moved to WindowB (where I placed a browswer), everything is normal. But when it is moved to a browser (mouse click, scroll down), windowB stays on top and focus can not be moved back to WindowA. Only if focus is moved to third window or if windwB is minimized and restored again.

I beleive there is a trivial solution, which I can't find it by myself.

I would appreciate your answer.

Thanks
Janko

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: FOCUS handlig with MDI

#2 Post by rdonnay »

Your sample code does not demonstrate the problem.

There is no browser in Window B.
The eXpress train is coming - and it has more cars.

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: FOCUS handlig with MDI

#3 Post by Janko »

Dear Roger,

Yes you're right. I added browser to windowB.

Code: Select all

 #INCLUDE "dcdialog.ch"

FUNCTION TestnaOkna()

LOCAL GetList[0] ,i


PRIVATE aRRW, nW ,oWindowB

m->aRRw:={}
m->nW:=1

@ 0,10 DCPUSHBUTTON CAPTION 'Novo okno' ;
  SIZE 20,3 ;
  ACTION {||m->nW++, WindowB()}

DCREAD GUI FIT TITLE 'Window A' //EVAL {|o|M->oWindowA := o, WindowB()}


for i:=1 to len(m->arrW)

   IF Valtype(M->arrW[i,1]) == 'O'
     M->arrW[i,1]:destroy()
   ENDIF

next

//wtf 'stop' pause

RETURN nil

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

FUNCTION WindowB()

LOCAL GetList[0], GetOptions, oDlg, nnW:=m->nW
//------------------------------------------------------------------------------ added
LOCAL cFileName, oFileName, aDirectory, i, nPointer, oDirectory, aColors, bColor
aDirectory := Directory()

@ 3.5,2 DCBROWSE oDirectory DATA aDirectory  SIZE 60,12 FIT
DCBROWSECOL ELEMENT 1 WIDTH 10 HEADER "Name" PARENT oDirectory
DCBROWSECOL ELEMENT 2 WIDTH 7 HEADER "Size" PARENT oDirectory
DCBROWSECOL ELEMENT 3 WIDTH 8 HEADER "Date" PARENT oDirectory
DCBROWSECOL ELEMENT 4 WIDTH 6 HEADER "Time" PARENT oDirectory
DCBROWSECOL ELEMENT 5 WIDTH 4 HEADER "Marked" PARENT oDirectory



//------------------------------------------------------------------------------ added
//@ 0,0 DCSAY 'This is Window B  '+strZero(nnW,4)  SAYSIZE 0 FONT '9.Arial Bold'

DCGETOPTIONS WINDOWROW 700 WINDOWCOL 900

DCREAD GUI FIT TITLE 'Window B '+strZero(m->nW,4) ;
   OPTIONS GetOptions ;
   PARENT @oDlg ;
   EXIT

aaDD(m->aRRw,{oDlg,nnW})

oDlg:close := {|a,b,o|o:destroy(),M->aRRW[nnW,1] := nil }


RETURN nil




This sample demonstrates the difficulty. If you touch (move) browser in windowB, FOCUS is glued to it. What I need is to move FOCUS to any other window which is touched with mouse.

Thank you for your help.

Janko

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: FOCUS handlig with MDI

#4 Post by rdonnay »

I don't like writing code where there are multiple windows in a single thread.
The problem is caused by the lastfocus logic in eXpress++.
Apparently, I should defeat this logic under such conditions.
I am not eager, however, to make changes to the main kernel of eXpress++, therefore I am giving you a workaround:

Code: Select all

DCREAD GUI FIT SETAPPWINDOW PARENT @oDlg TITLE 'Window A' ;
   EVAL {|o|o:setDisplayFocus := {||SetAppFocus(oButton),DC_CompleteEvents()}}
The eXpress train is coming - and it has more cars.

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: FOCUS handlig with MDI

#5 Post by Janko »

Roger,

I am not the sharpest knife in the drawer. I do not insist on single threat solution. Could I ask you to help me with multi thread version sample?

Thank you in advance
Janko

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: FOCUS handlig with MDI

#6 Post by rdonnay »

I'm not sure what you are trying to do here, but here is a rewrite of your test program that uses threads and no private variables.

Code: Select all

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

FUNCTION Main()

LOCAL GetList[0] ,i, oButton, aRRw[0], nW := 1

@ 0,10 DCPUSHBUTTON CAPTION 'Novo okno' ;
  SIZE 20,3 ;
  OBJECT oButton ;
  ACTION {|o|nW++, o := Thread():new(),Sleep(5),o:start({||WindowB(aRRw,@nW)})}

DCREAD GUI FIT SETAPPWINDOW TITLE 'Window A'

for i:=1 to len(aRRw)

   IF Valtype(aRRw[i]) == 'O'
     PostAppEvent(xbeP_Close,,,aRRw[i])
     Sleep(10)
   ENDIF

next

RETURN nil

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

PROC appsys ; return

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

FUNCTION WindowB( aRRw )

LOCAL GetList[0], GetOptions, oDlg
LOCAL cFileName, oFileName, aDirectory, i, nPointer, oDirectory, aColors, bColor

aDirectory := Directory()

@ 3.5,2 DCBROWSE oDirectory DATA aDirectory  SIZE 60,12 FIT
DCBROWSECOL ELEMENT 1 WIDTH 10 HEADER "Name" PARENT oDirectory
DCBROWSECOL ELEMENT 2 WIDTH 7 HEADER "Size" PARENT oDirectory
DCBROWSECOL ELEMENT 3 WIDTH 8 HEADER "Date" PARENT oDirectory
DCBROWSECOL ELEMENT 4 WIDTH 6 HEADER "Time" PARENT oDirectory
DCBROWSECOL ELEMENT 5 WIDTH 4 HEADER "Marked" PARENT oDirectory

DCGETOPTIONS WINDOWROW 700 WINDOWCOL 900

DCREAD GUI FIT TITLE 'Window B '+strZero(Len(aRRw)+1,4) ;
   OPTIONS GetOptions ;
   PARENT @oDlg ;
   EVAL {|o|aaDD(aRRw,o)}

nPointer := AScan(aRRw,oDlg)
IF nPointer > 0
  ARemove(aRRw,nPointer)
ENDIF

RETURN nil
The eXpress train is coming - and it has more cars.

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: FOCUS handlig with MDI

#7 Post by Janko »

Thank you very much, MDI solution seems to show less collateral effects. With minor changes I managed to implement it in my other programs.

Best regards
JAnko

Post Reply