Add asynchronous callback capability to the askappend() alert box.
[u/mdw/putty] / mac / macterm.c
index c81e635..78efa65 100644 (file)
@@ -87,6 +87,8 @@ static void mac_drawgrowicon(Session *s);
 static pascal void mac_growtermdraghook(void);
 static pascal void mac_scrolltracker(ControlHandle, short);
 static pascal void do_text_for_device(short, short, GDHandle, long);
+static void do_text_internal(Context, int, int, wchar_t *, int,
+                            unsigned long, int);
 static void text_click(Session *, EventRecord *);
 static void mac_activateterm(WindowPtr, EventRecord *);
 static void mac_adjusttermcursor(WindowPtr, Point, RgnHandle);
@@ -305,18 +307,6 @@ static pascal OSStatus uni_to_font_fallback(UniChar *ucp,
 }
 
 /*
- * Called every time round the event loop.
- */
-void mac_pollterm(void)
-{
-    Session *s;
-
-    for (s = sesslist; s != NULL; s = s->next) {
-       term_update(s->term);
-    }
-}
-
-/*
  * To be called whenever the window size changes.
  * rows and cols should be desired values.
  * It's assumed the terminal emulator will be informed, and will set rows
@@ -324,14 +314,18 @@ void mac_pollterm(void)
  */
 static void mac_adjustsize(Session *s, int newrows, int newcols) {
     int winwidth, winheight;
+    int extraforscroll;
 
-    winwidth = newcols * s->font_width + 15;
+    extraforscroll=s->cfg.scrollbar ? 15 : 0;
+    winwidth = newcols * s->font_width + extraforscroll;
     winheight = newrows * s->font_height;
     SizeWindow(s->window, winwidth, winheight, true);
-    HideControl(s->scrollbar);
-    MoveControl(s->scrollbar, winwidth - 15, -1);
-    SizeControl(s->scrollbar, 16, winheight - 13);
-    ShowControl(s->scrollbar);
+    if (s->cfg.scrollbar) {
+        HideControl(s->scrollbar);
+        MoveControl(s->scrollbar, winwidth - extraforscroll, -1);
+        SizeControl(s->scrollbar, extraforscroll + 1, winheight - 13);
+        ShowControl(s->scrollbar);
+    }
     mac_drawgrowicon(s);
 }
 
@@ -466,6 +460,7 @@ static void mac_adjusttermmenus(WindowPtr window)
     menu = GetMenuHandle(mFile);
     DisableItem(menu, iSave); /* XXX enable if modified */
     EnableItem(menu, iSaveAs);
+    EnableItem(menu, iChange);
     EnableItem(menu, iDuplicate);
     menu = GetMenuHandle(mEdit);
     EnableItem(menu, 0);
@@ -980,6 +975,8 @@ static void mac_growterm(WindowPtr window, EventRecord *event)
        newcols = (LoWord(grow_result) - 15) / s->font_width;
        mac_adjustsize(s, newrows, newcols);
        term_size(s->term, newrows, newcols, s->cfg.savelines);
+       s->cfg.height=s->term->rows;
+       s->cfg.width=s->term->cols;
     }
 }
 
@@ -1042,7 +1039,7 @@ static void mac_activateterm(WindowPtr window, EventRecord *event)
     s = mac_windowsession(window);
     term_set_focus(s->term, active);
     term_update(s->term);
-    if (active)
+    if (active && s->cfg.scrollbar)
        ShowControl(s->scrollbar);
     else {
        if (HAVE_COLOR_QD())
@@ -1136,8 +1133,8 @@ struct do_text_args {
  *
  * x and y are text row and column (zero-based)
  */
-void do_text(Context ctx, int x, int y, wchar_t *text, int len,
-            unsigned long attr, int lattr)
+static void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
+                     unsigned long attr, int lattr)
 {
     Session *s = ctx;
     int style;
@@ -1155,11 +1152,6 @@ void do_text(Context ctx, int x, int y, wchar_t *text, int len,
 
     assert(len <= 1024);
 
-    /* SGT, 2004-10-14: I don't know how to support combining characters
-     * on the Mac. Hopefully the first person to fail this assertion will
-     * know how to do it better than me... */
-    assert(!(attr & TATTR_COMBINING));
-
     SetPort((GrafPtr)GetWindowPort(s->window));
 
     fontwidth = s->font_width;
@@ -1264,6 +1256,24 @@ void do_text(Context ctx, int x, int y, wchar_t *text, int len,
 #endif
 }
 
+/*
+ * Wrapper that handles combining characters.
+ */
+void do_text(Context ctx, int x, int y, wchar_t *text, int len,
+            unsigned long attr, int lattr)
+{
+    if (attr & TATTR_COMBINING) {
+       unsigned long a = 0;
+       attr &= ~TATTR_COMBINING;
+       while (len--) {
+           do_text_internal(ctx, x, y, text, 1, attr | a, lattr);
+           text++;
+           a = TATTR_COMBINING;
+       }
+    } else
+       do_text_internal(ctx, x, y, text, len, attr, lattr);
+}
+
 static pascal void do_text_for_device(short depth, short devflags,
                                      GDHandle device, long cookie)
 {
@@ -1318,7 +1328,8 @@ static pascal void do_text_for_device(short depth, short devflags,
        }
     }
 
-    EraseRect(&a->textrect);
+    if (!(a->attr & TATTR_COMBINING))
+       EraseRect(&a->textrect);
     switch (a->lattr & LATTR_MODE) {
       case LATTR_NORM:
       case LATTR_WIDE:
@@ -1505,6 +1516,14 @@ void set_title(void *frontend, char *title)
 }
 
 /*
+ * Used by backend to indicate busy-ness
+ */
+void set_busy_status(void *frontend, int status)
+{
+    /* FIXME do something */
+}
+
+/*
  * set or clear the "raw mouse message" mode
  */
 void set_raw_mouse_mode(void *frontend, int activate)
@@ -1846,7 +1865,8 @@ void frontend_keypress(void *handle)
  * Ask whether to wipe a session log file before writing to it.
  * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
  */
-int askappend(void *frontend, Filename filename)
+int askappend(void *frontend, Filename filename,
+             void (*callback)(void *ctx, int result), void *ctx)
 {
 
     /* FIXME: not implemented yet. */