home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* */
- /* window_error Display an error message in a small window and */
- /* await confirmation before returning. */
- /* */
- /************************************************************************/
-
- #include <suntool/sunview.h>
- #include <suntool/panel.h>
-
- #include "contool.h"
-
- #define charwidth_of(f) ((f)->pf_char['0'].pc_adv.x)
- #define charheight_of(f) ((f)->pf_defaultsize.y)
-
- PUBLIC Pixrect *better_button_image();
-
- EXPORT Frame confirmer = NULL;
- PRIVATE Panel panel = NULL;
-
- PRIVATE struct pixfont *pf = NULL;
-
- /************************************************************************/
- PRIVATE confirmed(item, event)
-
- Panel_item item;
- Event *event;
-
- {
- if (event_is_up(event))
- window_return(0);
- }
-
- /************************************************************************/
- EXPORT window_error(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)
-
- char *s0;
- char *s1;
- char *s2;
- char *s3;
- char *s4;
- char *s5;
- char *s6;
- char *s7;
- char *s8;
- char *s9;
-
- { char buf[1024], message[1024], **p, *b, *m;
- int i, j, k, left, top, width, lines;
- Rect *r;
- Pixrect *image;
- Panel_item *item, button;
-
- if (pf == NULL)
- pf = pf_open(BOLD_FONT);
- if (confirmer == NULL) {
- confirmer = window_create(0, FRAME,
- FRAME_NO_CONFIRM, TRUE,
- FRAME_SHOW_LABEL, FALSE,
- 0);
- panel = window_create(confirmer, PANEL,
- PANEL_BACKGROUND_PROC, confirmed,
- 0);
- }
-
- sprintf(message, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
- for (m = message, b = buf, i = 0, lines = 1; *m; m++, b++, i++)
- if (*m == '\t') {
- for (j = i % 8; j < 8; j++, i++)
- *b++ = ' ';
- i--, b--;
- }
- else if ((*b = *m) == '\n') {
- i = -1;
- lines++;
- }
- *b = '\0';
-
- item = (Panel_item *) malloc(lines * sizeof(Panel_item));
- for (b = m = buf, i = 4, width = 0, k = 0; k < lines; b++)
- if (*b == '\n' || *b == '\0') {
- *b = '\0';
- item[k++] = panel_create_item(panel, PANEL_MESSAGE,
- PANEL_LABEL_STRING, m,
- PANEL_LABEL_FONT, pf,
- PANEL_ITEM_X, 4,
- PANEL_ITEM_Y, i,
- 0);
- width = (width < (j = charwidth_of(pf) * strlen(m)))? j : width;
- i += charheight_of(pf) + 4;
- m = b + 1;
- }
- window_fit_width(panel);
- image = better_button_image(panel, "OK", 12, 0, pf);
- button = panel_create_item(panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, image,
- PANEL_ITEM_X, (width - image->pr_width) / 2 + 4,
- PANEL_ITEM_Y, i,
- PANEL_NOTIFY_PROC, confirmed,
- 0);
- window_fit(panel);
- window_fit(confirmer);
- r = (Rect *) window_get(confirmer, WIN_SCREEN_RECT);
- left = (r->r_width - (int) window_get(confirmer, WIN_WIDTH)) / 2;
- top = (r->r_height - (int) window_get(confirmer, WIN_HEIGHT)) / 2;
- if (left < 0) left = 0;
- if (top < 0) top = 0;
- window_set(confirmer, WIN_X, left, WIN_Y, top, 0);
- window_loop(confirmer);
- panel_destroy_item(button);
- for (i = 0; i < lines; i++)
- panel_destroy_item(item[i]);
- free(item);
- }
-