+ extra_width = wr.right - wr.left - cr.right + cr.left;
+ extra_height = wr.bottom - wr.top - cr.bottom + cr.top;
+
+ if (cfg.resize_action != RESIZE_TERM) {
+ if ( font_width != win_width/term->cols ||
+ font_height != win_height/term->rows) {
+ deinit_fonts();
+ init_fonts(win_width/term->cols, win_height/term->rows);
+ offset_width = (win_width-font_width*term->cols)/2;
+ offset_height = (win_height-font_height*term->rows)/2;
+ InvalidateRect(hwnd, NULL, TRUE);
+#ifdef RDB_DEBUG_PATCH
+ debug((25, "reset_window() -> Z font resize to (%d, %d)",
+ font_width, font_height));
+#endif
+ }
+ } else {
+ if ( font_width != win_width/term->cols ||
+ font_height != win_height/term->rows) {
+ /* Our only choice at this point is to change the
+ * size of the terminal; Oh well.
+ */
+ term_size(term, win_height/font_height, win_width/font_width,
+ cfg.savelines);
+ offset_width = (win_width-font_width*term->cols)/2;
+ offset_height = (win_height-font_height*term->rows)/2;
+ InvalidateRect(hwnd, NULL, TRUE);
+#ifdef RDB_DEBUG_PATCH
+ debug((27, "reset_window() -> Zoomed term_size"));
+#endif
+ }
+ }
+ return;
+ }
+
+ /* Hmm, a force re-init means we should ignore the current window
+ * so we resize to the default font size.
+ */
+ if (reinit>0) {
+#ifdef RDB_DEBUG_PATCH
+ debug((27, "reset_window() -> Forced re-init"));
+#endif
+
+ offset_width = offset_height = cfg.window_border;
+ extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2;
+ extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2;
+
+ if (win_width != font_width*term->cols + offset_width*2 ||
+ win_height != font_height*term->rows + offset_height*2) {
+
+ /* If this is too large windows will resize it to the maximum
+ * allowed window size, we will then be back in here and resize
+ * the font or terminal to fit.
+ */
+ SetWindowPos(hwnd, NULL, 0, 0,
+ font_width*term->cols + extra_width,
+ font_height*term->rows + extra_height,
+ SWP_NOMOVE | SWP_NOZORDER);
+ }
+
+ InvalidateRect(hwnd, NULL, TRUE);
+ return;
+ }
+
+ /* Okay the user doesn't want us to change the font so we try the
+ * window. But that may be too big for the screen which forces us
+ * to change the terminal.
+ */
+ if ((cfg.resize_action == RESIZE_TERM && reinit<=0) ||
+ (cfg.resize_action == RESIZE_EITHER && reinit<0) ||
+ reinit>0) {
+ offset_width = offset_height = cfg.window_border;
+ extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2;
+ extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2;
+
+ if (win_width != font_width*term->cols + offset_width*2 ||
+ win_height != font_height*term->rows + offset_height*2) {
+
+ static RECT ss;
+ int width, height;
+
+ get_fullscreen_rect(&ss);
+
+ width = (ss.right - ss.left - extra_width) / font_width;
+ height = (ss.bottom - ss.top - extra_height) / font_height;
+
+ /* Grrr too big */
+ if ( term->rows > height || term->cols > width ) {
+ if (cfg.resize_action == RESIZE_EITHER) {
+ /* Make the font the biggest we can */
+ if (term->cols > width)
+ font_width = (ss.right - ss.left - extra_width)
+ / term->cols;
+ if (term->rows > height)
+ font_height = (ss.bottom - ss.top - extra_height)
+ / term->rows;
+
+ deinit_fonts();
+ init_fonts(font_width, font_height);
+
+ width = (ss.right - ss.left - extra_width) / font_width;
+ height = (ss.bottom - ss.top - extra_height) / font_height;
+ } else {
+ if ( height > term->rows ) height = term->rows;
+ if ( width > term->cols ) width = term->cols;
+ term_size(term, height, width, cfg.savelines);
+#ifdef RDB_DEBUG_PATCH
+ debug((27, "reset_window() -> term resize to (%d,%d)",
+ height, width));
+#endif
+ }
+ }
+
+ SetWindowPos(hwnd, NULL, 0, 0,
+ font_width*term->cols + extra_width,
+ font_height*term->rows + extra_height,
+ SWP_NOMOVE | SWP_NOZORDER);
+
+ InvalidateRect(hwnd, NULL, TRUE);
+#ifdef RDB_DEBUG_PATCH
+ debug((27, "reset_window() -> window resize to (%d,%d)",
+ font_width*term->cols + extra_width,
+ font_height*term->rows + extra_height));
+#endif
+ }
+ return;
+ }
+
+ /* We're allowed to or must change the font but do we want to ? */
+
+ if (font_width != (win_width-cfg.window_border*2)/term->cols ||
+ font_height != (win_height-cfg.window_border*2)/term->rows) {
+
+ deinit_fonts();
+ init_fonts((win_width-cfg.window_border*2)/term->cols,
+ (win_height-cfg.window_border*2)/term->rows);
+ offset_width = (win_width-font_width*term->cols)/2;
+ offset_height = (win_height-font_height*term->rows)/2;
+
+ extra_width = wr.right - wr.left - cr.right + cr.left +offset_width*2;
+ extra_height = wr.bottom - wr.top - cr.bottom + cr.top+offset_height*2;
+
+ InvalidateRect(hwnd, NULL, TRUE);
+#ifdef RDB_DEBUG_PATCH
+ debug((25, "reset_window() -> font resize to (%d,%d)",
+ font_width, font_height));
+#endif
+ }
+}
+
+static void set_input_locale(HKL kl)
+{
+ char lbuf[20];
+
+ GetLocaleInfo(LOWORD(kl), LOCALE_IDEFAULTANSICODEPAGE,
+ lbuf, sizeof(lbuf));
+
+ kbd_codepage = atoi(lbuf);
+}
+
+static void click(Mouse_Button b, int x, int y, int shift, int ctrl, int alt)
+{
+ int thistime = GetMessageTime();
+
+ if (send_raw_mouse && !(cfg.mouse_override && shift)) {
+ lastbtn = MBT_NOTHING;
+ term_mouse(term, b, translate_button(b), MA_CLICK,
+ x, y, shift, ctrl, alt);
+ return;
+ }
+
+ if (lastbtn == b && thistime - lasttime < dbltime) {
+ lastact = (lastact == MA_CLICK ? MA_2CLK :
+ lastact == MA_2CLK ? MA_3CLK :
+ lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
+ } else {
+ lastbtn = b;
+ lastact = MA_CLICK;
+ }
+ if (lastact != MA_NOTHING)
+ term_mouse(term, b, translate_button(b), lastact,
+ x, y, shift, ctrl, alt);
+ lasttime = thistime;
+}
+
+/*
+ * Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT)
+ * into a cooked one (SELECT, EXTEND, PASTE).
+ */
+static Mouse_Button translate_button(Mouse_Button button)
+{
+ if (button == MBT_LEFT)
+ return MBT_SELECT;
+ if (button == MBT_MIDDLE)
+ return cfg.mouse_is_xterm ? MBT_PASTE : MBT_EXTEND;
+ if (button == MBT_RIGHT)
+ return cfg.mouse_is_xterm ? MBT_EXTEND : MBT_PASTE;
+ return 0; /* shouldn't happen */
+}
+
+static void show_mouseptr(int show)
+{