File: u_splitcontainer.sru
Size: 10161
Date: Mon, 07 Apr 2008 21:31:58 +0200
$PBExportHeader$u_splitcontainer.sru
$PBExportComments$Split Container
forward
global type u_splitcontainer from u_base
end type
type st_label from statictext within u_splitcontainer
end type
end forward

global type u_splitcontainer from u_base
integer width = 768
integer height = 580
boolean border = true
string pointer = "SizeWE!"
event ke_mousemove pbm_mousemove
event ke_lbuttondown pbm_lbuttondown
event ke_lbuttonup pbm_lbuttonup
event ke_resize pbm_size
event ke_lbuttondoubleclick pbm_lbuttondblclk
event ke_showsplitpart ( readonly integer part )
st_label st_label
end type
global u_splitcontainer u_splitcontainer

type variables
Public:
boolean #VerticalOrientation, #LockSizing
integer #FixedPanelOnResize = CSplitcontainer.TOPLEFT;
string #LeftTopControl, #RightBottomControl
integer #SplitterWidth = 3, #MinControlSize = 100
integer #ShowPart = 0
boolean #UseThemeColors = TRUE
dragobject ido_lefttop, ido_rightbottom
mdiclient imdi, imdi_l

Private:
boolean MOUSEDOWN
CONSTANT string SPLIT_SERVICE = "n_svc_splitcontainer"
integer ii_SplitterLocation = -1
integer ii_touchdown
integer il_lastpos, ii_original_splitter_width
RECT str_capture

long NormalColor

int ii_splitPart = 0
string is_pointer
end variables
forward prototypes
public subroutine of_setvertical (readonly boolean ab_vertical)
public subroutine of_setsplitcontrols (dragobject ado_lefttop, dragobject ado_rightbottom)
public function integer of_getsplitterwidth ()
public subroutine of_setsplitterwidth (readonly integer ai_splitterwidth)
public subroutine of_resizecontrols ()
public subroutine of_setsplitterlocation (readonly integer ai_location)
public function integer of_getsplitterlocation ()
protected subroutine of_setsplitcontrols (readonly string as_lefttop, readonly string as_rightbottom)
public subroutine of_splitterhalf ()
private subroutine of_capturemouse ()
private subroutine of_releasemouse ()
public subroutine of_unregistercontrols ()
public subroutine of_showsplitpart (readonly integer ai_part)
public subroutine of_locksizing (readonly boolean ab_set)
public subroutine of_setsplitterpercent (readonly integer ai_percent)
public subroutine of_setsplitcontrols (dragobject ado_lefttop, mdiclient amdiclient)
public subroutine of_setsplitcontrols (mdiclient amdiclient, dragobject ado_rightbottom)
public function integer of_getcurrentsplitpart ()
public subroutine of_usethemecolors (readonly boolean ab_usetheme)
end prototypes

event ke_mousemove;integer li_diff, li_new

IF #LockSizing THEN RETURN

IF MOUSEDOWN THEN
   IF #verticalorientation THEN
      li_new = ypos
   ELSE
      li_new = xpos
   END IF
   
   IF il_lastpos = li_new THEN RETURN
   
   il_lastpos = li_new

   IF li_new > ii_touchdown THEN
      li_diff = li_new - ii_touchdown
   ELSE
      li_diff = (ii_touchdown - li_new) * -1
   END IF
   
   ii_splitterlocation += li_diff   
   
   this.of_resizecontrols()
   
   ii_touchdown = li_new
ELSE
   IF #VerticalOrientation THEN
      IF ISVALID(ido_lefttop) THEN
         IF ypos < ido_lefttop.height - 4 THEN
            this.Pointer = "Arrow!"
         ELSE
            this.Pointer = is_pointer
         END IF
      END IF
   ELSE
      IF ISVALID(ido_lefttop) THEN
         IF xpos < ido_lefttop.width - 4 THEN
            this.Pointer = "Arrow!"
         ELSE
            this.Pointer = is_pointer
         END IF
      END IF
   END IF
END IF
end event

event ke_lbuttondown;il_lastpos = -1

IF #LockSizing THEN RETURN

this.of_capturemouse()

MOUSEDOWN = TRUE

IF #verticalorientation THEN
   ii_touchdown = ypos
ELSE
   ii_touchdown = xpos
END IF
end event

event ke_lbuttonup;IF #LockSizing THEN RETURN

this.of_releasemouse()

MOUSEDOWN = FALSE

ii_touchdown = -1
end event

event ke_resize;of_resizecontrols()
end event

event ke_lbuttondoubleclick;IF #LockSizing THEN RETURN

this.of_splitterhalf()
end event

event ke_showsplitpart(readonly integer part);//fired when calling of_showsplitpart()
end event

public subroutine of_setvertical (readonly boolean ab_vertical);#VerticalOrientation = ab_vertical
IF #VerticalOrientation THEN
   this.Pointer = "SizeNS!"
ELSE
   this.Pointer = "SizeWE!"
END IF

is_pointer = this.Pointer

of_setsplitterwidth(ii_original_splitter_width)
end subroutine

public subroutine of_setsplitcontrols (dragobject ado_lefttop, dragobject ado_rightbottom);ido_lefttop = ado_lefttop
ido_rightbottom = ado_rightbottom
end subroutine

public function integer of_getsplitterwidth ();RETURN #splitterwidth
end function

public subroutine of_setsplitterwidth (readonly integer ai_splitterwidth);IF #verticalorientation THEN
   #splitterwidth = PixelsToUnits(ai_splitterwidth, YPixelsToUnits!)
ELSE
   #splitterwidth = PixelsToUnits(ai_splitterwidth, XPixelsToUnits!)
END IF
end subroutine

public subroutine of_resizecontrols ();n_svc_mgr lnv_svcman
n_svc_splitcontainer lnv_splitservice

IF ISVALID(ido_lefttop) AND ISVALID(ido_rightbottom) THEN
   lnv_svcman.of_loadsvc(lnv_splitservice, SPLIT_SERVICE)
   lnv_splitservice.of_resizecontrols( &
      this, &
      #VerticalOrientation, &
      ii_splitterlocation, &
      #splitterwidth, &    
      ii_splitpart, &
      #mincontrolsize, &
      ido_lefttop, &
      ido_rightbottom)
ELSEIF ISVALID(ido_lefttop) AND ISVALID(imdi) THEN
   lnv_svcman.of_loadsvc(lnv_splitservice, SPLIT_SERVICE)
   lnv_splitservice.of_resizecontrols( &
      this, &
      #VerticalOrientation, &
      ii_splitterlocation, &
      #splitterwidth, &    
      ii_splitpart, &
      #mincontrolsize, &
      ido_lefttop, &
      imdi)
ELSEIF ISVALID(ido_rightbottom) AND ISVALID(imdi_l) THEN
   lnv_svcman.of_loadsvc(lnv_splitservice, SPLIT_SERVICE)
   lnv_splitservice.of_resizecontrols( &
      this, &
      #VerticalOrientation, &
      ii_splitterlocation, &
      #splitterwidth, &    
      ii_splitpart, &
      #mincontrolsize, &
      imdi_l, &
      ido_rightbottom)
END IF
end subroutine

public subroutine of_setsplitterlocation (readonly integer ai_location);ii_splitterlocation = ai_location
end subroutine

public function integer of_getsplitterlocation ();RETURN ii_splitterlocation
end function

protected subroutine of_setsplitcontrols (readonly string as_lefttop, readonly string as_rightbottom);n_svc_mgr lnv_svcman
n_svc_splitcontainer lnv_splitservice

lnv_svcman.of_loadsvc(lnv_splitservice, SPLIT_SERVICE)
lnv_splitservice.of_setsplitcontrols(this, as_lefttop, as_rightbottom)
of_resizecontrols()
end subroutine

public subroutine of_splitterhalf ();//set 50%
of_setsplitterpercent(50)
end subroutine

private subroutine of_capturemouse ();n_svc_mgr lnsvc
n_svc_splitcontainer lnv_split
RECT lstr

//load service
lnsvc.of_loadsvc(lnv_split, SPLIT_SERVICE)
//capture mouse
lnv_split.of_capturemouse(this, str_capture)
end subroutine

private subroutine of_releasemouse ();n_svc_mgr lnsvc
n_svc_splitcontainer lnv_split
RECT lstr

//load service
lnsvc.of_loadsvc(lnv_split, SPLIT_SERVICE)
//release mouse
lnv_split.of_releasemouse(str_capture)
//revert color
this.BackColor = NormalColor
end subroutine

public subroutine of_unregistercontrols ();n_svc_mgr lnv_svcman
n_svc_splitcontainer lnv_splitservice

lnv_svcman.of_loadsvc(lnv_splitservice, SPLIT_SERVICE)
lnv_splitservice.of_unregistercontrols(this, ido_lefttop, ido_rightbottom)
end subroutine

public subroutine of_showsplitpart (readonly integer ai_part);ii_splitpart = ai_part
SetRedraw(FALSE)
of_resizecontrols()
SetRedraw(TRUE)
EVENT ke_showsplitpart(ii_splitpart)
end subroutine

public subroutine of_locksizing (readonly boolean ab_set);#LockSizing = ab_set

IF #LockSizing THEN
   this.Pointer = "Arrow!"
ELSE
   of_SetVertical(#VerticalOrientation)
END IF
end subroutine

public subroutine of_setsplitterpercent (readonly integer ai_percent);IF ai_percent > 100 THEN RETURN

IF #VerticalOrientation THEN
   ii_splitterLocation = ((this.height - PixelsToUnits(#splitterwidth, YPixelsToUnits!)) / 100) * ai_percent
ELSE
   ii_splitterLocation = ((this.width - PixelsToUnits(#splitterwidth, XPixelsToUnits!)) / 100) * ai_percent
END IF

of_resizecontrols()
end subroutine

public subroutine of_setsplitcontrols (dragobject ado_lefttop, mdiclient amdiclient);ido_lefttop = ado_lefttop
imdi = amdiclient
end subroutine

public subroutine of_setsplitcontrols (mdiclient amdiclient, dragobject ado_rightbottom);imdi_l = amdiclient
ido_rightbottom = ado_rightbottom
end subroutine

public function integer of_getcurrentsplitpart ();RETURN ii_splitpart
end function

public subroutine of_usethemecolors (readonly boolean ab_usetheme);#UseThemeColors = ab_usetheme

IF #UseThemeColors THEN
   n_svc_mgr lnv_svc
   n_svc_theme lnv_t
   str_theme lstr
   
   lnv_svc.of_LoadSvc(lnv_t, CSvc.THEME)
   lstr = lnv_t.of_GetTheme()
   this.Backcolor = lstr.Window
ELSE
   this.BackColor = CColor.BUTTON_FACE
END IF

NormalColor = this.BackColor
end subroutine

on u_splitcontainer.create
int iCurrent
call super::create
this.st_label=create st_label
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.st_label
end on

on u_splitcontainer.destroy
call super::destroy
destroy(this.st_label)
end on

event ke_postopen;call super::ke_postopen;this.Border = FALSE
st_label.Visible = FALSE
this.of_setvertical(#VerticalOrientation)
this.of_setsplitterwidth(#splitterwidth)
this.of_setsplitcontrols(#lefttopcontrol, #rightbottomcontrol)
this.of_LockSizing(#LockSizing)
IF #ShowPart > 0 THEN
   of_Showsplitpart(#ShowPart)
END IF
end event

event destructor;call super::destructor;this.of_unregistercontrols()
end event

event ke_preopen;call super::ke_preopen;of_UseThemeColors(#UseThemeColors)

ii_original_splitter_width = #splitterwidth
end event

type st_label from statictext within u_splitcontainer
integer x = 165
integer y = 240
integer width = 416
integer height = 52
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Split Container"
alignment alignment = center!
boolean focusrectangle = false
end type