Namhyung Kim | 0985a94 | 2012-08-16 17:14:54 +0900 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | |
Namhyung Kim | 4bb1646 | 2012-08-16 17:14:52 +0900 | [diff] [blame] | 4 | #include "gtk.h" |
Namhyung Kim | 0985a94 | 2012-08-16 17:14:54 +0900 | [diff] [blame] | 5 | #include "../ui.h" |
Namhyung Kim | 4bb1646 | 2012-08-16 17:14:52 +0900 | [diff] [blame] | 6 | #include "../helpline.h" |
Namhyung Kim | 0985a94 | 2012-08-16 17:14:54 +0900 | [diff] [blame] | 7 | #include "../../util/debug.h" |
Namhyung Kim | 4bb1646 | 2012-08-16 17:14:52 +0900 | [diff] [blame] | 8 | |
| 9 | static void gtk_helpline_pop(void) |
| 10 | { |
| 11 | if (!perf_gtk__is_active_context(pgctx)) |
| 12 | return; |
| 13 | |
| 14 | gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar), |
| 15 | pgctx->statbar_ctx_id); |
| 16 | } |
| 17 | |
| 18 | static void gtk_helpline_push(const char *msg) |
| 19 | { |
| 20 | if (!perf_gtk__is_active_context(pgctx)) |
| 21 | return; |
| 22 | |
| 23 | gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar), |
| 24 | pgctx->statbar_ctx_id, msg); |
| 25 | } |
| 26 | |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 27 | static int gtk_helpline_show(const char *fmt, va_list ap) |
Namhyung Kim | 0985a94 | 2012-08-16 17:14:54 +0900 | [diff] [blame] | 28 | { |
| 29 | int ret; |
| 30 | char *ptr; |
| 31 | static int backlog; |
| 32 | |
| 33 | ret = vscnprintf(ui_helpline__current + backlog, |
| 34 | sizeof(ui_helpline__current) - backlog, fmt, ap); |
| 35 | backlog += ret; |
| 36 | |
| 37 | /* only first line can be displayed */ |
| 38 | ptr = strchr(ui_helpline__current, '\n'); |
| 39 | if (ptr && (ptr - ui_helpline__current) <= backlog) { |
| 40 | *ptr = '\0'; |
| 41 | ui_helpline__puts(ui_helpline__current); |
| 42 | backlog = 0; |
| 43 | } |
| 44 | |
| 45 | return ret; |
| 46 | } |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 47 | |
| 48 | static struct ui_helpline gtk_helpline_fns = { |
| 49 | .pop = gtk_helpline_pop, |
| 50 | .push = gtk_helpline_push, |
| 51 | .show = gtk_helpline_show, |
| 52 | }; |
| 53 | |
| 54 | void perf_gtk__init_helpline(void) |
| 55 | { |
| 56 | helpline_fns = >k_helpline_fns; |
| 57 | } |