File: n_base_dropdown.sru
Size: 7957
Date: Mon, 07 Apr 2008 21:31:49 +0200
$PBExportHeader$n_base_dropdown.sru
$PBExportComments$Base dropdown class
forward
global type n_base_dropdown from n_base
end type
end forward

global type n_base_dropdown from n_base
event ke_setdwvalue ( readonly u_dw_form adw,  readonly long al_row,  readonly string as_colname,  readonly any aa_value )
event ke_setobjectvalue ( readonly powerobject apo,  readonly string as_eventname,  readonly any aa_value )
end type
global n_base_dropdown n_base_dropdown

type variables
Protected:
string #WindowClassname = "w_base_dropdown"
w_base_dropdown iw_dropdown
Powerobject ipo_source
//datawindow source
Datawindow idw_source
string is_column, is_eventname
long il_row
any ia_return
boolean ib_cancel
end variables

forward prototypes
public subroutine of_setreturnvalue (readonly any aa_value)
public subroutine of_cancel ()
public subroutine of_showdropdown (readonly u_dw_form adw, readonly long al_row, readonly string as_colname)
public function any of_getreturnvalue ()
public subroutine of_showdropdown (readonly powerobject apo, readonly string as_eventname, readonly any aa_initvalue, readonly integer ai_x, readonly integer ai_y)
public subroutine of_showdropdowntoolbar (readonly u_toolbar auo_toolbar, readonly powerobject apo, readonly string as_eventname, readonly any aa_initvalue, readonly integer ai_x, readonly integer ai_y)
public subroutine of_showdropdownbelow (readonly dragobject ado, readonly string as_eventname, readonly any aa_initvalue)
public subroutine of_showdropdowntoolbar (readonly u_dwtoolbar auo_toolbar, readonly powerobject apo, readonly string as_eventname, readonly any aa_initvalue, readonly integer ai_x, readonly integer ai_y)
end prototypes

event ke_setdwvalue(readonly u_dw_form adw, readonly long al_row, readonly string as_colname, readonly any aa_value);IF ISVALID(idw_source) THEN
   IF al_row <= adw.RowCount() THEN
      adw.SetItem(al_row, as_colname, aa_value)
      adw.AcceptText()
   END IF
END IF
end event

event ke_setobjectvalue(readonly powerobject apo, readonly string as_eventname, readonly any aa_value);//notify object
IF ISVALID(apo) THEN
   apo.TriggerEvent(as_eventname, 0, this.ClassName())
END IF
end event

public subroutine of_setreturnvalue (readonly any aa_value);ia_return = aa_value

IF ISVALID(idw_source) THEN EVENT ke_setdwvalue(idw_source, il_row, is_column, ia_return)
IF ISVALID(ipo_source) THEN EVENT ke_setobjectvalue(ipo_source, is_eventname, ia_return)

IF ISVALID(iw_dropdown) THEN CLOSE(iw_dropdown)
end subroutine

public subroutine of_cancel ();ib_cancel = TRUE
IF ISVALID(iw_dropdown) THEN CLOSE(iw_dropdown)
end subroutine

public subroutine of_showdropdown (readonly u_dw_form adw, readonly long al_row, readonly string as_colname);idw_source = adw
il_row = al_row
is_column = as_colname

n_svc_mgr lnv_svc
n_svc_dw_form lnv_dw
n_svc_win32 lnv_win32
long llx, lly, ll_vpos, ll_hpos, ScreenX, ScreenY
long ll_firstrow, ll_detailheight
any la_ret
RECT rc

lnv_svc.of_LoadSvc(lnv_dw, "n_svc_dw_form")
lnv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)
la_ret = lnv_dw.of_GetItemAny(adw, al_row, as_colname)

lnv_win32.GetWindowRect(Handle(adw), rc)
rc.top = PixelsToUnits(rc.top, YPixelsToUnits!)
rc.left = PixelsToUnits(rc.left, XPixelsToUnits!)     
llx = integer(adw.Describe(is_column + ".X")) + rc.left - 4
lly = integer(adw.Describe(is_column + ".Y")) + rc.top + integer(adw.Describe(is_column + ".height")) + 4
//offset row
IF adw.RowCount() > 1 THEN
   ll_firstrow = integer(adw.Describe("DataWindow.FirstRowOnPage"))
   ll_detailheight = integer(adw.Describe("DataWindow.Detail.height"))
   lly += ((il_row - ll_firstrow) * ll_detailheight) + 72
   ll_hpos = integer(adw.Describe("DataWindow.HorizontalScrollPosition"))
   IF ll_hpos > 0 THEN llx -= ll_hpos  
ELSE
   //offset scrollbars
   ll_vpos = integer(adw.Describe("DataWindow.VerticalScrollPosition"))
   ll_hpos = integer(adw.Describe("DataWindow.HorizontalScrollPosition"))
   IF ll_vpos > 0 THEN lly -= ll_vpos
   IF ll_hpos > 0 THEN llx -= ll_hpos  
END IF

//check screen resolution against window position
Environment le
GetEnvironment(le)

ScreenX = PixelsToUnits(le.ScreenWidth, XPixelsToUnits!)
ScreenY = PixelsToUnits(le.ScreenHeight, YPixelsToUnits!)

//open window
OPENWITHPARM(iw_dropdown, this, #windowclassname)
//do events
DoPosts()
//bottom & right
IF (llx + iw_dropdown.width) > ScreenX THEN llx = (ScreenX - iw_dropdown.width)
IF (lly + iw_dropdown.height) > ScreenY THEN 
   IF ISVALID(adw) THEN
      lly -= iw_dropdown.height + integer(adw.Describe(is_column + ".height"))
   ELSE
      lly -= iw_dropdown.height + (rc.bottom - rc.top)
   END IF
END IF

//left
IF llx < 0 THEN llx = 0
iw_dropdown.of_setinitialvalue(la_ret)
iw_dropdown.Move(llx, lly)
//do post
DoPosts()
iw_dropdown.Show()
end subroutine

public function any of_getreturnvalue ();RETURN ia_return
end function

public subroutine of_showdropdown (readonly powerobject apo, readonly string as_eventname, readonly any aa_initvalue, readonly integer ai_x, readonly integer ai_y);ipo_source = apo
is_eventname = as_eventname

long llx, lly, ScreenX, ScreenY
RECT rc
n_svc_mgr lnv_svc
n_svc_win32 lnv_win32

lnv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)
lnv_win32.GetWindowRect(Handle(apo), rc)

llx = ai_x
lly = ai_y

//check screen resolution against window position
Environment le
GetEnvironment(le)

ScreenX = PixelsToUnits(le.ScreenWidth, XPixelsToUnits!)
ScreenY = PixelsToUnits(le.ScreenHeight, YPixelsToUnits!)

//open window
OPENWITHPARM(iw_dropdown, this, #windowclassname)
//do events
DoPosts()
////bottom & right
IF (llx + iw_dropdown.width) > ScreenX THEN llx = (ScreenX - iw_dropdown.width)
IF (lly + iw_dropdown.height) > ScreenY THEN lly = (ScreenY - iw_dropdown.Height)
//IF (lly + iw_dropdown.height) > ScreenY THEN 
// lly -= iw_dropdown.height + (rc.bottom - rc.top)
//END IF

//left
IF llx < 0 THEN llx = 0
iw_dropdown.of_setinitialvalue(aa_initvalue)
iw_dropdown.Move(llx, lly)
//do post
DoPosts()
iw_dropdown.Show()
end subroutine

public subroutine of_showdropdowntoolbar (readonly u_toolbar auo_toolbar, readonly powerobject apo, readonly string as_eventname, readonly any aa_initvalue, readonly integer ai_x, readonly integer ai_y);integer lix, liy

lix = ai_x + auo_toolbar.of_GetParentWindow().X + 24
liy = ai_y + auo_toolbar.of_GetParentWindow().Y + auo_toolbar.height

n_svc_mgr lnv_svc
n_svc_system lnv_sys

lnv_svc.of_LoadSvc(lnv_sys, CSvc.SYS)

IF lnv_sys.of_issysthemed() THEN
   liy += 28
END IF

of_showdropdown(apo, as_eventname, aa_initvalue, lix, liy)
end subroutine

public subroutine of_showdropdownbelow (readonly dragobject ado, readonly string as_eventname, readonly any aa_initvalue);long llx, lly
RECT rc
n_svc_mgr lnv_svc
n_svc_win32 lnv_win32

lnv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)
lnv_win32.GetWindowRect(Handle(ado), rc)

llx = PixelsToUnits(rc.left, XPixelsToUnits!)
lly = PixelsToUnits(rc.top, YPixelsToUnits!) + ado.Height

of_ShowDropdown(ado, as_eventname, aa_initvalue, llx, lly)
end subroutine

public subroutine of_showdropdowntoolbar (readonly u_dwtoolbar auo_toolbar, readonly powerobject apo, readonly string as_eventname, readonly any aa_initvalue, readonly integer ai_x, readonly integer ai_y);integer lix, liy

lix = ai_x //+ auo_toolbar.of_GetParentWindow().X + 24
liy = ai_y //+ auo_toolbar.of_GetParentWindow().Y + auo_toolbar.height

RECT rc
n_svc_mgr lnv_svc
n_svc_win32 lnv_win32

lnv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)
lnv_win32.GetWindowRect(Handle(auo_toolbar.dw_1), rc)

rc.left = PixelsToUnits(rc.left, XPixelsToUnits!)
rc.top = PixelsToUnits(rc.top, YPixelsToUnits!)

of_showdropdown(apo, as_eventname, aa_initvalue, rc.left + lix, rc.top + liy)
end subroutine

on n_base_dropdown.create
call super::create
end on

on n_base_dropdown.destroy
call super::destroy
end on