File: u_base_datawindow.sru
Size: 3539
Date: Tue, 22 Aug 2017 17:30:58 +0200
$PBExportHeader$u_base_datawindow.sru
forward
global type u_base_datawindow from datawindow
end type
end forward

global type u_base_datawindow from datawindow
integer width = 686
integer height = 400
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type
global u_base_datawindow u_base_datawindow

type variables
String is_sort

end variables

forward prototypes
public subroutine of_gridsort_arrows (unsignedlong aul_color)
end prototypes

public subroutine of_gridsort_arrows (unsignedlong aul_color);// add arrows to grid column headers to indicate sorting

Integer li_col, li_max
String ls_syntax, ls_xpos, ls_width, ls_name, ls_color, ls_exprsn

// bail out if not a valid grid datawindow
If this.DataObject = "" Then Return
If this.Object.DataWindow.Processing <> "1" Then Return

// loop thru all visible columns
li_max = Integer(this.Object.DataWindow.Column.Count)
FOR li_col = 1 TO li_max
   // process column if visible
   If this.Describe("#" + String(li_col) + ".Visible") = "1" Then
      // get columns name
      ls_name = this.Describe("#" + String(li_col) + ".Name")
      // build parts of the syntax
      ls_xpos  = this.Describe(ls_name + ".X")
      ls_width = this.Describe(ls_name + ".Width")
      ls_color = String(aul_color)
      // build compute expression
      ls_exprsn  = "~"if(pos(lower(describe('datawindow.table.sort')), '"
      ls_exprsn += ls_name + " a') > 0, '5', "
      ls_exprsn += "if(pos(lower(describe('datawindow.table.sort')), '"
      ls_exprsn += ls_name + " d') > 0, '6', "
      ls_exprsn += "if(pos(lower(describe('datawindow.table.sort')), '"
      ls_exprsn += "lookupdisplay(" + ls_name + ") a') > 0, '5', "
      ls_exprsn += "if(pos(lower(describe('datawindow.table.sort')), '"
      ls_exprsn += "lookupdisplay(" + ls_name + ") d') > 0, '6', ''))))~" "
      // build create computed column syntax
      ls_syntax  = "create compute( band=header alignment=~"1~" expression=" + ls_exprsn
      ls_syntax += "border=~"0~" color=~"" + ls_color + "~" x=~"" + ls_xpos + "~" y=~"8~" "
      ls_syntax += "height=~"48~" width=~"" + ls_width + "~" format=~"[general]~" "
      ls_syntax += "name=" + ls_name + "_a font.face=~"Marlett~" font.height=~"-10~" "
      ls_syntax += "font.weight=~"400~" font.family=~"0~" font.pitch=~"2~" font."
      ls_syntax += "charset=~"2~" background.mode=~"1~" background.color=~"553648127~" )"
      // create the computed column
      this.Modify(ls_syntax)
      this.SetPosition(ls_name + "_a", "header", True)
   End If
NEXT

end subroutine

event clicked;String ls_name, ls_sort

// sort grid datawindow if header clicked on
If this.Object.DataWindow.Processing = "1" Then
   ls_name = dwo.Name
   If Right(ls_name, 2) = "_a" or Right(ls_name, 2) = "_t" Then
      ls_name = Left(ls_name, Len(ls_name) - 2)
      // if this is a dropdown, sort on display value not data value
      If this.Describe(ls_name + ".Edit.Style") = "dddw" Or &
         this.Describe(ls_name + ".Edit.CodeTable") = "yes" Then
         ls_name = "LookUpDisplay(" + ls_name + ")"
      End If
      ls_sort = ls_name + " A"
      If ls_sort = is_sort Then
         is_sort = ls_name + " D"
      Else
         is_sort = ls_sort
      End If
      this.SetSort(is_sort)
      this.Sort()
      this.Event RowFocusChanged(this.GetRow())
   End If
End If

// get out if user clicked in a non-row area
If row = 0 Then Return

end event

on u_base_datawindow.create
end on

on u_base_datawindow.destroy
end on

event rowfocuschanged;this.SelectRow(0, False)
this.SelectRow(currentrow, True)

end event