/
gtkframe.cxx
6182 lines (5394 loc) · 214 KB
/
gtkframe.cxx
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <unx/gtk/gtkframe.hxx>
#include <unx/gtk/gtkdata.hxx>
#include <unx/gtk/gtkinst.hxx>
#include <unx/gtk/gtkgdi.hxx>
#include <unx/gtk/gtksalmenu.hxx>
#include <unx/gtk/hudawareness.h>
#include <vcl/event.hxx>
#include <vcl/i18nhelp.hxx>
#include <vcl/keycodes.hxx>
#include <unx/geninst.h>
#include <headless/svpgdi.hxx>
#include <sal/log.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <vcl/toolkit/floatwin.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <vcl/window.hxx>
#include <vcl/settings.hxx>
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <unx/gtk/gtkbackend.hxx>
#include <window.h>
#include <basegfx/vector/b2ivector.hxx>
#include <dlfcn.h>
#include <algorithm>
#if OSL_DEBUG_LEVEL > 1
# include <cstdio>
#endif
#include <i18nlangtag/mslangid.hxx>
#include <cstdlib>
#include <cmath>
#include <com/sun/star/awt/MouseButton.hpp>
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#if !GTK_CHECK_VERSION(4, 0, 0)
# define GDK_ALT_MASK GDK_MOD1_MASK
# define GDK_TOPLEVEL_STATE_MAXIMIZED GDK_WINDOW_STATE_MAXIMIZED
# define GDK_TOPLEVEL_STATE_MINIMIZED GDK_WINDOW_STATE_ICONIFIED
# define gdk_wayland_surface_get_wl_surface gdk_wayland_window_get_wl_surface
# define gdk_x11_surface_get_xid gdk_x11_window_get_xid
#endif
using namespace com::sun::star;
int GtkSalFrame::m_nFloats = 0;
static GDBusConnection* pSessionBus = nullptr;
static void EnsureSessionBus()
{
if (!pSessionBus)
pSessionBus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
}
sal_uInt16 GtkSalFrame::GetKeyModCode( guint state )
{
sal_uInt16 nCode = 0;
if( state & GDK_SHIFT_MASK )
nCode |= KEY_SHIFT;
if( state & GDK_CONTROL_MASK )
nCode |= KEY_MOD1;
if (state & GDK_ALT_MASK)
nCode |= KEY_MOD2;
if( state & GDK_SUPER_MASK )
nCode |= KEY_MOD3;
return nCode;
}
sal_uInt16 GtkSalFrame::GetMouseModCode( guint state )
{
sal_uInt16 nCode = GetKeyModCode( state );
if( state & GDK_BUTTON1_MASK )
nCode |= MOUSE_LEFT;
if( state & GDK_BUTTON2_MASK )
nCode |= MOUSE_MIDDLE;
if( state & GDK_BUTTON3_MASK )
nCode |= MOUSE_RIGHT;
return nCode;
}
// KEY_F26 is the last function key known to keycodes.hxx
static bool IsFunctionKeyVal(guint keyval)
{
return keyval >= GDK_KEY_F1 && keyval <= GDK_KEY_F26;
}
sal_uInt16 GtkSalFrame::GetKeyCode(guint keyval)
{
sal_uInt16 nCode = 0;
if( keyval >= GDK_KEY_0 && keyval <= GDK_KEY_9 )
nCode = KEY_0 + (keyval-GDK_KEY_0);
else if( keyval >= GDK_KEY_KP_0 && keyval <= GDK_KEY_KP_9 )
nCode = KEY_0 + (keyval-GDK_KEY_KP_0);
else if( keyval >= GDK_KEY_A && keyval <= GDK_KEY_Z )
nCode = KEY_A + (keyval-GDK_KEY_A );
else if( keyval >= GDK_KEY_a && keyval <= GDK_KEY_z )
nCode = KEY_A + (keyval-GDK_KEY_a );
else if (IsFunctionKeyVal(keyval))
{
switch( keyval )
{
// - - - - - Sun keyboard, see vcl/unx/source/app/saldisp.cxx
// although GDK_KEY_F1 ... GDK_KEY_L10 are known to
// gdk/gdkkeysyms.h, they are unlikely to be generated
// except possibly by Solaris systems
// this whole section needs review
case GDK_KEY_L2:
nCode = KEY_F12;
break;
case GDK_KEY_L3: nCode = KEY_PROPERTIES; break;
case GDK_KEY_L4: nCode = KEY_UNDO; break;
case GDK_KEY_L6: nCode = KEY_COPY; break; // KEY_F16
case GDK_KEY_L8: nCode = KEY_PASTE; break; // KEY_F18
case GDK_KEY_L10: nCode = KEY_CUT; break; // KEY_F20
default:
nCode = KEY_F1 + (keyval-GDK_KEY_F1); break;
}
}
else
{
switch( keyval )
{
case GDK_KEY_KP_Down:
case GDK_KEY_Down: nCode = KEY_DOWN; break;
case GDK_KEY_KP_Up:
case GDK_KEY_Up: nCode = KEY_UP; break;
case GDK_KEY_KP_Left:
case GDK_KEY_Left: nCode = KEY_LEFT; break;
case GDK_KEY_KP_Right:
case GDK_KEY_Right: nCode = KEY_RIGHT; break;
case GDK_KEY_KP_Begin:
case GDK_KEY_KP_Home:
case GDK_KEY_Begin:
case GDK_KEY_Home: nCode = KEY_HOME; break;
case GDK_KEY_KP_End:
case GDK_KEY_End: nCode = KEY_END; break;
case GDK_KEY_KP_Page_Up:
case GDK_KEY_Page_Up: nCode = KEY_PAGEUP; break;
case GDK_KEY_KP_Page_Down:
case GDK_KEY_Page_Down: nCode = KEY_PAGEDOWN; break;
case GDK_KEY_KP_Enter:
case GDK_KEY_Return: nCode = KEY_RETURN; break;
case GDK_KEY_Escape: nCode = KEY_ESCAPE; break;
case GDK_KEY_ISO_Left_Tab:
case GDK_KEY_KP_Tab:
case GDK_KEY_Tab: nCode = KEY_TAB; break;
case GDK_KEY_BackSpace: nCode = KEY_BACKSPACE; break;
case GDK_KEY_KP_Space:
case GDK_KEY_space: nCode = KEY_SPACE; break;
case GDK_KEY_KP_Insert:
case GDK_KEY_Insert: nCode = KEY_INSERT; break;
case GDK_KEY_KP_Delete:
case GDK_KEY_Delete: nCode = KEY_DELETE; break;
case GDK_KEY_plus:
case GDK_KEY_KP_Add: nCode = KEY_ADD; break;
case GDK_KEY_minus:
case GDK_KEY_KP_Subtract: nCode = KEY_SUBTRACT; break;
case GDK_KEY_asterisk:
case GDK_KEY_KP_Multiply: nCode = KEY_MULTIPLY; break;
case GDK_KEY_slash:
case GDK_KEY_KP_Divide: nCode = KEY_DIVIDE; break;
case GDK_KEY_period: nCode = KEY_POINT; break;
case GDK_KEY_decimalpoint: nCode = KEY_POINT; break;
case GDK_KEY_comma: nCode = KEY_COMMA; break;
case GDK_KEY_less: nCode = KEY_LESS; break;
case GDK_KEY_greater: nCode = KEY_GREATER; break;
case GDK_KEY_KP_Equal:
case GDK_KEY_equal: nCode = KEY_EQUAL; break;
case GDK_KEY_Find: nCode = KEY_FIND; break;
case GDK_KEY_Menu: nCode = KEY_CONTEXTMENU;break;
case GDK_KEY_Help: nCode = KEY_HELP; break;
case GDK_KEY_Undo: nCode = KEY_UNDO; break;
case GDK_KEY_Redo: nCode = KEY_REPEAT; break;
// on a sun keyboard this actually is usually SunXK_Stop = 0x0000FF69 (XK_Cancel),
// but VCL doesn't have a key definition for that
case GDK_KEY_Cancel: nCode = KEY_F11; break;
case GDK_KEY_KP_Decimal:
case GDK_KEY_KP_Separator: nCode = KEY_DECIMAL; break;
case GDK_KEY_asciitilde: nCode = KEY_TILDE; break;
case GDK_KEY_leftsinglequotemark:
case GDK_KEY_quoteleft: nCode = KEY_QUOTELEFT; break;
case GDK_KEY_bracketleft: nCode = KEY_BRACKETLEFT; break;
case GDK_KEY_bracketright: nCode = KEY_BRACKETRIGHT; break;
case GDK_KEY_semicolon: nCode = KEY_SEMICOLON; break;
case GDK_KEY_quoteright: nCode = KEY_QUOTERIGHT; break;
case GDK_KEY_braceright: nCode = KEY_RIGHTCURLYBRACKET; break;
// some special cases, also see saldisp.cxx
// - - - - - - - - - - - - - Apollo - - - - - - - - - - - - - 0x1000
// These can be found in ap_keysym.h
case 0x1000FF02: // apXK_Copy
nCode = KEY_COPY;
break;
case 0x1000FF03: // apXK_Cut
nCode = KEY_CUT;
break;
case 0x1000FF04: // apXK_Paste
nCode = KEY_PASTE;
break;
case 0x1000FF14: // apXK_Repeat
nCode = KEY_REPEAT;
break;
// Exit, Save
// - - - - - - - - - - - - - - D E C - - - - - - - - - - - - - 0x1000
// These can be found in DECkeysym.h
case 0x1000FF00:
nCode = KEY_DELETE;
break;
// - - - - - - - - - - - - - - H P - - - - - - - - - - - - - 0x1000
// These can be found in HPkeysym.h
case 0x1000FF73: // hpXK_DeleteChar
nCode = KEY_DELETE;
break;
case 0x1000FF74: // hpXK_BackTab
case 0x1000FF75: // hpXK_KP_BackTab
nCode = KEY_TAB;
break;
// - - - - - - - - - - - - - - I B M - - - - - - - - - - - - -
// - - - - - - - - - - - - - - O S F - - - - - - - - - - - - - 0x1004
// These also can be found in HPkeysym.h
case 0x1004FF02: // osfXK_Copy
nCode = KEY_COPY;
break;
case 0x1004FF03: // osfXK_Cut
nCode = KEY_CUT;
break;
case 0x1004FF04: // osfXK_Paste
nCode = KEY_PASTE;
break;
case 0x1004FF07: // osfXK_BackTab
nCode = KEY_TAB;
break;
case 0x1004FF08: // osfXK_BackSpace
nCode = KEY_BACKSPACE;
break;
case 0x1004FF1B: // osfXK_Escape
nCode = KEY_ESCAPE;
break;
// Up, Down, Left, Right, PageUp, PageDown
// - - - - - - - - - - - - - - S C O - - - - - - - - - - - - -
// - - - - - - - - - - - - - - S G I - - - - - - - - - - - - - 0x1007
// - - - - - - - - - - - - - - S N I - - - - - - - - - - - - -
// - - - - - - - - - - - - - - S U N - - - - - - - - - - - - - 0x1005
// These can be found in Sunkeysym.h
case 0x1005FF10: // SunXK_F36
nCode = KEY_F11;
break;
case 0x1005FF11: // SunXK_F37
nCode = KEY_F12;
break;
case 0x1005FF70: // SunXK_Props
nCode = KEY_PROPERTIES;
break;
case 0x1005FF71: // SunXK_Front
nCode = KEY_FRONT;
break;
case 0x1005FF72: // SunXK_Copy
nCode = KEY_COPY;
break;
case 0x1005FF73: // SunXK_Open
nCode = KEY_OPEN;
break;
case 0x1005FF74: // SunXK_Paste
nCode = KEY_PASTE;
break;
case 0x1005FF75: // SunXK_Cut
nCode = KEY_CUT;
break;
// - - - - - - - - - - - - - X F 8 6 - - - - - - - - - - - - - 0x1008
// These can be found in XF86keysym.h
// but more importantly they are also available GTK/Gdk version 3
// and hence are already provided in gdk/gdkkeysyms.h, and hence
// in gdk/gdk.h
case GDK_KEY_Copy: nCode = KEY_COPY; break; // 0x1008ff57
case GDK_KEY_Cut: nCode = KEY_CUT; break; // 0x1008ff58
case GDK_KEY_Open: nCode = KEY_OPEN; break; // 0x1008ff6b
case GDK_KEY_Paste: nCode = KEY_PASTE; break; // 0x1008ff6d
}
}
return nCode;
}
#if !GTK_CHECK_VERSION(4, 0, 0)
guint GtkSalFrame::GetKeyValFor(GdkKeymap* pKeyMap, guint16 hardware_keycode, guint8 group)
{
guint updated_keyval = 0;
gdk_keymap_translate_keyboard_state(pKeyMap, hardware_keycode,
GdkModifierType(0), group, &updated_keyval, nullptr, nullptr, nullptr);
return updated_keyval;
}
#endif
namespace {
// F10 means either KEY_F10 or KEY_MENU, which has to be decided
// in the independent part.
struct KeyAlternate
{
sal_uInt16 nKeyCode;
sal_Unicode nCharCode;
KeyAlternate() : nKeyCode( 0 ), nCharCode( 0 ) {}
KeyAlternate( sal_uInt16 nKey, sal_Unicode nChar = 0 ) : nKeyCode( nKey ), nCharCode( nChar ) {}
};
}
static KeyAlternate
GetAlternateKeyCode( const sal_uInt16 nKeyCode )
{
KeyAlternate aAlternate;
switch( nKeyCode )
{
case KEY_F10: aAlternate = KeyAlternate( KEY_MENU );break;
case KEY_F24: aAlternate = KeyAlternate( KEY_SUBTRACT, '-' );break;
}
return aAlternate;
}
#if OSL_DEBUG_LEVEL > 0
static bool dumpframes = false;
#endif
bool GtkSalFrame::doKeyCallback( guint state,
guint keyval,
guint16 hardware_keycode,
guint8 group,
sal_Unicode aOrigCode,
bool bDown,
bool bSendRelease
)
{
SalKeyEvent aEvent;
aEvent.mnCharCode = aOrigCode;
aEvent.mnRepeat = 0;
vcl::DeletionListener aDel( this );
#if OSL_DEBUG_LEVEL > 0
const char* pKeyDebug = getenv("VCL_GTK3_PAINTDEBUG");
if (pKeyDebug && *pKeyDebug == '1')
{
if (bDown)
{
// shift-zero forces a re-draw and event is swallowed
if (keyval == GDK_KEY_0)
{
SAL_INFO("vcl.gtk3", "force widget_queue_draw.");
gtk_widget_queue_draw(GTK_WIDGET(m_pDrawingArea));
return false;
}
else if (keyval == GDK_KEY_1)
{
SAL_INFO("vcl.gtk3", "force repaint all.");
TriggerPaintEvent();
return false;
}
else if (keyval == GDK_KEY_2)
{
dumpframes = !dumpframes;
SAL_INFO("vcl.gtk3", "toggle dump frames to " << dumpframes);
return false;
}
}
}
#endif
/*
* #i42122# translate all keys with Ctrl and/or Alt to group 0 else
* shortcuts (e.g. Ctrl-o) will not work but be inserted by the
* application
*
* #i52338# do this for all keys that the independent part has no key code
* for
*
* fdo#41169 rather than use group 0, detect if there is a group which can
* be used to input Latin text and use that if possible
*/
aEvent.mnCode = GetKeyCode( keyval );
#if !GTK_CHECK_VERSION(4, 0, 0)
if( aEvent.mnCode == 0 )
{
gint best_group = SAL_MAX_INT32;
// Try and find Latin layout
GdkKeymap* keymap = gdk_keymap_get_default();
GdkKeymapKey *keys;
gint n_keys;
if (gdk_keymap_get_entries_for_keyval(keymap, GDK_KEY_A, &keys, &n_keys))
{
// Find the lowest group that supports Latin layout
for (gint i = 0; i < n_keys; ++i)
{
if (keys[i].level != 0 && keys[i].level != 1)
continue;
best_group = std::min(best_group, keys[i].group);
if (best_group == 0)
break;
}
g_free(keys);
}
//Unavailable, go with original group then I suppose
if (best_group == SAL_MAX_INT32)
best_group = group;
guint updated_keyval = GetKeyValFor(keymap, hardware_keycode, best_group);
aEvent.mnCode = GetKeyCode(updated_keyval);
}
#else
(void)hardware_keycode;
(void)group;
#endif
aEvent.mnCode |= GetKeyModCode( state );
bool bStopProcessingKey;
if (bDown)
{
bStopProcessingKey = CallCallbackExc(SalEvent::KeyInput, &aEvent);
// #i46889# copy AlternateKeyCode handling from generic plugin
if (!bStopProcessingKey)
{
KeyAlternate aAlternate = GetAlternateKeyCode( aEvent.mnCode );
if( aAlternate.nKeyCode )
{
aEvent.mnCode = aAlternate.nKeyCode;
if( aAlternate.nCharCode )
aEvent.mnCharCode = aAlternate.nCharCode;
bStopProcessingKey = CallCallbackExc(SalEvent::KeyInput, &aEvent);
}
}
if( bSendRelease && ! aDel.isDeleted() )
{
CallCallbackExc(SalEvent::KeyUp, &aEvent);
}
}
else
bStopProcessingKey = CallCallbackExc(SalEvent::KeyUp, &aEvent);
return bStopProcessingKey;
}
GtkSalFrame::GtkSalFrame( SalFrame* pParent, SalFrameStyleFlags nStyle )
: m_nXScreen( getDisplay()->GetDefaultXScreen() )
, m_pHeaderBar(nullptr)
, m_bGraphics(false)
, m_nSetFocusSignalId(0)
#if !GTK_CHECK_VERSION(4, 0, 0)
, m_aSmoothScrollIdle("GtkSalFrame m_aSmoothScrollIdle")
#endif
{
getDisplay()->registerFrame( this );
m_bDefaultPos = true;
m_bDefaultSize = ( (nStyle & SalFrameStyleFlags::SIZEABLE) && ! pParent );
Init( pParent, nStyle );
}
GtkSalFrame::GtkSalFrame( SystemParentData* pSysData )
: m_nXScreen( getDisplay()->GetDefaultXScreen() )
, m_pHeaderBar(nullptr)
, m_bGraphics(false)
, m_nSetFocusSignalId(0)
#if !GTK_CHECK_VERSION(4, 0, 0)
, m_aSmoothScrollIdle("GtkSalFrame m_aSmoothScrollIdle")
#endif
{
getDisplay()->registerFrame( this );
// permanently ignore errors from our unruly children ...
GetGenericUnixSalData()->ErrorTrapPush();
m_bDefaultPos = true;
m_bDefaultSize = true;
Init( pSysData );
}
// AppMenu watch functions.
static void ObjectDestroyedNotify( gpointer data )
{
if ( data ) {
g_object_unref( data );
}
}
#if !GTK_CHECK_VERSION(4,0,0)
static void hud_activated( gboolean hud_active, gpointer user_data )
{
if ( hud_active )
{
SolarMutexGuard aGuard;
GtkSalFrame* pSalFrame = static_cast< GtkSalFrame* >( user_data );
GtkSalMenu* pSalMenu = reinterpret_cast< GtkSalMenu* >( pSalFrame->GetMenu() );
if ( pSalMenu )
pSalMenu->UpdateFull();
}
}
#endif
static void attach_menu_model(GtkSalFrame* pSalFrame)
{
GtkWidget* pWidget = pSalFrame->getWindow();
GdkSurface* gdkWindow = widget_get_surface(pWidget);
if ( gdkWindow == nullptr || g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) != nullptr )
return;
// Create menu model and action group attached to this frame.
GMenuModel* pMenuModel = G_MENU_MODEL( g_lo_menu_new() );
GActionGroup* pActionGroup = reinterpret_cast<GActionGroup*>(g_lo_action_group_new());
// Set window properties.
g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-menubar", pMenuModel, ObjectDestroyedNotify );
g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-action-group", pActionGroup, ObjectDestroyedNotify );
#if !GTK_CHECK_VERSION(4,0,0)
// Get a DBus session connection.
EnsureSessionBus();
if (!pSessionBus)
return;
// Generate menu paths.
sal_uIntPtr windowId = GtkSalFrame::GetNativeWindowHandle(pWidget);
gchar* aDBusWindowPath = g_strdup_printf( "/org/libreoffice/window/%lu", windowId );
gchar* aDBusMenubarPath = g_strdup_printf( "/org/libreoffice/window/%lu/menus/menubar", windowId );
GdkDisplay *pDisplay = GtkSalFrame::getGdkDisplay();
#if defined(GDK_WINDOWING_X11)
if (DLSYM_GDK_IS_X11_DISPLAY(pDisplay))
{
gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_APPLICATION_ID", "org.libreoffice" );
gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath );
gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath );
gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "/org/libreoffice" );
gdk_x11_window_set_utf8_property( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) );
}
#endif
#if defined(GDK_WINDOWING_WAYLAND)
if (DLSYM_GDK_IS_WAYLAND_DISPLAY(pDisplay))
{
gdk_wayland_window_set_dbus_properties_libgtk_only(gdkWindow, "org.libreoffice",
nullptr,
aDBusMenubarPath,
aDBusWindowPath,
"/org/libreoffice",
g_dbus_connection_get_unique_name( pSessionBus ));
}
#endif
// Publish the menu model and the action group.
SAL_INFO("vcl.unity", "exporting menu model at " << pMenuModel << " for window " << windowId);
pSalFrame->m_nMenuExportId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, pMenuModel, nullptr);
SAL_INFO("vcl.unity", "exporting action group at " << pActionGroup << " for window " << windowId);
pSalFrame->m_nActionGroupExportId = g_dbus_connection_export_action_group( pSessionBus, aDBusWindowPath, pActionGroup, nullptr);
pSalFrame->m_nHudAwarenessId = hud_awareness_register( pSessionBus, aDBusMenubarPath, hud_activated, pSalFrame, nullptr, nullptr );
g_free( aDBusWindowPath );
g_free( aDBusMenubarPath );
#endif
}
void on_registrar_available( GDBusConnection * /*connection*/,
const gchar * /*name*/,
const gchar * /*name_owner*/,
gpointer user_data )
{
SolarMutexGuard aGuard;
GtkSalFrame* pSalFrame = static_cast< GtkSalFrame* >( user_data );
SalMenu* pSalMenu = pSalFrame->GetMenu();
if ( pSalMenu != nullptr )
{
GtkSalMenu* pGtkSalMenu = static_cast<GtkSalMenu*>(pSalMenu);
pGtkSalMenu->EnableUnity(true);
}
}
// This is called when the registrar becomes unavailable. It shows the menubar.
void on_registrar_unavailable( GDBusConnection * /*connection*/,
const gchar * /*name*/,
gpointer user_data )
{
SolarMutexGuard aGuard;
SAL_INFO("vcl.unity", "on_registrar_unavailable");
//pSessionBus = NULL;
GtkSalFrame* pSalFrame = static_cast< GtkSalFrame* >( user_data );
SalMenu* pSalMenu = pSalFrame->GetMenu();
if ( pSalMenu ) {
GtkSalMenu* pGtkSalMenu = static_cast< GtkSalMenu* >( pSalMenu );
pGtkSalMenu->EnableUnity(false);
}
}
void GtkSalFrame::EnsureAppMenuWatch()
{
if ( m_nWatcherId )
return;
// Get a DBus session connection.
EnsureSessionBus();
if (!pSessionBus)
return;
// Publish the menu only if AppMenu registrar is available.
m_nWatcherId = g_bus_watch_name_on_connection( pSessionBus,
"com.canonical.AppMenu.Registrar",
G_BUS_NAME_WATCHER_FLAGS_NONE,
on_registrar_available,
on_registrar_unavailable,
this,
nullptr );
}
void GtkSalFrame::InvalidateGraphics()
{
if( m_pGraphics )
{
m_bGraphics = false;
}
}
GtkSalFrame::~GtkSalFrame()
{
#if !GTK_CHECK_VERSION(4,0,0)
m_aSmoothScrollIdle.Stop();
m_aSmoothScrollIdle.ClearInvokeHandler();
#endif
if (m_pDropTarget)
{
m_pDropTarget->deinitialize();
m_pDropTarget = nullptr;
}
if (m_pDragSource)
{
m_pDragSource->deinitialize();
m_pDragSource= nullptr;
}
InvalidateGraphics();
if (m_pParent)
{
m_pParent->m_aChildren.remove( this );
}
getDisplay()->deregisterFrame( this );
if( m_pRegion )
{
cairo_region_destroy( m_pRegion );
}
m_pIMHandler.reset();
//tdf#108705 remove grabs on event widget before
//destroying event widget
while (m_nGrabLevel)
removeGrabLevel();
{
SolarMutexGuard aGuard;
if (m_nWatcherId)
g_bus_unwatch_name(m_nWatcherId);
if (m_nPortalSettingChangedSignalId)
g_signal_handler_disconnect(m_pSettingsPortal, m_nPortalSettingChangedSignalId);
if (m_pSettingsPortal)
g_object_unref(m_pSettingsPortal);
}
GtkWidget *pEventWidget = getMouseEventWidget();
for (auto handler_id : m_aMouseSignalIds)
g_signal_handler_disconnect(G_OBJECT(pEventWidget), handler_id);
#if !GTK_CHECK_VERSION(4, 0, 0)
if( m_pFixedContainer )
gtk_widget_destroy( GTK_WIDGET( m_pFixedContainer ) );
if( m_pEventBox )
gtk_widget_destroy( GTK_WIDGET(m_pEventBox) );
if( m_pTopLevelGrid )
gtk_widget_destroy( GTK_WIDGET(m_pTopLevelGrid) );
#else
g_signal_handler_disconnect(G_OBJECT(gtk_widget_get_display(pEventWidget)), m_nSettingChangedSignalId);
#endif
{
SolarMutexGuard aGuard;
if( m_pWindow )
{
g_object_set_data( G_OBJECT( m_pWindow ), "SalFrame", nullptr );
if ( pSessionBus )
{
if ( m_nHudAwarenessId )
hud_awareness_unregister( pSessionBus, m_nHudAwarenessId );
if ( m_nMenuExportId )
g_dbus_connection_unexport_menu_model( pSessionBus, m_nMenuExportId );
if ( m_nActionGroupExportId )
g_dbus_connection_unexport_action_group( pSessionBus, m_nActionGroupExportId );
}
m_xFrameWeld.reset();
#if !GTK_CHECK_VERSION(4,0,0)
gtk_widget_destroy( m_pWindow );
#else
if (GTK_IS_WINDOW(m_pWindow))
gtk_window_destroy(GTK_WINDOW(m_pWindow));
else
g_clear_pointer(&m_pWindow, gtk_widget_unparent);
#endif
}
}
#if !GTK_CHECK_VERSION(4,0,0)
if( m_pForeignParent )
g_object_unref( G_OBJECT( m_pForeignParent ) );
if( m_pForeignTopLevel )
g_object_unref( G_OBJECT( m_pForeignTopLevel) );
#endif
m_pGraphics.reset();
if (m_pSurface)
cairo_surface_destroy(m_pSurface);
}
void GtkSalFrame::moveWindow( tools::Long nX, tools::Long nY )
{
if( isChild( false ) )
{
GtkWidget* pParent = m_pParent ? gtk_widget_get_parent(m_pWindow) : nullptr;
// tdf#130414 it's possible that we were reparented and are no longer inside
// our original GtkFixed parent
if (pParent && GTK_IS_FIXED(pParent))
{
gtk_fixed_move( GTK_FIXED(pParent),
m_pWindow,
nX - m_pParent->maGeometry.x(), nY - m_pParent->maGeometry.y() );
}
return;
}
#if GTK_CHECK_VERSION(4,0,0)
if (GTK_IS_POPOVER(m_pWindow))
{
GdkRectangle aRect;
aRect.x = nX;
aRect.y = nY;
aRect.width = 1;
aRect.height = 1;
gtk_popover_set_pointing_to(GTK_POPOVER(m_pWindow), &aRect);
return;
}
#else
gtk_window_move( GTK_WINDOW(m_pWindow), nX, nY );
#endif
}
void GtkSalFrame::widget_set_size_request(tools::Long nWidth, tools::Long nHeight)
{
gtk_widget_set_size_request(GTK_WIDGET(m_pFixedContainer), nWidth, nHeight );
#if GTK_CHECK_VERSION(4,0,0)
gtk_widget_set_size_request(GTK_WIDGET(m_pDrawingArea), nWidth, nHeight );
#endif
}
void GtkSalFrame::window_resize(tools::Long nWidth, tools::Long nHeight)
{
m_nWidthRequest = nWidth;
m_nHeightRequest = nHeight;
if (!GTK_IS_WINDOW(m_pWindow))
{
#if GTK_CHECK_VERSION(4,0,0)
gtk_widget_set_size_request(GTK_WIDGET(m_pDrawingArea), nWidth, nHeight);
#endif
return;
}
gtk_window_set_default_size(GTK_WINDOW(m_pWindow), nWidth, nHeight);
#if !GTK_CHECK_VERSION(4,0,0)
if (gtk_widget_get_visible(m_pWindow))
gtk_window_resize(GTK_WINDOW(m_pWindow), nWidth, nHeight);
#endif
}
void GtkSalFrame::resizeWindow( tools::Long nWidth, tools::Long nHeight )
{
if( isChild( false ) )
{
widget_set_size_request(nWidth, nHeight);
}
else if( ! isChild( true, false ) )
window_resize(nWidth, nHeight);
}
#if !GTK_CHECK_VERSION(4,0,0)
// tdf#124694 GtkFixed takes the max size of all its children as its
// preferred size, causing it to not clip its child, but grow instead.
static void
ooo_fixed_get_preferred_height(GtkWidget*, gint *minimum, gint *natural)
{
*minimum = 0;
*natural = 0;
}
static void
ooo_fixed_get_preferred_width(GtkWidget*, gint *minimum, gint *natural)
{
*minimum = 0;
*natural = 0;
}
#endif
static void
ooo_fixed_class_init(GtkFixedClass *klass)
{
#if !GTK_CHECK_VERSION(4,0,0)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
widget_class->get_accessible = ooo_fixed_get_accessible;
widget_class->get_preferred_height = ooo_fixed_get_preferred_height;
widget_class->get_preferred_width = ooo_fixed_get_preferred_width;
#else
(void)klass;
#endif
}
/*
* Always use a sub-class of GtkFixed we can tag for a11y. This allows us to
* utilize GAIL for the toplevel window and toolkit implementation incl.
* key event listener support ..
*/
GType
ooo_fixed_get_type()
{
static GType type = 0;
if (!type) {
static const GTypeInfo tinfo =
{
sizeof (GtkFixedClass),
nullptr, /* base init */
nullptr, /* base finalize */
reinterpret_cast<GClassInitFunc>(ooo_fixed_class_init), /* class init */
nullptr, /* class finalize */
nullptr, /* class data */
sizeof (GtkFixed), /* instance size */
0, /* nb preallocs */
nullptr, /* instance init */
nullptr /* value table */
};
type = g_type_register_static( GTK_TYPE_FIXED, "OOoFixed",
&tinfo, GTypeFlags(0));
}
return type;
}
void GtkSalFrame::updateScreenNumber()
{
#if !GTK_CHECK_VERSION(4,0,0)
int nScreen = 0;
GdkScreen *pScreen = gtk_widget_get_screen( m_pWindow );
if( pScreen )
nScreen = getDisplay()->getSystem()->getScreenMonitorIdx( pScreen, maGeometry.x(), maGeometry.y() );
maGeometry.setScreen(nScreen);
#endif
}
GtkWidget *GtkSalFrame::getMouseEventWidget() const
{
#if !GTK_CHECK_VERSION(4,0,0)
return GTK_WIDGET(m_pEventBox);
#else
return GTK_WIDGET(m_pFixedContainer);
#endif
}
static void damaged(void *handle,
sal_Int32 nExtentsX, sal_Int32 nExtentsY,
sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight)
{
GtkSalFrame* pThis = static_cast<GtkSalFrame*>(handle);
pThis->damaged(nExtentsX, nExtentsY, nExtentsWidth, nExtentsHeight);
}
void GtkSalFrame::InitCommon()
{
m_pSurface = nullptr;
m_nGrabLevel = 0;
m_bSalObjectSetPosSize = false;
m_nPortalSettingChangedSignalId = 0;
m_pSettingsPortal = nullptr;
m_aDamageHandler.handle = this;
m_aDamageHandler.damaged = ::damaged;
#if !GTK_CHECK_VERSION(4,0,0)
m_aSmoothScrollIdle.SetInvokeHandler(LINK(this, GtkSalFrame, AsyncScroll));
#endif
m_pTopLevelGrid = GTK_GRID(gtk_grid_new());
container_add(m_pWindow, GTK_WIDGET(m_pTopLevelGrid));
#if !GTK_CHECK_VERSION(4,0,0)
m_pEventBox = GTK_EVENT_BOX(gtk_event_box_new());
gtk_widget_add_events( GTK_WIDGET(m_pEventBox),
GDK_ALL_EVENTS_MASK );
gtk_widget_set_vexpand(GTK_WIDGET(m_pEventBox), true);
gtk_widget_set_hexpand(GTK_WIDGET(m_pEventBox), true);
gtk_grid_attach(m_pTopLevelGrid, GTK_WIDGET(m_pEventBox), 0, 0, 1, 1);
#endif
// add the fixed container child,
// fixed is needed since we have to position plugin windows
#if !GTK_CHECK_VERSION(4,0,0)
m_pFixedContainer = GTK_FIXED(g_object_new( ooo_fixed_get_type(), nullptr ));
m_pDrawingArea = m_pFixedContainer;
#else
m_pOverlay = GTK_OVERLAY(gtk_overlay_new());
m_pFixedContainer = GTK_FIXED(gtk_fixed_new());
m_pDrawingArea = GTK_DRAWING_AREA(gtk_drawing_area_new());
#endif
gtk_widget_set_can_focus(GTK_WIDGET(m_pFixedContainer), true);
gtk_widget_set_size_request(GTK_WIDGET(m_pFixedContainer), 1, 1);
#if !GTK_CHECK_VERSION(4,0,0)
gtk_container_add( GTK_CONTAINER(m_pEventBox), GTK_WIDGET(m_pFixedContainer) );
#else
gtk_widget_set_vexpand(GTK_WIDGET(m_pOverlay), true);
gtk_widget_set_hexpand(GTK_WIDGET(m_pOverlay), true);
gtk_grid_attach(m_pTopLevelGrid, GTK_WIDGET(m_pOverlay), 0, 0, 1, 1);
gtk_overlay_set_child(m_pOverlay, GTK_WIDGET(m_pDrawingArea));
gtk_overlay_add_overlay(m_pOverlay, GTK_WIDGET(m_pFixedContainer));
#endif
GtkWidget *pEventWidget = getMouseEventWidget();
#if !GTK_CHECK_VERSION(4,0,0)
gtk_widget_set_app_paintable(GTK_WIDGET(m_pFixedContainer), true);
gtk_widget_set_redraw_on_allocate(GTK_WIDGET(m_pFixedContainer), false);
#endif
#if GTK_CHECK_VERSION(4,0,0)
m_nSettingChangedSignalId = g_signal_connect(G_OBJECT(gtk_widget_get_display(pEventWidget)), "setting-changed", G_CALLBACK(signalStyleUpdated), this);
#else
// use pEventWidget instead of m_pWindow to avoid infinite event loop under Linux Mint Mate 18.3
g_signal_connect(G_OBJECT(pEventWidget), "style-updated", G_CALLBACK(signalStyleUpdated), this);
#endif
gtk_widget_set_has_tooltip(pEventWidget, true);
// connect signals
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "query-tooltip", G_CALLBACK(signalTooltipQuery), this ));
#if !GTK_CHECK_VERSION(4,0,0)
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "button-press-event", G_CALLBACK(signalButton), this ));
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "button-release-event", G_CALLBACK(signalButton), this ));
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "motion-notify-event", G_CALLBACK(signalMotion), this ));
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "leave-notify-event", G_CALLBACK(signalCrossing), this ));
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "enter-notify-event", G_CALLBACK(signalCrossing), this ));
m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "scroll-event", G_CALLBACK(signalScroll), this ));