summaryrefslogtreecommitdiffstats
path: root/app/gtk_signal.h
blob: e56c75dbc6666645bcf0087879fd621ac35204c6 (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
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef APP_GTK_SIGNAL_H_
#define APP_GTK_SIGNAL_H_

typedef void* gpointer;
typedef struct _GtkWidget GtkWidget;

// At the time of writing this, there were two common ways of binding our C++
// code to the gobject C system. We either defined a whole bunch of "static
// MethodThunk()" which just called nonstatic Method()s on a class (which hurt
// readability of the headers and signal connection code) OR we declared
// "static Method()" and passed in the current object as the gpointer (and hurt
// readability in the implementation by having "context->" before every
// variable).

// The hopeful result of using these macros is that the code will be more
// readable and regular. There shouldn't be a bunch of static Thunks visible in
// the headers and the implementations shouldn't be filled with "context->"
// de-references.

#define CHROMEGTK_CALLBACK_0(TYPE, RETURN, METHOD)                      \
  static RETURN METHOD ## Thunk(GtkWidget* widget, gpointer userdata) { \
    return reinterpret_cast<TYPE*>(userdata)->METHOD(widget);           \
  }                                                                     \
                                                                        \
  RETURN METHOD(GtkWidget* widget);

#define CHROMEGTK_CALLBACK_1(TYPE, RETURN, METHOD, ARG1)            \
  static RETURN METHOD ## Thunk(GtkWidget* widget, ARG1 one,        \
                                gpointer userdata) {                \
    return reinterpret_cast<TYPE*>(userdata)->METHOD(widget, one);  \
  }                                                                 \
                                                                    \
  RETURN METHOD(GtkWidget* widget, ARG1 one);

#define CHROMEGTK_CALLBACK_2(TYPE, RETURN, METHOD, ARG1, ARG2)          \
  static RETURN METHOD ## Thunk(GtkWidget* widget, ARG1 one, ARG2 two,  \
                                gpointer userdata) {                    \
    return reinterpret_cast<TYPE*>(userdata)->METHOD(widget, one, two); \
  }                                                                     \
                                                                        \
  RETURN METHOD(GtkWidget* widget, ARG1 one, ARG2 two);

#define CHROMEGTK_CALLBACK_3(TYPE, RETURN, METHOD, ARG1, ARG2, ARG3)    \
  static RETURN METHOD ## Thunk(GtkWidget* widget, ARG1 one, ARG2 two,  \
                                ARG3 three, gpointer userdata) {        \
    return reinterpret_cast<TYPE*>(userdata)->                          \
        METHOD(widget, one, two, three);                                \
  }                                                                     \
                                                                        \
  RETURN METHOD(GtkWidget* widget, ARG1 one, ARG2 two, ARG3 three);

#define CHROMEGTK_CALLBACK_4(TYPE, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4) \
  static RETURN METHOD ## Thunk(GtkWidget* widget, ARG1 one, ARG2 two,  \
                                ARG3 three, ARG4 four,                  \
                                gpointer userdata) {                    \
    return reinterpret_cast<TYPE*>(userdata)->                          \
        METHOD(widget, one, two, three, four);                          \
  }                                                                     \
                                                                        \
  RETURN METHOD(GtkWidget* widget, ARG1 one, ARG2 two, ARG3 three,      \
                ARG4 four);

#define CHROMEGTK_CALLBACK_5(TYPE, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4, \
                             ARG5)                                      \
  static RETURN METHOD ## Thunk(GtkWidget* widget, ARG1 one, ARG2 two,  \
                                ARG3 three, ARG4 four, ARG5 five,       \
                                gpointer userdata) {                    \
    return reinterpret_cast<TYPE*>(userdata)->                          \
        METHOD(widget, one, two, three, four, five);                    \
  }                                                                     \
                                                                        \
  RETURN METHOD(GtkWidget* widget, ARG1 one, ARG2 two, ARG3 three,      \
                ARG4 four, ARG5 five);

#define CHROMEGTK_CALLBACK_6(TYPE, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4, \
                             ARG5, ARG6)                                \
  static RETURN METHOD ## Thunk(GtkWidget* widget, ARG1 one, ARG2 two,  \
                                ARG3 three, ARG4 four, ARG5 five,       \
                                ARG6 six, gpointer userdata) {          \
    return reinterpret_cast<TYPE*>(userdata)->                          \
        METHOD(widget, one, two, three, four, five, six);               \
  }                                                                     \
                                                                        \
  RETURN METHOD(GtkWidget* widget, ARG1 one, ARG2 two, ARG3 three,      \
                ARG4 four, ARG5 five, ARG6 six);

#endif  // APP_GTK_SIGNAL_H_