Linux gtk IDE Program Design (2)

Source: Internet
Author: User
Tags gtk
Linux gtk IDE Program Design (2)
Flyli
At this morning, I received pearl in my sleep. (My girlfriend, ha, is my first girlfriend. After going to Beijing this year, she went home, I went back to school. Well, it's not easy for programmers to find a good wife. They need to cherish it. Do you mean no ?) The text message said that he went to the temple to draw lots today and drew a lucky sign. If he didn't ask anyone to unsign the lottery, he issued the result and asked me to solve it online.

Check it. Wow, sign it up ~ Haha

As mentioned above
Jun Lisi Zun is boundless, praying and praying for the absence of party bias;
All emotions are used, and all profits are comprehensive.

I looked at the unsigned online and thought it was very simple. I also learned classical Chinese, so I could solve it myself, but I found that the ancients were really embarrassed, there seems to be a lot of medium solutions for this sign, and then look at another face, basically we can work out a more realistic sign...

However, it is also a sign-on. Because Pearl is a bit superstitious, it should be very helpful to draw such a sign-on.

But le guile, learning is still to continue, or no money to raise a wife to let his wife suffer, it is a shame of men...

Today, I wrote the code box, which is an important part of this ide. I used the text_view component of GTK. A good compiling box must be surrounded by a scroll bar, otherwise, it is not enough to write code in such a small text box. text_view has the basic text editing function, but when the size of the written text exceeds the original size, it will automatically zoom in, but its unlimited zoom in will lead to damage to the IDE interface, so we must add something to constrain it, that is, add the so-called scroll bar

Before writing this code, I think the scroll bar should be an attribute of text_view. If it is set, it will exist. However, it is found in the actual materials, in fact, text_view is put into a scroll bar container. In this way, when text_view is enlarged, the scroll bar container will set the size according to text_view. I think this is a clever method, haha, GTK is very smart.
The scroll bar container uses the gtkscrolledwindow to check its mannal to get all of his usage methods. Here I will illustrate the simplest usage methods.
Of course, the creation was initially required.
View_scroll = gtk_scrolled_window_new (null, null );
Then set
Gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
This setting can be automatically adjusted by the scroll bar. Of course, there are other options. For details, see mannal.
Then, put the text_view component in the Set container.
Gtk_container_add (GTK_CONTAINER (view_scroll), view)
In the end, place view_scroll in the area where you want it to be displayed. That's easy.

The following are all my current code. I used to compile it with projects, but I still don't know how to compile multiple files in linux. Sorry, I still need to continue learning ~
# Include <gtk/gtk. h>

/* =================================== */
/* Definition space */
/* =================================== */
# Define MAIN_WINDOW_WIDTH 790
# Define main_window_highly 590
/* =================================== */
/* The place of fuction declear */
/* =================================== */
Gint delete_event (GtkWidget * widget, GdkEvent * event, gpointer data );
Void init_show (void );

/* ===================================== */
/* Global symbol declear */
/* ===================================== */
GtkWidget * main_window;
GtkWidget * window;
GtkWidget * main_menu;
GtkWidget * main_menu_bar;
GtkWidget * main_file_item;
GtkWidget * view;
GtkWidget * table;
GtkWidget * view_scroll;
GtkWidget * main_menu_box;
GtkWidget * project_box;
GtkWidget * debug_box;
GtkWidget * view_box;
GtkWidget * default_box;
GtkWidget * menu_items;
GtkWidget * tmp1;
GtkWidget * tmp2;
GtkWidget * tmp3;
GtkWidget * tmp4;
Int main (INT argc, char * argv [])
{

/* Init */
Gtk_init (& argc, & argv );
/* Create the mainwindow */
Main_window = gtk_window_new (gtk_window_toplevel );
Main_menu = gtk_menu_new ();
View_scroll = gtk_scrolled_window_new (null, null );
Tmp1 = gtk_button_new_with_label ("project_space ");
Tmp2 = gtk_button_new_with_label ("debug_space ");
Tmp3 = gtk_button_new_with_label ("default_space ");
Tmp4 = gtk_button_new_with_label ("view_space ");
Main_menu_box = gtk_hbox_new (false, 0 );
Project_box = gtk_hbox_new (false, 0 );
Debug_box = gtk_hbox_new (FALSE, 0 );
View_box = gtk_hbox_new (FALSE, 0 );
Default_box = gtk_hbox_new (FALSE, 0 );
View = gtk_text_view_new ();

/* Set attribute */
Gtk_window_set_title (GTK_WINDOW (main_window), "flyli ");
Gtk_window_set_default_size (GTK_WINDOW (main_window), MAIN_WINDOW_WIDTH, MAIN_WINDOW_HIGH );
Gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );

/* Set menu */
Main_file_item = gtk_menu_item_new_with_label ("file ");
Gtk_widget_show (main_file_item );

Menu_items = gtk_menu_item_new_with_label ("open ");
Gtk_menu_shell_append (GTK_MENU_SHELL (main_menu), menu_items );
Gtk_widget_show (menu_items );

Gtk_menu_item_set_submenu (GTK_MENU_ITEM (main_file_item), main_menu );

Main_menu_bar = gtk_menu_bar_new ();
Gtk_menu_shell_append (GTK_MENU_SHELL (main_menu_bar), main_file_item );
Gtk_widget_show (main_menu_bar );
/* Signal connect */
G_signal_connect (G_OBJECT (main_window), "delete_event", G_CALLBACK (delete_event), "main_window ");
/* Display set */
Table = gtk_table_new (100,100, TRUE );
Gtk_container_add (GTK_CONTAINER (main_window), table );

Gtk_table_attach_defaults (GTK_TABLE (table), main_menu_box, 0,100, 0, 5 );
Gtk_table_attach_defaults (GTK_TABLE (table), project_box, 5,100 );
Gtk_table_attach_defaults (GTK_TABLE (table), debug_box, 0,100, 85,100 );
Gtk_table_attach_defaults (GTK_TABLE (table), default_box, 85,100, 5, 85 );
Gtk_table_attach_defaults (GTK_TABLE (table), view_scroll, 15, 85, 5, 85 );

Gtk_container_add (GTK_CONTAINER (view_scroll), view );
Gtk_box_pack_start (GTK_BOX (project_box), tmp1, TRUE, TRUE, 0 );
Gtk_box_pack_start (GTK_BOX (debug_box), tmp2, TRUE, TRUE, 0 );
Gtk_box_pack_start (GTK_BOX (default_box), tmp3, TRUE, TRUE, 0 );
Gtk_box_pack_start (GTK_BOX (main_menu_box), main_menu_bar, TRUE, TRUE, 0 );
/* Show */
Init_show ();
Gtk_main ();
Return 0;
}

/* = */
/* A common function to answer */
/* Window_main */
/* = */
Gint delete_event (GtkWidget * widget, GdkEvent * event, gpointer data)
{
If (data = "main_window ")
{
G_print ("main_window send quit! /N ");
}
Gtk_main_quit ();
// Gtk_widget_destroy (widget );
Return false;
}
Void init_show (void)
{
Gtk_widget_show (main_window );
Gtk_widget_show (table );
Gtk_widget_show (main_menu_box );
Gtk_widget_show (project_box );
Gtk_widget_show (debug_box );
Gtk_widget_show (view_box );
Gtk_widget_show (default_box );
Gtk_widget_show (tmp1 );
Gtk_widget_show (tmp2 );
Gtk_widget_show (tmp3 );
Gtk_widget_show (tmp4 );
Gtk_widget_show (View );
Gtk_widget_show (view_scroll );
Gtk_widget_show (view );
}
After reading the above Code, the experts must be full of contempt. In fact, I also know that it's all about global variables, which is obviously not correct.
And the code module is not doing well, but I am initially engaged in gtk programming, and I have not figured out what modularity will be clear, there are those variables that need to be global and those that need to be local, as well as the writing of private variables between files, as well as naming rules, have not yet been clearly explored, but believe me, I will find it very fast, don't despise me

What I need to do next is to learn gcc multi-file compilation and linux file operation methods. Multi-file compilation seems to involve makefile and so on. I don't know much about it, so you need to read a lot of information ~
It's a bit like Lu Yao and his feeling of building a long distance
But I think it's nice to have Pearl for refreshing.
The following is the running interface.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.