/* Title: Elementary Sequal * * * Based Upon the code-example by Tom Beckmann: https://plus.google.com/111734729718206650167/posts/jGGQrQrqxdg * Toms' Code is Based upon the design by Harvey Cabaguio: https://plus.google.com/110079731285191638950/posts/F8LZJuHxojD * */ using Gtk; using Granite; namespace eSQL { class MainWindow : Gtk.Window { /* APPLICATION INFORMATION */ const string program_name = ""; const string exec_name = ""; const string app_years = ""; const string app_version = ""; const string application_id = ""; const string app_icon = ""; const string app_launcher = ".desktop"; const string app_website = ""; const string app_website_lbl = ""; const string[] app_authors = {""}; const string[] app_documenters = {""}; const string[] app_translators = {"Chris Timberlake "}; const string[] app_artists = {""}; const string app_license_name = "Unknown License"; const Gtk.License app_license = License.MIT_X11; const string app_comments = ""; //Define variables. Gtk.Box main_container; Gtk.Toolbar main_toolbar; Gtk.ToolItem main_title; const int icon_size = Gtk.IconSize.LARGE_TOOLBAR; const int icon_height = 48; const string main_toolbar_css = """ .title { color: #666; text-shadow: 0px 1px 0px white; } .toolbar { padding: 0px; box-shadow: inset 0px 1px 0px rgba(255,255,255,0.3); } """; Gtk.CssProvider css; /* CUSTOM WIDGETS */ // It's just good coding practice in any language to define everything before it's used. // Even if that specific language doesn't care. public Gtk.ToolItem toolbar_seperator() { //Create the Seperator Referance var sep = new Gtk.ToolItem (); //Set Height/Width sep.height_request = icon_height; sep.width_request = 1; //Design the look! sep.draw.connect ((cr) => { cr.move_to (0, 0); cr.line_to (0, 60); cr.set_line_width (1); var grad = new Cairo.Pattern.linear (0, 0, 0, icon_height); grad.add_color_stop_rgba (0, 0.3, 0.3, 0.3, 0.4); grad.add_color_stop_rgba (0.8, 0, 0, 0, 0); cr.set_source (grad); cr.stroke (); return true; }); //Add CSS Class Contexts sep.get_style_context ().add_class ("sep"); sep.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); return sep; } //Main window's title Gtk.Label mw_title; public new string title { get { return mw_title.label; } set { mw_title.label = value; } } public MainWindow(){ /* CREATE THE BASE! */ //Build Main Toolbar main_toolbar = new Gtk.Toolbar(); //Setup the Toolbar's Look main_toolbar.icon_size = icon_size; //The CSS main_toolbar.get_style_context().add_class ("primary-toolbar"); main_toolbar.get_style_context().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); //Build the Box Container! main_container = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); main_container.pack_start (main_toolbar, false); //main_container.window-state-event.connect (() => { this.toggle_maximize(); }); /* TOOLBAR ITEMS! */ // Close Button var tb_close = new Gtk.ToolButton (new Gtk.Image.from_file("/usr/share/themes/elementary/metacity-1/close.svg"), "Close"); // Clicked Action tb_close.clicked.connect (() => destroy ()); // Set the proper dimension so it doesn't look ugly! tb_close.height_request = icon_height; tb_close.width_request = icon_height; // Maximize Button var tb_maximize = new Gtk.ToolButton (new Gtk.Image.from_file("/usr/share/themes/elementary/metacity-1/maximize.svg"), "Close"); // Clicked Action => TOGGLE MAXIMIZE! tb_maximize.clicked.connect (() => { this.toggle_maximize(); }); // Set the proper dimension so it doesn't look ugly! tb_maximize.height_request = icon_height; tb_maximize.width_request = icon_height; // Prepare the Main Window Title. mw_title = new Gtk.Label("Elementary Studio (Sequal)"); // Make it look right. mw_title.override_font(Pango.FontDescription.from_string("bold")); // Create the ToolBar Item main_title = new Gtk.ToolItem(); // Add the Main Window Title. main_title.add(mw_title); // Expand it! main_title.set_expand(true); // Settings Menu! var settings_menu = new Gtk.Menu(); //Make a spot for an about dlg Gtk.MenuItem item_about = new Gtk.MenuItem.with_label ("About"); Gtk.MenuItem item_tf = new Gtk.MenuItem.with_label ("tf"); item_about.activate.connect (() => { Granite.Widgets.show_about_dialog (base, "program_name", program_name, // "version", build_version, "logo_icon_name", app_icon, "comments", app_comments, "copyright", "%s %s Developers".printf (app_years, program_name), "website", app_website, "website_label", "Website", "authors", app_authors, "documenters", app_documenters, "artists", app_artists, "translator_credits", app_translators, "license", app_license_name, "license_type", app_license, "help", app_website, "translate", app_website, "bug", app_website); }); // Compile the menu! settings_menu.add(item_about); settings_menu.add(item_tf); // Settings Button! //new Granite.Widgets.ToolButtonWithMenu (new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", new Gtk.Menu ()), true var tb_menu = new Granite.Widgets.ToolButtonWithMenu(new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", settings_menu); // Insert the toolbar items in order! main_toolbar.insert (tb_close, -1); main_toolbar.insert (toolbar_seperator (), -1); main_toolbar.insert (main_title, -1); main_toolbar.insert (toolbar_seperator (), -1); main_toolbar.insert (tb_menu, -1); main_toolbar.insert (toolbar_seperator (), -1); main_toolbar.insert (tb_maximize, -1); /*CONTENT */ //main_container.pack_start(/*CONTENT WIDGET HERE*/, true, true, 0); //Add the Container to the Base GTK base.add(main_container); //set the default size base.set_default_size(800, 600); //Push it to the center! base.window_position = WindowPosition.CENTER; } // This is to check and see if it's maximized. If so, Minimize. void toggle_maximize(){ get_window ().maximize (); } // We need to hijack the show function of the GTK Window. public override void show(){ //Show the GTK Window base.show(); //Change the window style. Border-Only. get_window ().set_decorations (Gdk.WMDecoration.BORDER); } public override void add (Gtk.Widget widget){ main_container.pack_start(widget, true, true, 0); main_container.show_all(); } public override void remove (Gtk.Widget widget){ main_container.remove(widget); } } } //Main Loop! public static int main (string[] args){ //Init GTK! Gtk.init(ref args); //Assign window var main_window = new eSQL.MainWindow(); // When our app is closed, Cancel the process. main_window.destroy.connect (Gtk.main_quit); //Show the main window. main_window.show_all(); //GTK Main Loop. Gtk.main(); return 0; }