ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/menubar.C
(Generate patch)

Comparing rxvt-unicode/src/menubar.C (file contents):
Revision 1.8 by pcg, Fri Feb 13 12:16:21 2004 UTC vs.
Revision 1.9 by pcg, Tue Feb 24 00:02:44 2004 UTC

328 unsigned int len; 328 unsigned int len;
329 329
330 if (!parse[i].len) 330 if (!parse[i].len)
331 continue; 331 continue;
332 332
333 str = rxvt_malloc (parse[i].len + xtra_len + 1); 333 str = (unsigned char *) rxvt_malloc (parse[i].len + xtra_len + 1);
334 334
335 len = 0; 335 len = 0;
336 if (beg.len) 336 if (beg.len)
337 { 337 {
338 STRNCPY (str + len, beg.str, beg.len); 338 STRNCPY (str + len, beg.str, beg.len);
406 406
407 item->len2 = 0; 407 item->len2 = 0;
408 item->name2 = NULL; 408 item->name2 = NULL;
409 409
410 len = STRLEN (name); 410 len = STRLEN (name);
411 item->name = rxvt_malloc (len + 1); 411 item->name = (char *)rxvt_malloc (len + 1);
412 STRCPY (item->name, name); 412 STRCPY (item->name, name);
413 if (name[0] == '.' && name[1] != '.') 413 if (name[0] == '.' && name[1] != '.')
414 len = 0; /* hidden menu name */ 414 len = 0; /* hidden menu name */
415 item->len = len; 415 item->len = len;
416 416
434 len = STRLEN (name2); 434 len = STRLEN (name2);
435 if (len == 0) 435 if (len == 0)
436 item->name2 = NULL; 436 item->name2 = NULL;
437 else 437 else
438 { 438 {
439 item->name2 = rxvt_malloc (len + 1); 439 item->name2 = (char *)rxvt_malloc (len + 1);
440 STRCPY (item->name2, name2); 440 STRCPY (item->name2, name2);
441 } 441 }
442 item->len2 = len; 442 item->len2 = len;
443 } 443 }
444 item->entry.type = MenuLabel; 444 item->entry.type = MenuLabel;
449 action = item->name2; 449 action = item->name2;
450 len = item->len2; 450 len = item->len2;
451 } 451 }
452 if (len) 452 if (len)
453 { 453 {
454 unsigned char *str = rxvt_malloc (len + 1); 454 unsigned char *str = (unsigned char *)rxvt_malloc (len + 1);
455 455
456 STRCPY (str, action); 456 STRCPY (str, action);
457 457
458 if (rxvt_action_type (& (item->entry.action), str) < 0) 458 if (rxvt_action_type (& (item->entry.action), str) < 0)
459 free (str); 459 free (str);
673 menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); 673 menu = (menu_t *) rxvt_malloc (sizeof (menu_t));
674 674
675 menu->width = 0; 675 menu->width = 0;
676 menu->parent = parent; 676 menu->parent = parent;
677 menu->len = STRLEN (path); 677 menu->len = STRLEN (path);
678 menu->name = rxvt_malloc ((menu->len + 1)); 678 menu->name = (char *)rxvt_malloc ((menu->len + 1));
679 STRCPY (menu->name, path); 679 STRCPY (menu->name, path);
680 680
681 /* initialize head/tail */ 681 /* initialize head/tail */
682 menu->head = menu->tail = NULL; 682 menu->head = menu->tail = NULL;
683 menu->prev = menu->next = NULL; 683 menu->prev = menu->next = NULL;
1003 } 1003 }
1004 else if (item->name2 && !STRCMP (name, item->name2)) 1004 else if (item->name2 && !STRCMP (name, item->name2))
1005 name = NULL; 1005 name = NULL;
1006 1006
1007 if (len && name) 1007 if (len && name)
1008 {
1009#ifdef USE_XIM
1010 if (TermWin.fontset)
1011 XmbDrawString (display->display,
1012 ActiveMenu->win, TermWin.fontset,
1013 gc, xoff,
1014 2 * SHADOW + y + TermWin.font->ascent + 1,
1015 name, len);
1016 else
1017#endif
1018 XDrawString (display->display, ActiveMenu->win, gc, xoff, 1008 draw_string (display->display, ActiveMenu->win, gc, xoff,
1019 2 * SHADOW + y + TermWin.font->ascent + 1, 1009 2 * SHADOW + y + TermWin.font->ascent + 1,
1020 name, len); 1010 name, len);
1021 }
1022 1011
1023 len = item->len2; 1012 len = item->len2;
1024 name = item->name2; 1013 name = item->name2;
1014
1025 if (len && name) 1015 if (len && name)
1026 {
1027#ifdef USE_XIM
1028 if (TermWin.fontset)
1029 XmbDrawString (display->display,
1030 ActiveMenu->win, TermWin.fontset,
1031 gc,
1032 ActiveMenu->w - (xoff + Width2Pixel (xright)),
1033 2 * SHADOW + y + TermWin.font->ascent + 1,
1034 name, len);
1035 else
1036#endif
1037 XDrawString (display->display, ActiveMenu->win, gc, 1016 draw_string (display->display, ActiveMenu->win, gc,
1038 ActiveMenu->w - (xoff + Width2Pixel (xright)), 1017 ActiveMenu->w - (xoff + Width2Pixel (xright)),
1039 2 * SHADOW + y + TermWin.font->ascent + 1, 1018 2 * SHADOW + y + TermWin.font->ascent + 1,
1040 name, len); 1019 name, len);
1041 } 1020
1042 h = HEIGHT_TEXT + 2 * SHADOW; 1021 h = HEIGHT_TEXT + 2 * SHADOW;
1043 } 1022 }
1044 y += h; 1023 y += h;
1045 } 1024 }
1046} 1025}
1047 1026
1048void 1027void
1049rxvt_term::menu_display (void (*update) (rxvt_t *)) 1028rxvt_term::menu_display (void (rxvt_term::*update) ())
1050{ 1029{
1051 menu_t *ActiveMenu = ActiveMenu; 1030 menu_t *ActiveMenu = ActiveMenu;
1052 1031
1053 if (ActiveMenu == NULL) 1032 if (ActiveMenu == NULL)
1054 return; 1033 return;
1058 ActiveMenu->item = NULL; 1037 ActiveMenu->item = NULL;
1059 1038
1060 if (ActiveMenu->parent == NULL) 1039 if (ActiveMenu->parent == NULL)
1061 drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); 1040 drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1);
1062 ActiveMenu = ActiveMenu->parent; 1041 ActiveMenu = ActiveMenu->parent;
1063 update (r); 1042 (this->*update) ();
1064} 1043}
1065 1044
1066void 1045void
1067rxvt_term::menu_hide_all () 1046rxvt_term::menu_hide_all ()
1068{ 1047{
1069 menu_display (rxvt_menu_hide_all); 1048 menu_display (&rxvt_term::menu_hide_all);
1070} 1049}
1071 1050
1072void 1051void
1073rxvt_term::menu_hide () 1052rxvt_term::menu_hide ()
1074{ 1053{
1075 menu_display (rxvt_menu_show); 1054 menu_display (&rxvt_term::menu_show);
1076} 1055}
1077 1056
1078void 1057void
1079rxvt_term::menu_clear (menu_t *menu) 1058rxvt_term::menu_clear (menu_t *menu)
1080{ 1059{
1576rxvt_term::menubar_dispatch (char *str) 1555rxvt_term::menubar_dispatch (char *str)
1577{ 1556{
1578 int n, cmd; 1557 int n, cmd;
1579 char *path, *name, *name2; 1558 char *path, *name, *name2;
1580 1559
1581 if (menubar_visible (r) && ActiveMenu != NULL) 1560 if (menubar_visible () && ActiveMenu != NULL)
1582 menubar_expose (); 1561 menubar_expose ();
1583 else 1562 else
1584 ActiveMenu = NULL; 1563 ActiveMenu = NULL;
1585 1564
1586 cmd = *str; 1565 cmd = *str;
1674 str += n; 1653 str += n;
1675 if (CurrentBar != NULL && !menu_readonly) 1654 if (CurrentBar != NULL && !menu_readonly)
1676 { 1655 {
1677 if (*str) 1656 if (*str)
1678 { 1657 {
1679 name = rxvt_realloc (CurrentBar->title, 1658 name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1);
1680 STRLEN (str) + 1);
1681 if (name != NULL) 1659 if (name != NULL)
1682 { 1660 {
1683 STRCPY (name, str); 1661 STRCPY (name, str);
1684 CurrentBar->title = name; 1662 CurrentBar->title = name;
1685 } 1663 }
2013rxvt_term::menubar_expose () 1991rxvt_term::menubar_expose ()
2014{ 1992{
2015 menu_t *menu; 1993 menu_t *menu;
2016 int x; 1994 int x;
2017 1995
2018 if (!menubar_visible (r) || menuBar.win == 0) 1996 if (!menubar_visible () || menuBar.win == 0)
2019 return; 1997 return;
2020 1998
2021 if (menubarGC == None) 1999 if (menubarGC == None)
2022 { 2000 {
2023 /* Create the graphics context */ 2001 /* Create the graphics context */
2053 2031
2054 if (x >= TermWin.ncol) 2032 if (x >= TermWin.ncol)
2055 len = (TermWin.ncol - (menu->x + HSPACE)); 2033 len = (TermWin.ncol - (menu->x + HSPACE));
2056 2034
2057 drawbox_menubar (menu->x, len, +1); 2035 drawbox_menubar (menu->x, len, +1);
2058#ifdef USE_XIM
2059 if (TermWin.fontset)
2060 XmbDrawString (display->display,
2061 menuBar.win, TermWin.fontset,
2062 menubarGC,
2063 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2064 menuBar_height () - SHADOW, menu->name, len);
2065 else
2066#endif
2067 XDrawString (display->display, menuBar.win, menubarGC, 2036 draw_string (display->display, menuBar.win, menubarGC,
2068 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2037 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2069 menuBar_height () - SHADOW, menu->name, len); 2038 menuBar_height () - SHADOW, menu->name, len);
2070 2039
2071 if (x >= TermWin.ncol) 2040 if (x >= TermWin.ncol)
2072 break; 2041 break;
2073 } 2042 }
2074 } 2043 }
2125 } 2094 }
2126 title[len] = '\0'; 2095 title[len] = '\0';
2127 2096
2128 ncol -= (x + len + HSPACE); 2097 ncol -= (x + len + HSPACE);
2129 if (len > 0 && ncol >= 0) 2098 if (len > 0 && ncol >= 0)
2130 {
2131#ifdef USE_XIM
2132 if (TermWin.fontset)
2133 XmbDrawString (display->display,
2134 menuBar.win, TermWin.fontset,
2135 menubarGC,
2136 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2137 menuBar_height () - SHADOW, title, len);
2138 else
2139#endif
2140 XDrawString (display->display, menuBar.win, menubarGC, 2099 draw_string (display->display, menuBar.win, menubarGC,
2141 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2100 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2142 menuBar_height () - SHADOW, title, len); 2101 menuBar_height () - SHADOW, title, len);
2143 }
2144 } 2102 }
2145} 2103}
2146 2104
2147int 2105int
2148rxvt_term::menubar_mapping (int map) 2106rxvt_term::menubar_mapping (int map)
2149{ 2107{
2150 int change = 0; 2108 int change = 0;
2151 2109
2152 if (map && !menubar_visible (r)) 2110 if (map && !menubar_visible ())
2153 { 2111 {
2154 menuBar.state = 1; 2112 menuBar.state = 1;
2155 if (menuBar.win == 0) 2113 if (menuBar.win == 0)
2156 return 0; 2114 return 0;
2157 XMapWindow (display->display, menuBar.win); 2115 XMapWindow (display->display, menuBar.win);
2158 change = 1; 2116 change = 1;
2159 } 2117 }
2160 else if (!map && menubar_visible (r)) 2118 else if (!map && menubar_visible ())
2161 { 2119 {
2162 menubar_expose (); 2120 menubar_expose ();
2163 menuBar.state = 0; 2121 menuBar.state = 0;
2164 XUnmapWindow (display->display, menuBar.win); 2122 XUnmapWindow (display->display, menuBar.win);
2165 change = 1; 2123 change = 1;
2169 2127
2170 return change; 2128 return change;
2171} 2129}
2172 2130
2173int 2131int
2174rxvt_term::menu_select (XButtonEvent *ev) 2132rxvt_term::menu_select (XButtonEvent &ev)
2175{ 2133{
2176 menuitem_t *thisitem, *item = NULL; 2134 menuitem_t *thisitem, *item = NULL;
2177 int this_y, y; 2135 int this_y, y;
2178 menu_t *ActiveMenu = ActiveMenu; 2136 menu_t *ActiveMenu = ActiveMenu;
2179 2137
2185 return 0; 2143 return 0;
2186 2144
2187 XQueryPointer (display->display, ActiveMenu->win, 2145 XQueryPointer (display->display, ActiveMenu->win,
2188 &unused_root, &unused_child, 2146 &unused_root, &unused_child,
2189 &unused_root_x, &unused_root_y, 2147 &unused_root_x, &unused_root_y,
2190 & (ev->x), & (ev->y), &unused_mask); 2148 &ev.x, &ev.y, &unused_mask);
2191 2149
2192 if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) 2150 if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0))
2193 { 2151 {
2194 menu_hide (); 2152 menu_hide ();
2195 return 1; 2153 return 1;
2196 } 2154 }
2197 /* determine the menu item corresponding to the Y index */ 2155 /* determine the menu item corresponding to the Y index */
2198 y = SHADOW; 2156 y = SHADOW;
2199 if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) 2157 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW))
2200 { 2158 {
2201 for (item = ActiveMenu->head; item != NULL; item = item->next) 2159 for (item = ActiveMenu->head; item != NULL; item = item->next)
2202 { 2160 {
2203 int h = HEIGHT_TEXT + 2 * SHADOW; 2161 int h = HEIGHT_TEXT + 2 * SHADOW;
2204 2162
2205 if (isSeparator (item->name)) 2163 if (isSeparator (item->name))
2206 h = HEIGHT_SEPARATOR; 2164 h = HEIGHT_SEPARATOR;
2207 else if (ev->y >= y && ev->y < (y + h)) 2165 else if (ev.y >= y && ev.y < (y + h))
2208 break; 2166 break;
2209 y += h; 2167 y += h;
2210 } 2168 }
2211 } 2169 }
2212 if (item == NULL && ev->type == ButtonRelease) 2170 if (item == NULL && ev.type == ButtonRelease)
2213 { 2171 {
2214 menu_hide_all (); 2172 menu_hide_all ();
2215 return 0; 2173 return 0;
2216 } 2174 }
2217 thisitem = item; 2175 thisitem = item;
2242 y += h; 2200 y += h;
2243 } 2201 }
2244 } 2202 }
2245 else 2203 else
2246 { 2204 {
2247 switch (ev->type) 2205 switch (ev.type)
2248 { 2206 {
2249 case ButtonRelease: 2207 case ButtonRelease:
2250 switch (item->entry.type) 2208 switch (item->entry.type)
2251 { 2209 {
2252 case MenuLabel: 2210 case MenuLabel:
2254 menu_hide_all (); 2212 menu_hide_all ();
2255 break; 2213 break;
2256 2214
2257 case MenuAction: 2215 case MenuAction:
2258 case MenuTerminalAction: 2216 case MenuTerminalAction:
2259 drawbox_menuitem (_y, -1); 2217 drawbox_menuitem (this_y, -1);
2260 { 2218 {
2261#ifdef HAVE_NANOSLEEP 2219#ifdef HAVE_NANOSLEEP
2262 struct timespec rqt; 2220 struct timespec rqt;
2263 2221
2264 rqt.tv_sec = 0; 2222 rqt.tv_sec = 0;
2306 { 2264 {
2307 int x; 2265 int x;
2308 2266
2309 drawtriangle (ActiveMenu->w, y, -1); 2267 drawtriangle (ActiveMenu->w, y, -1);
2310 2268
2311 x = ev->x + (ActiveMenu->parent 2269 x = ev.x + (ActiveMenu->parent
2312 ? ActiveMenu->x 2270 ? ActiveMenu->x
2313 : Width2Pixel (ActiveMenu->x)); 2271 : Width2Pixel (ActiveMenu->x));
2314 2272
2315 if (x >= item->entry.submenu.menu->x) 2273 if (x >= item->entry.submenu.menu->x)
2316 { 2274 {
2322 } 2280 }
2323 return 0; 2281 return 0;
2324} 2282}
2325 2283
2326void 2284void
2327rxvt_term::menubar_select (XButtonEvent *ev) 2285rxvt_term::menubar_select (XButtonEvent &ev)
2328{ 2286{
2329 menu_t *menu = NULL; 2287 menu_t *menu = NULL;
2330 2288
2331 /* determine the pulldown menu corresponding to the X index */ 2289 /* determine the pulldown menu corresponding to the X index */
2332 if (ev->y >= 0 && ev->y <= menuBar_height () && CurrentBar != NULL) 2290 if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL)
2333 { 2291 {
2334 for (menu = CurrentBar->head; menu != NULL; menu = menu->next) 2292 for (menu = CurrentBar->head; menu != NULL; menu = menu->next)
2335 { 2293 {
2336 int x = Width2Pixel (menu->x); 2294 int x = Width2Pixel (menu->x);
2337 int w = Width2Pixel (menu->len + HSPACE); 2295 int w = Width2Pixel (menu->len + HSPACE);
2338 2296
2339 if ((ev->x >= x && ev->x < x + w)) 2297 if ((ev.x >= x && ev.x < x + w))
2340 break; 2298 break;
2341 } 2299 }
2342 } 2300 }
2343 switch (ev->type) 2301 switch (ev.type)
2344 { 2302 {
2345 case ButtonRelease: 2303 case ButtonRelease:
2346 menu_hide_all (); 2304 menu_hide_all ();
2347 break; 2305 break;
2348 2306
2349 case ButtonPress: 2307 case ButtonPress:
2350 if (menu == NULL && Arrows_x && ev->x >= Arrows_x) 2308 if (menu == NULL && Arrows_x && ev.x >= Arrows_x)
2351 { 2309 {
2352 int i; 2310 int i;
2353 2311
2354 for (i = 0; i < NARROWS; i++) 2312 for (i = 0; i < NARROWS; i++)
2355 { 2313 {
2356 if (ev->x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) 2314 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4)
2357 && ev->x < (Arrows_x 2315 && ev.x < (Arrows_x
2358 + (Width2Pixel (4 * i + i + 4)) / 4)) 2316 + (Width2Pixel (4 * i + i + 4)) / 4))
2359 { 2317 {
2360 draw_Arrows (Arrows[i].name, -1); 2318 draw_Arrows (Arrows[i].name, -1);
2361 { 2319 {
2362#ifdef HAVE_NANOSLEEP 2320#ifdef HAVE_NANOSLEEP
2392 { 2350 {
2393 fprintf (stderr, "%s\n", 2351 fprintf (stderr, "%s\n",
2394 CurrentBar->arrows[i].str); 2352 CurrentBar->arrows[i].str);
2395 } 2353 }
2396#else /* DEBUG_MENUARROWS */ 2354#else /* DEBUG_MENUARROWS */
2397 if (CurrentBar == NULL 2355 if (CurrentBar == NULL || action_dispatch (&CurrentBar->arrows[i]))
2398 || rxvt_action_dispatch (r,
2399 & (CurrentBar->arrows[i]))
2400 )
2401 { 2356 {
2402 if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) 2357 if (Arrows[i].str != NULL && Arrows[i].str[0] != 0)
2403 tt_write ((Arrows[i].str + 1), 2358 tt_write ((Arrows[i].str + 1),
2404 Arrows[i].str[0]); 2359 Arrows[i].str[0]);
2405 } 2360 }
2427/* 2382/*
2428 * general dispatch routine, 2383 * general dispatch routine,
2429 * it would be nice to have `sticky' menus 2384 * it would be nice to have `sticky' menus
2430 */ 2385 */
2431void 2386void
2432rxvt_term::menubar_control (XButtonEvent *ev) 2387rxvt_term::menubar_control (XButtonEvent &ev)
2433{ 2388{
2434 switch (ev->type) 2389 switch (ev.type)
2435 { 2390 {
2436 case ButtonPress: 2391 case ButtonPress:
2437 if (ev->button == Button1) 2392 if (ev.button == Button1)
2438 menubar_select (ev); 2393 menubar_select (ev);
2439 break; 2394 break;
2440 2395
2441 case ButtonRelease: 2396 case ButtonRelease:
2442 if (ev->button == Button1) 2397 if (ev.button == Button1)
2443 menu_select (ev); 2398 menu_select (ev);
2444 break; 2399 break;
2445 2400
2446 case MotionNotify: 2401 case MotionNotify:
2447 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], 2402 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0],
2448 MotionNotify, (XEvent *) ev)) ; 2403 MotionNotify, (XEvent *)&ev)) ;
2449 2404
2450 if (ActiveMenu) 2405 if (ActiveMenu)
2451 while (menu_select (ev)) ; 2406 while (menu_select (ev)) ;
2452 else 2407 else
2453 ev->y = -1; 2408 ev.y = -1;
2454 if (ev->y < 0) 2409 if (ev.y < 0)
2455 { 2410 {
2456 Window unused_root, unused_child; 2411 Window unused_root, unused_child;
2457 int unused_root_x, unused_root_y; 2412 int unused_root_x, unused_root_y;
2458 unsigned int unused_mask; 2413 unsigned int unused_mask;
2459 2414
2460 XQueryPointer (display->display, menuBar.win, 2415 XQueryPointer (display->display, menuBar.win,
2461 &unused_root, &unused_child, 2416 &unused_root, &unused_child,
2462 &unused_root_x, &unused_root_y, 2417 &unused_root_x, &unused_root_y,
2463 & (ev->x), & (ev->y), &unused_mask); 2418 &ev.x, &ev.y, &unused_mask);
2464 menubar_select (ev); 2419 menubar_select (ev);
2465 } 2420 }
2466 break; 2421 break;
2467 } 2422 }
2468} 2423}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines