summaryrefslogtreecommitdiff
path: root/iup/test/mdi.c
blob: e483ba889297de01283836fc1361f09009780958 (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
146
147
148
149
150
#include <stdlib.h>
#include <stdio.h>
#include <iup.h>


static int mdi_tilehoriz(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "TILEHORIZONTAL");
  return IUP_DEFAULT;
}

static int mdi_tilevert(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "TILEVERTICAL");
  return IUP_DEFAULT;
}

static int mdi_cascade(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "CASCADE");
  return IUP_DEFAULT;
}

static int mdi_icon(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "ICON");
  return IUP_DEFAULT;
}

static int mdi_next(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDIACTIVATE", "NEXT");
  return IUP_DEFAULT;
}

static int mdi_previous(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDIACTIVATE", "PREVIOUS");
  return IUP_DEFAULT;
}

static int mdi_closeall(Ihandle* ih)
{
  IupSetAttribute(IupGetDialog(ih), "MDICLOSEALL", NULL);
  return IUP_DEFAULT;
}

static int mdi_activate(Ihandle* ih)
{
  printf("mdi_activate(%s)\n", IupGetName(ih));
  return IUP_DEFAULT;
}

static int mdi_new(Ihandle* ih)
{
  static int id = 0;
  Ihandle *box, *cnv, *dlg;

  cnv = IupCanvas(NULL);
  IupSetAttribute(cnv,"BGCOLOR","128 255 0");

  box = IupVbox(cnv, NULL);
  IupSetAttribute(box,"MARGIN","5x5");

  dlg = IupDialog(box);
  IupSetfAttribute(dlg,"TITLE","MDI Child (%d)", id); id++;
  IupSetAttribute(dlg,"MDICHILD","YES");
  IupSetAttribute(dlg,"PARENTDIALOG","mdiFrame");
  IupSetCallback(dlg,"MDIACTIVATE_CB",(Icallback)mdi_activate);
  IupSetAttribute(dlg,"RASTERSIZE","300x300");
//  IupSetAttribute(dlg, "PLACEMENT", "MAXIMIZED");

  IupShow(dlg);

  return IUP_DEFAULT;
}

static void createMenu(void)
{
  Ihandle* winmenu;
  Ihandle* mnu = IupMenu(
  IupSubmenu("MDI",IupMenu(
      IupItem("New", "mdi_new"), 
      NULL)),
  IupSubmenu("Window", winmenu = IupMenu(
      IupItem("Tile Horizontal", "mdi_tilehoriz"), 
      IupItem("Tile Vertical", "mdi_tilevert"), 
      IupItem("Cascade", "mdi_cascade"), 
      IupItem("Icon Arrange", "mdi_icon"), 
      IupItem("Close All", "mdi_closeall"), 
      IupSeparator(),
      IupItem("Next", "mdi_next"), 
      IupItem("Previous", "mdi_previous"), 
      NULL)),
    NULL);
  IupSetHandle("mnu",mnu);
  IupSetHandle("mdiMenu",winmenu);

  IupSetFunction("mdi_new", (Icallback)mdi_new);
  IupSetFunction("mdi_tilehoriz", (Icallback)mdi_tilehoriz);
  IupSetFunction("mdi_tilevert", (Icallback)mdi_tilevert);
  IupSetFunction("mdi_cascade", (Icallback)mdi_cascade);
  IupSetFunction("mdi_icon", (Icallback)mdi_icon);
  IupSetFunction("mdi_next", (Icallback)mdi_next);
  IupSetFunction("mdi_previous", (Icallback)mdi_previous);
  IupSetFunction("mdi_closeall", (Icallback)mdi_closeall);
}

static Ihandle* createFrame(void)
{
  Ihandle *dlg, *cnv;
  cnv = IupCanvas( NULL);
  IupSetAttribute(cnv,"MDICLIENT","YES");
  IupSetAttribute(cnv,"MDIMENU","mdiMenu");

  dlg = IupDialog(cnv);
  IupSetAttribute(dlg,"TITLE","MDI Frame");
  IupSetAttribute(dlg,"MDIFRAME","YES");
  IupSetAttribute(dlg,"RASTERSIZE","800x600");
  IupSetAttribute(dlg,"MENU","mnu");
  IupSetHandle("mdiFrame", dlg);

  return dlg;
}

void MdiTest(void)
{
  Ihandle* dlg;

  createMenu();

  dlg = createFrame();
//  IupSetAttribute(dlg, "PLACEMENT", "MAXIMIZED");
  IupShow(dlg);
}

#ifndef BIG_TEST
int main(int argc, char* argv[])
{
  IupOpen(&argc, &argv);

  MdiTest();

  IupMainLoop();

  IupClose();

  return EXIT_SUCCESS;
}
#endif