summaryrefslogtreecommitdiff
path: root/examples/hello.cc (plain)
blob: bcb6ba89a000266c425a00f5a2040f625c5a4903
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
/* Rapicorn Example
 * Copyright (C) 2007 Tim Janik
 *
 * This work is provided "as is"; redistribution and modification
 * in whole or in part, in any medium, physical or electronic is
 * permitted without restriction.
 *
 * This work 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.
 *
 * In no event shall the authors or contributors be liable for any
 * direct, indirect, incidental, special, exemplary, or consequential
 * damages (including, but not limited to, procurement of substitute
 * goods or services; loss of use, data, or profits; or business
 * interruption) however caused and on any theory of liability, whether
 * in contract, strict liability, or tort (including negligence or
 * otherwise) arising in any way out of the use of this software, even
 * if advised of the possibility of such damage.
 */
#include <rapicorn.hh>

namespace {
using namespace Rapicorn;

static bool
handle_commands (Window           &window,
                 const String     &command,
                 const StringList &args)
{
  if (command == "close")
    window.close();
  else
    printout ("%s(): custom command: %s(%s)\n", __func__, command.c_str(), string_join (",", args).c_str());
  return true;
}

extern "C" int
main (int   argc,
      char *argv[])
{
  /* initialize Rapicorn for X11 backend with application name */
  app.init_with_x11 (&argc, &argv, "HelloWorld");

  /* find and load GUI definitions relative to argv[0] */
  app.auto_load ("RapicornTest",        // namespace domain
                 "hello.xml",           // GUI file name
                 argv[0]);

  /* create main window */
  Window &window = *app.create_window ("main-window");

  /* connect custom callback to handle UI commands */
  window.sig_commands += handle_commands;

  /* display window on screen */
  window.show();

  /* run event loops while windows are on screen */
  app.execute_loops();

  return 0;
}

} // anon