#import <objc/HashTable.h>
#import <stdio.h>
#import <string.h>
#import <stdlib.h>
#import <ctype.h>
#import "structures.h"
#import "Htag.h"
#import "TeXviewSwitchBoard.h"

extern TeXviewSwitchBoard *myTeXviewSwitchBoard ;
extern Boolean      prescan;
extern shalfword    hh, vv;
extern integer      pagenum;
extern int          lasthh, lastvv;
extern int          last_pagenum;
//extern id           htags;
//extern id           htpages;
//extern id           page;
extern shalfword    hh, vv;
extern shalfword    hhoffset, vvoffset;
extern shalfword    hhmarg, vvmarg;
extern int          ht_highlight;
extern id           ht_highlight_tag;
void
draw_all_ht_pt(int sheetview)
{
    char               *key;
    id                  value;
    NXHashState         state;
    id                  htpages ;
    id page  ;
    htpages = [myTeXviewSwitchBoard getCurrentHtpages] ;
    page = [htpages valueForKey:(void *)pagenum];
    if (!page)
	return;
    state = [page initState];

    while ([page nextState:&state key:(void *)&key value:(void *)&value]) {
	[value paintBox:0.66666:0.0];
    }
    if (ht_highlight) {
/*Need to highlight a target that we just moved to*/
	[ht_highlight_tag showSelf:(id)sheetview];
	[ht_highlight_tag paintBox:0.2:3.0];
    }
}
#define BIGH 17
#define SMALLH 9
int
process_ht_click(int x, int y,id sheetview, int cmdclk)
{
    char               *key;
    id                  value;
    NXHashState         state;
    id                  htpages ;
    id page  ;
    htpages = [myTeXviewSwitchBoard getCurrentHtpages] ;
    page = [htpages valueForKey:(void *)pagenum];
    state = [page initState];
    x = x - hhoffset;
    y = y - vvoffset;
    if (ht_highlight)
	if ([ht_highlight_tag checkIfHit:x :y :sheetview: SMALLH: cmdclk])
	    return 1;

    while ([page nextState:&state key:(void *)&key value:(void *)&value]) {
	if ([value checkIfHit:x :y :sheetview :SMALLH: cmdclk])
	    return 1;
    } 
    if (ht_highlight)
	if ([ht_highlight_tag checkIfHit:x :y :sheetview: BIGH: cmdclk])
	    return 1;

    while ([page nextState:&state key:(void *)&key value:(void *)&value]) {
	if ([value checkIfHit:x :y :sheetview :BIGH:cmdclk])
	    return 1;
    } 

return 0;
}
