Copy link to clipboard
Copied
Sorry for the newbie question but I can't seem to find this myself.
I have a panel and that panel contains a TextEditBoxWidget like so:
...
TextEditBoxWidget
(
kM5TablemodelValueWidgetID, // WidgetId
kSysEditBoxPMRsrcId, // RsrcId
kBindNone, // Frame binding
Frame(110, 10, 180, 30), // Frame (l,t,r,b)
kTrue, kTrue // Visible, Enabled
0, // Widget id of nudge button (0 so we don't get one)
0, 0,// small, large nudge amount
0, // max num chars(0 = no limit)
kTrue,// is read only
kFalse,// should notify each key stroke
kFalse,// range checking enabled
kFalse,// blank entry allowed
0, // Upper bounds
0, // Lower bounds
"-", // Initial text
),
...
I get an action from the panel menu and catch it in my M5ActionComponent class. That is where I want to change the TextEditBoxWidget's value to "something".. Now, how can I do that?
Copy link to clipboard
Copied
Use ITextControlData to get or set the text from your kM5TablemodelValueWidgetID;
For instance first find IControlView for your widget.
InterfacePtr<IControlView> yourCV(theParent, UseDefaultIID());
InterfacePtr<ITextControlData> yourWidgetData(yourCV, UseDefaultIID());
PMString yourText = yourWidgetData->GetString();
yourWidgetData->SetString(PMString( "your string " ));
Regards
Bartek
Copy link to clipboard
Copied
Thanks, that cleared a lot of things. One minor thing though, what exactly is "theParent" variable and how do I get it?
The action triggers when I click the action in panel menu and I get a widget but I guess that's not "theParent"?
Copy link to clipboard
Copied
there's many ways to obtain IControlView pointer.
for instance you can try:
InterfacePtr< IControlView > thePanelData(Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kM5TablemodelValueWidgetID));
Regards
Bartek
Copy link to clipboard
Copied
Thank you so much for the answers so far dude!
My code still isn't working though. I don't understand how the "textControlData" should know which widget's value I'm setting if It doesn't yet know about my kM5TablemodelValueWidgetID (TextEditBoxWidget)?
here's my code:
InterfacePtr<IControlView> controlView( Utils<IPalettePanelUtils>()->QueryPanelByWidgetID( kM5PanelWidgetID ), UseDefaultIID() );
InterfacePtr<ITextControlData> textControlData(controlView, UseDefaultIID());
textControlData->SetString(PMString( "SOMETHING" ));
Copy link to clipboard
Copied
Your TextEditBoxWidget is based on kTextEditBoxWidgetBoss with following interfaces.
IID_ICONTROLVIEW kNudgeEditBoxWidgetBoss
IID_ICURSORREGION kNudgeEditBoxWidgetBoss
IID_IDOMELEMENT kBaseWidgetBoss
IID_IEDITBOXATTRIBUTES kNudgeEditBoxWidgetBoss
IID_IEVEINFO kBaseWidgetBoss
IID_IEVENTHANDLER kNudgeEditBoxWidgetBoss
IID_IISLASTCHANGEVALID kNudgeEditBoxWidgetBoss
IID_ILASTVALIDTEXTCONTROLDATA kNudgeEditBoxWidgetBoss
IID_INUDGEOBSERVER kNudgeEditBoxWidgetBoss
IID_IPMPERSIST kBaseWidgetBoss
IID_ISCRAPSUITE kNudgeEditBoxWidgetBoss
IID_ISCRIPT kBaseWidgetBoss
IID_ISCRIPTEVENTTARGET kBaseWidgetBoss
IID_ISCRIPTWIDGETTYPE kBaseWidgetBoss
IID_ISUBJECT kBaseWidgetBoss
IID_ITEXTCONTROLDATA kNudgeEditBoxWidgetBoss
IID_ITEXTDATAVALIDATION kTextEditBoxWidgetBoss
IID_ITEXTVALUE kTextEditBoxWidgetBoss
IID_ITIP kNudgeEditBoxWidgetBoss
IID_IVALIDATECONTENTS kNudgeEditBoxWidgetBoss
IID_IWIDGETPARENT kBaseWidgetBoss
IID_NEVERWRITESTODOCUMENT kBaseWidgetBoss
Copy link to clipboard
Copied
Problem is I'm getting nil from:
InterfacePtr<IControlView> controlView2( Utils<IPalettePanelUtils>()->QueryPanelByWidgetID( kM5TablemodelValueWidgetID ), UseDefaultIID() );
And I assume it's because kM5TablemodelValueWidgetID isn't referencing to a panel and when I try the same using the kM5PanelWidgetID which IS referencing to a panel it works. But I don't need the controlview to panel. I need controlview to the TextEditBoxWidget (kM5TablemodelValueWidgetID).
So, before I can construct that interface pointer, I need at least the TextEditBoxWidget object, right? Now, how can I do that?
Thanks.
Copy link to clipboard
Copied
Phew! I got it working now. Thank you so much for the help. At the end I was looking for the method "FindWidget".
So here's the code:
IControlView* cv = Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kM5PanelWidgetID)->FindWidget(kM5TablemodelValueWidgetID);
InterfacePtr<ITextControlData> tcd(cv, UseDefaultIID());
tcd->SetString(PMString( "SOMETHING" ));
Regards
Copy link to clipboard
Copied
You're introducing a boss leak. QueryPanelByWidgetID yields a reference counted value, you must store it within an InterfacePtr<> or explicitly invoke Release().
Besides those wide multi-step expressions are bad to read, even with nowadays monitors, and debug (set a breakpoint?).
Finally defensive code should check pointers, e.g. before you invoke SetString(). Sometime later you might want to modify the underlying resource to use a different widget type, remove the widget for localization or make it optional...
Also have a look at the header comments, QueryPanelByWidgetID may yield NULL if the panel is not showing.
Dirk
Copy link to clipboard
Copied
True, I didn't spot that, thanks. The defensive code I left out with a purpose but the code below is the code as is and works. It shouldn't have leaks anymore(?)
In this case this code is executed when the user clicks one of the panel menu actions, so the panel is going to be at the top at the moment..
do{
InterfacePtr<IPanelControlData> panelControlData(Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kM5PanelWidgetID));
ASSERT(panelControlData);
if(panelControlData == nil){ break; }
InterfacePtr<IControlView> cv(panelControlData->FindWidget(kM5TablemodelValueWidgetID));
ASSERT(cv);
if(cv == nil){ break; }
InterfacePtr<ITextControlData> textControlData(cv, UseDefaultIID());
ASSERT(textControlData);
if(textControlData == nil){ break; }
textControlData->SetString(PMString( "SOMETHING" ));
} while(false);
Copy link to clipboard
Copied
With FindWidget it is the other way around - it is equivalent to Get() rather than to Query().
So you'd assign its result to an IControlView* cv, or add IID_ICONTROLVIEW to the InterfacePtr constructor.
It takes a while to get used to this reference counting.
Dirk
Find more inspiration, events, and resources on the new Adobe Community
Explore Now