Difference between revisions of "Writer/API/View cursor"
m (→See also: + cat Basic:Tutorials) |
m |
||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | + | {{Writer Project|Category=Writer/API}} | |
+ | __TOC__ | ||
− | =Accessing the view cursor= | + | == Accessing the view cursor == |
A view cursor in text document is referenced as follows: | A view cursor in text document is referenced as follows: | ||
− | < | + | <syntaxhighlight lang="oobas"> |
oVC = thisComponent.getCurrentController.getViewCursor | oVC = thisComponent.getCurrentController.getViewCursor | ||
− | </ | + | </syntaxhighlight> |
It is the only way to move within the page layout. For example to find the start of a line, the top of a page. | It is the only way to move within the page layout. For example to find the start of a line, the top of a page. | ||
− | =Moving the view cursor= | + | == Moving the view cursor == |
− | < | + | <syntaxhighlight lang="oobas"> |
bExtend = false | bExtend = false | ||
oVC.goLeft(5, bExtend) 'go left 5 characters | oVC.goLeft(5, bExtend) 'go left 5 characters | ||
Line 31: | Line 32: | ||
oVC.jumpToPreviousPage | oVC.jumpToPreviousPage | ||
oVC.jumpToStartOfPage | oVC.jumpToStartOfPage | ||
− | </ | + | </syntaxhighlight> |
− | =Using view cursor to find location on page= | + | == Using view cursor to find location on page == |
The following routine returns the current insertion points location on a page in terms of lines and characters. The number of characters is meaningless if the insertion point is in a table. | The following routine returns the current insertion points location on a page in terms of lines and characters. The number of characters is meaningless if the insertion point is in a table. | ||
− | < | + | <syntaxhighlight lang="oobas"> |
function fnPosn(oDoc) | function fnPosn(oDoc) | ||
set mCurSelection = oDoc.currentSelection ' Record current selection | set mCurSelection = oDoc.currentSelection ' Record current selection | ||
Line 58: | Line 59: | ||
fnPosn = "(" & nx & ", " & nY & ")" | fnPosn = "(" & nx & ", " & nY & ")" | ||
end function | end function | ||
− | </ | + | </syntaxhighlight> |
To call this code: | To call this code: | ||
− | < | + | <syntaxhighlight lang="oobas"> |
msgbox fnPosn(thisComponent) | msgbox fnPosn(thisComponent) | ||
− | </ | + | </syntaxhighlight> |
− | ==Updating the status bar with the insertion points current location== | + | == Updating the status bar with the insertion points current location == |
This code could be called whenever a key is pressed or the mouse clicked so that the status bar is updated with the current insertion point location. As follows: | This code could be called whenever a key is pressed or the mouse clicked so that the status bar is updated with the current insertion point location. As follows: | ||
− | < | + | <syntaxhighlight lang="oobas"> |
global Iannz_TSB_Controller, Iannz_TSB_MouseClickHandler, Iannz_TSB_KeyHandler | global Iannz_TSB_Controller, Iannz_TSB_MouseClickHandler, Iannz_TSB_KeyHandler | ||
Line 131: | Line 132: | ||
end if | end if | ||
end sub | end sub | ||
− | </ | + | </syntaxhighlight> |
== See also == | == See also == | ||
* [[Text cursor| Text cursors]] | * [[Text cursor| Text cursors]] | ||
− | [[Category: | + | [[Category:StarBasic]] |
Latest revision as of 13:49, 5 March 2021
Please view the guidelines
|
---|
Popular Subcategories: <DPL> category=+**Writer namespace=Category ordermethod=counter order=descending count=5 </DPL> Internal Documentation: <DPL> category=+Writer/CoreDoc ordermethod=counter order=descending count=5 namespace= </DPL> API Documentation: Ongoing Efforts: <DPL> category=+Writer/Effort ordermethod=counter order=descending count=5 namespace= </DPL> Projects on this Wiki: (edit list)
|
Sw.OpenOffice.org |
Accessing the view cursor
A view cursor in text document is referenced as follows:
oVC = thisComponent.getCurrentController.getViewCursor
It is the only way to move within the page layout. For example to find the start of a line, the top of a page.
Moving the view cursor
bExtend = false
oVC.goLeft(5, bExtend) 'go left 5 characters
oVC.goRight(10, bExtend) 'go right 10 characters
oVC.gotoStart(bExtend) 'go to the start of the text range
oVC.gotoEnd(bExtend) 'go to the end of the text range
oVC.gotoRange(oCursor, false) 'view cursor can go anywhere
oVC.goDown(2, bExtend)
oVC.goLeft(3, bExtend)
oVC.goUp(1, bExtend)
oVC.gotoEndOfLine(bExtend)
oVC.gotoStartOfLine(bExtend)
oVC.jumpToEndOfPage
oVC.jumpToFirstPage
oVC.jumpToLastPage
oVC.jumpToNextPage
oVC.jumpToPage(2, false)
oVC.jumpToPreviousPage
oVC.jumpToStartOfPage
Using view cursor to find location on page
The following routine returns the current insertion points location on a page in terms of lines and characters. The number of characters is meaningless if the insertion point is in a table.
function fnPosn(oDoc)
set mCurSelection = oDoc.currentSelection ' Record current selection
'Locking controller prevents flicker. But under ALL circumstances must be unlocked
on local error goto finished:
oDoc.lockControllers
oVC = oDoc.getCurrentController.getViewCursor
oVC.collapseToEnd 'Move view Cursor
oVC.gotoStartofLine(true)
nX = len(oVC.string) 'How many characters from the start of the line
nY = 0
'How many lines from top of page
nPage = oVC.getPage
while oVC.goUp(1,false) and oVC.getPage = nPage
nY = nY + 1
wend
thisComponent.currentController.select(mCurSelection) 'Restore current selection
finished:
on error goto 0
oDoc.unlockControllers
fnPosn = "(" & nx & ", " & nY & ")"
end function
To call this code:
msgbox fnPosn(thisComponent)
Updating the status bar with the insertion points current location
This code could be called whenever a key is pressed or the mouse clicked so that the status bar is updated with the current insertion point location. As follows:
global Iannz_TSB_Controller, Iannz_TSB_MouseClickHandler, Iannz_TSB_KeyHandler
sub subSetupCustomStatusBar
Iannz_TSB_Controller = thisComponent.currentController
Iannz_TSB_MouseClickHandler = CreateUnoListener("MouseClickHandler_","com.sun.star.awt.XMouseClickHandler")
Iannz_TSB_Controller.addMouseClickHandler(Iannz_TSB_MouseClickHandler)
Iannz_TSB_KeyHandler = CreateUnoListener("KeyHandler_","com.sun.star.awt.XKeyHandler")
Iannz_TSB_Controller.addKeyHandler(Iannz_TSB_KeyHandler)
end sub
sub subRemoveCustomStatusBar
if not isNull(Iannz_TSB_Controller) and not isEmpty(Iannz_TSB_Controller) then
oStatus = Iannz_TSB_Controller.Frame.createStatusIndicator
oStatus.end
Iannz_TSB_Controller.removeMouseClickHandler(Iannz_TSB_MouseClickHandler)
Iannz_TSB_Controller.removeKeyHandler(Iannz_TSB_KeyHandler)
end if
end sub
Sub MouseClickHandler_MousePressed(Event As Object)
Iannz_TSB_Controller.addMouseClickHandler(Iannz_TSB_MouseClickHandler)
end sub
sub MouseClickHandler_mouseReleased
subChangeStatusBar
Iannz_TSB_Controller.addMouseClickHandler(Iannz_TSB_MouseClickHandler)
end sub
sub MouseClickHandler_disposing
end sub
function KeyHandler_KeyPressed
KeyHandler_KeyPressed = false
end function
function KeyHandler_KeyReleased
subChangeStatusBar
KeyHandler_KeyReleased = false
end function
sub KeyHandler_disposing
end sub
sub subChangeStatusBar
oDoc = thisComponent
oVC = Iannz_TSB_Controller.viewCursor
oStatus = Iannz_TSB_Controller.Frame.createStatusIndicator
oStatus.end
if oVC.isCollapsed and isEmpty(oVC.getPropertyValue("Cell")) then
oStatus.start(fnPosn(thisComponent),100)
end if
end sub