Curl Global Community

Full Version: RecordGrid の縦のスクロールバー
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
RecordGrid の縦のスクロールバーを操作したいです。
ScrollBox であれば、get-vscroll で取得できると思いますが、
RecordGrid には、このプロパティがありません。

取得方法があれば教えてください。
とりあえず、下記の記述で私の環境では取得できました。

バージョンや、クラスの継承状況によって、取得できない可能性が高いです。

Curl のコアAPI の機能として提供されることを強く望みます。

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}
            }
        }
    }
}