IAC Driver Demo (code 2)
Volume Number: 4
Issue Number: 11
Column Tag: Advanced Mac'ing
IAC Driver Demo in MPW C (code)
Listing: Edit_IAC_rtns.c
# include
# include
# include
# include
# include < windows.h>
# include < dialogs.h>
# include
# include
# include
# include < files.h>
# include < resources.h>
# include
# define PUBLIC extern
# include
#define noErr 0
/* 0 for success */
/**
* Routine: Set Current Extent
*
* This is a local routine to set the fields in the ‘ current
extent’ structure in the window data record. It is called by both
hotCopy and hotPaste routines, since by definitions the extents they
define become the ‘current extent’. */
# define __SEG__ Main
void set_curr_ext(the_data_H, which)
win_dataH the_data_H; /* data associated with the window */
short which; /* # of extent which is now current */
{
extentH the_extH; /* handle to extent block */
exTable ext_recs;
the_extH = (**the_data_H).the_extents;
ext_recs = *the_extH;
curr_ext.src_doc = ext_recs[ which].src_doc;
curr_ext.hat_check = ext_recs[ which].hat_check;
curr_ext.ed_level = ext_recs[ which].ed_level;
curr_ext.ext_strt = ext_recs[ which].ext_strt;
curr_ext.ext_end = ext_recs[ which].ext_end;
}
/**
* Routine: do_hotCopy
*
* This routine is responsible for creating a new dependency
source and notifying the IAC driver. It is called primarily by the
“source” program. */
# define __SEG__ Main
void do_hotCopy()
{
win_dataH the_data_H; /* data associated with a window */
TEHandle TextH; /* The TextEdit handle */
extentH the_extH; /* handle to extent block */
exTable ext_recs;
long the_doc; /* local copies due to memory mashing */
short slot_ID, h_check, the_ed;
short e_cnt;
short item_hit; /* error processing */
Str255 err_str, str2;
short iac_err = noErr;
Boolean in_extent = false;
extern Boolean chk_extent(); /* sets “current extent” if found */
extern void add_display_cmd(); /* update ‘Links’ menu */
extern void set_curr_ext(); /* update global structure */
extern Boolean ext_active;
the_data_H = (win_dataH) GetWRefCon (myWindow);
the_extH = (**the_data_H).the_extents;
TextH = (**the_data_H).wind_TEH;
the_doc = (**the_data_H).doc_ID;
slot_ID = (**the_data_H).the_slot;
e_cnt = (**the_data_H).ext_cnt;
h_check = 0;
if (!chk_extent(TextH, the_extH, (**the_data_H).ext_cnt))
{
iac_err = iac_add_dependency(&the_doc, &slot_ID, &h_check,
&the_ed);
if (iac_err == noErr)
{
SetHandleSize ((Handle)the_extH, sizeof(extent) * (e_cnt+1));
ext_recs = *the_extH;
ext_recs[e_cnt].hat_check = h_check;
ext_recs[e_cnt].ed_level = the_ed;
ext_recs[e_cnt].ext_strt = (**TextH).selStart;
ext_recs[e_cnt].ext_end = (**TextH).selEnd;
ext_recs[e_cnt].src_doc = the_doc;
set_curr_ext(the_data_H,e_cnt);
curr_ext_no = e_cnt;
e_cnt += 1;
(**the_data_H).doc_ID = the_doc; /* update window */
(**the_data_H).the_slot = slot_ID;
(**the_data_H).ext_cnt = e_cnt;
(**the_data_H).dirty = true; /* so save extents */
ext_active = true;
iac_err = ext_write(TextH,
(**TextH).selStart,
((**TextH).selEnd - (**TextH).selStart),
the_doc,
h_check,
&the_ed);
add_display_cmd(curr_ext_no, e_cnt); /* update menu */
}
else /* IAC alert here */
{
NumToString ((long)iac_err, &err_str);
ParamText (&err_str, “Hot Copy”, nil, nil);
item_hit = StopAlert(IAC_ERR_ALRT, nil);
}
}
else /* already-in-extent alert */
{
ParamText (“\”already-in-extent\””, “Hot Copy”, nil, nil);
item_hit = StopAlert(IAC_ERR_ALRT, nil);
}
}
/**
* Routine: do_hotPaste
*
* This routine is responsible for completing a new dependency and
notifying the IAC driver. It is called primarily by the “ target”
program. The dependencies are stored in the array in ascending
sequence to make updating simpler. See the header for poll_iac() for
details. */
# define __SEG__ Main
void do_hotPaste()
{
win_dataH the_data_H; /* data associated with a window */
TEHandle TextH; /* The TextEdit handle */
extentH the_extH; /* handle to extent block */
exTable ext_recs;
long the_doc; /* local copies due to memory mashing */
short slot_ID, h_check;
short e_cnt, startt;
short the_ed;
short item_hit; /* error processing */
Str255 err_str, str2;
short i = 0;
short iac_err = noErr;
Boolean in_extent = false;
extern Boolean chk_extent(); /* sets “current extent” */
extern void add_display_cmd(); /* update ‘Links’ menu */
extern Boolean ext_active;
the_data_H = (win_dataH) GetWRefCon (myWindow);
the_extH = (**the_data_H).the_extents;
TextH = (**the_data_H).wind_TEH;
slot_ID = (**the_data_H).the_slot;
e_cnt = (**the_data_H).ext_cnt;
the_doc = 0; /* just link to “available” */
h_check = 0;
if (!chk_extent(TextH, the_extH, e_cnt))
{
iac_err = iac_complete_dependency(&the_doc, &slot_ID, &h_check);
if (iac_err == noErr) /* save “location” in TERec as extent */
{
(**the_data_H).the_slot = slot_ID; /* update window */
ext_active = true;