/* 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
 *
 * 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_H__
#define __PIKA_H__


#include "pikaobject.h"
#include "pika-gui.h"


#define PIKA_TYPE_PIKA            (pika_get_type ())
#define PIKA(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_PIKA, Pika))
#define PIKA_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_PIKA, PikaClass))
#define PIKA_IS_PIKA(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_PIKA))
#define PIKA_IS_PIKA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_PIKA))


typedef struct _PikaClass PikaClass;

struct _Pika
{
  PikaObject              parent_instance;

  GApplication           *app;

  PikaCoreConfig         *config;
  PikaCoreConfig         *edit_config; /* don't use this one, it's just
                                        * for the preferences dialog
                                        */
  gchar                  *session_name;
  GFile                  *default_folder;

  gboolean                be_verbose;
  gboolean                no_data;
  gboolean                no_fonts;
  gboolean                no_interface;
  gboolean                show_gui;
  gboolean                use_shm;
  gboolean                use_cpu_accel;
  PikaMessageHandlerType  message_handler;
  gboolean                console_messages;
  gboolean                show_playground;
  gboolean                show_debug_menu;
  PikaStackTraceMode      stack_trace_mode;
  PikaPDBCompatMode       pdb_compat_mode;

  PikaGui                 gui;         /* gui vtable */

  gboolean                restored;    /* becomes TRUE in pika_restore() */
  gboolean                initialized; /* Fully initialized (only set once at start). */
  gboolean                query_all;   /* Force query all plug-ins. */

  gint                    busy;
  guint                   busy_idle_id;

  GList                  *user_units;
  gint                    n_user_units;

  PikaParasiteList       *parasites;

  PikaContainer          *paint_info_list;
  PikaPaintInfo          *standard_paint_info;

  PikaModuleDB           *module_db;
  gboolean                write_modulerc;

  PikaExtensionManager   *extension_manager;
  PikaPlugInManager      *plug_in_manager;

  GList                  *filter_history;

  PikaContainer          *images;
  guint32                 next_guide_id;
  guint32                 next_sample_point_id;
  PikaIdTable            *image_table;
  PikaIdTable            *item_table;

  PikaContainer          *displays;
  gint                    next_display_id;

  GList                  *image_windows;

  PikaImage              *clipboard_image;
  PikaBuffer             *clipboard_buffer;
  PikaContainer          *named_buffers;

  PikaDataFactory        *brush_factory;
  PikaDataFactory        *dynamics_factory;
  PikaDataFactory        *mybrush_factory;
  PikaDataFactory        *pattern_factory;
  PikaDataFactory        *gradient_factory;
  PikaDataFactory        *palette_factory;
  PikaDataFactory        *font_factory;
  PikaDataFactory        *tool_preset_factory;

  PikaTagCache           *tag_cache;

  PikaPDB                *pdb;

  PikaContainer          *tool_info_list;
  PikaToolInfo           *standard_tool_info;

  PikaContainer          *tool_item_list;
  PikaContainer          *tool_item_ui_list;

  /*  the opened and saved images in MRU order  */
  PikaContainer          *documents;

  /*  image_new values  */
  PikaContainer          *templates;
  PikaTemplate           *image_new_last_template;

  /*  the list of all contexts  */
  GList                  *context_list;

  /*  the default context which is initialized from pikarc  */
  PikaContext            *default_context;

  /*  the context used by the interface  */
  PikaContext            *user_context;
};

struct _PikaClass
{
  PikaObjectClass  parent_class;

  void     (* initialize)             (Pika               *pika,
                                       PikaInitStatusFunc  status_callback);
  void     (* restore)                (Pika               *pika,
                                       PikaInitStatusFunc  status_callback);
  gboolean (* exit)                   (Pika               *pika,
                                       gboolean            force);

  void     (* clipboard_changed)      (Pika               *pika);

  void     (* filter_history_changed) (Pika               *pika);

  /*  emitted if an image is loaded and opened with a display  */
  void     (* image_opened)           (Pika               *pika,
                                       GFile              *file);
};


GType          pika_get_type               (void) G_GNUC_CONST;

Pika         * pika_new                    (const gchar         *name,
                                            const gchar         *session_name,
                                            GFile               *default_folder,
                                            gboolean             be_verbose,
                                            gboolean             no_data,
                                            gboolean             no_fonts,
                                            gboolean             no_interface,
                                            gboolean             use_shm,
                                            gboolean             use_cpu_accel,
                                            gboolean             console_messages,
                                            gboolean             show_playground,
                                            gboolean             show_debug_menu,
                                            PikaStackTraceMode   stack_trace_mode,
                                            PikaPDBCompatMode    pdb_compat_mode);
void           pika_set_show_gui           (Pika                *pika,
                                            gboolean             show_gui);
gboolean       pika_get_show_gui           (Pika                *pika);

void           pika_load_config            (Pika                *pika,
                                            GFile               *alternate_system_pikarc,
                                            GFile               *alternate_pikarc);
void           pika_initialize             (Pika                *pika,
                                            PikaInitStatusFunc   status_callback);
void           pika_restore                (Pika                *pika,
                                            PikaInitStatusFunc   status_callback,
                                            GError             **error);
gboolean       pika_is_restored            (Pika                *pika);

void           pika_exit                   (Pika                *pika,
                                            gboolean             force);

GList        * pika_get_image_iter         (Pika                *pika);
GList        * pika_get_display_iter       (Pika                *pika);
GList        * pika_get_image_windows      (Pika                *pika);
GList        * pika_get_paint_info_iter    (Pika                *pika);
GList        * pika_get_tool_info_iter     (Pika                *pika);
GList        * pika_get_tool_item_iter     (Pika                *pika);
GList        * pika_get_tool_item_ui_iter  (Pika                *pika);

PikaObject   * pika_get_clipboard_object   (Pika                *pika);

void           pika_set_clipboard_image    (Pika                *pika,
                                            PikaImage           *image);
PikaImage    * pika_get_clipboard_image    (Pika                *pika);

void           pika_set_clipboard_buffer   (Pika                *pika,
                                            PikaBuffer          *buffer);
PikaBuffer   * pika_get_clipboard_buffer   (Pika                *pika);

PikaImage    * pika_create_image           (Pika                *pika,
                                            gint                 width,
                                            gint                 height,
                                            PikaImageBaseType    type,
                                            PikaPrecision        precision,
                                            gboolean             attach_comment);

void           pika_set_default_context    (Pika                *pika,
                                            PikaContext         *context);
PikaContext  * pika_get_default_context    (Pika                *pika);

void           pika_set_user_context       (Pika                *pika,
                                            PikaContext         *context);
PikaContext  * pika_get_user_context       (Pika                *pika);

PikaToolInfo * pika_get_tool_info          (Pika                *pika,
                                            const gchar         *tool_name);

void           pika_message                (Pika                *pika,
                                            GObject             *handler,
                                            PikaMessageSeverity  severity,
                                            const gchar         *format,
                                            ...) G_GNUC_PRINTF (4, 5);
void           pika_message_valist         (Pika                *pika,
                                            GObject             *handler,
                                            PikaMessageSeverity  severity,
                                            const gchar         *format,
                                            va_list              args) G_GNUC_PRINTF (4, 0);
void           pika_message_literal        (Pika                *pika,
                                            GObject             *handler,
                                            PikaMessageSeverity  severity,
                                            const gchar         *message);

void           pika_filter_history_changed (Pika                *pika);

void           pika_image_opened           (Pika                *pika,
                                            GFile               *file);

GFile        * pika_get_temp_file          (Pika                *pika,
                                            const gchar         *extension);


#endif  /* __PIKA_H__ */
