Another take on menu's. This uses the hosting menu scroll view container as a menuba...
[chromium-blink-merge.git] / app / gtk_signal.h
blob5d3defeb886c16456891f094e4c8d7e804af0ed1
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef APP_GTK_SIGNAL_H_
6 #define APP_GTK_SIGNAL_H_
7 #pragma once
9 typedef void* gpointer;
10 typedef struct _GtkWidget GtkWidget;
12 // At the time of writing this, there were two common ways of binding our C++
13 // code to the gobject C system. We either defined a whole bunch of "static
14 // MethodThunk()" which just called nonstatic Method()s on a class (which hurt
15 // readability of the headers and signal connection code) OR we declared
16 // "static Method()" and passed in the current object as the gpointer (and hurt
17 // readability in the implementation by having "context->" before every
18 // variable).
20 // The hopeful result of using these macros is that the code will be more
21 // readable and regular. There shouldn't be a bunch of static Thunks visible in
22 // the headers and the implementations shouldn't be filled with "context->"
23 // de-references.
25 #define CHROMEG_CALLBACK_0(CLASS, RETURN, METHOD, SENDER) \
26 static RETURN METHOD ## Thunk(SENDER sender, gpointer userdata) { \
27 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender); \
28 } \
30 virtual RETURN METHOD(SENDER);
32 #define CHROMEG_CALLBACK_1(CLASS, RETURN, METHOD, SENDER, ARG1) \
33 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, \
34 gpointer userdata) { \
35 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one); \
36 } \
38 virtual RETURN METHOD(SENDER, ARG1);
40 #define CHROMEG_CALLBACK_2(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2) \
41 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
42 gpointer userdata) { \
43 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one, two); \
44 } \
46 virtual RETURN METHOD(SENDER, ARG1, ARG2);
48 #define CHROMEG_CALLBACK_3(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3) \
49 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
50 ARG3 three, gpointer userdata) { \
51 return reinterpret_cast<CLASS*>(userdata)-> \
52 METHOD(sender, one, two, three); \
53 } \
55 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3);
57 #define CHROMEG_CALLBACK_4(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \
58 ARG4) \
59 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
60 ARG3 three, ARG4 four, \
61 gpointer userdata) { \
62 return reinterpret_cast<CLASS*>(userdata)-> \
63 METHOD(sender, one, two, three, four); \
64 } \
66 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4);
68 #define CHROMEG_CALLBACK_5(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \
69 ARG4, ARG5) \
70 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
71 ARG3 three, ARG4 four, ARG5 five, \
72 gpointer userdata) { \
73 return reinterpret_cast<CLASS*>(userdata)-> \
74 METHOD(sender, one, two, three, four, five); \
75 } \
77 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5);
79 #define CHROMEG_CALLBACK_6(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \
80 ARG4, ARG5, ARG6) \
81 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
82 ARG3 three, ARG4 four, ARG5 five, \
83 ARG6 six, gpointer userdata) { \
84 return reinterpret_cast<CLASS*>(userdata)-> \
85 METHOD(sender, one, two, three, four, five, six); \
86 } \
88 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
90 // These macros handle the common case where the sender object will be a
91 // GtkWidget*.
92 #define CHROMEGTK_CALLBACK_0(CLASS, RETURN, METHOD) \
93 CHROMEG_CALLBACK_0(CLASS, RETURN, METHOD, GtkWidget*);
95 #define CHROMEGTK_CALLBACK_1(CLASS, RETURN, METHOD, ARG1) \
96 CHROMEG_CALLBACK_1(CLASS, RETURN, METHOD, GtkWidget*, ARG1);
98 #define CHROMEGTK_CALLBACK_2(CLASS, RETURN, METHOD, ARG1, ARG2) \
99 CHROMEG_CALLBACK_2(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2);
101 #define CHROMEGTK_CALLBACK_3(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3) \
102 CHROMEG_CALLBACK_3(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3);
104 #define CHROMEGTK_CALLBACK_4(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4) \
105 CHROMEG_CALLBACK_4(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, ARG4);
107 #define CHROMEGTK_CALLBACK_5(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4, \
108 ARG5) \
109 CHROMEG_CALLBACK_5(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, \
110 ARG4, ARG5);
112 #define CHROMEGTK_CALLBACK_6(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4, \
113 ARG5, ARG6) \
114 CHROMEG_CALLBACK_6(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, \
115 ARG4, ARG5, ARG6);
117 #endif // APP_GTK_SIGNAL_H_