/*************************************************************************************************************
* This file contains Chat SingleBodies widgets system
* 2012/10 by Dlxko
* Version 4.0
**************************************************************************************************************/
#include "ChatSingleWidgets.h"

// Function to create universal vbox
void singlebody_widget_vbox(int function_buddy_number)
{
	buddy[function_buddy_number].vbox = gtk_vbox_new (FALSE, 0);
}

// Function to create chat toolbar
void singlebody_widget_chat_toolbar(int function_buddy_number)
{
	// Create toolbar
	buddy[function_buddy_number].toolbar = gtk_toolbar_new();
	gtk_toolbar_set_style(GTK_TOOLBAR(buddy[function_buddy_number].toolbar), GTK_TOOLBAR_ICONS);
	gtk_toolbar_set_icon_size(GTK_TOOLBAR(buddy[function_buddy_number].toolbar), GTK_ICON_SIZE_MENU);
	gtk_container_set_border_width(GTK_CONTAINER(buddy[function_buddy_number].toolbar), 0);

	// Add items
	buddy[function_buddy_number].menu_close = gtk_tool_button_new_from_stock(GTK_STOCK_CLOSE);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy[function_buddy_number].toolbar), buddy[function_buddy_number].menu_close, -1);
	buddy[function_buddy_number].menu_transfer = gtk_tool_button_new_from_stock(GTK_STOCK_NETWORK);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy[function_buddy_number].toolbar), buddy[function_buddy_number].menu_transfer, -1);
	buddy[function_buddy_number].menu_conversation = gtk_tool_button_new_from_stock(GTK_STOCK_EDIT);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy[function_buddy_number].toolbar), buddy[function_buddy_number].menu_conversation, -1);
	buddy[function_buddy_number].menu_buddy_history = gtk_tool_button_new_from_stock(GTK_STOCK_INDEX);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy[function_buddy_number].toolbar), buddy[function_buddy_number].menu_buddy_history, -1);

	// Set signals
	g_signal_connect(G_OBJECT(buddy[function_buddy_number].menu_close), "clicked", G_CALLBACK(signal_close_chat), (gint*) function_buddy_number);
	g_signal_connect(G_OBJECT(buddy[function_buddy_number].menu_transfer), "clicked", G_CALLBACK(signal_ftp_upload), (gint*) function_buddy_number);
	g_signal_connect(G_OBJECT(buddy[function_buddy_number].menu_buddy_history), "clicked", G_CALLBACK(singlebody_chat_history_shown), (gint*) function_buddy_number);
	g_signal_connect(G_OBJECT(buddy[function_buddy_number].menu_conversation), "clicked", G_CALLBACK(singlebody_chat_signal_conversation_info_shown), (gint*) function_buddy_number);
}

// Function to create chat scroll
void singlebody_widget_chat_scroll(int function_buddy_number)
{
	buddy[function_buddy_number].scroll = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(buddy[function_buddy_number].scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
}

// Function to create chat textview
void singlebody_widget_chat_textview(int function_buddy_number)
{
	// Creat buffer is necessary
	if (!buddy[function_buddy_number].chat_buffer_created)
	{
		buddy[function_buddy_number].buffer = gtk_text_buffer_new(NULL);
		gtk_text_buffer_create_tag (buddy[function_buddy_number].buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
		gtk_text_buffer_create_tag (buddy[function_buddy_number].buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL);
		gtk_text_buffer_create_tag (buddy[function_buddy_number].buffer, "font", "font", "fixed", NULL);
		buddy[function_buddy_number].chat_buffer_created = true;
	}

	// Create text view
	buddy[function_buddy_number].text_view = gtk_text_view_new_with_buffer(buddy[function_buddy_number].buffer);
	gtk_text_view_set_editable (GTK_TEXT_VIEW (buddy[function_buddy_number].text_view), 0);
	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (buddy[function_buddy_number].text_view), GTK_WRAP_CHAR);
	gtk_text_view_set_left_margin (GTK_TEXT_VIEW (buddy[function_buddy_number].text_view), 5);
	gtk_text_view_set_right_margin (GTK_TEXT_VIEW (buddy[function_buddy_number].text_view), 5);
	gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (buddy[function_buddy_number].text_view), 0);
}

// Function to create chat entry
void singlebody_widget_chat_entry(int function_buddy_number)
{
	buddy[function_buddy_number].entry = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (buddy[function_buddy_number].entry), CHAT_MAX_MESSAGE_SIZE);
	g_signal_connect (buddy[function_buddy_number].entry, "activate", G_CALLBACK (signal_send_message), (gint*) function_buddy_number);
}

// Function to create info label
void singlebody_widget_info_label(int function_buddy_number)
{
	buddy[function_buddy_number].info_label = gtk_label_new (" ");
	gtk_label_set_justify(GTK_LABEL (buddy[function_buddy_number].info_label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap(GTK_LABEL (buddy[function_buddy_number].info_label), FALSE);
	gtk_label_set_selectable(GTK_LABEL (buddy[function_buddy_number].info_label), FALSE);
	gtk_label_set_single_line_mode(GTK_LABEL (buddy[function_buddy_number].info_label), TRUE);
}

// Function to create history entry
void singlebody_widget_history_entry(int function_buddy_number)
{
	buddy[function_buddy_number].history_entry = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (buddy[function_buddy_number].history_entry), 20);
	g_signal_connect (buddy[function_buddy_number].history_entry, "activate", G_CALLBACK (signal_search_history), (gint*) function_buddy_number);
}

// Function to create history view
void singlebody_widget_history_view(int function_buddy_number)
{
	// Creat buffer is necessary
	if (!buddy[function_buddy_number].history_buffer_created)
	{
		buddy[function_buddy_number].history_buffer = gtk_text_buffer_new(NULL);
		gtk_text_buffer_create_tag (buddy[function_buddy_number].history_buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
		gtk_text_buffer_create_tag (buddy[function_buddy_number].history_buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL);
		gtk_text_buffer_create_tag (buddy[function_buddy_number].history_buffer, "font", "font", "fixed", NULL);
		buddy[function_buddy_number].chat_buffer_created = true;
	}

	// Create view and assign buffer
	buddy[function_buddy_number].history_view = gtk_text_view_new_with_buffer(buddy[function_buddy_number].history_buffer);
	gtk_text_view_set_editable (GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), FALSE);
	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), GTK_WRAP_WORD);
	gtk_text_view_set_justification(GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), GTK_JUSTIFY_LEFT);
	gtk_widget_set_size_request (buddy[function_buddy_number].history_view, 400, 185);
	gtk_text_view_set_left_margin (GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), 5);
	gtk_text_view_set_right_margin (GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), 5);
	gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), FALSE);
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (buddy[function_buddy_number].history_view), FALSE);
}

// Function to create history label
void singlebody_widget_history_label(int function_buddy_number)
{
	buddy[function_buddy_number].history_label = gtk_label_new (LANG_ENTER_HISTORY_DATA);
	gtk_label_set_justify(GTK_LABEL (buddy[function_buddy_number].history_label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap(GTK_LABEL (buddy[function_buddy_number].history_label), FALSE);
	gtk_label_set_selectable(GTK_LABEL (buddy[function_buddy_number].history_label), FALSE);
	gtk_label_set_single_line_mode(GTK_LABEL (buddy[function_buddy_number].history_label), TRUE);
}

// Function to create history label spaced
void singlebody_widget_history_label_spaced(int function_buddy_number)
{
	buddy[function_buddy_number].history_label_spaced = gtk_label_new (" ");
	gtk_label_set_justify(GTK_LABEL (buddy[function_buddy_number].history_label_spaced), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap(GTK_LABEL (buddy[function_buddy_number].history_label_spaced), FALSE);
	gtk_label_set_selectable(GTK_LABEL (buddy[function_buddy_number].history_label_spaced), FALSE);
	gtk_label_set_single_line_mode(GTK_LABEL (buddy[function_buddy_number].history_label_spaced), TRUE);
	gtk_widget_set_size_request(buddy[function_buddy_number].history_label_spaced, 400, 7);
}

// Function to create history hbox
void singlebody_widget_history_hbox(int function_buddy_number)
{
	buddy[function_buddy_number].history_hbox = gtk_hbox_new (FALSE, 0);
}

// Function to create history entry as day input
void singlebody_widget_history_day(int function_buddy_number)
{
	buddy[function_buddy_number].history_day = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (buddy[function_buddy_number].history_day), 2);
	gtk_entry_set_text (GTK_ENTRY (buddy[function_buddy_number].history_day), "DD");
	g_signal_connect (buddy[function_buddy_number].history_day, "activate", G_CALLBACK (signal_request_history_data), (gint*) function_buddy_number);
}

// Function to create history entry as month input
void singlebody_widget_history_month(int function_buddy_number)
{
	buddy[function_buddy_number].history_month = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (buddy[function_buddy_number].history_month), 2);
	gtk_entry_set_text (GTK_ENTRY (buddy[function_buddy_number].history_month), "MM");
	g_signal_connect (buddy[function_buddy_number].history_month, "activate", G_CALLBACK (signal_request_history_data), (gint*) function_buddy_number);
}

// Function to create history entry as year input
void singlebody_widget_history_year(int function_buddy_number)
{
	buddy[function_buddy_number].history_year = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (buddy[function_buddy_number].history_year), 4);
	gtk_entry_set_text (GTK_ENTRY (buddy[function_buddy_number].history_year), "YYY");
	g_signal_connect (buddy[function_buddy_number].history_year, "activate", G_CALLBACK (signal_request_history_data), (gint*) function_buddy_number);
}