[comp.sys.mac.programmer] Window Scrolling Problem

850181f@aucs.uucp (S. Ferguson-Parker) (12/09/89)

Having a problem scrolling windows.  I'm new at programming the Mac, but it
is proving to be challenging.

Here's the problem.  I'm using TrackControl() passing it an action procedure
to do continuous scrolling.  I should state that I am programming in 
LightSpeed C version 2.15.  Originally, no scrolling was taking place at all, 
but I fixed that problem by reversing the parameters of the action procedure.

Now I'll get to the problem.  After reversing the parameters of the action 
procedure, continuous scrolling would take place while the mouse was held
down in the scroll bar.  But it will only do it once!  If I release the mouse
button and try scrolling again, there is no result!  I cannot even move the 
thumb. 

After a little poking aroung I found that the toolbox routine TrackControl()
is returning a NULL pointer as the control handle instead of the handle to the
scroll bar being manipulated.

Also after scrolling once, if I try to zoom or grow the window, the system
crashes.  If it is of any help my action procedure is of type void.

I have tried everything I can think of to fix this problem, but have had no 
luck.  

  Does anyone have any suggestions?

Wade.
850860w@AcadiaU.CA

zben@umd5.umd.edu (Ben Cranston) (12/12/89)

In article <1989Dec8.164905.13550@aucs.uucp> 850860w@aucs.UUCP
(VINCENT W. WHYNOT) writes:

> I'm using TrackControl() passing it an action procedure
> to do continuous scrolling.  I should state that I am programming in 
> LightSpeed C version 2.15.  Originally, no scrolling was taking place at all, 
> but I fixed that problem by reversing the parameters of the action procedure.
> After reversing the parameters of the action 
> procedure, continuous scrolling would take place while the mouse was held
> down in the scroll bar.  But it will only do it once!  If I release the mouse
> button and try scrolling again, there is no result!  I cannot even move the 
> thumb. 

From the observation that reversing the arguments made it work, it would seem
like the action procedure is expecting the C calling sequence rather than the
Pascal calling sequence.  The argument orders are reversed between the two.
Unfortunately, there is another important differance between the two calling
sequences.  In Pascal the callEE pops the arguments off the stack, while in
C the callER pops them.  This mismatch would not manifest itself until the
procedure returns, hence your works-only-once behaviour.

I don't know how to make Think C do this.  In MPW C I just put the keyword
pascal into the routine declaration, like this example taken from an actual
program:

/* Called periodically when button is held down in scrolling arrrow.
 */

pascal ScrollAction(ControlHandle hitctl,short part)
{
	WindowPtr	windp = (*hitctl)->contrlOwner;
	short		oldval,newval,limit,setval;

	newval = oldval = GetCtlValue(hitctl);

	switch(part) {
	case inUpButton:
		newval -= 10;
		break;
	case inDownButton:
		newval += 10;
		break;
	case inPageUp:
		newval -= RectHite(windp->portRect);
		break;
	case inPageDown:
		newval += RectHite(windp->portRect);
	}

	limit = GetCtlMax(hitctl);
	setval = newval<0?0:newval>limit?limit:newval;

	if (setval != oldval) {
		SetCtlValue(hitctl,setval);
		ScrollContent(hitctl,oldval);
		UpdateWindow(windp);
	}
}

Could somebody with Think C experience post the correct solution?

Private complaint: consistency of capitalization of proper names:

pascal Boolean foo()
^      ^
Grump

-- 
Sig     DS.L    ('ZBen')       ; Ben Cranston <zben@Trantor.UMD.EDU>
* Network Infrastructures Group, Computer Science Center
* University of Maryland at College Park
* of Ulm

pepke@loligo (Eric Pepke) (12/12/89)

In article <5764@umd5.umd.edu> zben@umd5.umd.edu (Ben Cranston) writes:
>I don't know how to make Think C do this.  In MPW C I just put the keyword
>pascal into the routine declaration, like this example taken from an actual
>program:
>
>/* Called periodically when button is held down in scrolling arrrow.
> */
>
>pascal ScrollAction(ControlHandle hitctl,short part)

It's the same in Think C.  Of course, it should probably be

pascal void ScrollAction(.....

Aside: One of the irritating things about the pascal keyword in Think C is that
it is a storage class, which makes it difficult to declare a pointer to a
pascal function as a function argument.  You have to pretend it is a pointer
to a C function and use CallPascal.  In this case, the function to which 
you pass a pascal function has already been declared, so you don't have to
worry about it.  However, if you ever need to write routines using forms 
similar to toolbox routines and want to pass them pascal procedure, keep this
in mind.

>Private complaint: consistency of capitalization of proper names:
>
>pascal Boolean foo()
>^      ^
>Grump

I think that Boolean is capitalized to maintain consistency with IM, not that
IM is consistent (i.e. INTEGER vs. Integer).  "pascal" is an actual keyword,
so like all keywords in C, it is in lower case.  I once had a C which used
all lower case (Megamax), and it was much worse.

This is not to say that the capitalization conventions could not be
improved, only to say that if it be madness, yet there be method in it.

Eric Pepke                                     INTERNET: pepke@gw.scri.fsu.edu
Supercomputer Computations Research Institute  MFENET:   pepke@fsu
Florida State University                       SPAN:     scri::pepke
Tallahassee, FL 32306-4052                     BITNET:   pepke@fsu

Disclaimer: My employers seldom even LISTEN to my opinions.
Meta-disclaimer: Any society that needs disclaimers has too many lawyers.