Preventing MouseDown on Textfield control in Cocoa App

I have a window with many fields, some that can be edited depending on the status of other fields or extraneous circumstances. Rather than constantly enabling and disabling the fields as various events occur, I want to check for the enabling condition in the MouseDown event. If the circumstances dictate the field cannot be edited, I return True and clicking on the field is ignored.

Building with Carbon, this works fine. But with Cocoa, this is not working and if the user clicks in the field the text gets selected and the focus ring activates even though I return True. Long ago, I submitted a Feedback case (20052) and it was verified. It is still not fixed and Cocoa is (supposedly) not in beta status.

This functionality seems fairly basic. If it is not working in Cocoa by now, I’m wondering if I should approach this differently but I don’t know what else to do.

I haven’t tested this with Cocoa, but can you cover up the textfield with an invisible canvas that intercepts the mousedown event first? I’ve done something like that long ago in the past, but can’t say if that approach still works or is the best, but if might be worth exploring.

I will look into that, thanks. The down side is that doubles the number of controls I have to put on the window just for one simple function.

I’d recommend against this. Accessibility APIs, AppleScript, full keyboard access, and other things can edit the text even if you return True from MouseDown.

Maybe I’m missing something here, but I’m ok with other external events editing the text. I just want to prevent the user from clicking in the field and thinking they can type in it when they can’t.

Maybe I’m not making myself clear. I have a window that is used like a form to display database records. I display the records field by field in TextFields or TextAreas. If the user wants to update a record, he presses a button and the window goes into edit mode and I set a boolean indicating editing is being done. When the save button is pressed, I turn off the boolean. In all the controls, I merely have to use the MouseDown event to prevent the user from clicking in a TextField to type in it. It still allows update of the TextField from within the app as the user selects different records to view. This has been working for me in Carbon, just not Cocoa.

A common procedure may be used for all the fields in each of the Form/Window containing all the applicable checks to enable or disable each field as necessary. This can then be called each time the value of any field changes or any event of interest takes place.

This may be the way I’ll have to go on this, but the problem here is that the text is dimmed when the TextField is disabled. That makes it harder to read.

Use the GOTFOCUS event of the TextArea and throw the focus to another control

Nice and simple! Thanks! There is a very slight flicker when I do this, but I can live with that. Now I can convert my apps to Cocoa.

There’s also a ReadOnly Property. Users will still be able to select and copy but there’s no automatic selection, edit-ability or dimmed text.

The problem I have with this approach is that I have to set the ReadOnly property at all the situations where the status could change when the change occurs. It’s easy to miss a place and also hard to keep track of all the situations. By using the MouseDown event, I can simply check the status at the time and react to it.