/* sourcecompletion.h
 *
 * Copyright (C) 2009, 2010 Krzesimir Nowak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtkmm/object.h>
#include <gtksourceviewmm/sourcecompletioncontext.h>
#include <gtksourceviewmm/sourcecompletionprovider.h>
#include <gtksourceviewmm/sourceview.h>
#include <gtksourceviewmm/sourcecompletioninfo.h>

_DEFS(gtksourceviewmm,gtksourceview)
_PINCLUDE(gtkmm/private/object_p.h)

namespace gtksourceview
{

class SourceCompletionContext;
class SourceCompletionProvider;

_WRAP_GERROR(SourceCompletionError, GtkSourceCompletionError, GTK_SOURCE_COMPLETION_ERROR)

/** Main Completion Object
 *
 * @newin{2,10}
 */
class SourceCompletion : public Gtk::Object
{
  _CLASS_GTKOBJECT(SourceCompletion, GtkSourceCompletion, GTK_SOURCE_COMPLETION, Gtk::Object, GtkObject)
public:

  /** Add a new SourceCompletionProvider to the completion object.
   *
   * This will add a reference provider.
   *
   * @param provider A SourceCompletionProvider.
   *
   * @return @c true if provider was successfully added, otherwise error is
   * thrown.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(bool add_provider(const Glib::RefPtr<SourceCompletionProvider>& provider), gtk_source_completion_add_provider, errthrow)

  /** Remove provider from the completion.
   *
   * @param provider A SourceCompletionProvider.
   *
   * @return @c true if provider was successfully removed, otherwise error is
   * thrown.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(bool remove_provider(const Glib::RefPtr<SourceCompletionProvider>& provider), gtk_source_completion_remove_provider, errthrow)

#m4 _CONVERSION(`GList*',`Glib::ListHandle<Glib::RefPtr<SourceCompletionProvider> >',`$2($3, Glib::OWNERSHIP_NONE)')
  /** Get list of providers registered on completion.
   *
   * @return List of SourceCompletionProvider.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(Glib::ListHandle<Glib::RefPtr<SourceCompletionProvider> > get_providers() const, gtk_source_completion_get_providers)

#m4 _CONVERSION(`const Glib::ListHandle<Glib::RefPtr<SourceCompletionProvider> >&',`GList*',`($3).data()')
  /** Starts a new completion with the specified SourceCompletionContext and
   *  a list of potential candidate providers for completion.
   *
   * @param providers A list of SourceCompletionProvider.
   * @param context The SourceCompletionContext with which to start the
   * completion.
   *
   * @return @c true if it was possible to the show completion window.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(bool show(const Glib::ListHandle<Glib::RefPtr<SourceCompletionProvider> >& providers, const Glib::RefPtr<SourceCompletionContext>& context), gtk_source_completion_show)

  /** Hides the completion if it is active (visible).
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(void hide(), gtk_source_completion_hide)

  /** Gets the SourceCompletionInfo window.
   *
   * The info widget is the window where the completion displays optional extra information of the proposal.
   *
   * @return The SourceCompletionInfo window.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(SourceCompletionInfo* get_info_window(), gtk_source_completion_get_info_window)

  /** Gets the SourceCompletionInfo window.
   *
   * The info widget is the window where the completion displays optional extra information of the proposal.
   *
   * @return The SourceCompletionInfo window.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(const SourceCompletionInfo* get_info_window() const, gtk_source_completion_get_info_window, constversion)

  /** Gets the SourceView associated with completion.
   *
   * @return The SourceView associated with completion.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(SourceView* get_view(), gtk_source_completion_get_view)

  /** Gets the SourceView associated with completion.
   *
   * @return The SourceView associated with completion.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(const SourceView* get_view() const, gtk_source_completion_get_view, constversion)

  // TODO: Does "The reference being returned is a 'floating' reference, so if you invoke gtk_source_completion_show with this context you don't need to unref it." something mean for us? krnowak
#m4 _CONVERSION(`const Gtk::TextIter&',`GtkTextIter*',`const_cast<GtkTextIter*>(($3).gobj())')
  /** Create a new SourceCompletionContext for completion.
   *
   * The position at which the completion using the new context will consider
   * completion can be provided by @a position.
   *
   * @param position A Gtk::TextIter.
   *
   * @return A new SourceCompletionContext.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(Glib::RefPtr<SourceCompletionContext> create_context(const Gtk::TextIter& position), gtk_source_completion_create_context)

  // TODO: better wording could be used here - it is too convoluted. krnowak
  /** Create a new SourceCompletionContext for completion.
   *
   * The position at which the completion using the new context will consider
   * completion is current cursor position.
   *
   * @return A new SourceCompletionContext.
   *
   * @newin{2,10}
   */
  Glib::RefPtr<SourceCompletionContext> create_context();

  /** Move the completion window to a specific iter.
   *
   * @param iter A Gtk::TextIter.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(void move_window(const Gtk::TextIter& iter), gtk_source_completion_move_window)

  /** Block interactive completion.
   *
   * This can be used to disable interactive completion when inserting or
   * deleting text from the buffer associated with the completion. Use
   * unblock_interactive() to enable interactive completion again.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(void block_interactive(), gtk_source_completion_block_interactive)

  /** Unblock interactive completion.
   *
   * This can be used after using block_interactive() to enable interactive
   * completion again.
   *
   * @newin{2,10}
   */
  _WRAP_METHOD(void unblock_interactive(), gtk_source_completion_unblock_interactive)

  /** Emitted when the completion window is hidden.
   *
   * The default handler will actually hide the window.
   *
   * @newin{2,10}
   */
  _WRAP_SIGNAL(void hide(), "hide")

#m4 _CONVERSION(`GtkSourceCompletionContext*', `const Glib::RefPtr<SourceCompletionContext>&', `Glib::wrap($3, true)')
  /** Emitted just before starting to populate the completion with providers.
   *
   * You can use this signal to add additional attributes in the context.
   *
   * @par Handler parameters:
   * context The context for current completion.
   *
   * @newin{2,10}
   */
  _WRAP_SIGNAL(void populate_context(const Glib::RefPtr<SourceCompletionContext>& context), "populate-context")
#m4 _CONVERSION(`GtkSourceCompletionContext*', `const Glib::RefPtr<SourceCompletionContext>&', `Glib::wrap($3)')
  /** Emitted when the completion window is shown.
   *
   * The default handler will actually show the window.
   *
   * @newin{2,10}
   */
  _WRAP_SIGNAL(void show(), "show")
// those are keybinding signals, so ignore them
  _IGNORE_SIGNAL(activate-proposal)
  _IGNORE_SIGNAL(move-cursor)
  _IGNORE_SIGNAL(move-page)

  _WRAP_PROPERTY("accelerators", guint)
  _WRAP_PROPERTY("auto-complete-delay", guint)
  _WRAP_PROPERTY("proposal-page-size", guint)
  _WRAP_PROPERTY("provider-page-size", guint)
  _WRAP_PROPERTY("remember-info-visibility", bool)
  _WRAP_PROPERTY("select-on-show", bool)
  _WRAP_PROPERTY("show-headers", bool)
  _WRAP_PROPERTY("show-icons", bool)
  _WRAP_PROPERTY("view", SourceView*)
};

} /* namespace gtksourceview */

