/* -*-C-*-
-$Id: os2pmcon.c,v 1.17 1995/11/03 01:29:57 cph Exp $
+$Id: os2pmcon.c,v 1.18 1995/11/04 00:10:51 cph Exp $
Copyright (c) 1994-95 Massachusetts Institute of Technology
static void initialize_marked_region (short, short);
static void update_marked_region (short, short);
static void unmark_marked_region (void);
+static int marked_region_nonempty_p (void);
+static char * extract_marked_region (int);
static void compute_marked_region
(short, short, short, short,
unsigned short *, unsigned short *, unsigned short *, unsigned short *);
(unsigned short, unsigned short, unsigned short, unsigned short, char);
static void paint_marked_region_segment
(unsigned short, unsigned short, unsigned short, unsigned short);
-static char * extract_marked_region (int);
+static void disable_marked_region (void);
+static void enable_menu_copy_items (int);
static void console_resize (unsigned short, unsigned short);
static void console_paint
(unsigned short, unsigned short, unsigned short, unsigned short);
static int console_tracking_mouse_p;
static HWND console_tracking_mouse_pointer;
static int console_marked_region_active_p;
+static HWND console_menu;
static short console_mark_x;
static short console_mark_y;
static short console_point_x;
console_tracking_mouse_p = 0;
console_tracking_mouse_pointer
= (WinQuerySysPointer (HWND_DESKTOP, SPTR_TEXT, FALSE));
- console_marked_region_active_p = 0;
readahead_repeat = 0;
readahead_insert = 0;
pending_events_head = 0;
if (width > max_width)
OS2_window_set_size (console_wid, max_width, height);
}
+ console_menu
+ = (OS2_window_handle_from_id (console_pm_qid,
+ (OS2_window_frame_handle (console_wid)),
+ FID_MENU));
+ disable_marked_region ();
}
wid_t
cell to its right, unless it falls on leftmost edge of cell. If
the argument is inclusive-lower, then the result is also;
likewise for exclusive-upper. */
- short cx = (x / CHAR_WIDTH);
- if (! (lowerp || ((x % CHAR_WIDTH) == 0)))
+ short cx = (x / ((short) CHAR_WIDTH));
+ if (! (lowerp || ((x % ((short) CHAR_WIDTH)) == 0)))
cx += 1;
return ((cx < 0) ? 0 : (cx > console_width) ? console_width : cx);
}
edge of cell, when result is cell below. If the argument is
inclusive-lower, then the result is exclusive-upper, and
vice-versa. */
- short cy = (((short) (console_height - 1)) - ((short) (y / CHAR_HEIGHT)));
- if (lowerp || ((y % CHAR_HEIGHT) == 0))
+ short cy = (((short) (console_height - 1)) - (y / ((short) CHAR_HEIGHT)));
+ if (lowerp || ((y % ((short) CHAR_HEIGHT)) == 0))
cy += 1;
return ((cy < 0) ? 0 : (cy > console_height) ? console_height : cy);
}
(SHORT2FROMMP (mp1)));
(void) OS2_window_set_capture (console_wid, 0);
OS2_window_mousetrack (console_wid, 0);
+ enable_menu_copy_items (marked_region_nonempty_p ());
console_tracking_mouse_p = 0;
release_console_lock ();
}
unsigned short i12;
unsigned short i22;
+ if (!console_marked_region_active_p)
+ return;
+
compute_marked_region (console_mark_x, console_mark_y,
console_point_x, console_point_y,
(&cx11), (&cy11), (&cx21), (&cy21));
console_point_x = x;
console_point_y = y;
- console_marked_region_active_p = 1;
}
static void
(&cx1), (&cy1), (&cx2), (&cy2));
highlight_marked_region (cx1, cy1, cx2, cy2, '\0');
paint_marked_region_segment (cx1, cy1, cx2, cy2);
- console_marked_region_active_p = 0;
+ disable_marked_region ();
+ }
+}
+
+static int
+marked_region_nonempty_p (void)
+{
+ if (console_marked_region_active_p)
+ {
+ unsigned short cx1;
+ unsigned short cy1;
+ unsigned short cx2;
+ unsigned short cy2;
+ unsigned short y;
+ compute_marked_region (console_mark_x, console_mark_y,
+ console_point_x, console_point_y,
+ (&cx1), (&cy1), (&cx2), (&cy2));
+ return
+ ((cy1 < cy2)
+ || ((cx1 < cx2) && (cx1 < (console_line_lengths[cy1]))));
}
+ else
+ return (0);
}
static char *
if (xl < lx)
length += (((xh < lx) ? xh : lx) - xl);
}
+ if (length == 1)
+ return (0);
result = (OS_malloc (length));
scan = result;
for (y = cy1; (y <= cy2); y += 1)
unsigned short cy1a = (y2cy (y1, 0));
unsigned short cx2a = (x2cx (x2, 1));
unsigned short cy2a = (y2cy (y2, 0));
- if (((cy1a * console_width) + cx1a) < ((cy2a * console_width) + cx2a))
+ if (((cy1a * console_width) + cx1a) > ((cy2a * console_width) + cx2a))
{
- (*cx1) = cx1a;
- (*cy1) = cy1a;
- (*cx2) = cx2a;
- (*cy2) = cy2a;
+ unsigned short cx = cx1a;
+ unsigned short cy = cy1a;
+ cx1a = cx2a;
+ cy1a = cy2a;
+ cx2a = cx;
+ cy2a = cy;
}
- else
+ if (cy1a >= console_height)
{
- (*cx1) = cx2a;
- (*cy1) = cy2a;
- (*cx2) = cx1a;
- (*cy2) = cy1a;
+ cx1a = (console_width - 1);
+ cy1a = (console_height - 1);
}
+ else if (cx1a >= console_width)
+ cx1a = (console_width - 1);
+ if (cy2a >= console_height)
+ {
+ cx2a = 0;
+ cy2a = console_height;
+ }
+ else if (cx2a > console_width)
+ cx2a = console_width;
+ (*cx1) = cx1a;
+ (*cy1) = cy1a;
+ (*cx2) = cx2a;
+ (*cy2) = cy2a;
}
static void
console_paint (0, x2, y2, (y2 + 1));
}
}
+
+static void
+disable_marked_region (void)
+{
+ console_marked_region_active_p = 0;
+ enable_menu_copy_items (0);
+}
+
+static void
+enable_menu_copy_items (int enablep)
+{
+ if (console_menu != NULLHANDLE)
+ {
+ USHORT value = (enablep ? 0 : MIA_DISABLED);
+#if 0
+ (void) OS2_menu_set_item_attributes
+ (console_pm_qid, console_menu, IDM_CUT, TRUE, MIA_DISABLED, value);
+#endif
+ (void) OS2_menu_set_item_attributes
+ (console_pm_qid, console_menu, IDM_COPY, TRUE, MIA_DISABLED, value);
+ }
+}
\f
static void
console_resize (unsigned short new_pel_width, unsigned short new_pel_height)