diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d0d799f4..76f528408 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -380,6 +380,8 @@ set(OC_CLONK_SOURCES ) set(MAPE_SOURCES + src/mape/cpp-handles/group-handle.h + src/mape/cpp-handles/group-handle.cpp src/mape/configfile.c src/mape/configfile.h src/mape/diskview.c @@ -389,7 +391,7 @@ set(MAPE_SOURCES src/mape/fileicon.c src/mape/fileicon.h src/mape/forward.h - src/mape/group.cpp + src/mape/group.c src/mape/group.h src/mape/header.c src/mape/header.h diff --git a/src/mape/diskview.c b/src/mape/diskview.c index 59d38d9f1..ee58288e4 100644 --- a/src/mape/diskview.c +++ b/src/mape/diskview.c @@ -173,7 +173,7 @@ static gboolean mape_disk_view_load_materials(MapeDiskView* disk_view, parent_group = disk_view->group_top; } - group = mape_group_new_from_parent( + group = mape_group_open_child( parent_group, "Material.c4g", error @@ -225,7 +225,7 @@ static gboolean mape_disk_view_load_materials(MapeDiskView* disk_view, { /* TODO: Check if the group is already open! (mape_disk_view_find_iter). */ - overloaded_group = mape_group_new_from_parent( + overloaded_group = mape_group_open_child( overloaded_group, "Material.c4g", error @@ -357,7 +357,7 @@ static gboolean mape_disk_view_load(MapeDiskView* disk_view, g_free(utf8_file); - child_group = mape_group_new_from_parent( + child_group = mape_group_open_child( parent_group, filename, error @@ -383,8 +383,13 @@ static gboolean mape_disk_view_load(MapeDiskView* disk_view, if(disk_view->group_top != NULL) return TRUE; - disk_view->group_top = mape_group_new("/", error); - if(disk_view->group_top == NULL) return FALSE; + disk_view->group_top = mape_group_new(); + if(!mape_group_open(disk_view->group_top, "/", error)) + { + g_object_unref(disk_view->group_top); + disk_view->group_top = NULL; + return FALSE; + } child_group = disk_view->group_top; } @@ -456,7 +461,7 @@ static gboolean mape_disk_view_load(MapeDiskView* disk_view, icon_type = MAPE_FILE_ICON_C4SCENARIO; } - if(child_group->group_handle == NULL) + if(mape_group_is_drive_container(child_group)) icon_type = MAPE_FILE_ICON_DRIVE; icon = mape_file_icon_set_lookup( @@ -788,7 +793,7 @@ static void mape_disk_view_close_groups(MapeDiskView* disk_view, mape_disk_view_close_groups(disk_view, &child); if(group != NULL) - mape_group_destroy(group); + g_object_unref(group); if(has_next == TRUE) mape_disk_view_close_groups(disk_view, iter); @@ -966,12 +971,12 @@ void mape_disk_view_destroy(MapeDiskView* disk_view) { /* Close open groups */ GtkTreeIter iter; - gtk_tree_model_get_iter_first(disk_view->tree_store, &iter); - mape_disk_view_close_groups(disk_view, &iter); + if(gtk_tree_model_get_iter_first(disk_view->tree_store, &iter)) + mape_disk_view_close_groups(disk_view, &iter); /* TODO: unref cell renderers? */ /*mape_file_icon_set_destroy(disk_view->icon_set);*/ - mape_group_destroy(disk_view->group_top); + g_object_unref(disk_view->group_top); g_object_unref(G_OBJECT(disk_view->tree_store) ); free(disk_view); diff --git a/src/mape/diskview.h b/src/mape/diskview.h index 1c740922a..01b9d735e 100644 --- a/src/mape/diskview.h +++ b/src/mape/diskview.h @@ -21,7 +21,9 @@ #include #include #include + #include "forward.h" +#include "group.h" typedef enum MapeDiskViewColumns_ { MAPE_DISK_VIEW_COLUMN_ICON, diff --git a/src/mape/fileicon.c b/src/mape/fileicon.c index 048ce1801..51b1d233d 100644 --- a/src/mape/fileicon.c +++ b/src/mape/fileicon.c @@ -16,7 +16,8 @@ */ #include -#include +#include + #include "icons.h" #include "fileicon.h" diff --git a/src/mape/forward.h b/src/mape/forward.h index 745d5c324..0392044d7 100644 --- a/src/mape/forward.h +++ b/src/mape/forward.h @@ -18,7 +18,7 @@ #ifndef INC_MAPE_FORWARD_H #define INC_MAPE_FORWARD_H -typedef struct MapeGroup_ MapeGroup; +/*typedef struct MapeGroup_ MapeGroup;*/ typedef struct MapeMaterialMap_ MapeMaterialMap; typedef struct MapeTextureMap_ MapeTextureMap; typedef struct MapeFileIcon_ MapeFileIcon; diff --git a/src/mape/group.h b/src/mape/group.h index c9b43ce20..3fd9413eb 100644 --- a/src/mape/group.h +++ b/src/mape/group.h @@ -1,72 +1,130 @@ -/* mape - C4 Landscape.txt editor - * Copyright (C) 2005 Armin Burgmeier +/* + * mape - C4 Landscape.txt editor * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * Copyright (c) 2005-2009 Armin Burgmeier * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * Portions might be copyrighted by other authors who have contributed + * to OpenClonk. * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * See isc_license.txt for full license and disclaimer. + * + * "Clonk" is a registered trademark of Matthes Bender. + * See clonk_trademark_license.txt for full license. */ #ifndef INC_MAPE_GROUP_H #define INC_MAPE_GROUP_H -#include -#include "forward.h" +#include -/* Simple C-based interface to C4Group */ +G_BEGIN_DECLS -#ifdef MAPE_COMPILING_CPP -extern "C" { -#endif +#define MAPE_TYPE_GROUP (mape_group_get_type()) +#define MAPE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MAPE_TYPE_GROUP, MapeGroup)) +#define MAPE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MAPE_TYPE_GROUP, MapeGroupClass)) +#define MAPE_IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MAPE_TYPE_GROUP)) +#define MAPE_IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MAPE_TYPE_GROUP)) +#define MAPE_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MAPE_TYPE_GROUP, MapeGroupClass)) -typedef enum MapeGroupError_ { - MAPE_GROUP_ERROR_OPEN, - MAPE_GROUP_ERROR_READ, - MAPE_GROUP_ERROR_FAILED +#define MAPE_TYPE_GROUP_STATUS (mape_group_status_get_type()) + +typedef struct _MapeGroup MapeGroup; +typedef struct _MapeGroupClass MapeGroupClass; + +/** + * MapeGroupError: + * @MAPE_GROUP_ERROR_OPEN: An error occured when attempting to open the group. + * @MAPE_GROUP_ERROR_ACCESS: An error occurred when accessing a group element. + * @MAPE_GROUP_ERROR_READ: An error occured when reading from the group. + * + * These errors are from the MAPE_GROUP_ERROR error domain. They can occur + * when opening, seeking or reading from a group, respectively. + */ +typedef enum _MapeGroupError { + MAPE_GROUP_ERROR_OPEN, + MAPE_GROUP_ERROR_ACCESS, + MAPE_GROUP_ERROR_READ } MapeGroupError; - -struct MapeGroup_ { - void* group_handle; -#ifdef G_OS_WIN32 - unsigned int drive_idtf; -#endif + +/** + * MapeGroupClass: + * + * This structure does not contain any public fields. + */ +struct _MapeGroupClass { + /*< private >*/ + GObjectClass parent_class; }; -MapeGroup* mape_group_new(const gchar* path, - GError** error); -MapeGroup* mape_group_new_from_parent(MapeGroup* parent, - const gchar* entry, - GError** error); -void mape_group_destroy(MapeGroup* group); +/** + * MapeGroup: + * + * #MapeGroup is an opaque data type. You should only access it via the + * public API functions. + */ +struct _MapeGroup { + /*< private >*/ + GObject parent; +}; -const gchar* mape_group_get_name(MapeGroup* group); -const gchar* mape_group_get_full_name(MapeGroup* group); +GType +mape_group_get_type(void) G_GNUC_CONST; -gboolean mape_group_has_entry(MapeGroup* group, - const gchar* entry); +MapeGroup* +mape_group_new(void); -void mape_group_rewind(MapeGroup* group); -gchar* mape_group_get_next_entry(MapeGroup* group); +gboolean +mape_group_is_open(MapeGroup* group); -guchar* mape_group_load_entry(MapeGroup* group, - gsize* size, - GError** error); +gboolean +mape_group_open(MapeGroup* group, + const gchar* path, + GError** error); -gboolean mape_group_is_folder(MapeGroup* group); -gboolean mape_group_is_child_folder(MapeGroup* group, - const gchar* child); +MapeGroup* +mape_group_open_child(MapeGroup* group, + const gchar* entry, + GError** error); -#ifdef MAPE_COMPILING_CPP -} /* extern "C" */ -#endif +void +mape_group_close(MapeGroup* group); -#endif /* INC_MAPE_GORUP_H */ +const gchar* +mape_group_get_name(MapeGroup* group); + +gchar* +mape_group_get_full_name(MapeGroup* group); + +gboolean +mape_group_has_entry(MapeGroup* group, + const gchar* entry); + +void +mape_group_rewind(MapeGroup* group); + +gchar* +mape_group_get_next_entry(MapeGroup* group); + +guchar* +mape_group_load_entry(MapeGroup* group, + gsize* size, + GError** error); + +gboolean +mape_group_is_folder(MapeGroup* group); + +gboolean +mape_group_is_drive_container(MapeGroup* group); + +gboolean +mape_group_is_child_folder(MapeGroup* group, + const gchar* child); + +G_END_DECLS + +#endif /* MAPE_GROUP_H */ + +/* vim:set et sw=2 ts=2: */ diff --git a/src/mape/material.cpp b/src/mape/material.cpp index e65d1479b..591fa44ff 100644 --- a/src/mape/material.cpp +++ b/src/mape/material.cpp @@ -29,16 +29,22 @@ C4FullScreen FullScreen; C4Game Game; C4Network2 Network; + #define MAPE_COMPILING_CPP #include #include + +#include "cpp-handles/group-handle.h" + #include "group.h" #include "material.h" #define CPPMAT(mat) ( (C4Material*)mat) #define CPPMATMAP(map) ( (C4MaterialMap*)map->handle) -#define CPPGROUP(group) ((C4Group*)group->group_handle) + +extern "C" C4GroupHandle* _mape_group_get_handle(MapeGroup*); +#define CPPGROUP(group) (reinterpret_cast(_mape_group_get_handle(group))) extern "C" { @@ -57,7 +63,7 @@ MapeMaterialMap* mape_material_map_new(MapeGroup* base, if(overload_from != NULL) CPPMATMAP(map)->Load(*CPPGROUP(overload_from)); } - catch(std::exception& e) + catch(const std::exception& e) { g_set_error( error, diff --git a/src/mape/material.h b/src/mape/material.h index c73242757..61d480aaf 100644 --- a/src/mape/material.h +++ b/src/mape/material.h @@ -18,9 +18,10 @@ #ifndef INC_MAPE_MATERIAL_H #define INC_MAPE_MATERIAL_H -#include -#include +#include + #include "forward.h" +#include "group.h" /* Simple C-based interface to C4MaterialMap */ diff --git a/src/mape/mattexview.h b/src/mape/mattexview.h index 5d364bbc6..d0d67bc2f 100644 --- a/src/mape/mattexview.h +++ b/src/mape/mattexview.h @@ -19,7 +19,9 @@ #define INC_MAPE_MATTEXVIEW_H #include + #include "forward.h" +#include "group.h" struct MapeMatTexView_ { GtkWidget* notebook; diff --git a/src/mape/texture.cpp b/src/mape/texture.cpp index 067902918..e39ec042a 100644 --- a/src/mape/texture.cpp +++ b/src/mape/texture.cpp @@ -19,11 +19,15 @@ #include #include + +#include "cpp-handles/group-handle.h" #include "group.h" #include "texture.h" #define CPPTEXMAP(map) ( (C4TextureMap*)map->handle) -#define CPPGROUP(group) ((C4Group*)group->group_handle) + +extern "C" C4GroupHandle* _mape_group_get_handle(MapeGroup*); +#define CPPGROUP(group) (reinterpret_cast(_mape_group_get_handle(group))) extern "C" { diff --git a/src/mape/texture.h b/src/mape/texture.h index 571f22c84..4c6d816a0 100644 --- a/src/mape/texture.h +++ b/src/mape/texture.h @@ -20,7 +20,9 @@ #include #include + #include "forward.h" +#include "group.h" /* Simple C-based interface to C4TextureMap */