Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to set my TextEditBoxWidget value from ActionComponent?

New Here ,
Jul 28, 2010 Jul 28, 2010

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?

TOPICS
SDK
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 28, 2010 Jul 28, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2010 Jul 29, 2010

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"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 29, 2010 Jul 29, 2010

there's many ways to obtain IControlView pointer.

for instance you can try:

InterfacePtr< IControlView > thePanelData(Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kM5TablemodelValueWidgetID));

Regards

Bartek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2010 Jul 29, 2010

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" ));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 29, 2010 Jul 29, 2010

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

First you need to find IControlView (IID_ICONTROLVIEW) and then based on this interface you can create pointer to ITextControlData (IID_ITEXTCONTROLDATA) interface.
IControlView is responsible for size, widgetID, position visibility and so on of widget. ITextControlData is responisble for controling text data of particular widget.
Because you where looking for particular widgetID and IControlView strores that value - that why you creating that pointer first.
InterfacePtr<IControlView> controlView1( Utils<IPalettePanelUtils>()->QueryPanelByWidgetID( kM5PanelWidgetID ), UseDefaultIID() );
InterfacePtr<IControlView> controlView2( Utils<IPalettePanelUtils>()->QueryPanelByWidgetID( kM5TablemodelValueWidgetID ), UseDefaultIID() );
InterfacePtr<ITextControlData> textControlData1(controlView1, UseDefaultIID());
InterfacePtr<ITextControlData> textControlData2(controlView2, UseDefaultIID());
Regards
bartek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2010 Jul 29, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2010 Jul 29, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 29, 2010 Jul 29, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2010 Jul 29, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 30, 2010 Jul 30, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines