Пример #1
0
void GlobalPressedKeys_connect( ui::Window window ){
	unsigned int key_press_handler = window.connect( "key_press_event", G_CALLBACK( PressedKeys_key_press ), &g_pressedKeys );
	unsigned int key_release_handler = window.connect( "key_release_event", G_CALLBACK( PressedKeys_key_release ), &g_pressedKeys );
	g_object_set_data( G_OBJECT( window ), "key_press_handler", gint_to_pointer( key_press_handler ) );
	g_object_set_data( G_OBJECT( window ), "key_release_handler", gint_to_pointer( key_release_handler ) );
	unsigned int focus_in_handler = window.connect( "focus_in_event", G_CALLBACK( PressedKeys_focus_in ), &g_pressedKeys );
	unsigned int focus_out_handler = window.connect( "focus_out_event", G_CALLBACK( PressedKeys_focus_out ), &g_pressedKeys );
	g_object_set_data( G_OBJECT( window ), "focus_in_handler", gint_to_pointer( focus_in_handler ) );
	g_object_set_data( G_OBJECT( window ), "focus_out_handler", gint_to_pointer( focus_out_handler ) );
}
Пример #2
0
guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback ){
#if 1
	guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
#else
	guint handler = g_signal_connect_closure( G_OBJECT( button ), "toggled", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), TRUE );
#endif
	g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) );
	return handler;
}
Пример #3
0
void global_accel_connect_window( ui::Window window ){
#if 1
	unsigned int override_handler = window.connect( "key_press_event", G_CALLBACK( override_global_accelerators ), 0 );
	g_object_set_data( G_OBJECT( window ), "override_handler", gint_to_pointer( override_handler ) );

	unsigned int special_key_press_handler = window.connect( "key_press_event", G_CALLBACK( accelerator_key_event ), &g_special_accelerators );
	g_object_set_data( G_OBJECT( window ), "special_key_press_handler", gint_to_pointer( special_key_press_handler ) );

	GlobalPressedKeys_connect( window );
#else
	unsigned int key_press_handler = window.connect( "key_press_event", G_CALLBACK( accelerator_key_event ), &g_keydown_accelerators );
	unsigned int key_release_handler = window.connect( "key_release_event", G_CALLBACK( accelerator_key_event ), &g_keyup_accelerators );
	g_object_set_data( G_OBJECT( window ), "key_press_handler", gint_to_pointer( key_press_handler ) );
	g_object_set_data( G_OBJECT( window ), "key_release_handler", gint_to_pointer( key_release_handler ) );
#endif
	g_accel_windows.insert( window );
	window.add_accel_group( global_accel );
}
Пример #4
0
GtkWidget* glwidget_new( gboolean zbuffer ){
	GtkWidget* widget = gtk_drawing_area_new();

	g_object_set_data( G_OBJECT( widget ), "zbuffer", gint_to_pointer( zbuffer ) );

	g_signal_connect( G_OBJECT( widget ), "hierarchy-changed", G_CALLBACK( glwidget_enable_gl ), 0 );

	g_signal_connect( G_OBJECT( widget ), "realize", G_CALLBACK( glwidget_context_created ), 0 );
	g_signal_connect( G_OBJECT( widget ), "unrealize", G_CALLBACK( glwidget_context_destroyed ), 0 );

	return widget;
}
Пример #5
0
ui::Window create_floating_window( const char* title, ui::Window parent ){
	ui::Window window = ui::Window( ui::window_type::TOP );
	gtk_window_set_title( window, title );

	if ( parent ) {
		gtk_window_set_transient_for( window, parent );
		connect_floating_window_destroy_present( window, parent );
		g_object_set_data( G_OBJECT( window ), "floating_handler", gint_to_pointer( connect_floating( parent, window ) ) );
		window.connect( "destroy", G_CALLBACK( destroy_disconnect_floating ), parent );
	}

	return window;
}
Пример #6
0
		void visit (const map::ump::UMPTile& tile) const
		{
			// Get the menu manager
			IMenuManager* menuManager = GlobalUIManager().getMenuManager();

			std::string base = _file.getBase();
			const std::string name = tile.getTileName(base);
			const std::string relativeName = "maps/" + _file.getMapName(name) + ".map";
			const std::string filename = GlobalFileSystem().findFile(relativeName) + relativeName;

			// Create the filter menu item
			GtkWidget* item = menuManager->add(MENU_PATH, os::getFilenameFromPath(filename),
						ui::menuItem, name,
						MENU_ICON, "");
			gtk_widget_set_sensitive(item, true);
			g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(UMPMenu::_activate), gint_to_pointer(
					g_quark_from_string(filename.c_str())));
		}
Пример #7
0
inline void CHECK_MINIMIZE( ui::Widget w ){
	g_object_set_data( G_OBJECT( w ), "was_mapped", gint_to_pointer( gtk_widget_get_visible( w ) ) );
	w.hide();
}
Пример #8
0
	PrefabSelector::PrefabSelector () :
		_widget(gtk_vbox_new(FALSE, 2)), _store(gtk_tree_store_new(PREFAB_STORE_SIZE, G_TYPE_STRING, G_TYPE_STRING,
				GDK_TYPE_PIXBUF, G_TYPE_STRING)),
				_fileFiltered(gtk_tree_model_filter_new(GTK_TREE_MODEL(_store), NULL)), _fileSorted(
						GTK_TREE_MODEL(gtk_tree_model_sort_new_with_model(_fileFiltered))), _view(
						GTK_TREE_VIEW(gtk_tree_view_new_with_model(_fileSorted)))
	{
		std::string fullpath = GlobalRegistry().get(RKEY_APP_PATH) + "prefabs/";
		_selectedSelectionStrategy = PREFAB_SELECT_EXTEND;

		GtkWidget* scr = gtk_scrolled_window_new(0, 0);
		gtk_box_pack_start(GTK_BOX(_widget), scr, TRUE, TRUE, 0);
		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scr), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
		gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);

		{
			gtk_tree_view_set_enable_search(_view, TRUE);
			gtk_tree_view_set_search_column(_view, PREFAB_SHORTNAME);
			gtk_tree_view_set_headers_visible(_view, TRUE);
			gtk_tree_view_set_headers_clickable(_view, TRUE);
#if GTK_CHECK_VERSION(2,10,0)
			gtk_tree_view_set_grid_lines(_view, GTK_TREE_VIEW_GRID_LINES_HORIZONTAL);
#endif
			g_signal_connect(G_OBJECT(_view), "button_press_event", G_CALLBACK(callbackButtonPress), this);

			{
				GtkTreeViewColumn* column = gtk_tree_view_column_new();
				gtk_tree_view_column_set_title(column, _("Prefab"));
				gtk_tree_view_column_set_expand(column, FALSE);
				gtk_tree_view_column_set_sort_indicator(column, TRUE);
				gtk_tree_view_column_set_sort_column_id(column, PREFAB_SHORTNAME);
				gtk_tree_view_append_column(_view, column);
				GtkCellRenderer* imageRenderer = gtk_cell_renderer_pixbuf_new();
				gtk_cell_renderer_set_fixed_size(imageRenderer, 128, -1);
				gtk_tree_view_column_pack_start(column, imageRenderer, false);
				gtk_tree_view_column_add_attribute(column, imageRenderer, "pixbuf", PREFAB_IMAGE);
				GtkCellRenderer* nameRenderer = gtk_cell_renderer_text_new();
				gtk_tree_view_column_pack_end(column, nameRenderer, false);
				gtk_tree_view_column_add_attribute(column, nameRenderer, "markup", PREFAB_DESCRIPTION);
			}

			gtk_container_add(GTK_CONTAINER(scr), GTK_WIDGET(_view));
			g_object_unref(G_OBJECT(_store));
		}

		GtkWidget* hboxFooter = gtk_hbox_new(TRUE, 0);
		gtk_box_pack_start(GTK_BOX(_widget), hboxFooter, FALSE, TRUE, 0);
		{
			// options
			GtkWidget* vboxOptions = gtk_vbox_new(FALSE, 3);
			gtk_box_pack_start(GTK_BOX(hboxFooter), vboxOptions, FALSE, TRUE, 0);
			GtkRadioButton* radioExtendSelection =
					GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(NULL, _("Extend current selection")));
			gtk_widget_ref(GTK_WIDGET(radioExtendSelection));
			gtk_box_pack_start(GTK_BOX(vboxOptions), GTK_WIDGET(radioExtendSelection), TRUE, TRUE, 0);
			g_object_set_data(G_OBJECT(radioExtendSelection), "handler", gint_to_pointer(
					g_signal_connect(radioExtendSelection,
							"toggled", G_CALLBACK(callbackSelectionOptionToggleExtend), this)));

			GtkRadioButton
					* radioUnselect =
							GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(radioExtendSelection, _("Deselect before insert")));
			gtk_widget_ref(GTK_WIDGET(radioUnselect));
			gtk_box_pack_start(GTK_BOX(vboxOptions), GTK_WIDGET(radioUnselect), TRUE, TRUE, 0);
			g_object_set_data(G_OBJECT(radioUnselect), "handler", gint_to_pointer(
					g_signal_connect(G_OBJECT(radioUnselect),
							"toggled", G_CALLBACK(callbackSelectionOptionToggleUnselect), this)));

			GtkRadioButton
					* radioReplace =
							GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(radioUnselect, _("Replace current selection")));
			gtk_widget_ref(GTK_WIDGET(radioReplace));
			gtk_box_pack_start(GTK_BOX(vboxOptions), GTK_WIDGET(radioReplace), TRUE, TRUE, 0);
			g_object_set_data(G_OBJECT(radioReplace), "handler", gint_to_pointer(
					g_signal_connect(G_OBJECT(radioReplace),
							"toggled", G_CALLBACK(callbackSelectionOptionToggleReplace), this)));
		}
		{
			//search entry, connect to file filter
			GtkWidget* vboxSearch = gtk_vbox_new(FALSE, 3);
			gtk_box_pack_start(GTK_BOX(hboxFooter), vboxSearch, FALSE, TRUE, 3);
			GtkWidget *searchEntry = gtk_entry_new();
			gtk_box_pack_start(GTK_BOX(vboxSearch), searchEntry, FALSE, TRUE, 3);
			gtk_widget_show(searchEntry);

			gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(_fileFiltered),
					(GtkTreeModelFilterVisibleFunc) callbackFilterFiles, this, NULL);
			g_signal_connect(G_OBJECT(searchEntry), "changed", G_CALLBACK(callbackRefilter), NULL);
			_filterEntry = GTK_ENTRY(searchEntry);
#if GTK_CHECK_VERSION(2,10,0)
			gtk_tree_view_set_search_entry(_view, _filterEntry);
#endif
		}
		/* fill prefab store with data */
		Directory_forEach(fullpath, LoadPrefabDirectoryFunctor(fullpath, "", NULL, _store));
		Directory_forEach(fullpath, MatchFileExtension<LoadPrefabFileFunctor> ("map", LoadPrefabFileFunctor("", NULL, _store)));
		gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(_fileFiltered));
		gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(_fileSorted), PREFAB_SHORTNAME, GTK_SORT_ASCENDING);
	}
Пример #9
0
void PlugInMenu_Add( GtkMenu* plugin_menu, IPlugIn* pPlugIn ){
	GtkWidget *menu, *item, *parent, *subMenu;
	const char *menuText, *menuCommand;
	WidgetStack menuStack;

	parent = gtk_menu_item_new_with_label( pPlugIn->getMenuName() );
	gtk_widget_show( parent );
	gtk_container_add( GTK_CONTAINER( plugin_menu ), parent );

	std::size_t nCount = pPlugIn->getCommandCount();
	if ( nCount > 0 ) {
		menu = gtk_menu_new();
		if ( g_Layout_enableDetachableMenus.m_value ) {
			menu_tearoff( GTK_MENU( menu ) );
		}
		while ( nCount > 0 )
		{
			menuText = pPlugIn->getCommandTitle( --nCount );
			menuCommand = pPlugIn->getCommand( nCount );

			if ( menuText != 0 && strlen( menuText ) > 0 ) {
				if ( !strcmp( menuText, "-" ) ) {
					item = gtk_menu_item_new();
					gtk_widget_set_sensitive( item, FALSE );
				}
				else if ( !strcmp( menuText, ">" ) ) {
					menuText = pPlugIn->getCommandTitle( --nCount );
					menuCommand = pPlugIn->getCommand( nCount );
					if ( !strcmp( menuText, "-" ) || !strcmp( menuText, ">" ) || !strcmp( menuText, "<" ) ) {
						globalErrorStream() << pPlugIn->getMenuName() << " Invalid title (" << menuText << ") for submenu.\n";
						continue;
					}

					item = gtk_menu_item_new_with_label( menuText );
					gtk_widget_show( item );
					gtk_container_add( GTK_CONTAINER( menu ), item );

					subMenu = gtk_menu_new();
					gtk_menu_item_set_submenu( GTK_MENU_ITEM( item ), subMenu );
					menuStack.push( menu );
					menu = subMenu;
					continue;
				}
				else if ( !strcmp( menuText, "<" ) ) {
					if ( !menuStack.empty() ) {
						menu = menuStack.top();
						menuStack.pop();
					}
					else
					{
						globalErrorStream() << pPlugIn->getMenuName() << ": Attempt to end non-existent submenu ignored.\n";
					}
					continue;
				}
				else
				{
					item = gtk_menu_item_new_with_label( menuText );
					g_object_set_data( G_OBJECT( item ),"command", const_cast<gpointer>( static_cast<const void*>( menuCommand ) ) );
					g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( plugin_activated ), gint_to_pointer( m_nNextPlugInID ) );
				}
				gtk_widget_show( item );
				gtk_container_add( GTK_CONTAINER( menu ), item );
				pPlugIn->addMenuID( m_nNextPlugInID++ );
			}
		}
		if ( !menuStack.empty() ) {
			std::size_t size = menuStack.size();
			if ( size != 0 ) {
				globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << Unsigned( size ) << " submenu(s) not closed.\n";
			}
			for ( std::size_t i = 0; i < ( size - 1 ); i++ )
			{
				menuStack.pop();
			}
			menu = menuStack.top();
			menuStack.pop();
		}
		gtk_menu_item_set_submenu( GTK_MENU_ITEM( parent ), menu );
	}
}