Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!ubc-cs!alberta!uqv-mts!Steve_Wart From: userRED3@ualtamts.BITNET (Steve Wart) Newsgroups: comp.sys.mac.programmer Subject: More problems with dialogs and textedit Message-ID: <217@ualtamts.BITNET> Date: 1 Aug 89 21:53:59 GMT Organization: University of Alberta (MTS) Lines: 73 I've been having some difficulty lately with modeless dialogs containing more than a few editable text items. The problem is largely due to the fact that the default update routine for these items draws a border with a 3 pixel offset around the item's rectangle. I don't want this offset; it makes the edit fields too small. (I'm using a 9 point font and only digital characters, so I'm not too concerned about them not fitting within the borders.) My solution has been to bypass IsDialogEvent and DialogSelect completely, handling the keyboard and mouse events myself. This has led to certain problems. I wrote a routine called "UseTextItem" (see below) which is called whenever someone clicks the mouse in a text field other than the current one. This routine seems to alter the text in the dialog's item list. There must be simple reason that it's messing things up, but I'm blind to it. I was originally calling it when a keyboard event indicated that a new field was to be hilighted (e.g. when the tab key was pressed, I would call UseTextItem(theDialog, editField + 2). Note that DialogPeek(theDialog)^.editField refers to the item number of the text field minus one), but I discovered that all I had to do was call SelIText(theDialog, editField + 2, 0, 32767). This works well when I want the entire field to be hilighted, but I'm not sure what I should do to handle mouse events (i.e. double clicks, etc.). There are other solutions. I could avoid dialogs altogether and keep 35 textedit fields, but that doesn't solve the other problem I'm having; namely aligning the text items in the little boxes. When I get an update event, I draw all the inactive fields with DrawString and they look swell. The active field however, is always a few pixels off. As usual, any comments, suggestions or explanations are welcome. procedure UseTextItem( dialog : DialogPtr; itemNum : Integer ); { Set the dialog's text edit field to itemNum. ItemNum should reference a editable text field. } var box : Rect; itemType : Integer; item : Handle; text : Str255; begin SetPort(dialog); GetDItem(dialog, itemNum, itemType, item, box); with DialogPeek(dialog)^, DialogPeek(dialog)^.textH^^ do begin if editField = itemNum - 1 then exit(UseTextItem); HLock(Handle(textH)); TEDeactivate(textH); { remove hilighting, caret } GetIText(item, text); viewRect := box; with box do { attempt to align text properly } SetRect(destRect, left, top - 1, right - 1, bottom); editField := itemNum - 1; TESetText(item^, Length(text), textH); InvalRect(viewRect); TEActivate(textH); HUnlock(Handle(textH)) end end { of UseTextItem }; You can attempt to reach me at the following address: steve_wart@ualtamts.BITNET