| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:52 +09:00
										 |  |  | #include "gtk.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | #include "../ui.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:52 +09:00
										 |  |  | #include "../helpline.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | #include "../../util/debug.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:52 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void gtk_helpline_pop(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!perf_gtk__is_active_context(pgctx)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar), | 
					
						
							|  |  |  | 			  pgctx->statbar_ctx_id); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void gtk_helpline_push(const char *msg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!perf_gtk__is_active_context(pgctx)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar), | 
					
						
							|  |  |  | 			   pgctx->statbar_ctx_id, msg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 01:47:41 +09:00
										 |  |  | static int gtk_helpline_show(const char *fmt, va_list ap) | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 	char *ptr; | 
					
						
							|  |  |  | 	static int backlog; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = vscnprintf(ui_helpline__current + backlog, | 
					
						
							|  |  |  | 			 sizeof(ui_helpline__current) - backlog, fmt, ap); | 
					
						
							|  |  |  | 	backlog += ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* only first line can be displayed */ | 
					
						
							|  |  |  | 	ptr = strchr(ui_helpline__current, '\n'); | 
					
						
							|  |  |  | 	if (ptr && (ptr - ui_helpline__current) <= backlog) { | 
					
						
							|  |  |  | 		*ptr = '\0'; | 
					
						
							|  |  |  | 		ui_helpline__puts(ui_helpline__current); | 
					
						
							|  |  |  | 		backlog = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-15 01:47:41 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct ui_helpline gtk_helpline_fns = { | 
					
						
							|  |  |  | 	.pop	= gtk_helpline_pop, | 
					
						
							|  |  |  | 	.push	= gtk_helpline_push, | 
					
						
							|  |  |  | 	.show	= gtk_helpline_show, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void perf_gtk__init_helpline(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	helpline_fns = >k_helpline_fns; | 
					
						
							|  |  |  | } |