summaryrefslogtreecommitdiffstats
path: root/src/ui/view/view.h
blob: 3e3545a101bccd503181dbccf62028996f329edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef INKSCAPE_UI_VIEW_VIEW_H
#define INKSCAPE_UI_VIEW_VIEW_H
/*
 * Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   Ralf Stephan <ralf@ark.in-berlin.de>
 *
 * Copyright (C) 2001-2002 Lauris Kaplinski
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <gdk/gdk.h>
#include <cstddef>
#include <memory>
#include <sigc++/connection.h>
#include "message.h"
#include "inkgc/gc-managed.h"
#include "gc-finalized.h"
#include "gc-anchored.h"
#include <2geom/forward.h>

/**
 * Iterates until true or returns false.
 * When used as signal accumulator, stops emission if one slot returns true.
 */
struct StopOnTrue {
  typedef bool result_type;

  template<typename T_iterator>
  result_type operator()(T_iterator first, T_iterator last) const{
      for (; first != last; ++first)
          if (*first) return true;
      return false;
  }
};

/**
 * Iterates until nonzero or returns 0.
 * When used as signal accumulator, stops emission if one slot returns nonzero.
 */
struct StopOnNonZero {
  typedef int result_type;

  template<typename T_iterator>
  result_type operator()(T_iterator first, T_iterator last) const{
      for (; first != last; ++first)
          if (*first) return *first;
      return 0;
  }
};

class SPDocument;

namespace Inkscape {
    class MessageContext;
    class MessageStack;
    namespace UI {
        namespace View {

/**
 * View is an abstract base class of all UI document views.  This
 * includes both the editing window and the SVG preview, but does not
 * include the non-UI RGBA buffer-based Inkscape::Drawing nor the XML editor or
 * similar views.  The View base class has very little functionality of
 * its own.
 */
class View : public GC::Managed<>,
             public GC::Finalized,
             public GC::Anchored
{
public:

    View();

    /**
     * Deletes and nulls all View message stacks and disconnects it from signals.
     */
    ~View() override;

    void close() { _close(); }

    /// Returns a pointer to the view's document.
    SPDocument *doc() const
      { return _doc; }
    /// Returns a pointer to the view's message stack.
    std::shared_ptr<Inkscape::MessageStack> messageStack() const
      { return _message_stack; }
    /// Returns a pointer to the view's tipsMessageContext.
    Inkscape::MessageContext *tipsMessageContext() const
      { return _tips_message_context.get(); }

    void emitResized(gdouble width, gdouble height);
    void requestRedraw();

    virtual void onResized (double, double) {};
    virtual void onRedrawRequested() {};
    virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message) {};
    virtual void onDocumentFilenameSet (gchar const* filename) {};

protected:
    SPDocument *_doc;
    std::shared_ptr<Inkscape::MessageStack> _message_stack;
    std::unique_ptr<Inkscape::MessageContext> _tips_message_context;

    virtual void _close();

    /**
     * Disconnects the view from the document signals, connects the view 
     * to a new one, and emits the _document_set_signal on the view.
     *
     * This is code common to all subclasses and called from their
     * setDocument() methods after they are done.
     * 
     * @param doc The new document to connect the view to.
     */
    virtual void setDocument(SPDocument *doc);

    sigc::signal<void,double,double>   _resized_signal;
    sigc::signal<void,gchar const*>    _document_filename_set_signal;
    sigc::signal<void>                 _redraw_requested_signal;

private:
    sigc::connection _resized_connection;
    sigc::connection _redraw_requested_connection;
    sigc::connection _message_changed_connection;  // foreign
    sigc::connection _document_uri_set_connection; // foreign
};

}}}

#endif  // INKSCAPE_UI_VIEW_VIEW_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :