ui/motif/window.c

Wed, 04 Dec 2024 18:31:22 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 04 Dec 2024 18:31:22 +0100
branch
newapi
changeset 406
0ebf9d7b23e8
parent 253
087cc9216f28
child 416
89ad8467c39f
permissions
-rw-r--r--

add first code of the new Motif implementation, implement buttons

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "toolkit.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "menu.h"
3
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
34 #include "toolbar.h"
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
35 #include "container.h"
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../ui/window.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "../common/context.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
39 #include "Grid.h"
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
40
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 176
diff changeset
41 #include <cx/mempool.h>
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
42
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 static int nwindows = 0;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
62
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
45 static int window_default_width = 600;
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
46 static int window_default_height = 500;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 static void window_close_handler(Widget window, void *udata, void *cdata) {
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
49 UiObject *obj = udata;
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
50 uic_object_destroy(obj);
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
51
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 nwindows--;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 if(nwindows == 0) {
36
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
54 ui_exit_mainloop();
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
58
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
59 static UiObject* create_window(const char *title, void *window_data, Boolean simple) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
60 CxMempool *mp = cxBasicMempoolCreate(256);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
61 const CxAllocator *a = mp->allocator;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
62 UiObject *obj = cxCalloc(a, 1, sizeof(UiObject));
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 176
diff changeset
63 obj->ctx = uic_context(obj, mp);
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
64 obj->window = window_data;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 Arg args[16];
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 int n = 0;
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
68 XtSetArg(args[n], XmNtitle, title); n++;
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
69 XtSetArg(args[n], XmNminWidth, 100); n++;
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
70 XtSetArg(args[n], XmNminHeight, 50); n++;
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
71 XtSetArg(args[n], XmNwidth, window_default_width); n++;
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
72 XtSetArg(args[n], XmNheight, window_default_height); n++;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 Widget toplevel = XtAppCreateShell(
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
75 ui_appname(),
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
76 "mainwindow",
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 //applicationShellWidgetClass,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 vendorShellWidgetClass,
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
79 ui_motif_get_display(),
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 args,
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
81 n);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 Atom wm_delete_window;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 wm_delete_window = XmInternAtom(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 XtDisplay(toplevel),
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 "WM_DELETE_WINDOW",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 0);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 XmAddWMProtocolCallback(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 toplevel,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 wm_delete_window,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 window_close_handler,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 obj);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 Widget window = XtVaCreateManagedWidget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 title,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 xmMainWindowWidgetClass,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 toplevel,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 NULL);
3
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
99
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
100 // content frame
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
101 n = 0;
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
102 Widget frame = XmCreateFrame(window, "window_frame", args, n);
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
103 XtManageChild(frame);
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
104
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
105 Widget vbox = XtCreateManagedWidget("window_vbox", gridClass, frame, NULL, 0);
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
106 UiContainerX *container = ui_box_container(obj, vbox, UI_BOX_VERTICAL);
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
107 uic_object_push_container(obj, container);
3
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
108
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 obj->widget = toplevel;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 nwindows++;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 return obj;
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
112 }
28
794a5c91c479 added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
113
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
114 UiObject* ui_window(const char *title, void *window_data) {
106
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
115 return create_window(title, window_data, FALSE);
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
116 }
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
117
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
118 UiObject* ui_simple_window(const char *title, void *window_data) {
106
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
119 return create_window(title, window_data, TRUE);
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
120 }

mercurial