Ribbon gets deactivated on RV action

General TRichView support forum. Please post your questions here
Post Reply
infrax
Posts: 31
Joined: Wed Aug 10, 2011 10:57 am

Ribbon gets deactivated on RV action

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I do not completely understand what happens in your application.

Can you create a simple project and send it to richviewgmailcom?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
infrax
Posts: 31
Joined: Wed Aug 10, 2011 10:57 am

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
infrax
Posts: 31
Joined: Wed Aug 10, 2011 10:57 am

Post by infrax »

Any ideas what to do?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Somehow disallowing activating the main form, or reactivate the editor form.
infrax
Posts: 31
Joined: Wed Aug 10, 2011 10:57 am

Post 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
philipljackson
Posts: 6
Joined: Fri Jan 27, 2012 8:37 pm
Location: UnitedKingdom

Post 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; 

Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply