Deal with the warnings generated when passing a pointer-to-enum to
[u/mdw/putty] / unix / pterm.c
index 03017ec..58f9846 100644 (file)
@@ -38,6 +38,8 @@ struct gui_data {
     int pasteout_data_len;
     int font_width, font_height;
     int ignore_sbar;
+    int mouseptr_visible;
+    guint term_paste_idle_id;
     GdkAtom compound_text_atom;
     char wintitle[sizeof(((Config *)0)->wintitle)];
 };
@@ -59,8 +61,10 @@ void ldisc_update(int echo, int edit)
 int askappend(char *filename)
 {
     /*
-     * FIXME: for the moment we just wipe the log file. Since I
-     * haven't yet enabled logging, this shouldn't matter yet!
+     * Logging in an xterm-alike is liable to be something you only
+     * do at serious diagnostic need. Hence, I'm going to take the
+     * easy option for now and assume we always want to overwrite
+     * log files. I can always make it properly configurable later.
      */
     return 2;
 }
@@ -186,6 +190,7 @@ void show_mouseptr(int show)
        gdk_window_set_cursor(inst->area->window, inst->currcursor);
     else
        gdk_window_set_cursor(inst->area->window, inst->blankcursor);
+    inst->mouseptr_visible = show;
 }
 
 gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
@@ -193,6 +198,11 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
     struct gui_data *inst = (struct gui_data *)data;
     int w, h, need_size = 0;
 
+    /*
+     * Set up the colour map.
+     */
+    palette_reset();
+
     w = (event->width - 2*cfg.window_border) / inst->font_width;
     h = (event->height - 2*cfg.window_border) / inst->font_height;
 
@@ -226,11 +236,6 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
        term_size(h, w, cfg.savelines);
     }
 
-    /*
-     * Set up the colour map.
-     */
-    palette_reset();
-
     return TRUE;
 }
 
@@ -276,7 +281,6 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
 
        /*
         * NYI:
-        *  - nethack mode
         *  - alt+numpad
         *  - Compose key (!!! requires Unicode faff before even trying)
         */
@@ -748,13 +752,6 @@ gint timer_func(gpointer data)
     return TRUE;
 }
 
-gint idle_func(gpointer data)
-{
-    /* struct gui_data *inst = (struct gui_data *)data; */
-    term_paste();
-    return TRUE;
-}
-
 void pty_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
 {
     /* struct gui_data *inst = (struct gui_data *)data; */
@@ -806,7 +803,7 @@ void set_raw_mouse_mode(int activate)
        inst->currcursor = inst->rawcursor;
     else
        inst->currcursor = inst->textcursor;
-    show_mouseptr(1);
+    show_mouseptr(inst->mouseptr_visible);
 }
 
 void request_resize(int w, int h)
@@ -922,6 +919,8 @@ void request_paste(void)
                          GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME);
 }
 
+gint idle_paste_func(gpointer data);   /* forward ref */
+
 void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
                        gpointer data)
 {
@@ -938,8 +937,24 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
             inst->pastein_data, inst->pastein_data_len);
 
     term_do_paste();
+
+    if (term_paste_pending())
+       inst->term_paste_idle_id = gtk_idle_add(idle_paste_func, inst);
 }
 
+gint idle_paste_func(gpointer data)
+{
+    struct gui_data *inst = (struct gui_data *)data;
+
+    if (term_paste_pending())
+       term_paste();
+    else
+       gtk_idle_remove(inst->term_paste_idle_id);
+
+    return TRUE;
+}
+
+
 void get_clip(wchar_t ** p, int *len)
 {
     if (p) {
@@ -1031,7 +1046,6 @@ void do_text(Context ctx, int x, int y, char *text, int len,
     /*
      * NYI:
      *  - Unicode, code pages, and ATTR_WIDE for CJK support.
-     *  - LATTR_* (ESC # 4 double-width and double-height stuff)
      *  - cursor shapes other than block
      *  - shadow bolding
      */
@@ -1052,6 +1066,14 @@ void do_text(Context ctx, int x, int y, char *text, int len,
        nbg = NCOLOURS-1;
     }
 
+    if (lattr != LATTR_NORM) {
+       x *= 2;
+       if (x >= cols)
+           return;
+       if (x + len*2 > cols)
+           len = (cols-x)/2;          /* trim to LH half */
+    }
+
     gdk_gc_set_foreground(gc, &inst->cols[nbg]);
     gdk_draw_rectangle(inst->pixmap, gc, 1,
                       x*inst->font_width+cfg.window_border,
@@ -1074,6 +1096,44 @@ void do_text(Context ctx, int x, int y, char *text, int len,
                      y*inst->font_height + uheight + cfg.window_border);
     }
 
+    if (lattr != LATTR_NORM) {
+       /*
+        * I can't find any plausible StretchBlt equivalent in the
+        * X server, so I'm going to do this the slow and painful
+        * way. This will involve repeated calls to
+        * gdk_draw_pixmap() to stretch the text horizontally. It's
+        * O(N^2) in time and O(N) in network bandwidth, but you
+        * try thinking of a better way. :-(
+        */
+       int i;
+       for (i = 0; i < len * inst->font_width; i++) {
+           gdk_draw_pixmap(inst->pixmap, gc, inst->pixmap,
+                           x*inst->font_width+cfg.window_border + 2*i,
+                           y*inst->font_height+cfg.window_border,
+                           x*inst->font_width+cfg.window_border + 2*i+1,
+                           y*inst->font_height+cfg.window_border,
+                           len * inst->font_width - i, inst->font_height);
+       }
+       len *= 2;
+       if (lattr != LATTR_WIDE) {
+           int dt, db;
+           /* Now stretch vertically, in the same way. */
+           if (lattr == LATTR_BOT)
+               dt = 0, db = 1;
+           else
+               dt = 1, db = 0;
+           for (i = 0; i < inst->font_height; i+=2) {
+               gdk_draw_pixmap(inst->pixmap, gc, inst->pixmap,
+                               x*inst->font_width+cfg.window_border,
+                               y*inst->font_height+cfg.window_border+dt*i+db,
+                               x*inst->font_width+cfg.window_border,
+                               y*inst->font_height+cfg.window_border+dt*(i+1),
+                               len * inst->font_width, inst->font_height-i-1);
+           }
+       }
+       len *= 2;
+    }
+
     gdk_draw_pixmap(inst->area->window, gc, inst->pixmap,
                    x*inst->font_width+cfg.window_border,
                    y*inst->font_height+cfg.window_border,
@@ -1253,6 +1313,14 @@ int main(int argc, char **argv)
            } else
                err = 1, fprintf(stderr, "pterm: -T expects an argument\n");
        }
+       if (!strcmp(p, "-log")) {
+           if (--argc > 0) {
+               strncpy(cfg.logfilename, *++argv, sizeof(cfg.logfilename));
+               cfg.logfilename[sizeof(cfg.logfilename)-1] = '\0';
+               cfg.logtype = LGTYP_DEBUG;
+           } else
+               err = 1, fprintf(stderr, "pterm: -log expects an argument\n");
+       }
        if (!strcmp(p, "-hide")) {
            cfg.hide_mouseptr = 1;
        }
@@ -1335,7 +1403,6 @@ int main(int argc, char **argv)
                       GTK_SIGNAL_FUNC(selection_clear), inst);
     gtk_signal_connect(GTK_OBJECT(inst->sbar_adjust), "value_changed",
                       GTK_SIGNAL_FUNC(scrollbar_moved), inst);
-    gtk_idle_add(idle_func, inst);
     gtk_timeout_add(20, timer_func, inst);
     gdk_input_add(pty_master_fd, GDK_INPUT_READ, pty_input_func, inst);
     gtk_widget_add_events(GTK_WIDGET(inst->area),