ChrisR has asked for the wisdom of the Perl Monks concerning the following question:

I'm sure that this is a simple task, however, I just can't seem to get it right. I have a Win322::GUI::RichEdit control that is set to readonly:
$mainform->tab->Page4->AddRichEdit(-name=>'articletext',-style=>WS_VISIBLE|WS_VSCROLL,-multiline=>1,-text=>"",-width=>745,-height=>450,-left=>10,-top=>35,-readonly=>1); I am trying to change it's status from readonly to editable when the user clicks a button. I have tried:
$mainform->tab->Page4->articletext->Enable(); $mainform->tab->Page4->articletext->ReadOnly(0); $mainform->tab->Page4->articletext->ReadOnly('FALSE'); $mainform->tab->Page4->articletext(-readonly=>0); $mainform->tab->Page4->articletext->configure(-readonly=>0); # I think + this one is for tk
None of which worked. I have googled for almost an hour now and found nothing. I SuperSearched PerlMonks and found only one node Win32::GUI Chatterbox client but I couldn't find a solution to my problem there. I did notice the constant ES_READONLY used in the style option but I can't seem to find a style constant that will set it to editable.

Do I need to create the RichEdit control in a different manner? I have tried removing the -readonly=>1 option and using the ES_READONLY style when I create the control:
$form->tab->Page4->AddRichEdit(-name=>'articletext',-style=>WS_VISIBLE +|WS_VSCROLL|ES_READONLY,-multiline=>1,-text=>"",-width=>745,-height=> +450,-left=>10,-top=>35);
Then use $mainform->tab->Page4->articletext(-style=>WS_VISIBLE|WS_VSCROLL); to set it to editable but that doesn't work either.

Any help or links to good docs will be greatly appreciated.

Thanks,
Chris

Update:

I was not able to figure out how to change the readonly status so I went about it another way. Granted, I don't really like this way because it slightly increases overhead but, hey, if the mountain is too tall to climb, you just have to go around it.

The workaround:
Create two identical objects except that one is readonly and the other is not. Hide the editable object immediately after creation. When the user wants to edit the text, set the text of the editable object equal to that of the readonly object. Hide the readonly object and show the editable object. When the user is done editing and has chosen to exit the edit mode, set the text of the readonly object equal to that of the editable object. Hide the editable object and show the readonly object again. It's the long way around it, really long, but it works.

I would still like to hear of other ideas /solutions / comments anyone might have.

Replies are listed 'Best First'.
Re: Change readonly status of Win32::GUI::RichEdit
by halley (Prior) on Feb 11, 2005 at 16:58 UTC
    The read/write ability is an attribute of the control (the widget), not the text itself. I'm not familiar with the perl bindings here, so I don't know if ->articletext-> refers to the widget, or the text.

    The WS_ stands for Window Style, a Win32 staple constant. You should be able to adjust that style at runtime, but you will need to tell the control that the style has changed. Typically, both tasks are done at once with a special method (message) you invoke on the control itself, but in a pinch, there's a generic "style changed" message.

    Again, not familiar with the Win32:: perl binding module, but that's a meager start. The docs I've seen are not particularly helpful, either.

    --
    [ e d @ h a l l e y . c c ]

      Just for clarification:

      $mainform->tab->Page4->AddRichEdit(-name=>'articletext',-style=>WS_VISIBLE|WS_VSCROLL,-multiline=>1,-text=>"",-width=>745,-height=>450,-left=>10,-top=>35,-readonly=>1);
      Is used to create the object/control/widget
      The -name=>'articletext' option gives the object its name.

      The following is used to modify the object (or at least that is what i had hoped it would do).
      $mainform->tab->Page4->articletext(-readonly=>0);

      Here is a breakdown of the objects:
      $mainform = The main window object
      $mainform->tab = tab object within $mainform
      $mainform-tab->Page4 = a page object within $mainform->tab
      $mainform->tab->Page4->articletext = The RichEdit control (widget) within $mainform-tab->Page4

      I have tried using the Refresh method to inform the system of the change, however that didn't work either.
Re: Change readonly status of Win32::GUI::RichEdit
by Courage (Parson) on Feb 11, 2005 at 19:44 UTC
    I know my comment is no usefull, but can't resist noticing that RichEdit is actually 'poor edit' compared to 'Text' widget of Tk
    :)

    Sorry

      I'll agree with you on two things. You are correct in stating that your comment is not useful. I also agree that Tk's Text widget has a ton of options. However, I am not using Tk for this project. I have used Tk before and the Text widget. If I remember correctly, the Text widget has a readonly form called TextRO. Is that because the Text widget can't do this either? How do you go about changing the readonly status of the Text widget?
        first, ROText is based on Text (i mean implementation, to check do some RTFS), this means that Text is able to become unresponsive to changes.

        Second, Text have -state disabled.

        what forces you using Win32::GUI?