home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / Text / Docu / Controllers (.txt) next >
Encoding:
Oberon Document  |  1994-06-07  |  7.4 KB  |  180 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Geneva
  22. Geneva
  23. 6.6 TextControllers
  24. DEFINITION TextControllers;
  25.     IMPORT Models, Views, Containers, TextModels, TextViews;
  26.     CONST
  27.         noAutoScroll = 16; noAutoIndent = 17;
  28.         none = -1;
  29.     TYPE
  30.         LONGCHAR = INTEGER;
  31.         Controller = POINTER TO ControllerDesc;
  32.         ControllerDesc = RECORD (Containers.ControllerDesc)
  33.             view-: TextViews.View;
  34.             text-: TextModels.Model;
  35.             PROCEDURE (c: Controller) Clone (): Controller;
  36.             PROCEDURE (c: Controller) InitView (v: Views.View);
  37.             PROCEDURE (c: Controller) CaretPos (): LONGINT;
  38.             PROCEDURE (c: Controller) SetCaret (pos: LONGINT);
  39.             PROCEDURE (c: Controller) GetSelection (VAR beg, end: LONGINT);
  40.             PROCEDURE (c: Controller) SetSelection (beg, end: LONGINT)
  41.         END;
  42.         Directory = POINTER TO DirectoryDesc;
  43.         DirectoryDesc = RECORD (Containers.DirectoryDesc)
  44.             PROCEDURE (d: Directory) NewController (opts: SET): Controller;
  45.             PROCEDURE (d: Directory) New (): Controller
  46.         END;
  47.         ModelMessage = RECORD (Models.Message) END;
  48.         SetCaretMsg = RECORD (ModelMessage)
  49.             pos: LONGINT
  50.         END;
  51.         SetSelectionMsg = RECORD (ModelMessage)
  52.             beg, end: LONGINT
  53.         END;
  54.     VAR dir-, stdDir-: Directory;
  55.     PROCEDURE SetDir (d: Directory);
  56.     PROCEDURE Install;
  57.     PROCEDURE Focus (): Controller;
  58.     PROCEDURE SetCaret (text: TextModels.Model; pos: LONGINT);
  59.     PROCEDURE SetSelection (text: TextModels.Model; beg, end: LONGINT);
  60. END TextControllers.
  61. TextControllers are the standard controllers for text views as defined in TextViews.
  62. CONST noAutoScroll
  63. Possible element of controller option set. If included, automatic scrolling of views is disabled. Autoscrolling is used to show the caret position or to show the position of the modification performed most recently.
  64. CONST noAutoIndent
  65. Possible element of controller option set. If included, automatic indentation after entering a line character is disabled.
  66. CONST none
  67. Possible argument to controller.SetCaret and controller.SetSelection to indicate removal of the caret or the selection, respectively. Likewise, controller.CarPos and controller.GetSelection may return none to indicate the absense of a caret or selection, respectively.
  68. TYPE LONGCHAR = INTEGER
  69. Type of long characters.
  70. TYPE Controller
  71. Interface, Extension
  72. Standard controllers for text views.
  73. view-: TextViews.View
  74. The view to which the controller is connected.
  75. text-: TextModels.Model    view # NIL => text = view.ThisText()
  76. The text displayed by the controlled view; cached for easy access.
  77. PROCEDURE (c: Controller) Clone (): Controller
  78. Default, Extension
  79. Result type is narrowed.
  80. PROCEDURE (c: Controller) InitView (v: Views.View)
  81. Default, Extension
  82. Strengthened preconditions!
  83. c.init    20
  84. v = NIL  #  c.view = NIL    21
  85. c.view = NIL
  86.     v IS TextViews.View    22
  87. v # NIL
  88.     c.view = v
  89.     c.text = c.view.ThisModel()
  90. v = NIL
  91.     c.view = NIL
  92.     c.text = NIL
  93. PROCEDURE (c: Controller) CaretPos (): LONGINT
  94. Interface
  95. Current position of the caret, or none if not set.
  96. result = none  OR  0 <= result <= c.text.Length()
  97. PROCEDURE (c: Controller) SetCaret (pos: LONGINT)
  98. Interface
  99. Set the caret at position pos, or remove the caret if pos = none.
  100. pos = none  OR  0 <= pos    20
  101. pos <= c.text.Length()    21
  102. c.CarPos() = pos
  103. PROCEDURE (c: Controller) GetSelection (VAR beg, end: LONGINT)
  104. Interface
  105. Get the currently selected stretch [beg, end), or beg = end if none exists.
  106. beg = end  OR  0 <= beg <= end <= c.text.Length()
  107. PROCEDURE (c: Controller) SetSelection (beg, end: LONGINT)
  108. Interface
  109. Set the stretch to be selected to [beg, end), or remove the selection if beg = end.
  110. beg = end  OR  0 <= beg < end <= c.text.Length()    20
  111. c.GetSelection(b, e): b = beg, e = end
  112. TYPE Directory
  113. Directory for controllers.
  114. PROCEDURE (d: Directory) NewController (opts: SET): Controller
  115. Interface
  116. Return new controller with options opts.
  117. PROCEDURE (d: Directory) New (): Controller
  118. Default, Extension
  119. Result type is narrowed.
  120. Except for performance, equivalent to:
  121.     RETURN d.NewController({})
  122. TYPE ModelMessage
  123. Interface
  124. Messages to control virtual model extensions, such as marks (e.g. caret or selection).
  125. TYPE SetCaretMsg
  126. Extension
  127. Set the caret in a view displaying text model msg.model.
  128. pos: LONGINT
  129. Set the caret at position pos.
  130. TYPE SetSelectionMsg
  131. Extension
  132. Set the caret in a view displaying text model msg.model.
  133. beg, end: LONGINT
  134. Set the selection to cover the stretch [beg, end).
  135. VAR dir-, stdDir-: Directory    dir # NIL, stdDir # NIL, stable stdDir = d
  136. Directory and standard directory objects for controllers.
  137. PROCEDURE SetDir (d: Directory)
  138. Set the directory object.
  139. d # NIL    20
  140. dir = d
  141. PROCEDURE Install
  142. Install the current controller directory object in TextViews.
  143. Except for performance, equivalent to:
  144.     TextViews.SetCtrlDir(dir)
  145. PROCEDURE Focus (): Controller
  146. Return the text controller that currently has the focus, if any.
  147. Except for performance, equivalent to:
  148.     VAR v: Views.View; c: Controllers.Controller;
  149.     v := Controllers.FocusView();
  150.     IF (v # NIL) & (v IS TextViews.View) THEN
  151.         c := v(TextViews.View).ThisController();
  152.         IF (c # NIL) & (c IS Controller) THEN RETURN c(Controller)
  153.         ELSE RETURN NIL
  154.         END
  155.     ELSE RETURN NIL
  156. PROCEDURE SetCaret (text: TextModels.Model; pos: LONGINT)
  157. In all views displaying text, set the caret to position pos.
  158. text # NIL    20
  159. pos = none  OR  0 <= pos    21
  160. pos <= text.Length()    22
  161. Except for performance, equivalent to:
  162.     VAR cm: SetCaretMsg;
  163.     cm.pos := pos; Models.Broadcast(text, cm)
  164. PROCEDURE SetSelection (text: TextModels.Model; beg, end: LONGINT)
  165. In all views displaying text, set the selection to the stretch [beg, end).
  166. text # NIL    20
  167. beg # end
  168.     0 <= beg    21
  169.     beg < end    22
  170.     end <= text.Length()    23
  171. Except for performance, equivalent to:
  172.     VAR sm: SetSelectionMsg;
  173.     sm.beg := beg; sm.end := end; Models.Broadcast(text, sm)
  174. TextControllers.StdCtrlDesc
  175. TextControllers.ControllerDesc
  176. Containers.ControllerDesc
  177. Controllers.ControllerDesc
  178. Geneva
  179. Documents.ControllerDesc
  180.