FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Enhanced Class TActiveX and easier RibbonBar
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Enhanced Class TActiveX and easier RibbonBar
Posted: Tue Apr 07, 2009 07:39 AM
Thanks to these days CodeJock's RibbonBar tests, we have enhanced Class TActiveX to automatically manage TOleAuto objects from the events, so now the management of the CodeJock's RibbonBar is much simpler and easier :-)

See a working example. Please notice how oControl is retrieved from RibbonBarEvent():
Code (fw): Select all Collapse
#include "FiveWin.ch"

#define xtpControlButton      1

#define xtpFlagRightAlign     1

#define ID_ADDTAB            10
#define ID_ADDGROUP          20
#define ID_ADDBUTTON         30

static oRb

function Main()

   local oWnd, oAct, oMenu, oTabs, oGroups, oControls

   DEFINE WINDOW oWnd TITLE "Visual RibbonBar"

   @ 0, 0 ACTIVEX oAct PROGID "Codejock.CommandBarsFrame.12.1.1" OF oWnd SIZE 0, 0

   oAct:bOnEvent = { | cEvent, aParams | RibbonBarEvent( cEvent, aParams ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   oTabs:CommandBar:Controls:Add( 1, ID_ADDTAB, "Add" )

   oGroups = oMenu:CommandBar:Controls:Add( 3, 0, "Groups" )
   oGroups:CommandBar:Controls:Add( 1, ID_ADDGROUP, "Add" )

   oControls = oMenu:CommandBar:Controls:Add( 3, 0, "Controls" )
   oControls:CommandBar:Controls:Add( 1, ID_ADDBUTTON, "Add Button" )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams )

   local oControl, oTab, oGroup, oItem 

   do case
      case cEvent == "Execute"
           
           oControl = aParams[ 1 ]
           
           do case
              case oControl:Id == ID_ADDTAB
                   oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oControl:Id = oRb:TabCount
                   oControl:Selected = .T.

              case oControl:Id == ID_ADDGROUP
                   if oRb:TabCount > 0
                      oGroup = oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                               ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   

              case oControl:Id == ID_ADDBUTTON
                   if oRb:SelectedTab:Groups:GroupCount > 0
                      oGroup = oRb:FindGroup( ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount )
                      oItem = oGroup:Add( xtpControlButton, 1, nil )
                      oItem:Caption = "Button " + AllTrim( Str( oGroup:Count ) )
                   endif   
                   
              otherwise
                   if ! Empty( oControl:Caption )
                      MsgInfo( oControl:Caption )     
                   endif   

           endcase        
   endcase
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Enhanced Class TActiveX and RibbonBar management
Posted: Tue Apr 07, 2009 08:23 AM
Dynamically inspecting the RibbonBar controls:



RibonBar.prg
Code (fw): Select all Collapse
#include "FiveWin.ch"

#define xtpControlButton      1

#define xtpFlagRightAlign     1

#define ID_ADDTAB            10
#define ID_ADDGROUP          20
#define ID_ADDBUTTON         30

static oRb

function Main()

   local oWnd, oAct, oMenu, oTabs, oGroups, oControls

   DEFINE WINDOW oWnd TITLE "Visual RibbonBar"

   @ 0, 0 ACTIVEX oAct PROGID "Codejock.CommandBarsFrame.12.1.1" OF oWnd SIZE 0, 0

   oAct:bOnEvent = { | cEvent, aParams | RibbonBarEvent( cEvent, aParams ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   oTabs:CommandBar:Controls:Add( 1, ID_ADDTAB, "Add" )

   oGroups = oMenu:CommandBar:Controls:Add( 2, 0, "Groups" )
   oGroups:CommandBar:Controls:Add( 1, ID_ADDGROUP, "Add" )

   oControls = oMenu:CommandBar:Controls:Add( 2, 0, "Controls" )
   oControls:CommandBar:Controls:Add( 1, ID_ADDBUTTON, "Add Button" )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams )

   local oControl, oTab, oGroup, oItem 

   do case
      case cEvent == "Execute"
           
           oControl = aParams[ 1 ]
           
           do case
              case oControl:Id == ID_ADDTAB
                   oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oControl:Id = oRb:TabCount
                   oControl:Selected = .T.

              case oControl:Id == ID_ADDGROUP
                   if oRb:TabCount > 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                             ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   

              case oControl:Id == ID_ADDBUTTON
                   if oRb:TabCount == 0
                      oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) ) 
                      oControl:Id = oRb:TabCount
                      oControl:Selected = .T.
                   endif
                   if oRb:SelectedTab:Groups:GroupCount == 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                             ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   
                   if oRb:SelectedTab:Groups:GroupCount > 0
                      oGroup = oRb:FindGroup( ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount )
                      oItem = oGroup:Add( xtpControlButton, 1, nil )
                      oItem:Caption = "Button " + AllTrim( Str( oGroup:Count ) )
                   endif   
                   
              otherwise
                   if ! Empty( oControl:Caption )
                      ControlInspect( oControl )     
                   endif   

           endcase        
   endcase
   
return nil     

function ControlInspect( oControl )

   local oDlg, cCaption := PadR( oControl:Caption, 30 )
   
   DEFINE DIALOG oDlg TITLE "Control Properties" SIZE 300, 300
   
   @ 0.9, 1 SAY "Caption:"
   
   @ 1,  4  GET cCaption VALID ( oControl:Caption := AllTrim( cCaption ), .T. )
   
   @ 1.9, 1 SAY "Width:"
   
   @ 2.2, 4 GET oControl:Width SIZE 25, 12

   @ 1.9, 12 SAY "Height:"
   
   @ 2.2, 12 GET oControl:Height SIZE 25, 12
   
   ACTIVATE DIALOG oDlg CENTERED
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Enhanced Class TActiveX and easier RibbonBar
Posted: Tue Apr 07, 2009 11:51 AM

Hello Antonio,
do I need an updated TActiveX-class?
I use FWH 9.03.
Thanks in advance
Otto

VISTA and Codejock 13

Application

Path and name: C:\fwhtests\codejock\menu3.exe (32 bits)
Size: 1,648,128 bytes
Time from start: 0 hours 0 mins 16 secs
Error occurred at: 04/07/09, 13:48:59
Error description: Error BASE/1004 Class: 'NUMERIC' has no exported method: ID
Args:
[ 1] = N 28001224

Stack Calls

Called from: => ID(0)
Called from: C:\fwhtests\codejock\menu3.prg => RIBBONBAREVENT(49)
Called from: C:\fwhtests\codejock\menu3.prg => (b)MAIN(22)
Called from: .\source\classes\ACTIVEX.PRG => TACTIVEX:ONEVENT(0)
Called from: => WINRUN(0)
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE(0)
Called from: C:\fwhtests\codejock\menu3.prg => MAIN(40)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Enhanced Class TActiveX and easier RibbonBar
Posted: Tue Apr 07, 2009 02:54 PM


Code (fw): Select all Collapse
#include "FiveWin.ch"

#define xtpControlButton      1

#define xtpFlagRightAlign     1

#define xtpImageNormal        0
#define xtpImageDisabled      1
#define xtpImageHot           2
#define xtpImageChecked       3
#define xtpImagePressed       4

#define ID_ADDTAB            10
#define ID_ADDGROUP          20
#define ID_ADDBUTTON         30
#define ID_ADDIMAGE          40

static oIcons, oRb 

function Main()

   local oWnd, oAct, oMenu, oTabs, oGroups, oControls, oImages

   DEFINE WINDOW oWnd TITLE "Visual RibbonBar"

   @ 0, 0 ACTIVEX oAct PROGID "Codejock.CommandBarsFrame.12.1.1" OF oWnd SIZE 0, 0

   oAct:bOnEvent = { | cEvent, aParams | RibbonBarEvent( cEvent, aParams ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oIcons = oAct:Do( "icons" )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   oTabs:CommandBar:Controls:Add( 1, ID_ADDTAB, "Add" )

   oGroups = oMenu:CommandBar:Controls:Add( 2, 0, "Groups" )
   oGroups:CommandBar:Controls:Add( 1, ID_ADDGROUP, "Add" )

   oControls = oMenu:CommandBar:Controls:Add( 2, 0, "Controls" )
   oControls:CommandBar:Controls:Add( 1, ID_ADDBUTTON, "Add Button" )

   oImages = oMenu:CommandBar:Controls:Add( 2, 0, "Images" )
   oImages:CommandBar:Controls:Add( 1, ID_ADDIMAGE, "Load Image" )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams )

   local oControl, oTab, oGroup, oItem, cBmpFile 

   do case
      case cEvent == "Execute"
           
           oControl = aParams[ 1 ]
           
           do case
              case oControl:Id == ID_ADDTAB
                   oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oControl:Id = oRb:TabCount
                   oControl:Selected = .T.

              case oControl:Id == ID_ADDGROUP
                   if oRb:TabCount > 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                             ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   

              case oControl:Id == ID_ADDBUTTON
                   if oRb:TabCount == 0
                      oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) ) 
                      oControl:Id = oRb:TabCount
                      oControl:Selected = .T.
                   endif
                   if oRb:SelectedTab:Groups:GroupCount == 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                             ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   
                   if oRb:SelectedTab:Groups:GroupCount > 0
                      oGroup = oRb:FindGroup( ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount )
                      oItem = oGroup:Add( xtpControlButton, 1, nil )
                      oItem:Caption = "Button " + AllTrim( Str( oGroup:Count ) )
                   endif   

              case oControl:Id = ID_ADDIMAGE
                   cBmpFile = cGetFile( "*.bmp", "Please select a BMP file" ) 
                   if File( cBmpFile )
                      MsgInfo( oIcons:Count + 1 )
                      oIcons:LoadBitmap( cBmpFile, oIcons:Count + 1, xtpImageNormal )
                   endif   
                   
              otherwise
                   if ! Empty( oControl:Caption )
                      ControlInspect( oControl )     
                   endif   

           endcase        
   endcase
   
return nil     

function ControlInspect( oControl )

   local oDlg, cCaption := PadR( oControl:Caption, 30 )
   
   DEFINE DIALOG oDlg TITLE "Control Properties" SIZE 300, 300
   
   @ 0.9, 1 SAY "Caption:"
   
   @ 1,  4  GET cCaption VALID ( oControl:Caption := AllTrim( cCaption ), .T. )
   
   @ 1.9, 1 SAY "Width:"
   
   @ 2.2, 4 GET oControl:Width SIZE 25, 12

   @ 1.9, 12 SAY "Height:"
   
   @ 2.2, 12 GET oControl:Height SIZE 25, 12

   @ 2.9, 1 SAY "Icon Id:"
   
   @ 3.4, 4 GET oControl:IconId SIZE 25, 12
   
   ACTIVATE DIALOG oDlg CENTERED
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Enhanced Class TActiveX and easier RibbonBar
Posted: Tue Apr 07, 2009 02:56 PM

Otto,

An enhanced Class TActiveX is required. It will be included in FWH 9.04

We may publish an early FWH 9.04 so you can start using these new features :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Enhanced Class TActiveX and easier RibbonBar
Posted: Tue Apr 07, 2009 09:12 PM

You can download a working demo (EXE + OCX) from here:

http://www.mediafire.com/?sharekey=414c ... 6e282a0ee8

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Enhanced Class TActiveX and easier RibbonBar
Posted: Tue Apr 07, 2009 11:28 PM
Editing the Tab and Group captions:



Download it and test it from here:
http://www.mediafire.com/?sharekey=d045 ... 8114394287

Code (fw): Select all Collapse
#include "FiveWin.ch"

#define xtpControlButton      1

#define xtpFlagRightAlign     1

#define xtpImageNormal        0
#define xtpImageDisabled      1
#define xtpImageHot           2
#define xtpImageChecked       3
#define xtpImagePressed       4

#define ID_ADDTAB            10
#define ID_ADDGROUP          20
#define ID_ADDBUTTON         30
#define ID_ADDIMAGE          40

static oIcons, oRb 

function Main()

   local oWnd, oAct, oMenu, oTabs, oGroups, oControls, oImages

   if ! IsActiveX( "Codejock.CommandBars.v13.0.0.Demo.ocx" )
      RegisterServer( "Codejock.CommandBars.v13.0.0.Demo.ocx" )
   endif   

   DEFINE WINDOW oWnd TITLE "Visual RibbonBar"

   @ 0, 0 ACTIVEX oAct PROGID "Codejock.CommandBarsFrame.13.0.0" OF oWnd SIZE 0, 0

   oAct:bOnEvent = { | cEvent, aParams | RibbonBarEvent( cEvent, aParams ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oIcons = oAct:Do( "icons" )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   oTabs:CommandBar:Controls:Add( 1, ID_ADDTAB, "Add" )

   oGroups = oMenu:CommandBar:Controls:Add( 2, 0, "Groups" )
   oGroups:CommandBar:Controls:Add( 1, ID_ADDGROUP, "Add" )

   oControls = oMenu:CommandBar:Controls:Add( 2, 0, "Controls" )
   oControls:CommandBar:Controls:Add( 1, ID_ADDBUTTON, "Add Button" )

   oImages = oMenu:CommandBar:Controls:Add( 2, 0, "Images" )
   oImages:CommandBar:Controls:Add( 1, ID_ADDIMAGE, "Load Image" )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams )

   local oControl, oTab, oGroup, oItem, cBmpFile 

   do case
      case cEvent == "Execute"
           
           oControl = aParams[ 1 ]
           
           do case
              case oControl:Id == ID_ADDTAB
                   oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oControl:Id = oRb:TabCount
                   oControl:Selected = .T.

              case oControl:Id == ID_ADDGROUP
                   if oRb:TabCount > 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                             ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   

              case oControl:Id == ID_ADDBUTTON
                   if oRb:TabCount == 0
                      oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) ) 
                      oControl:Id = oRb:TabCount
                      oControl:Selected = .T.
                   endif
                   if oRb:SelectedTab:Groups:GroupCount == 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                             ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   
                   if oRb:SelectedTab:Groups:GroupCount > 0
                      oGroup = oRb:FindGroup( ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount )
                      oItem = oGroup:Add( xtpControlButton, 1, nil )
                      oItem:Caption = "Button " + AllTrim( Str( oGroup:Count ) )
                   endif   

              case oControl:Id = ID_ADDIMAGE
                   cBmpFile = cGetFile( "*.bmp", "Please select a BMP file" ) 
                   if File( cBmpFile )
                      MsgInfo( oIcons:Count + 1 )
                      oIcons:LoadBitmap( cBmpFile, oIcons:Count + 1, xtpImageNormal )
                   endif   
                   
              otherwise
                   if ! Empty( oControl:Caption )
                      ControlInspect( oControl )     
                   endif   

           endcase        
   endcase
   
return nil     

function ControlInspect( oControl )

   local oDlg, cCaption := PadR( oControl:Caption, 30 )
   local cTabCaption := PadR( oRb:SelectedTab:Caption, 30 )
   local cGrpCaption := PadR( oControl:RibbonGroup:Caption, 30 )
   
   DEFINE DIALOG oDlg TITLE "Control Properties" SIZE 300, 300
   
   @ 0.9, 1 SAY "Caption:"
   
   @ 1,  4  GET cCaption VALID ( oControl:Caption := AllTrim( cCaption ), .T. )
   
   @ 1.9, 1 SAY "Width:"
   
   @ 2.2, 4 GET oControl:Width SIZE 25, 12

   @ 1.9, 12 SAY "Height:"
   
   @ 2.2, 12 GET oControl:Height SIZE 25, 12

   @ 2.9, 1 SAY "Icon Id:"
   
   @ 3.4, 4 GET oControl:IconId SIZE 25, 12

   @ 4.9, 1 SAY "Tab caption:"
   
   @ 5.6, 5.3 GET cTabCaption VALID ( oRb:SelectedTab:Caption := AllTrim( cTabCaption ), .T. ) SIZE 100, 12

   @ 5.7, 1 SAY "Group caption:"
   
   @ 6.6, 5.3 GET cGrpCaption VALID ( oControl:RibbonGroup:Caption := AllTrim( cGrpCaption ), oRb:RedrawBar(), .T. ) SIZE 100, 12

   @ 7, 10 BUTTON "Ok" ACTION oDlg:End()
   
   ACTIVATE DIALOG oDlg CENTERED
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion