FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Tree Focus Problem
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Tree Focus Problem
Posted: Thu Aug 21, 2008 10:48 AM
Hi,

I have modified the tresttre2.prg like below. When click the New button or About menuitem, my mdiclient window is activated. This window includes the Tree object. I could not focus the first item (Page-1) of tree object.

I try to use focus method line 218. but it gives an error.

How can i focus the page-1 treeitem when its activated?



thanks,

#include "FiveWin.ch" 
#include "Splitter.ch" 

//----------------------------------------------------------------------------// 
#define DISABLE_CALLINGITEM 
// above define is used when we want to disable 
// invoking button or menuitem 

STATIC aResize := {}

function Main()

   local oIco, oBar, oBmp

   DEFINE ICON oIco FILE "..\icons\fax.ico"

   DEFINE WINDOW oWnd FROM 1, 1 TO 22, 75 MDI ;
      TITLE "FiveWin sample" ;
      MENU  BuildMenu() ;
      COLOR "B/W" ;
      ICON oIco

   DEFINE BUTTONBAR oBar _3D SIZE 26, 27 OF oWnd

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\new.bmp" FLAT ;
      ACTION Parametre(This) ;
      TOOLTIP "Creates a new document"

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\open.bmp" FLAT ;
      ACTION MsgInfo( cGetFile( "*.*", "Select a document to open" ) ) ;
      TOOLTIP "Opens a document" WHEN .f.

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\floppy.bmp" FLAT ;
      ACTION MsgInfo( Time() ) TOOLTIP "Saves this document"

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\printer.bmp" FLAT ;
      ACTION MsgInfo( "Prints this document" ) TOOLTIP "Print this document" GROUP

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\prop.bmp" FLAT ;
      ACTION PrinterSetup() TOOLTIP "Setup the printer"

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\HelpInd.bmp" FLAT ;
      ACTION MsgInfo( Version() ) TOOLTIP "A multiple lines" + ;
      Chr( 13 ) + Chr( 10 ) + "tooltip!" GROUP

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\Help.bmp" FLAT ;
      ACTION MsgInfo( "fivewin power!" ) TOOLTIP "fivewin power!"

   DEFINE BUTTON OF oBar FILENAME "..\bitmaps\16x16\Exit.bmp" FLAT ;
      ACTION oWnd:End() TOOLTIP "Exit this app" GROUP

   DEFINE MESSAGE OF oWnd ;
      PROMPT FWVERSION + " " + FWCOPYRIGHT ;
      NOINSET CENTERED KEYBOARD DATE CLOCK

   DEFINE BITMAP oBmp FILENAME "..\bitmaps\fiveback.bmp"

   oWnd:bPainted = { | hDC | BmpTiled( hDC, oWnd, oBmp ) }

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Do you want to quit ?" )

return nil

//----------------------------------------------------------------------------//

function BuildMenu()

   local oMenu

   MENU oMenu
      MENUITEM "Information"
      MENU
         MENUITEM "&About..." ;
            ACTION Parametre(oMenuItem) ;
            FILENAME "..\bitmaps\16x16\info.bmp"
         SEPARATOR
         MENUITEM "&End..."  ;
            ACTION oWnd:End() FILENAME "..\bitmaps\16x16\exit.bmp"

      ENDMENU

      MENUITEM "&Clients"
      MENU
         MENUITEM "&New..." ;
            ACTION ( MsgStop( "New Clients" ),;
                     oWnd:Say( 5, 5, "New Clients...", "GR+/G" ) ) ;
            FILENAME "..\bitmaps\16x16\faces.bmp"

         MENUITEM "&Modify..."  ACTION MsgInfo( "Modif. Clients" ) ;
            FILENAME "..\bitmaps\edit.bmp"

         MENUITEM "&Delete..."  ACTION MsgAlert( "Del Clients" ) ;
            FILENAME "..\bitmaps\16x16\delete.bmp"

         SEPARATOR

         MENUITEM "&Browse..."  ACTION MsgInfo( "Browse Clients" ) ;
            FILENAME "..\bitmaps\16x16\browse.bmp"

      ENDMENU

      MENUITEM "&Utilities"
      MENU
         MENUITEM "&Calculator..." ACTION WinExec( "Calc" ) ;
            FILENAME "..\bitmaps\16x16\calc.bmp"

         MENUITEM "&Internet..." ;
            ACTION WinExec( "start iexplore www.fivetech.com", 0 ) ;
            FILENAME "..\bitmaps\16x16\explorer.bmp"
      ENDMENU
   ENDMENU

return oMenu

//----------------------------------------------------------------------------//

STATIC FUNCTION BmpTiled( hDC, oWnd, oBmp )

   local nWidth := oWnd:nWidth(), nHeight := oWnd:nHeight()
   local nRow := 0, nCol := 0, n
   local nBmpWidth  := oBmp:nWidth(),  nBmpHeight := oBmp:nHeight()

   if oBmp:hBitmap == 0
      return nil
   endif

   while nRow < nHeight
      nCol = 0
      while nCol < nWidth
         PalBmpDraw( hDC, nRow, nCol, oBmp:hBitmap )
         nCol += nBmpWidth
      end
      nRow += nBmpHeight
   end

return nil

//----------------------------------------------------------------------------//

procedure AppSys  // Alaska XBase++ requirement

return


function Parametre( oItem ) 
	local  OWndParam, oDlg, oBar, oTree, oItem1, oItem2, oImageList, oSplit
	
	
   static lRunning := .f. 
   local lMenuDisabled := .f. 
          
   if lRunning 
      if OWndParam != nil 
         if isIconic( OWndParam:hWnd ) 
            WndMain():oWndClient:ChildRestore( OWndParam ) 
         endif 
         WndMain():oWndClient:ChildActivate( OWndParam ) 
      endif 
      return nil 
   endif 
    
   lRunning := .t. 

#ifdef DISABLE_CALLINGITEM 

   if Valtype( oItem ) == "O" .and. ; 
      Upper( oItem:ClassName ) $ "TBTNBMP,TMENUITEM" 
      oItem:Disable() 
      lMenuDisabled := .t. 
   endif      

#endif 
	
	   DEFINE WINDOW OWndParam FROM 3, 6 TO 20, 70 ; 
      TITLE "Welcome to " + FWVERSION COLOR "N/W";
      OF oWnd MDICLIENT




   oTree := TTreeView():New( 2, 0, OWndParam ) 
	 oTree:nWidth := 100
   oTree:bChanged := { | oItem | oItem := oTree:GetSelected(), If( ValType( oItem:Cargo ) == "B", Eval( oItem:Cargo ),) } 
                   
   oTree:Add( "Page - 1", 1 ):Cargo = {|| Test1( oDlg ) }                      
   oTree:Add( "Page - 2", 1 ):Cargo = {|| Test2( oDlg ) } 

   DEFINE DIALOG oDlg OF OWndParam ; 
      STYLE nOR( WS_CHILD, WS_VISIBLE ) ; 

   @ 29, 100 SPLITTER oSplit ; 
      VERTICAL _3DLOOK ; 
      PREVIOUS CONTROLS oTree ; 
      HINDS CONTROLS oDlg ; 
      SIZE 4, 100 PIXEL ; 
      LEFT MARGIN 20 ; 
      RIGHT MARGIN 25 ; 
      OF OWndParam 

   ACTIVATE DIALOG oDlg NOMODAL 

   ACTIVATE WINDOW OWndParam ; 
      ON INIT Wnd_Init(OWndParam, oDlg, oSplit, oTree);
      VALID ( If( lMenuDisabled, oItem:Enable(), ), lRunning := .f., .t. ) 
return nil

//----------------------------------------------------------------------------// 

static function Wnd_Init(OWndParam, oDlg, oSplit, oTree) 
local oItem
	oDlg:Move( 0, oSplit:nRight, OWndParam:nWidth, OWndParam:nHeight, .f. )
	//oDlg:bResized := {|| Dlg_Resize(oDlg) }
	OWndParam:bResized := {|| Wnd_Resize(OWndParam, oDlg, oSplit, oTree) }
	
	// -------------------------
	oItem := oTree:aItems[1]
	oItem:Focus()
	// -------------------------
	oDlg:refresh(.t.) 
	oTree:refresh(.t.) // required so that objects around splitter paint correctly on init 
return .t.

//----------------------------------------------------------------------------// 

static function Wnd_Resize(OWndParam, oDlg, oSplit, oTree) 
	oSplit:AdjClient()
	oDlg:SetSize( OWndParam:nWidth - oTree:nWidth - oSplit:nWidth - 8, oSplit:nHeight - 1,.t.)
	Button_Aligment(oDlg)
return .t.
	
//----------------------------------------------------------------------------// 

static function Button_Aligment(oDlg) 
	local n := 1
	local oControl, oRadMenu
	local i, lbul:=.f.
	
	if Len( oDlg:aControls ) > 0 .and. Len(Aresize) > 0
   
   		//MsgInfo (Len( oDlg:aControls ))
		
		while n <= Len( oDlg:aControls )
			oControl := oDlg:aControls[ n ]
//			MsgInfo(oDlg:aControls[ n ]:nID)
//			MsgInfo(oDlg:aControls[ n ]:cVarName)
//			If Upper( oDlg:aControls[ n ]:ClassName() ) == 'TBUTTON'
			for i:=1 to len(aResize)
				if aResize[i]=oControl:nID
					lbul=.t.
					exit
				endif
			next i
			if lbul
				If Upper( oControl:ClassName() ) == 'TBUTTON'
					oControl:nTop := oDlg:nHeight-30
				elseIf Upper( oControl:ClassName() ) == 'TGROUP'
					oControl:nTop := oDlg:nHeight-40
					oControl:nBottom := oDlg:nHeight-40
					oControl:nWidth := oDlg:nWidth
  			endif
  			oControl:refresh(.t.)
			endif
			n++
			//MsgInfo(n)
		end
		//MsgInfo("Bitti")	   

	end
return .t.

//----------------------------------------------------------------------------// 

static function CleanSlate( oDlg ) 

   while Len( oDlg:aControls ) > 0 
      ATail( oDlg:aControls ):end() 
   end
   if len(aResize) > 0
   	aResize := {}
   endif 

return nil 

//----------------------------------------------------------------------------// 

static function Test1( oDlg ) 
   Local oGet1, oGet2, oBtnOK, oBtnCancel, oGrp
   Local cGet1 := PadR( "Type something!", 50 ) 
   Local cGet2 := PadR( "Type something else!", 50 ) 

   CleanSlate( oDlg ) 
   @ 5,10 Say "Some data:" Of oDlg Pixel 
   @ 3,70 Get oGet1 Var cGet1 Of oDlg Pixel ; 
      Size 150,22 

   @ 30,10 Say "Other data:" Of oDlg Pixel 
   @ 28,70 Get oGet2 Var cGet2 Of oDlg Pixel ; 
      Size 150,22 
  //@ 0, 0 GROUP oGrp TO 0,0 PROMPT "" Pixel
  @ 100, 10 BUTTON oBtnOK PROMPT "OK" Of oDlg Pixel Size 100,25
	@ 100,120 BUTTON oBtnCancel PROMPT "Cancel" Of oDlg Pixel Size 100,25
	add_AResize(oBtnCancel:nId)
	add_AResize(oBtnOK:nId)
	//add_AResize(oGrp:nId)
	Button_Aligment(oDlg)		
  
Return nil 

//----------------------------------------------------------------------------// 

static function Test2( oDlg ) 
   Local oCbx1, oChk1 
   Local cCbx1 := "", lChk1 := .t. 

   CleanSlate( oDlg ) 

   @ 5,10 Say "Choose:" Of oDlg Pixel 
   @ 3,70 Combobox oCbx1 Var cCbx1 Of oDlg Pixel ; 
      Items { "Uno", "Dos", "Tres", "Mambo!" } ; 
      Size 80,18 

   @ 28,70 Checkbox oChk1 Var lChk1 Of oDlg Pixel ; 
      Prompt "Tick tock tick tock" ; 
      Size 150,22 
      
  //@ 0, 0 GROUP oGrp TO 0,0 PROMPT "" Pixel
  @ 100, 10 BUTTON oBtnOK PROMPT "OK" Of oDlg Pixel Size 100,25
	@ 100,120 BUTTON oBtnCancel PROMPT "Cancel" Of oDlg Pixel Size 100,25
	add_AResize(oBtnCancel:nId)
	add_AResize(oBtnOK:nId)
	//add_AResize(oGrp:nId)
	Button_Aligment(oDlg)		

Return nil 

//----------------------------------------------------------------------------// 
procedure add_aresize(xp1)
	local i, lbul:=.f.
	for i:=1 to len(aResize)
		if aResize[i]=xp1
			lbul=.t.
			exit
		endif
	next i
	if !lbul
		aadd(aResize, xp1)
	endif
return
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Tree Focus Problem
Posted: Fri Aug 22, 2008 10:35 AM

Any Suggestion?

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Tree Focus Problem
Posted: Fri Aug 22, 2008 11:12 AM

Hakan,

Please change lines 218 and 219 this way:

oItem := oTree:aItems[1]
oTree:Select( oItem )
oTree:SetFocus()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Tree Focus Problem
Posted: Fri Aug 22, 2008 12:21 PM

Thanks Antonio,

It works. Can I take the testtre4.prg if it is possible?.

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06

Continue the discussion