File: n_base_wizard.sru
Size: 10796
Date: Mon, 07 Apr 2008 21:31:48 +0200
$PBExportHeader$n_base_wizard.sru
$PBExportComments$Base wizard NVO
forward
global type n_base_wizard from n_base
end type
end forward

global type n_base_wizard from n_base
event ke_initwizard ( )
event ke_pageinit ( readonly u_wizard_page auo_page,  readonly integer ai_index )
event type integer ke_closing ( )
event ke_pageactivate ( readonly u_wizard_page auo_page,  readonly integer ai_index,  readonly boolean isforward )
event type integer ke_validateback ( readonly u_wizard_page auo_page,  readonly integer ai_index )
event type integer ke_validateforward ( readonly u_wizard_page auo_page,  readonly integer ai_index )
event ke_finishactivate ( )
event ke_help ( readonly u_wizard_page auo_page,  readonly integer ai_index )
end type
global n_base_wizard n_base_wizard

type variables
Public:
String #WizardTitle, #ModuleName
Protected:
String #FinishPage = "u_wizard_finish"
Boolean #ShowHelpButton
w_wizard iw_wiz
any Parameter, ReturnValue
str_wizard istr_wizard
str_wizard_page istr_pages[]
u_wizard_page iuo_currentpage, iuo_finish

CONSTANT string NEXT_PAGE = "N"
CONSTANT string PREVIOUS_PAGE = "P"
CONSTANT string FINISH = "F"

Private:
Integer TotalPages, CurrentPage, TotalPaths, CurrentPath
Boolean FORCE_CLOSE
end variables
forward prototypes
public subroutine of_setparameter (readonly str_wizard astr)
public function window of_getparentwindow ()
public subroutine of_addpages (readonly string as_classnames[])
public subroutine of_settitle (readonly string as_title)
public subroutine of_closepages ()
public subroutine of_back ()
public subroutine of_cancel ()
public subroutine of_close ()
public subroutine of_finish ()
public function w_wizard of_getwizardwindow ()
public subroutine of_next ()
public function integer of_gotopage (readonly integer ai_index)
public subroutine of_help ()
public subroutine of_showfinishpage ()
public function any of_showwizard ()
public subroutine of_setreturnvalue (readonly any aa_returnvalue)
end prototypes

event ke_initwizard();//place wizard initialization here
IF #ShowHelpButton THEN
   IF ISVALID(iw_wiz) THEN iw_wiz.cb_help.Visible = TRUE
END IF
end event

event ke_pageinit(readonly u_wizard_page auo_page, readonly integer ai_index);//place wizard page initialization here
//this event is fired when a page is created
//for the first time
end event

event type integer ke_closing();integer li_ret

IF currentpage > 1 AND NOT FORCE_CLOSE THEN
   IF Messagebox(iw_wiz.title, &
   "The wizard has not yet completed gathering information.~n~nAre you sure you want to exit the wizard?", &
   Exclamation!, YesNo!, 2) = 2 THEN li_ret = 1
END IF

RETURN li_ret
end event

event ke_pageactivate(readonly u_wizard_page auo_page, readonly integer ai_index, readonly boolean isforward);//fired when a page is activated
//isforward is true when activated from button "next"
auo_page.of_SetFocus()
end event

event type integer ke_validateback(readonly u_wizard_page auo_page, readonly integer ai_index);//fired when back button is pressed
//return CRet.FAILURE to prevent page back
RETURN CRet.SUCCESS
end event

event type integer ke_validateforward(readonly u_wizard_page auo_page, readonly integer ai_index);//fired when next button is pressed
//return CRet.FAILURE to prevent page next
RETURN CRet.SUCCESS
end event

event ke_finishactivate();//fired when finish page is activated
end event

event ke_help(readonly u_wizard_page auo_page, readonly integer ai_index);//fired when help button is pressed
//auo_page is the current page
end event

public subroutine of_setparameter (readonly str_wizard astr);istr_wizard = astr
end subroutine

public function window of_getparentwindow ();RETURN istr_wizard.parentwindow
end function

public subroutine of_addpages (readonly string as_classnames[]);long n

TotalPages = UPPERBOUND(as_classnames)

FOR n = TotalPages to 1 STEP -1
   istr_pages[n].classname = as_classnames[n]
NEXT
end subroutine

public subroutine of_settitle (readonly string as_title);#WizardTitle = as_title
end subroutine

public subroutine of_closepages ();long ll_count, n

IF NOT ISVALID(iw_wiz) THEN RETURN

ll_count = UPPERBOUND(istr_pages)

FOR n = 1 to ll_count
   IF ISVALID(istr_pages[n].page) THEN
      iw_wiz.CloseUserObject(istr_pages[n].page)
   END IF
NEXT
end subroutine

public subroutine of_back ();IF Currentpage > 1 THEN this.of_GoToPage(Currentpage - 1)
end subroutine

public subroutine of_cancel ();IF this.EVENT ke_closing() = 0 THEN 
   FORCE_CLOSE = TRUE
   CLOSE(iw_wiz)
END IF
end subroutine

public subroutine of_close ();CLOSE(iw_wiz)
end subroutine

public subroutine of_finish ();IF ISVALID(iuo_finish) THEN
   //determine if finish base class
   IF Classname(iuo_finish) = "u_wizard_finish" THEN
      //should we continue using the wizard?
      u_wizard_finish luo
      
      luo = iuo_finish
      IF luo.cbx_continue.checked THEN
         //remove default and cancel for next button
         iw_wiz.cb_next.Default = FALSE
         //reset all pages
         long ll_count, n
   
         ll_count = UPPERBOUND(istr_pages)
         FOR n = 1 to ll_count
            istr_pages[n].page.EVENT ke_reset()
         NEXT
         //show first page
         this.of_gotopage(1)
         RETURN
      END IF
   END IF
END IF

this.of_close()
end subroutine

public function w_wizard of_getwizardwindow ();RETURN iw_wiz
end function

public subroutine of_next ();IF Currentpage <= TotalPages THEN this.of_GoToPage(Currentpage + 1)
end subroutine

public function integer of_gotopage (readonly integer ai_index);Boolean IsForward
any la

iw_wiz.cb_help.Visible = this.#ShowHelpButton

IF CurrentPage > 0 THEN
   IF CurrentPage < ai_index THEN
      IF this.EVENT ke_validateforward(iuo_currentpage, CurrentPage) = CRet.FAILURE THEN RETURN CRet.FAILURE
      IsForward = TRUE
   ELSE
      IF this.EVENT ke_validateback(iuo_currentpage, CurrentPage) = CRet.FAILURE THEN RETURN CRet.FAILURE
   END IF
END IF

//if done with the last page, show finish page
IF ai_index > TotalPages THEN
   iw_wiz.cb_next.text = "&Finish"
   iw_wiz.of_setback(FALSE)
   iw_wiz.of_setcancel(FALSE)
   iw_wiz.title = #WizardTitle + " (Complete)"
   //show finish
   FORCE_CLOSE = TRUE
   this.of_showfinishpage()
   this.EVENT ke_finishactivate()   
   RETURN CRet.SUCCESS
ELSE
   IF ai_index = 1 THEN
      FORCE_CLOSE = FALSE
      iw_wiz.cb_next.text = "&Next >"
      iw_wiz.of_setcancel(TRUE)
   END IF
END IF

IF NOT ISVALID(istr_pages[ai_index].page) THEN
   iw_wiz.OpenUserObject(istr_pages[ai_index].page, istr_pages[ai_index].classname)
   //fire custom constructor
   la = istr_pages[ai_index].page.EVENT DYNAMIC ke_constructor()
   //hide for now
   istr_pages[ai_index].page.visible = FALSE
   //set wizard driver
   istr_pages[ai_index].page.of_registerwizarddriver(this, iw_wiz)
   //set size order for resize service
   istr_pages[ai_index].page.#SizeOrder = (ai_index * 10)
   
   iw_wiz.of_SuspendResize()
   
   long ll_wsw, ll_wsh
   
   ll_wsw = iw_wiz.WorkSpaceWidth()
   ll_wsh = iw_wiz.WorkSpaceHeight() - iw_wiz.st_divide.height
   
   //if smaller than wizard, adjust page to wizard size
   //if larger than wizard, adjust wizard to page size
   IF istr_pages[ai_index].page.width < ll_wsw THEN
      istr_pages[ai_index].page.width = ll_wsw
   ELSEIF istr_pages[ai_index].page.width > ll_wsw THEN
      iw_wiz.width = istr_pages[ai_index].page.width + 24 //extra pad correction
      //set minmax
      iw_wiz.#minwidth = UnitsToPixels(iw_wiz.width, XUnitsToPixels!)
   END IF

   IF istr_pages[ai_index].page.height < ll_wsh THEN
      istr_pages[ai_index].page.height = iw_wiz.height - (iw_wiz.height - iw_wiz.st_divide.Y)
   ELSEIF istr_pages[ai_index].page.height > ll_wsh THEN
      iw_wiz.height = istr_pages[ai_index].page.height + (iw_wiz.height - iw_wiz.st_divide.Y)
      //set minmax
      iw_wiz.#minheight = UnitsToPixels(iw_wiz.height, YUnitsToPixels!)
   END IF
   iw_wiz.of_ResumeResize()
   //show page
   istr_pages[ai_index].page.visible = TRUE  
   //size objects
   iw_wiz.of_resizeobjects(TRUE)
   //init page
   this.EVENT ke_pageinit(istr_pages[ai_index].page, ai_index) 
END IF
//set as top most page
istr_pages[ai_index].page.BringToTop = TRUE
iw_wiz.st_divide.BringToTop = TRUE
//set current page
CurrentPage = ai_index
iuo_currentpage = istr_pages[ai_index].page
//set wizard title
iw_wiz.title = #WizardTitle + " (Page " + STRING(CurrentPage) + " of " + STRING(TotalPages) + ")"
//activate page
this.EVENT ke_pageactivate(iuo_currentpage, CurrentPage, IsForward)

iw_wiz.of_setforward(currentpage <= totalpages)
iw_wiz.of_setback(currentpage > 1)

RETURN CRet.SUCCESS
end function

public subroutine of_help ();this.EVENT ke_help(iuo_currentpage, Currentpage)
end subroutine

public subroutine of_showfinishpage ();IF NOT ISVALID(iuo_finish) THEN
   iw_wiz.OpenUserObject(iuo_finish, #finishpage)
   //fire custom constructor
   any la
   la = iuo_finish.EVENT DYNAMIC ke_constructor()
   
   iuo_finish.#SizeOrder = 5555

   iw_wiz.of_SuspendResize()
   long ll_wsw, ll_wsh
   ll_wsw = iw_wiz.WorkSpaceWidth()
   ll_wsh = iw_wiz.WorkSpaceHeight() - iw_wiz.st_divide.height
   //if smaller than wizard, adjust page to wizard size
   //if larger than wizard, adjust wizard to page size
   IF iuo_finish.width < ll_wsw THEN
      iuo_finish.width = ll_wsw
   ELSEIF iuo_finish.width > ll_wsw THEN
      iw_wiz.width = iuo_finish.width + 24 //pad fix
   END IF
   
   IF iuo_finish.height < ll_wsh THEN
      iuo_finish.height = iw_wiz.height - (iw_wiz.height - iw_wiz.st_divide.Y)
   ELSEIF iuo_finish.height > ll_wsh THEN
      iw_wiz.height = iuo_finish.height + (iw_wiz.height - iw_wiz.st_divide.Y)
   END IF

   //set minmax
   iw_wiz.#minwidth = UnitsToPixels(iw_wiz.width, XUnitsToPixels!)
   iw_wiz.#minheight = UnitsToPixels(iw_wiz.height, YUnitsToPixels!)
   iw_wiz.of_ResumeResize()

   iw_wiz.of_resizeobjects(TRUE)
   
   //shoud we customize?
   IF #FinishPage = "u_wizard_finish" THEN
      u_wizard_finish luo
      luo = iuo_finish
//    luo.st_title.Text = "Finishing the " + #ModuleName
   END IF
END IF

//set as top most page
iuo_finish.BringToTop = TRUE
iw_wiz.st_divide.BringToTop = TRUE
iuo_finish.of_Registerwizarddriver(this, iw_wiz)
iuo_finish.of_SetFocus()
end subroutine

public function any of_showwizard ();IF TotalPages <= 0 THEN
   MessageBox(this.ClassName(), "No pages have been defined.", StopSign!)
   SetNull(ReturnValue)
ELSE
   OPENWITHPARM(iw_wiz, this)
END IF

RETURN ReturnValue
end function

public subroutine of_setreturnvalue (readonly any aa_returnvalue);ReturnValue = aa_Returnvalue
end subroutine

on n_base_wizard.create
call super::create
end on

on n_base_wizard.destroy
call super::destroy
end on

event constructor;call super::constructor;this.of_SetTitle(#WizardTitle)

this.EVENT ke_initwizard()
end event