//!
//! \addtogroup linuxui Linux UI
//! @{
//! 

#ifndef _MODEL_VIEW_PANEL_H_
#define _MODEL_VIEW_PANEL_H_

#include "linux_utilities/form_view_base.h"

#include <gtkmm/box.h>
#include "workbench/wb_model_diagram_form.h"
#include "gtk/mdc_gtk_canvas_view.h"
#include "gtk/mdc_gtk_canvas_scroller.h"
#include "mdc_canvas_view_x11.h"

namespace Gtk
{
  class Entry;
};

class ToolbarManager;

class ModelDiagramPanel : public Gtk::HBox, public FormViewBase
{
  class InlineEditor : public wb::InlineEditContext
  {
    ModelDiagramPanel *_owner;
    Gtk::Entry *_edit_field;
    bool _editing;
    
    virtual void begin_editing(int x, int y, int width, int height, const std::string &text);
    virtual void end_editing();

    virtual void set_font_size(float size);
    virtual void set_multiline(bool flag);

  public:
    InlineEditor(ModelDiagramPanel *owner);
  };
  
  friend class InlineEditor;
  
  Gtk::VBox _tools_toolbar;
  Gtk::HBox _options_toolbar;
  Gtk::VBox _vbox;

  wb::WBContextUI *_wb;

  wb::ModelDiagramForm *_be;
  mdc::GtkCanvasScroller _scroller;
  mdc::GtkCanvas *_canvas;
  Gdk::Cursor *_cursor;
  Gtk::Widget *_sidebar;
  InlineEditor _inline_editor;
  
  ToolbarManager *_toolbar_manager;

  bool drag_drop(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y, guint time);

  void drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y,
                          const Gtk::SelectionData &selection_data,
                          guint, guint time);

  void view_realized();
  
public:
  ModelDiagramPanel(wb::WBContextUI *wb, ToolbarManager *toolbar_manager);
  ~ModelDiagramPanel();

  void init(const std::string &view_id);
  virtual bec::UIForm *get_form() const { return _be; }
  virtual std::string get_title() { return _be->get_title(); }
  virtual Gtk::Widget *get_panel() { return this; }
  
  void set_title(const std::string &title);
  
  wb::ModelDiagramForm *get_diagram_form() const { return _be; }
  
  mdc::CanvasView *get_canvas() const { return _canvas->get_canvas(); }
  
  void update_tool_cursor();

  void update_toolbar(const std::string &toolbar);
};


#endif /* _MODEL_VIEW_PANEL_H_ */

//!                                                                                                                                     
//! @}                                                                                                                                  
//!
