forked from fvwmorg/fvwm3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menus.c
7566 lines (7088 loc) · 169 KB
/
menus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see: <http://www.gnu.org/licenses/>
*/
/* IMPORTANT NOTE: Do *not* use any constant numbers in this file. All values
* have to be #defined in the section below or in defaults.h to ensure full
* control over the menus. */
/* ---------------------------- included header files ---------------------- */
#include "config.h"
#include <stdio.h>
#include <assert.h>
#include "libs/ftime.h"
#include "libs/fvwmlib.h"
#include "libs/Grab.h"
#include "libs/Parse.h"
#include "libs/ColorUtils.h"
#include "libs/Picture.h"
#include "libs/PictureUtils.h"
#include "libs/Graphics.h"
#include "libs/PictureGraphics.h"
#include "libs/charmap.h"
#include "libs/FEvent.h"
#include "libs/wcontext.h"
#include "fvwm.h"
#include "externs.h"
#include "cmdparser.h"
#include "execcontext.h"
#include "events.h"
#include "eventhandler.h"
#include "eventmask.h"
#include "cursor.h"
#include "functions.h"
#include "commands.h"
#include "misc.h"
#include "screen.h"
#include "colormaps.h"
#include "geometry.h"
#include "move_resize.h"
#include "menudim.h"
#include "menuitem.h"
#include "menuroot.h"
#include "menustyle.h"
#include "bindings.h"
#include "menubindings.h"
#include "menugeometry.h"
#include "menuparameters.h"
#include "menus.h"
#include "libs/FGettext.h"
/* ---------------------------- local definitions -------------------------- */
/* used in float to int arithmetic */
#define ROUNDING_ERROR_TOLERANCE 0.005
/* ---------------------------- local macros ------------------------------- */
#define SCTX_SET_MI(ctx,item) ((ctx).type = SCTX_MENU_ITEM, \
(ctx).menu_item.menu_item = (item))
#define SCTX_GET_MI(ctx) ((ctx).type == SCTX_MENU_ITEM ? \
(ctx).menu_item.menu_item : NULL)
#define SCTX_SET_MR(ctx,root) ((ctx).type = SCTX_MENU_ROOT, \
(ctx).menu_root.menu_root = (root))
#define SCTX_GET_MR(ctx) ((ctx).type == SCTX_MENU_ROOT ? \
(ctx).menu_root.menu_root : NULL)
/* ---------------------------- imports ------------------------------------ */
/* This external is safe. It's written only during startup. */
extern XContext MenuContext;
/* ---------------------------- included code files ------------------------ */
/* ---------------------------- local types -------------------------------- */
/* patch to pass the last popups position hints to popup_func */
typedef struct
{
struct
{
unsigned is_last_menu_pos_hints_valid : 1;
unsigned do_ignore_pos_hints : 1;
unsigned do_warp_title : 1;
} flags;
struct MenuPosHints pos_hints;
} saved_pos_hints;
typedef struct MenuInfo
{
MenuRoot *all;
int n_destroyed_menus;
} MenuInfo;
typedef struct MenuSizingParameters
{
MenuRoot *menu;
/* number of item labels present in the item format */
int used_item_labels;
/* same for mini icons */
int used_mini_icons;
struct
{
int sidepic_width;
MenuItemPartSizesT i;
} max;
struct
{
unsigned is_popup_indicator_used : 1;
} flags;
} MenuSizingParameters;
typedef enum
{
SCTX_MENU_ROOT,
SCTX_MENU_ITEM
} string_context_type_t;
typedef union
{
string_context_type_t type;
struct
{
string_context_type_t type;
MenuRoot *menu_root;
} menu_root;
struct
{
string_context_type_t type;
MenuItem *menu_item;
} menu_item;
} string_context_t;
typedef struct
{
char delimiter;
Bool (*string_handler)(
char *string, char delimiter,
string_context_t *user_data);
} string_def_t;
/* ---------------------------- menu loop types ---------------------------- */
typedef enum
{
MENU_MLOOP_RET_NORMAL,
MENU_MLOOP_RET_LOOP,
MENU_MLOOP_RET_END
} mloop_ret_code_t;
typedef struct
{
unsigned do_popup_immediately : 1;
/* used for delay popups, to just popup the menu */
unsigned do_popup_now : 1;
unsigned do_popdown_now : 1;
/* used for keystrokes, to popup and move to that menu */
unsigned do_popup_and_warp : 1;
unsigned do_force_reposition : 1;
unsigned do_force_popup : 1;
unsigned do_popdown : 1;
unsigned do_popup : 1;
unsigned do_menu : 1;
unsigned do_recycle_event : 1;
unsigned do_propagate_event_into_submenu : 1;
unsigned has_mouse_moved : 1;
unsigned is_off_menu_allowed : 1;
unsigned is_key_press : 1;
unsigned is_item_entered_by_key_press : 1;
unsigned is_motion_faked : 1;
unsigned is_popped_up_by_timeout : 1;
unsigned is_pointer_in_active_item_area : 1;
unsigned is_motion_first : 1;
unsigned is_release_first : 1;
unsigned is_submenu_mapped : 1;
unsigned was_item_unposted : 1;
unsigned is_button_release : 1;
} mloop_flags_t;
typedef struct
{
MenuItem *mi;
MenuRoot *mrMi;
int x_offset;
int popdown_delay_10ms;
int popup_delay_10ms;
} mloop_evh_data_t;
typedef struct
{
MenuRoot *mrPopup;
MenuRoot *mrPopdown;
mloop_flags_t mif;
/* used to reduce network traffic with delayed popup/popdown */
MenuItem *mi_with_popup;
MenuItem *mi_wants_popup;
MenuItem *miRemovedSubmenu;
} mloop_evh_input_t;
/* values that are set once when the menu loop is entered */
typedef struct mloop_static_info_t
{
int x_init;
int y_init;
Time t0;
unsigned int event_mask;
} mloop_static_info_t;
/* ---------------------------- forward declarations ----------------------- */
/* ---------------------------- local variables ---------------------------- */
/* This global is saved and restored every time a function is called that
* might modify them, so we can safely let it live outside a function. */
static saved_pos_hints last_saved_pos_hints;
/* structures for menus */
static MenuInfo Menus;
/* ---------------------------- exported variables (globals) --------------- */
/* ---------------------------- local functions ---------------------------- */
static void __menu_execute_function(const exec_context_t **pexc, char *action)
{
const exec_context_t *exc;
exec_context_changes_t ecc;
int old_emf;
ecc.w.w = ((*pexc)->w.fw) ? FW_W((*pexc)->w.fw) : None;
exc = exc_clone_context(*pexc, &ecc, ECC_W);
old_emf = Scr.flags.is_executing_menu_function;
Scr.flags.is_executing_menu_function = 1;
execute_function(NULL, exc, action, NULL, FUNC_DONT_EXPAND_COMMAND);
Scr.flags.is_executing_menu_function = old_emf;
exc_destroy_context(exc);
/* See if the window has been deleted */
if (!check_if_fvwm_window_exists((*pexc)->w.fw))
{
ecc.w.fw = NULL;
ecc.w.w = None;
ecc.w.wcontext = 0;
exc = exc_clone_context(
*pexc, &ecc, ECC_FW | ECC_W | ECC_WCONTEXT);
exc_destroy_context(*pexc);
*pexc = exc;
}
return;
}
static Bool pointer_in_active_item_area(int x_offset, MenuRoot *mr)
{
float ratio = (float)MST_ACTIVE_AREA_PERCENT(mr) / 100.0;
if (MST_ACTIVE_AREA_PERCENT(mr) >= 100)
{
return False;
}
if (MST_USE_LEFT_SUBMENUS(mr))
{
return (x_offset <=
MR_ITEM_X_OFFSET(mr) + MR_ITEM_WIDTH(mr) -
MR_ITEM_WIDTH(mr) * ratio);
}
else
{
return (x_offset >=
MR_ITEM_X_OFFSET(mr) + MR_ITEM_WIDTH(mr) * ratio);
}
}
static Bool pointer_in_passive_item_area(int x_offset, MenuRoot *mr)
{
float ratio = (float)MST_ACTIVE_AREA_PERCENT(mr) / 100.0;
if (MST_ACTIVE_AREA_PERCENT(mr) >= 100)
{
return False;
}
if (MST_USE_LEFT_SUBMENUS(mr))
{
return (x_offset >=
MR_ITEM_X_OFFSET(mr) + MR_ITEM_WIDTH(mr) * ratio);
}
else
{
return (x_offset <=
MR_ITEM_X_OFFSET(mr) + MR_ITEM_WIDTH(mr) -
MR_ITEM_WIDTH(mr) * ratio);
}
}
/*
* warping functions
*/
static void warp_pointer_to_title(MenuRoot *mr)
{
FWarpPointer(
dpy, 0, MR_WINDOW(mr), 0, 0, 0, 0,
menudim_middle_x_offset(&MR_DIM(mr)),
menuitem_middle_y_offset(MR_FIRST_ITEM(mr), MR_STYLE(mr)));
}
static MenuItem *warp_pointer_to_item(
MenuRoot *mr, MenuItem *mi, Bool do_skip_title)
{
if (do_skip_title)
{
while (MI_NEXT_ITEM(mi) != NULL &&
(!MI_IS_SELECTABLE(mi) || MI_IS_TEAR_OFF_BAR(mi)))
{
/* skip separators, titles and tear off bars until the
* first 'real' item is found */
mi = MI_NEXT_ITEM(mi);
}
}
if (mi == NULL)
{
mi = MR_LAST_ITEM(mr);
}
if (mi == NULL)
{
return mi;
}
FWarpPointer(
dpy, 0, MR_WINDOW(mr), 0, 0, 0, 0,
menudim_middle_x_offset(&MR_DIM(mr)),
menuitem_middle_y_offset(mi, MR_STYLE(mr)));
return mi;
}
/*
* menu animation functions
*/
/* prepares the parameters to be passed to AnimatedMoveOfWindow
* mr - the menu instance that holds the menu item
* fw - the FvwmWindow structure to check against allowed functions */
static void get_menu_repaint_transparent_parameters(
MenuRepaintTransparentParameters *pmrtp, MenuRoot *mr, FvwmWindow *fw)
{
pmrtp->mr = mr;
pmrtp->fw = fw;
return;
}
/* Undo the animation of a menu */
static void animated_move_back(
MenuRoot *mr, Bool do_warp_pointer, FvwmWindow *fw)
{
MenuRepaintTransparentParameters mrtp;
position start;
position end;
if (MR_XANIMATION(mr) == 0)
{
return;
}
if (menu_get_geometry(
mr, &JunkRoot, &start.x, &start.y, &JunkWidth, &JunkHeight,
&JunkBW, &JunkDepth))
{
Bool transparent_bg = False;
/* move it back */
if (ST_HAS_MENU_CSET(MR_STYLE(mr)) &&
CSET_IS_TRANSPARENT(ST_CSET_MENU(MR_STYLE(mr))))
{
transparent_bg = True;
get_menu_repaint_transparent_parameters(
&mrtp, mr, fw);
}
end.x = start.x - MR_XANIMATION(mr);
end.y = start.y;
AnimatedMoveOfWindow(
MR_WINDOW(mr), start, end, do_warp_pointer, -1, NULL,
(transparent_bg)? &mrtp:NULL);
MR_XANIMATION(mr) = 0;
}
return;
}
/* move a menu or a tear-off menu preserving transparency.
* tear-off menus are moved with their frame coordinates. */
static void move_any_menu(
MenuRoot *mr, MenuParameters *pmp, int endX, int endY)
{
if (MR_IS_TEAR_OFF_MENU(mr))
{
float fFull = 1.0;
position start = { -1, -1 };
position end = { endX, endY };
/* this moves the tearoff menu, updating of transparency
* will not be as good as if menu repaint parameters
* are used. */
AnimatedMoveFvwmWindow(
pmp->tear_off_root_menu_window,
FW_W_FRAME(pmp->tear_off_root_menu_window),
start, end, False, 0, &fFull);
}
else
{
int x;
int y;
int JunkDept;
menu_get_geometry(mr, &JunkRoot, &x, &y, &JunkWidth,
&JunkHeight, &JunkBW, &JunkDept);
if (x == endX && y == endY)
{
return;
}
if (ST_HAS_MENU_CSET(MR_STYLE(mr)) &&
CSET_IS_TRANSPARENT(ST_CSET_MENU(MR_STYLE(mr))))
{
MenuRepaintTransparentParameters mrtp;
get_menu_repaint_transparent_parameters(
&mrtp, mr, (*pmp->pexc)->w.fw);
update_transparent_menu_bg(
&mrtp, x, y, endX, endY, endX, endY);
XMoveWindow(dpy, MR_WINDOW(mr), endX, endY);
repaint_transparent_menu(
&mrtp, False, endX,endY, endX, endY, True);
}
else
{
XMoveWindow(dpy, MR_WINDOW(mr), endX, endY);
}
}
}
/* ---------------------------- submenu function --------------------------- */
/* Search for a submenu that was popped up by the given item in the given
* instance of the menu. */
static MenuRoot *seek_submenu_instance(
MenuRoot *parent_menu, MenuItem *parent_item)
{
MenuRoot *mr;
for (mr = Menus.all; mr != NULL; mr = MR_NEXT_MENU(mr))
{
if (MR_PARENT_MENU(mr) == parent_menu &&
MR_PARENT_ITEM(mr) == parent_item)
{
/* here it is */
break;
}
}
return mr;
}
static Bool is_submenu_mapped(MenuRoot *parent_menu, MenuItem *parent_item)
{
XWindowAttributes win_attribs;
MenuRoot *mr;
mr = seek_submenu_instance(parent_menu, parent_item);
if (mr == NULL)
{
return False;
}
if (MR_WINDOW(mr) == None)
{
return False;
}
if (!XGetWindowAttributes(dpy, MR_WINDOW(mr), &win_attribs))
{
return False;
}
return (win_attribs.map_state == IsViewable);
}
/* Returns the menu root that a given menu item pops up */
static MenuRoot *mr_popup_for_mi(MenuRoot *mr, MenuItem *mi)
{
char *menu_name;
MenuRoot *menu = NULL;
/* This checks if mi is != NULL too */
if (!mi || !MI_IS_POPUP(mi))
{
return NULL;
}
/* first look for a menu that is already mapped */
menu = seek_submenu_instance(mr, mi);
if (menu)
{
return menu;
}
/* just look past "Popup " in the action, and find that menu root */
menu_name = PeekToken(SkipNTokens(MI_ACTION(mi), 1), NULL);
menu = menus_find_menu(menu_name);
return menu;
}
/* ---------------------------- item handling ------------------------------ */
/*
* find_entry()
*
* Returns the menu item the pointer is over and optionally the offset
* from the left side of the menu entry (if px_offset is != NULL) and
* the MenuRoot the pointer is over (if pmr is != NULL).
*/
static MenuItem *find_entry(
MenuParameters *pmp,
int *px_offset /*NULL means don't return this value */,
MenuRoot **pmr /*NULL means don't return this value */,
/* values passed in from caller it FQueryPointer was already called
* there */
Window p_child, int p_rx, int p_ry)
{
MenuItem *mi;
MenuRoot *mr;
int root_x, root_y;
int x, y;
Window Child;
int r;
/* x_offset returns the x offset of the pointer in the found menu item
*/
if (px_offset)
{
*px_offset = 0;
}
if (pmr)
{
*pmr = NULL;
}
/* get the pointer position */
if (p_rx < 0)
{
if (!FQueryPointer(
dpy, Scr.Root, &JunkRoot, &Child,
&root_x, &root_y, &JunkX, &JunkY, &JunkMask))
{
/* pointer is on a different screen */
return NULL;
}
}
else
{
root_x = p_rx;
root_y = p_ry;
Child = p_child;
}
/* find out the menu the pointer is in */
if (pmp->tear_off_root_menu_window != NULL &&
Child == FW_W_FRAME(pmp->tear_off_root_menu_window))
{
/* we're in the top level torn off menu */
Child = FW_W(pmp->tear_off_root_menu_window);
}
if (XFindContext(dpy, Child, MenuContext, (caddr_t *)&mr) == XCNOENT)
{
return NULL;
}
/* get position in that child window */
if (!XTranslateCoordinates(
dpy, Scr.Root, MR_WINDOW(mr), root_x, root_y, &x, &y,
&JunkChild))
{
return NULL;
}
if (x < 0 || y < 0 || x >= MR_WIDTH(mr) || y >= MR_HEIGHT(mr))
{
return NULL;
}
if (pmr)
{
*pmr = mr;
}
r = MST_RELIEF_THICKNESS(mr);
/* look for the entry that the mouse is in */
for (mi = MR_FIRST_ITEM(mr); mi; mi = MI_NEXT_ITEM(mi))
{
int a;
int b;
a = (MI_PREV_ITEM(mi) &&
MI_IS_SELECTABLE(MI_PREV_ITEM(mi))) ? r / 2 : 0;
if (!MI_IS_SELECTABLE(mi))
{
b = 0;
}
else if (MI_NEXT_ITEM(mi) &&
MI_IS_SELECTABLE(MI_NEXT_ITEM(mi)))
{
b = r / 2;
}
else
{
b = r;
}
if (y >= MI_Y_OFFSET(mi) - a &&
y < MI_Y_OFFSET(mi) + MI_HEIGHT(mi) + b)
{
break;
}
}
if (x < MR_ITEM_X_OFFSET(mr) ||
x >= MR_ITEM_X_OFFSET(mr) + MR_ITEM_WIDTH(mr) - 1)
{
mi = NULL;
}
if (mi && px_offset)
{
*px_offset = x;
}
return mi;
}
/* ---------------------------- keyboard shortcuts ------------------------- */
static Bool is_double_click(
Time t0, MenuItem *mi, MenuParameters *pmp, MenuReturn *pmret,
double_keypress *pdkp, Bool has_mouse_moved)
{
if ((*pmp->pexc)->x.elast->type == KeyPress)
{
return False;
}
if (fev_get_evtime() - t0 >= MST_DOUBLE_CLICK_TIME(pmp->menu))
{
return False;
}
if (has_mouse_moved)
{
return False;
}
if (!pmp->flags.has_default_action &&
(mi && mi == MR_FIRST_ITEM(pmp->menu) && MI_IS_SELECTABLE(mi)))
{
return False;
}
if (pmp->flags.is_submenu)
{
return False;
}
if (pmp->flags.is_invoked_by_key_press && pdkp->timestamp == 0)
{
return False;
}
return True;
}
/* ---------------------------- item label parsing ------------------------- */
/*
* Procedure:
* scanForHotkeys - Look for hotkey markers in a MenuItem
* (pete@tecc.co.uk)
*
* Inputs:
* it - MenuItem to scan
* column - The column number in which to look for a hotkey.
*
*/
static void scanForHotkeys(
MenuItem *it, int column)
{
char *start;
char *s;
char *t;
/* Get start of string */
start = MI_LABEL(it)[column];
/* Scan whole string */
for (s = start; *s != '\0'; s++)
{
if (*s != '&')
{
continue;
}
if (s[1] != '&')
{
/* found a hotkey - only one hotkey per item */
break;
}
/* Just an escaped '&'; copy the string down over it */
for (t = s; *t != '\0'; t++)
{
t[0] = t[1];
}
}
if (*s != 0)
{
/* It's a hot key marker - work out the offset value */
MI_HOTKEY_COFFSET(it) = s - start;
MI_HOTKEY_COLUMN(it) = column;
MI_HAS_HOTKEY(it) = (s[1] != '\0');
MI_IS_HOTKEY_AUTOMATIC(it) = 0;
for ( ; *s != '\0'; s++)
{
/* Copy down.. */
s[0] = s[1];
}
}
return;
}
static void __copy_down(char *remove_from, char *remove_to)
{
char *t1;
char *t2;
for (t1 = remove_from, t2 = remove_to; *t2 != '\0'; t2++, t1++)
{
*t1 = *t2;
}
*t1 = '\0';
return;
}
static int __check_for_delimiter(char *s, const string_def_t *string_defs)
{
int type;
for (type = 0; string_defs[type].delimiter != '\0'; type++)
{
if (s[0] == string_defs[type].delimiter)
{
if (s[1] != string_defs[type].delimiter)
{
return type;
}
else
{
/* escaped delimiter, copy the
* string down over it */
__copy_down(s, s+1);
return -1;
}
}
}
return -1;
}
/* This scans for strings within delimiters and calls a callback based
* on the delimiter found for each found string */
static void scanForStrings(
char *instring, const string_def_t *string_defs,
string_context_t *context)
{
char *s;
int type;
char *string;
type = -1;
/* string is set whenever type >= 0, and unused otherwise
* set to NULL to suppress compiler warning */
string = NULL;
for (s = instring; *s != '\0'; s++)
{
if (type < 0)
{
/* look for starting delimiters */
type = __check_for_delimiter(s, string_defs);
if (type >= 0)
{
/* start of a string */
string = s + 1;
}
}
else if (
s[0] == string_defs[type].delimiter &&
s[1] != string_defs[type].delimiter)
{
/* found ending delimiter */
Bool is_valid;
/* terminate the string pointer */
s[0] = '\0';
is_valid = string_defs[type].string_handler(
string, string_defs[type].delimiter, context);
/* restore the string */
s[0] = string_defs[type].delimiter;
if (is_valid)
{
/* the string was OK, remove it from
* instring */
__copy_down(string - 1, s + 1);
/* continue next iteration at the
* first character after the string */
s = string - 2;
}
type = -1;
}
else if (s[0] == string_defs[type].delimiter)
{
/* escaped delimiter, copy the string down over
* it */
__copy_down(s, s + 1);
}
}
}
/* Side picture support: this scans for a color int the menu name
for colorization */
static Bool __scan_for_color(
char *name, char type, string_context_t *context)
{
if (type != '^' || SCTX_GET_MR(*context) == NULL)
{
abort();
}
if (MR_HAS_SIDECOLOR(SCTX_GET_MR(*context)))
{
return False;
}
MR_SIDECOLOR(SCTX_GET_MR(*context)) = GetColor(name);
MR_HAS_SIDECOLOR(SCTX_GET_MR(*context)) = True;
return True;
}
static Bool __scan_for_pixmap(
char *name, char type, string_context_t *context)
{
FvwmPicture *p;
FvwmPictureAttributes fpa;
int current_mini_icon;
/* check that more pictures are allowed before trying to load the
* picture */
current_mini_icon = -999999999;
switch (type)
{
case '@':
if (SCTX_GET_MR(*context) == NULL)
{
abort();
}
if (MR_SIDEPIC(SCTX_GET_MR(*context)))
{
return False;
}
break;
case '*':
/* menu item picture, requires menu item */
if (SCTX_GET_MI(*context) == NULL)
{
abort();
}
if (MI_PICTURE(SCTX_GET_MI(*context)))
{
return False;
}
break;
case '%':
/* mini icon - look for next free spot */
if (SCTX_GET_MI(*context) == NULL)
{
abort();
}
current_mini_icon = 0;
while (current_mini_icon < MAX_MENU_ITEM_MINI_ICONS)
{
if (
MI_MINI_ICON(SCTX_GET_MI(*context))
[current_mini_icon])
{
current_mini_icon++;
}
else
{
break;
}
}
if (current_mini_icon == MAX_MENU_ITEM_MINI_ICONS)
{
return False;
}
break;
default:
abort();
}
fpa.mask = 0;
p = PCacheFvwmPicture(
dpy, Scr.NoFocusWin, NULL, name, fpa);
if (!p)
{
fvwm_debug(__func__,
"Couldn't load image from %s", name);
fvwm_debug(__func__,
"Check that FVWM has support for the filetype it's "
"being asked to load.");
/* return true to make missing pictures not appear in the
* label/name */
return True;
}
switch (type)
{
case '@':
MR_SIDEPIC(SCTX_GET_MR(*context)) = p;
break;
case '*':
MI_PICTURE(SCTX_GET_MI(*context)) = p;
MI_HAS_PICTURE(SCTX_GET_MI(*context)) = True;
break;
case '%':
MI_MINI_ICON(SCTX_GET_MI(*context))[current_mini_icon] = p;
MI_HAS_PICTURE(SCTX_GET_MI(*context)) = True;
break;
}
return True;
}
/* ---------------------------- item list handling ------------------------- */
static void unlink_item_from_menu(
MenuRoot *mr, MenuItem *mi)
{
MenuItem *next;
MenuItem *prev;
next = MI_NEXT_ITEM(mi);
prev = MI_PREV_ITEM(mi);
if (next != NULL)
{
MI_PREV_ITEM(next) = prev;
}
else
{
MR_LAST_ITEM(mr) = prev;
}
if (prev != NULL)
{
MI_NEXT_ITEM(prev) = next;
}
else
{
MR_FIRST_ITEM(mr) = next;
}
MI_NEXT_ITEM(mi) = NULL;
MI_PREV_ITEM(mi) = NULL;
MR_ITEMS(mr)--;
return;
}
/* Add the given menu item to the menu. If the first item of the menu is a
* title, and the do_replace_title flag is True, the old title is deleted and
* replaced by the new item. Otherwise the item is appended at the end of the
* menu. */
static void append_item_to_menu(
MenuRoot *mr, MenuItem *mi, Bool do_replace_title)
{
if (MR_FIRST_ITEM(mr) == NULL)
{
MR_FIRST_ITEM(mr) = mi;
MR_LAST_ITEM(mr) = mi;
MI_NEXT_ITEM(mi) = NULL;
MI_PREV_ITEM(mi) = NULL;
}