using IUP - Is there any way to clear all the content out of a IupText object? - iup

using IUP - Is there any way to clear all the content out of a IupText object? I'm implementing a very simple 4 line display that is supposed to emulate a hardware device. Unfortunately, through days of experimentation, I found that using IupInsert eventually reaches a limit, so you need to delete the contents. The only way I was able to simulate this was to destroy the IupText object and the IupDialog object containing it. This is very inefficient and ugly, but the documentation is misleading. I also attempted to detach and destroy the text box, without destroying the dialog, but I was unable to insert/append a new text box that would actually show up on the screen. The return value from the append was valid, but even after refresh, IupShow, etc., the dlg would never display the text again. Thank you for any insights

Just set the VALUE attribute to "".

Related

UNbound Text Box wont save

I have a form onto which I have placed an unbound text box. This box is designed to calculate the total of 4 other bound text boxes which have simple numerical values in. I have used the expression builder in the unbound text box to set its control source property i.e. =([box1]+[box2]+[box3]+[box4])
When I first put this in it works fine. However after I close and then reopen the data base the box sits on the form saying #NAME? as if it has lost its control source. I have checked the data source after and nothing seems to be wrong. Any ideas why its happening. Its a pain as I have a button which when pressed opens a report based on the value in the unbound text box.
Try using Nz:
=Nz([box1],0)+Nz([box2],0)+Nz([box3],0)+Nz([box4],0)
Not entirely sure why it now works but I have re added the text box and the calculations into the source code and it seems to be fine. Perhaps just a glitch in my previous attempt... I used the =sum solution rather than the =Nz solution. Maybe my version of access or my data base is just fickle... thanks anyway

Removing text from NSTextView

I have created an NSTextView and managed to populate it using a getter for the scroll view that it is nested in, and using the .insertText() function.
How do I empty the same NSTextView? I have read the documentation and there doesn't seem to be a function .removeText(). It seems a bit weird that Apple would allow you to insert data but not remove it programmatically. I have searched high and low for answers but have come up empty handed.
You can't set the text of the text view directly, but you can set its textStorage's, getting that object's mutableString, which it inherits from NSMutableAttributedString, and then using setString(), passing an empty string.
No idea what I was thinking. Use var string { get set }, inherited from NSText.
If you set the text on the textview directly you'll lose the ability to automatically have the undo manager pick that change up.
I've found it more reliable to first select all the text and then delete it.
[self.textInput selectAll:self];
[self.textInput delete:self];

Windows Phone 7.1 data binding confusion

I'm trying to work out how to catch a data binding in the act (either intercept or post-process) to customize the display of data in the target control.
I know about IValueConvertor and understand that I can transform a simple value into another simple value, but I don't believe this is enough for my needs... which are:
The control in this case is a TextBlock and the data values from the objects in my ObservableCollection are variable length strings. I want to render the strings in multiple colours by splitting them into pieces and programatically creating a <Run Foreground="xxx" Text="yyy"/> for each piece inside the TextBlock.
Since the strings are variable length and the colours have to be programatically determined from the content of the string, I don't believe I can pre-create the <Run>s in the XAML, so I have to somehow get in on the data binding action and generate the <Run>s at bind-time (or very soon after).
Binding.NotifyOnTargetUpdated would seem to be a way to set up an event handler to do the work, but that's not available in the Windows Phone cut-down Silverlight implementation.
Any ideas? All search results seem to point to the above, but I'm looking for that little bit more.
Having apparently exhausted all the cut-down Silverlight on Windows Phone options for programmatically hooking the rendering of ListBoxItems via the data model, I ended up adding a Loaded="..." event handler to the XAML for the TextBlock.
It doesn't feel like the nicest solution, but perhaps that's just my code-preference talking and it's actually the right way to do it on Windows Phone.
In any case, because I'm hooked to the TextBlock directly, I'm not sure how to then get to the databound object on the ListBoxItem containing the TextBlock... if anyone has advice on how to get back up the tree to the generated ListBoxItem then I could use the bound object directly instead of retrieving it from elsewhere.
Note that since the ListBoxItem is generated, I didn't find where to put a Loaded="..." event handler for that in the XAML. The ListBox.ItemTemplate doesn't accept a Loaded attribute.
Update: this doesn't work!
The Loaded event handler fires when the TextBlock is first created and loaded, so the substitution works initially.
BUT
The generated ListBoxItem seems to be recycled (I guess by the ListBox.ItemContainerGenerator which doesn't want to use excessive amounts of memory by instantiating a whole new container when there are many off-screen entries in the list that won't need to be seen for a while) and when this happens, the Loaded event DOES NOT FIRE.
Since I modify the content when the TextBlock was first Loaded, this breaks the binding association so when the ListBoxItem is recycled, it now contains old/incorrect data.
Still no solution.
I'm thinking about trying to use an IValueConvertor and somehow pass a reference to the binding target... now sure how yet though.
Update 2: finally got it to work...
Sticking with the Loaded="..." event handler, it is possible to disable recycling of previously-generated ListBoxItems by configuring the VirtualizingStackPanel used by the ListBox under the covers.
In the XAML for the ListBox set VirtualizingStackPanel.VirtualizationMode="Standard" to force a new ListBoxItem to be generated each time instead of recycling previously-generated ones.
This means the Loaded event handler is called every time and I can replace the ordinary text of the TextBlock with the <Run>s to produce dynamically coloured text.

How can I make a console-like textbox?

I am making a program called "BasicSys". It is a BASIC System simulator that uses a textbox for the console. So far I have everything working great but I need to have the text box act like a command prompt window. It needs to be able to ask for input and retreive the value without allowing the user to modify anything outside of the prompt space (the space where the user should only be able to type is after a ":" or a ">"). Some feilds are password feilds that require either no echoing or having the chartacters replaced by *'s. Is it possible to make a console out of a textbox?
P.S. I also want to know if there are any small BASIC v2 compilers for Win32 so BasicSys can compile and run BASIC programs.
Depending on how realistic you want it to be you can use the API to open a real console window and interact with it. There are many examples available that you can find by searching such as this one. My suggestion though would be to fake it with a multi-line textbox. It would not be very tricky. Set an index every time you draw the prompt, then as long as the cursor is positioned after the index the textbox is read / write. If the user scrolls backwards make the textbox read only. It should be fairly simple using the KeyDown event and setting the ReadOnly property True / False to get a passable "command" window.

Setting value of AXTextField programmatically (OS X Cocoa Accessibility API)

I'm using the Cocoa Accessibility API to try and modify the value of a text field (AXTextField) in another application, but I've run into a problem: my code correctly identifies and modifies the contents of the text field in question, and the text of the field visibly changes, but the changes aren't registered by the program I'm trying to control. Is there a way to do this in with the API without having to generate keyboard events?
Sample code:
AXUIElementCopyElementAtPosition(appRef,
clickPoint.x,
clickPoint.y,
&boxRef);
NSString *valueToSet = [NSString stringWithFormat:#"%f",amount];
AXUIElementSetAttributeValue(boxRef,kAXValueAttribute,valueToSet);
And the text field changes to the value specified in "amount" but the other program doesn't recognize the change - I have to go type the number in myself to get it to pick up the change (I can tell the difference, because the program responds when a new value is typed in the box). Can anyone point me in the right direction?
For posterity: Informed sources tell me that this is actually a bug in the application I'm trying to control. You can tell the difference by using UI Browser (http://prefabsoftware.com/uibrowser/) to try and set the value of the textfield; if UI Browser can't make the change stick, then the matter is out of your control.
Try telling the text field:
perform action "AXConfirm"
This is Applescript, but whatever the Cocoa equivalent is, it may make the change stick even if UI Browser can not (I've used it before).

Resources