Change the term_mouse interface a little so that it gets passed
[u/mdw/putty] / mac / macterm.c
index 5379c20..61dc4b4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macterm.c,v 1.48 2003/01/14 18:44:34 ben Exp $ */
+/* $Id: macterm.c,v 1.54 2003/01/25 16:16:44 ben Exp $ */
 /*
  * Copyright (c) 1999 Simon Tatham
  * Copyright (c) 1999, 2002 Ben Harris
@@ -33,6 +33,7 @@
 #include <MacTypes.h>
 #include <Controls.h>
 #include <ControlDefinitions.h>
+#include <FixMath.h>
 #include <Fonts.h>
 #include <Gestalt.h>
 #include <LowMem.h>
@@ -46,9 +47,7 @@
 #include <Scrap.h>
 #include <Script.h>
 #include <Sound.h>
-#include <StandardFile.h>
 #include <TextCommon.h>
-#include <Threads.h>
 #include <ToolUtils.h>
 #include <UnicodeConverter.h>
 
@@ -62,7 +61,6 @@
 #include "putty.h"
 #include "charset.h"
 #include "mac.h"
-#include "storage.h"
 #include "terminal.h"
 
 #define NCOLOURS (lenof(((Config *)0)->colours))
@@ -109,23 +107,12 @@ static RoutineDescriptor do_text_for_device_upp =
 #define do_text_for_device_upp do_text_for_device
 #endif /* not TARGET_RT_MAC_CFM */
 
-void mac_opensession(void) {
-    Session *s;
-    StandardFileReply sfr;
-    static const OSType sftypes[] = { 'Sess', 0, 0, 0 };
-    void *sesshandle;
+void mac_startsession(Session *s)
+{
+    char *errmsg;
     int i;
 
-    s = smalloc(sizeof(*s));
-    memset(s, 0, sizeof(*s));
-
-    StandardGetFile(NULL, 1, sftypes, &sfr);
-    if (!sfr.sfGood) goto fail;
-
-    sesshandle = open_settings_r_fsp(&sfr.sfFile);
-    if (sesshandle == NULL) goto fail;
-    load_open_settings(sesshandle, TRUE, &s->cfg);
-    close_settings_r(sesshandle);
+    init_ucs(s);
 
     /*
      * Select protocol. This is farmed out into a table in a
@@ -137,20 +124,8 @@ void mac_opensession(void) {
            s->back = backends[i].backend;
            break;
        }
-    if (s->back == NULL) {
+    if (s->back == NULL)
        fatalbox("Unsupported protocol number found");
-    }
-    mac_startsession(s);
-    return;
-
-  fail:
-    sfree(s);
-    return;
-}
-
-void mac_startsession(Session *s)
-{
-    char *errmsg;
 
     /* XXX: Own storage management? */
     if (HAVE_COLOR_QD())
@@ -159,7 +134,7 @@ void mac_startsession(Session *s)
        s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
     SetWRefCon(s->window, (long)s);
     s->scrollbar = GetNewControl(cVScroll, s->window);
-    s->term = term_init(&s->cfg, s);
+    s->term = term_init(&s->cfg, &s->ucsdata, s);
 
     mac_initfont(s);
     mac_initpalette(s);
@@ -189,7 +164,7 @@ void mac_startsession(Session *s)
 
     ShowWindow(s->window);
     s->next = sesslist;
-    s->prev = s->next->prev;
+    s->prev = &sesslist;
     if (s->next != NULL)
        s->next->prev = &s->next;
     sesslist = s;
@@ -440,6 +415,10 @@ void mac_adjusttermmenus(WindowPtr window) {
     long offset;
 
     s = (Session *)GetWRefCon(window);
+    menu = GetMenuHandle(mFile);
+    DisableItem(menu, iSave); /* XXX enable if modified */
+    EnableItem(menu, iSaveAs);
+    EnableItem(menu, iDuplicate);
     menu = GetMenuHandle(mEdit);
     EnableItem(menu, 0);
     DisableItem(menu, iUndo);
@@ -523,8 +502,8 @@ static void text_click(Session *s, EventRecord *event) {
                   lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
     else
        lastact = MA_CLICK;
-    /* Fake right button with shift key */
-    term_mouse(s->term, event->modifiers & shiftKey ? MBT_RIGHT : MBT_LEFT,
+    term_mouse(s->term, MBT_LEFT,
+              event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
               lastact, col, row, event->modifiers & shiftKey,
               event->modifiers & controlKey, event->modifiers & optionKey);
     lastsess = s;
@@ -534,8 +513,8 @@ static void text_click(Session *s, EventRecord *event) {
        GetMouse(&localwhere);
        col = PTOCC(localwhere.h);
        row = PTOCR(localwhere.v);
-       term_mouse(s->term,
-                  event->modifiers & shiftKey ? MBT_RIGHT : MBT_LEFT,
+       term_mouse(s->term, MBT_LEFT, 
+                  event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
                   MA_DRAG, col, row, event->modifiers & shiftKey,
                   event->modifiers & controlKey,
                   event->modifiers & optionKey);
@@ -544,25 +523,13 @@ static void text_click(Session *s, EventRecord *event) {
        else if (row < 0)
            term_scroll(s->term, 0, row);
     }
-    term_mouse(s->term, event->modifiers & shiftKey ? MBT_RIGHT : MBT_LEFT,
+    term_mouse(s->term, MBT_LEFT,
+              event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
               MA_RELEASE, col, row, event->modifiers & shiftKey,
               event->modifiers & controlKey, event->modifiers & optionKey);
     lastwhen = TickCount();
 }
 
-Mouse_Button translate_button(void *frontend, Mouse_Button button)
-{
-
-    switch (button) {
-      case MBT_LEFT:
-       return MBT_SELECT;
-      case MBT_RIGHT:
-       return MBT_EXTEND;
-      default:
-       return 0;
-    }
-}
-
 void write_clip(void *cookie, wchar_t *data, int len, int must_deselect) {
     
     /*
@@ -916,6 +883,25 @@ static pascal void mac_growtermdraghook(void)
     SetPort(portsave);
 }
 
+void mac_closeterm(WindowPtr window)
+{
+    Session *s = (Session *)GetWRefCon(window);
+
+    /* XXX warn on close */
+    HideWindow(s->window);
+    *s->prev = s->next;
+    s->next->prev = s->prev;
+    ldisc_free(s->ldisc);
+    s->back->free(s->backhandle);
+    log_free(s->logctx);
+    if (s->uni_to_font != NULL)
+       DisposeUnicodeToTextInfo(&s->uni_to_font);
+    term_free(s->term);
+    DisposeWindow(s->window);
+    DisposePalette(s->palette);
+    sfree(s);
+}
+
 void mac_activateterm(WindowPtr window, Boolean active) {
     Session *s;