TIP3.TXT 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Many people have admired the paged question selection facility in the
  2. OpenDoors 5.00 EZVote example door. EZVote allows the user to choose
  3. questions from a list of up to 200 questions, by displaying one page
  4. of questions at a time. The user is able to page up or down in the list
  5. of quesitons, select a question from the list, or return to the main
  6. menu. A prompt at the bottom of the screen shows the current page
  7. number, and a list of options that are currently available. For
  8. instance, when displaying the first of two pages, this prompt indicates
  9. that the user can move to the next page, but not the previous page.
  10. This OpenDoors Tip shows a generic function that provides the same sorts
  11. of capabilities that are seen in the EZVote example door, in a form that
  12. can be re-used in many different programs. This function, named
  13. PagedViewer(), can be used for displaying multi-paged messages, text
  14. files, or for permitting selection from a potentially very long list of
  15. items. To use the PagedViewer() in a program, you should add the
  16. pageview.c file to your project file / makefile, and #include the
  17. pageview.h file in any source file that calls PagedViewer().
  18. The prototype for the PagedViewer() function is as follows:
  19. int PagedViewer(
  20. int nInitialLine,
  21. int nTotalLines,
  22. void (*pDisplayCallback)(int nLine, void *pCallbackData),
  23. void *pCallbackData,
  24. BOOL bAllowSelection,
  25. char *pszTitle,
  26. int nPageSize);
  27. The nInitialLine parameter specifies the line to begin viewing at.
  28. Normally this would be 0, but you may wish to pass a different value to
  29. this function to force the viewer to begin on a page other than the
  30. first. Using this parameter, you can have the user return to
  31. the page they were previously viewing, rather than returning to the
  32. first page and having to again find their original location.
  33. The nTotalLines parameter specifies the total number of lines that can
  34. be viewed, and can be any value greater than or equal to 0.
  35. The pDisplayCallback parameter must be a pointer to a function that the
  36. PagedViewer will call to display a particular line of the file at the
  37. current location. When PagedViewer() calls your function, it will pass
  38. the line number to be displayed, along with the value originally passed
  39. to PagedViewer() in pCallbackData. The provided function should simply
  40. display the text for the specified line number, without a trailing CR/LF
  41. sequence, and then return.
  42. The pCallbackData can point to any data that you wish PagedViewer() to
  43. pass to your callback function, or may be NULL if you do not wish to use
  44. this feature.
  45. The bAllowSelection parameter should be TRUE if the user should be able
  46. to make a selection from the list, and FALSE if they should not. If
  47. bAllowSelection is TRUE, PagedViewer() will display a letter beside each
  48. line, and allow the user to select a line by pressing the corresponding
  49. letter. If you are using PagedViewer() to display a text file or
  50. message, you will want to set bAllowSelection to FALSE. If you are using
  51. PagedViewer() to display a list of items from which the user can select,
  52. you will want to set bAllowSelection to TRUE.
  53. The pszTitle parameter can point to a title to be displayed at the top
  54. of each page, and could be something like ("Select a message"). If you
  55. do not wish to have a title displayed, set this parameter to NULL.
  56. The nPageSize parameter specifies the number of lines that should be
  57. displayed on each page. If you do not wish to have the local screen
  58. (with a two line status line) to be scrolled while displaying the list,
  59. the maximum page size you should use is 21 if no title is being
  60. displayed, and 19 if a title is being displayed.
  61. The included fileview.c text file viewing program demonstrates the use
  62. of PagedViewer(). The fileview.c door can be setup to allow the user to
  63. view one or more files. If setup to view multiple files, the program
  64. first displays a list of files that the user can select to view.
  65. The fileview.c program uses PagedViewer() in two places - for providing
  66. the list of files and for displaying the file itself. As such, the user
  67. can page up or down in the list of files, select a file to view, and
  68. then page up or down in the file. When the user selects quit while
  69. viewing the file, they are returned to the list of files to possibly
  70. select another file. When the user selects quit from the list of files,
  71. the door returns control to the calling BBS software.