Set check of CMFCRibbonCheckBox - mfc

The MFC CMFCRibbonCheckBox class only supports IsChecked().
How do I change check status of ribbon check box in program code?
Is there way to set check status like CButton::SetCheck().

you can copy code from CMFCRibbonCmdUI::SetCheck. CMFCRibbonBaseElement::m_bIsPressed is a protected member so you need to expose it via a derived class. CMFCRibbonCmdUI has a backdoor to it through class friendship.

Related

Calling overridden function within component of class

I have 4 classes, Customer, PickyCustomer, SegmentCustomer, and Delivery.
The Delivery class has a component within it called customer, like so:
class Delivery {
private:
Customer *customer;
Delivery(Customer *cust) // constructor
each of the Customer classes have a method called getAcceptable()
that is overrideable and is overridden within PickyCustomer and SegmentCustomer
From what I've read this is the correct way to call the overridden method from the Delivery class. By keeping the customer as a pointer it allows Delivery to call the child methods that override the base class.
But when trying to use unique_ptr I keep getting the error
no matching function for call to 'Delivery::Delivery(std::unique_ptr<Customer>*)'
when using the following bit of code to initialize
unique_ptr<Customer> cust1(new Customer("Name", "Home", 1000.0, 25.0, fileProduce));
shared_ptr<Delivery> cust1Delivery(new Delivery(cust1));
Can someone explain why I am getting this error, and show how I could fix this? Thanks.
Thanks to #paddy in the comments with the help! Using the get() function worked for me.
The below works for me.
unique_ptr<Delivery> cust1Delivery(new Delivery(cust1.get()));

C++ design question (using Model Presenter View with protected member)

I use touchGFX which is a C++ hmi for embedded devcices. I have the following problem and I am not sure how to solve it most effective. I need to access functions in the various StatusBar instances from MyModelListener (see below).
System description:
There is a model which holds the data, the views for the hmi and some presenters which interact between the model and the views. The base classes are automatically generated, I am allowed to modify all class with "My...". All My...Pesenters are linked with the corresponding My...Views by references in both directions.
I have some Presenters:
class MyAPresenter : public MyModelListener;
...
class MyZPresenter : public MyModelListener;
I have some Views belonging to the presenters:
class MyAView: public AViewBase;
...
class MyZView: public ZViewBase;
There is a status bar which should be used in each of the views:
class MyStatusbar : public Statusbar;
AViewBase, ..., ZViewBase each have a protected member instance of class MyStatusbar.
MyAPresenter, ..., MyZPresenter have a reference to MyAView, ..., MyZView.
How can I access (many) functions of MyStatusBar instances (inside the MyAView...) from MyModelListener without introducing as many functions into each MyAView... MyZView?
The data path how status bar can be reached is:
MyModelListener -> MyAPresenter -> MyAView -> AViewBase -> MyStatusbar
Problems:
I cannot access MyStatusbar instances from MyModelListener or MyAView via the AViewBase because MyStatusbar instances are declared protected within AViewBase.
I cannot modifiy AViewBase
I do not want to access MyStatusBar from MyAView..MyZView because I do not want to have all those many functions in each My...View.
I do not want to write all the needed functions in each of MyAPresenter...MyZPresenter.
(All the classes are virtual)
My solution:
Make functions getStatusPtr() returning the address of the Statusbar instances in each of MyAView to MyZView. This is possible because StatusBar is defined protected but not private.
Make virtual getStatusPtr() in each of MyAPresenter to MyZPresenter which calls the getStatusPtr() function in MyAView to MyZView via the owned references.
Define a virtual getStatusPtr() returning 0 in MyModelListener.
Access the StatusBar from MyModelListener if the pointer is not 0. This should deliver the the status bar of A if the MyModelListener functions are called from a MyAPresenter object.
If the View is changed both view and presenter are destroyed and the status bar too. The statusbar thus has to be rebuilt but this is acceptable.
Is there a better/alternative solution?

Populate C++ model from external source in Qt

I need to populate c++ model from a external source (for example USB). I have registered the model in main.cpp like this,
qmlRegisterType<HardwareDataModel>("org.example", 1, 0, "HardwareDataModel");
I need to change the private member of this HardwareDataModel class from the external source. Because I would like to change the the private data member of this model and fire signal to qml to change the UI. I got stuck how to proceed as I do not know how to populate those private data members. Do I need to instatiate HardwareDataModel in main.cpp? If yes, how to connect the instatiated HardwareDataModel object and one that is qmlRegisteredType (one shown above).

A descendant of TStyledPresentationProxy has not been registered for class

I have a custom grid control that inherits from TGrid called TFmGrid. This control was working fine in Rad Studio 10 Seattle Update One. I recently upgraded to 10.1 Berlin and started noticing this error message showing up on my TFmGrid controls both when I run the application and in the designer:
A descendant of TStyledPresentationProxy has not been registered for class TFmGrid. Maybe it is necessary to add the FMX.Grid.Style module to the uses section
The image below shows how the error message shows up on my grid controls:
I started by doing as the message suggests, and adding #include <FMX.Grid.Style.hpp> to the header file of my TFmGrid control, however this seems to have done nothing.
So as far as trying to register a decendant of TStyledPresentationProxy I am not exactly sure where to start. I found this documentation about a method which:
Attempts to register the presentation proxy class with the specified name or the specified combination of control class and control type.
So I assume I need to use this method or at least something similar, but I don't understand how I am supposed to go about calling this method.
But then that brings up the question of WHERE do I call this code?
My custom control has a method in its namespace called Register() which I believe was autogenerated by the IDE when the control was created:
namespace Fmgridu
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TFmGrid)};
RegisterComponents(L"Kalos FM Controls", classes, 0);
}
}
Do I need to call something in there to register a decendant of TStyledPresentationProxy? What is the proper way to go about this?
Just override virtual method DefinePresentationName in you TfmGrid and return name of presentation name for grid:
function TfmGrid.DefinePresentationName: string;
begin
Result := 'Grid-' + GetPresentationSuffix;
end;
Fm registers presentation by string name and uses class name for it, so if you create new component (based on existed) you automatically change classname, so system cannot find presentation for you. There are two solution:
Said that you will use presentation from TGrid (DefinePresentationName)
Register existed presentation for you class (look at the initialization section of FMX.Grid.Style.pas)
P.S. Year ago i wrote article about it in common eNew approach of development of FireMonkey control “Control – Model – Presentation”. Part 1 I hope it will help you
It's simple :
Just put "StyleBook" component to your form
I had the same issue with a test component I was developing.
Complementing Yaroslav Brovin's speech, I solved the problem by adding the class register in the initialization and finalization clauses at the end of the unit, like this:
initialization
TPresentationProxyFactory.Current.Register(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
finalization
TPresentationProxyFactory.Current.Unregister(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
In my case looks like this:
initialization
TPresentationProxyFactory.Current.Register(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
finalization
TPresentationProxyFactory.Current.Unregister(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
PS: Don't forget to declare the FMX.Presentation.Factory,
FMX.Presentation.Style and FMX.Grid.Style units in the uses clause

How to activate an instance of a ref class

Say I have this class:
public ref class Page1 sealed : Windows::UI::Xaml::Controls::Page {};
I can activate an instance of this class like this:
auto page = ref new Page1();
But how would I do that in raw C++?
I have tried this but it doesn't work:
Microsoft::WRL::Wrappers::HString className;
className.Set(L"App1.Page1");
IInspectable *page;
Windows::Foundation::ActivateInstance(className.Get(), &page);
The above code does work when I specify a windows runtime class name, (such as "Windows.UI.Xaml.Controls.Button"), just not my own ref class "App1.Page1".
Alternatively, given that I have declared a public ref class named Page1 in the App1 namespace, how can I activate an instance of this class as an IInspectable* from the HSTRING "App1.Page1"?
I think I have figured it out. Well, this answer does not directly solve the problem of activating any arbitrary type, but it does what I want.
The devil is in the detail. The XAML compiler will generate a bunch of files not visible in the Solution Explorer. These files have the extension .g.h and .g.hpp. You can click the "Show All Files" button in Solution Explorer to see them.
In App.g.h, the App class implements the Windows::UI::Xaml::Markup::IXamlMetadataProvider class, which we can use to obtain information about our XAML types. The XamlTypeInfo files contains the generated type definitions.
Here's some code which shows how to activate one of our XAML types from a TypeName:
Object^ activate(TypeName typeName)
{
auto app = Application::Current;
auto provider = static_cast<IXamlMetadataProvider^>(app);
auto xamlType = provider->GetXamlType(typeName);
return xamlType->ActivateInstance();
}
No WRL necessary, 100% C++/CX, thanks to the XAML type information generated by the XAML compiler!
I believe a similar structure is also the case for C# projects, in that the Application-derived class will implement IXamlMetadataProvider interface too. Under the hood, the Windows Runtime does not use .NET, so it does not have any kind of "real" reflection, so it relies on statically defined type definitions.