Esempio n. 1
0
//
// Constructor
//
CPreview::CPreview():m_Path(NULL), m_Data(NULL), m_FileType(TYPE_UNKNOWN), 
	m_MinX(0.0), m_MaxX(0.0), m_EpsX(0.0), m_MinY(0.0), m_MaxY(0.0), m_EpsY(0.0),
	m_ReverseY(FALSE)
{
	GtkWidget *vbox;

	m_Buffer = gtk_text_buffer_new(NULL);

	// Frame
	m_Widget = gtk_frame_new(NULL);
	vbox = gtk_vbox_new(FALSE, 4);
	gtk_container_add(GTK_CONTAINER(m_Widget), vbox);
	gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);

	// Image area
	m_Preview = cmpack_preview_new();
	gtk_widget_set_size_request(m_Preview, 160, 160);
	gtk_box_pack_start(GTK_BOX(vbox), m_Preview, FALSE, TRUE, 0);
	gtk_widget_set_events(m_Preview, GDK_BUTTON_PRESS_MASK);
	gtk_widget_set_tooltip_text(m_Preview, "Double click to enlarge the preview");
	g_signal_connect(G_OBJECT(m_Preview), "button_press_event", G_CALLBACK(button_press_event), this);

	// Text area
	m_View = gtk_text_view_new_with_buffer(m_Buffer);
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(m_View), GTK_WRAP_WORD_CHAR);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(m_View), false);
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(m_View), false);
	gtk_text_view_set_justification(GTK_TEXT_VIEW(m_View), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start(GTK_BOX(vbox), m_View, TRUE, TRUE, 0);

	gtk_widget_show_all(m_Widget);
}
Esempio n. 2
0
/*
 * Set the default style
 */
static void
set_default_tag (GtkTextBuffer *buffer, GtkTextTag *tag)
{
  PangoFontDescription *font_desc;
  GdkColor *color = (GdkColor *)g_malloc(sizeof(GdkColor));
  PangoUnderline *underline;
  int val;
  GtkJustification justification;

  if(!tag)
    return;

  g_object_get (G_OBJECT (tag), "foreground-gdk", &color, NULL);
  g_object_get (G_OBJECT (tag), "underline", &underline, NULL);
  g_object_get (G_OBJECT (tag), "font-desc", &font_desc, NULL);

  gtk_widget_modify_font (view, font_desc);
  gtk_widget_modify_text (view, GTK_STATE_NORMAL, color);

  g_object_get (G_OBJECT (tag), "left-margin", &val, NULL);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), val);

  g_object_get (G_OBJECT (tag), "justification", &justification, NULL);
  gtk_text_view_set_justification(GTK_TEXT_VIEW (view), justification);

  g_object_get (G_OBJECT (tag), "pixels-below-lines", &val, NULL);
  gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW (view), val);

  g_object_get (G_OBJECT (tag), "pixels-above-lines", &val, NULL);
  gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW (view), val);
}
/////**********************************************************************
/////	函数名称	:	GtkWidget *build_scrolled_win()
/////	
/////	函数功能	:	创  建  scrolled滚动窗口及文本框    
/////									
/////   返 回 值	:	Send_scrolled_win
/////**********************************************************************
GtkWidget *build_scrolled_win()
{
	//GtkWidget *text;
	GtkWidget *scrolled;

	Send_scrolled_win = gtk_scrolled_window_new(NULL,NULL);
	Send_textview = gtk_text_view_new();                                          
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(Send_textview),GTK_WRAP_WORD);	  
	gtk_text_view_set_justification(GTK_TEXT_VIEW(Send_textview),GTK_JUSTIFY_LEFT);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(Send_textview),TRUE);					
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(Send_textview),TRUE);			
	gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(Send_textview),5);			
	gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(Send_textview),5);			
	gtk_text_view_set_pixels_inside_wrap(GTK_TEXT_VIEW(Send_textview),5);			
	gtk_text_view_set_left_margin(GTK_TEXT_VIEW(Send_textview),10);					
	gtk_text_view_set_right_margin(GTK_TEXT_VIEW(Send_textview),10);				
	Send_buffer =  gtk_text_view_get_buffer(GTK_TEXT_VIEW(Send_textview));	

	//////////**********************************************************************************************字体、颜色 的消息循环
	g_signal_connect(G_OBJECT(font), "clicked", G_CALLBACK(select_font),(gpointer)Send_textview);
	g_signal_connect(G_OBJECT(font_color), "clicked", G_CALLBACK(select_color),(gpointer)Send_textview);//将color对象与clicked相关联,回调函数为select_font
	gtk_container_add(GTK_CONTAINER(Send_scrolled_win),Send_textview);

	return Send_scrolled_win;
}
Esempio n. 4
0
/*
 Main sidegadget's function
*/
GtkWidget*
sidegadget_new (void)
{
	block_notes = g_new0 (block_notes_s, 1);
	block_notes->work_dir = g_strdup_printf ("sidegadget/block-notes/%s", BLOCK_NOTES_DATA_FILE);

	/* Get initial text */
	block_notes_conf_get_initial_text (block_notes, block_notes->work_dir);
	
	block_notes->view = gtk_text_view_new ();
	
	gtk_widget_set_size_request (block_notes->view, -1, 200 - 25);

	/* Set textview's color*/
//	gtk_widget_modify_base (block_notes->view, GTK_STATE_NORMAL, &sidegadget->color_gadget);
	gtk_widget_grab_focus (block_notes->view);

	gtk_text_view_set_editable (GTK_TEXT_VIEW (block_notes->view), TRUE);
	gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (block_notes->view), TRUE);

	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (block_notes->view), GTK_WRAP_WORD_CHAR);
	gtk_text_view_set_justification (GTK_TEXT_VIEW (block_notes->view), GTK_JUSTIFY_LEFT);

	/* Set space between two rows */
	gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (block_notes->view), 1);
	gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (block_notes->view), 1);

	/* Set borders */
	gtk_text_view_set_left_margin (GTK_TEXT_VIEW (block_notes->view), 2);
	gtk_text_view_set_right_margin (GTK_TEXT_VIEW (block_notes->view), 2);

	/* Set font color */
	gtk_widget_modify_text (block_notes->view, GTK_STATE_NORMAL, &block_notes->color_text);
	
	/* Set font */
	gtk_widget_modify_font (block_notes->view, block_notes->font_pango);

	gtk_widget_show (block_notes->view);

	/* Create a buffer*/
	block_notes->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(block_notes->view));

	/* Insert init_text in the buffer */
	gtk_text_buffer_set_text (block_notes->buffer, block_notes->string_init, -1);

	/* Create scrolled window */
	block_notes->scrolled_win = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (block_notes->scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	/* Insert the textview in the scrolled win */
	gtk_container_add (GTK_CONTAINER(block_notes->scrolled_win), block_notes->view);

	g_signal_connect (G_OBJECT (block_notes->buffer), "changed", G_CALLBACK (block_notes_save_text), block_notes);
	
	return block_notes->scrolled_win;
}
Esempio n. 5
0
void gTextArea::setAlignment(int vl)
{
	GtkJustification align;
	
	_align_normal = false;
	
	switch(vl & 0xF)
	{
		case ALIGN_LEFT: align = GTK_JUSTIFY_LEFT; break;
		case ALIGN_RIGHT: align = GTK_JUSTIFY_RIGHT; break;
		case ALIGN_CENTER: align = GTK_JUSTIFY_CENTER; break;
		case ALIGN_NORMAL: default: align = gDesktop::rightToLeft() ? GTK_JUSTIFY_RIGHT: GTK_JUSTIFY_LEFT; _align_normal = true; break;
	}

	gtk_text_view_set_justification(GTK_TEXT_VIEW(textview), align);
}
Esempio n. 6
0
/*
  Create main textview
*/
void
arduino_csr_create_textview_buffer (arduino_csr_dialog_core_s *dialog)
{
    GtkWidget *v_box;
    v_box = gtk_vbox_new (FALSE, 0);

    dialog->view = gtk_text_view_new ();

//  gtk_widget_modify_font (dialog->view, font_pango);

    gtk_widget_grab_focus (dialog->view);

    gtk_text_view_set_editable (GTK_TEXT_VIEW (dialog->view), FALSE);
    gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (dialog->view), TRUE);

    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (dialog->view), GTK_WRAP_WORD_CHAR);
    gtk_text_view_set_justification (GTK_TEXT_VIEW (dialog->view), GTK_JUSTIFY_LEFT);

    /* Set space between two rows */
    gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (dialog->view), 1);
    gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (dialog->view), 1);

    /* Set borders */
    gtk_text_view_set_left_margin (GTK_TEXT_VIEW (dialog->view), 2);
    gtk_text_view_set_right_margin (GTK_TEXT_VIEW (dialog->view), 2);

    gtk_widget_set_can_focus (dialog->view, TRUE);
    gtk_widget_grab_focus (dialog->view);

    dialog->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(dialog->view));

    dialog->scrolled_win = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (dialog->scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    gtk_container_add (GTK_CONTAINER(dialog->scrolled_win), dialog->view);
    gtk_widget_show (dialog->view);

    gtk_widget_set_can_focus (dialog->scrolled_win, TRUE);
    gtk_widget_grab_focus (dialog->scrolled_win);

    gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog->window)->vbox), dialog->scrolled_win, TRUE, TRUE, 1);
    gtk_widget_show (dialog->scrolled_win);
}
Esempio n. 7
0
static void
create_gui(MathDisplay *display)
{
    GtkWidget *info_view, *info_box, *main_box;
    PangoFontDescription *font_desc;
    int i;
    GtkStyle *style;

    main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_container_add(GTK_CONTAINER(display), main_box);

    g_signal_connect(display, "key-press-event", G_CALLBACK(key_press_cb), display);

    display->priv->text_view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(display->priv->equation));
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(display->priv->text_view), GTK_WRAP_WORD);
    gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(display->priv->text_view), FALSE);
    gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(display->priv->text_view), 8);
    gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(display->priv->text_view), 2);
    /* TEMP: Disabled for now as GTK+ doesn't properly render a right aligned right margin, see bug #482688 */
    /*gtk_text_view_set_right_margin(GTK_TEXT_VIEW(display->priv->text_view), 6);*/
    gtk_text_view_set_justification(GTK_TEXT_VIEW(display->priv->text_view), GTK_JUSTIFY_RIGHT);
    gtk_widget_ensure_style(display->priv->text_view);
    font_desc = pango_font_description_copy(gtk_widget_get_style(display->priv->text_view)->font_desc);
    pango_font_description_set_size(font_desc, 16 * PANGO_SCALE);
    gtk_widget_modify_font(display->priv->text_view, font_desc);
    pango_font_description_free(font_desc);
    gtk_widget_set_name(display->priv->text_view, "displayitem");
    atk_object_set_role(gtk_widget_get_accessible(display->priv->text_view), ATK_ROLE_EDITBAR);
  //FIXME:<property name="AtkObject::accessible-description" translatable="yes" comments="Accessible description for the area in which results are displayed">Result Region</property>
    g_signal_connect(display->priv->text_view, "key-press-event", G_CALLBACK(display_key_press_cb), display);
    gtk_box_pack_start(GTK_BOX(main_box), display->priv->text_view, TRUE, TRUE, 0);

    info_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
    gtk_box_pack_start(GTK_BOX(main_box), info_box, FALSE, TRUE, 0);

    info_view = gtk_text_view_new();
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(info_view), GTK_WRAP_WORD);
    gtk_widget_set_can_focus(info_view, TRUE); // FIXME: This should be FALSE but it locks the cursor inside the main view for some reason
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(info_view), FALSE); // FIXME: Just here so when incorrectly gets focus doesn't look editable
    gtk_text_view_set_editable(GTK_TEXT_VIEW(info_view), FALSE);
    gtk_text_view_set_justification(GTK_TEXT_VIEW(info_view), GTK_JUSTIFY_RIGHT);
    /* TEMP: Disabled for now as GTK+ doesn't properly render a right aligned right margin, see bug #482688 */
    /*gtk_text_view_set_right_margin(GTK_TEXT_VIEW(info_view), 6);*/
    gtk_box_pack_start(GTK_BOX(info_box), info_view, TRUE, TRUE, 0);
    display->priv->info_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(info_view));

    display->priv->spinner = gtk_spinner_new();
    gtk_box_pack_end(GTK_BOX(info_box), display->priv->spinner, FALSE, FALSE, 0);
    style = gtk_widget_get_style(info_view);
    for (i = 0; i < 5; i++) {
        gtk_widget_modify_bg(GTK_WIDGET(display), i, &style->base[i]);
    }

    gtk_widget_show(info_box);
    gtk_widget_show(info_view);
    gtk_widget_show(display->priv->text_view);
    gtk_widget_show(main_box);

    g_signal_connect(display->priv->equation, "notify::status", G_CALLBACK(status_changed_cb), display);
    status_changed_cb(display->priv->equation, NULL, display);
}
Esempio n. 8
0
gint chat(void)
{
GtkWidget *window_chat;
GtkWidget *vpaned;
GtkWidget *Send_scrolled_win, *Rcv_scrolled_win;
GtkWidget *sendbutton, *closebutton, *recordsbutton, *docbutton;
GtkWidget *table_chat;


//Send=(struct chat *)malloc(sizeof (struct chat));
//Recv=(struct chat *)malloc(sizeof (struct chat));

Send->choose = 'e';
Recv->choose = 'e';
records->choose = 'i';                                                                  //gaibian
//char* ip ="10.3.2.133";
//strcpy(Send->ip, ip);
Send->send_id = myid;
//Send->target_id = 5;

strcpy(Send->nickname, mynickname);
printf("%s\n",Send->nickname);
//printf("%s\n",Send->ip);


window_chat = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window_chat), "Paned Windows");
g_signal_connect (G_OBJECT (window_chat), "destroy",
G_CALLBACK (close_current_window), window_chat);
gtk_container_set_border_width (GTK_CONTAINER (window_chat), 5);
gtk_widget_set_size_request (GTK_WIDGET (window_chat), 550, 450);
gtk_window_set_position(GTK_WINDOW(window_chat),GTK_WIN_POS_CENTER);


/* 上添加垂直分栏窗口构件 */
vpaned = gtk_vpaned_new ();
gtk_container_add (GTK_CONTAINER (window_chat), vpaned);
gtk_widget_show (vpaned);
gtk_paned_set_position(GTK_PANED(vpaned), 260);

//设置滚轮
Send_scrolled_win = gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Send_scrolled_win),
GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
//gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW(Send_scrolled_win), GTK_CORNER_BOTTOM_LEFT);
Rcv_scrolled_win = gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Rcv_scrolled_win),
GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
//gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW(Rcv_scrolled_win), GTK_CORNER_BOTTOM_LEFT);


//设置显示消息栏
Rcv_textview = gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(Rcv_textview),GTK_WRAP_WORD);
gtk_text_view_set_justification(GTK_TEXT_VIEW(Rcv_textview),GTK_JUSTIFY_LEFT);
gtk_text_view_set_editable(GTK_TEXT_VIEW(Rcv_textview),TRUE);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(Rcv_textview),TRUE);
gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(Rcv_textview),5);
gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(Rcv_textview),5);
gtk_text_view_set_pixels_inside_wrap(GTK_TEXT_VIEW(Rcv_textview),5);
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(Rcv_textview),10);
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(Rcv_textview),10);
Rcv_buffer =  gtk_text_view_get_buffer(GTK_TEXT_VIEW(Rcv_textview));
gtk_paned_pack1 (GTK_PANED (vpaned), Rcv_scrolled_win, FALSE, TRUE);
gtk_container_add(GTK_CONTAINER(Rcv_scrolled_win),Rcv_textview);
gtk_widget_show (Rcv_textview);

//在分栏的下栏中添加表
table_chat = gtk_table_new (20, 20, TRUE);
gtk_paned_pack2 (GTK_PANED (vpaned), table_chat, FALSE, TRUE);
gtk_widget_show (table_chat);

//设置输入栏
Send_textview = gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(Send_textview),GTK_WRAP_WORD);
gtk_text_view_set_justification(GTK_TEXT_VIEW(Send_textview),GTK_JUSTIFY_LEFT);
gtk_text_view_set_editable(GTK_TEXT_VIEW(Send_textview),TRUE);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(Send_textview),TRUE);
gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(Send_textview),5);
gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(Send_textview),5);
gtk_text_view_set_pixels_inside_wrap(GTK_TEXT_VIEW(Send_textview),5);
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(Send_textview),10);
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(Send_textview),10);
Send_buffer =  gtk_text_view_get_buffer(GTK_TEXT_VIEW(Send_textview));
gtk_table_attach_defaults (GTK_TABLE (table_chat), Send_scrolled_win, 0, 20, 3, 16);
gtk_container_add(GTK_CONTAINER(Send_scrolled_win),Send_textview);
gtk_widget_show (Send_textview);
gtk_widget_grab_focus (Send_textview);

//聊天记录
recordsbutton = gtk_button_new_with_label("聊天记录");
g_signal_connect (G_OBJECT (recordsbutton), "clicked",
G_CALLBACK (show_records), NULL);
gtk_table_attach_defaults (GTK_TABLE (table_chat), recordsbutton, 16, 20, 0, 3);
gtk_widget_show (recordsbutton);

docbutton = gtk_button_new_with_label("文件");
g_signal_connect (G_OBJECT (docbutton), "clicked",
G_CALLBACK (send_data), NULL);
gtk_table_attach_defaults (GTK_TABLE (table_chat), docbutton, 13, 15, 0, 3);
gtk_widget_show (docbutton);

//设置关闭发送按钮
closebutton = gtk_button_new_with_label("关闭");
g_signal_connect (G_OBJECT (closebutton), "clicked",
G_CALLBACK (close_current_window), window_chat);
gtk_table_attach_defaults (GTK_TABLE (table_chat), closebutton, 12, 16, 16, 20);
gtk_widget_show (closebutton);
sendbutton = gtk_button_new_with_label("发送");
g_signal_connect (G_OBJECT (sendbutton), "clicked",
G_CALLBACK (send_msg), Send_textview);
gtk_table_attach_defaults (GTK_TABLE (table_chat), sendbutton, 16, 20, 16, 20);
gtk_widget_show (sendbutton);

gtk_widget_show_all(window_chat);

return 0;
}
Esempio n. 9
0
static void facq_log_window_constructed(GObject *self)
{
	gchar *window_title = NULL;
	GtkWidget *window = NULL;
	GError *local_err = NULL;
	gchar *log_content = NULL;
	gsize log_size = 0;
	FacqLogWindow *log_window = FACQ_LOG_WINDOW(self);

	/* create a new #GIOChannel for reading the log file */
	log_window->priv->log = 
		g_io_channel_new_file(log_window->priv->filename,"r",&local_err);
	if(local_err)
		goto error;

	/* read the file to the end */
	if( g_io_channel_read_to_end(log_window->priv->log,
				     &log_content,
				     &log_size,
				     &local_err) != G_IO_STATUS_NORMAL ){
		g_io_channel_unref(log_window->priv->log);
		log_window->priv->log = NULL;
		goto error;
	}
	/* set \n as line term */
	g_io_channel_set_line_term(log_window->priv->log,"\n",-1);

	/* create the file monitor, first we create a #GFile. */
	log_window->priv->file = g_file_new_for_path(log_window->priv->filename);
	log_window->priv->mon = 
		g_file_monitor(log_window->priv->file,
			       G_FILE_MONITOR_NONE,
			       NULL,
			       &local_err);

	/* create the text view and put the last lines, lines, in buffer */
	log_window->priv->text_view = gtk_text_view_new();
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(log_window->priv->text_view),
					 FALSE);
	gtk_text_view_set_justification(GTK_TEXT_VIEW(log_window->priv->text_view),
					GTK_JUSTIFY_LEFT);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(log_window->priv->text_view),
				   FALSE);
	
	facq_log_window_from_log_to_text_buffer(log_window,log_content);

	/* connect the file monitor with the callback function, every time the
	 * file changes the callback will be called*/
	g_signal_connect(log_window->priv->mon,"changed",
				G_CALLBACK(log_file_changed_callback),log_window);

	/* create a scrolled window and append the text view to it*/
	window = gtk_scrolled_window_new(NULL,NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
				       GTK_POLICY_AUTOMATIC,
				       GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(window),GTK_SHADOW_NONE);
	log_window->priv->scrolled_window = window;
	gtk_container_add(GTK_CONTAINER(window),log_window->priv->text_view);

	/* Main log window, this window contains all the other components
	 * and will have a title according to your main application window title */
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	if(gtk_window_get_title(GTK_WINDOW(log_window->priv->top_window)))
		window_title = 
			g_strdup_printf("%s Log",
				gtk_window_get_title(GTK_WINDOW(log_window->priv->top_window)));
	else
		window_title = g_strdup_printf("Log Window");

	gtk_window_set_title(GTK_WINDOW(window),window_title);
	g_free(window_title);
	gtk_window_set_destroy_with_parent(GTK_WINDOW(window),TRUE);
	gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(log_window->priv->top_window));
	gtk_container_add(GTK_CONTAINER(window),log_window->priv->scrolled_window);
	g_signal_connect(window,"delete-event",
			G_CALLBACK(delete_event),log_window);

	/* ready to go */
	gtk_widget_show_all(window);
	log_window->priv->window = window;
	
	return;

	error:
	if(local_err)
		g_propagate_error(&log_window->priv->construct_error,local_err);
	return;
}
Esempio n. 10
0
File: text.c Progetto: polarcat/yad
GtkWidget *
text_create_widget (GtkWidget * dlg)
{
  GtkWidget *w;

  w = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

  text_view = gtk_text_view_new ();
  gtk_widget_set_name (text_view, "yad-text-widget");
  text_buffer = gtk_text_buffer_new (NULL);
  gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer);
  gtk_text_view_set_justification (GTK_TEXT_VIEW (text_view), options.text_data.justify);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), options.text_data.margins);
  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), options.text_data.margins);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), options.common_data.editable);
  if (!options.common_data.editable)
    gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);

  if (options.text_data.wrap)
    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR);

  if (options.text_data.fore)
    {
#if GTK_CHECK_VERSION(3,0,0)
      GdkRGBA clr;
      if (gdk_rgba_parse (&clr, options.text_data.fore))
	gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
      GdkColor clr;
      if (gdk_color_parse (options.text_data.fore, &clr))
	gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr);
#endif
    }

  if (options.text_data.back)
    {
#if GTK_CHECK_VERSION(3,0,0)
      GdkRGBA clr;
      if (gdk_rgba_parse (&clr, options.text_data.fore))
	gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
      GdkColor clr;
      if (gdk_color_parse (options.text_data.back, &clr))
	gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr);
#endif
    }

  if (options.common_data.font)
    {
      PangoFontDescription *fd =
	pango_font_description_from_string (options.common_data.font);
#if GTK_CHECK_VERSION(3,0,0)
      gtk_widget_override_font (text_view, fd);
#else
      gtk_widget_modify_font (text_view, fd);
#endif
      pango_font_description_free (fd);
    }

  /* Add submit on ctrl+enter */
  g_signal_connect (text_view, "key-press-event", G_CALLBACK (key_press_cb), dlg);

  /* Initialize linkifying */
  if (options.text_data.uri)
    {
      GRegex *regex;

      regex = g_regex_new (YAD_URL_REGEX,
			   G_REGEX_CASELESS | G_REGEX_OPTIMIZE | G_REGEX_EXTENDED,
			   G_REGEX_MATCH_NOTEMPTY,
			   NULL);

      /* Create text tag for URI */
      tag = gtk_text_buffer_create_tag (text_buffer, NULL,
                                        "foreground", "blue",
                                        "underline", PANGO_UNDERLINE_SINGLE,
                                        NULL);
      g_object_set_data (G_OBJECT (tag), "is_link", GINT_TO_POINTER (1));
      g_signal_connect (G_OBJECT (tag), "event", G_CALLBACK (tag_event_cb), NULL);

      /* Create cursors */
      hand = gdk_cursor_new (GDK_HAND2);
      normal= gdk_cursor_new (GDK_XTERM);
      g_signal_connect (G_OBJECT (text_view), "motion-notify-event", G_CALLBACK (motion_cb), NULL);

      g_signal_connect_after (G_OBJECT (text_buffer), "changed", G_CALLBACK (linkify_cb), regex);
    }

  gtk_container_add (GTK_CONTAINER (w), text_view);

  if (options.common_data.uri)
    fill_buffer_from_file ();
  else
    fill_buffer_from_stdin ();

  return w;
}
Esempio n. 11
0
int ajouterMessageDated(int fd,tlv* tlv,int hasLock){
/* Cette fonction s'occupe d'écrire directement dans le fichier dazibao.
 * Elle reçoit en argument le FILE *, un pointeur sur tlv (normalement rempli avec un Dated
 * et un flag pour savoir si cette fonction doit lock le fichier ou non 
 * (ie : si elle a été appelée par une autre fonction).
 */

    GtkTextIter end;
    GtkTextBuffer *buf;
    buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pTextView));
    gtk_text_view_set_wrap_mode((GTK_TEXT_VIEW(pTextView)),GTK_WRAP_WORD);
    gtk_text_view_set_justification((GTK_TEXT_VIEW(pTextView)),GTK_JUSTIFY_CENTER);
    gtk_text_buffer_get_end_iter(buf,&end);
    int err;
    // verrou du fichier
    if(hasLock!=1) {
        if((err=flock(fd,LOCK_EX))!=0){
            perror("flock ");
            exit(EXIT_FAILURE);
        }
    }
    // On écrit le type du tlv dans le fichier
    if(write(fd,&tlv->type,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }

    // On écrit la longueur du tlv
    unsigned int lenght=tlv->lenght;
    unsigned char l1=0,l2=0,l3=0;
    l1=ecrireLenght1(lenght);
    l2=ecrireLenght2(lenght,l1);
    l3=ecrireLenght3(lenght,l1,l2);
    if (write(fd,&l1,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    if (write(fd,&l2,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    if (write(fd,&l3,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    // On écrit la date, en convertissant pour écrire octet par octet
    unsigned int t1=0,t2=0,t3=0,t4=0;
    if(tlv->time<(256*256*256+256*256+256)){
        t1=0;
    }else{
        t1=tlv->time/(256*256*256);
    }
    if(tlv->time<(256*256+256)){
        t2=0;
    }else{
        t2=(tlv->time-(256*256*256*t1))/(256*256);
    }
    if(tlv->time<(256)){
        t3=0;
    }else{
        t3=(tlv->time-(256*256*256*t1)-(256*256*t2))/(256);
    }
    if(tlv->time<(256)){
        t4=tlv->time;
    }else{
        t4=(tlv->time-(256*256*256*t1)-(256*256*t2)-(256*t3));
    }
    // Affichage sur l'interface graphique
    gtk_text_buffer_insert(buf, &end, g_locale_to_utf8(ctime(&tlv->time), -1, NULL, NULL, NULL), -1);
    if(write(fd,&t1,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    if(write(fd,&t2,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    if(write(fd,&t3,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    if(write(fd,&t4,1)==0) {
        perror("write");
        exit(EXIT_FAILURE);
    }
    // Ensuite on écrit le sous tlv en appelant la fonction adaptée au type.
    if(tlv->tlvList[0]->type==2) {
        gtk_text_buffer_insert(buf, &end, g_locale_to_utf8(tlv->tlvList[0]->textOrPath, -1, NULL, NULL, NULL), -1);
        gtk_text_buffer_insert(buf, &end, g_locale_to_utf8("\n", -1, NULL, NULL, NULL), -1);
        ajouterMessageTxt(fd,tlv->tlvList[0],1);
    }else if(tlv->tlvList[0]->type==3){
        ajouterMessagePng(fd,tlv->tlvList[0],1);
    }else if(tlv->tlvList[0]->type==4){
        ajouterMessageJpeg(fd,tlv->tlvList[0],1);
    }else if(tlv->tlvList[0]->type==5){ 
        ajouterMessageCompound(fd,tlv->tlvList[0],1);
    }else if(tlv->tlvList[0]->type==6){
        ajouterMessageDated(fd,tlv->tlvList[0],1);
    }
    if(hasLock!=1) {
        if((err=flock(fd,LOCK_UN))!=0){
            perror("flock ");
            exit(EXIT_FAILURE);
        }
    }
    freeTlv(tlv);
    return 0;
}
Esempio n. 12
0
tlv* ajouter_dated(int opt){
/* Cette fonction va permettre de remplir un tlv dated, en appelant une fonction qui
 * sera adapter à remplir le sous tlv du type spécifié.
 * Elle renvoie un pointeur sur tlv, et NULL si quelque chose est arrivé.
 */
    GtkWidget* pBoite;
    GtkWidget* pEntry;
    const gchar* type;
    int len,i,valid=1;
    time_t now;
    tlv* tlvDated=NULL;

    // L'interface graphique demande à l'utilisateur de choisir le type du sous tlv
    pBoite = gtk_dialog_new_with_buttons("Choix du dated",
				       GTK_WINDOW(pWindow2),
				       GTK_DIALOG_MODAL,
				       GTK_STOCK_OK,GTK_RESPONSE_OK,
				       GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
				       NULL);
    pEntry = gtk_entry_new();
    gtk_entry_set_text(GTK_ENTRY(pEntry), "Entrez le type du TLV voulu");
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pBoite)->vbox), pEntry, TRUE, FALSE, 0);
    gtk_widget_show_all(GTK_DIALOG(pBoite)->vbox);
    switch (gtk_dialog_run(GTK_DIALOG(pBoite))){
        case GTK_RESPONSE_OK:
            type = gtk_entry_get_text(GTK_ENTRY(pEntry));
            len = strlen(type);
            // on vérifie qu'il s'agit bien d'un nombre ou d'un chiffre
            for(i = 0; i < len; i++){
                if((type[i]< '0') || (type[i]> '9')){
                    valid = 0;
                    break;
                }
            }
      
            if(valid == 0){ // Si la valeur rentrée n'est pas valide
                dialog = gtk_message_dialog_new(GTK_WINDOW(pBoite),GTK_DIALOG_MODAL,
                    GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,"Vous devez saisir un nombre entier!");
     
	            gtk_dialog_run(GTK_DIALOG(dialog));
	            gtk_widget_destroy(dialog);
	            gtk_widget_destroy(pBoite);
            }else{
                int n=atol(type);
                if(n > 1 && n <= TLV_MAX){
                    tlv* tlv=NULL;
                    switch (n) { // On va agir selon le type du tlv
                        case 2 : // Dans le cas d'un message texte
                            tlvDated=newTlv(6);
                            // On remplie le tlv
                            tlvDated->nbTlv=1;
                            if((tlvDated->tlvList=malloc(2*sizeof(struct tlv*)))==NULL){
                                perror("malloc");
                                exit(EXIT_FAILURE);
                            }
                            time(&now);
                            tlvDated->time=now;
                            // on appelle la fonction pour un sous-tlv texte
                            tlv=ajouter_texte(2);
                            if(tlv==NULL){   // Si le tlv a retourné NULL
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            if(tlv->lenght > 16777216){ // Si la taille du Tlv est trop grande
                                freeTlv(tlv);
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            tlvDated->lenght=tlv->lenght+4+4; //+4 pour le tlv, +4 pour le time
                            tlvDated->tlvList[0]=tlv;
                            break;
                        case 3 :
                            tlvDated=newTlv(6);
                            tlvDated->nbTlv=1;
                            if((tlvDated->tlvList=malloc(2*sizeof(struct tlv*)))==NULL){
                                perror("malloc");
                                exit(EXIT_FAILURE);
                            }
                            tlvDated->tlvList[0]=ajouter_png(3);
                            if(tlvDated->tlvList[0]==NULL){
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            if(tlvDated->tlvList[0]->lenght > 16777216){
                                freeTlv(tlv);
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            time(&now);
                            tlvDated->time=now;
                            tlvDated->lenght=tlvDated->tlvList[0]->lenght+4+4;
                            break;
                        case 4 : 
                            tlvDated=newTlv(6);
                            tlvDated->nbTlv=1;
                            if((tlvDated->tlvList=malloc(2*sizeof(struct tlv*)))==NULL){
                                perror("malloc");
                                exit(EXIT_FAILURE);
                            }
                            tlvDated->tlvList[0]=ajouter_jpeg(4);
                            if(tlvDated->tlvList[0]==NULL){
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            if(tlvDated->tlvList[0]->lenght > 16777216){ 
                                freeTlv(tlv);
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            time(&now);
                            tlvDated->time=now;
                            tlvDated->lenght=tlvDated->tlvList[0]->lenght+4+4;
                            break;
                        case 5 :
                            tlvDated=newTlv(6);
                            tlvDated->nbTlv=1;
                            if((tlvDated->tlvList=malloc(2*sizeof(struct tlv*)))==NULL){
                                perror("malloc");
                                exit(EXIT_FAILURE);
                            }
                            tlvDated->tlvList[0]=ajouter_compound(5);
                            if(tlvDated->tlvList[0]==NULL){
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            if(tlvDated->tlvList[0]->lenght > 16777216){ 
                                freeTlv(tlv);
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            time(&now);
                            tlvDated->time=now;
                            tlvDated->lenght=tlvDated->tlvList[0]->lenght+4+4;
                            break;
                        case 6 : 
                            tlvDated=newTlv(6);
                            tlvDated->nbTlv=1;
                            if((tlvDated->tlvList=malloc(2*sizeof(struct tlv*)))==NULL){
                                perror("malloc");
                                exit(EXIT_FAILURE);
                            }
                            tlvDated->tlvList[0]=ajouter_dated(6);
                            if(tlvDated->tlvList[0]==NULL){
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            if(tlvDated->tlvList[0]->lenght > 16777216){                                 
                                freeTlv(tlv);
                                freeTlv(tlvDated);
                                gtk_widget_destroy(pBoite);
                                return NULL;
                            }
                            time(&now);
                            tlvDated->time=now;
                            tlvDated->lenght=tlvDated->tlvList[0]->lenght+4+4;
                            break;
                    }
                    gtk_widget_destroy(pBoite);	

                }else {
                // Si le chiffre ne spécifiait aucun TLV
	                dialog = gtk_message_dialog_new(GTK_WINDOW(pBoite),GTK_DIALOG_MODAL,
					GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,"Vous devez rentrer un nombre compris dans les types de TLV");
     
                    gtk_dialog_run(GTK_DIALOG(dialog));
                    gtk_widget_destroy(dialog);
                    gtk_widget_destroy(pBoite);
                    return NULL;
                }
            }

            break;
        case GTK_RESPONSE_CANCEL:
        case GTK_RESPONSE_NONE:
        default:
            dialog = gtk_message_dialog_new(GTK_WINDOW(pBoite),GTK_DIALOG_MODAL,
					  GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,"Vous n'avez rien saisi!");
     
            gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
            gtk_widget_destroy(pBoite);
            return NULL;
            break;
    }
    if(opt==0){ // si la fonction est appelée par l'interface graphique (pas de parent).
        num_msg++;
        char* num_msg2=NULL;
        struct stat statBuf;
        int fd;
        if((num_msg2=malloc(10*sizeof(char)))==NULL){
            perror("malloc");
            exit(EXIT_FAILURE);
        }
        sprintf(num_msg2,"%d",num_msg);
        GtkTextIter end;
        GtkTextBuffer *buf;
        buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pTextView));
        gtk_text_view_set_wrap_mode((GTK_TEXT_VIEW(pTextView)),GTK_WRAP_WORD);
        gtk_text_view_set_justification((GTK_TEXT_VIEW(pTextView)),GTK_JUSTIFY_CENTER);
        gtk_text_buffer_get_end_iter(buf,&end);
        gtk_text_buffer_insert(buf, &end, num_msg2, -1);
        gtk_text_buffer_insert(buf, &end, "------------------------------------------------------------------------------------------------------------------------------------\n", -1);
        if((fd=open(pathToDazibao,O_RDWR|O_APPEND))==-1){
            perror("open");
            exit(EXIT_FAILURE);
        }
        if(fstat(fd,&statBuf)==-1){
            perror("fstat");
            exit(EXIT_FAILURE);
        }
        posM[num_msg]=statBuf.st_size;
        ajouterMessageDated(fd,tlvDated,0);
        close(fd);
        return NULL;
    }else{
        return tlvDated;
    }

    return NULL;
}
Esempio n. 13
0
tlv* ajouter_texte(int opt){
/* Cette fonction va permettre de remplir le tlv texte 
 * Elle va renvoyer un pointeur sur le tlv rempli une fois qu'elle a terminé,
 * ou un pointeur vers NULL, si l'utilisateur annule, ou si quelque chose 
 * s'est mal passé, où encore si la fonction n'a rien à renvoyer (pas de parent).
*/
    GtkWidget* pBoite;
    GtkWidget* pEntry;
    const gchar* sNom;
 
    pBoite = gtk_dialog_new_with_buttons("Ajout",
				       GTK_WINDOW(pWindow2),
				       GTK_DIALOG_MODAL,
				       GTK_STOCK_OK,GTK_RESPONSE_OK,
				       GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
				       NULL);
 
 // On rentre le texte voulu
    pEntry = gtk_entry_new();
    gtk_entry_set_text(GTK_ENTRY(pEntry), "Saisissez votre texte");
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pBoite)->vbox), pEntry, TRUE, FALSE, 0);
    gtk_widget_show_all(GTK_DIALOG(pBoite)->vbox);
    switch (gtk_dialog_run(GTK_DIALOG(pBoite))){
        case GTK_RESPONSE_OK:
        // On initialise le tlv texte et on le rempli
            sNom = gtk_entry_get_text(GTK_ENTRY(pEntry));
            tlv* new_msg=NULL;
            new_msg=newTlv(2);
            if((new_msg->textOrPath=malloc((strlen(sNom)+1)*sizeof(char)))==NULL){
                perror("malloc");
                exit(EXIT_FAILURE);
            }
            strcpy(new_msg->textOrPath,(char*)sNom);
            new_msg->lenght=strlen(new_msg->textOrPath);

            // si la fonction n'a pas de parent
            if(opt==0){
                num_msg++;
                struct stat statBuf;
                int fd;
                if((fd=open(pathToDazibao,O_RDWR|O_APPEND))==-1){
                    perror("open");
                    exit(EXIT_FAILURE);
                }
                if(fstat(fd,&statBuf)==-1){
                    perror("fstat");
                    exit(EXIT_FAILURE);
                }
                posM[num_msg]=statBuf.st_size;
                char* num_msg2=NULL;
                if((num_msg2=malloc(10*sizeof(char)))==NULL){
                    perror("malloc");
                    exit(EXIT_FAILURE);
                }
                sprintf(num_msg2,"%d",num_msg);
                GtkTextIter end;
                GtkTextBuffer *buf;
                buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pTextView));
                gtk_text_view_set_wrap_mode((GTK_TEXT_VIEW(pTextView)),GTK_WRAP_WORD);
                gtk_text_view_set_justification((GTK_TEXT_VIEW(pTextView)),GTK_JUSTIFY_CENTER);
                gtk_text_buffer_get_end_iter(buf,&end);
                gtk_text_buffer_insert(buf, &end, num_msg2, -1);
                gtk_text_buffer_insert(buf, &end, "------------------------------------------------------------------------------------------------------------------------------------\n", -1);
                gtk_text_buffer_insert(buf, &end, g_locale_to_utf8(new_msg->textOrPath, -1, NULL, NULL, NULL), -1);
                gtk_text_buffer_insert(buf, &end, g_locale_to_utf8("\n", -1, NULL, NULL, NULL), -1);
                ajouterMessageTxt(fd,new_msg,0);
                close(fd);
                free(num_msg2);
                gtk_widget_destroy(pEntry);	
                gtk_widget_destroy(pBoite);	
                return NULL;
            }else{
                gtk_widget_destroy(pEntry);	
                gtk_widget_destroy(pBoite);	
                return new_msg;
            }
            break;
        case GTK_RESPONSE_CANCEL:
        case GTK_RESPONSE_NONE:
            gtk_widget_destroy(pEntry);	
            gtk_widget_destroy(pBoite);
            break;
        default:
            gtk_widget_destroy(pEntry);	
            gtk_widget_destroy(pBoite);
            break;
    }
    return NULL;
}