Page 1 of 1

Ribbon gets deactivated on RV action

Posted: Thu Sep 06, 2012 7:35 am
by infrax
I used the ribbon example, added a new form and button.

On button click I open the ribbon form:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var r:TfrmMain;
begin
  r := TfrmMain.Create(Self);
  r.Show;
end;
Now on every RV action the ribbon form gets deactivated (it activates the main form). What am I missing?

RVAControlPanel1.DefaultControl is set to RichViewEdit1. I searched a little bit but no luck.

Posted: Thu Sep 06, 2012 11:36 am
by Sergey Tkachenko
I do not completely understand what happens in your application.

Can you create a simple project and send it to richviewgmailcom?

Posted: Sat Sep 08, 2012 11:36 am
by Sergey Tkachenko
You assume that actions use TRVAControlPanel component (and thus its DefaultControl property) placed on the same form.
This is a wrong assumption. Properties of RVAControlPanel only provide access to global variables, so several instances of this component change the same variables.

If you want to link specific actions to the specific editor, you should do it using action.Control property.
Place this code in TfrmMain.FormCreate:

Code: Select all

  for i := 0 to ComponentCount-1 do
    if Components[i] is TrvAction then
      TrvAction(Components[i]).Control := RichViewEdit1;
Besides, it's better to move RVAControlPanel1 to Form1 to provide that this component is created in a single instance.

Note 1: If you use multiple forms, you need to change code that changes measuring units (TfrmMain.cmbUnitsClick). Changing RVAControlPanel1.UnitsDisplay affects all forms. So you need to change UnitsDisplay for all rulers on all forms, change MarginsUnits for all rvActionPageSetup1 on all forms, call RVA_ConvertToPixels/RVA_ConvertToTwips for all forms, call ConvertDocToDifferentUnits for RichViewEdit1 and RVStyle1 on all forms.
Besides, when a new form is created, if RVAControlPanel1.UnitsDisplay=twips (i.e. it was changed in one of previously created forms), and if yes, update the form accordingly.

Note 2: consider using a single editing form with editor switched on tabs instead of multiform approach. A demo (with classic toolbar) is here: http://www.trichview.com/support/files/ ... sttabs.zip
In this case, you can use a single ribbon and a single set of actions for multiple editors.

Note 2: in the next update, internal implementation of TRVAControlPanel will be completely rewritten, it will not use global variables; you will be able to link specific actions to specific RVAControlPanel, so, for example, different forms can use different measuring units.

Posted: Tue Sep 18, 2012 9:09 am
by infrax
Yes but still, with that code added it still goes out of focus. Form1 gets focused.

We are planning to have multiple forms (measuring units will be fixed on all forms). So all the code for converting between different units will be skipped.

RVAControlPanel1 will be moved out of RVARibbonFrm (for single instance).

Ribbon with multiple editor tabs is a no-go for us.

Posted: Tue Sep 18, 2012 12:38 pm
by Sergey Tkachenko
The main form activation is seems to be related to TRibbon itself, not to RichViewActions, because:
- any actions in menus of split-buttons do not activate the main form;
- I added a simple action in ActionManager1 and the ribbon:

Code: Select all

procedure TfrmMain.Action3Execute(Sender: TObject);
begin
  beep;
end;
It does activate the main form.

Posted: Wed Sep 19, 2012 12:08 pm
by infrax
Any ideas what to do?

Posted: Wed Sep 19, 2012 1:25 pm
by Sergey Tkachenko
Somehow disallowing activating the main form, or reactivate the editor form.

Posted: Thu Sep 20, 2012 5:45 am
by infrax
Yes ribbon control assumes that it is also the main form (and only 1 ribbon from in the application)

It has a fixed code:

Code: Select all

procedure TRibbonBaseButtonControl.Click;
begin
  inherited;
  SetFocus(Application.MainForm.Handle);
end;
By modifying this I got it working...... :D

Posted: Sun Mar 03, 2013 4:43 pm
by philipljackson
Hi

I am having exactly the same issue as that described in this topic - could someone please advise where exactly the code fix should be applied to? The ribbon does not appear to have any property RibbonBaseButtonControl

Thanks in advance

Code: Select all

   

 procedure TRibbonBaseButtonControl.Click; 
 begin 
   inherited; 
   SetFocus(Application.MainForm.Handle); 
 end; 


Posted: Mon Mar 04, 2013 10:24 am
by Sergey Tkachenko
This fix requires modification of the VCL source code.
For example, in XE2 on my computer, c:\Program Files\Embarcadero\RAD Studio\9.0\source\vcl\Vcl.RibbonActnCtrls.pas has the code:

Code: Select all

procedure TRibbonBaseButtonControl.Click;
begin
  inherited;
  SetFocus(Application.MainForm.Handle);
end;
(XE3 has the same code in this unit).

As you can see, this code focuses the main form. It should be modified to activate the proper form.
And the directory of this pas file must be added as the first directory in the "Library path", to use this source code instead the compiled VCL packages.