eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'TextView':

Home

everywhere
www.exept.de
for:
[back]

Class: TextView


Inheritance:

   Object
   |
   +--GraphicsContext
      |
      +--DeviceGraphicsContext
         |
         +--GraphicsMedium
            |
            +--DisplaySurface
               |
               +--SimpleView
                  |
                  +--View
                     |
                     +--ListView
                        |
                        +--TextView
                           |
                           +--EditTextView

Package:
stx:libwidg
Category:
Views-Text
Version:
rev: 1.316 date: 2010/03/18 14:56:16
user: cg
file: TextView.st directory: libwidg
module: stx stc-classLibrary: libwidg
Author:
Claus Gittinger

Description:


a view for readOnly text - this class adds selections to a simple list.
The text is not editable and there is no cursor.
Use TextViews for readonly text, EditTextView for editable text.

Please read the historic notice in the ListView class.

[Instance variables:]

  selectionStartLine      <Number>                the line of the selection start (or nil)
  selectionStartCol       <Number>                the col of the selection start
  selectionEndLine        <Number>                the line of the selection end
  selectionEndCol         <Number>                the col of the selection end

  clickStartLine          <Number>                temporary - remember where select operation started
  clickStartCol           <Number>                temporary
  clickLine               <Number>                temporary
  clickCol                <Number>                temporary
  clickCount              <Number>                temporary
  expandingTop            <Boolean>               temporary - for expandSelection

  selectionFgColor        <Color>                 color used to draw selections
  selectionBgColor        <Color>                 color used to draw selections

  selectStyle             <Symbol>                how words are selected

  directoryForFileDialog  <nil|pathName>          directory where save dialog should start

  contentsWasSaved        <Boolean>               set to true, whenever saved in a file

  externalEncoding        <Symbol|nil>            external encoding, used when text is saved to
                                                  a file. Usually something like
                                                  #jis7, #euc, #sjis etc.
                                                  (currently only passed down from the
                                                   fileBrowser)

  dropSource              <DropSource>            drag operation descriptor or nil (dragging disabled)
  dragIsActive            <Boolean>               true, drag operation is activated  

  searchAction            <Block>                 an autosearch action; typically set by the browser. 
                                                  Will be used as default when searchFwd/searchBwd is 
                                                  pressed. If the searchPattern is changed, no autosearch 
                                                  action will be executed.

  searchBarActionBlock    <Block>                 search action block for embedded search
                                                  panel. Used as second chance for searchFwd/bwd

[class variables:]
    ST80Selections        <Boolean>               enables ST80 style doubleclick behavior
                                                  (right after opening parenthesis, right before
                                                   closing parenthesis, at begin of a line
                                                   at begin of text)

[StyleSheet parameters:]

  textView.background                       defaults to viewBackground
  textView.ViewFont                         defaults to textFont

  text.st80Selections                       st80 behavior (click on char after parent or quote)

  text.selectionForegroundColor             defaults to textBackgroundColor
  text.selectionBackgroundColor             defaults to textForegroundColor

  text.alternativeSelectionForegroundColor  pasted text (i.e. paste will not replace)
                                            defaults to selectionForegroundColor
  text.alternativeSelectionBackgroundColor  pasted text (i.e. paste will not replace)
                                            defaults to selectionBackgroundColor


Related information:

    EditTextView
    CodeView
    Workspace

Class protocol:

class initialization
o  initialize

defaults
o  defaultIcon
return the default icon if started as a topView

o  defaultMenuMessage
This message is the default yo be sent to the menuHolder to get a menu

o  defaultSelectionBackgroundColor
return the default selection background color

o  defaultSelectionForegroundColor
return the default selection foreground color

o  defaultViewBackgroundColor
return the default view background

o  lastSearchIgnoredCase

o  lastSearchWasMatch

o  st80SelectMode

o  st80SelectMode: aBoolean

o  updateStyleCache
extract values from the styleSheet and cache them in class variables

instance creation
o  on: aModel aspect: aspect change: change menu: menu initialSelection: initial
for ST-80 compatibility

o  with: someText

interface specs
o  searchDialogSpec
This resource specification was automatically generated
by the UIPainter of ST/X.

startup
o  open
start an empty TextView

o  openModalOnModel: aModel
start a textView on a model; return the textView

o  openModalWith: aString
start a textView with aString as initial contents

o  openModalWith: aString title: aTitle
start a textView with aString as initial contents. Return the textView.

o  openOn: aFileName
start a textView on a file; return the textView

o  openOnModel: aModel
start a textView on a model; return the textView

o  openWith: aStringOrStringCollection
start a textView with aStringOrStringCollection as initial contents

o  openWith: aStringOrStringCollection selected: selectedBoolean
start a textView with aStringOrStringCollection as initial (optionally selected) contents.
Return the textView.

o  openWith: aStringOrStringCollection title: aTitle
start a textView with aStringOrStringCollection as initial contents. Return the textView.

o  setupEmpty
create a textview in a topview, with horizontal and
vertical scrollbars - a helper for #startWith: and #startOn:

o  setupForFile: aFileName
setup a textView on a file; return the textView

o  setupForModel: aModel
setup a textView on a model; return the textView

o  setupWith: aStringOrStringCollection title: aTitle
setup a textView with aStringOrStringCollection as initial contents in a topView


Instance protocol:

Compatibility-ST80
o  displaySelection: aBoolean
ST-80 compatibility: ignored here.

o  editText: someText
ST-80 compatibility: set the edited text.

o  selectAndScroll
ST-80 compatibility: ignored here.

o  selectionStartIndex
ST-80 compatibility: return the selections start character position.

o  selectionStopIndex
ST-80 compatibility: return the character position of
the character right after the selection.

accessing
o  characterEncoding: encodingArg
define how the contents is encoded internally.
This should normally never be required, as ST/X now assumes
unicode (of which iso8859-1 is a subset) encoding.
The possibility to change the characterEncoding is provided as
a backward compatibility hook for programs which want to use
another encoding internally.

o  characterPositionOfSelection
return the character index of the first character in the selection.
Returns 0 if there is no selection.

o  characterPositionOfSelectionEnd
return the character index of the last character in the selection.
Returns 0 if there is no selection.

o  contentsWasSaved
return true, if the contents was saved (by a save action),
false if not (or was modified again after the last save).

o  contentsWasSaved: aBoolean

o  defaultFileNameForFileDialog
return the default fileName to use for the save-box

o  defaultFileNameForFileDialog: aBaseName
define the default fileName to use for the save-box

o  directoryForFileDialog: aDirectory
define the default directory to use for save-box

o  externalEncoding
return the encoding used when the contents is saved via the 'save / save as' dialog.
This is (currently only) passed down from the fileBrowser,
and required when utf8/japanese/chinese/korean text is edited.
(encoding is something like #utf8 #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc).
Notice: this only affects the external representation of the text.

o  externalEncoding: encodingSymOrNil
define how the contents should be encoded when saved
via the 'save / save as' dialog.
This is (currently only) passed down from the fileBrowser,
and required when utf8/japanese/chinese/korean text is edited.
(encoding is something like #utf8 #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc).
Notice: this only affects the external representation of the text.

o  parenthesisSpecification
return the value of the instance variable 'parenthesisSpecification' (automatically generated)

o  parenthesisSpecification: aDictionary
set the dictionary which specifies which characters are opening, which are closing
and which are ignored characters w.r.t. parenthesis matching.
See the classes initialize method for a useful value.

o  saveAction: something

o  searchBarActionBlock

o  searchBarActionBlock: something

accessing-behavior
o  readOnly: aBoolean
for protocol compatibility with editTextViews,
but actually ignored

accessing-contents
o  contents: newContents selected: selectedBoolean

o  fromFile: aFileName
take contents from a named file

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  list: something
set the displayed contents (a collection of strings)
with redraw.
Redefined since changing the contents implies deselect

o  loadTextFile: aFileName
take contents from a named file

o  setContents: something
set the contents (either a string or a Collection of strings)
dont change the position (i.e. do not scroll) or the selection.

o  setList: something
set the displayed contents (a collection of strings)
without redraw.
Redefined since changing contents implies deselect

o  setupForFile: aFileName
take contents from a named file

o  text
for ST80 compatibility

o  wordAtLine: selectLine col: selectCol do: aFiveArgBlock
find word boundaries, evaluate the block argument with those.
A helper for nextWord and selectWord functions.

accessing-look
o  selectionBackgroundColor
return the selection-background color.

o  selectionForegroundColor
return the selection-foreground color.

o  selectionForegroundColor: color1 backgroundColor: color2
set both the selection-foreground and cursor background colors.
The default is defined by the styleSheet;
typically black-on-green for color displays and white-on-black for b&w displays.

accessing-mvc
o  on: aModel aspect: aspectSym list: listSym change: changeSym menu: menuSym initialSelection: initial
set all of model, aspect, listMessage, changeSymbol, menySymbol
and selection. Added for ST-80 compatibility

drag & drop
o  allowDrag: aBoolean
enable/disable dragging support

o  canDrag
returns true if dragging is enabled

o  collectionOfDragObjects
returns collection of dragable objects assigned to selection
Here, by default, a collection of text-dragObjects is generated;
however, if a dragObjectConverter is defined, that one gets a chance
to convert as appropriate.

o  dropSource
returns the dropSource or nil

o  dropSource: aDropSourceOrNil
set the dropSource or nil

encoding
o  validateFontEncodingFor: newEncoding ask: ask
if required, query user if he/she wants to change to another font,
which is able to display text encoded as specified by newEncoding

event handling
o  buttonMotion: buttonState x: x y: y
mouse-move while button was pressed - handle selection changes

o  buttonMultiPress: button x: x y: y
multi-mouse-click - select word under pointer

o  buttonPress: button x: x y: y
mouse-click - prepare for selection change

o  buttonRelease: button x: x y: y
mouse- button release - turn off autoScroll if any

o  doubleClickX: x y: y
double-click - select word under pointer

o  extendSelectionToX: x y: y
mouse-move while button was pressed - handle selection changes

o  keyPress: key x: x y: y
handle some keyboard input (there is not much to be done here)

o  mapped

o  quadClickX: x y: y
quadrupleClick-click - select all

o  tripleClickX: x y: y
triple-click - select line under pointer

initialization & release
o  fetchDeviceResources
fetch device colors, to avoid reallocation at redraw time

o  initStyle
setup viewStyle specifics

o  initialize

o  initializeSaveAction

menu actions
o  appendTo: aFileName
append contents to a file named fileName

o  changeFont
pop up a fontPanel to change font

o  copySelection
copy contents into smalltalk copybuffer

o  defaultForGotoLine
return a default value to show in the gotoLine box

o  doPrint
print the contents on the printer

o  editMenu
return my popUpMenu

o  find
same as search - for VW compatibility

o  gotoLine
show a box to enter lineNumber for positioning;
The entered number may be prefixed by a + or -;
in this case, the linenumber is taken relative to the current position.

o  openSaveDialog
Ask user for filename using a fileSelectionBox
and save contents into that file.

o  save
save contents into a file
- ask user for filename using a fileSelectionBox.

o  saveAs: fileName
save the contents into a file named fileName

o  saveAs: aFilename doAppend: doAppend
save the contents into a file named fileName;
if doAppend is true, the views contents is appended to the existing
contents - otherwise, it overwrites any previous file contents.
on error return false otherwise return true

o  search
search for a string - show a box to enter searchpattern
- currently no regular expressions are handled.

o  search: patternArg ignoreCase: ign forward: fwd
search for a string without matching

o  search: patternArg ignoreCase: ign match: match forward: fwd

private
o  currentSelectionBgColor

o  currentSelectionFgColor

o  fileOutContentsOn: aStream
save contents on a stream, replacing leading spaces by tab-characters.

o  fileOutContentsOn: aStream compressTabs: compressTabs
save contents on a stream. If compressTabs is true,
leading spaces will be replaced by tab-characters in the output.

o  fileOutContentsOn: aStream compressTabs: compressTabs encoding: encodingSymOrNil
save contents on a stream. If compressTabs is true,
leading spaces will be replaced by tab-characters in the output.

o  getFontParameters
get some info of the used font. They are cached since we use them often ..
This is redefined here, to use the fonts maxHeight/maxAscent for
line separation. This is required, to allow for proper handling of
national characters, such as A-dieresis ...

o  isClosingParenthesis: ch

o  isOpeningParenthesis: ch

o  rememberSearchPattern: pattern

o  removeTrailingWhitespace

o  resetVariablesBeforeNewSearch
clear the autosearch action, when the first pattern is searched for

o  scrollSelectDown
auto scroll action; scroll and reinstall timed-block

o  scrollSelectLeft
auto scroll action; scroll and reinstall timed-block

o  scrollSelectRight
auto scroll action; scroll and reinstall timed-block

o  scrollSelectUp
auto scroll action; scroll and reinstall timed-block

o  stopScrollSelect
stop auto scroll; deinstall timed-block

o  widthForScrollBetween: firstLine and: lastLine
return the width in pixels for a scroll between firstLine and lastLine

queries
o  hasSearchActionSelection
Here we fake the use of typeOfSelection which is really in EditTextView

o  isTextView
I am showing text

o  specClass
redefined, since the name of my specClass is nonStandard (i.e. not TextViewSpec)

redrawing
o  clearMarginOfVisibleLine: visLine with: color
if there is a margin, clear it - a helper for selection drawing

o  drawSelectedFromVisibleLine: startVisLineNr to: endVisLineNr

o  drawVisibleLineSelected: visLineNr

o  drawVisibleLineSelected: visLineNr col: col

o  drawVisibleLineSelected: visLineNr from: selectionStartCol

o  drawVisibleLineSelected: visLineNr from: startCol to: endCol

o  redrawFromVisibleLine: startVisLineNr to: endVisLineNr
redraw a visible line range

o  redrawMarginOfVisibleLine: visLine
draw margin - a helper for selection drawing

o  redrawVisibleLine: visLineNr
redraw visible line lineNr

o  redrawVisibleLine: visLine col: col
redraw single character at col in visible line lineNr.

o  redrawVisibleLine: visLine from: startCol
redraw visible line lineNr from startCol to end of line

o  redrawVisibleLine: visLine from: startCol to: endCol
redraw visible line lineNr from startCol to endCol

searching
o  clearSearchAction

o  scanFor: aCharacter fromLine: startLine col: startCol forward: forward ifFound: foundBlock ifNotFound: notFoundBlock
search for a character in the direction given by forward.
Performs foundBlock with line/col as argument if found, notFoundBlock if not.

o  searchAction

o  searchAction: aSearcherOrSearchBlock

o  searchAgainInSameDirection
search again in the same direction and -if found- position cursor

o  searchBwd
search backward and -if found- position cursor

o  searchBwd: pattern
do a backward search

o  searchBwd: pattern ifAbsent: aBlock
do a backward search

o  searchBwd: pattern ignoreCase: ign
do a backward search

o  searchBwd: pattern ignoreCase: ign ifAbsent: aBlock
do a backward search

o  searchBwd: pattern ignoreCase: ign match: match
do a backward search.
match pattern functionality is not yet available for backward search

o  searchForAndSelectMatchingParenthesisFromLine: startLine col: startCol
select characters enclosed by matching parenthesis if one is under startLine/Col

o  searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.

o  searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock ignoring: ignoreSet
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.

o  searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock openingCharacters: openingCharacters closingCharacters: closingCharacters
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.

o  searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock openingCharacters: openingCharacters closingCharacters: closingCharacters ignoredCharacters: ignoreSet specialEOLComment: eolCommentSequence
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.

o  searchFwd
search forward for pattern or selection

o  searchFwd: pattern
do a forward search

o  searchFwd: pattern ifAbsent: aBlock
do a forward search

o  searchFwd: pattern ignoreCase: ign
do a forward search

o  searchFwd: pattern ignoreCase: ign ifAbsent: aBlock
do a forward search

o  searchFwd: pattern ignoreCase: ign match: match
do a forward search

o  searchFwd: pattern ignoreCase: ign match: match ifAbsent: aBlock
do a forward search

o  searchFwd: pattern ignoreCase: ign match: match startingAtLine: startLine col: startCol ifAbsent: aBlock
do a forward search

o  searchPattern
return the last search pattern

o  searchUsingSearchAction: direction

o  searchUsingSearchAction: direction ifAbsent: notFoundAction

o  setSearchPattern
set the searchpattern from the selection if there is one

o  setSearchPattern: aStringOrNil
set the searchpattern for future searches

o  setSearchPattern: aString ignoreCase: aBoolean
set the searchpattern and caseIgnore for future searches

o  setSearchPatternWithMatchEscapes: match
set the searchpattern from the selection if there is one

o  showMatch: pattern atLine: line col: col
after a search, highlight the matched pattern.
The code below needs a rewrite to take care of match-characters
(for now, it only highlights simple patterns and '*string*' correctly)

o  showMatch: pattern isMatch: isMatch atLine: line col: col
after a search, highlight the matched pattern.
The code below needs a rewrite to take care of match-characters
(for now, it only highlights simple patterns and '*string*' correctly)

o  showNotFound
search not found - tell user by beeping and changing
cursor for a while (sometimes I work with a headset :-)
(used to be: tell user by changing cursor for a while)

o  startPositionForSearchBackward

o  startPositionForSearchBackwardBasedOnSelection

o  startPositionForSearchForward

o  startPositionForSearchForwardBasedOnSelection

selections
o  changeTypeOfSelectionTo: newType
ignored here - but redefined in subclasses which
differentiate between pasted- and user-selections

o  expandSelectionDown

o  expandSelectionLeft

o  expandSelectionRight

o  expandSelectionUp

o  hasSelection
return true, if there is a selection

o  hasSelectionForCopy
return true, if there is a selection which can be copyied
(the same as #hasSelection, except for editfields in password-mode)

o  hasSelectionWithinSingleLine
return true, if there is a selection and it is within a line

o  isInSelection: line col: aColNr
returns true, if the line, and column is in the selection

o  makeSelectionVisible
scroll to make the selection visible

o  selectAll
select the whole text

o  selectFromCharacterPosition: pos1
compute line/col from the character position and select the text up to the end

o  selectFromCharacterPosition: pos1 to: pos2
compute line/col from character positions and select the text

o  selectFromLine: startLine col: startCol toLine: endLine col: endCol
select a piece of text and redraw that area

o  selectFromLine: startLine toLine: endLine
select a piece of text and redraw that area

o  selectLine: selectLine
select one line and redraw it

o  selectLineAtY: y
select the line at given y-(view-)coordinate

o  selectLineWhereCharacterPosition: pos
select the line, where characterPosition pos is living.
The argument pos starts at 1 from the start of the text
and counts characters (i.e. can be used to convert from
character position within a string to line-position in view).

o  selectWordAtLine: line col: col
select the word at given line/col

o  selectWordAtX: x y: y
select the word at given x/y-(view-)coordinate

o  selectedInterval
return the selection-boundaries as interval

o  selection
return the selection as a collection of (line-)strings.
If the selection ends in a full line, the last entry in the returned
collection will be an empty string.

o  selectionAsString
return the selection as a String (i.e. without emphasis)

o  selectionChanged
can be redefined for notification or special actions

o  selectionEndCol

o  selectionEndLine

o  selectionStartCol

o  selectionStartLine

o  st80SelectMode

o  st80SelectMode: aBoolean

o  unselect
unselect - if there was a selection redraw that area

o  unselectWithoutRedraw
forget selection but do not redraw the selection area
- can be done when the selected area is redrawn anyway or
known to be invisible (however, redraw knows about that anyway).

o  validateNewSelection
make certain that the selection is valid.
This is a dummy here, but subclasses (like single-line editFields)
may redefine it to limit the selection to a single line, or whatever.


Examples:


although textViews (and instances of subclasses) are mostly used as components (in the fileBrowser, the browser, the launcher etc.), they may also be opened as a textEditor; open a (readonly) textView on some information text:


    TextView 
        openWith:'read this' 
        title:'demonstration'
the same, but open it modal:


    TextView 
        openModalWith:'read this first' 
        title:'demonstration'
open it modal (but editable) on some text: (must accept before closing) This is somewhat kludgy - when closed, the view has already nilled its link to the model. Therefore, the accept must be done 'manually' below. However, usually an applicationModel is installed as the editor-topViews application. This would get a closeRequest, where it could handle things.


    |m textView|

    m := 'read this first' asValue.
    textView := EditTextView openModalOnModel:m.
    textView modified ifTrue:[
        (self confirm:'text was not accepted - do it now ?')
        ifTrue:[
            m value:textView contents
        ]
    ].

    Transcript showCR:m value.
open a textEditor on some file:


    EditTextView openOn:'Makefile'


ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 21:34:45 GMT