[comp.windows.x] Scrolling a spreadsheet inside a Viewport

kulkarni@umn-cs.CS.UMN.EDU (Srinivas R. Kulkarni) (08/19/89)

	I am developing a small spreadsheet sort of application using

Xaw. I am using X11R3.
	
	Since I want the spreadsheet to scroll both horizontally and 

vertically, I have implemented the spreadsheet canvas as the child of a

viewport widget.

concise problem description:
^^^^^^^^^^^^^^^^^^^^^^^^^^
	I want Column titles on the top row and Row titles in the 

leftmost column of my spreadsheet. The Column titles scroll ONLY

horizontally and similarly the Row titles scroll ONLY vertically.

	That is the problem. I am not quite sure if (and how)  I can  

achieve such 'partial' scrolling.

a few things I tried:
^^^^^^^^^^^^^^^^^^^^^
I thought of using label widgets for the Column titles and making 

them the children of the Viewport's horizontall scroll bar using

XtNameToWidget(viewport, "horizontal") but that's out of question 

since a scrollbar/viewport widget can have only child. So I created 

a form widget as the child of my viewport widget and made the

canvas and the column/row label widgets the child of my form widget.


	But now, as expected, the whole form widget i.e  ALL its 

children scroll. I somehow need to stop ( can i do this?) the vertical 

scroll bar from scrolling Column label widgets and vice versa for 

the Row label widgets. 
     
	Is there a better design? Would using two Scrollbar widgets

 help? If so, how can I do that? Also, can I scroll in units

 of CELL_HEIGHT(vertically) and CELL_WIDTH(horizontally) by 

'intercepting' the values passed to ScrollUpDownProc? 

	Please help. Thanks in advance. 

	Please e-mail me directly.

Srinivas R. Kulkarni

kulkarni@umn-cs.cs.umn.edu
(612) 341-2921 (home)

kulkarni@UMN-CS.CS.UMN.EDU ("Srinivas R. Kulkarni") (08/22/89)

	I am having problems choosing the right sort of widgets for

a small spreadsheet sort of application (with  Xaw,  X11R3). I will

appreciate it very much if you could help me out.
	
	Since I want the spreadsheet to scroll both horizontally and 

vertically, I have implemented the spreadsheet canvas as the child of a

viewport widget.

concise problem description:
^^^^^^^^^^^^^^^^^^^^^^^^^^
	I want Column titles on the top row and Row titles in the 

leftmost column of my spreadsheet. The Column titles scroll ONLY

horizontally and similarly the Row titles scroll ONLY vertically.

	That is the problem. I am not quite sure if (and how)  I can  

achieve such 'partial' scrolling.

a few things I tried:
^^^^^^^^^^^^^^^^^^^^^
I thought of using label widgets for the Column titles and making 

them the children of the Viewport's horizontall scroll bar using

XtNameToWidget(viewport, "horizontal") but that's out of question 

since a scrollbar/viewport widget can have only child. So I created 

a form widget as the child of my viewport widget and made the

canvas and the column/row label widgets the child of my form widget.


	But now, as expected, the whole form widget i.e  ALL its 

children scroll. I somehow need to stop ( can i do this?) the vertical 

scroll bar from scrolling Column label widgets and vice versa for 

the Row label widgets. 
     
	Is there a better design? Would using two Scrollbar widgets

 help? If so, how can I do that? Also, can I scroll in units

 of CELL_HEIGHT(vertically) and CELL_WIDTH(horizontally) by 

'intercepting' the values passed to ScrollUpDownProc? 

	Please help. Thanks in advance. 

	Please e-mail me directly.


Srinivas R. Kulkarni
kulkarni@umn-cs.CS.UMN.EDU 

(612) 341-2921 (home)

bob@odi.COM (Bob Miner) (08/22/89)

>      	I am developing a small spreadsheet sort of application using
>     Xaw. I am using X11R3.
>     	
>   [...stuff deleted...]
>
>     	I want Column titles on the top row and Row titles in the 
>     leftmost column of my spreadsheet. The Column titles scroll ONLY
>     horizontally and similarly the Row titles scroll ONLY vertically.
>     	That is the problem. I am quite sure if (and how)  I can  
>     achieve such 'partial' scrolling.
>
>   [...stuff deleted...]

I'd recommend you do one of two things, depending on how you want your
spreadsheet to look.  If you want the scrollbars to extend the full width
and height of the window, including to the right of the column titles and
below the row titles, #1 is the way to go.  If you want the scrollbars to
only extend to the boundaries of the cell area, leaving the space to the right
of the column titles and below the row titles empty, #2 is the way to go.

1. Create a form widget with 6 child widgets - 2 scrollbar widgets (one
   horizontal and and another vertical) and 4 core widgets (one for the
   column titles, another for the row titles, a third for the cells and a
   fourth for that little square area where the row titles and cell titles
   intersect).  You'll need to do scrolling in the core widgets yourself
   when you receive callbacks from the scrollbars.

2. Create a form widget with 4 children - 3 core widgets (one for the
   column titles, another for the row titles and the third for that little
   square area again) and 1 viewport widget with scrollbars.  Again, though,
   when the person scrolls the cell area in the viewport widget, you'll have
   to have set up a callback such that you know to scroll either the column
   or row area.

The answer you're really looking for is a way to synchronize the scrolling
of one widget's contents with the scrolling of another widget's contents.  I
know of no way to do that with the Athena widgets (or any other toolkit).

Another possibility, one which I've implemented but which takes more effort, is
to forget about making the column, row and cell areas separate widgets and
draw them all in one core widget.  You'll then need to do clipping to each area
yourself.  There are advantages to this approach in that you'll be able to draw
to all three areas simultaneously (with one Xlib call) which looks smoother
during scrolling and dynamic cell selection than first drawing in the cell
area with one Xlib call and then drawing in either the row or column area with
another Xlib call. 

I haven't used the Athena widget set much myself, so I could be off slightly
on the exact capabilities of the Athena widgets.  Most form and scrollbar
widgets in the various toolkits provide similar capabilities, however.

Good luck,

Bob Miner
Object Design, Inc.
1 New England Executive Park
Burlington, MA 01803
(617) 270-9797
Email: bob@odi.com

meo@stiatl.UUCP (Miles O'Neal) (08/25/89)

In article <15318@umn-cs.CS.UMN.EDU> kulkarni@umn-cs.CS.UMN.EDU (Srinivas R. Kulkarni) writes:
|
|	I am developing a small spreadsheet sort of application using
|Xaw. I am using X11R3.
|	
|	Since I want the spreadsheet to scroll both horizontally and 
|vertically, I have implemented the spreadsheet canvas as the child of a
|viewport widget.
|
|concise problem description:
|^^^^^^^^^^^^^^^^^^^^^^^^^^
|	I want Column titles on the top row and Row titles in the 
|leftmost column of my spreadsheet. The Column titles scroll ONLY
|horizontally and similarly the Row titles scroll ONLY vertically.
|	That is the problem. I am not quite sure if (and how)  I can  
|achieve such 'partial' scrolling.
|
|a few things I tried:
|^^^^^^^^^^^^^^^^^^^^^
|I thought of using label widgets for the Column titles and making 
|them the children of the Viewport's horizontall scroll bar using
|XtNameToWidget(viewport, "horizontal") but that's out of question 
|since a scrollbar/viewport widget can have only child. So I created 
|a form widget as the child of my viewport widget and made the
|canvas and the column/row label widgets the child of my form widget.

In addition to the suggestions someone else made, there is another
solution. It involves a bit more work, but has some advantages.

Don't use a viwport widget. Use a form widget with something like
the following layout.


 +----------------------------------------------------------------------+
 |     sub-form widget containing labels containing column titles       |
 +----------------------------------------------------------------------+
 | sub-form   |                                                         |
 | widget     |                                                         |
 | containing |                                                         |
 | labels     |                                                         |
 | containing |       This are contains the cell widgets (label,        |
 | row titles |       or whatever)                                      |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 |            |                                                         |
 +----------------------------------------------------------------------+

Only create enough cell widgets to fill your screen. I didn't draw the
scrollbars above, but attach them wherever you want them. The scrollbar
action routines would change internal spreadsheet cell pointers to point
to the "active" cells. These would then be mapped into the cell widgets
on the screen.

For large spreadsheets, this is MUCH less memory-intensive than having
lots and lots of widgets. For any size spreadsheet, this should give you
much faster scrolling than having the viewport tell a whole bunch of
widgets to move/unmap/map themselves.

We did a srcolling menu based on this. We originally tried the classic
approaches, and discarded them one by one for memory and/or speed reasons.
This was not an academic excersize; this was a real-world solution to real-
world problems. It works VERY well.

-Miles

(if I disappear from the net, it is because I was shot for giving away
trade secrets...)