Mercurial > vim
annotate src/gui_motif.c @ 30974:013f8436b0d5 v9.0.0822
patch 9.0.0822: crash when dragging the statusline with a mapping
Commit: https://github.com/vim/vim/commit/8ab9ca93eea32b318235384720200771863ecaee
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Oct 31 13:06:26 2022 +0000
patch 9.0.0822: crash when dragging the statusline with a mapping
Problem: Crash when dragging the statusline with a mapping.
Solution: Check for valid window pointer. (issue https://github.com/vim/vim/issues/11427)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 02 Nov 2022 11:18:52 +0100 |
parents | 101f08b49ed3 |
children | e5ee2ffd826a |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
7831
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * GUI/Motif support by Robert Webb | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 | |
10956
90af0c60d78d
patch 8.0.0367: types in include files may be inconsistent
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
11 #include "vim.h" |
90af0c60d78d
patch 8.0.0367: types in include files may be inconsistent
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
12 |
7 | 13 #include <Xm/Form.h> |
14 #include <Xm/RowColumn.h> | |
15 #include <Xm/PushB.h> | |
16 #include <Xm/Text.h> | |
17 #include <Xm/TextF.h> | |
18 #include <Xm/Separator.h> | |
19 #include <Xm/Label.h> | |
20 #include <Xm/CascadeB.h> | |
21 #include <Xm/ScrollBar.h> | |
22 #include <Xm/MenuShell.h> | |
23 #include <Xm/DrawingA.h> | |
24 #if (XmVersion >= 1002) | |
25 # include <Xm/RepType.h> | |
26 #endif | |
27 #include <Xm/Frame.h> | |
28 #include <Xm/LabelG.h> | |
29 #include <Xm/ToggleBG.h> | |
30 #include <Xm/SeparatoG.h> | |
824 | 31 #include <Xm/XmP.h> |
7 | 32 |
33 #include <X11/keysym.h> | |
34 #include <X11/Xatom.h> | |
35 #include <X11/StringDefs.h> | |
36 #include <X11/Intrinsic.h> | |
37 #ifdef HAVE_X11_XPM_H | |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
38 # if defined(VMS) |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
39 # include <xpm.h> |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
40 # else |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
41 # include <X11/xpm.h> |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
42 # endif |
7 | 43 #else |
44 # ifdef HAVE_XM_XPMP_H | |
45 # include <Xm/XpmP.h> | |
46 # endif | |
47 #endif | |
838 | 48 #ifdef HAVE_XM_NOTEBOOK_H |
49 # include <Xm/Notebook.h> | |
50 #endif | |
7 | 51 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
52 #include "gui_xmebw.h" // for our Enhanced Button Widget |
48 | 53 |
7 | 54 #if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM) |
55 # include "../pixmaps/alert.xpm" | |
56 # include "../pixmaps/error.xpm" | |
57 # include "../pixmaps/generic.xpm" | |
58 # include "../pixmaps/info.xpm" | |
59 # include "../pixmaps/quest.xpm" | |
60 #endif | |
61 | |
62 #define MOTIF_POPUP | |
63 | |
64 extern Widget vimShell; | |
65 | |
66 static Widget vimForm; | |
67 static Widget textAreaForm; | |
68 Widget textArea; | |
69 #ifdef FEAT_TOOLBAR | |
70 static Widget toolBarFrame; | |
71 static Widget toolBar; | |
72 #endif | |
819 | 73 #ifdef FEAT_GUI_TABLINE |
74 static Widget tabLine; | |
75 static Widget tabLine_menu = 0; | |
76 static int showing_tabline = 0; | |
77 #endif | |
7 | 78 #ifdef FEAT_MENU |
79 # if (XmVersion >= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
80 // remember the last set value for the tearoff item |
7 | 81 static int tearoff_val = (int)XmTEAR_OFF_ENABLED; |
82 # endif | |
83 static Widget menuBar; | |
84 #endif | |
85 | |
86 #ifdef FEAT_TOOLBAR | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
87 static void reset_focus(void); |
7 | 88 #endif |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
90 static void gui_motif_menu_colors(Widget id); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
91 static void gui_motif_scroll_colors(Widget id); |
7 | 92 |
93 #if (XmVersion >= 1002) | |
94 # define STRING_TAG XmFONTLIST_DEFAULT_TAG | |
95 #else | |
96 # define STRING_TAG XmSTRING_DEFAULT_CHARSET | |
97 #endif | |
98 | |
99 /* | |
100 * Call-back routines. | |
101 */ | |
102 | |
103 static void | |
7831
d621ab23fd19
commit https://github.com/vim/vim/commit/c1ab67674aa0dfdcf9f0e9701ac248e3eb41b19c
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
104 scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data) |
7 | 105 { |
106 scrollbar_T *sb; | |
107 long value; | |
108 int dragging; | |
109 | |
110 sb = gui_find_scrollbar((long)client_data); | |
111 | |
112 value = ((XmScrollBarCallbackStruct *)call_data)->value; | |
113 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason == | |
114 (int)XmCR_DRAG); | |
115 gui_drag_scrollbar(sb, value, dragging); | |
116 } | |
117 | |
819 | 118 #ifdef FEAT_GUI_TABLINE |
119 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
120 tabline_cb( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
121 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
122 XtPointer client_data UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
123 XtPointer call_data) |
819 | 124 { |
125 XmNotebookCallbackStruct *nptr; | |
126 | |
127 nptr = (XmNotebookCallbackStruct *)call_data; | |
128 if (nptr->reason != (int)XmCR_NONE) | |
129 send_tabline_event(nptr->page_number); | |
130 } | |
131 | |
132 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
133 tabline_button_cb( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
134 Widget w, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
135 XtPointer client_data UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
136 XtPointer call_data UNUSED) |
819 | 137 { |
28191
e4ca5a390f48
patch 8.2.4621: crash when using the tabline right-click menu
Bram Moolenaar <Bram@vim.org>
parents:
28067
diff
changeset
|
138 XtPointer cmd, tab_idx; |
819 | 139 |
140 XtVaGetValues(w, XmNuserData, &cmd, NULL); | |
141 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL); | |
142 | |
28191
e4ca5a390f48
patch 8.2.4621: crash when using the tabline right-click menu
Bram Moolenaar <Bram@vim.org>
parents:
28067
diff
changeset
|
143 send_tabline_menu_event((int)(long)tab_idx, (int)(long)cmd); |
824 | 144 } |
145 | |
146 /* | |
147 * Tabline single mouse click timeout handler | |
148 */ | |
149 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
150 motif_tabline_timer_cb ( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
151 XtPointer timed_out, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
152 XtIntervalId *interval_id UNUSED) |
824 | 153 { |
154 *((int *)timed_out) = TRUE; | |
155 } | |
156 | |
157 /* | |
158 * check if the tabline tab scroller is clicked | |
159 */ | |
160 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
161 tabline_scroller_clicked( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
162 char *scroller_name, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
163 XButtonPressedEvent *event) |
824 | 164 { |
165 Widget tab_scroll_w; | |
166 Position pos_x, pos_y; | |
167 Dimension width, height; | |
168 | |
169 tab_scroll_w = XtNameToWidget(tabLine, scroller_name); | |
170 if (tab_scroll_w != (Widget)0) { | |
171 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth, | |
172 &width, XmNheight, &height, NULL); | |
173 if (pos_x >= 0) { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
174 // Tab scroller (next) is visible |
824 | 175 if ((event->x >= pos_x) && (event->x <= pos_x + width) && |
176 (event->y >= pos_y) && (event->y <= pos_y + height)) { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
177 // Clicked on the scroller |
824 | 178 return TRUE; |
179 } | |
180 } | |
181 } | |
182 return FALSE; | |
819 | 183 } |
184 | |
185 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
186 tabline_menu_cb( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
187 Widget w, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
188 XtPointer closure UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
189 XEvent *e, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
190 Boolean *continue_dispatch UNUSED) |
819 | 191 { |
192 Widget tab_w; | |
193 XButtonPressedEvent *event; | |
194 int tab_idx = 0; | |
195 WidgetList children; | |
196 Cardinal numChildren; | |
824 | 197 static XtIntervalId timer = (XtIntervalId)0; |
198 static int timed_out = TRUE; | |
819 | 199 |
200 event = (XButtonPressedEvent *)e; | |
201 | |
824 | 202 if (event->button == Button1) |
203 { | |
204 if (tabline_scroller_clicked("MajorTabScrollerNext", event) | |
205 || tabline_scroller_clicked("MajorTabScrollerPrevious", event)) | |
206 return; | |
207 | |
208 if (!timed_out) | |
209 { | |
210 XtRemoveTimeOut(timer); | |
211 timed_out = TRUE; | |
212 | |
213 /* | |
214 * Double click on the tabline gutter, add a new tab | |
215 */ | |
216 send_tabline_menu_event(0, TABLINE_MENU_NEW); | |
217 } | |
218 else | |
219 { | |
220 /* | |
221 * Single click on the tabline gutter, start a timer to check | |
222 * for double clicks | |
223 */ | |
224 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset, | |
225 motif_tabline_timer_cb, &timed_out); | |
226 timed_out = FALSE; | |
227 } | |
228 return; | |
229 } | |
230 | |
30645
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
231 if (event->button == Button2) |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
232 { |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
233 // Middle mouse click on tabpage label closes that tab. |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
234 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL); |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
235 send_tabline_menu_event(tab_idx, (int)TABLINE_MENU_CLOSE); |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
236 return; |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
237 } |
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
238 |
819 | 239 if (event->button != Button3) |
240 return; | |
241 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
242 // When ignoring events don't show the menu. |
30645
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30075
diff
changeset
|
243 if (hold_gui_events || cmdwin_type != 0) |
844 | 244 return; |
245 | |
819 | 246 if (event->subwindow != None) |
247 { | |
248 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
249 // LINTED: avoid warning: dubious operation on enum |
819 | 250 if (tab_w != (Widget)0 && XmIsPushButton(tab_w)) |
251 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL); | |
252 } | |
253 | |
28191
e4ca5a390f48
patch 8.2.4621: crash when using the tabline right-click menu
Bram Moolenaar <Bram@vim.org>
parents:
28067
diff
changeset
|
254 XtVaSetValues(tabLine_menu, XmNuserData, (XtPointer)(long)tab_idx, NULL); |
819 | 255 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren, |
256 &numChildren, NULL); | |
257 XtManageChildren(children, numChildren); | |
258 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ; | |
259 XtManageChild(tabLine_menu); | |
260 } | |
844 | 261 |
262 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
263 tabline_balloon_cb(BalloonEval *beval, int state UNUSED) |
844 | 264 { |
265 int nr; | |
266 tabpage_T *tp; | |
267 | |
268 if (beval->target == (Widget)0) | |
269 return; | |
270 | |
271 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL); | |
272 tp = find_tabpage(nr); | |
273 if (tp == NULL) | |
274 return; | |
275 | |
276 get_tabline_label(tp, TRUE); | |
277 gui_mch_post_balloon(beval, NameBuff); | |
278 } | |
279 | |
819 | 280 #endif |
281 | |
7 | 282 /* |
283 * End of call-back routines | |
284 */ | |
285 | |
44 | 286 /* |
287 * Implement three dimensional shading of insensitive labels. | |
66 | 288 * By Marcin Dalecki. |
44 | 289 */ |
290 | |
291 #include <Xm/XmP.h> | |
292 #include <Xm/LabelP.h> | |
293 | |
294 static XtExposeProc old_label_expose = NULL; | |
295 | |
296 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
297 label_expose(Widget _w, XEvent *_event, Region _region) |
44 | 298 { |
299 GC insensitiveGC; | |
300 XmLabelWidget lw = (XmLabelWidget)_w; | |
48 | 301 unsigned char label_type = (int)XmSTRING; |
44 | 302 |
303 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0); | |
304 | |
48 | 305 if (XtIsSensitive(_w) || label_type != (int)XmSTRING) |
44 | 306 (*old_label_expose)(_w, _event, _region); |
307 else | |
308 { | |
309 XGCValues values; | |
310 XtGCMask mask; | |
311 XtGCMask dynamic; | |
312 XFontStruct *fs; | |
313 | |
314 _XmFontListGetDefaultFont(lw->label.font, &fs); | |
315 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
316 // FIXME: we should be doing the whole drawing ourself here. |
44 | 317 insensitiveGC = lw->label.insensitive_GC; |
318 | |
319 mask = GCForeground | GCBackground | GCGraphicsExposures; | |
320 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin; | |
321 values.graphics_exposures = False; | |
322 | |
323 if (fs != 0) | |
324 { | |
325 mask |= GCFont; | |
326 values.font = fs->fid; | |
327 } | |
328 | |
329 if (lw->primitive.top_shadow_pixmap != None | |
330 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP) | |
331 { | |
332 mask |= GCFillStyle | GCTile; | |
333 values.fill_style = FillTiled; | |
334 values.tile = lw->primitive.top_shadow_pixmap; | |
335 } | |
336 | |
337 lw->label.TextRect.x += 1; | |
338 lw->label.TextRect.y += 1; | |
339 if (lw->label._acc_text != 0) | |
340 { | |
341 lw->label.acc_TextRect.x += 1; | |
342 lw->label.acc_TextRect.y += 1; | |
343 } | |
344 | |
345 values.foreground = lw->primitive.top_shadow_color; | |
346 values.background = lw->core.background_pixel; | |
347 | |
48 | 348 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask, |
349 &values, dynamic, (XtGCMask)0); | |
44 | 350 (*old_label_expose)(_w, _event, _region); |
351 XtReleaseGC(_w, lw->label.insensitive_GC); | |
352 | |
353 lw->label.TextRect.x -= 1; | |
354 lw->label.TextRect.y -= 1; | |
355 if (lw->label._acc_text != 0) | |
356 { | |
357 lw->label.acc_TextRect.x -= 1; | |
358 lw->label.acc_TextRect.y -= 1; | |
359 } | |
360 | |
361 values.foreground = lw->primitive.bottom_shadow_color; | |
362 values.background = lw->core.background_pixel; | |
363 | |
48 | 364 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask, |
365 &values, dynamic, (XtGCMask)0); | |
44 | 366 (*old_label_expose)(_w, _event, _region); |
367 XtReleaseGC(_w, lw->label.insensitive_GC); | |
368 | |
369 lw->label.insensitive_GC = insensitiveGC; | |
370 } | |
371 } | |
372 | |
7 | 373 /* |
374 * Create all the motif widgets necessary. | |
375 */ | |
376 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
377 gui_x11_create_widgets(void) |
7 | 378 { |
819 | 379 #ifdef FEAT_GUI_TABLINE |
827 | 380 Widget button, scroller; |
819 | 381 Arg args[10]; |
382 int n; | |
383 XmString xms; | |
384 #endif | |
385 | |
44 | 386 /* |
387 * Install the 3D shade effect drawing routines. | |
388 */ | |
389 if (old_label_expose == NULL) | |
390 { | |
391 old_label_expose = xmLabelWidgetClass->core_class.expose; | |
392 xmLabelWidgetClass->core_class.expose = label_expose; | |
393 } | |
394 | |
7 | 395 /* |
396 * Start out by adding the configured border width into the border offset | |
397 */ | |
398 gui.border_offset = gui.border_width; | |
399 | |
400 /* | |
401 * Install the tearOffModel resource converter. | |
402 */ | |
403 #if (XmVersion >= 1002) | |
404 XmRepTypeInstallTearOffModelConverter(); | |
405 #endif | |
406 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
407 // Make sure the "Quit" menu entry of the window manager is ignored |
7 | 408 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL); |
409 | |
410 vimForm = XtVaCreateManagedWidget("vimForm", | |
411 xmFormWidgetClass, vimShell, | |
412 XmNborderWidth, 0, | |
413 XmNhighlightThickness, 0, | |
414 XmNshadowThickness, 0, | |
415 XmNmarginWidth, 0, | |
416 XmNmarginHeight, 0, | |
417 XmNresizePolicy, XmRESIZE_ANY, | |
418 NULL); | |
419 gui_motif_menu_colors(vimForm); | |
420 | |
421 #ifdef FEAT_MENU | |
422 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
423 Arg al[7]; // Make sure there is enough room for arguments! |
7 | 424 int ac = 0; |
425 | |
426 # if (XmVersion >= 1002) | |
427 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++; | |
428 # endif | |
429 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++; | |
430 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++; | |
431 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
432 # ifndef FEAT_TOOLBAR | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
433 // Always stick to right hand side. |
7 | 434 XtSetArg(al[ac], XmNrightOffset, 0); ac++; |
435 # endif | |
48 | 436 XtSetArg(al[ac], XmNmarginHeight, 0); ac++; |
7 | 437 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac); |
438 XtManageChild(menuBar); | |
439 | |
440 gui_motif_menu_colors(menuBar); | |
441 } | |
442 #endif | |
443 | |
444 #ifdef FEAT_TOOLBAR | |
445 /* | |
446 * Create an empty ToolBar. We should get buttons defined from menu.vim. | |
447 */ | |
448 toolBarFrame = XtVaCreateWidget("toolBarFrame", | |
449 xmFrameWidgetClass, vimForm, | |
450 XmNshadowThickness, 0, | |
451 XmNmarginHeight, 0, | |
452 XmNmarginWidth, 0, | |
453 XmNleftAttachment, XmATTACH_FORM, | |
454 XmNrightAttachment, XmATTACH_FORM, | |
455 NULL); | |
456 gui_motif_menu_colors(toolBarFrame); | |
457 | |
458 toolBar = XtVaCreateManagedWidget("toolBar", | |
459 xmRowColumnWidgetClass, toolBarFrame, | |
460 XmNchildType, XmFRAME_WORKAREA_CHILD, | |
461 XmNrowColumnType, XmWORK_AREA, | |
462 XmNorientation, XmHORIZONTAL, | |
463 XmNtraversalOn, False, | |
464 XmNisHomogeneous, False, | |
465 XmNpacking, XmPACK_TIGHT, | |
466 XmNspacing, 0, | |
467 XmNshadowThickness, 0, | |
468 XmNhighlightThickness, 0, | |
469 XmNmarginHeight, 0, | |
470 XmNmarginWidth, 0, | |
471 XmNadjustLast, True, | |
472 NULL); | |
473 gui_motif_menu_colors(toolBar); | |
474 | |
475 #endif | |
476 | |
819 | 477 #ifdef FEAT_GUI_TABLINE |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
478 // Create the Vim GUI tabline |
819 | 479 n = 0; |
480 XtSetArg(args[n], XmNbindingType, XmNONE); n++; | |
481 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; | |
482 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++; | |
483 XtSetArg(args[n], XmNbackPageNumber, 0); n++; | |
484 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++; | |
485 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++; | |
486 XtSetArg(args[n], XmNshadowThickness, 0); n++; | |
487 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; | |
488 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; | |
489 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n); | |
490 | |
491 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb, | |
492 NULL); | |
493 XtAddEventHandler(tabLine, ButtonPressMask, False, | |
494 (XtEventHandler)tabline_menu_cb, NULL); | |
495 | |
843 | 496 gui.tabline_height = TABLINE_HEIGHT; |
497 | |
827 | 498 /* |
499 * Set the size of the minor next/prev scrollers to zero, so | |
500 * that they are not displayed. Due to a bug in OpenMotif 2.3, | |
501 * even if these children widget are unmanaged, they are again | |
502 * managed by the Notebook widget and the notebook widget geometry | |
503 * is adjusted to account for the minor scroller widgets. | |
504 */ | |
505 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext"); | |
506 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False, | |
507 XmNtraversalOn, False, NULL); | |
508 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious"); | |
509 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False, | |
510 XmNtraversalOn, False, NULL); | |
511 | |
15134
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
512 // Create the tabline popup menu |
819 | 513 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0); |
514 | |
15134
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
515 // Add the buttons to the tabline popup menu |
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
516 n = 0; |
28191
e4ca5a390f48
patch 8.2.4621: crash when using the tabline right-click menu
Bram Moolenaar <Bram@vim.org>
parents:
28067
diff
changeset
|
517 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_CLOSE); n++; |
15134
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
518 xms = XmStringCreate((char *)"Close tab", STRING_TAG); |
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
519 XtSetArg(args[n], XmNlabelString, xms); n++; |
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
520 button = XmCreatePushButton(tabLine_menu, "Close", args, n); |
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
521 XtAddCallback(button, XmNactivateCallback, |
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
522 (XtCallbackProc)tabline_button_cb, NULL); |
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
523 XmStringFree(xms); |
819 | 524 |
525 n = 0; | |
28191
e4ca5a390f48
patch 8.2.4621: crash when using the tabline right-click menu
Bram Moolenaar <Bram@vim.org>
parents:
28067
diff
changeset
|
526 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_NEW); n++; |
819 | 527 xms = XmStringCreate((char *)"New Tab", STRING_TAG); |
528 XtSetArg(args[n], XmNlabelString, xms); n++; | |
529 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n); | |
530 XtAddCallback(button, XmNactivateCallback, | |
531 (XtCallbackProc)tabline_button_cb, NULL); | |
532 XmStringFree(xms); | |
533 | |
534 n = 0; | |
28191
e4ca5a390f48
patch 8.2.4621: crash when using the tabline right-click menu
Bram Moolenaar <Bram@vim.org>
parents:
28067
diff
changeset
|
535 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_OPEN); n++; |
819 | 536 xms = XmStringCreate((char *)"Open tab...", STRING_TAG); |
537 XtSetArg(args[n], XmNlabelString, xms); n++; | |
538 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n); | |
539 XtAddCallback(button, XmNactivateCallback, | |
540 (XtCallbackProc)tabline_button_cb, NULL); | |
541 XmStringFree(xms); | |
542 #endif | |
543 | |
7 | 544 textAreaForm = XtVaCreateManagedWidget("textAreaForm", |
545 xmFormWidgetClass, vimForm, | |
546 XmNleftAttachment, XmATTACH_FORM, | |
547 XmNrightAttachment, XmATTACH_FORM, | |
548 XmNbottomAttachment, XmATTACH_FORM, | |
549 XmNtopAttachment, XmATTACH_FORM, | |
550 XmNmarginWidth, 0, | |
551 XmNmarginHeight, 0, | |
552 XmNresizePolicy, XmRESIZE_ANY, | |
553 NULL); | |
554 gui_motif_scroll_colors(textAreaForm); | |
555 | |
556 textArea = XtVaCreateManagedWidget("textArea", | |
557 xmDrawingAreaWidgetClass, textAreaForm, | |
558 XmNforeground, gui.norm_pixel, | |
559 XmNbackground, gui.back_pixel, | |
560 XmNleftAttachment, XmATTACH_FORM, | |
561 XmNtopAttachment, XmATTACH_FORM, | |
562 XmNrightAttachment, XmATTACH_FORM, | |
563 XmNbottomAttachment, XmATTACH_FORM, | |
564 | |
565 /* | |
566 * These take some control away from the user, but avoids making them | |
567 * add resources to get a decent looking setup. | |
568 */ | |
569 XmNborderWidth, 0, | |
570 XmNhighlightThickness, 0, | |
571 XmNshadowThickness, 0, | |
572 NULL); | |
573 | |
574 /* | |
575 * Install the callbacks. | |
576 */ | |
577 gui_x11_callbacks(textArea, vimForm); | |
578 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
579 // Pretend we don't have input focus, we will get an event if we do. |
7 | 580 gui.in_focus = FALSE; |
581 } | |
582 | |
583 /* | |
584 * Called when the GUI is not going to start after all. | |
585 */ | |
586 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
587 gui_x11_destroy_widgets(void) |
7 | 588 { |
589 textArea = NULL; | |
590 #ifdef FEAT_MENU | |
591 menuBar = NULL; | |
592 #endif | |
593 } | |
594 | |
595 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
596 gui_mch_set_text_area_pos( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
597 int x UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
598 int y UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
599 int w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
600 int h UNUSED) |
7 | 601 { |
602 #ifdef FEAT_TOOLBAR | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
603 // Give keyboard focus to the textArea instead of the toolbar. |
54 | 604 reset_focus(); |
7 | 605 #endif |
606 } | |
607 | |
608 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
609 gui_x11_set_back_color(void) |
7 | 610 { |
611 if (textArea != NULL) | |
612 #if (XmVersion >= 1002) | |
613 XmChangeColor(textArea, gui.back_pixel); | |
614 #else | |
615 XtVaSetValues(textArea, | |
616 XmNbackground, gui.back_pixel, | |
617 NULL); | |
618 #endif | |
619 } | |
620 | |
621 /* | |
28303
9849df834f1d
patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
28247
diff
changeset
|
622 * Manage dialog centered on pointer. |
7 | 623 */ |
44 | 624 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
625 manage_centered(Widget dialog_child) |
7 | 626 { |
627 Widget shell = XtParent(dialog_child); | |
628 Window root, child; | |
629 unsigned int mask; | |
630 unsigned int width, height, border_width, depth; | |
631 int x, y, win_x, win_y, maxX, maxY; | |
632 Boolean mappedWhenManaged; | |
633 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
634 // Temporarily set value of XmNmappedWhenManaged |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
635 // to stop the dialog from popping up right away |
1604 | 636 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL); |
637 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL); | |
7 | 638 |
639 XtManageChild(dialog_child); | |
640 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
641 // Get the pointer position (x, y) |
7 | 642 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child, |
643 &x, &y, &win_x, &win_y, &mask); | |
644 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
645 // Translate the pointer position (x, y) into a position for the new |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
646 // window that will place the pointer at its center |
7 | 647 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y, |
648 &width, &height, &border_width, &depth); | |
649 width += 2 * border_width; | |
650 height += 2 * border_width; | |
651 x -= width / 2; | |
652 y -= height / 2; | |
653 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
654 // Ensure that the dialog remains on screen |
7 | 655 maxX = XtScreen(shell)->width - width; |
656 maxY = XtScreen(shell)->height - height; | |
657 if (x < 0) | |
658 x = 0; | |
659 if (x > maxX) | |
660 x = maxX; | |
661 if (y < 0) | |
662 y = 0; | |
663 if (y > maxY) | |
664 y = maxY; | |
665 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
666 // Set desired window position in the DialogShell |
7 | 667 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL); |
668 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
669 // Map the widget |
7 | 670 XtMapWidget(shell); |
671 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
672 // Restore the value of XmNmappedWhenManaged |
1604 | 673 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL); |
7 | 674 } |
675 | |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15134
diff
changeset
|
676 #if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO) |
7 | 677 |
678 /* | |
679 * Encapsulate the way an XmFontList is created. | |
680 */ | |
681 XmFontList | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
682 gui_motif_create_fontlist(XFontStruct *font) |
7 | 683 { |
684 XmFontList font_list; | |
685 | |
686 # if (XmVersion <= 1001) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
687 // Motif 1.1 method |
7 | 688 font_list = XmFontListCreate(font, STRING_TAG); |
689 # else | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
690 // Motif 1.2 method |
7 | 691 XmFontListEntry font_list_entry; |
692 | |
693 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT, | |
694 (XtPointer)font); | |
695 font_list = XmFontListAppendEntry(NULL, font_list_entry); | |
696 XmFontListEntryFree(&font_list_entry); | |
697 # endif | |
698 return font_list; | |
699 } | |
700 | |
701 # if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO) | |
702 XmFontList | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
703 gui_motif_fontset2fontlist(XFontSet *fontset) |
7 | 704 { |
705 XmFontList font_list; | |
706 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
707 // Motif 1.2 method |
7 | 708 XmFontListEntry font_list_entry; |
709 | |
710 font_list_entry = XmFontListEntryCreate(STRING_TAG, | |
711 XmFONT_IS_FONTSET, | |
712 (XtPointer)*fontset); | |
713 font_list = XmFontListAppendEntry(NULL, font_list_entry); | |
714 XmFontListEntryFree(&font_list_entry); | |
715 return font_list; | |
716 } | |
717 # endif | |
718 | |
719 #endif | |
720 | |
721 #if defined(FEAT_MENU) || defined(PROTO) | |
722 /* | |
723 * Menu stuff. | |
724 */ | |
725 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
726 static void gui_motif_add_actext(vimmenu_T *menu); |
7 | 727 #if (XmVersion >= 1002) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
728 static void toggle_tearoff(Widget wid); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
729 static void gui_mch_recurse_tearoffs(vimmenu_T *menu); |
7 | 730 #endif |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
731 static void submenu_change(vimmenu_T *mp, int colors); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
732 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
733 static void do_set_mnemonics(int enable); |
7 | 734 static int menu_enabled = TRUE; |
735 | |
736 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
737 gui_mch_enable_menu(int flag) |
7 | 738 { |
739 if (flag) | |
740 { | |
741 XtManageChild(menuBar); | |
742 #ifdef FEAT_TOOLBAR | |
743 if (XtIsManaged(XtParent(toolBar))) | |
744 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
745 // toolBar is attached to top form |
7 | 746 XtVaSetValues(XtParent(toolBar), |
747 XmNtopAttachment, XmATTACH_WIDGET, | |
748 XmNtopWidget, menuBar, | |
749 NULL); | |
819 | 750 #ifdef FEAT_GUI_TABLINE |
751 if (showing_tabline) | |
752 { | |
753 XtVaSetValues(tabLine, | |
754 XmNtopAttachment, XmATTACH_WIDGET, | |
755 XmNtopWidget, XtParent(toolBar), | |
756 NULL); | |
757 XtVaSetValues(textAreaForm, | |
758 XmNtopAttachment, XmATTACH_WIDGET, | |
759 XmNtopWidget, tabLine, | |
760 NULL); | |
761 } | |
762 else | |
763 #endif | |
764 XtVaSetValues(textAreaForm, | |
765 XmNtopAttachment, XmATTACH_WIDGET, | |
766 XmNtopWidget, XtParent(toolBar), | |
767 NULL); | |
7 | 768 } |
769 else | |
770 #endif | |
771 { | |
819 | 772 #ifdef FEAT_GUI_TABLINE |
773 if (showing_tabline) | |
774 { | |
775 XtVaSetValues(tabLine, | |
776 XmNtopAttachment, XmATTACH_WIDGET, | |
777 XmNtopWidget, menuBar, | |
778 NULL); | |
779 XtVaSetValues(textAreaForm, | |
780 XmNtopAttachment, XmATTACH_WIDGET, | |
781 XmNtopWidget, tabLine, | |
782 NULL); | |
783 } | |
784 else | |
785 #endif | |
786 XtVaSetValues(textAreaForm, | |
787 XmNtopAttachment, XmATTACH_WIDGET, | |
788 XmNtopWidget, menuBar, | |
789 NULL); | |
7 | 790 } |
791 } | |
792 else | |
793 { | |
794 XtUnmanageChild(menuBar); | |
795 #ifdef FEAT_TOOLBAR | |
796 if (XtIsManaged(XtParent(toolBar))) | |
797 { | |
798 XtVaSetValues(XtParent(toolBar), | |
799 XmNtopAttachment, XmATTACH_FORM, | |
800 NULL); | |
819 | 801 #ifdef FEAT_GUI_TABLINE |
802 if (showing_tabline) | |
803 { | |
804 XtVaSetValues(tabLine, | |
805 XmNtopAttachment, XmATTACH_WIDGET, | |
806 XmNtopWidget, XtParent(toolBar), | |
807 NULL); | |
808 XtVaSetValues(textAreaForm, | |
809 XmNtopAttachment, XmATTACH_WIDGET, | |
810 XmNtopWidget, tabLine, | |
811 NULL); | |
812 } | |
813 else | |
814 #endif | |
815 XtVaSetValues(textAreaForm, | |
816 XmNtopAttachment, XmATTACH_WIDGET, | |
817 XmNtopWidget, XtParent(toolBar), | |
818 NULL); | |
7 | 819 } |
820 else | |
821 #endif | |
822 { | |
819 | 823 #ifdef FEAT_GUI_TABLINE |
824 if (showing_tabline) | |
825 { | |
826 XtVaSetValues(tabLine, | |
827 XmNtopAttachment, XmATTACH_FORM, | |
828 NULL); | |
829 XtVaSetValues(textAreaForm, | |
830 XmNtopAttachment, XmATTACH_WIDGET, | |
831 XmNtopWidget, tabLine, | |
832 NULL); | |
833 } | |
834 else | |
835 #endif | |
836 XtVaSetValues(textAreaForm, | |
837 XmNtopAttachment, XmATTACH_FORM, | |
838 NULL); | |
7 | 839 } |
840 } | |
841 | |
842 } | |
843 | |
844 /* | |
845 * Enable or disable mnemonics for the toplevel menus. | |
846 */ | |
847 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
848 gui_motif_set_mnemonics(int enable) |
7 | 849 { |
850 /* | |
851 * Don't enable menu mnemonics when the menu bar is disabled, LessTif | |
852 * crashes when using a mnemonic then. | |
853 */ | |
854 if (!menu_enabled) | |
855 enable = FALSE; | |
856 do_set_mnemonics(enable); | |
857 } | |
858 | |
859 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
860 do_set_mnemonics(int enable) |
7 | 861 { |
862 vimmenu_T *menu; | |
863 | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
18788
diff
changeset
|
864 FOR_ALL_MENUS(menu) |
7 | 865 if (menu->id != (Widget)0) |
866 XtVaSetValues(menu->id, | |
867 XmNmnemonic, enable ? menu->mnemonic : NUL, | |
868 NULL); | |
869 } | |
870 | |
871 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
872 gui_mch_add_menu(vimmenu_T *menu, int idx) |
7 | 873 { |
874 XmString label; | |
875 Widget shell; | |
876 vimmenu_T *parent = menu->parent; | |
877 | |
878 #ifdef MOTIF_POPUP | |
879 if (menu_is_popup(menu->name)) | |
880 { | |
881 Arg arg[2]; | |
882 int n = 0; | |
883 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
884 // Only create the popup menu when it's actually used, otherwise there |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
885 // is a delay when using the right mouse button. |
7 | 886 # if (XmVersion <= 1002) |
887 if (mouse_model_popup()) | |
888 # endif | |
889 { | |
890 if (gui.menu_bg_pixel != INVALCOLOR) | |
22329
858d7ceb1135
patch 8.2.1713: Motif GUI: crash when setting menu colors
Bram Moolenaar <Bram@vim.org>
parents:
21355
diff
changeset
|
891 { |
7 | 892 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++; |
22329
858d7ceb1135
patch 8.2.1713: Motif GUI: crash when setting menu colors
Bram Moolenaar <Bram@vim.org>
parents:
21355
diff
changeset
|
893 } |
7 | 894 if (gui.menu_fg_pixel != INVALCOLOR) |
22329
858d7ceb1135
patch 8.2.1713: Motif GUI: crash when setting menu colors
Bram Moolenaar <Bram@vim.org>
parents:
21355
diff
changeset
|
895 { |
7 | 896 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++; |
22329
858d7ceb1135
patch 8.2.1713: Motif GUI: crash when setting menu colors
Bram Moolenaar <Bram@vim.org>
parents:
21355
diff
changeset
|
897 } |
7 | 898 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu", |
899 arg, n); | |
900 menu->id = (Widget)0; | |
901 } | |
902 return; | |
903 } | |
904 #endif | |
905 | |
906 if (!menu_is_menubar(menu->name) | |
907 || (parent != NULL && parent->submenu_id == (Widget)0)) | |
908 return; | |
909 | |
910 label = XmStringCreate((char *)menu->dname, STRING_TAG); | |
911 if (label == NULL) | |
912 return; | |
913 menu->id = XtVaCreateWidget("subMenu", | |
914 xmCascadeButtonWidgetClass, | |
915 (parent == NULL) ? menuBar : parent->submenu_id, | |
916 XmNlabelString, label, | |
917 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic, | |
918 #if (XmVersion >= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
919 // submenu: count the tearoff item (needed for LessTif) |
7 | 920 XmNpositionIndex, idx + (parent != NULL |
921 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0), | |
922 #endif | |
923 NULL); | |
924 XmStringFree(label); | |
925 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
926 if (menu->id == (Widget)0) // failed |
7 | 927 return; |
928 | |
28247
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
929 // The "Help" menu is a special case, and should be placed at the far |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
930 // right hand side of the menu-bar. It's recognized by its high priority. |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
931 if (parent == NULL && menu->priority >= 9999) |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
932 XtVaSetValues(menuBar, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
933 XmNmenuHelpWidget, menu->id, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
934 NULL); |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
935 |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
936 gui_motif_menu_colors(menu->id); |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
937 gui_motif_menu_fontlist(menu->id); |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
938 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
939 // add accelerator text |
7 | 940 gui_motif_add_actext(menu); |
941 | |
942 shell = XtVaCreateWidget("subMenuShell", | |
943 xmMenuShellWidgetClass, menu->id, | |
944 XmNwidth, 1, | |
945 XmNheight, 1, | |
946 NULL); | |
947 gui_motif_menu_colors(shell); | |
948 menu->submenu_id = XtVaCreateWidget("rowColumnMenu", | |
949 xmRowColumnWidgetClass, shell, | |
950 XmNrowColumnType, XmMENU_PULLDOWN, | |
951 NULL); | |
952 gui_motif_menu_colors(menu->submenu_id); | |
953 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
954 if (menu->submenu_id == (Widget)0) // failed |
7 | 955 return; |
956 | |
957 #if (XmVersion >= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
958 // Set the colors for the tear off widget |
7 | 959 toggle_tearoff(menu->submenu_id); |
960 #endif | |
961 | |
962 XtVaSetValues(menu->id, | |
963 XmNsubMenuId, menu->submenu_id, | |
964 NULL); | |
965 | |
28247
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
966 // When we add a top-level item to the menu bar, we can figure out how |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
28191
diff
changeset
|
967 // high the menu bar should be. |
7 | 968 if (parent == NULL) |
969 gui_mch_compute_menu_height(menu->id); | |
970 } | |
971 | |
972 | |
973 /* | |
974 * Add mnemonic and accelerator text to a menu button. | |
975 */ | |
976 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
977 gui_motif_add_actext(vimmenu_T *menu) |
7 | 978 { |
979 XmString label; | |
980 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
981 // Add accelerator text, if there is one |
7 | 982 if (menu->actext != NULL && menu->id != (Widget)0) |
983 { | |
984 label = XmStringCreate((char *)menu->actext, STRING_TAG); | |
985 if (label == NULL) | |
986 return; | |
987 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL); | |
988 XmStringFree(label); | |
989 } | |
990 } | |
991 | |
992 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
993 gui_mch_toggle_tearoffs(int enable) |
7 | 994 { |
995 #if (XmVersion >= 1002) | |
996 if (enable) | |
997 tearoff_val = (int)XmTEAR_OFF_ENABLED; | |
998 else | |
999 tearoff_val = (int)XmTEAR_OFF_DISABLED; | |
1000 toggle_tearoff(menuBar); | |
1001 gui_mch_recurse_tearoffs(root_menu); | |
1002 #endif | |
1003 } | |
1004 | |
1005 #if (XmVersion >= 1002) | |
1006 /* | |
1007 * Set the tearoff for one menu widget on or off, and set the color of the | |
1008 * tearoff widget. | |
1009 */ | |
1010 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1011 toggle_tearoff(Widget wid) |
7 | 1012 { |
1013 Widget w; | |
1014 | |
1015 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL); | |
1016 if (tearoff_val == (int)XmTEAR_OFF_ENABLED | |
1017 && (w = XmGetTearOffControl(wid)) != (Widget)0) | |
1018 gui_motif_menu_colors(w); | |
1019 } | |
1020 | |
1021 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1022 gui_mch_recurse_tearoffs(vimmenu_T *menu) |
7 | 1023 { |
1024 while (menu != NULL) | |
1025 { | |
1026 if (!menu_is_popup(menu->name)) | |
1027 { | |
1028 if (menu->submenu_id != (Widget)0) | |
1029 toggle_tearoff(menu->submenu_id); | |
1030 gui_mch_recurse_tearoffs(menu->children); | |
1031 } | |
1032 menu = menu->next; | |
1033 } | |
1034 } | |
1035 #endif | |
1036 | |
1037 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1038 gui_mch_text_area_extra_height(void) |
7 | 1039 { |
1040 Dimension shadowHeight; | |
1041 | |
1042 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL); | |
1043 return shadowHeight; | |
1044 } | |
1045 | |
1046 /* | |
1047 * Compute the height of the menu bar. | |
1048 * We need to check all the items for their position and height, for the case | |
1049 * there are several rows, and/or some characters extend higher or lower. | |
1050 */ | |
1051 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1052 gui_mch_compute_menu_height( |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1053 Widget id) // can be NULL when deleting menu |
7 | 1054 { |
1055 Dimension y, maxy; | |
1056 Dimension margin, shadow; | |
1057 vimmenu_T *mp; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1058 static Dimension height = 21; // normal height of a menu item |
7 | 1059 |
1060 /* | |
1061 * Get the height of the new item, before managing it, because it will | |
1062 * still reflect the font size. After managing it depends on the menu | |
1063 * height, which is what we just wanted to get!. | |
1064 */ | |
1065 if (id != (Widget)0) | |
1066 XtVaGetValues(id, XmNheight, &height, NULL); | |
1067 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1068 // Find any menu Widget, to be able to call XtManageChild() |
7 | 1069 else |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
18788
diff
changeset
|
1070 FOR_ALL_MENUS(mp) |
7 | 1071 if (mp->id != (Widget)0 && menu_is_menubar(mp->name)) |
1072 { | |
1073 id = mp->id; | |
1074 break; | |
1075 } | |
1076 | |
1077 /* | |
1078 * Now manage the menu item, to make them all be positioned (makes an | |
1079 * extra row when needed, removes it when not needed). | |
1080 */ | |
1081 if (id != (Widget)0) | |
1082 XtManageChild(id); | |
1083 | |
1084 /* | |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1085 * Now find the menu item that is the furthest down, and get its position. |
7 | 1086 */ |
1087 maxy = 0; | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
18788
diff
changeset
|
1088 FOR_ALL_MENUS(mp) |
7 | 1089 { |
1090 if (mp->id != (Widget)0 && menu_is_menubar(mp->name)) | |
1091 { | |
1092 XtVaGetValues(mp->id, XmNy, &y, NULL); | |
1093 if (y > maxy) | |
1094 maxy = y; | |
1095 } | |
1096 } | |
1097 | |
1098 XtVaGetValues(menuBar, | |
1099 XmNmarginHeight, &margin, | |
1100 XmNshadowThickness, &shadow, | |
1101 NULL); | |
1102 | |
1103 /* | |
1104 * This computation is the result of trial-and-error: | |
1105 * maxy = The maximum position of an item; required for when there are | |
1106 * two or more rows | |
1107 * height = height of an item, before managing it; Hopefully this will | |
1108 * change with the font height. Includes shadow-border. | |
1109 * shadow = shadow-border; must be subtracted from the height. | |
1110 * margin = margin around the menu buttons; Must be added. | |
1111 * Add 4 for the underlining of shortcut keys. | |
1112 */ | |
1113 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4; | |
1114 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1115 // Somehow the menu bar doesn't resize automatically. Set it here, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1116 // even though this is a catch 22. Don't do this when starting up, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1117 // somehow the menu gets very high then. |
7 | 1118 if (gui.shell_created) |
1119 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL); | |
48 | 1120 } |
1121 | |
147 | 1122 #ifdef FEAT_TOOLBAR |
1123 | |
48 | 1124 /* |
1125 * Icons used by the toolbar code. | |
1126 */ | |
1127 #include "gui_x11_pm.h" | |
1128 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
1129 static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname); |
48 | 1130 |
1131 /* | |
1132 * Read an Xpm file. Return OK or FAIL. | |
1133 */ | |
1134 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1135 check_xpm(char_u *path) |
48 | 1136 { |
1137 XpmAttributes attrs; | |
1138 int status; | |
1139 Pixmap mask; | |
1140 Pixmap map; | |
1141 | |
1142 attrs.valuemask = 0; | |
1143 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1144 // Create the "sensitive" pixmap |
48 | 1145 status = XpmReadFileToPixmap(gui.dpy, |
1146 RootWindow(gui.dpy, DefaultScreen(gui.dpy)), | |
1147 (char *)path, &map, &mask, &attrs); | |
1148 XpmFreeAttributes(&attrs); | |
1149 | |
1150 if (status == XpmSuccess) | |
1151 return OK; | |
1152 return FAIL; | |
1153 } | |
1154 | |
1155 | |
1156 /* | |
1157 * Allocated a pixmap for toolbar menu "menu". | |
161 | 1158 * When it's to be read from a file, "fname" is set to the file name |
1159 * (in allocated memory). | |
48 | 1160 * Return a blank pixmap if it fails. |
1161 */ | |
1162 static char ** | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1163 get_toolbar_pixmap(vimmenu_T *menu, char **fname) |
48 | 1164 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1165 char_u buf[MAXPATHL]; // buffer storing expanded pathname |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1166 char **xpm = NULL; // xpm array |
48 | 1167 int res; |
1168 | |
161 | 1169 *fname = NULL; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1170 buf[0] = NUL; // start with NULL path |
48 | 1171 |
1172 if (menu->iconfile != NULL) | |
1173 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1174 // Use the "icon=" argument. |
48 | 1175 gui_find_iconfile(menu->iconfile, buf, "xpm"); |
1176 res = check_xpm(buf); | |
1177 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1178 // If it failed, try using the menu name. |
48 | 1179 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK) |
1180 res = check_xpm(buf); | |
1181 if (res == OK) | |
161 | 1182 { |
1183 *fname = (char *)vim_strsave(buf); | |
48 | 1184 return tb_blank_xpm; |
161 | 1185 } |
48 | 1186 } |
1187 | |
1188 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL) | |
1189 { | |
1190 if (menu->iconidx >= 0 && menu->iconidx | |
1887 | 1191 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0]))) |
48 | 1192 xpm = built_in_pixmaps[menu->iconidx]; |
1193 else | |
1194 xpm = tb_blank_xpm; | |
1195 } | |
1196 | |
1197 return xpm; | |
7 | 1198 } |
161 | 1199 |
1200 /* | |
1201 * Add arguments for the toolbar pixmap to a menu item. | |
1202 */ | |
1203 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1204 add_pixmap_args(vimmenu_T *menu, Arg *args, int n) |
161 | 1205 { |
1206 vim_free(menu->xpm_fname); | |
1207 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname); | |
1208 if (menu->xpm == NULL) | |
1209 { | |
1210 XtSetArg(args[n], XmNlabelType, XmSTRING); n++; | |
1211 } | |
1212 else | |
1213 { | |
1214 if (menu->xpm_fname != NULL) | |
22333
2ccc3e68b617
patch 8.2.1715: Motif GUI: commented out code missed {}
Bram Moolenaar <Bram@vim.org>
parents:
22329
diff
changeset
|
1215 { |
161 | 1216 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++; |
22333
2ccc3e68b617
patch 8.2.1715: Motif GUI: commented out code missed {}
Bram Moolenaar <Bram@vim.org>
parents:
22329
diff
changeset
|
1217 } |
161 | 1218 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++; |
1219 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++; | |
1220 } | |
1221 return n; | |
1222 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1223 #endif // FEAT_TOOLBAR |
7 | 1224 |
1225 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1226 gui_mch_add_menu_item(vimmenu_T *menu, int idx) |
7 | 1227 { |
1228 XmString label; | |
1229 vimmenu_T *parent = menu->parent; | |
1230 | |
1231 # if (XmVersion <= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1232 // Don't add Popup menu items when the popup menu isn't used. |
7 | 1233 if (menu_is_child_of_popup(menu) && !mouse_model_popup()) |
1234 return; | |
1235 # endif | |
1236 | |
1237 # ifdef FEAT_TOOLBAR | |
1238 if (menu_is_toolbar(parent->name)) | |
1239 { | |
1240 WidgetClass type; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1241 XmString xms = NULL; // fallback label if pixmap not found |
7 | 1242 int n; |
1243 Arg args[18]; | |
1244 | |
1245 n = 0; | |
1246 if (menu_is_separator(menu->name)) | |
1247 { | |
1248 char *cp; | |
1249 Dimension wid; | |
1250 | |
1251 /* | |
1252 * A separator has the format "-sep%d[:%d]-". The optional :%d is | |
1253 * a width specifier. If no width is specified then we choose one. | |
1254 */ | |
1255 cp = (char *)vim_strchr(menu->name, ':'); | |
1256 if (cp != NULL) | |
1257 wid = (Dimension)atoi(++cp); | |
1258 else | |
1259 wid = 4; | |
1260 | |
1261 type = xmSeparatorWidgetClass; | |
1262 XtSetArg(args[n], XmNwidth, wid); n++; | |
1263 XtSetArg(args[n], XmNminWidth, wid); n++; | |
1264 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; | |
48 | 1265 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++; |
7 | 1266 } |
1267 else | |
1268 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1269 // Without shadows one can't sense whatever the button has been |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1270 // pressed or not! However we want to save a bit of space... |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1271 // Need the highlightThickness to see the focus. |
44 | 1272 XtSetArg(args[n], XmNhighlightThickness, 1); n++; |
7 | 1273 XtSetArg(args[n], XmNhighlightOnEnter, True); n++; |
1274 XtSetArg(args[n], XmNmarginWidth, 0); n++; | |
1275 XtSetArg(args[n], XmNmarginHeight, 0); n++; | |
54 | 1276 XtSetArg(args[n], XmNtraversalOn, False); n++; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1277 // Set the label here, so that we can switch between icons/text |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1278 // by changing the XmNlabelType resource. |
48 | 1279 xms = XmStringCreate((char *)menu->dname, STRING_TAG); |
1280 XtSetArg(args[n], XmNlabelString, xms); n++; | |
1281 | |
161 | 1282 n = add_pixmap_args(menu, args, n); |
1283 | |
48 | 1284 type = xmEnhancedButtonWidgetClass; |
7 | 1285 } |
1286 | |
1287 XtSetArg(args[n], XmNpositionIndex, idx); n++; | |
1288 if (menu->id == NULL) | |
1289 { | |
1290 menu->id = XtCreateManagedWidget((char *)menu->dname, | |
1291 type, toolBar, args, n); | |
48 | 1292 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass) |
7 | 1293 { |
1294 XtAddCallback(menu->id, | |
1295 XmNactivateCallback, gui_x11_menu_cb, menu); | |
1296 } | |
1297 } | |
1298 else | |
1299 XtSetValues(menu->id, args, n); | |
1300 if (xms != NULL) | |
1301 XmStringFree(xms); | |
1302 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1303 # ifdef FEAT_BEVAL_GUI |
7 | 1304 gui_mch_menu_set_tip(menu); |
844 | 1305 # endif |
7 | 1306 |
1307 menu->parent = parent; | |
1308 menu->submenu_id = NULL; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1309 // When adding first item to toolbar it might have to be enabled . |
7 | 1310 if (!XtIsManaged(XtParent(toolBar)) |
1311 && vim_strchr(p_go, GO_TOOLBAR) != NULL) | |
1312 gui_mch_show_toolbar(TRUE); | |
1313 gui.toolbar_height = gui_mch_compute_toolbar_height(); | |
1314 return; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1315 } // toolbar menu item |
7 | 1316 # endif |
1317 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1318 // No parent, must be a non-menubar menu |
7 | 1319 if (parent->submenu_id == (Widget)0) |
1320 return; | |
1321 | |
1322 menu->submenu_id = (Widget)0; | |
1323 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1324 // Add menu separator |
7 | 1325 if (menu_is_separator(menu->name)) |
1326 { | |
1327 menu->id = XtVaCreateWidget("subMenu", | |
1328 xmSeparatorGadgetClass, parent->submenu_id, | |
1329 #if (XmVersion >= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1330 // count the tearoff item (needed for LessTif) |
7 | 1331 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED |
1332 ? 1 : 0), | |
1333 #endif | |
1334 NULL); | |
1335 gui_motif_menu_colors(menu->id); | |
1336 return; | |
1337 } | |
1338 | |
1339 label = XmStringCreate((char *)menu->dname, STRING_TAG); | |
1340 if (label == NULL) | |
1341 return; | |
1342 menu->id = XtVaCreateWidget("subMenu", | |
1343 xmPushButtonWidgetClass, parent->submenu_id, | |
1344 XmNlabelString, label, | |
1345 XmNmnemonic, menu->mnemonic, | |
1346 #if (XmVersion >= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1347 // count the tearoff item (needed for LessTif) |
7 | 1348 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED |
1349 ? 1 : 0), | |
1350 #endif | |
1351 NULL); | |
1352 gui_motif_menu_colors(menu->id); | |
1353 gui_motif_menu_fontlist(menu->id); | |
1354 XmStringFree(label); | |
1355 | |
1356 if (menu->id != (Widget)0) | |
1357 { | |
1358 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb, | |
1359 (XtPointer)menu); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1360 // add accelerator text |
7 | 1361 gui_motif_add_actext(menu); |
1362 } | |
1363 } | |
1364 | |
1365 #if (XmVersion <= 1002) || defined(PROTO) | |
1366 /* | |
1367 * This function will destroy/create the popup menus dynamically, | |
1368 * according to the value of 'mousemodel'. | |
1369 * This will fix the "right mouse button freeze" that occurs when | |
1370 * there exists a popup menu but it isn't managed. | |
1371 */ | |
1372 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1373 gui_motif_update_mousemodel(vimmenu_T *menu) |
7 | 1374 { |
1375 int idx = 0; | |
1376 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1377 // When GUI hasn't started the menus have not been created. |
7 | 1378 if (!gui.in_use) |
1379 return; | |
1380 | |
1381 while (menu) | |
1382 { | |
1383 if (menu->children != NULL) | |
1384 { | |
1385 if (menu_is_popup(menu->name)) | |
1386 { | |
1387 if (mouse_model_popup()) | |
1388 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1389 // Popup menu will be used. Create the popup menus. |
7 | 1390 gui_mch_add_menu(menu, idx); |
1391 gui_motif_update_mousemodel(menu->children); | |
1392 } | |
1393 else | |
1394 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1395 // Popup menu will not be used. Destroy the popup menus. |
7 | 1396 gui_motif_update_mousemodel(menu->children); |
1397 gui_mch_destroy_menu(menu); | |
1398 } | |
1399 } | |
1400 } | |
1401 else if (menu_is_child_of_popup(menu)) | |
1402 { | |
1403 if (mouse_model_popup()) | |
1404 gui_mch_add_menu_item(menu, idx); | |
1405 else | |
1406 gui_mch_destroy_menu(menu); | |
1407 } | |
1408 menu = menu->next; | |
1409 ++idx; | |
1410 } | |
1411 } | |
1412 #endif | |
1413 | |
1414 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1415 gui_mch_new_menu_colors(void) |
7 | 1416 { |
1417 if (menuBar == (Widget)0) | |
1418 return; | |
1419 gui_motif_menu_colors(menuBar); | |
1420 #ifdef FEAT_TOOLBAR | |
1421 gui_motif_menu_colors(toolBarFrame); | |
1422 gui_motif_menu_colors(toolBar); | |
1423 #endif | |
1424 | |
54 | 1425 submenu_change(root_menu, TRUE); |
7 | 1426 } |
1427 | |
1428 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1429 gui_mch_new_menu_font(void) |
7 | 1430 { |
1431 if (menuBar == (Widget)0) | |
1432 return; | |
54 | 1433 submenu_change(root_menu, FALSE); |
7 | 1434 { |
1435 Dimension height; | |
1436 Position w, h; | |
1437 | |
1438 XtVaGetValues(menuBar, XmNheight, &height, NULL); | |
1439 gui.menu_height = height; | |
1440 | |
1441 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL); | |
1442 gui_resize_shell(w, h | |
1443 #ifdef FEAT_XIM | |
1444 - xim_get_status_area_height() | |
1445 #endif | |
1446 ); | |
1447 } | |
811 | 1448 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT); |
7 | 1449 ui_new_shellsize(); |
1450 } | |
1451 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1452 #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
7 | 1453 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1454 gui_mch_new_tooltip_font(void) |
7 | 1455 { |
1456 # ifdef FEAT_TOOLBAR | |
1457 vimmenu_T *menu; | |
1458 | |
1459 if (toolBar == (Widget)0) | |
1460 return; | |
1461 | |
1462 menu = gui_find_menu((char_u *)"ToolBar"); | |
1463 if (menu != NULL) | |
54 | 1464 submenu_change(menu, FALSE); |
7 | 1465 # endif |
1466 } | |
1467 | |
1468 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1469 gui_mch_new_tooltip_colors(void) |
7 | 1470 { |
1471 # ifdef FEAT_TOOLBAR | |
1472 vimmenu_T *toolbar; | |
1473 | |
1474 if (toolBar == (Widget)0) | |
1475 return; | |
1476 | |
1477 toolbar = gui_find_menu((char_u *)"ToolBar"); | |
1478 if (toolbar != NULL) | |
54 | 1479 submenu_change(toolbar, TRUE); |
7 | 1480 # endif |
1481 } | |
1482 #endif | |
1483 | |
1484 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1485 submenu_change( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1486 vimmenu_T *menu, |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1487 int colors) // TRUE for colors, FALSE for font |
7 | 1488 { |
1489 vimmenu_T *mp; | |
1490 | |
1491 for (mp = menu; mp != NULL; mp = mp->next) | |
1492 { | |
1493 if (mp->id != (Widget)0) | |
1494 { | |
1495 if (colors) | |
1496 { | |
1497 gui_motif_menu_colors(mp->id); | |
1498 #ifdef FEAT_TOOLBAR | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1499 // For a toolbar item: Free the pixmap and allocate a new one, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1500 // so that the background color is right. |
48 | 1501 if (mp->xpm != NULL) |
7 | 1502 { |
48 | 1503 int n = 0; |
1504 Arg args[18]; | |
1505 | |
161 | 1506 n = add_pixmap_args(mp, args, n); |
48 | 1507 XtSetValues(mp->id, args, n); |
7 | 1508 } |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1509 # ifdef FEAT_BEVAL_GUI |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1510 // If we have a tooltip, then we need to change its font |
7 | 1511 if (mp->tip != NULL) |
1512 { | |
1513 Arg args[2]; | |
1514 | |
1515 args[0].name = XmNbackground; | |
1516 args[0].value = gui.tooltip_bg_pixel; | |
1517 args[1].name = XmNforeground; | |
1518 args[1].value = gui.tooltip_fg_pixel; | |
1519 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args)); | |
1520 } | |
1521 # endif | |
1522 #endif | |
1523 } | |
1524 else | |
1525 { | |
1526 gui_motif_menu_fontlist(mp->id); | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1527 #ifdef FEAT_BEVAL_GUI |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1528 // If we have a tooltip, then we need to change its font |
7 | 1529 if (mp->tip != NULL) |
1530 { | |
1531 Arg args[1]; | |
1532 | |
1533 args[0].name = XmNfontList; | |
1534 args[0].value = (XtArgVal)gui_motif_fontset2fontlist( | |
1535 &gui.tooltip_fontset); | |
1536 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args)); | |
1537 } | |
1538 #endif | |
1539 } | |
1540 } | |
1541 | |
1542 if (mp->children != NULL) | |
1543 { | |
1544 #if (XmVersion >= 1002) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1545 // Set the colors/font for the tear off widget |
7 | 1546 if (mp->submenu_id != (Widget)0) |
1547 { | |
1548 if (colors) | |
1549 gui_motif_menu_colors(mp->submenu_id); | |
1550 else | |
1551 gui_motif_menu_fontlist(mp->submenu_id); | |
1552 toggle_tearoff(mp->submenu_id); | |
1553 } | |
1554 #endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1555 // Set the colors for the children |
54 | 1556 submenu_change(mp->children, colors); |
7 | 1557 } |
1558 } | |
1559 } | |
1560 | |
1561 /* | |
1562 * Destroy the machine specific menu widget. | |
1563 */ | |
1564 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1565 gui_mch_destroy_menu(vimmenu_T *menu) |
7 | 1566 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1567 // Please be sure to destroy the parent widget first (i.e. menu->id). |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1568 // On the other hand, problems have been reported that the submenu must be |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1569 // deleted first... |
7 | 1570 if (menu->submenu_id != (Widget)0) |
1571 { | |
1572 XtDestroyWidget(menu->submenu_id); | |
1573 menu->submenu_id = (Widget)0; | |
1574 } | |
1575 | |
1576 if (menu->id != (Widget)0) | |
1577 { | |
1578 Widget parent; | |
1579 | |
1580 parent = XtParent(menu->id); | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1581 #if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI) |
216 | 1582 if (parent == toolBar && menu->tip != NULL) |
7 | 1583 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1584 // We try to destroy this before the actual menu, because there are |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1585 // callbacks, etc. that will be unregistered during the tooltip |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1586 // destruction. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1587 // |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1588 // If you call "gui_mch_destroy_beval_area()" after destroying |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1589 // menu->id, then the tooltip's window will have already been |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1590 // deallocated by Xt, and unknown behaviour will ensue (probably |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1591 // a core dump). |
7 | 1592 gui_mch_destroy_beval_area(menu->tip); |
1593 menu->tip = NULL; | |
1594 } | |
1595 #endif | |
1596 XtDestroyWidget(menu->id); | |
1597 menu->id = (Widget)0; | |
1598 if (parent == menuBar) | |
1599 gui_mch_compute_menu_height((Widget)0); | |
1600 #ifdef FEAT_TOOLBAR | |
1601 else if (parent == toolBar) | |
1602 { | |
1603 Cardinal num_children; | |
1604 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1605 // When removing last toolbar item, don't display the toolbar. |
7 | 1606 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL); |
1607 if (num_children == 0) | |
1608 gui_mch_show_toolbar(FALSE); | |
1609 else | |
1610 gui.toolbar_height = gui_mch_compute_toolbar_height(); | |
1611 } | |
1612 #endif | |
1613 } | |
1614 } | |
1615 | |
1616 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1617 gui_mch_show_popupmenu(vimmenu_T *menu UNUSED) |
7 | 1618 { |
1619 #ifdef MOTIF_POPUP | |
1620 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event()); | |
1621 XtManageChild(menu->submenu_id); | |
1622 #endif | |
1623 } | |
1624 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1625 #endif // FEAT_MENU |
7 | 1626 |
1627 /* | |
1628 * Set the menu and scrollbar colors to their default values. | |
1629 */ | |
1630 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1631 gui_mch_def_colors(void) |
7 | 1632 { |
1633 if (gui.in_use) | |
1634 { | |
28067
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1635 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name); |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1636 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name); |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1637 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name); |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1638 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name); |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1639 #ifdef FEAT_BEVAL_GUI |
7 | 1640 gui.tooltip_fg_pixel = |
1641 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name); | |
1642 gui.tooltip_bg_pixel = | |
1643 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name); | |
1644 #endif | |
1645 } | |
1646 } | |
1647 | |
1648 | |
1649 /* | |
1650 * Scrollbar stuff. | |
1651 */ | |
1652 | |
1653 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1654 gui_mch_set_scrollbar_thumb( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1655 scrollbar_T *sb, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1656 long val, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1657 long size, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1658 long max) |
7 | 1659 { |
1660 if (sb->id != (Widget)0) | |
1661 XtVaSetValues(sb->id, | |
1662 XmNvalue, val, | |
1663 XmNsliderSize, size, | |
1664 XmNpageIncrement, (size > 2 ? size - 2 : 1), | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1665 XmNmaximum, max + 1, // Motif has max one past the end |
7 | 1666 NULL); |
1667 } | |
1668 | |
1669 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1670 gui_mch_set_scrollbar_pos( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1671 scrollbar_T *sb, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1672 int x, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1673 int y, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1674 int w, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1675 int h) |
7 | 1676 { |
1677 if (sb->id != (Widget)0) | |
1678 { | |
1679 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT) | |
1680 { | |
1681 if (y == 0) | |
1682 h -= gui.border_offset; | |
1683 else | |
1684 y -= gui.border_offset; | |
1685 XtVaSetValues(sb->id, | |
1686 XmNtopOffset, y, | |
1687 XmNbottomOffset, -y - h, | |
1688 XmNwidth, w, | |
1689 NULL); | |
1690 } | |
1691 else | |
1692 XtVaSetValues(sb->id, | |
1693 XmNtopOffset, y, | |
1694 XmNleftOffset, x, | |
1695 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT] | |
1696 ? gui.scrollbar_width : 0, | |
1697 XmNheight, h, | |
1698 NULL); | |
1699 XtManageChild(sb->id); | |
1700 } | |
1701 } | |
1702 | |
21355
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1703 int |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1704 gui_mch_get_scrollbar_xpadding(void) |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1705 { |
27587
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1706 int xpad; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1707 Dimension tw, ww; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1708 Position tx; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1709 |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1710 XtVaGetValues(textArea, XtNwidth, &tw, XtNx, &tx, NULL); |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1711 XtVaGetValues(vimShell, XtNwidth, &ww, NULL); |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1712 xpad = ww - tw - tx - gui.scrollbar_width; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1713 return (xpad < 0) ? 0 : xpad; |
21355
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1714 } |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1715 |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1716 int |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1717 gui_mch_get_scrollbar_ypadding(void) |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1718 { |
27587
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1719 int ypad; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1720 Dimension th, wh; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1721 Position ty; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1722 |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1723 XtVaGetValues(textArea, XtNheight, &th, XtNy, &ty, NULL); |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1724 XtVaGetValues(vimShell, XtNheight, &wh, NULL); |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1725 ypad = wh - th - ty - gui.scrollbar_height; |
298b32b544ae
patch 8.2.4320: Athena and Motif: when maximized scrollbar position is wrong
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1726 return (ypad < 0) ? 0 : ypad; |
21355
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1727 } |
fcccc29bd386
patch 8.2.1228: scrollbars not flush against the window edges when maximised
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
1728 |
7 | 1729 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1730 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) |
7 | 1731 { |
1732 Arg args[16]; | |
1733 int n; | |
1734 | |
1735 if (sb->id != (Widget)0) | |
1736 { | |
1737 n = 0; | |
1738 if (flag) | |
1739 { | |
1740 switch (sb->type) | |
1741 { | |
1742 case SBAR_LEFT: | |
1743 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++; | |
1744 break; | |
1745 | |
1746 case SBAR_RIGHT: | |
1747 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++; | |
1748 break; | |
1749 | |
1750 case SBAR_BOTTOM: | |
1751 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++; | |
1752 break; | |
1753 } | |
1754 XtSetValues(textArea, args, n); | |
1755 XtManageChild(sb->id); | |
1756 } | |
1757 else | |
1758 { | |
1759 if (!gui.which_scrollbars[sb->type]) | |
1760 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1761 // The scrollbars of this type are all disabled, adjust the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1762 // textArea attachment offset. |
7 | 1763 switch (sb->type) |
1764 { | |
1765 case SBAR_LEFT: | |
1766 XtSetArg(args[n], XmNleftOffset, 0); n++; | |
1767 break; | |
1768 | |
1769 case SBAR_RIGHT: | |
1770 XtSetArg(args[n], XmNrightOffset, 0); n++; | |
1771 break; | |
1772 | |
1773 case SBAR_BOTTOM: | |
1774 XtSetArg(args[n], XmNbottomOffset, 0);n++; | |
1775 break; | |
1776 } | |
1777 XtSetValues(textArea, args, n); | |
1778 } | |
1779 XtUnmanageChild(sb->id); | |
1780 } | |
1781 } | |
1782 } | |
1783 | |
1784 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1785 gui_mch_create_scrollbar( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1786 scrollbar_T *sb, |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1787 int orient) // SBAR_VERT or SBAR_HORIZ |
7 | 1788 { |
1789 Arg args[16]; | |
1790 int n; | |
1791 | |
1792 n = 0; | |
1793 XtSetArg(args[n], XmNminimum, 0); n++; | |
1794 XtSetArg(args[n], XmNorientation, | |
1795 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++; | |
1796 | |
1797 switch (sb->type) | |
1798 { | |
1799 case SBAR_LEFT: | |
1800 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; | |
1801 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++; | |
1802 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; | |
1803 break; | |
1804 | |
1805 case SBAR_RIGHT: | |
1806 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; | |
1807 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++; | |
1808 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; | |
1809 break; | |
1810 | |
1811 case SBAR_BOTTOM: | |
1812 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; | |
1813 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; | |
1814 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; | |
1815 break; | |
1816 } | |
1817 | |
1818 sb->id = XtCreateWidget("scrollBar", | |
1819 xmScrollBarWidgetClass, textAreaForm, args, n); | |
1820 | |
1821 if (sb->id != (Widget)0) | |
1822 { | |
1823 gui_mch_set_scrollbar_colors(sb); | |
1824 XtAddCallback(sb->id, XmNvalueChangedCallback, | |
1825 scroll_cb, (XtPointer)sb->ident); | |
1826 XtAddCallback(sb->id, XmNdragCallback, | |
1827 scroll_cb, (XtPointer)sb->ident); | |
1828 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb, | |
1829 (XtPointer)0); | |
1830 } | |
1831 } | |
1832 | |
1833 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1834 gui_mch_destroy_scrollbar(scrollbar_T *sb) |
7 | 1835 { |
1836 if (sb->id != (Widget)0) | |
1837 XtDestroyWidget(sb->id); | |
1838 } | |
1839 | |
1840 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1841 gui_mch_set_scrollbar_colors(scrollbar_T *sb) |
7 | 1842 { |
1843 if (sb->id != (Widget)0) | |
1844 { | |
1845 if (gui.scroll_bg_pixel != INVALCOLOR) | |
1846 { | |
1847 #if (XmVersion>=1002) | |
28067
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1848 // This should not only set the through color but also adjust |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1849 // related colors, such as shadows. |
7 | 1850 XmChangeColor(sb->id, gui.scroll_bg_pixel); |
28067
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1851 #endif |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1852 |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1853 // Set the through color directly, in case XmChangeColor() decided |
e257b6be5bd6
patch 8.2.4558: Motif: using default colors does not work as expected
Bram Moolenaar <Bram@vim.org>
parents:
28051
diff
changeset
|
1854 // to change it. |
7 | 1855 XtVaSetValues(sb->id, |
1856 XmNtroughColor, gui.scroll_bg_pixel, | |
1857 NULL); | |
1858 } | |
1859 | |
1860 if (gui.scroll_fg_pixel != INVALCOLOR) | |
1861 XtVaSetValues(sb->id, | |
1862 XmNforeground, gui.scroll_fg_pixel, | |
1863 XmNbackground, gui.scroll_fg_pixel, | |
1864 NULL); | |
1865 } | |
1866 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1867 // This is needed for the rectangle below the vertical scrollbars. |
7 | 1868 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0) |
1869 gui_motif_scroll_colors(textAreaForm); | |
1870 } | |
1871 | |
1872 /* | |
1873 * Miscellaneous stuff: | |
1874 */ | |
1875 | |
1876 Window | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
1877 gui_x11_get_wid(void) |
7 | 1878 { |
1879 return(XtWindow(textArea)); | |
1880 } | |
1881 | |
44 | 1882 /* |
1883 * Look for a widget in the widget tree w, with a mnemonic matching keycode. | |
1884 * When one is found, simulate a button press on that widget and give it the | |
1885 * keyboard focus. If the mnemonic is on a label, look in the userData field | |
1886 * of the label to see if it points to another widget, and give that the focus. | |
1887 */ | |
1888 static void | |
1889 do_mnemonic(Widget w, unsigned int keycode) | |
1890 { | |
1891 WidgetList children; | |
1892 int numChildren, i; | |
1893 Boolean isMenu; | |
1894 KeySym mnemonic = '\0'; | |
1895 char mneString[2]; | |
1896 Widget userData; | |
1897 unsigned char rowColType; | |
1898 | |
1899 if (XtIsComposite(w)) | |
1900 { | |
1901 if (XtClass(w) == xmRowColumnWidgetClass) | |
1902 { | |
1604 | 1903 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL); |
44 | 1904 isMenu = (rowColType != (unsigned char)XmWORK_AREA); |
1905 } | |
1906 else | |
1907 isMenu = False; | |
1908 if (!isMenu) | |
1909 { | |
1910 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, | |
1604 | 1911 &numChildren, NULL); |
44 | 1912 for (i = 0; i < numChildren; i++) |
1913 do_mnemonic(children[i], keycode); | |
1914 } | |
1915 } | |
1916 else | |
1917 { | |
1604 | 1918 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL); |
44 | 1919 if (mnemonic != '\0') |
1920 { | |
1921 mneString[0] = mnemonic; | |
1922 mneString[1] = '\0'; | |
1923 if (XKeysymToKeycode(XtDisplay(XtParent(w)), | |
1924 XStringToKeysym(mneString)) == keycode) | |
1925 { | |
1926 if (XtClass(w) == xmLabelWidgetClass | |
1927 || XtClass(w) == xmLabelGadgetClass) | |
1928 { | |
1604 | 1929 XtVaGetValues(w, XmNuserData, &userData, NULL); |
44 | 1930 if (userData != NULL && XtIsWidget(userData)) |
1931 XmProcessTraversal(userData, XmTRAVERSE_CURRENT); | |
1932 } | |
1933 else | |
1934 { | |
1935 XKeyPressedEvent keyEvent; | |
1936 | |
1937 XmProcessTraversal(w, XmTRAVERSE_CURRENT); | |
1938 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
1939 CLEAR_FIELD(keyEvent); |
44 | 1940 keyEvent.type = KeyPress; |
1941 keyEvent.serial = 1; | |
1942 keyEvent.send_event = True; | |
1943 keyEvent.display = XtDisplay(w); | |
1944 keyEvent.window = XtWindow(w); | |
1945 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent, | |
1946 NULL, 0); | |
1947 } | |
1948 } | |
1949 } | |
1950 } | |
1951 } | |
1952 | |
1953 /* | |
1954 * Callback routine for dialog mnemonic processing. | |
1955 */ | |
1956 static void | |
24266
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
1957 mnemonic_event( |
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
1958 Widget w, |
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
1959 XtPointer call_data UNUSED, |
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
1960 XKeyEvent *event, |
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
1961 Boolean *b UNUSED) |
44 | 1962 { |
1963 do_mnemonic(w, event->keycode); | |
1964 } | |
1965 | |
1966 | |
1967 /* | |
1968 * Search the widget tree under w for widgets with mnemonics. When found, add | |
1969 * a passive grab to the dialog widget for the mnemonic character, thus | |
1970 * directing mnemonic events to the dialog widget. | |
1971 */ | |
1972 static void | |
1973 add_mnemonic_grabs(Widget dialog, Widget w) | |
1974 { | |
1975 char mneString[2]; | |
1976 WidgetList children; | |
1977 int numChildren, i; | |
1978 Boolean isMenu; | |
1979 KeySym mnemonic = '\0'; | |
1980 unsigned char rowColType; | |
1981 | |
1982 if (XtIsComposite(w)) | |
1983 { | |
1984 if (XtClass(w) == xmRowColumnWidgetClass) | |
1985 { | |
1604 | 1986 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL); |
44 | 1987 isMenu = (rowColType != (unsigned char)XmWORK_AREA); |
1988 } | |
1989 else | |
1990 isMenu = False; | |
1991 if (!isMenu) | |
1992 { | |
1993 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, | |
1604 | 1994 &numChildren, NULL); |
44 | 1995 for (i = 0; i < numChildren; i++) |
1996 add_mnemonic_grabs(dialog, children[i]); | |
1997 } | |
1998 } | |
1999 else | |
2000 { | |
1604 | 2001 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL); |
44 | 2002 if (mnemonic != '\0') |
2003 { | |
2004 mneString[0] = mnemonic; | |
2005 mneString[1] = '\0'; | |
2006 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog), | |
2007 XStringToKeysym(mneString)), | |
2008 Mod1Mask, True, GrabModeAsync, GrabModeAsync); | |
2009 } | |
2010 } | |
2011 } | |
2012 | |
2013 /* | |
2014 * Add a handler for mnemonics in a dialog. Motif itself only handles | |
2015 * mnemonics in menus. Mnemonics added or changed after this call will be | |
2016 * ignored. | |
2017 * | |
2018 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on | |
2019 * the appropriate label and set the XmNuserData resource of the label to the | |
2020 * widget to get the focus when the mnemonic is typed. | |
2021 */ | |
2022 static void | |
2023 activate_dialog_mnemonics(Widget dialog) | |
2024 { | |
2025 if (!dialog) | |
2026 return; | |
2027 | |
2028 XtAddEventHandler(dialog, KeyPressMask, False, | |
2029 (XtEventHandler) mnemonic_event, (XtPointer) NULL); | |
2030 add_mnemonic_grabs(dialog, dialog); | |
2031 } | |
2032 | |
2033 /* | |
2034 * Removes the event handler and key-grabs for dialog mnemonic handling. | |
2035 */ | |
2036 static void | |
2037 suppress_dialog_mnemonics(Widget dialog) | |
2038 { | |
2039 if (!dialog) | |
2040 return; | |
2041 | |
2042 XtUngrabKey(dialog, AnyKey, Mod1Mask); | |
2043 XtRemoveEventHandler(dialog, KeyPressMask, False, | |
2044 (XtEventHandler) mnemonic_event, (XtPointer) NULL); | |
2045 } | |
2046 | |
2047 #if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG) | |
2048 /* | |
2049 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget. | |
2050 */ | |
2051 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2052 set_fontlist(Widget id) |
44 | 2053 { |
2054 XmFontList fl; | |
2055 | |
2056 #ifdef FONTSET_ALWAYS | |
48 | 2057 if (gui.fontset != NOFONTSET) |
2058 { | |
44 | 2059 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset); |
2060 if (fl != NULL) | |
2061 { | |
2062 if (XtIsManaged(id)) | |
2063 { | |
2064 XtUnmanageChild(id); | |
2065 XtVaSetValues(id, XmNfontList, fl, NULL); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2066 // We should force the widget to recalculate its |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2067 // geometry now. |
44 | 2068 XtManageChild(id); |
2069 } | |
2070 else | |
2071 XtVaSetValues(id, XmNfontList, fl, NULL); | |
2072 XmFontListFree(fl); | |
2073 } | |
2074 } | |
2075 #else | |
48 | 2076 if (gui.norm_font != NOFONT) |
2077 { | |
44 | 2078 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font); |
2079 if (fl != NULL) | |
2080 { | |
2081 if (XtIsManaged(id)) | |
2082 { | |
2083 XtUnmanageChild(id); | |
2084 XtVaSetValues(id, XmNfontList, fl, NULL); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2085 // We should force the widget to recalculate its |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2086 // geometry now. |
44 | 2087 XtManageChild(id); |
2088 } | |
2089 else | |
2090 XtVaSetValues(id, XmNfontList, fl, NULL); | |
2091 XmFontListFree(fl); | |
2092 } | |
2093 } | |
2094 #endif | |
2095 } | |
2096 #endif | |
7 | 2097 |
2098 #if defined(FEAT_BROWSE) || defined(PROTO) | |
2099 | |
2100 /* | |
2101 * file selector related stuff | |
2102 */ | |
2103 | |
2104 #include <Xm/FileSB.h> | |
2105 #include <Xm/XmStrDefs.h> | |
2106 | |
2107 typedef struct dialog_callback_arg | |
2108 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2109 char * args; // not used right now |
7 | 2110 int id; |
2111 } dcbarg_T; | |
2112 | |
2113 static Widget dialog_wgt; | |
2114 static char *browse_fname = NULL; | |
2115 static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2116 // used to set up XmStrings |
7 | 2117 |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
2118 static void DialogCancelCB(Widget, XtPointer, XtPointer); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
2119 static void DialogAcceptCB(Widget, XtPointer, XtPointer); |
7 | 2120 |
2121 /* | |
2122 * This function is used to translate the predefined label text of the | |
2123 * precomposed dialogs. We do this explicitly to allow: | |
2124 * | |
2125 * - usage of gettext for translation, as in all the other places. | |
2126 * | |
2127 * - equalize the messages between different GUI implementations as far as | |
2128 * possible. | |
2129 */ | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2130 static void |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2131 set_predefined_label(Widget parent, String name, char *new_label) |
7 | 2132 { |
44 | 2133 XmString str; |
2134 Widget w; | |
2135 char_u *p, *next; | |
2136 KeySym mnemonic = NUL; | |
7 | 2137 |
2138 w = XtNameToWidget(parent, name); | |
2139 | |
2140 if (!w) | |
2141 return; | |
2142 | |
44 | 2143 p = vim_strsave((char_u *)new_label); |
2144 if (p == NULL) | |
2145 return; | |
2146 for (next = p; *next; ++next) | |
7 | 2147 { |
44 | 2148 if (*next == DLG_HOTKEY_CHAR) |
2149 { | |
2150 int len = STRLEN(next); | |
2151 | |
2152 if (len > 0) | |
2153 { | |
2154 mch_memmove(next, next + 1, len); | |
2155 mnemonic = next[0]; | |
2156 } | |
2157 } | |
2158 } | |
2159 | |
2160 str = XmStringCreate((char *)p, STRING_TAG); | |
2161 vim_free(p); | |
2162 | |
2163 if (str != NULL) | |
2164 { | |
2165 XtVaSetValues(w, | |
2166 XmNlabelString, str, | |
2167 XmNmnemonic, mnemonic, | |
2168 NULL); | |
7 | 2169 XmStringFree(str); |
2170 } | |
44 | 2171 gui_motif_menu_fontlist(w); |
2172 } | |
2173 | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2174 static void |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2175 set_predefined_fontlist(Widget parent, String name) |
44 | 2176 { |
2177 Widget w; | |
2178 w = XtNameToWidget(parent, name); | |
2179 | |
2180 if (!w) | |
2181 return; | |
2182 | |
2183 set_fontlist(w); | |
7 | 2184 } |
2185 | |
2186 /* | |
2187 * Put up a file requester. | |
2188 * Returns the selected name in allocated memory, or NULL for Cancel. | |
2189 */ | |
2190 char_u * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2191 gui_mch_browse( |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2192 int saving UNUSED, // select file to write |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2193 char_u *title, // title for the window |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2194 char_u *dflt, // default name |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2195 char_u *ext UNUSED, // not used (extension added) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2196 char_u *initdir, // initial directory, NULL for current dir |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2197 char_u *filter) // file name filter |
7 | 2198 { |
2199 char_u dirbuf[MAXPATHL]; | |
2200 char_u dfltbuf[MAXPATHL]; | |
2201 char_u *pattern; | |
2202 char_u *tofree = NULL; | |
2203 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2204 // There a difference between the resource name and value, Therefore, we |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2205 // avoid to (ab-)use the (maybe internationalized!) dialog title as a |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2206 // dialog name. |
44 | 2207 |
2208 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0); | |
7 | 2209 |
2210 if (initdir == NULL || *initdir == NUL) | |
2211 { | |
2212 mch_dirname(dirbuf, MAXPATHL); | |
2213 initdir = dirbuf; | |
2214 } | |
2215 | |
2216 if (dflt == NULL) | |
2217 dflt = (char_u *)""; | |
2218 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL) | |
2219 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2220 // The default selection should be the full path, "dflt" is only the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2221 // file name. |
7 | 2222 STRCPY(dfltbuf, initdir); |
2223 add_pathsep(dfltbuf); | |
2224 STRCAT(dfltbuf, dflt); | |
2225 dflt = dfltbuf; | |
2226 } | |
2227 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2228 // Can only use one pattern for a file name. Get the first pattern out of |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2229 // the filter. An empty pattern means everything matches. |
7 | 2230 if (filter == NULL) |
2231 pattern = (char_u *)""; | |
2232 else | |
2233 { | |
2234 char_u *s, *p; | |
2235 | |
2236 s = filter; | |
2237 for (p = filter; *p != NUL; ++p) | |
2238 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2239 if (*p == '\t') // end of description, start of pattern |
7 | 2240 s = p + 1; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2241 if (*p == ';' || *p == '\n') // end of (first) pattern |
7 | 2242 break; |
2243 } | |
2244 pattern = vim_strnsave(s, p - s); | |
2245 tofree = pattern; | |
2246 if (pattern == NULL) | |
2247 pattern = (char_u *)""; | |
2248 } | |
2249 | |
2250 XtVaSetValues(dialog_wgt, | |
2251 XtVaTypedArg, | |
2252 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1, | |
2253 XtVaTypedArg, | |
2254 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1, | |
2255 XtVaTypedArg, | |
2256 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1, | |
2257 XtVaTypedArg, | |
2258 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1, | |
2259 NULL); | |
2260 | |
44 | 2261 set_predefined_label(dialog_wgt, "Apply", _("&Filter")); |
2262 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel")); | |
7 | 2263 set_predefined_label(dialog_wgt, "Dir", _("Directories")); |
2264 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter")); | |
44 | 2265 set_predefined_label(dialog_wgt, "Help", _("&Help")); |
7 | 2266 set_predefined_label(dialog_wgt, "Items", _("Files")); |
44 | 2267 set_predefined_label(dialog_wgt, "OK", _("&OK")); |
7 | 2268 set_predefined_label(dialog_wgt, "Selection", _("Selection")); |
2269 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2270 // This is to save us from silly external settings using not fixed with |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2271 // fonts for file selection. |
44 | 2272 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList"); |
2273 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList"); | |
2274 | |
7 | 2275 gui_motif_menu_colors(dialog_wgt); |
2276 if (gui.scroll_bg_pixel != INVALCOLOR) | |
2277 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL); | |
2278 | |
2279 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0); | |
2280 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2281 // We have no help in this window, so hide help button |
7 | 2282 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt, |
2283 (unsigned char)XmDIALOG_HELP_BUTTON)); | |
2284 | |
2285 manage_centered(dialog_wgt); | |
44 | 2286 activate_dialog_mnemonics(dialog_wgt); |
7 | 2287 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2288 // sit in a loop until the dialog box has gone away |
7 | 2289 do |
2290 { | |
2291 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt), | |
2292 (XtInputMask)XtIMAll); | |
2293 } while (XtIsManaged(dialog_wgt)); | |
2294 | |
44 | 2295 suppress_dialog_mnemonics(dialog_wgt); |
7 | 2296 XtDestroyWidget(dialog_wgt); |
2297 vim_free(tofree); | |
2298 | |
2299 if (browse_fname == NULL) | |
2300 return NULL; | |
2301 return vim_strsave((char_u *)browse_fname); | |
2302 } | |
2303 | |
2304 /* | |
2305 * The code below was originally taken from | |
2306 * /usr/examples/motif/xmsamplers/xmeditor.c | |
2307 * on Digital Unix 4.0d, but heavily modified. | |
2308 */ | |
2309 | |
2310 /* | |
2311 * Process callback from Dialog cancel actions. | |
2312 */ | |
2313 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2314 DialogCancelCB( |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2315 Widget w UNUSED, // widget id |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2316 XtPointer client_data UNUSED, // data from application |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2317 XtPointer call_data UNUSED) // data from widget class |
7 | 2318 { |
2319 if (browse_fname != NULL) | |
2320 { | |
2321 XtFree(browse_fname); | |
2322 browse_fname = NULL; | |
2323 } | |
2324 XtUnmanageChild(dialog_wgt); | |
2325 } | |
2326 | |
2327 /* | |
2328 * Process callback from Dialog actions. | |
2329 */ | |
2330 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2331 DialogAcceptCB( |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2332 Widget w UNUSED, // widget id |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2333 XtPointer client_data UNUSED, // data from application |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2334 XtPointer call_data) // data from widget class |
7 | 2335 { |
2336 XmFileSelectionBoxCallbackStruct *fcb; | |
2337 | |
2338 if (browse_fname != NULL) | |
2339 { | |
2340 XtFree(browse_fname); | |
2341 browse_fname = NULL; | |
2342 } | |
2343 fcb = (XmFileSelectionBoxCallbackStruct *)call_data; | |
2344 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2345 // get the filename from the file selection box |
7 | 2346 XmStringGetLtoR(fcb->value, charset, &browse_fname); |
2347 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2348 // popdown the file selection box |
7 | 2349 XtUnmanageChild(dialog_wgt); |
2350 } | |
2351 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2352 #endif // FEAT_BROWSE |
7 | 2353 |
2354 #if defined(FEAT_GUI_DIALOG) || defined(PROTO) | |
2355 | |
2356 static int dialogStatus; | |
2357 | |
2358 /* | |
2359 * Callback function for the textfield. When CR is hit this works like | |
2360 * hitting the "OK" button, ESC like "Cancel". | |
2361 */ | |
2362 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2363 keyhit_callback( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2364 Widget w, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2365 XtPointer client_data UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2366 XEvent *event, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2367 Boolean *cont UNUSED) |
7 | 2368 { |
2369 char buf[2]; | |
2370 KeySym key_sym; | |
2371 | |
2372 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1) | |
2373 { | |
2374 if (*buf == CAR) | |
2375 dialogStatus = 1; | |
2376 else if (*buf == ESC) | |
2377 dialogStatus = 2; | |
2378 } | |
2379 if ((key_sym == XK_Left || key_sym == XK_Right) | |
2380 && !(event->xkey.state & ShiftMask)) | |
2381 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy)); | |
2382 } | |
2383 | |
2384 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2385 butproc( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2386 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2387 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2388 XtPointer call_data UNUSED) |
7 | 2389 { |
2390 dialogStatus = (int)(long)client_data + 1; | |
2391 } | |
2392 | |
2393 #ifdef HAVE_XPM | |
2394 | |
2395 static Widget | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2396 create_pixmap_label( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2397 Widget parent, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2398 String name, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2399 char **data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2400 ArgList args, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2401 Cardinal arg) |
7 | 2402 { |
2403 Widget label; | |
2404 Display *dsp; | |
2405 Screen *scr; | |
2406 int depth; | |
2407 Pixmap pixmap = 0; | |
2408 XpmAttributes attr; | |
2409 Boolean rs; | |
2410 XpmColorSymbol color[5] = | |
2411 { | |
2412 {"none", NULL, 0}, | |
2413 {"iconColor1", NULL, 0}, | |
2414 {"bottomShadowColor", NULL, 0}, | |
2415 {"topShadowColor", NULL, 0}, | |
2416 {"selectColor", NULL, 0} | |
2417 }; | |
2418 | |
2419 label = XmCreateLabelGadget(parent, name, args, arg); | |
2420 | |
2421 /* | |
1207 | 2422 * We need to be careful here, since in case of gadgets, there is |
7 | 2423 * no way to get the background color directly from the widget itself. |
2424 * In such cases we get it from The Core part of his parent instead. | |
2425 */ | |
2426 dsp = XtDisplayOfObject(label); | |
2427 scr = XtScreenOfObject(label); | |
2428 XtVaGetValues(XtIsSubclass(label, coreWidgetClass) | |
2429 ? label : XtParent(label), | |
2430 XmNdepth, &depth, | |
2431 XmNbackground, &color[0].pixel, | |
2432 XmNforeground, &color[1].pixel, | |
2433 XmNbottomShadowColor, &color[2].pixel, | |
2434 XmNtopShadowColor, &color[3].pixel, | |
2435 XmNhighlight, &color[4].pixel, | |
2436 NULL); | |
2437 | |
2438 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth; | |
2439 attr.colorsymbols = color; | |
2440 attr.numsymbols = 5; | |
2441 attr.closeness = 65535; | |
2442 attr.depth = depth; | |
2443 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr), | |
2444 data, &pixmap, NULL, &attr); | |
2445 | |
2446 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL); | |
2447 XtVaSetValues(label, XmNrecomputeSize, True, NULL); | |
2448 XtVaSetValues(label, | |
2449 XmNlabelType, XmPIXMAP, | |
2450 XmNlabelPixmap, pixmap, | |
2451 NULL); | |
2452 XtVaSetValues(label, XmNrecomputeSize, rs, NULL); | |
2453 | |
2454 return label; | |
2455 } | |
2456 #endif | |
2457 | |
2458 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2459 gui_mch_dialog( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2460 int type UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2461 char_u *title, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2462 char_u *message, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2463 char_u *button_names, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2464 int dfltbutton, |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2465 char_u *textfield, // buffer of size IOSIZE |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2466 int ex_cmd UNUSED) |
7 | 2467 { |
2468 char_u *buts; | |
2469 char_u *p, *next; | |
2470 XtAppContext app; | |
2471 XmString label; | |
2472 int butcount; | |
44 | 2473 Widget w; |
7 | 2474 Widget dialogform = NULL; |
2475 Widget form = NULL; | |
2476 Widget dialogtextfield = NULL; | |
2477 Widget *buttons; | |
2478 Widget sep_form = NULL; | |
2479 Boolean vertical; | |
2480 Widget separator = NULL; | |
2481 int n; | |
2482 Arg args[6]; | |
2483 #ifdef HAVE_XPM | |
2484 char **icon_data = NULL; | |
2485 Widget dialogpixmap = NULL; | |
2486 #endif | |
2487 | |
2488 if (title == NULL) | |
2489 title = (char_u *)_("Vim dialog"); | |
2490 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2491 // if our pointer is currently hidden, then we should show it. |
7 | 2492 gui_mch_mousehide(FALSE); |
2493 | |
2494 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0); | |
2495 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2496 // Check 'v' flag in 'guioptions': vertical button placement. |
7 | 2497 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); |
2498 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2499 // Set the title of the Dialog window |
7 | 2500 label = XmStringCreateSimple((char *)title); |
2501 if (label == NULL) | |
2502 return -1; | |
2503 XtVaSetValues(dialogform, | |
2504 XmNdialogTitle, label, | |
2505 XmNhorizontalSpacing, 4, | |
2506 XmNverticalSpacing, vertical ? 0 : 4, | |
2507 NULL); | |
2508 XmStringFree(label); | |
2509 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2510 // make a copy, so that we can insert NULs |
7 | 2511 buts = vim_strsave(button_names); |
2512 if (buts == NULL) | |
2513 return -1; | |
2514 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2515 // Count the number of buttons and allocate buttons[]. |
7 | 2516 butcount = 1; |
2517 for (p = buts; *p; ++p) | |
2518 if (*p == DLG_BUTTON_SEP) | |
2519 ++butcount; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2520 buttons = ALLOC_MULT(Widget, butcount); |
7 | 2521 if (buttons == NULL) |
2522 { | |
2523 vim_free(buts); | |
2524 return -1; | |
2525 } | |
2526 | |
2527 /* | |
2528 * Create the buttons. | |
2529 */ | |
2530 sep_form = (Widget) 0; | |
2531 p = buts; | |
2532 for (butcount = 0; *p; ++butcount) | |
2533 { | |
44 | 2534 KeySym mnemonic = NUL; |
2535 | |
7 | 2536 for (next = p; *next; ++next) |
2537 { | |
2538 if (*next == DLG_HOTKEY_CHAR) | |
44 | 2539 { |
2540 int len = STRLEN(next); | |
2541 | |
2542 if (len > 0) | |
2543 { | |
2544 mch_memmove(next, next + 1, len); | |
2545 mnemonic = next[0]; | |
2546 } | |
2547 } | |
7 | 2548 if (*next == DLG_BUTTON_SEP) |
2549 { | |
2550 *next++ = NUL; | |
2551 break; | |
2552 } | |
2553 } | |
2554 label = XmStringCreate(_((char *)p), STRING_TAG); | |
2555 if (label == NULL) | |
2556 break; | |
2557 | |
2558 buttons[butcount] = XtVaCreateManagedWidget("button", | |
2559 xmPushButtonWidgetClass, dialogform, | |
2560 XmNlabelString, label, | |
44 | 2561 XmNmnemonic, mnemonic, |
7 | 2562 XmNbottomAttachment, XmATTACH_FORM, |
2563 XmNbottomOffset, 4, | |
2564 XmNshowAsDefault, butcount == dfltbutton - 1, | |
2565 XmNdefaultButtonShadowThickness, 1, | |
2566 NULL); | |
2567 XmStringFree(label); | |
44 | 2568 gui_motif_menu_fontlist(buttons[butcount]); |
7 | 2569 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2570 // Layout properly. |
7 | 2571 |
2572 if (butcount > 0) | |
2573 { | |
2574 if (vertical) | |
2575 XtVaSetValues(buttons[butcount], | |
2576 XmNtopWidget, buttons[butcount - 1], | |
2577 NULL); | |
2578 else | |
2579 { | |
2580 if (*next == NUL) | |
2581 { | |
2582 XtVaSetValues(buttons[butcount], | |
2583 XmNrightAttachment, XmATTACH_FORM, | |
2584 XmNrightOffset, 4, | |
2585 NULL); | |
2586 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2587 // fill in a form as invisible separator |
7 | 2588 sep_form = XtVaCreateWidget("separatorForm", |
2589 xmFormWidgetClass, dialogform, | |
2590 XmNleftAttachment, XmATTACH_WIDGET, | |
2591 XmNleftWidget, buttons[butcount - 1], | |
2592 XmNrightAttachment, XmATTACH_WIDGET, | |
2593 XmNrightWidget, buttons[butcount], | |
2594 XmNbottomAttachment, XmATTACH_FORM, | |
2595 XmNbottomOffset, 4, | |
2596 NULL); | |
2597 XtManageChild(sep_form); | |
2598 } | |
2599 else | |
2600 { | |
2601 XtVaSetValues(buttons[butcount], | |
2602 XmNleftAttachment, XmATTACH_WIDGET, | |
2603 XmNleftWidget, buttons[butcount - 1], | |
2604 NULL); | |
2605 } | |
2606 } | |
2607 } | |
2608 else if (!vertical) | |
2609 { | |
2610 if (*next == NUL) | |
2611 { | |
2612 XtVaSetValues(buttons[0], | |
2613 XmNrightAttachment, XmATTACH_FORM, | |
2614 XmNrightOffset, 4, | |
2615 NULL); | |
2616 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2617 // fill in a form as invisible separator |
7 | 2618 sep_form = XtVaCreateWidget("separatorForm", |
2619 xmFormWidgetClass, dialogform, | |
2620 XmNleftAttachment, XmATTACH_FORM, | |
2621 XmNleftOffset, 4, | |
2622 XmNrightAttachment, XmATTACH_WIDGET, | |
2623 XmNrightWidget, buttons[0], | |
2624 XmNbottomAttachment, XmATTACH_FORM, | |
2625 XmNbottomOffset, 4, | |
2626 NULL); | |
2627 XtManageChild(sep_form); | |
2628 } | |
2629 else | |
2630 XtVaSetValues(buttons[0], | |
2631 XmNleftAttachment, XmATTACH_FORM, | |
2632 XmNleftOffset, 4, | |
2633 NULL); | |
2634 } | |
2635 | |
2636 XtAddCallback(buttons[butcount], XmNactivateCallback, | |
2637 (XtCallbackProc)butproc, (XtPointer)(long)butcount); | |
2638 p = next; | |
2639 } | |
2640 vim_free(buts); | |
2641 | |
2642 separator = (Widget) 0; | |
2643 if (butcount > 0) | |
2644 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2645 // Create the separator for beauty. |
7 | 2646 n = 0; |
2647 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++; | |
2648 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++; | |
2649 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++; | |
2650 XtSetArg(args[n], XmNbottomOffset, 4); n++; | |
2651 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; | |
2652 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; | |
2653 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n); | |
2654 XtManageChild(separator); | |
2655 } | |
2656 | |
2657 if (textfield != NULL) | |
2658 { | |
2659 dialogtextfield = XtVaCreateWidget("textField", | |
2660 xmTextFieldWidgetClass, dialogform, | |
2661 XmNleftAttachment, XmATTACH_FORM, | |
2662 XmNrightAttachment, XmATTACH_FORM, | |
2663 NULL); | |
2664 if (butcount > 0) | |
2665 XtVaSetValues(dialogtextfield, | |
2666 XmNbottomAttachment, XmATTACH_WIDGET, | |
2667 XmNbottomWidget, separator, | |
2668 NULL); | |
2669 else | |
2670 XtVaSetValues(dialogtextfield, | |
2671 XmNbottomAttachment, XmATTACH_FORM, | |
2672 NULL); | |
2673 | |
44 | 2674 set_fontlist(dialogtextfield); |
7 | 2675 XmTextFieldSetString(dialogtextfield, (char *)textfield); |
2676 XtManageChild(dialogtextfield); | |
2677 XtAddEventHandler(dialogtextfield, KeyPressMask, False, | |
2678 (XtEventHandler)keyhit_callback, (XtPointer)NULL); | |
2679 } | |
2680 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2681 // Form holding both message and pixmap labels |
7 | 2682 form = XtVaCreateWidget("separatorForm", |
2683 xmFormWidgetClass, dialogform, | |
2684 XmNleftAttachment, XmATTACH_FORM, | |
2685 XmNrightAttachment, XmATTACH_FORM, | |
2686 XmNtopAttachment, XmATTACH_FORM, | |
2687 NULL); | |
2688 XtManageChild(form); | |
2689 | |
2690 #ifdef HAVE_XPM | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2691 // Add a pixmap, left of the message. |
7 | 2692 switch (type) |
2693 { | |
2694 case VIM_GENERIC: | |
2695 icon_data = generic_xpm; | |
2696 break; | |
2697 case VIM_ERROR: | |
2698 icon_data = error_xpm; | |
2699 break; | |
2700 case VIM_WARNING: | |
2701 icon_data = alert_xpm; | |
2702 break; | |
2703 case VIM_INFO: | |
2704 icon_data = info_xpm; | |
2705 break; | |
2706 case VIM_QUESTION: | |
2707 icon_data = quest_xpm; | |
2708 break; | |
2709 default: | |
2710 icon_data = generic_xpm; | |
2711 } | |
2712 | |
2713 n = 0; | |
2714 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; | |
2715 XtSetArg(args[n], XmNtopOffset, 8); n++; | |
2716 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; | |
2717 XtSetArg(args[n], XmNbottomOffset, 8); n++; | |
2718 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; | |
2719 XtSetArg(args[n], XmNleftOffset, 8); n++; | |
2720 | |
2721 dialogpixmap = create_pixmap_label(form, "dialogPixmap", | |
2722 icon_data, args, n); | |
2723 XtManageChild(dialogpixmap); | |
2724 #endif | |
2725 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2726 // Create the dialog message. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2727 // Since LessTif is apparently having problems with the creation of |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2728 // properly localized string, we use LtoR here. The symptom is that the |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26592
diff
changeset
|
2729 // string is not shown properly in multiple lines as it does in native |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2730 // Motif. |
44 | 2731 label = XmStringCreateLtoR((char *)message, STRING_TAG); |
7 | 2732 if (label == NULL) |
2733 return -1; | |
44 | 2734 w = XtVaCreateManagedWidget("dialogMessage", |
7 | 2735 xmLabelGadgetClass, form, |
2736 XmNlabelString, label, | |
44 | 2737 XmNalignment, XmALIGNMENT_BEGINNING, |
7 | 2738 XmNtopAttachment, XmATTACH_FORM, |
2739 XmNtopOffset, 8, | |
2740 #ifdef HAVE_XPM | |
2741 XmNleftAttachment, XmATTACH_WIDGET, | |
2742 XmNleftWidget, dialogpixmap, | |
2743 #else | |
2744 XmNleftAttachment, XmATTACH_FORM, | |
2745 #endif | |
2746 XmNleftOffset, 8, | |
2747 XmNrightAttachment, XmATTACH_FORM, | |
2748 XmNrightOffset, 8, | |
2749 XmNbottomAttachment, XmATTACH_FORM, | |
2750 XmNbottomOffset, 8, | |
2751 NULL); | |
2752 XmStringFree(label); | |
44 | 2753 set_fontlist(w); |
7 | 2754 |
2755 if (textfield != NULL) | |
2756 { | |
2757 XtVaSetValues(form, | |
2758 XmNbottomAttachment, XmATTACH_WIDGET, | |
2759 XmNbottomWidget, dialogtextfield, | |
2760 NULL); | |
2761 } | |
2762 else | |
2763 { | |
2764 if (butcount > 0) | |
2765 XtVaSetValues(form, | |
2766 XmNbottomAttachment, XmATTACH_WIDGET, | |
2767 XmNbottomWidget, separator, | |
2768 NULL); | |
2769 else | |
2770 XtVaSetValues(form, | |
2771 XmNbottomAttachment, XmATTACH_FORM, | |
2772 NULL); | |
2773 } | |
2774 | |
2775 if (dfltbutton < 1) | |
2776 dfltbutton = 1; | |
2777 if (dfltbutton > butcount) | |
2778 dfltbutton = butcount; | |
2779 XtVaSetValues(dialogform, | |
2780 XmNdefaultButton, buttons[dfltbutton - 1], NULL); | |
2781 if (textfield != NULL) | |
2782 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL); | |
2783 else | |
2784 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1], | |
2785 NULL); | |
2786 | |
2787 manage_centered(dialogform); | |
44 | 2788 activate_dialog_mnemonics(dialogform); |
7 | 2789 |
2790 if (textfield != NULL && *textfield != NUL) | |
2791 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2792 // This only works after the textfield has been realised. |
7 | 2793 XmTextFieldSetSelection(dialogtextfield, |
2794 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield), | |
2795 XtLastTimestampProcessed(gui.dpy)); | |
2796 XmTextFieldSetCursorPosition(dialogtextfield, | |
2797 (XmTextPosition)STRLEN(textfield)); | |
2798 } | |
2799 | |
2800 app = XtWidgetToApplicationContext(dialogform); | |
2801 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2802 // Loop until a button is pressed or the dialog is killed somehow. |
7 | 2803 dialogStatus = -1; |
2804 for (;;) | |
2805 { | |
2806 XtAppProcessEvent(app, (XtInputMask)XtIMAll); | |
2807 if (dialogStatus >= 0 || !XtIsManaged(dialogform)) | |
2808 break; | |
2809 } | |
2810 | |
2811 vim_free(buttons); | |
2812 | |
2813 if (textfield != NULL) | |
2814 { | |
2815 p = (char_u *)XmTextGetString(dialogtextfield); | |
2816 if (p == NULL || dialogStatus < 0) | |
2817 *textfield = NUL; | |
2818 else | |
418 | 2819 vim_strncpy(textfield, p, IOSIZE - 1); |
2137
dabcabce3f9d
updated for version 7.2.419
Bram Moolenaar <bram@zimbu.org>
parents:
1887
diff
changeset
|
2820 XtFree((char *)p); |
7 | 2821 } |
2822 | |
44 | 2823 suppress_dialog_mnemonics(dialogform); |
7 | 2824 XtDestroyWidget(dialogform); |
2825 | |
2826 return dialogStatus; | |
2827 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2828 #endif // FEAT_GUI_DIALOG |
7 | 2829 |
2830 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
2831 void | |
2832 gui_mch_show_toolbar(int showit) | |
2833 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2834 Cardinal numChildren; // how many children toolBar has |
7 | 2835 |
2836 if (toolBar == (Widget)0) | |
2837 return; | |
2838 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL); | |
2839 if (showit && numChildren > 0) | |
2840 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2841 // Assume that we want to show the toolbar if p_toolbar contains |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2842 // valid option settings, therefore p_toolbar must not be NULL. |
7 | 2843 WidgetList children; |
2844 | |
2845 XtVaGetValues(toolBar, XmNchildren, &children, NULL); | |
2846 { | |
2847 void (*action)(BalloonEval *); | |
2848 int text = 0; | |
2849 | |
2850 if (strstr((const char *)p_toolbar, "tooltips")) | |
2851 action = &gui_mch_enable_beval_area; | |
2852 else | |
2853 action = &gui_mch_disable_beval_area; | |
2854 if (strstr((const char *)p_toolbar, "text")) | |
2855 text = 1; | |
2856 else if (strstr((const char *)p_toolbar, "icons")) | |
2857 text = -1; | |
2858 if (text != 0) | |
2859 { | |
2860 vimmenu_T *toolbar; | |
2861 vimmenu_T *cur; | |
2862 | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
18788
diff
changeset
|
2863 FOR_ALL_MENUS(toolbar) |
7 | 2864 if (menu_is_toolbar(toolbar->dname)) |
2865 break; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2866 // Assumption: toolbar is NULL if there is no toolbar, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2867 // otherwise it contains the toolbar menu structure. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2868 // |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2869 // Assumption: "numChildren" == the number of items in the list |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2870 // of items beginning with toolbar->children. |
7 | 2871 if (toolbar) |
2872 { | |
2873 for (cur = toolbar->children; cur; cur = cur->next) | |
2874 { | |
2875 Arg args[1]; | |
2876 int n = 0; | |
2877 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2878 // Enable/Disable tooltip (OK to enable while |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2879 // currently enabled). |
7 | 2880 if (cur->tip != NULL) |
2881 (*action)(cur->tip); | |
2882 if (!menu_is_separator(cur->name)) | |
2883 { | |
48 | 2884 if (text == 1 || cur->xpm == NULL) |
2885 { | |
7 | 2886 XtSetArg(args[n], XmNlabelType, XmSTRING); |
48 | 2887 ++n; |
2888 } | |
7 | 2889 if (cur->id != NULL) |
2890 { | |
2891 XtUnmanageChild(cur->id); | |
2892 XtSetValues(cur->id, args, n); | |
2893 XtManageChild(cur->id); | |
2894 } | |
2895 } | |
2896 } | |
2897 } | |
2898 } | |
2899 } | |
2900 gui.toolbar_height = gui_mch_compute_toolbar_height(); | |
2901 XtManageChild(XtParent(toolBar)); | |
819 | 2902 #ifdef FEAT_GUI_TABLINE |
2903 if (showing_tabline) | |
2904 { | |
2905 XtVaSetValues(tabLine, | |
2906 XmNtopAttachment, XmATTACH_WIDGET, | |
2907 XmNtopWidget, XtParent(toolBar), | |
2908 NULL); | |
2909 XtVaSetValues(textAreaForm, | |
2910 XmNtopAttachment, XmATTACH_WIDGET, | |
2911 XmNtopWidget, tabLine, | |
2912 NULL); | |
2913 } | |
2914 else | |
2915 #endif | |
2916 XtVaSetValues(textAreaForm, | |
2917 XmNtopAttachment, XmATTACH_WIDGET, | |
2918 XmNtopWidget, XtParent(toolBar), | |
2919 NULL); | |
7 | 2920 if (XtIsManaged(menuBar)) |
2921 XtVaSetValues(XtParent(toolBar), | |
2922 XmNtopAttachment, XmATTACH_WIDGET, | |
2923 XmNtopWidget, menuBar, | |
2924 NULL); | |
2925 else | |
2926 XtVaSetValues(XtParent(toolBar), | |
2927 XmNtopAttachment, XmATTACH_FORM, | |
2928 NULL); | |
2929 } | |
2930 else | |
2931 { | |
2932 gui.toolbar_height = 0; | |
2933 if (XtIsManaged(menuBar)) | |
819 | 2934 { |
2935 #ifdef FEAT_GUI_TABLINE | |
2936 if (showing_tabline) | |
2937 { | |
2938 XtVaSetValues(tabLine, | |
2939 XmNtopAttachment, XmATTACH_WIDGET, | |
2940 XmNtopWidget, menuBar, | |
2941 NULL); | |
2942 XtVaSetValues(textAreaForm, | |
2943 XmNtopAttachment, XmATTACH_WIDGET, | |
2944 XmNtopWidget, tabLine, | |
2945 NULL); | |
2946 } | |
2947 else | |
2948 #endif | |
2949 XtVaSetValues(textAreaForm, | |
2950 XmNtopAttachment, XmATTACH_WIDGET, | |
2951 XmNtopWidget, menuBar, | |
2952 NULL); | |
2953 } | |
7 | 2954 else |
819 | 2955 { |
2956 #ifdef FEAT_GUI_TABLINE | |
2957 if (showing_tabline) | |
2958 { | |
2959 XtVaSetValues(tabLine, | |
2960 XmNtopAttachment, XmATTACH_FORM, | |
2961 NULL); | |
2962 XtVaSetValues(textAreaForm, | |
2963 XmNtopAttachment, XmATTACH_WIDGET, | |
2964 XmNtopWidget, tabLine, | |
2965 NULL); | |
2966 } | |
2967 else | |
2968 #endif | |
2969 XtVaSetValues(textAreaForm, | |
2970 XmNtopAttachment, XmATTACH_FORM, | |
2971 NULL); | |
2972 } | |
7 | 2973 |
2974 XtUnmanageChild(XtParent(toolBar)); | |
2975 } | |
811 | 2976 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
7 | 2977 } |
2978 | |
2979 /* | |
2980 * A toolbar button has been pushed; now reset the input focus | |
2981 * such that the user can type page up/down etc. and have the | |
2982 * input go to the editor window, not the button | |
2983 */ | |
2984 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2985 reset_focus(void) |
7 | 2986 { |
2987 if (textArea != NULL) | |
2988 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT); | |
2989 } | |
2990 | |
2991 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
2992 gui_mch_compute_toolbar_height(void) |
7 | 2993 { |
48 | 2994 Dimension borders; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2995 Dimension height; // total Toolbar height |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2996 Dimension whgt; // height of each widget |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2997 WidgetList children; // list of toolBar's children |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2998 Cardinal numChildren; // how many children toolBar has |
7 | 2999 int i; |
3000 | |
48 | 3001 borders = 0; |
7 | 3002 height = 0; |
3003 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3004 { // get height of XmFrame parent |
48 | 3005 Dimension fst; |
3006 Dimension fmh; | |
3007 Dimension tst; | |
3008 Dimension tmh; | |
3009 | |
7 | 3010 XtVaGetValues(toolBarFrame, |
48 | 3011 XmNshadowThickness, &fst, |
3012 XmNmarginHeight, &fmh, | |
7 | 3013 NULL); |
48 | 3014 borders += fst + fmh; |
7 | 3015 XtVaGetValues(toolBar, |
48 | 3016 XmNshadowThickness, &tst, |
3017 XmNmarginHeight, &tmh, | |
7 | 3018 XmNchildren, &children, |
3019 XmNnumChildren, &numChildren, NULL); | |
48 | 3020 borders += tst + tmh; |
1887 | 3021 for (i = 0; i < (int)numChildren; i++) |
7 | 3022 { |
3023 whgt = 0; | |
3024 XtVaGetValues(children[i], XmNheight, &whgt, NULL); | |
3025 if (height < whgt) | |
3026 height = whgt; | |
3027 } | |
3028 } | |
48 | 3029 #ifdef LESSTIF_VERSION |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3030 // Hack: When starting up we get wrong dimensions. |
48 | 3031 if (height < 10) |
3032 height = 24; | |
3033 #endif | |
3034 | |
3035 return (int)(height + (borders << 1)); | |
7 | 3036 } |
3037 | |
161 | 3038 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3039 motif_get_toolbar_colors( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3040 Pixel *bgp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3041 Pixel *fgp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3042 Pixel *bsp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3043 Pixel *tsp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3044 Pixel *hsp) |
161 | 3045 { |
3046 XtVaGetValues(toolBar, | |
856 | 3047 XmNbackground, bgp, |
3048 XmNforeground, fgp, | |
3049 XmNbottomShadowColor, bsp, | |
3050 XmNtopShadowColor, tsp, | |
3051 XmNhighlightColor, hsp, | |
3052 NULL); | |
161 | 3053 } |
7 | 3054 #endif |
3055 | |
819 | 3056 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3057 /* | |
3058 * Show or hide the tabline. | |
3059 */ | |
3060 void | |
3061 gui_mch_show_tabline(int showit) | |
3062 { | |
3063 if (tabLine == (Widget)0) | |
3064 return; | |
3065 | |
3066 if (!showit != !showing_tabline) | |
3067 { | |
3068 if (showit) | |
3069 { | |
3070 XtManageChild(tabLine); | |
3071 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller")); | |
824 | 3072 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext")); |
3073 XtUnmanageChild(XtNameToWidget(tabLine, | |
3074 "MinorTabScrollerPrevious")); | |
819 | 3075 #ifdef FEAT_MENU |
3076 # ifdef FEAT_TOOLBAR | |
3077 if (XtIsManaged(XtParent(toolBar))) | |
3078 XtVaSetValues(tabLine, | |
3079 XmNtopAttachment, XmATTACH_WIDGET, | |
3080 XmNtopWidget, XtParent(toolBar), NULL); | |
3081 else | |
3082 # endif | |
3083 if (XtIsManaged(menuBar)) | |
3084 XtVaSetValues(tabLine, | |
3085 XmNtopAttachment, XmATTACH_WIDGET, | |
3086 XmNtopWidget, menuBar, NULL); | |
3087 else | |
3088 #endif | |
3089 XtVaSetValues(tabLine, | |
3090 XmNtopAttachment, XmATTACH_FORM, NULL); | |
3091 XtVaSetValues(textAreaForm, | |
3092 XmNtopAttachment, XmATTACH_WIDGET, | |
3093 XmNtopWidget, tabLine, | |
3094 NULL); | |
3095 } | |
3096 else | |
3097 { | |
3098 XtUnmanageChild(tabLine); | |
3099 #ifdef FEAT_MENU | |
3100 # ifdef FEAT_TOOLBAR | |
3101 if (XtIsManaged(XtParent(toolBar))) | |
3102 XtVaSetValues(textAreaForm, | |
3103 XmNtopAttachment, XmATTACH_WIDGET, | |
3104 XmNtopWidget, XtParent(toolBar), NULL); | |
3105 else | |
3106 # endif | |
3107 if (XtIsManaged(menuBar)) | |
3108 XtVaSetValues(textAreaForm, | |
3109 XmNtopAttachment, XmATTACH_WIDGET, | |
3110 XmNtopWidget, menuBar, NULL); | |
3111 else | |
3112 #endif | |
3113 XtVaSetValues(textAreaForm, | |
3114 XmNtopAttachment, XmATTACH_FORM, NULL); | |
3115 } | |
3116 showing_tabline = showit; | |
3117 } | |
3118 } | |
3119 | |
3120 /* | |
3121 * Return TRUE when tabline is displayed. | |
3122 */ | |
3123 int | |
3124 gui_mch_showing_tabline(void) | |
3125 { | |
3126 return tabLine != (Widget)0 && showing_tabline; | |
3127 } | |
3128 | |
3129 /* | |
3130 * Update the labels of the tabline. | |
3131 */ | |
3132 void | |
3133 gui_mch_update_tabline(void) | |
3134 { | |
3135 tabpage_T *tp; | |
3136 int nr = 1, n; | |
3137 Arg args[10]; | |
3138 int curtabidx = 0, currentpage; | |
3139 Widget tab; | |
3140 XmNotebookPageInfo page_info; | |
3141 XmNotebookPageStatus page_status; | |
3142 int last_page, tab_count; | |
824 | 3143 XmString label_str; |
3144 char *label_cstr; | |
844 | 3145 BalloonEval *beval; |
819 | 3146 |
3147 if (tabLine == (Widget)0) | |
3148 return; | |
3149 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3150 // Add a label for each tab page. They all contain the same text area. |
819 | 3151 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) |
3152 { | |
3153 if (tp == curtab) | |
3154 curtabidx = nr; | |
3155 | |
3156 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info); | |
3157 if (page_status == XmPAGE_INVALID | |
844 | 3158 || page_info.major_tab_widget == (Widget)0) |
819 | 3159 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3160 // Add the tab |
819 | 3161 n = 0; |
3162 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++; | |
3163 XtSetArg(args[n], XmNtraversalOn, False); n++; | |
3164 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++; | |
3165 XtSetArg(args[n], XmNhighlightThickness, 1); n++; | |
3166 XtSetArg(args[n], XmNshadowThickness , 1); n++; | |
3167 tab = XmCreatePushButton(tabLine, "-Empty-", args, n); | |
3168 XtManageChild(tab); | |
844 | 3169 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb, |
3170 NULL); | |
3171 XtVaSetValues(tab, XmNuserData, beval, NULL); | |
819 | 3172 } |
3173 else | |
3174 tab = page_info.major_tab_widget; | |
3175 | |
3176 XtVaSetValues(tab, XmNpageNumber, nr, NULL); | |
824 | 3177 |
3178 /* | |
3179 * Change the label text only if it is different | |
3180 */ | |
3181 XtVaGetValues(tab, XmNlabelString, &label_str, NULL); | |
3182 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr)) | |
3183 { | |
839 | 3184 get_tabline_label(tp, FALSE); |
3185 if (STRCMP(label_cstr, NameBuff) != 0) | |
3186 { | |
824 | 3187 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString, |
3188 NameBuff, STRLEN(NameBuff) + 1, NULL); | |
3189 /* | |
3190 * Force a resize of the tab label button | |
3191 */ | |
3192 XtUnmanageChild(tab); | |
3193 XtManageChild(tab); | |
3194 } | |
3195 XtFree(label_cstr); | |
3196 } | |
819 | 3197 } |
3198 | |
3199 tab_count = nr - 1; | |
3200 | |
3201 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL); | |
3202 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3203 // Remove any old labels. |
819 | 3204 while (nr <= last_page) |
3205 { | |
3206 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID | |
3207 && page_info.page_number == nr | |
3208 && page_info.major_tab_widget != (Widget)0) | |
3209 { | |
844 | 3210 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL); |
3211 if (beval != NULL) | |
3212 gui_mch_destroy_beval_area(beval); | |
819 | 3213 XtUnmanageChild(page_info.major_tab_widget); |
3214 XtDestroyWidget(page_info.major_tab_widget); | |
3215 } | |
3216 nr++; | |
3217 } | |
3218 | |
3219 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL); | |
3220 | |
3221 XtVaGetValues(tabLine, XmNcurrentPageNumber, ¤tpage, NULL); | |
3222 if (currentpage != curtabidx) | |
3223 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL); | |
3224 } | |
3225 | |
3226 /* | |
3227 * Set the current tab to "nr". First tab is 1. | |
3228 */ | |
3229 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3230 gui_mch_set_curtab(int nr) |
819 | 3231 { |
3232 int currentpage; | |
3233 | |
3234 if (tabLine == (Widget)0) | |
3235 return; | |
3236 | |
3237 XtVaGetValues(tabLine, XmNcurrentPageNumber, ¤tpage, NULL); | |
3238 if (currentpage != nr) | |
3239 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL); | |
3240 } | |
3241 #endif | |
3242 | |
7 | 3243 /* |
3244 * Set the colors of Widget "id" to the menu colors. | |
3245 */ | |
3246 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3247 gui_motif_menu_colors(Widget id) |
7 | 3248 { |
3249 if (gui.menu_bg_pixel != INVALCOLOR) | |
3250 #if (XmVersion >= 1002) | |
3251 XmChangeColor(id, gui.menu_bg_pixel); | |
3252 #else | |
3253 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL); | |
3254 #endif | |
3255 if (gui.menu_fg_pixel != INVALCOLOR) | |
3256 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL); | |
3257 } | |
3258 | |
3259 /* | |
3260 * Set the colors of Widget "id" to the scrollbar colors. | |
3261 */ | |
3262 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3263 gui_motif_scroll_colors(Widget id) |
7 | 3264 { |
3265 if (gui.scroll_bg_pixel != INVALCOLOR) | |
3266 #if (XmVersion >= 1002) | |
3267 XmChangeColor(id, gui.scroll_bg_pixel); | |
3268 #else | |
3269 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL); | |
3270 #endif | |
3271 if (gui.scroll_fg_pixel != INVALCOLOR) | |
3272 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL); | |
3273 } | |
3274 | |
3275 /* | |
3276 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font. | |
3277 */ | |
44 | 3278 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3279 gui_motif_menu_fontlist(Widget id UNUSED) |
7 | 3280 { |
44 | 3281 #ifdef FEAT_MENU |
7 | 3282 #ifdef FONTSET_ALWAYS |
3283 if (gui.menu_fontset != NOFONTSET) | |
3284 { | |
3285 XmFontList fl; | |
3286 | |
3287 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset); | |
3288 if (fl != NULL) | |
3289 { | |
3290 if (XtIsManaged(id)) | |
3291 { | |
3292 XtUnmanageChild(id); | |
3293 XtVaSetValues(id, XmNfontList, fl, NULL); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3294 // We should force the widget to recalculate its |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3295 // geometry now. |
7 | 3296 XtManageChild(id); |
3297 } | |
3298 else | |
3299 XtVaSetValues(id, XmNfontList, fl, NULL); | |
3300 XmFontListFree(fl); | |
3301 } | |
3302 } | |
3303 #else | |
3304 if (gui.menu_font != NOFONT) | |
3305 { | |
3306 XmFontList fl; | |
3307 | |
3308 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font); | |
3309 if (fl != NULL) | |
3310 { | |
3311 if (XtIsManaged(id)) | |
3312 { | |
3313 XtUnmanageChild(id); | |
3314 XtVaSetValues(id, XmNfontList, fl, NULL); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3315 // We should force the widget to recalculate its |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3316 // geometry now. |
7 | 3317 XtManageChild(id); |
3318 } | |
3319 else | |
3320 XtVaSetValues(id, XmNfontList, fl, NULL); | |
3321 XmFontListFree(fl); | |
3322 } | |
3323 } | |
3324 #endif | |
44 | 3325 #endif |
7 | 3326 } |
3327 | |
3328 | |
3329 /* | |
3330 * We don't create it twice for the sake of speed. | |
3331 */ | |
3332 | |
3333 typedef struct _SharedFindReplace | |
3334 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3335 Widget dialog; // the main dialog widget |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3336 Widget wword; // 'Exact match' check button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3337 Widget mcase; // 'match case' check button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3338 Widget up; // search direction 'Up' radio button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3339 Widget down; // search direction 'Down' radio button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3340 Widget what; // 'Find what' entry text widget |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3341 Widget with; // 'Replace with' entry text widget |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3342 Widget find; // 'Find Next' action button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3343 Widget replace; // 'Replace With' action button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3344 Widget all; // 'Replace All' action button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3345 Widget undo; // 'Undo' action button |
7 | 3346 |
3347 Widget cancel; | |
3348 } SharedFindReplace; | |
3349 | |
1887 | 3350 static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; |
3351 static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; | |
7 | 3352 |
3353 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3354 find_replace_destroy_callback( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3355 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3356 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3357 XtPointer call_data UNUSED) |
7 | 3358 { |
3359 SharedFindReplace *cd = (SharedFindReplace *)client_data; | |
3360 | |
48 | 3361 if (cd != NULL) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3362 // suppress_dialog_mnemonics(cd->dialog); |
7 | 3363 cd->dialog = (Widget)0; |
3364 } | |
3365 | |
3366 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3367 find_replace_dismiss_callback( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3368 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3369 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3370 XtPointer call_data UNUSED) |
7 | 3371 { |
3372 SharedFindReplace *cd = (SharedFindReplace *)client_data; | |
3373 | |
3374 if (cd != NULL) | |
3375 XtUnmanageChild(cd->dialog); | |
3376 } | |
3377 | |
3378 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3379 entry_activate_callback( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3380 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3381 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3382 XtPointer call_data UNUSED) |
7 | 3383 { |
3384 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT); | |
3385 } | |
3386 | |
3387 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3388 find_replace_callback( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3389 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3390 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3391 XtPointer call_data UNUSED) |
7 | 3392 { |
3393 long_u flags = (long_u)client_data; | |
3394 char *find_text, *repl_text; | |
3395 Boolean direction_down = TRUE; | |
3396 Boolean wword; | |
3397 Boolean mcase; | |
3398 SharedFindReplace *sfr; | |
3399 | |
3400 if (flags == FRD_UNDO) | |
3401 { | |
3402 char_u *save_cpo = p_cpo; | |
3403 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3404 // No need to be Vi compatible here. |
23501
60ba9ec58fd9
patch 8.2.2293: build failure with Motif
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
3405 p_cpo = empty_option; |
7 | 3406 u_undo(1); |
3407 p_cpo = save_cpo; | |
3408 gui_update_screen(); | |
3409 return; | |
3410 } | |
3411 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3412 // Get the search/replace strings from the dialog |
7 | 3413 if (flags == FRD_FINDNEXT) |
3414 { | |
3415 repl_text = NULL; | |
3416 sfr = &find_widgets; | |
3417 } | |
3418 else | |
3419 { | |
3420 repl_text = XmTextFieldGetString(repl_widgets.with); | |
3421 sfr = &repl_widgets; | |
3422 } | |
3423 find_text = XmTextFieldGetString(sfr->what); | |
3424 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL); | |
3425 XtVaGetValues(sfr->wword, XmNset, &wword, NULL); | |
3426 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL); | |
3427 if (wword) | |
3428 flags |= FRD_WHOLE_WORD; | |
3429 if (mcase) | |
3430 flags |= FRD_MATCH_CASE; | |
3431 | |
3432 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text, | |
3433 direction_down); | |
3434 | |
3435 if (find_text != NULL) | |
3436 XtFree(find_text); | |
3437 if (repl_text != NULL) | |
3438 XtFree(repl_text); | |
3439 } | |
3440 | |
3441 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3442 find_replace_keypress( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3443 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3444 SharedFindReplace *frdp, |
24266
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
3445 XKeyEvent *event, |
982786f8454d
patch 8.2.2674: Motif: cancelling the font dialog resets the font
Bram Moolenaar <Bram@vim.org>
parents:
23501
diff
changeset
|
3446 Boolean *b UNUSED) |
7 | 3447 { |
3448 KeySym keysym; | |
3449 | |
3450 if (frdp == NULL) | |
3451 return; | |
3452 | |
3453 keysym = XLookupKeysym(event, 0); | |
3454 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3455 // the scape key pops the whole dialog down |
7 | 3456 if (keysym == XK_Escape) |
3457 XtUnmanageChild(frdp->dialog); | |
3458 } | |
3459 | |
3460 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3461 set_label(Widget w, char *label) |
44 | 3462 { |
3463 XmString str; | |
3464 char_u *p, *next; | |
3465 KeySym mnemonic = NUL; | |
3466 | |
3467 if (!w) | |
3468 return; | |
3469 | |
4960
27b008d5b7ac
updated for version 7.3.1225
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3470 p = vim_strsave((char_u *)label); |
44 | 3471 if (p == NULL) |
3472 return; | |
3473 for (next = p; *next; ++next) | |
3474 { | |
3475 if (*next == DLG_HOTKEY_CHAR) | |
3476 { | |
3477 int len = STRLEN(next); | |
3478 | |
3479 if (len > 0) | |
3480 { | |
3481 mch_memmove(next, next + 1, len); | |
3482 mnemonic = next[0]; | |
3483 } | |
3484 } | |
3485 } | |
3486 | |
3487 str = XmStringCreateSimple((char *)p); | |
3488 vim_free(p); | |
3489 if (str) | |
3490 { | |
3491 XtVaSetValues(w, | |
3492 XmNlabelString, str, | |
3493 XmNmnemonic, mnemonic, | |
3494 NULL); | |
3495 XmStringFree(str); | |
3496 } | |
3497 gui_motif_menu_fontlist(w); | |
3498 } | |
3499 | |
3500 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3501 find_replace_dialog_create(char_u *arg, int do_replace) |
7 | 3502 { |
3503 SharedFindReplace *frdp; | |
3504 Widget separator; | |
3505 Widget input_form; | |
3506 Widget button_form; | |
3507 Widget toggle_form; | |
3508 Widget frame; | |
3509 XmString str; | |
3510 int n; | |
3511 Arg args[6]; | |
3512 int wword = FALSE; | |
3513 int mcase = !p_ic; | |
3514 Dimension width; | |
3515 Dimension widest; | |
3516 char_u *entry_text; | |
3517 | |
3518 frdp = do_replace ? &repl_widgets : &find_widgets; | |
3519 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3520 // Get the search string to use. |
7 | 3521 entry_text = get_find_dialog_text(arg, &wword, &mcase); |
3522 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3523 // If the dialog already exists, just raise it. |
7 | 3524 if (frdp->dialog) |
3525 { | |
44 | 3526 gui_motif_synch_fonts(); |
3527 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3528 // If the window is already up, just pop it to the top |
7 | 3529 if (XtIsManaged(frdp->dialog)) |
3530 XMapRaised(XtDisplay(frdp->dialog), | |
3531 XtWindow(XtParent(frdp->dialog))); | |
3532 else | |
3533 XtManageChild(frdp->dialog); | |
3534 XtPopup(XtParent(frdp->dialog), XtGrabNone); | |
3535 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT); | |
3536 | |
3537 if (entry_text != NULL) | |
3538 XmTextFieldSetString(frdp->what, (char *)entry_text); | |
3539 vim_free(entry_text); | |
3540 | |
3541 XtVaSetValues(frdp->wword, XmNset, wword, NULL); | |
3542 return; | |
3543 } | |
3544 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3545 // Create a fresh new dialog window |
7 | 3546 if (do_replace) |
3547 str = XmStringCreateSimple(_("VIM - Search and Replace...")); | |
3548 else | |
3549 str = XmStringCreateSimple(_("VIM - Search...")); | |
3550 | |
3551 n = 0; | |
3552 XtSetArg(args[n], XmNautoUnmanage, False); n++; | |
3553 XtSetArg(args[n], XmNnoResize, True); n++; | |
3554 XtSetArg(args[n], XmNdialogTitle, str); n++; | |
3555 | |
3556 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n); | |
3557 XmStringFree(str); | |
3558 XtAddCallback(frdp->dialog, XmNdestroyCallback, | |
3559 find_replace_destroy_callback, frdp); | |
3560 | |
3561 button_form = XtVaCreateWidget("buttonForm", | |
3562 xmFormWidgetClass, frdp->dialog, | |
3563 XmNrightAttachment, XmATTACH_FORM, | |
3564 XmNrightOffset, 4, | |
3565 XmNtopAttachment, XmATTACH_FORM, | |
3566 XmNtopOffset, 4, | |
3567 XmNbottomAttachment, XmATTACH_FORM, | |
3568 XmNbottomOffset, 4, | |
3569 NULL); | |
3570 | |
3571 frdp->find = XtVaCreateManagedWidget("findButton", | |
3572 xmPushButtonWidgetClass, button_form, | |
3573 XmNsensitive, True, | |
3574 XmNtopAttachment, XmATTACH_FORM, | |
3575 XmNleftAttachment, XmATTACH_FORM, | |
3576 XmNrightAttachment, XmATTACH_FORM, | |
3577 NULL); | |
44 | 3578 set_label(frdp->find, _("Find &Next")); |
7 | 3579 |
3580 XtAddCallback(frdp->find, XmNactivateCallback, | |
3581 find_replace_callback, | |
1522 | 3582 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT)); |
7 | 3583 |
3584 if (do_replace) | |
3585 { | |
3586 frdp->replace = XtVaCreateManagedWidget("replaceButton", | |
3587 xmPushButtonWidgetClass, button_form, | |
3588 XmNtopAttachment, XmATTACH_WIDGET, | |
3589 XmNtopWidget, frdp->find, | |
3590 XmNleftAttachment, XmATTACH_FORM, | |
3591 XmNrightAttachment, XmATTACH_FORM, | |
3592 NULL); | |
44 | 3593 set_label(frdp->replace, _("&Replace")); |
7 | 3594 XtAddCallback(frdp->replace, XmNactivateCallback, |
3595 find_replace_callback, (XtPointer)FRD_REPLACE); | |
3596 | |
3597 frdp->all = XtVaCreateManagedWidget("replaceAllButton", | |
3598 xmPushButtonWidgetClass, button_form, | |
3599 XmNtopAttachment, XmATTACH_WIDGET, | |
3600 XmNtopWidget, frdp->replace, | |
3601 XmNleftAttachment, XmATTACH_FORM, | |
3602 XmNrightAttachment, XmATTACH_FORM, | |
3603 NULL); | |
44 | 3604 set_label(frdp->all, _("Replace &All")); |
7 | 3605 XtAddCallback(frdp->all, XmNactivateCallback, |
3606 find_replace_callback, (XtPointer)FRD_REPLACEALL); | |
3607 | |
3608 frdp->undo = XtVaCreateManagedWidget("undoButton", | |
3609 xmPushButtonWidgetClass, button_form, | |
3610 XmNtopAttachment, XmATTACH_WIDGET, | |
3611 XmNtopWidget, frdp->all, | |
3612 XmNleftAttachment, XmATTACH_FORM, | |
3613 XmNrightAttachment, XmATTACH_FORM, | |
3614 NULL); | |
44 | 3615 set_label(frdp->undo, _("&Undo")); |
7 | 3616 XtAddCallback(frdp->undo, XmNactivateCallback, |
3617 find_replace_callback, (XtPointer)FRD_UNDO); | |
3618 } | |
3619 | |
3620 frdp->cancel = XtVaCreateManagedWidget("closeButton", | |
3621 xmPushButtonWidgetClass, button_form, | |
3622 XmNleftAttachment, XmATTACH_FORM, | |
3623 XmNrightAttachment, XmATTACH_FORM, | |
3624 XmNbottomAttachment, XmATTACH_FORM, | |
3625 NULL); | |
44 | 3626 set_label(frdp->cancel, _("&Cancel")); |
7 | 3627 XtAddCallback(frdp->cancel, XmNactivateCallback, |
3628 find_replace_dismiss_callback, frdp); | |
44 | 3629 gui_motif_menu_fontlist(frdp->cancel); |
7 | 3630 |
3631 XtManageChild(button_form); | |
3632 | |
3633 n = 0; | |
3634 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; | |
3635 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++; | |
3636 XtSetArg(args[n], XmNrightWidget, button_form); n++; | |
3637 XtSetArg(args[n], XmNrightOffset, 4); n++; | |
3638 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; | |
3639 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; | |
3640 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n); | |
3641 XtManageChild(separator); | |
3642 | |
3643 input_form = XtVaCreateWidget("inputForm", | |
3644 xmFormWidgetClass, frdp->dialog, | |
3645 XmNleftAttachment, XmATTACH_FORM, | |
3646 XmNleftOffset, 4, | |
3647 XmNrightAttachment, XmATTACH_WIDGET, | |
3648 XmNrightWidget, separator, | |
3649 XmNrightOffset, 4, | |
3650 XmNtopAttachment, XmATTACH_FORM, | |
3651 XmNtopOffset, 4, | |
3652 NULL); | |
3653 | |
3654 { | |
3655 Widget label_what; | |
3656 Widget label_with = (Widget)0; | |
3657 | |
3658 str = XmStringCreateSimple(_("Find what:")); | |
3659 label_what = XtVaCreateManagedWidget("whatLabel", | |
3660 xmLabelGadgetClass, input_form, | |
3661 XmNlabelString, str, | |
3662 XmNleftAttachment, XmATTACH_FORM, | |
3663 XmNtopAttachment, XmATTACH_FORM, | |
3664 XmNtopOffset, 4, | |
3665 NULL); | |
3666 XmStringFree(str); | |
44 | 3667 gui_motif_menu_fontlist(label_what); |
7 | 3668 |
3669 frdp->what = XtVaCreateManagedWidget("whatText", | |
3670 xmTextFieldWidgetClass, input_form, | |
3671 XmNtopAttachment, XmATTACH_FORM, | |
3672 XmNrightAttachment, XmATTACH_FORM, | |
3673 XmNleftAttachment, XmATTACH_FORM, | |
3674 NULL); | |
3675 | |
3676 if (do_replace) | |
3677 { | |
3678 frdp->with = XtVaCreateManagedWidget("withText", | |
3679 xmTextFieldWidgetClass, input_form, | |
3680 XmNtopAttachment, XmATTACH_WIDGET, | |
3681 XmNtopWidget, frdp->what, | |
3682 XmNtopOffset, 4, | |
3683 XmNleftAttachment, XmATTACH_FORM, | |
3684 XmNrightAttachment, XmATTACH_FORM, | |
3685 XmNbottomAttachment, XmATTACH_FORM, | |
3686 NULL); | |
3687 | |
3688 XtAddCallback(frdp->with, XmNactivateCallback, | |
3689 find_replace_callback, (XtPointer) FRD_R_FINDNEXT); | |
3690 | |
3691 str = XmStringCreateSimple(_("Replace with:")); | |
3692 label_with = XtVaCreateManagedWidget("withLabel", | |
3693 xmLabelGadgetClass, input_form, | |
3694 XmNlabelString, str, | |
3695 XmNleftAttachment, XmATTACH_FORM, | |
3696 XmNtopAttachment, XmATTACH_WIDGET, | |
3697 XmNtopWidget, frdp->what, | |
3698 XmNtopOffset, 4, | |
3699 XmNbottomAttachment, XmATTACH_FORM, | |
3700 NULL); | |
3701 XmStringFree(str); | |
44 | 3702 gui_motif_menu_fontlist(label_with); |
7 | 3703 |
3704 /* | |
3705 * Make the entry activation only change the input focus onto the | |
3706 * with item. | |
3707 */ | |
3708 XtAddCallback(frdp->what, XmNactivateCallback, | |
3709 entry_activate_callback, frdp->with); | |
3710 XtAddEventHandler(frdp->with, KeyPressMask, False, | |
3711 (XtEventHandler)find_replace_keypress, | |
3712 (XtPointer) frdp); | |
3713 | |
3714 } | |
3715 else | |
3716 { | |
3717 /* | |
3718 * Make the entry activation do the search. | |
3719 */ | |
3720 XtAddCallback(frdp->what, XmNactivateCallback, | |
3721 find_replace_callback, (XtPointer)FRD_FINDNEXT); | |
3722 } | |
3723 XtAddEventHandler(frdp->what, KeyPressMask, False, | |
3724 (XtEventHandler)find_replace_keypress, | |
3725 (XtPointer)frdp); | |
3726 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3727 // Get the maximum width between the label widgets and line them up. |
7 | 3728 n = 0; |
3729 XtSetArg(args[n], XmNwidth, &width); n++; | |
3730 XtGetValues(label_what, args, n); | |
3731 widest = width; | |
3732 if (do_replace) | |
3733 { | |
3734 XtGetValues(label_with, args, n); | |
3735 if (width > widest) | |
3736 widest = width; | |
3737 } | |
3738 | |
3739 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL); | |
3740 if (do_replace) | |
3741 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL); | |
3742 | |
3743 } | |
3744 | |
3745 XtManageChild(input_form); | |
3746 | |
3747 { | |
3748 Widget radio_box; | |
44 | 3749 Widget w; |
7 | 3750 |
3751 frame = XtVaCreateWidget("directionFrame", | |
3752 xmFrameWidgetClass, frdp->dialog, | |
3753 XmNtopAttachment, XmATTACH_WIDGET, | |
3754 XmNtopWidget, input_form, | |
3755 XmNtopOffset, 4, | |
3756 XmNbottomAttachment, XmATTACH_FORM, | |
3757 XmNbottomOffset, 4, | |
3758 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET, | |
3759 XmNrightWidget, input_form, | |
3760 NULL); | |
3761 | |
3762 str = XmStringCreateSimple(_("Direction")); | |
44 | 3763 w = XtVaCreateManagedWidget("directionFrameLabel", |
7 | 3764 xmLabelGadgetClass, frame, |
3765 XmNlabelString, str, | |
3766 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, | |
3767 XmNchildType, XmFRAME_TITLE_CHILD, | |
3768 NULL); | |
3769 XmStringFree(str); | |
44 | 3770 gui_motif_menu_fontlist(w); |
7 | 3771 |
3772 radio_box = XmCreateRadioBox(frame, "radioBox", | |
3773 (ArgList)NULL, 0); | |
3774 | |
3775 str = XmStringCreateSimple( _("Up")); | |
3776 frdp->up = XtVaCreateManagedWidget("upRadioButton", | |
3777 xmToggleButtonGadgetClass, radio_box, | |
3778 XmNlabelString, str, | |
3779 XmNset, False, | |
3780 NULL); | |
3781 XmStringFree(str); | |
44 | 3782 gui_motif_menu_fontlist(frdp->up); |
7 | 3783 |
3784 str = XmStringCreateSimple(_("Down")); | |
3785 frdp->down = XtVaCreateManagedWidget("downRadioButton", | |
3786 xmToggleButtonGadgetClass, radio_box, | |
3787 XmNlabelString, str, | |
3788 XmNset, True, | |
3789 NULL); | |
3790 XmStringFree(str); | |
44 | 3791 gui_motif_menu_fontlist(frdp->down); |
7 | 3792 |
3793 XtManageChild(radio_box); | |
3794 XtManageChild(frame); | |
3795 } | |
3796 | |
3797 toggle_form = XtVaCreateWidget("toggleForm", | |
3798 xmFormWidgetClass, frdp->dialog, | |
3799 XmNleftAttachment, XmATTACH_FORM, | |
3800 XmNleftOffset, 4, | |
3801 XmNrightAttachment, XmATTACH_WIDGET, | |
3802 XmNrightWidget, frame, | |
3803 XmNrightOffset, 4, | |
3804 XmNtopAttachment, XmATTACH_WIDGET, | |
3805 XmNtopWidget, input_form, | |
3806 XmNtopOffset, 4, | |
3807 XmNbottomAttachment, XmATTACH_FORM, | |
3808 XmNbottomOffset, 4, | |
3809 NULL); | |
3810 | |
3811 str = XmStringCreateSimple(_("Match whole word only")); | |
3812 frdp->wword = XtVaCreateManagedWidget("wordToggle", | |
3813 xmToggleButtonGadgetClass, toggle_form, | |
3814 XmNlabelString, str, | |
3815 XmNtopAttachment, XmATTACH_FORM, | |
3816 XmNtopOffset, 4, | |
3817 XmNleftAttachment, XmATTACH_FORM, | |
3818 XmNleftOffset, 4, | |
3819 XmNset, wword, | |
3820 NULL); | |
3821 XmStringFree(str); | |
3822 | |
3823 str = XmStringCreateSimple(_("Match case")); | |
3824 frdp->mcase = XtVaCreateManagedWidget("caseToggle", | |
3825 xmToggleButtonGadgetClass, toggle_form, | |
3826 XmNlabelString, str, | |
3827 XmNleftAttachment, XmATTACH_FORM, | |
3828 XmNleftOffset, 4, | |
3829 XmNtopAttachment, XmATTACH_WIDGET, | |
3830 XmNtopWidget, frdp->wword, | |
3831 XmNtopOffset, 4, | |
3832 XmNset, mcase, | |
3833 NULL); | |
3834 XmStringFree(str); | |
44 | 3835 gui_motif_menu_fontlist(frdp->wword); |
3836 gui_motif_menu_fontlist(frdp->mcase); | |
7 | 3837 |
3838 XtManageChild(toggle_form); | |
3839 | |
3840 if (entry_text != NULL) | |
3841 XmTextFieldSetString(frdp->what, (char *)entry_text); | |
3842 vim_free(entry_text); | |
3843 | |
44 | 3844 gui_motif_synch_fonts(); |
3845 | |
3846 manage_centered(frdp->dialog); | |
3847 activate_dialog_mnemonics(frdp->dialog); | |
7 | 3848 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT); |
3849 } | |
3850 | |
3851 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3852 gui_mch_find_dialog(exarg_T *eap) |
7 | 3853 { |
3854 if (!gui.in_use) | |
3855 return; | |
3856 | |
3857 find_replace_dialog_create(eap->arg, FALSE); | |
3858 } | |
3859 | |
3860 | |
3861 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7815
diff
changeset
|
3862 gui_mch_replace_dialog(exarg_T *eap) |
7 | 3863 { |
3864 if (!gui.in_use) | |
3865 return; | |
3866 | |
3867 find_replace_dialog_create(eap->arg, TRUE); | |
3868 } | |
44 | 3869 |
3870 /* | |
26592
9f445e07f766
patch 8.2.3825: various comments could be improved
Bram Moolenaar <Bram@vim.org>
parents:
24266
diff
changeset
|
3871 * Synchronize all gui elements, which are dependent upon the |
44 | 3872 * main text font used. Those are in esp. the find/replace dialogs. |
3873 * If you don't understand why this should be needed, please try to | |
7815
3a96dfb42c55
commit https://github.com/vim/vim/commit/305598b71261265994e2846b4ff4a4d8efade280
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3874 * search for "pi\xea\xb6\xe6" in iso8859-2. |
44 | 3875 */ |
3876 void | |
3877 gui_motif_synch_fonts(void) | |
3878 { | |
3879 SharedFindReplace *frdp; | |
3880 int do_replace; | |
3881 XFontStruct *font; | |
3882 XmFontList font_list; | |
3883 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3884 // FIXME: Unless we find out how to create a XmFontList from a XFontSet, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3885 // we just give up here on font synchronization. |
44 | 3886 font = (XFontStruct *)gui.norm_font; |
3887 if (font == NULL) | |
3888 return; | |
3889 | |
3890 font_list = gui_motif_create_fontlist(font); | |
3891 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3892 // OK this loop is a bit tricky... |
44 | 3893 for (do_replace = 0; do_replace <= 1; ++do_replace) |
3894 { | |
3895 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); | |
3896 if (frdp->dialog) | |
3897 { | |
3898 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL); | |
3899 if (do_replace) | |
3900 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL); | |
3901 } | |
3902 } | |
3903 | |
3904 XmFontListFree(font_list); | |
3905 } |