499
512
AObject: TQtObject;
500
513
W: TQtMainWindow;
514
LCLEvent: QLCLMessageEventH;
515
ASequence: QKeySequenceH;
519
function IsAnyWindowActive: Boolean;
521
Result := (QApplication_activeWindow() <> nil) or
522
(QApplication_activeModalWidget() <> nil) or
523
(QApplication_activePopupWidget() <> nil);
505
528
case QEvent_type(Event) of
530
QEventShortcutOverride: // issue #22827
532
QKeyEvent_text(QKeyEventH(Event), @AKey);
533
if (QKeyEvent_modifiers(QKeyEventH(Event)) = QtAltModifier) and
536
ASequence := QKeySequence_create(QKeyEvent_modifiers(QKeyEventH(Event))
537
or QKeyEvent_Key(QKeyEventH(Event)));
539
AParent := QWidget_parentWidget(QWidgetH(Sender));
540
if AParent <> nil then
541
Result := QApplication_notify(App, AParent, Event);
543
QKeySequence_destroy(ASequence);
506
548
QEventApplicationFontChange: SetDefaultAppFontName;
551
if (Sender = QCoreApplication_instance()) then
552
FCachedMenuBarHeight := -1;
507
554
QEventApplicationActivate:
508
if Assigned(Application) and not FEatNextDeactivate then
556
LCLEvent := QLCLMessageEvent_create(LCLQt_ApplicationActivate);
557
// activate it imediatelly (high priority)
558
QCoreApplication_postEvent(Sender, LCLEvent, 1 {high priority});
560
LCLQt_ApplicationActivate:
561
if Assigned(Application) and not FAppActive then
564
{$IF DEFINED(QTDEBUGAPPACTIVATE) OR DEFINED(VerboseQtEvents)}
565
DebugLn('TQtWidgetSet.EventFilter: Application is activated - time ',dbgs(GetTickCount));
510
567
// check if activated form is StayOnTop, if it's so, we must
511
568
// eat next appdeactivate & appactivate since we are changing form
513
570
if (StayOnTopList <> nil) then
515
W := TQtMainWindow(HWNDFromWidgetH(QApplication_activeWindow()));
516
FEatNextDeactivate := StayOnTopList.HasId(W);
571
W := TQtMainWindow(HWNDFromWidgetH(QApplication_activeWindow()))
518
574
Application.IntfAppActivate;
519
575
QtRestoreStayOnTop;
520
if (FEatNextDeactivate) and (W <> nil) then
576
if (W <> nil) and Assigned(StayOnTopList) and StayOnTopList.HasId(W) then
523
FEatNextDeactivate := False;
525
581
QEventApplicationDeactivate:
526
if Assigned(Application) and not FEatNextDeactivate then
583
// we must check if we are ready for deactivation (low priority)
584
// this is 2way check. LCLQt_ApplicationDeActivate sends
585
// LCLQt_ApplicationDeActivate_Check to be 100% sure if needed.
586
LCLEvent := QLCLMessageEvent_create(LCLQt_ApplicationDeActivate);
587
QCoreApplication_postEvent(Sender, LCLEvent, -$FF);
590
LCLQt_ApplicationDeactivate:
592
if Assigned(Application) and FAppActive then
594
if not IsAnyWindowActive then
596
QCoreApplication_sendPostedEvents(nil, QEventWindowActivate);
597
QCoreApplication_processEvents(QEventLoopAllEvents, 10 {msec});
600
// if there's active window after posting from queue, just exit ...
601
// app is not deactivated.
602
if IsAnyWindowActive then
605
// to be 100% sure that we are really deactivated, send check
606
// event with pretty low priority. We need
607
// LCLQt_ApplicationDeActivate_Check to avoid infinite loop inside
608
// this event with same code.
609
LCLEvent := QLCLMessageEvent_create(LCLQt_ApplicationDeActivate_Check);
610
QCoreApplication_postEvent(Sender, LCLEvent, -$FFFF);
615
LCLQt_ApplicationDeactivate_Check:
616
if Assigned(Application) and FAppActive then
618
// 1st send posted events, and process few events from queue
619
if not IsAnyWindowActive then
621
QCoreApplication_sendPostedEvents(nil, QEventWindowActivate);
622
QCoreApplication_processEvents(QEventLoopAllEvents, 10 {msec});
625
// if there's active window after posting from queue, just exit ...
626
// app is not deactivated.
627
if IsAnyWindowActive then
629
{$IF DEFINED(QTDEBUGAPPACTIVATE) OR DEFINED(VerboseQtEvents)}
630
DebugLn('NOTICE: TQtWidgetSet.EventFilter: App deactivation called with active windows ... ignoring.');
632
QEvent_ignore(Event);
635
{$IF DEFINED(QTDEBUGAPPACTIVATE) OR DEFINED(VerboseQtEvents)}
636
DebugLn('TQtWidgetSet.EventFilter: Application is deactivated - time ',dbgs(GetTickCount));
528
639
Application.IntfAppDeactivate;
529
640
QtRemoveStayOnTop;
532
644
QEventApplicationPaletteChange:
571
procedure TQtWidgetSet.FocusChanged(old: QWidgetH; now: QWidgetH); cdecl;
675
procedure TQtWidgetSet.FocusChanged(aold: QWidgetH; anew: QWidgetH); cdecl;
573
677
OldWidget, NewWidget: TQtWidget;
679
FocusedQtWidget: QWidgetH;
680
FocusedTQtWidget: TQtWidget;
682
{qt is tricky about focus, we don't want to inform LCL when qt internally
683
kills focus on an inactive form. eg. TTreeView->Editor enabled}
684
function CheckIfActiveForm(AWidget: TQtWidget): Boolean;
687
AMainWin: TQtMainWindow;
691
if Assigned(AWidget) and Assigned(AWidget.LCLObject) then
694
if (csDesigning in AWidget.LCLObject.ComponentState) then
696
if TQtWidget(AWidget.LCLObject.Handle) is TQtMainWindow then
697
AMainWin := TQtMainWindow(AWidget);
699
if AMainWin = nil then
701
AForm := GetParentForm(AWidget.LCLObject);
702
if Assigned(AForm) and (AForm.HandleAllocated) then
703
AMainWin := TQtMainWindow(AForm.Handle);
705
Result := AMainWin <> nil;
708
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
709
WriteLn('TQtWidgetSet.FocusChanged: CheckIfActiveForm *** NO FORM ?!? ***');
714
if AMainWin.IsMdiChild then
717
QMdiArea_activeSubWindow(QMdiSubWindow_mdiArea(QMdiSubWindowH(AMainWin.Widget))) =
718
QMdiSubWindowH(AMainWin.Widget);
721
Result := QWidget_isActiveWindow(AMainWin.Widget);
723
if (AMainWin <> AWidget) and not Supports(AWidget, IQtEdit, QtEdit) then
728
{checks when qtmdi is doing weird thing (trying to loop itself)}
729
function MDIFocusFixNeeded: Boolean;
731
OldWin, NewWin: TCustomForm;
736
if Assigned(OldWidget.LCLObject) then
737
OldWin := GetParentForm(OldWidget.LCLObject)
741
if (NewWidget <> nil) and Assigned(NewWidget.LCLObject) then
742
NewWin := GetParentForm(NewWidget.LCLObject)
746
Result := (OldWin <> nil) and OldWin.HandleAllocated and
747
((OldWin = NewWin) or (NewWin = nil));
752
// that's real window of our => form
753
Result := TQtMainWindow(OldWin.Handle).MDIChildArea <> nil;
754
// Result := Result and ((NewWin = nil) or (TQtMainWindow(NewWin.Handle).MDIChildArea <> nil));
756
Result := (OldWin = OldWidget.LCLObject) or
757
((NewWin = nil) or (NewWin = NewWidget.LCLObject));
576
// WriteLn('old: ', PtrUInt(old), ' new: ', PtrUInt(now));
577
OldWidget := GetFirstQtObjectFromWidgetH(old);
578
NewWidget := GetFirstQtObjectFromWidgetH(now);
761
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
762
WriteLn('TQtWidgetSet.FocusChanged: old: ', dbgHex(PtrUInt(aold)), ' new: ', dbgHex(PtrUInt(anew)));
764
OldWidget := GetFirstQtObjectFromWidgetH(aold);
765
NewWidget := GetFirstQtObjectFromWidgetH(anew);
580
767
if OldWidget = NewWidget then
769
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
770
WriteLn('TQtWidgetSet.FocusChanged: OldWidget = NewWidget ... exiting ...');
583
775
{Applies to all TQtWidgets which have "subwidgets" created
584
776
by CreateFrom() eg. comboBox.}
585
777
if (OldWidget <> nil) and
586
778
(NewWidget <> nil) and
587
779
(OldWidget.LCLObject = NewWidget.LCLObject) then
781
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
782
WriteLn('TQtWidgetSet.FocusChanged: exiting ... '+
783
'OldWidget.LCLObject=NewWidget.LCLObject OBJ=',dbgsName(OldWidget.LCLObject));
590
FillChar(Msg, SizeOf(Msg), 0);
591
if OldWidget <> nil then
593
//WriteLn('KILL: ', OldWidget.LCLObject.ClassName);
788
Msg.Msg := 0; // shutup compiler
789
FillChar(Msg, SizeOf(Msg), 0);
791
if IsValidHandle(HWND(NewWidget)) then
793
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
794
WriteLn('TQtWidgetSet.FocusChanged: SET ', dbgsName(NewWidget.LCLObject));
796
Msg.msg := LM_SETFOCUS;
797
Msg.wParam := PtrInt(OldWidget);
798
if (NewWidget is TQtMainWindow) and (TQtMainWindow(NewWidget).IsMdiChild) and
799
Assigned(TQtMainWindow(NewWidget).LCLObject) and
800
not (csDesigning in TQtMainWindow(NewWidget).LCLObject.ComponentState) then
802
// DO NOT TRIGGER ANYTHING, THIS IS SPURIOUS EVENT FROM MDIAREA
803
FocusedQtWidget := QWidget_focusWidget(NewWidget.Widget);
804
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
805
Writeln('TQtWidgetSet.FocusChanged: *** DO NOT SET FOCUS ***',dbgHex(PtrUInt(FocusedQtWidget)));
807
if FocusedQtWidget <> nil then
809
FocusedTQtWidget := TQtWidget(HwndFromWidgetH(FocusedQtWidget));
810
if FocusedTQtWidget <> nil then
812
if FocusedTQtWidget = NewWidget then
814
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
815
writeln('TQtWidgetSet.FocusChanged: WE CANNOT FOCUS (segfault) ',dbgsName(FocusedTQtWidget.LCLObject),
816
' Active ? ',TCustomForm(NewWidget.LCLObject).Active);
818
if Assigned(TCustomForm(NewWidget.LCLObject).ActiveControl) then
820
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
821
writeln('TQtWidgetSet.FocusChanged: THIS ONE SHOULD BE FOCUSED (1) : ',dbgsName(TCustomForm(NewWidget.LCLObject).ActiveControl));
823
if TCustomForm(NewWidget.LCLObject).ActiveControl.HandleAllocated then
825
// setFocus(TCustomForm(NewWidget.LCLObject).ActiveControl.Handle);
826
FocusedTQtWidget := TQtWidget(TCustomForm(NewWidget.LCLObject).ActiveControl.Handle);
827
if FocusedTQtWidget <> nil then
829
// first check if we are active subwin, if not then we'll trigger qt do
831
if TQtMainWindow(NewWidget).MDIChildArea.ActiveSubWindow <> NewWidget.Widget then
832
TQtMainWindow(NewWidget).MDIChildArea.ActivateSubWindow(QMDISubWindowH(NewWidget.Widget))
835
// if we are already active then just inform lcl
836
Msg.msg := LM_SETFOCUS;
837
if OldWidget = FocusedTQtWidget then
839
Msg.wParam := PtrInt(OldWidget);
840
FocusedTQtWidget.DeliverMessage(Msg);
844
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
845
writeln('TQtWidgetSet.FocusChanged: BUT NO HANDLE ... CRAP: ',dbgsName(TCustomForm(NewWidget.LCLObject).ActiveControl))
850
// if this happens then qt's mdi focus is real crap
851
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
852
writeln('TQtWidgetSet.FocusChanged: WE ARE COMPLETELY OUT OF MIND WHAT TO DO (1) .....')
858
// should never happen
859
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
860
if Assigned(TCustomForm(NewWidget.LCLObject).ActiveControl) then
861
writeln('TQtWidgetSet.FocusChanged: THIS ONE SHOULD BE FOCUSED (2) : ',dbgsName(TCustomForm(NewWidget.LCLObject).ActiveControl))
863
writeln('TQtWidgetSet.FocusChanged: WE ARE COMPLETELY OUT OF MIND WHAT TO DO (2) .....');
871
NewWidget.DeliverMessage(Msg);
874
FillChar(Msg, SizeOf(Msg), 0);
875
if IsValidHandle(HWND(OldWidget)) then
877
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
878
WriteLn('TQtWidgetSet.FocusChanged: KILL ', dbgsName(OldWidget.LCLObject),' W.Visible ',OldWidget.getVisible,
879
' destroying ? ',csDestroying in OldWidget.LCLObject.ComponentState,
880
' handle ?!? ',OldWidget.LCLObject.HandleAllocated);
594
882
Msg.msg := LM_KILLFOCUS;
595
883
Msg.wParam := PtrInt(NewWidget);
596
OldWidget.DeliverMessage(Msg);
598
if NewWidget <> nil then
600
//WriteLn('SET: ', NewWidget.LCLObject.ClassName);
601
Msg.msg := LM_SETFOCUS;
602
Msg.wParam := PtrInt(OldWidget);
603
NewWidget.DeliverMessage(Msg);
884
if ((OldWidget is TQtMainWindow) and (TQtMainWindow(OldWidget).IsMdiChild) and
885
Assigned(TQtMainWindow(OldWidget).LCLObject) and
886
not (csDesigning in TQtMainWindow(OldWidget).LCLObject.ComponentState))
887
or MDIFocusFixNeeded then
888
// DO NOT TRIGGER ANYTHING, THIS IS SPURIOUS EVENT FROM MDIAREA
889
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
890
Writeln('TQtWidgetSet.FocusChanged: *** DO NOT KILL FOCUS ***')
893
if CheckIfActiveForm(OldWidget) then
894
OldWidget.DeliverMessage(Msg)
895
{$IF DEFINED(VerboseFocus) OR DEFINED(DebugQtFocus)}
897
Writeln('TQtWidgetSet.FocusChanged: Cannot kill focus of ',dbgsName(OldWidget.LCLObject))
1089
1399
FStockDefaultDC := 0; // app must be initialized
1402
function TQtWidgetSet.GetMenuHeight: Integer;
1404
AMenuBar: QMenuBarH;
1405
DummyWindow: QMainWindowH;
1406
DummyStr: WideString;
1410
FCachedMenuBarHeight := 1;
1412
if FCachedMenuBarHeight = -1 then
1414
DummyWindow := QMainWindow_create(QApplication_desktop());
1415
QWidget_setVisible(DummyWindow, False);
1416
AMenuBar := QMenuBar_create();
1417
DummyStr := 'DUMMY BAR';
1418
QMenuBar_addMenu(AMenuBar, @DummyStr);
1419
QMainWindow_setMenuBar(DummyWindow, AMenuBar);
1420
QMenuBar_sizeHint(AMenuBar, @Size);
1421
QMainWindow_destroy(DummyWindow);
1422
FCachedMenuBarHeight := Size.cy;
1424
if QStyle_styleHint(QApplication_style(),
1425
QStyleSH_MainWindow_SpaceBelowMenuBar) > 0 then
1426
inc(FCachedMenuBarHeight, 4);
1427
if QStyle_styleHint(QApplication_style(),
1428
QStyleSH_ScrollView_FrameOnlyAroundContents) > 0 then
1429
inc(FCachedMenuBarHeight, 4);
1431
if (FCachedMenuBarHeight <= 0) then
1433
FCachedMenuBarHeight := 22;
1434
if QStyle_styleHint(QApplication_style(), QStyleSH_MainWindow_SpaceBelowMenuBar) > 0 then
1435
inc(FCachedMenuBarHeight, 4);
1437
Result := FCachedMenuBarHeight;
1092
1440
procedure TQtWidgetSet.ClearCachedColors;