Enhanced Class TActiveX and easier RibbonBar

Enhanced Class TActiveX and easier RibbonBar

Postby Antonio Linares » Tue Apr 07, 2009 7: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: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Enhanced Class TActiveX and RibbonBar management

Postby Antonio Linares » Tue Apr 07, 2009 8:23 am

Dynamically inspecting the RibbonBar controls:

Image

RibonBar.prg
Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Enhanced Class TActiveX and easier RibbonBar

Postby Otto » 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)
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Enhanced Class TActiveX and easier RibbonBar

Postby Antonio Linares » Tue Apr 07, 2009 2:54 pm

Image
Image
Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Enhanced Class TActiveX and easier RibbonBar

Postby Antonio Linares » Tue Apr 07, 2009 2: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Enhanced Class TActiveX and easier RibbonBar

Postby Antonio Linares » Tue Apr 07, 2009 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Enhanced Class TActiveX and easier RibbonBar

Postby Antonio Linares » Tue Apr 07, 2009 11:28 pm

Editing the Tab and Group captions:

Image

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

Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests