DCSTATIC

This forum is for eXpress++ general support.
Post Reply
Message
Author
WernerSt
Posts: 18
Joined: Thu Jan 28, 2010 3:48 am
Contact:

DCSTATIC

#1 Post by WernerSt »

Roger,

I use DCSTATIC Type XBPSTATIC_TYPE_TEXT together with the VSCROLL-command successfully.
Now it would be fine if I could also use the mouse wheel to execute a vertical scroll.
Do you or anybody have an idea to get this property?

I use xbase++ Version 2.0 and express 2.0.266.

Regards,
Werner

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCSTATIC

#2 Post by Tom »

Hi, Werner.

1. Add a custom handler to your dialog using the HANDLER or the HANDLERBLOCK option.

2. Catch the xbeM_Wheel-event (IF nEvent == xbeM_Wheel), look whether the mouse is over your static or not (using the object sent as the fourth parameter to the handler and the coordinates in the second parameter)

3. Send 1 or -1 to the scrollbar with oScrollbar:SetData(1/-1) depending on whether the wheel was moved up- or downwards (third parameter sent to the dialog positive or negative)

That's it.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

WernerSt
Posts: 18
Joined: Thu Jan 28, 2010 3:48 am
Contact:

Re: DCSTATIC

#3 Post by WernerSt »

Hi Tom,

thank you very much for your response.

Up to now I have never created a own event handler, but I will try it following your detailed instructions.

Best regards,
Werner

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCSTATIC

#4 Post by Tom »

Maybe I can build a short sample during the day.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

WernerSt
Posts: 18
Joined: Thu Jan 28, 2010 3:48 am
Contact:

Re: DCSTATIC

#5 Post by WernerSt »

It would be a great help to get a sample, if you have time.

Here my current dcstatics.
Now dcstatic Textbox oStatic3 has the vscroll command which offers the vertical scrollbar but does not allow to use the mouse wheel
as already explained.

@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_RECESSEDBOX size 54*sf, 12.5*zf ;
OBJECT oStatic1

@ .5,1 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT size 53*sf, 11.5*zf ;
OBJECT oStatic2

@ 1,1 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT size 52*sf, 250 ;
OBJECT oStatic3 ;
PARENT oStatic2 ;
caption cText ;
option XBPSTATIC_TEXT_WORDBREAK ;
FONT trim( DC->mailfont ) ;
VSCROLL oStatic1 RANGE 0, 5000 ;
helpcode mprogn + "dcstatic"

.....

dcread gui modal clearevents options getoptions ;
setFocus @oStatic1 setAppWindow fit ;
eval {|o|o : show() } ;
title "TEXT-Dokument " + cDatei

Regards, Werner

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCSTATIC

#6 Post by Tom »

Hi, Werner.

I modified your code a little, please take a closer look to the oTextStatic:SetPos() in the handler function, this may need some additional clearing. Remark: It seems you use the vars "sf" and "zf" to create something like scaling. Take a look at the "SCALEFACTOR" option of DCGET OPTIONS - this makes scaling much easier!

Code: Select all

#include "dcdialog.ch"
#include "appevent.ch"
#pragma library("dclipx.lib")

FUNCTION Werner()
LOCAL GetList := {}, GetOptions := {}, oStatic1, oStatic2, cText := "", nCtr, sf := 1, zf := 1, oVScroll

FOR nCtr := 1 TO 100
  cText += Str(nCtr)+" Dies ist ein Test"+Chr(13)+Chr(10)
NEXT

@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_RECESSEDBOX size 54*sf, 12.5*zf ;
OBJECT oStatic1

@ .5,1 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT size 53*sf, 11.5*zf ;
OBJECT oStatic2

@ 1,1 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT size 52*sf, 250 ;
OBJECT oStatic3 ;
PARENT oStatic2 ;
caption cText ;
option XBPSTATIC_TEXT_WORDBREAK ;
VSCROLL oStatic1 RANGE 0, 50 OBJECT oVScroll

dcread gui modal clearevents options getoptions ;
setFocus @oStatic1 setAppWindow fit ;
eval {|o|o : show() } ;
title "TEXT-Dokument " ;
HANDLERBLOCK {|a,b,c,d,e|MyHandler(a,b,c,d,e,oStatic3,oVScroll)}

RETURN NIL

STATIC FUNCTION MyHandler(nEvent,mp1,mp2,oXbp,oDlg,oTextStatic,oVScroll)
STATIC nTextScrollStartPos := 0
LOCAL nScrollDirection

IF nTextScrollStartPos = 0
 nTextScrollStartPos := oTextStatic:CurrentPos()[2]
ENDIF

IF nEvent == xbeM_Wheel .AND. IAmOverObject(oTextStatic,mp1)
  nScrollDirection := IF(mp2[2]>0,(-1),1)
  IF oVScroll:IsVisible() .AND. oVScroll:GetData()+nScrollDirection >= oVScroll:Range[1] .AND. ;
                                         oVScroll:GetData()+nScrollDirection <= oVScroll:Range[2]
    oVScroll:SetData(oVScroll:GetData()+nScrollDirection)
    oTextStatic:SetPos({oTextStatic:CurrentPos()[1],nTextScrollStartPos+oVScroll:GetData()})
  ENDIF
ENDIF
RETURN DCGUI_NONE

FUNCTION IAmOverObject(oXbp,mp1,aRefPos)
* tests if the coords in mp1 reflect to oXbp
DEFAULT aRefPos := {{0,0},oXbp:CurrentSize()} // {{oXbp:CurrentPos()[1],0},oXbp:CurrentSize()}
IF mp1[1] >= aRefPos[1,1] .and. mp1[1] <= aRefPos[2,1] .and. ;
   mp1[2] >= aRefPos[1,2] .and. mp1[2] <= aRefPos[2,2]
   RETURN .T.
ENDIF
RETURN .F.
Edit: Correction. Now scrolling works good in both directions!
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

WernerSt
Posts: 18
Joined: Thu Jan 28, 2010 3:48 am
Contact:

Re: DCSTATIC

#7 Post by WernerSt »

Tom,

Thank you for your effort to create a detailed sample code for my request, that works well!

There is only a certain flickering during the movement of longer static text, but I think that you cannot improve this behaviour.

You are right, zf and sf ( Zeilen/Spaltenfaktor), are for scaling I use since we have changed from DOS to WINDOWS.

I should really check the scalefactor command of the dcget options, thank you this advice!

Regards,
Werner

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCSTATIC

#8 Post by Tom »

Hi, Werner.

I'm happy about that. The flickering comes from the fact that the static is repositioned in very small steps. You have to play around a bit with the range of the scroll bar. oDialog:LockUpdate does not help because you only change one element.

DCGETOPTIONS ... SCALEFACTOR is a great improvement. You may keep your zf/sf-calculation and just move this to the SCALEFACTOR array, and you will get rid of all the lines containting "*sf" and "*zf".
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

WernerSt
Posts: 18
Joined: Thu Jan 28, 2010 3:48 am
Contact:

Re: DCSTATIC

#9 Post by WernerSt »

Tom,

Testing the range of the scrollbar ist a good recommendation.

By the way: I replaced the VScroll-command with dcscrollbar to have better control.

Using the scalefactor would really reduce my program codes, thank you!

Regards, Werner

Post Reply