Code:
{define-proc public {get-vscroll}:#Scrollbar
let vscroll:#Scrollbar = null
{walk-graphics
self,
{proc {g:Graphic}:void
{type-switch g
case grid:Grid do
{for c in grid.graphical-children do
{if {type-of c}.name == "\{DisplayFrame-of Scrollbar\}" then
{type-switch c
case bf:BaseFrame do
def (val:Graphic, eof?:bool) =
{bf.graphical-children.read-one}
{if not eof? then
{type-switch val
case sb:Scrollbar do
set vscroll = sb
}
}
}
}
}
}
}
}
{return vscroll}
}
Code:
{import * from COM.CURL.SONNTAG.LIB}
{define-class public CustomRecordGrid {inherits RecordGrid}
{constructor public {default ...}
{construct-super{splice ...}}
}
||縦スクロールの取得
{method public {get-vscroll}:#Scrollbar
{return {self.get-scroll Orientation.vertical}}
}
||横スクロールの取得
{method public {get-hscroll}:#Scrollbar
{return {self.get-scroll Orientation.horizontal}}
}
||グリッド内のスクロールの取得
{method private {get-scroll direction:Orientation}:#Scrollbar
let scroll:#Scrollbar = null
{walk-graphics
self,
ensure-ui-generated? = true,
{proc {g:Graphic}:void
{if {type-of g}.name == "\{DisplayFrame-of Scrollbar\}" then
{type-switch g
case bf:BaseFrame do
def (val:Graphic, eof?:bool) =
{bf.graphical-children.read-one}
{if not eof? then
{type-switch val
case sb:Scrollbar do
{if sb.direction == direction then
set scroll = sb
{return}
}
}
}
}
}
}
}
{return scroll}
}
}
{def rs =
{RecordSet
{RecordFields
{RecordField "a", nullable? = true},
{RecordField "b", nullable? = true},
{RecordField "c", nullable? = true},
{RecordField "d", nullable? = true},
{RecordField "e", nullable? = true},
{RecordField "f", nullable? = true},
{RecordField "g", nullable? = true},
{RecordField "h", nullable? = true},
{RecordField "i", nullable? = true}
}
}
}
{def grid =
{CustomRecordGrid record-source = rs }
}
{for i:int = 0 to 50 do
def new-r = {rs.new-record}
{rs.append new-r}
}
{VBox grid,
{CommandButton
label = "縦スクロールのリセット",
{on Action do
{if-non-null sb = {grid.get-vscroll} then
{sb.set-scroll-value 0}
}
}
},
{CommandButton
label = "横スクロールのリセット",
{on Action do
{if-non-null sb = {grid.get-hscroll} then
{sb.set-scroll-value 0}
}
}
},
{CommandButton
label = "両スクロールのリセット",
{on Action do
{if-non-null sb = {grid.get-vscroll} then
{sb.set-scroll-value 0}
}
||なぜか連続で呼ぶと正常に振舞わないのでdispatchする
{dispatch-events false}
{if-non-null sb = {grid.get-hscroll} then
{sb.set-scroll-value 0}
}
}
}
}