⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helpsys.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 2 页
字号:
  if (out) {
    l_int i;

    if (!HELPBOX(o)->f_in_split) {
      draw_bevel(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, shadow3d, light3d);
      draw_bevel(out, r.a.x+p.x+1, r.a.y+p.y+1, r.b.x+p.x-1, r.b.y+p.y-1, dark3d, face3d);
    } else {
      rect(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, flat);
      rect(out, r.a.x+p.x+1, r.a.y+p.y+1, r.b.x+p.x-1, r.b.y+p.y-1, flat);
    };

    if (!HELPBOX(o)->f_split && HELPBOX(o)->f_in_split)
    if (OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED))
      rect(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, dark3d);

    if (!HELPBOX(o)->f_split) {
      l_text old_back = HELPBOX(o)->background;
      helpbox_draw_text(HELPBOX(o), out, r, p);
      if (old_back != HELPBOX(o)->background)
        helpbox_draw_text(HELPBOX(o), out, r, p);
    };
  };
  VIEW(o)->end_of_paint(VIEW(o), r);
}

void helpbox_set_state(p_object o, l_dword st, l_bool set)
{
  view_set_state(o, st, set);
  if (st & OB_SF_FOCUSED) {
    VIEW(o)->draw_view(VIEW(o));
  };
}

void helpbox_select_me(p_helpbox o)
{
  OBJECT(o)->select(OBJECT(o));
  if (o->f_in_split)
    helpbox_select_me(HELPBOX(OBJECT(o)->owner));
}

void helpbox_handle_event(p_object o, t_event *event)
{
  view_translate_event(o, event);

  RETVIEW(o, event);

  if (!(HELPBOX(o)->flags & HBF_NOSCROLL))
  if (event->type & EV_KEYBOARD && o->is_state(o, OB_SF_FOCUSED)) {
    if (OBJECT(keyb)->state & KB_SF_KEYDOWN ) {
      switch (KEY_TO(keyb->code)) {
        case KB_DOWN: if (HELPBOX(o)->f_prg < (HELPBOX(o)->f_maxy-rect_sizey(VIEW(o)->bounds)+35)) {
          HELPBOX(o)->f_prg += 30;
          VIEW(o)->draw_view(VIEW(o));
          clear_event(event);
        }; break;
        case KB_UP: if (HELPBOX(o)->f_prg > 0) {
          HELPBOX(o)->f_prg -= 30;
          VIEW(o)->draw_view(VIEW(o));
          clear_event(event);
        }; break;
      };
    };
  };

  if (!(HELPBOX(o)->flags & HBF_UNSELECTABLE))
  if ((event->type & EV_MOUSE) && OBJECT(mouse)->state & MO_SF_MOUSELPRESS) {
    p_helpbox base = base_helpbox(HELPBOX(o));
    helpbox_select_me(HELPBOX(o));
    base->active_split = HELPBOX(o);
  };

  if ((event->type & EV_MOUSE) && (OBJECT(mouse)->state & MO_SF_MOUSEMOVE || OBJECT(mouse)->state & MO_SF_MOUSELPRESS)) {
    l_int i;
    t_point p = VIEW(o)->get_global_point(VIEW(o), point_assign(0, 0));
    t_rect r = VIEW(o)->get_local_extent(VIEW(o));
    p_helpbox ho = HELPBOX(o);
    l_int cur = CUR_ARROW;
    l_int lnk = -1;
    l_bool mouse_pressed = FALSE;

    for (i=0;i<=ho->links;i++)
      if (mouse->where.x >= ho->link[i].x1+r.a.x+p.x && mouse->where.y >= ho->link[i].y1+r.a.y+p.y &&
          mouse->where.x <= ho->link[i].x2+r.a.x+p.x && mouse->where.y <= ho->link[i].y2+r.a.y+p.y) {
        cur = CUR_FINGER;
        lnk = i;

        break;
      };

    if (VIEW(o)->cursor != cur) {
      VIEW(o)->cursor = cur;
      VIEW(o)->set_mouse_cursor(VIEW(o));
    };

    mouse_pressed = (OBJECT(mouse)->state & MO_SF_MOUSELPRESS);

    while (OBJECT(mouse)->state & MO_SF_MOUSELPRESS) {
      o->get_event(o, event);
    };
    clear_event(event);

    if (cur == CUR_FINGER && mouse_pressed) {
      p_helpbox target = HELPBOX(o);
      if (HELPBOX(o)->f_in_split && HELPBOX(o)->link[lnk].target)
        target = get_split(HELPBOX(o), HELPBOX(o)->link[lnk].target);
      target->navigate(target, HELPBOX(o)->link[lnk].where);
    };
  };
}

void helpbox_navigate(p_helpbox o, l_text where)
{
  __p_hbgbinfo tmp = o->f_back;
  if (!where) return;

  #define clear_bitmaps \
    if (o->bitmaps) do { \
      __p_hbbitmap next = o->bitmaps->next; \
      destroy_bitmap(o->bitmaps->bmp); \
      free(o->bitmaps->name); \
      free(o->bitmaps); \
      o->bitmaps = next; \
    } while (o->bitmaps)


  if (!stricmp(where, "HELP:ABOUT")) {
    if (o->text) afree(&o->text);
    if (o->topic) afree(&o->topic);
    if (o->background) afree(&o->background);
    if (o->flags & HBF_WATERMARK) o->flags &=~HBF_WATERMARK;
    clear_bitmaps;
    free_links(o);
    o->topic = strdup("help:about");

    o->text = strdup("<b>Bad Seal Help System version 0.2</b><br><br>
  HELP (Bad Seal Help System), was made at 20.05.2001 by Kostas Michalopoulos
 aka Bad Sector, mostly for use under Bad Seal GUI. But you can find HELP
 also for SEAL 1.0E and other compatible versions and distributions (like
 StarSeal).<br><br>
  For more information on how to write your own HELP (*.HLP) files, see
 HELP's documentation.<br><br>
  You can contact me at:<br>
    e-mail:<br>
      badsector@badseal.org<br>
    www:<br>
      (SEAL/Bad Seal resources page)<br>
      http://www.badseal.org/<br>
<br>
 Last Update: " __DATE__" " __TIME__ "
");
  } else if (!stricmp(where, "HELP:NONE")) {
    if (o->text) afree(&o->text);
    if (o->topic) afree(&o->topic);
    if (o->background) afree(&o->background);
    if (o->flags & HBF_WATERMARK) o->flags &=~HBF_WATERMARK;
    clear_bitmaps;
    free_links(o);
    o->topic = strdup("help:none");
    o->text = strdup("\n");
  } else if (!stricmp(where, "HELP:OPEN")) {
    l_text file;
    file = open_dialog("/", "*.hlp", get_file_items());
    if (file) {
      if (o->filename) free(o->filename);
      o->filename = file;
      o->navigate(o, "main");
      return;
    };
  } else if (!stricmp(where, "HELP:BACK")) {
    if (!o->f_back || !o->f_back->prev) {
      msgbox(MW_INFO, MB_OK, "Cannot go back");
    } else o->go_back(o);
    return;
  } else if (!o->filename) {
    if (o->text) afree(&o->text);
    if (o->topic) afree(&o->topic);
    if (o->background) afree(&o->background);
    if (o->flags & HBF_WATERMARK) o->flags &=~HBF_WATERMARK;
    clear_bitmaps;
    free_links(o);
    o->text = strdup("<b>Error: topic without file specified");
  } else {
    FILE *f;
    t_topic rec;
    t_head head;
    l_int i, pos;
    l_text s;

    if (o->text) afree(&o->text);
    if (o->topic) afree(&o->topic);
    if (o->background) afree(&o->background);
    if (o->flags & HBF_WATERMARK) o->flags &=~HBF_WATERMARK;
    clear_bitmaps;
    if (!strcmp(o->filename, "")) {
      f = NULL;
    } else {
      f = fopen(o->filename, "rb");
    };

    if (!f) {
      free_links(o);
      o->text = strdup("<b>Error: file not found, cannot open file or file not specified");
    } else {
      l_bool ok = TRUE;
      fread(&head, sizeof(t_head), 1, f);
      if (head.ID[0] != 'B' || head.ID[1] != 'S' || head.ID[2] != 'H' ||
          head.ID[3] != 'L' || head.ID[4] != 'P') {
        free_links(o);
        o->text = strdup("<b>Error: invalid file header or file is damaged");
        ok = FALSE;
      };
      if (head.version > 1) {
        free_links(o);
        o->text = strdup("<b>Error: unknown file version");
        ok = FALSE;
      };
      if (head.topics == 0) {
        free_links(o);
        o->text = strdup("<b>Error: file without topics");
        ok = FALSE;
      };
      if (ok) {
        pos = 0;
        for (i=0;i<head.topics;i++) {
          fread(&rec, sizeof(t_topic), 1, f);
          if (!stricmp(rec.name, where)) {
            pos = rec.pos;
            break;
          };
        };
        if (pos == 0) {
          o->text = malloc(1024);
          strcpy(o->text, "<b>Error: topic not found - '</b>");
          strcat(o->text, where);
          strcat(o->text, "<b>'.</b>");
          ok = FALSE;
        };
      };
      if (ok) {
        fpos_t ps = pos;
        fsetpos(f, &ps);
        s = (l_text) malloc(rec.size+1);
        fread(s, rec.size, 1, f);
        s[rec.size] = 0;
        o->text = s;
        o->topic = strdup(where);
        free_links(o);
/*        o->text = (l_text) malloc(rec.size+1);
        memcpy(o->text, s, rec.size);
        o->text[rec.size]=0;
        free(s);*/
      };
      fclose(f);
    };
  };

  if (!o->text) o->text = strdup("");

  o->f_maxy = 0;
  o->f_prg = 0;

  VIEW(o)->draw_view(VIEW(o));

  if (!o->f_avoid_bi) {
    o->f_back = (__p_hbgbinfo) malloc(sizeof(__t_hbgbinfo));
    o->f_back->where = strdup(where);
    o->f_back->prev = tmp;
  } else {
    o->f_avoid_bi = FALSE;
  };
}

l_bool helpbox_request(p_helpbox o, l_int request, void *data1, void *data2, void **rdata1)
{
  return TRUE;
}

void helpbox_go_back(p_helpbox o)
{
  __p_hbgbinfo tmp = o->f_back;

  if (o->f_split && o->active_split) {
    o->active_split->go_back(o->active_split);
    return;
  };

  if (!o->f_back || !o->f_back->prev) {
    return;
  };

  if (o->f_back->prev->where) {
    o->f_avoid_bi = TRUE;
    o->navigate(o, o->f_back->prev->where);
  };

  o->f_back = o->f_back->prev;
  free(tmp);
}

BITMAP *helpbox_get_bitmap(p_helpbox o, l_text name)
{
  FILE *f;
  t_bitmap_info rec;
  t_head head;
  int i, ii;
  BITMAP *bmp;
  int pal[256];

  __p_hbbitmap p = o->bitmaps, m;

  STANDARD_GET_BITMAP_SEARCH;

  if (!o->filename) return NULL;

  f = fopen(o->filename, "rb");
  fread(&head, sizeof(t_head), 1, f);
  if (head.bitmaps == 0 || head.version == 0) return NULL;
  for (i=0;i<head.bitmaps;i++) {
    fseek(f, sizeof(head)+head.topics*sizeof(t_topic)+i*sizeof(t_bitmap_info), SEEK_SET);
    fread(&rec, sizeof(rec), 1, f);
    if (!stricmp(rec.name, name)) {
      bmp = create_bitmap(rec.width, rec.height);

      fseek(f, rec.pos, SEEK_SET);
      for (ii=0;ii<256;ii++) {
        unsigned char r;
        unsigned char g;
        unsigned char b;
        fread(&r, 1, 1, f);
        fread(&g, 1, 1, f);
        fread(&b, 1, 1, f);
        pal[ii] = makecol(r, g, b);
      };
      for (ii=0;ii<rec.height;ii++) {
        int x;
        unsigned char col;

        for (x=0;x<rec.width;x++) {
          fread(&col, 1, 1, f);
          putpixel(bmp, x, ii, pal[(int) col]);
        };
      };

      break;
    };
  };
  fclose(f);

  ADD_BITMAP_TO_BITMAP_LIST(o, bmp, name);

  return bmp;
}

l_bool helpbox_done(p_object o)
{
  p_helpbox ho = HELPBOX(o);
  if (!view_done(o)) return false;

  if (ho->text) free(ho->text);
  if (ho->topic) free(ho->topic);
  if (ho->filename) free(ho->filename);
  if (ho->bitmaps) do {
    __p_hbbitmap next = ho->bitmaps->next;
    destroy_bitmap(ho->bitmaps->bmp);
    free(ho->bitmaps->name);
    free(ho->bitmaps);
    ho->bitmaps = next;
  } while (ho->bitmaps);
  if (ho->f_back) do {
    __p_hbgbinfo prev = ho->f_back->prev;
    if (ho->f_back->where) free(ho->f_back->where);
    free(ho->f_back);
    ho->f_back = prev;
  } while (ho->f_back);
  if (ho->background) free(ho->background);
  free_links(ho);

  return true;
}

p_helpbox _helpbox_init(p_helpbox o, t_rect r)
{
  l_int i;
  if (!o) return NULL;
  clear_type(o, sizeof(t_helpbox));
  view_init(&o->obclass, r);

  OBJECT(o)->translate_event = &helpbox_handle_event;
  OBJECT(o)->set_state = &helpbox_set_state;
  OBJECT(o)->done = &helpbox_done;

  VIEW(o)->draw = &helpbox_draw;

  o->navigate = &helpbox_navigate;
  o->go_back = &helpbox_go_back;
  o->get_bitmap = &helpbox_get_bitmap;

  o->request = &helpbox_request;

  o->text = strdup("Bad Seal help system<br>
No file loaded<br><br><br>
Click <l help:open>here<le> to open a help file.<br><br>
Click <l help:about popup>here<le> for more info about Help System.
");
  o->bitmaps = NULL;
  o->filename = NULL;
  o->topic = NULL;
  o->background = NULL;

  o->f_prg = 0;
  o->f_maxy = 0;
  o->f_back = NULL;
  o->f_avoid_bi = FALSE;
  o->f_split = FALSE;
  o->f_in_split = FALSE;
  o->active_split = NULL;
  o->splits = NULL;

  return o;
}

void open_help(l_text filename)
{
  /* i can also run HELP.EXE with only filename specified, but this
   will also check if filename is in ./help if not in current directory. */
  open_help_topic(filename, "main");
}

void open_help_topic(l_text filename, l_text topic)
{
  FILE *f = fopen(filename, "rb");
  l_text fn = (l_text) malloc(strlen(filename)+16);
  l_text args = (l_text) malloc(strlen(filename)+strlen(topic)+2);

  if (!f) {
    strcpy(fn, "./help/");
    strcat(fn, filename);
    f = fopen(fn, "rb");
    if (f) filename = fn; else {
      free(fn);
      free(args);
      msgbox(MW_ERROR, MB_OK, "Cannot find help file - %s", filename);
      return;
    };
  };
  fclose(f);

  strcpy(args, filename);
  strcat(args, " ");
  strcat(args, topic);
  if (!run_file_args(HELP_EXE, args)) {
    msgbox(MW_ERROR, MB_OK, "Help System error: cannot find help viewer");
  };

  free(args);
  free(fn);
}

#include "helpsys.exp"

#ifdef SEAL_2
SetInfoAppName("HELP");
SetInfoDesciption("SEAL2 Help System");
SetInfoCopyright("(c) 2000-2001 Kostas Michalopoulos aka Bad Sector");
SetInfoManufacturer("Bad Sector");
#endif

lib_begin(void)
{
  if (ap_process == AP_ALLOC)
  {
    AP_EXPORTLIB();
  } else
  if (ap_process == AP_INIT)
  {
    AP_SETNUMOFCALLS(1);

    #ifdef Bad_Seal
    flat = registry_color("flat_background");
    text = registry_color("edit_text");
    face3d = registry_color("3d_face");
    light3d = registry_color("3d_light");
    shadow3d = registry_color("3d_shadow");
    dark3d = registry_color("3d_dark");
    if (key_exists("current/seal/colors/link")) _link = registry_color("link"); else _link = COLOR(9);
    #else
    #ifdef SEAL_2  // means that SEAL2 is used
    flat = color_flat_face;
    text = color_3d_text;
    face3d = color_3d_face;
    light3d = color_3d_light;
    shadow3d = color_3d_shadow;
    dark3d = color_3d_dark;
    _link = COLOR(9);
    #else
    flat = color_get_from_ini("text_input_background");
    text = color_get_from_ini("text");
    face3d = color_get_from_ini("3D_background");
    light3d = COLOR(15);
    shadow3d = COLOR(0);
    dark3d = COLOR(0);
    _link = COLOR(9);
    #endif
    #endif
  };
} lib_end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -