/* PIKA - Photo and Image Kooker Application
 * a rebranding of The GNU Image Manipulation Program (created with heckimp)
 * A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
 *
 * Original copyright, applying to most contents (license remains unchanged): 
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 *
 * pikacontainer.h
 * Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
 *
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef __PIKA_CONTAINER_H__
#define __PIKA_CONTAINER_H__


#include "pikaobject.h"


#define PIKA_TYPE_CONTAINER            (pika_container_get_type ())
#define PIKA_CONTAINER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_CONTAINER, PikaContainer))
#define PIKA_CONTAINER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_CONTAINER, PikaContainerClass))
#define PIKA_IS_CONTAINER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_CONTAINER))
#define PIKA_IS_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_CONTAINER))
#define PIKA_CONTAINER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_CONTAINER, PikaContainerClass))


typedef gboolean (* PikaContainerSearchFunc) (PikaObject *object,
                                              gpointer    user_data);


typedef struct _PikaContainerClass   PikaContainerClass;
typedef struct _PikaContainerPrivate PikaContainerPrivate;

struct _PikaContainer
{
  PikaObject            parent_instance;

  PikaContainerPrivate *priv;
};

struct _PikaContainerClass
{
  PikaObjectClass  parent_class;

  /*  signals  */
  void         (* add)                (PikaContainer           *container,
                                       PikaObject              *object);
  void         (* remove)             (PikaContainer           *container,
                                       PikaObject              *object);
  void         (* reorder)            (PikaContainer           *container,
                                       PikaObject              *object,
                                       gint                     new_index);
  void         (* freeze)             (PikaContainer           *container);
  void         (* thaw)               (PikaContainer           *container);

  /*  virtual functions  */
  void         (* clear)              (PikaContainer           *container);
  gboolean     (* have)               (PikaContainer           *container,
                                       PikaObject              *object);
  void         (* foreach)            (PikaContainer           *container,
                                       GFunc                    func,
                                       gpointer                 user_data);
  PikaObject * (* search)             (PikaContainer           *container,
                                       PikaContainerSearchFunc  func,
                                       gpointer                 user_data);
  gboolean     (* get_unique_names)   (PikaContainer           *container);
  PikaObject * (* get_child_by_name)  (PikaContainer           *container,
                                       const gchar             *name);
  GList    * (* get_children_by_name) (PikaContainer           *container,
                                       const gchar             *name);
  PikaObject * (* get_child_by_index) (PikaContainer           *container,
                                       gint                     index);
  gint         (* get_child_index)    (PikaContainer           *container,
                                       PikaObject              *object);
};


GType        pika_container_get_type           (void) G_GNUC_CONST;

GType        pika_container_get_children_type  (PikaContainer           *container);
PikaContainerPolicy pika_container_get_policy  (PikaContainer           *container);
gint         pika_container_get_n_children     (PikaContainer           *container);

gboolean     pika_container_add                (PikaContainer           *container,
                                                PikaObject              *object);
gboolean     pika_container_remove             (PikaContainer           *container,
                                                PikaObject              *object);
gboolean     pika_container_insert             (PikaContainer           *container,
                                                PikaObject              *object,
                                                gint                     new_index);
gboolean     pika_container_reorder            (PikaContainer           *container,
                                                PikaObject              *object,
                                                gint                     new_index);

void         pika_container_freeze             (PikaContainer           *container);
void         pika_container_thaw               (PikaContainer           *container);
gboolean     pika_container_frozen             (PikaContainer           *container);
gint         pika_container_freeze_count       (PikaContainer           *container);

void         pika_container_clear              (PikaContainer           *container);
gboolean     pika_container_is_empty           (PikaContainer           *container);
gboolean     pika_container_have               (PikaContainer           *container,
                                                PikaObject              *object);
void         pika_container_foreach            (PikaContainer           *container,
                                                GFunc                    func,
                                                gpointer                 user_data);
PikaObject * pika_container_search             (PikaContainer           *container,
                                                PikaContainerSearchFunc  func,
                                                gpointer                 user_data);

gboolean     pika_container_get_unique_names   (PikaContainer           *container);

GList    * pika_container_get_children_by_name (PikaContainer           *container,
                                                const gchar             *name);
PikaObject * pika_container_get_child_by_name  (PikaContainer           *container,
                                                const gchar             *name);
PikaObject * pika_container_get_child_by_index (PikaContainer           *container,
                                                gint                     index);
PikaObject * pika_container_get_first_child    (PikaContainer           *container);
PikaObject * pika_container_get_last_child     (PikaContainer           *container);
gint         pika_container_get_child_index    (PikaContainer           *container,
                                                PikaObject              *object);

PikaObject * pika_container_get_neighbor_of    (PikaContainer           *container,
                                                PikaObject              *object);

gchar     ** pika_container_get_name_array     (PikaContainer           *container);

GQuark       pika_container_add_handler        (PikaContainer           *container,
                                                const gchar             *signame,
                                                GCallback                callback,
                                                gpointer                 callback_data);
void         pika_container_remove_handler     (PikaContainer           *container,
                                                GQuark                   id);
void         pika_container_remove_handlers_by_func
                                               (PikaContainer           *container,
                                                GCallback                callback,
                                                gpointer                 callback_data);
void         pika_container_remove_handlers_by_data
                                               (PikaContainer           *container,
                                                gpointer                 callback_data);


#endif  /* __PIKA_CONTAINER_H__ */
