Example #1
0
void
helpForHyperDoc()
{
    HyperDocPage *page = NULL;

    /* do not do anything if we are already at the "no more help" page */

    if (0 == strcmp(gWindow->page->name, NoMoreHelpPage))
        return;

    /* if no help page recorded, use the standard "no more help" page */

    if (!gWindow->page->helppage)
        gWindow->page->helppage = alloc_string(NoMoreHelpPage);

    /* if we are on the main help page, use "no more help" page */

    if (0 == strcmp(gWindow->page->name, TopLevelHelpPage))
        gWindow->page->helppage = alloc_string(NoMoreHelpPage);

    page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, gWindow->page->helppage);

    if (page)
        make_window_link(gWindow->page->helppage);
    else
        BeepAtTheUser();
}
Example #2
0
void
handle_key(XEvent *event)
{
  char key_buffer[20];
  int key_buffer_size = 20;
  KeySym keysym;
  XComposeStatus compstatus;
  int charcount;
  int display_again = 0;
  char *name;
  char *filename;
  /*char *head = "echo htadd -l ";*/
  /*char *blank1 = "                                        ";*/
  /*char *blank2 = "                                       \n";*/
  char buffer[180];
  FILE *filehandle;

  charcount = XLookupString((XKeyEvent *)event, key_buffer, key_buffer_size, &keysym ,&compstatus); /* 5 args */

  key_buffer[charcount] = '\0';
  switch (keysym) {
  case XK_Prior:
  case XK_F29:
    scrollUpPage();
    break;
  case XK_Next:
  case XK_F35:
    scrollDownPage();
    break;
  case XK_F3:
  case XK_F12:
    quitHyperDoc();
    break;
  case XK_F5:
    if (event->xkey.state & ShiftMask) {
      name = gWindow->page->name;
      filename = gWindow->page->filename;
      sprintf(buffer, "htadd -l %s\n", filename);
      system(buffer);
      filehandle = (FILE *) hash_find(&gFileHashTable, filename);
      fclose(filehandle);
      hash_delete(&gFileHashTable, filename);
      gWindow->fMacroHashTable =
        (HashTable *) halloc(sizeof(HashTable), "macro hash");
      hash_init(
                gWindow->fMacroHashTable,
                MacroHashSize,
                (EqualFunction ) string_equal,
                (HashcodeFunction) string_hash);
      gWindow->fPatchHashTable = (HashTable *) halloc(sizeof(HashTable), "patch hash");
      hash_init(
                gWindow->fPatchHashTable,
                PatchHashSize,
                (EqualFunction ) string_equal,
                (HashcodeFunction) string_hash);
      gWindow->fPasteHashTable = (HashTable *) halloc(sizeof(HashTable), "paste hash");
      hash_init(gWindow->fPasteHashTable,
                PasteHashSize,
                (EqualFunction ) string_equal,
                (HashcodeFunction) string_hash);
      gWindow->fCondHashTable = (HashTable *) halloc(sizeof(HashTable), "cond hash");
      hash_init(
                gWindow->fCondHashTable,
                CondHashSize,
                (EqualFunction ) string_equal,
                (HashcodeFunction) string_hash);
      gWindow->fPageHashTable = (HashTable *) halloc(sizeof(HashTable), "page hash");
      hash_init(
                gWindow->fPageHashTable,
                PageHashSize,
                (EqualFunction ) string_equal,
                (HashcodeFunction) string_hash);
      make_special_pages(gWindow->fPageHashTable);
      read_ht_db(
                 gWindow->fPageHashTable,
                 gWindow->fMacroHashTable,
                 gWindow->fPatchHashTable);
      gWindow->page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, name);
      if (gWindow->page == NULL) {
        fprintf(stderr, "lose...gWindow->page for %s is null\n", name);
        exit(-1);
      }
      display_again = 1;
    }
    break;
  case XK_F9:
    make_window_link(KeyDefsHelpPage);
    break;
  case XK_Tab:
    if (event->xkey.state & ShiftMask)
      prev_input_focus();
    else if (event->xkey.state & ModifiersMask)
      BeepAtTheUser();
    else
      next_input_focus();
    break;
  case XK_Return:
    if (!(event->xkey.state & ShiftMask)) {
      next_input_focus();
      break;
    }

    /* next ones fall through to input area handling */

  case XK_Escape:
    if (!gWindow->page->current_item)
      break;
  case XK_F1:
    if (!gWindow->page->current_item) {
      gWindow->page->helppage = alloc_string(NoMoreHelpPage);
      helpForHyperDoc();
      break;
    }
  case XK_Home:
    if (!gWindow->page->current_item) {
      scrollToFirstPage();
      break;
    }
  case XK_Up:
    if (!gWindow->page->current_item) {
      scrollUp();
      break;
    }
  case XK_Down:
    if (!gWindow->page->current_item) {
      scrollDown();
      break;
    }

  default:
    display_again = 0;
    dialog(event, keysym, key_buffer);
    XFlush(gXDisplay);
    break;
  }

  if (display_again) {
    display_page(gWindow->page);
    gWindow->fWindowHashTable = gWindow->page->fLinkHashTable;
  }
}