Ejemplo n.º 1
0
void DoCommandListDlg()
{
  command_list_dialog_t dialog;

  GtkWindow* window = create_modal_dialog_window(MainFrame_getWindow(), "Mapped Commands", dialog, -1, 400);

  GtkAccelGroup* accel = gtk_accel_group_new();
  gtk_window_add_accel_group(window, accel);

  GtkHBox* hbox = create_dialog_hbox(4, 4);
  gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(hbox));

  {
    GtkScrolledWindow* scr = create_scrolled_window(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(scr), TRUE, TRUE, 0);

    {
      GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);

      GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));

      {
        GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
        GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("Command", renderer, "text", 0, 0);
        gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
      }

      {
        GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
        GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("Key", renderer, "text", 1, 0);
        gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
      }

      gtk_widget_show(view);
      gtk_container_add(GTK_CONTAINER (scr), view);

      {
        // Initialize dialog
        StringOutputStream path(256);
        path << SettingsPath_get() << "commandlist.txt";
        globalOutputStream() << "Writing the command list to " << path.c_str() << "\n";
        class BuildCommandList : public CommandVisitor
        {
          TextFileOutputStream m_commandList;
          GtkListStore* m_store;
        public:
          BuildCommandList(const char* filename, GtkListStore* store) : m_commandList(filename), m_store(store)
          {
          }
          void visit(const char* name, Accelerator& accelerator)
          {
            StringOutputStream modifiers;
            modifiers << accelerator;

            {
              GtkTreeIter iter;
              gtk_list_store_append(m_store, &iter);
              gtk_list_store_set(m_store, &iter, 0, name, 1, modifiers.c_str(), -1);
            }
 
            if(!m_commandList.failed())
            {
              m_commandList << makeLeftJustified(name, 25) << " " << modifiers.c_str() << '\n';
            }
          }
        } visitor(path.c_str(), store);

        GlobalShortcuts_foreach(visitor);
      }
    
      g_object_unref(G_OBJECT(store));
    }
  }

  GtkVBox* vbox = create_dialog_vbox(4);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), FALSE, FALSE, 0);
  {
    GtkButton* button = create_modal_dialog_button("Close", dialog.m_close_button);
    gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
    widget_make_default(GTK_WIDGET(button));
    gtk_widget_grab_focus(GTK_WIDGET(button));
    gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
    gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
  }

  modal_dialog_show(window, dialog);
  gtk_widget_destroy(GTK_WIDGET(window));
}
Ejemplo n.º 2
0
void DoCommandListDlg(){
	command_list_dialog_t dialog;

	GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Mapped Commands", dialog, -1, 400 );
	g_signal_connect( G_OBJECT( window ), "key-press-event", (GCallback) accelerator_window_key_press, &dialog );

	GtkAccelGroup* accel = gtk_accel_group_new();
	gtk_window_add_accel_group( window, accel );

	GtkHBox* hbox = create_dialog_hbox( 4, 4 );
	gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );

	{
		GtkScrolledWindow* scr = create_scrolled_window( GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
		gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( scr ), TRUE, TRUE, 0 );

		{
			GtkListStore* store = gtk_list_store_new( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT );

			GtkWidget* view = gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) );
			dialog.m_list = GTK_TREE_VIEW( view );

			gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), false ); // annoying

			{
				GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
				GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Command", renderer, "text", 0, "weight-set", 2, "weight", 3, NULL );
				gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
			}

			{
				GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
				GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Key", renderer, "text", 1, "weight-set", 2, "weight", 3, NULL );
				gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
			}

			gtk_widget_show( view );
			gtk_container_add( GTK_CONTAINER( scr ), view );

			{
				// Initialize dialog
				StringOutputStream path( 256 );
				path << SettingsPath_get() << "commandlist.txt";
				globalOutputStream() << "Writing the command list to " << path.c_str() << "\n";
				class BuildCommandList : public CommandVisitor
				{
				TextFileOutputStream m_commandList;
				GtkListStore* m_store;
public:
				BuildCommandList( const char* filename, GtkListStore* store ) : m_commandList( filename ), m_store( store ){
				}
				void visit( const char* name, Accelerator& accelerator ){
					StringOutputStream modifiers;
					modifiers << accelerator;

					{
						GtkTreeIter iter;
						gtk_list_store_append( m_store, &iter );
						gtk_list_store_set( m_store, &iter, 0, name, 1, modifiers.c_str(), 2, false, 3, 800, -1 );
					}

					if ( !m_commandList.failed() ) {
						int l = strlen( name );
						m_commandList << name;
						while ( l++ < 25 )
							m_commandList << ' ';
						m_commandList << modifiers.c_str() << '\n';
					}
				}
				} visitor( path.c_str(), store );

				GlobalShortcuts_foreach( visitor );
			}

			g_object_unref( G_OBJECT( store ) );
		}
	}

	GtkVBox* vbox = create_dialog_vbox( 4 );
	gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
	{
		GtkButton* editbutton = create_dialog_button( "Edit", (GCallback) accelerator_edit_button_clicked, &dialog );
		gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( editbutton ), FALSE, FALSE, 0 );

		GtkButton* clearbutton = create_dialog_button( "Clear", (GCallback) accelerator_clear_button_clicked, &dialog );
		gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( clearbutton ), FALSE, FALSE, 0 );

		GtkWidget *spacer = gtk_image_new();
		gtk_widget_show( spacer );
		gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( spacer ), TRUE, TRUE, 0 );

		GtkButton* button = create_modal_dialog_button( "Close", dialog.m_close_button );
		gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
		widget_make_default( GTK_WIDGET( button ) );
		gtk_widget_grab_default( GTK_WIDGET( button ) );
		gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
		gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
	}

	modal_dialog_show( window, dialog );
	gtk_widget_destroy( GTK_WIDGET( window ) );
}
Ejemplo n.º 3
0
EMessageBoxReturn gtk_MessageBox (GtkWidget *parent, const char* text, const char* title, EMessageBoxType type, EMessageBoxIcon icon)
{
  ModalDialog dialog;
  ModalDialogButton ok_button(dialog, eIDOK);
  ModalDialogButton cancel_button(dialog, eIDCANCEL);
  ModalDialogButton yes_button(dialog, eIDYES);
  ModalDialogButton no_button(dialog, eIDNO);

  GtkWindow* parentWindow = parent != 0 ? GTK_WINDOW(parent) : 0;

  GtkWindow* window = create_fixedsize_modal_dialog_window(parentWindow, title, dialog, 400, 100);

  if(parentWindow != 0)
  {
    //g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(floating_window_delete_present), parent);
    gtk_window_deiconify(parentWindow);
  }  

  GtkAccelGroup* accel = gtk_accel_group_new();
  gtk_window_add_accel_group(window, accel);

  GtkVBox* vbox = create_dialog_vbox(8, 8);
  gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vbox));


  GtkHBox* hboxDummy = create_dialog_hbox(0, 0);
  gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hboxDummy), FALSE, FALSE, 0);

  gtk_box_pack_start(GTK_BOX(hboxDummy), create_padding(0, 50), FALSE, FALSE, 0); // HACK to force minimum height

  GtkHBox* iconBox = create_dialog_hbox(16, 0);
  gtk_box_pack_start(GTK_BOX(hboxDummy), GTK_WIDGET(iconBox), FALSE, FALSE, 0);

  GtkImage* image = GTK_IMAGE(gtk_image_new_from_stock(messagebox_stock_icon(icon), GTK_ICON_SIZE_DIALOG));
  gtk_widget_show(GTK_WIDGET(image));
  gtk_box_pack_start(GTK_BOX(iconBox), GTK_WIDGET(image), FALSE, FALSE, 0);

  GtkLabel* label = GTK_LABEL(gtk_label_new(text));
  gtk_widget_show(GTK_WIDGET(label));
  gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  gtk_label_set_justify(label, GTK_JUSTIFY_LEFT);
  gtk_label_set_line_wrap(label, TRUE);
  gtk_box_pack_start(GTK_BOX(iconBox), GTK_WIDGET(label), TRUE, TRUE, 0);


  GtkVBox* vboxDummy = create_dialog_vbox(0, 0);
  gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(vboxDummy), FALSE, FALSE, 0);

  GtkAlignment* alignment = GTK_ALIGNMENT(gtk_alignment_new(0.5, 0.0, 0.0, 0.0));
  gtk_widget_show(GTK_WIDGET(alignment));
  gtk_box_pack_start(GTK_BOX(vboxDummy), GTK_WIDGET(alignment), FALSE, FALSE, 0);

  GtkHBox* hbox = create_dialog_hbox(8, 0);
  gtk_container_add(GTK_CONTAINER(alignment), GTK_WIDGET(hbox));

  gtk_box_pack_start(GTK_BOX(vboxDummy), create_padding(400, 0), FALSE, FALSE, 0); // HACK to force minimum width


  if (type == eMB_OK)
  {
    GtkButton* button = create_modal_dialog_button("OK", ok_button);
    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
    gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
    gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
    widget_make_default(GTK_WIDGET(button));
    gtk_widget_show(GTK_WIDGET(button));

    dialog.ret = eIDOK;
  }
  else if (type ==  eMB_OKCANCEL)
  {
    {
      GtkButton* button = create_modal_dialog_button("OK", ok_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
      widget_make_default(GTK_WIDGET(button));
      gtk_widget_show(GTK_WIDGET(button));
    }

    {
      GtkButton* button = create_modal_dialog_button("OK", cancel_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
      gtk_widget_show(GTK_WIDGET(button));
    }

    dialog.ret = eIDCANCEL;
  }
  else if (type == eMB_YESNOCANCEL)
  {
    {
      GtkButton* button = create_modal_dialog_button("Yes", yes_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      widget_make_default(GTK_WIDGET(button));
      gtk_widget_show(GTK_WIDGET(button));
    }

    {
      GtkButton* button = create_modal_dialog_button("No", no_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      gtk_widget_show(GTK_WIDGET(button));
    }
    {
      GtkButton* button = create_modal_dialog_button("Cancel", cancel_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      gtk_widget_show(GTK_WIDGET(button));
    }

    dialog.ret = eIDCANCEL;
  }
  else if (type == eMB_NOYES)
  {
    {
      GtkButton* button = create_modal_dialog_button("No", no_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      widget_make_default(GTK_WIDGET(button));
      gtk_widget_show(GTK_WIDGET(button));
    }
    {
      GtkButton* button = create_modal_dialog_button("Yes", yes_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      gtk_widget_show(GTK_WIDGET(button));
    }

    dialog.ret = eIDNO;
  }
  else /* if (type == eMB_YESNO) */
  {
    {
      GtkButton* button = create_modal_dialog_button("Yes", yes_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      widget_make_default(GTK_WIDGET(button));
      gtk_widget_show(GTK_WIDGET(button));
    }
 
    {
      GtkButton* button = create_modal_dialog_button("No", no_button);
      gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), TRUE, FALSE, 0);
      gtk_widget_show(GTK_WIDGET(button));
    }
    dialog.ret = eIDNO;
  }

  modal_dialog_show(window, dialog);

  gtk_widget_destroy(GTK_WIDGET(window));

  return dialog.ret;
}