§1  SCROLLBARS  SCROLLBARS AND MOVEMENT BUTTONS 1

1. Scrollbars and movement buttons.

These are a set of functions that can be used to implement scrollbars and or movement buttons. They have been written to help implement the “Skew Diagram Manipulation into Mathematical Pictures Interface” project by James Faux. It uses the ‘X Windows’ standard libraries, with no help from the ‘XToolkit’ libraries.

2. All C programs are required to include specific standard header files and ‘X Windows’ programs are no exception. #include #include #include #include

3. There is one general header file that does all the includes needed for the graphical interface compilation units, in a proper order. #include

4. The construction of the header file occurs here. It includes all the modules that are mentioned below. ⟨ 4 ⟩ ≡

⟨ Global typedefs 6 ⟩

⟨ Global function declarations 8 ⟩

5. Local functions will precede the globally visible ones (which are defined in unnamed section); this slightly facilitates a top-down presentation of the functions. #define local static

format local static

⟨ Local function declarations 17 ⟩

⟨ Global variable definitions 11 ⟩

6. Each scrollbar has three windows, a backward (up or left) and forward (down or right) button and middle window, whose identifiers are stored in back win, forward win and win, respectively. Furthermore the window index of the master window is stored, since that one will have to be redrawn when the scrollbar is moved. There is an offset field that holds the offset, and a length field that contains the current total size in pixels of the scrollbar. ⟨ Global typedefs 6 ⟩ ≡

typedef struct scrollbar

{ win p win, back win, forward win; win p master ; int offset ; int length;

} ∗p scrollbar;

This code is used in section 4.

2  FUNCTIONS TO CREATE THE SCROLLBARS  SCROLLBARS §7

7. Functions to create the scrollbars.

These are a set of routines that can be used to create a set of scrollbars for any ‘X Windows’ proogram.

8. These are the functions that creates a vertical (horizontal) scrollbar and returns a pointer to a s vert (s hor ) structure. The first (win p) argument is the outer window on which the bar is actually mapped (the parent in the window hierarchy, the second (win p) argument is the index of the inner window that should be redrawn when the scrollbar is moved. ⟨ Global function declarations 8 ⟩ ≡

p scrollbar create vert scrollbar (win p, win p, int, int, int, int); p scrollbar create hor scrollbar (win p, win p, int, int, int, int);

See also sections 12 and 15. This code is used in section 4.

9.

extern p scrollbar create vert scrollbar (win p parent , win p master , int x, int y, int w, int h) { p scrollbar s ⇐ new (struct scrollbar );

s→length ⇐ h; s→master ⇐ master ; s→back win ⇐ make window (scroll up win, parent , x, y, w − 4, 20); s→forward win ⇐ make window (scroll down win, parent , x, y + h − 20, w − 4, 20); s→win ⇐ make window (scrollbar win, parent , x, y + 20, w − 4, h − 40); s→back win→data.scroll ⇐ s; s→forward win→data.scroll ⇐ s; s→win→data.scroll ⇐ s; display scrollbar (s); return s;

}

10.

extern p scrollbar create hor scrollbar (win p parent , win p master , int x, int y, int w, int h) { p scrollbar s ⇐ new (struct scrollbar );

s→length ⇐ w; s→master ⇐ master ; s→back win ⇐ make window (scroll left win, parent , x, y, 20, h − 4); s→forward win ⇐ make window (scroll right win, parent , x + w − 20, y, 20, h − 4); s→win ⇐ make window (scrollbar win, parent , x + 20, y, w − 40, h − 4); s→back win→data.scroll ⇐ s; s→forward win→data.scroll ⇐ s; s→win→data.scroll ⇐ s; display scrollbar (s); return s;

}

11. ⟨ Global variable definitions 11 ⟩ ≡

event handler table scrollarrow handlers ⇐

{ ExposureMask | ButtonPressMask , scrollarrow expose, ⊙, ⊙, scrollarrow press , ⊙, ⊙, ⊙, ⊙ }; event handler table scrollbar handlers ⇐ { 0, ⊙, ⊙, ⊙, ⊙, ⊙, ⊙, ⊙, ⊙ };

This code is used in section 5.

§12  SCROLLBARS  FUNCTIONS TO CREATE THE SCROLLBARS 3

12. These function resize the scrollbars of the diagram and picture windows. ⟨ Global function declarations 8 ⟩ +≡

void resize diagram scrollbars (p diagram window); void resize picture scrollbars (p picture window);

13.

void resize diagram scrollbars (p diagram window dw ) { XResizeWindow (display , dw →disp.vert →win→w, 16, dw →pane.height − (2 ∗ bf height + 86));

XResizeWindow (display , dw →disp.hor →win→w, dw →pane.width − 64, 16);

XMoveWindow (display , dw →disp.vert →forward win→w, 0, dw →pane.height − (bf height + 34)); XMoveWindow (display , dw →disp.hor →forward win→w, dw →pane.width − 24, bf height + 12);

}

14.

void resize picture scrollbars (p picture window pw ) { XResizeWindow (display , pw →d.vert →win→w, 16, pw →pane.height − (2 ∗ bf height + 86));

XResizeWindow (display , pw →d.hor →win→w, (pw →pane.width/2) − 64, 16);

XMoveWindow (display , pw →d.vert →forward win→w, 0, pw →pane.height − (bf height + 34)); XMoveWindow (display , pw →d.hor →forward win→w, (pw →pane.width/2) − 24, bf height + 12); XMoveWindow (display , pw →i.vert →back win→w, pw →pane.width/2, bf height + 32); XMoveWindow (display , pw →i.vert →forward win→w, pw →pane.width/2,

pw →pane.height − (bf height + 34)); XMoveWindow (display , pw →i.hor →back win→w, (pw →pane.width/2) + 20, bf height + 12); XMoveWindow (display , pw →i.hor →forward win→w, pw →pane.width − 24, bf height + 12); XMoveResizeWindow (display , pw →i.vert →win→w, pw →pane.width/2, bf height + 52, 16,

pw →pane.height − (2 ∗ bf height + 86)); XMoveResizeWindow (display , pw →i.hor →win→w, (pw →pane.width/2) + 40, bf height + 12, (pw →pane.width/2) − 64, 16);

}

15. Here is a function to map a scrollbar. ⟨ Global function declarations 8 ⟩ +≡

extern void display scrollbar (p scrollbar);

16.

extern void display scrollbar (p scrollbar s) { map window (s→win); map window (s→back win); map window (s→forward win); }

4  SCROLLBAR MOVEMENT BUTTON FUNCTIONS  SCROLLBARS §17

17. Scrollbar movement button functions. The following function implements the scrollbar movement buttons. The offset field of the scrollbar is adjusted appropriately, and then its parent window is redrawn. The latter is achieved by calling the event handler for an expose event, since this should redraw the window and its relevant subwindows, notably the scrollbar itself. ⟨ Local function declarations 17 ⟩ ≡

void scrollarrow press (win p, XButtonEvent∗);

See also section 19. This code is used in section 5.

18.

void scrollarrow press (win p p, XButtonEvent ∗xbutton)

{ p scrollbar s ⇐ p→data.scroll ; win p master ⇐ s→master ; SimpleHandler redraw ; if (p→type = scroll up win ∨ p→type = scroll left win) s→offset +⇐ info→scale.box size; else s→offset −⇐ info→scale.box size; if ((redraw ⇐ event table[master →type]→expose) ≠ ⊙) XClearWindow (display , master →w), redraw (master );

}

§19  SCROLLBARS  ARROW GRAPHICS 5

19. Arrow graphics. These functions display various direction arrows. They are constructed by displaying some rectangles and points in specific positions relative to a fixed origin. ⟨ Local function declarations 17 ⟩ +≡

local void scrollarrow expose (win p);

20.

local void scrollarrow expose (win p p) { int i, t;

⟨ Install arrow data 21 ⟩

switch (p→type)

{

case scroll up win: ⟨ Build upward arrow 22 ⟩

break; case scroll down win: ⟨ Build downward arrow 23 ⟩

break; case scroll left win: ⟨ Build leftward arrow 24 ⟩

break; case scroll right win: ⟨ Build rightward arrow 25 ⟩ } XFillRectangles (display , p→w, gc_{1}, rct , n recs ); XDrawPoints (display , p→w, gc_{1}, pt , n pts , CoordModeOrigin);

}

21. #define n recs (sizeof (arrow rec)/sizeof (arrow rec[0])) #define n pts (sizeof (arrow pt )/sizeof (arrow pt [0])) ⟨ Install arrow data 21 ⟩ ≡

static XRectangle arrow rec[ ] ⇐

{ { 6, 10, 2, 2 }, { 2, 10, 2, 2 }, { 3, 1, 4, 10 }, { 2, 2, 6, 4 }, { 0, 5, 2, 2 }, { 8, 5, 2, 2 } }; static XPoint arrow pt [ ] ⇐ { { 1, 4 }, { 8, 4 }, { 4, 0 }, { 5, 0 } }; XRectangle rct [n recs ]; XPoint pt [n pts ]; for (i ⇐ 0; i < n recs ; ^{++}i) rct [i] ⇐ arrow rec[i]; for (i ⇐ 0; i < n pts ; ^{++}i) pt [i] ⇐ arrow pt [i];

This code is used in section 20.

22. ⟨ Build upward arrow 22 ⟩ ≡

{ for (i ⇐ 0; i < n recs ; ^{++}i) rct [i].x +⇐ 3, rct [i].y +⇐ 2;

for (i ⇐ 0; i < n pts ; ^{++}i) pt [i].x +⇐ 3, pt [i].y +⇐ 2; }

This code is used in section 20.

23. ⟨ Build downward arrow 23 ⟩ ≡

{ for (i ⇐ 0; i < n recs ; ^{++}i) rct [i].x +⇐ 3, rct [i].y ⇐ 17 − rct [i].y − rct [i].height ;

for (i ⇐ 0; i < n pts ; ^{++}i) pt [i].x +⇐ 3, pt [i].y ⇐ 16 − pt [i].y; }

This code is used in section 20.

6  ARROW GRAPHICS  SCROLLBARS §24

24. ⟨ Build leftward arrow 24 ⟩ ≡

{ for (i ⇐ 0; i < n recs ; ^{++}i)

{ t ⇐ rct [i].x + 3, rct [i].x ⇐ rct [i].y + 3, rct [i].y ⇐ t;

t ⇐ rct [i].width, rct [i].width ⇐ rct [i].height , rct [i].height ⇐ t; } for (i ⇐ 0; i < n pts ; ^{++}i) t ⇐ pt [i].x + 3, pt [i].x ⇐ pt [i].y + 3, pt [i].y ⇐ t;

}

This code is used in section 20.

25. ⟨ Build rightward arrow 25 ⟩ ≡

{ for (i ⇐ 0; i < n recs ; ^{++}i)

{ t ⇐ rct [i].x + 3, rct [i].x ⇐ 17 − rct [i].y − rct [i].height , rct [i].y ⇐ t;

t ⇐ rct [i].width, rct [i].width ⇐ rct [i].height , rct [i].height ⇐ t; } for (i ⇐ 0; i < n pts ; ^{++}i) t ⇐ pt [i].x + 3, pt [i].x ⇐ 16 − pt [i].y, pt [i].y ⇐ t;

}

This code is used in section 20.

§26  SCROLLBARS  INDEX 7

26. Index.

arrow pt : \underline{21}. arrow rec: \underline{21}. back win: \underline{6}, 9, 10, 14, 16. bf height : 13, 14. box size: 18. ButtonPressMask : 11. CoordModeOrigin: 20. create hor scrollbar : \underline{8}, \underline{10}. create vert scrollbar : \underline{8}, \underline{9}. data: 9, 10, 18. disp: 13. display : 13, 14, 18, 20. display scrollbar : 9, 10, \underline{15}, \underline{16}. dw : \underline{13}. event handler table: 11. event table: 18. expose: 18. ExposureMask : 11. forward win: \underline{6}, 9, 10, 13, 14, 16. gc_{1}: 20. h: \underline{9}, \underline{10}. height : 13, 14, 23, 24, 25. hor : 13, 14. i: \underline{20}. info: 18. length: \underline{6}, 9, 10. local: \underline{5}. make window : 9, 10. map window : 16. master : \underline{6}, \underline{9}, \underline{10}, \underline{18}. n pts : 20, \underline{21}, 22, 23, 24, 25. n recs : 20, \underline{21}, 22, 23, 24, 25. new : 9, 10. offset : \underline{6}, 18. p: \underline{18}, \underline{20}. p diagram window: 12, 13. p picture window: 12, 14. p scrollbar: \underline{6}, 8, 9, 10, 15, 16, 18. pane: 13, 14. parent : \underline{9}, \underline{10}. pt : 20, \underline{21}, 22, 23, 24, 25. pw : \underline{14}. rct : 20, \underline{21}, 22, 23, 24, 25. redraw : \underline{18}. resize diagram scrollbars : \underline{12}, \underline{13}. resize picture scrollbars : \underline{12}, \underline{14}. s: \underline{9}, \underline{10}, \underline{16}, \underline{18}. s hor : 8. s vert : 8. scale: 18. scroll : 9, 10, 18. scroll down win: 9, 20. scroll left win: 10, 18, 20. scroll right win: 10, 20. scroll up win: 9, 18, 20. scrollarrow expose: 11, \underline{19}, \underline{20}. scrollarrow handlers : \underline{11}. scrollarrow press : 11, \underline{17}, \underline{18}. scrollbar : \underline{6}, 9, 10. scrollbar handlers : \underline{11}. scrollbar win: 9, 10. SimpleHandler: 18. t: \underline{20}. type: 18, 20. vert : 13, 14. w: \underline{9}, \underline{10}. width: 13, 14, 24, 25. win: \underline{6}, 9, 10, 13, 14, 16. win p: 6, 8, 9, 10, 17, 18, 19, 20. x: \underline{9}, \underline{10}. xbutton: \underline{18}. XButtonEvent: 17, 18. XClearWindow : 18. XDrawPoints : 20. XFillRectangles : 20. XMoveResizeWindow : 14. XMoveWindow : 13, 14. XPoint: 21. XRectangle: 21. XResizeWindow : 13, 14. y: \underline{9}, \underline{10}.

⟨ Build downward arrow 23 ⟩ Used in section 20. ⟨ Build leftward arrow 24 ⟩ Used in section 20. ⟨ Build rightward arrow 25 ⟩ Used in section 20. ⟨ Build upward arrow 22 ⟩ Used in section 20. ⟨ Global function declarations 8, 12, 15 ⟩ Used in section 4. ⟨ Global typedefs 6 ⟩ Used in section 4. ⟨ Global variable definitions 11 ⟩ Used in section 5. ⟨ Install arrow data 21 ⟩ Used in section 20. ⟨ Local function declarations 17, 19 ⟩ Used in section 5. ⟨ 4 ⟩

SCROLLBARS

Section Page

Scrollbars and movement buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 Functions to create the scrollbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2 Scrollbar movement button functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4 Arrow graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 7