/* Copyright (C) 2012 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include <gtkmm/applicationwindow.h>
#ifndef GTKMM_DISABLE_DEPRECATED
#include <gtkmm/shortcutswindow.h>
#endif

namespace Gtk
{
ApplicationWindow::ApplicationWindow(const Glib::RefPtr<Application>& application)
:
  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(nullptr),
  Gtk::Window(Glib::ConstructParams(applicationwindow_class_.init()))
{
  // Don't set the "application" property in ConstructParams. It would result in
  // an attempt to set two C++ wrappers on the GApplicationWindow C object,
  // if "application" is not a plain Gtk::Application, but derived from it.
  // Like so:
  // - Glib::Object::Object(const Glib::ConstructParams& construct_params) calls
  //   g_object_newv() to create a new GApplicationWindow.
  // - In gtk+, gtk_application_add_window() is called. It emits the window_added
  //   signal with the new GApplicationWindow as a parameter.
  // - Application_signal_window_added_callback() calls Glib::wrap(GWindow*)
  //   before *this has been set as the wrapper. Glib::wrap() then creates a
  //   wrapper (not *this).
  // - Glib::Object::Object() calls Glib::ObjectBase::initialize(), which calls
  //   Glib::ObjectBase::_set_current_wrapper() to set *this as the C++ wrapper,
  //   but by then another wrapper has already been set.
  // https://bugzilla.gnome.org/show_bug.cgi?id=758813

  if (application)
    application->add_window(*this);
}

_DEPRECATE_IFDEF_START
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
void ApplicationWindow::unset_help_overlay()
{
  gtk_application_window_set_help_overlay(gobj(), nullptr);
}
G_GNUC_END_IGNORE_DEPRECATIONS
_DEPRECATE_IFDEF_END

} // namespace Gtk
