diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2025-11-27 19:28:03 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2025-11-27 21:43:01 +0100 |
| commit | 36a656e6188f227956dbdf12bf5fda8be1ea7985 (patch) | |
| tree | e32bf7d43d4ea7d6466db72ba1d6f0d29f75f059 | |
| parent | 90db8b6652f73ddc335922d3a7c593878d83c45e (diff) | |
| download | tuxcmd-36a656e6188f227956dbdf12bf5fda8be1ea7985.tar.xz | |
Fix panel separator resizing
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | UMain.pas | 90 | ||||
| -rw-r--r-- | libgtk_kylix/GTKControls.pas | 151 | ||||
| -rw-r--r-- | libgtk_kylix/GTKExtCtrls.pas | 77 | ||||
| -rw-r--r-- | libgtk_kylix/GTKForms.pas | 27 | ||||
| -rw-r--r-- | libgtk_kylix/GTKView.pas | 24 |
6 files changed, 231 insertions, 142 deletions
@@ -38,7 +38,7 @@ LIB_SUFFIX=`if test \`uname -m\` = x86_64 -o \`uname -m\` = ppc64; then echo 64; # -gc doesn't play nice with threads # "-k-z noexecstack" (with quotes as a single parameter) avoids marking stack as executable, allowing to work correctly with SELinux in Enforcing mode # CFLAGS= -vewnhib -Sch -Un -Ci -Co -XX "-k-z noexecstack" -CFLAGS= -vewnhib -Sch -Ci -Co -CO -Cr -CR +CFLAGS= -vewi -Sach -Ci -Cr -CR # EXTRA_CFLAGS= -O3 @@ -55,7 +55,7 @@ tuxcmd:: tuxcmd.dpr -debug: EXTRA_CFLAGS = -g -gt -gl -gw3 -gv -O- +debug: EXTRA_CFLAGS = -gw3 -godwarfsets -gl -O1 -Co -CO debug: tuxcmd final_debug: EXTRA_CFLAGS = -g -gl -gv -O3 @@ -91,10 +91,9 @@ type miDiff, miSynchronizeDirs: TGTKMenuItem; procedure FormCreate(Sender: TObject); override; procedure FormDestroy(Sender: TObject); - procedure FormResize(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); - procedure PanelSeparatorResize(Sender: TObject); - procedure PanelSeparatorMouseUp(Sender: TObject; Button: TGDKMouseButton; Shift: TShiftState; X, Y: Integer; var Accept: boolean); + procedure PanelSeparatorPositionChanged(Sender: TObject); + procedure PanelSeparatorRealize(Sender: TObject); procedure miExitClick(Sender: TObject); procedure miAboutClick(Sender: TObject); procedure miRefreshClick(Sender: TObject); @@ -182,7 +181,7 @@ type procedure miSynchronizeDirsClick(Sender: TObject); private LeftLastFocused, Editing, QuickFind, RedrawLeftInactive, RedrawRightInactive, StartUp, LeftTabPopup: boolean; - LastWidth, RunningEscSensitive: integer; + RunningEscSensitive: integer; InplaceEditTimer, RebuildListViewsTimer, RightMouseSelectPopupTimer: TGTKTimer; InplaceEditItem: TGTKListItem; SavedCmdLine: string; @@ -300,7 +299,7 @@ begin MainVBox := TGTKVBox.Create(Self); AddControl(MainVBox); MainMenu := TGTKMenuBar.Create(Self); - MainVBox.AddControlEx(MainMenu, False, True, 0); + MainVBox.AddControlEx(MainMenu, False, False, 0); ConstructMenu; InplaceEditTimer := TGTKTimer.Create(Self); InplaceEditTimer.Enabled := False; @@ -312,14 +311,12 @@ begin RightMouseSelectPopupTimer.Enabled := False; RightMouseSelectPopupTimer.OnTimer := @RightMouseSelectPopupTimerTimer; MounterBarBox := TGTKHBox.Create(Self); - MainVBox.AddControlEx(MounterBarBox, False, True, 0); + MainVBox.AddControlEx(MounterBarBox, False, False, 0); LeftPanelBox := TGTKVBox.Create(Self); RightPanelBox := TGTKVBox.Create(Self); PanelSeparator := TGTKHPaned.Create(Self); - MainVBox.AddControlEx(PanelSeparator, True, True, 0); - PanelSeparator.Child1 := LeftPanelBox; - PanelSeparator.Child2 := RightPanelBox; ConstructPanels; + MainVBox.AddControlEx(PanelSeparator, True, True, 0); CommandLineHBox := TGTKHBox.Create(Self); CommandLineHBox.Homogeneous := False; CommandLineCombo := TGTKComboBoxEntry.Create(Self); @@ -396,15 +393,15 @@ begin F6Button.CanFocus := False; F7Button.CanFocus := False; F8Button.CanFocus := False; - PanelSeparator.OnMouseUp := @PanelSeparatorMouseUp; // Events - OnResize := @FormResize; OnDestroy := @FormDestroy; OnKeyDown := @FormKeyDown; OnClose := @FormClose; g_signal_connect_data(PGObject(FWidget), 'event-after', TGCallback(@form_event_handler), nil, nil, [G_CONNECT_AFTER]); - PanelSeparator.OnResize := @PanelSeparatorResize; + PanelSeparator.OnPositionChanged := @PanelSeparatorPositionChanged; + PanelSeparator.OnRealize := @PanelSeparatorRealize; + PanelSeparator.HandlePopupMenu := SplitterPopupMenu; LeftListView.OnKeyDown := @ListViewKeyDown; RightListView.OnKeyDown := @ListViewKeyDown; LeftListView.OnEnter := @ListViewEnter; @@ -431,8 +428,8 @@ begin RightListView.OnMouseDown := @ListViewMouseDown; LeftListView.OnMouseUp := @ListViewMouseUp; RightListView.OnMouseUp := @ListViewMouseUp; -{ LeftListView.OnDblClick := @ListViewDblClick; - RightListView.OnDblClick := @ListViewDblClick;} + LeftListView.OnDblClick := @ListViewDblClick; + RightListView.OnDblClick := @ListViewDblClick; LeftListView.OnSelectionChanged := @ListViewSelectionChanged; RightListView.OnSelectionChanged := @ListViewSelectionChanged; LeftListView.OnMouseMove := @ListViewMouseMove; @@ -449,9 +446,9 @@ end; procedure TFMain.ConstructPanels; begin LeftMounterBarBox := TGTKHBox.Create(Self); - LeftMounterBarBox.SetSizeRequest(10, -1); +// LeftMounterBarBox.SetSizeRequest(10, -1); RightMounterBarBox := TGTKHBox.Create(Self); - RightMounterBarBox.SetSizeRequest(10, -1); +// RightMounterBarBox.SetSizeRequest(10, -1); LeftMounterBarBox.BorderWidth := 2; RightMounterBarBox.BorderWidth := 2; LeftPanelBox.AddControlEx(LeftMounterBarBox, False, False, 0); @@ -462,8 +459,8 @@ begin RightStatusBox.Homogeneous := False; LeftPathLabel := TGTKLabel.Create(Self); RightPathLabel := TGTKLabel.Create(Self); - LeftPathLabel.SetSizeRequest(10, -1); - RightPathLabel.SetSizeRequest(10, -1); +// LeftPathLabel.SetSizeRequest(10, -1); +// RightPathLabel.SetSizeRequest(10, -1); LeftPathLabelEventBox := TGTKEventBox.Create(Self); RightPathLabelEventBox := TGTKEventBox.Create(Self); LeftPathLabelHBox := TGTKHBox.Create(Self); @@ -560,7 +557,7 @@ begin RightPathLabelEventBox.AddControl(RightPathLabel); LeftPanelNotebook := TEphyNotebook.Create(Self); LeftPanelNotebook.Visible := False; - LeftPanelNotebook.SetSizeRequest(10, -1); +// LeftPanelNotebook.SetSizeRequest(10, -1); LeftPanelNotebook.Scrollable := True; LeftPanelNotebook.ShowBorder := False; LeftPanelNotebook.CanFocus := False; // Notebook should be focusable to allow scrolling when many tabs -- temporarily disabled @@ -575,7 +572,7 @@ begin LeftPanelNotebook.OnTabFocusOnlyEvent := @NotebookTabFocusOnlyEvent; RightPanelNotebook := TEphyNotebook.Create(Self); RightPanelNotebook.Visible := False; - RightPanelNotebook.SetSizeRequest(10, -1); +// RightPanelNotebook.SetSizeRequest(10, -1); RightPanelNotebook.Scrollable := True; RightPanelNotebook.ShowBorder := False; RightPanelNotebook.CanFocus := False; @@ -677,13 +674,16 @@ begin RightStatusLine.MarginEnd := 5; RightStatusLine.YAlign := 0.5; { LeftStatusBox.SetSizeRequest(1, 18); - RightStatusBox.SetSizeRequest(1, 18); } + RightStatusBox.SetSizeRequest(1, 18); LeftStatusLine.SetSizeRequest(1, 18); RightStatusLine.SetSizeRequest(1, 18); LeftDiskInfoLabel.SetSizeRequest(1, -1); RightDiskInfoLabel.SetSizeRequest(1, -1); LeftQuickFindVBox.SetSizeRequest(1, -1); - RightQuickFindVBox.SetSizeRequest(1, -1); + RightQuickFindVBox.SetSizeRequest(1, -1); } + + PanelSeparator.Child1 := LeftPanelBox; + PanelSeparator.Child2 := RightPanelBox; end; procedure TFMain.ConstructMenu; @@ -1075,10 +1075,9 @@ begin if (ConfRowHeight > 0) and ConfUseFileTypeIcons then begin Column.SetImageProperty('width', ConfRowHeight); Column.SetImageProperty('height', ConfRowHeight); - end; + end; end else Column := ListView.Columns.Add; - Column.Caption := ConfColumnTitlesShort[ConfColumnIDs[i]]; g_object_set(PGObject(Column.FColumn), 'sizing', [2, 'fixed-width', ConfColumnSizes[i], nil]); @@ -1313,9 +1312,7 @@ begin end; if not ConfWMCompatMode then Show; - // Other things StartUp := False; // Set the flag to process Splitter repositioning - PanelSeparator.Position := Round(Width * (ConfPanelSep / 100)); Application.ProcessMessages; // Need to process all messages before unlocking InternalLockInit(False); @@ -1330,21 +1327,22 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) (********************************************************************************************************************************) -procedure TFMain.PanelSeparatorResize(Sender: TObject); +procedure TFMain.PanelSeparatorPositionChanged(Sender: TObject); begin - if not StartUp then ConfPanelSep := Round((PanelSeparator.Position / Width) * 100); + if (not StartUp) and (PanelSeparator.Position > 0) then + ConfPanelSep := Round((PanelSeparator.Position / PanelSeparator.Width) * 100); end; -procedure TFMain.PanelSeparatorMouseUp(Sender: TObject; Button: TGDKMouseButton; Shift: TShiftState; X, Y: Integer; var Accept: boolean); -var XLeft, XRight: gint; +procedure TFMain.PanelSeparatorRealize(Sender: TObject); begin - if Button = mbRight then begin - Accept := False; - // TODO -// gtk_widget_get_pointer(LeftPanelBox.FWidget, @XLeft, nil); -// gtk_widget_get_pointer(RightPanelBox.FWidget, @XRight, nil); - if (XLeft >= LeftPanelBox.Width) and (XRight < 0) then SplitterPopupMenu.PopUp; - end; + PanelSeparator.Position := Round(PanelSeparator.Width * (ConfPanelSep / 100)); +end; + +procedure TFMain.SplitterPopupMenuClick(Sender: TObject); +begin + if not (Sender is TGTKMenuItem) then Exit; + ConfPanelSep := Integer((Sender as TGTKMenuItem).Data); + PanelSeparator.Position := Round(PanelSeparator.Width * (ConfPanelSep / 100)); end; procedure TFMain.miExitClick(Sender: TObject); @@ -1667,16 +1665,6 @@ begin ((not LeftLastFocused) and (RightPanelEngine is TVFSEngine) and (not TVFSEngine(RightPanelEngine).ArchiveMode)); end; -procedure TFMain.FormResize(Sender: TObject); -begin - if Width <> LastWidth then begin -// DebugMsg(['FormResize: ', Width, 'x', Height]); - PanelSeparator.Position := Round(Width * (ConfPanelSep / 100)); - CommandLineLabel.SetSizeRequest(Round(Width / 2.5), -1); - LastWidth := Width; - end; -end; - procedure TFMain.PathLabelMouseDown(Sender: TObject; Button: TGDKMouseButton; Shift: TShiftState; X, Y: Integer; var Accept: boolean); begin if Button in [mbLeft, mbRight] then begin @@ -3769,14 +3757,6 @@ begin end; (********************************************************************************************************************************) -procedure TFMain.SplitterPopupMenuClick(Sender: TObject); -begin - if not (Sender is TGTKMenuItem) then Exit; - ConfPanelSep := Integer((Sender as TGTKMenuItem).Data); - PanelSeparator.Position := Round(Width * (ConfPanelSep / 100)); -end; - -(********************************************************************************************************************************) procedure TFMain.miChangePermissionsClick(Sender: TObject); var LeftPanel: boolean; AListView: TGTKListView; diff --git a/libgtk_kylix/GTKControls.pas b/libgtk_kylix/GTKControls.pas index 502e1b9..79551ff 100644 --- a/libgtk_kylix/GTKControls.pas +++ b/libgtk_kylix/GTKControls.pas @@ -40,19 +40,6 @@ const mrNoToAll = mrAll + 1; mrYesToAll = mrNoToAll + 1; -type -{$IFNDEF CPU64} // 32-bit platform - TComponent64 = class(TComponent); -{$ELSE} // 64-bit platform - TComponent64 = class(TComponent) - private - FTag: QWORD; - published - property Tag: QWORD read FTag write FTag default 0; - end; -{$ENDIF} - - type TGTKShadowType = (stNone, stShadowIn, stShadowOut, stEtchedIn, stEtchedOut); @@ -65,14 +52,16 @@ type TGDKMouseEvent = procedure (Sender: TObject; Button: TGDKMouseButton; Shift: TShiftState; X, Y: Integer; var Accept: boolean) of object; TGDKFocusEvent = procedure (Sender: TObject; var Accept: boolean) of object; TGDKExposeEvent = procedure (Sender: TObject; const Rect: PGdkRectangle; var Accept: boolean) of object; + TGDKSizeAllocateEvent = procedure (Sender: TObject; const Rect: PGdkRectangle) of object; TGTKControlState = (csNormal, csActive, csPrelight, csSelected, csInsensitive, csInconsistent, csFocused, csBackdrop, csDirLTR, cdDirRTL, csLink, csVisited, csChecked, csDropActive); - TGTKControl = class(TComponent64) + TGTKControl = class(TComponent) private FVisible: Boolean; FParent: TGTKControl; FPopupMenu: TGTKControl; FButtonPressSignalHandler, FButtonReleaseSignalHandler, FKeyDownSignalHandler, FKeyUpSignalHandler, - FFocusInSignalHandler, FFocusOutSignalHandler, FExposeSignalHandler, FMotionNotifyHandler: gulong; + FFocusInSignalHandler, FFocusOutSignalHandler, FExposeSignalHandler, FMotionNotifyHandler, + FRealizeSignalHandler, FSizeAllocateSignalHandler: gulong; FOnKeyDown: TGDKKeyEvent; FOnKeyUp: TGDKKeyEvent; FOnEnter: TGDKFocusEvent; @@ -82,6 +71,8 @@ type FOnDblClick: TGDKMouseEvent; FOnExpose: TGDKExposeEvent; FOnMouseMove: TGDKMouseEvent; + FOnRealize: TNotifyEvent; + FOnSizeAllocate: TGDKSizeAllocateEvent; FCSSProvider: PGtkCssProvider; function GetWidth: Integer; function GetHeight: Integer; @@ -124,6 +115,8 @@ type procedure SetMarginEnd(Value: Integer); procedure SetMarginTop(Value: Integer); procedure SetMarginBottom(Value: Integer); + procedure SetOnRealize(Value: TNotifyEvent); + procedure SetOnSizeAllocate(Value: TGDKSizeAllocateEvent); protected procedure SetParent(const Value: TGTKControl); virtual; public @@ -161,6 +154,8 @@ type property OnMouseMove: TGDKMouseEvent read FOnMouseMove write SetOnMouseMove; property OnDblClick: TGDKMouseEvent read FOnDblClick write SetOnDblClick; property OnExpose: TGDKExposeEvent read FOnExpose write SetOnExpose; + property OnRealize: TNotifyEvent read FOnRealize write SetOnRealize; + property OnSizeAllocate: TGDKSizeAllocateEvent read FOnSizeAllocate write SetOnSizeAllocate; property ComponentState; property ControlState: TGTKControlState read GetControlState write SetControlState; property HAlign: TGTKAlignment read GetHAlign write SetHAlign; @@ -292,6 +287,8 @@ begin FFocusInSignalHandler := 0; FFocusOutSignalHandler := 0; FExposeSignalHandler := 0; + FRealizeSignalHandler := 0; + FSizeAllocateSignalHandler := 0; FVisible := True; FWidget := nil; FPopupMenu := nil; @@ -303,6 +300,8 @@ begin FOnMouseMove := nil; FOnMouseDown := nil; FOnMouseUp := nil; + FOnRealize := nil; + FOnSizeAllocate := nil; FCSSProvider := nil; end; @@ -427,7 +426,6 @@ begin Result := not Accept; if Accept then if (Event^.button = 3) and Assigned(TGTKControl(user_data).FPopupMenu) then begin -// if Assigned(TGTKMenuItem(TGTKControl(user_data).FPopupMenu).OnPopup) then TGTKMenuItem(TGTKControl(user_data).FPopupMenu).OnPopup(TGTKMenuItem(TGTKControl(user_data).FPopupMenu)); if Assigned(TGTKMenuItem(TGTKControl(user_data).FPopupMenu).OnPopup) then TGTKMenuItem(TGTKControl(user_data).FPopupMenu).OnPopup(TGTKControl(user_data)); gtk_menu_popup(PGtkMenu(TGTKMenuItem(TGTKControl(user_data).FPopupMenu).FMenu), nil, nil, nil, nil, event^.button, event^.time); Result := False; // Allow list views to process their events - select an item beneath the cursor @@ -439,10 +437,8 @@ begin if FPopupMenu <> Value then begin FPopupMenu := Value; if not Assigned(Value) then begin - if not Assigned(FOnMouseDown) then begin - g_signal_handler_disconnect(PGObject(FWidget), FButtonPressSignalHandler); - FButtonPressSignalHandler := 0; - end; + g_signal_handler_disconnect(PGObject(FWidget), FButtonPressSignalHandler); + FButtonPressSignalHandler := 0; end else if FButtonPressSignalHandler = 0 then FButtonPressSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-press-event', TGCallback(@TGTKControl_button_press_event), Self, nil, G_CONNECT_DEFAULT) @@ -528,9 +524,13 @@ procedure TGTKControl.SetOnKeyDown(Value: TGDKKeyEvent); begin if @FOnKeyDown <> @Value then begin FOnKeyDown := Value; - if Assigned(Value) - then FKeyDownSignalHandler := g_signal_connect_data(PGObject(FWidget), 'key-press-event', TGCallback(@TGTKControl_key_press_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FKeyDownSignalHandler); + if Assigned(Value) then begin + if FKeyDownSignalHandler = 0 then + FKeyDownSignalHandler := g_signal_connect_data(PGObject(FWidget), 'key-press-event', TGCallback(@TGTKControl_key_press_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FKeyDownSignalHandler); + FKeyDownSignalHandler := 0; + end; end; end; @@ -538,9 +538,13 @@ procedure TGTKControl.SetOnKeyUp(Value: TGDKKeyEvent); begin if @FOnKeyUp <> @Value then begin FOnKeyUp := Value; - if Assigned(Value) - then FKeyUpSignalHandler := g_signal_connect_data(PGObject(FWidget), 'key-release-event', TGCallback(@TGTKControl_key_release_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FKeyUpSignalHandler); + if Assigned(Value) then begin + if FKeyUpSignalHandler = 0 then + FKeyUpSignalHandler := g_signal_connect_data(PGObject(FWidget), 'key-release-event', TGCallback(@TGTKControl_key_release_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FKeyUpSignalHandler); + FKeyUpSignalHandler := 0; + end; end; end; @@ -564,9 +568,13 @@ procedure TGTKControl.SetOnEnter(Value: TGDKFocusEvent); begin if @FOnEnter <> @Value then begin FOnEnter := Value; - if Assigned(Value) - then FFocusInSignalHandler := g_signal_connect_data(PGObject(FWidget), 'focus-in-event', TGCallback(@TGTKControl_focus_in_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FFocusInSignalHandler); + if Assigned(Value) then begin + if FFocusInSignalHandler = 0 then + FFocusInSignalHandler := g_signal_connect_data(PGObject(FWidget), 'focus-in-event', TGCallback(@TGTKControl_focus_in_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FFocusInSignalHandler); + FFocusInSignalHandler := 0; + end; end; end; @@ -574,9 +582,13 @@ procedure TGTKControl.SetOnExit(Value: TGDKFocusEvent); begin if @FOnExit <> @Value then begin FOnExit := Value; - if Assigned(Value) - then FFocusOutSignalHandler := g_signal_connect_data(PGObject(FWidget), 'focus-out-event', TGCallback(@TGTKControl_focus_out_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FFocusOutSignalHandler); + if Assigned(Value) then begin + if FFocusOutSignalHandler = 0 then + FFocusOutSignalHandler := g_signal_connect_data(PGObject(FWidget), 'focus-out-event', TGCallback(@TGTKControl_focus_out_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FFocusOutSignalHandler); + FFocusOutSignalHandler := 0; + end; end; end; @@ -591,7 +603,7 @@ begin end; end else if FButtonPressSignalHandler = 0 - then FButtonPressSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-press-event', TGCallback(@TGTKControl_button_press_event), Self, nil, G_CONNECT_DEFAULT) + then FButtonPressSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-press-event', TGCallback(@TGTKControl_button_press_event), Self, nil, G_CONNECT_DEFAULT); end; end; @@ -606,7 +618,7 @@ begin end; end else if FButtonPressSignalHandler = 0 - then FButtonPressSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-press-event', TGCallback(@TGTKControl_button_press_event), Self, nil, G_CONNECT_DEFAULT) + then FButtonPressSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-press-event', TGCallback(@TGTKControl_button_press_event), Self, nil, G_CONNECT_DEFAULT); end; end; @@ -628,8 +640,13 @@ procedure TGTKControl.SetOnMouseUp(Value: TGDKMouseEvent); begin if @FOnMouseUp <> @Value then begin FOnMouseUp := Value; - if Assigned(Value) then FButtonReleaseSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-release-event', TGCallback(@TGTKControl_button_release_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FButtonReleaseSignalHandler); + if Assigned(Value) then begin + if FButtonReleaseSignalHandler = 0 then + FButtonReleaseSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-release-event', TGCallback(@TGTKControl_button_release_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FButtonReleaseSignalHandler); + FButtonReleaseSignalHandler := 0; + end; end; end; @@ -658,8 +675,13 @@ procedure TGTKControl.SetOnMouseMove(Value: TGDKMouseEvent); begin if @FOnMouseMove <> @Value then begin FOnMouseMove := Value; - if Assigned(Value) then FMotionNotifyHandler := g_signal_connect_data(PGObject(FWidget), 'motion-notify-event', TGCallback(@TGTKControl_motion_notify_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FMotionNotifyHandler); + if Assigned(Value) then begin + if FMotionNotifyHandler = 0 then + FMotionNotifyHandler := g_signal_connect_data(PGObject(FWidget), 'motion-notify-event', TGCallback(@TGTKControl_motion_notify_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FMotionNotifyHandler); + FMotionNotifyHandler := 0; + end; end; end; @@ -696,9 +718,53 @@ procedure TGTKControl.SetOnExpose(Value: TGDKExposeEvent); begin if @FOnExpose <> @Value then begin FOnExpose := Value; - if Assigned(Value) - then FExposeSignalHandler := g_signal_connect_data(PGObject(FWidget), 'expose-event', TGCallback(@TGTKControl_expose_event), Self, nil, G_CONNECT_DEFAULT) - else g_signal_handler_disconnect(PGObject(FWidget), FExposeSignalHandler); + if Assigned(Value) then begin + if FExposeSignalHandler = 0 then + FExposeSignalHandler := g_signal_connect_data(PGObject(FWidget), 'expose-event', TGCallback(@TGTKControl_expose_event), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FExposeSignalHandler); + FExposeSignalHandler := 0; + end; + end; +end; + +procedure TGTKControl_realize(widget: PGtkWidget; user_data: gpointer); cdecl; +begin + if Assigned(TGTKControl(user_data).FOnRealize) + then TGTKControl(user_data).FOnRealize(TGTKControl(user_data)); +end; + +procedure TGTKControl.SetOnRealize(Value: TNotifyEvent); +begin + if @FOnRealize <> @Value then begin + FOnRealize := Value; + if Assigned(Value) then begin + if FRealizeSignalHandler = 0 then + FRealizeSignalHandler := g_signal_connect_data(PGObject(FWidget), 'realize', TGCallback(@TGTKControl_realize), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FRealizeSignalHandler); + FRealizeSignalHandler := 0; + end; + end; +end; + +procedure TGTKControl_size_allocate(widget : PGtkWidget; allocation : PGtkAllocation; user_data : gpointer); cdecl; +begin + if Assigned(TGTKControl(user_data).FOnSizeAllocate) + then TGTKControl(user_data).FOnSizeAllocate(TGTKControl(user_data), allocation); +end; + +procedure TGTKControl.SetOnSizeAllocate(Value: TGDKSizeAllocateEvent); +begin + if @FOnSizeAllocate <> @Value then begin + FOnSizeAllocate := Value; + if Assigned(Value) then begin + if FSizeAllocateSignalHandler = 0 then + FSizeAllocateSignalHandler := g_signal_connect_data(PGObject(FWidget), 'size-allocate', TGCallback(@TGTKControl_size_allocate), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FSizeAllocateSignalHandler); + FSizeAllocateSignalHandler := 0; + end; end; end; @@ -783,8 +849,7 @@ begin end; procedure TGTKControl.ApplyCustomCSS(Stylesheet: string); -var provider: PGtkCssProvider; - error: PGError; +var error: PGError; begin error := nil; // No stylesheet previously attached and asked to reset, nothing to do diff --git a/libgtk_kylix/GTKExtCtrls.pas b/libgtk_kylix/GTKExtCtrls.pas index 4cb925e..0adfc1a 100644 --- a/libgtk_kylix/GTKExtCtrls.pas +++ b/libgtk_kylix/GTKExtCtrls.pas @@ -23,7 +23,7 @@ unit GTKExtCtrls; interface -uses lazglib2, lazgobject2, lazgtk3, Classes, GTKControls, GTKStdCtrls, GTKMenus; +uses lazglib2, lazgobject2, lazgdk3, lazgtk3, Classes, GTKControls, GTKStdCtrls, GTKMenus; type @@ -74,12 +74,17 @@ type (****************************************** TGTKPANED ***************************************************************************) TGTKPaned = class(TGTKContainer) private + FPositionChangedSignalHandler: gulong; + FButtonPressSignalHandler: gulong; FChild1, FChild2: TGTKControl; - FOnResize: TNotifyEvent; + FOnPositionChanged: TNotifyEvent; + FHandlePopupMenu: TGTKControl; function GetPosition: integer; procedure SetPosition(Value: integer); procedure SetChild1(Value: TGTKControl); procedure SetChild2(Value: TGTKControl); + procedure SetOnPositionChanged(Value: TNotifyEvent); + procedure SetHandlePopupMenu(Value: TGTKControl); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -87,7 +92,8 @@ type property Child1: TGTKControl read FChild1 write SetChild1; property Child2: TGTKControl read FChild2 write SetChild2; property Position: integer read GetPosition write SetPosition; - property OnResize: TNotifyEvent read FOnResize write FOnResize; + property OnPositionChanged: TNotifyEvent read FOnPositionChanged write SetOnPositionChanged; + property HandlePopupMenu: TGTKControl read FHandlePopupMenu write SetHandlePopupMenu; end; (****************************************** TGTKHPANED **************************************************************************) @@ -317,15 +323,13 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) - -procedure TGTKPaned_resize(widget : PGtkWidget; allocation : PGtkAllocation; user_data : gpointer); cdecl; -begin - if Assigned(TGTKPaned(user_data).FOnResize) then TGTKPaned(user_data).FOnResize(TGTKPaned(user_data)); -end; - constructor TGTKPaned.Create(AOwner: TComponent); begin inherited Create(AOwner); + FPositionChangedSignalHandler := 0; + FButtonPressSignalHandler := 0; + FOnPositionChanged := nil; + FHandlePopupMenu := nil; FChild1 := nil; FChild2 := nil; end; @@ -338,7 +342,6 @@ end; procedure TGTKPaned.SetChild1(Value: TGTKControl); begin gtk_paned_pack1(PGtkPaned(FWidget), Value.FWidget, True, False); - g_signal_connect_data(PGObject(Value.FWidget), 'size-allocate', TGCallback(@TGTKPaned_resize), Self, nil, G_CONNECT_DEFAULT); end; procedure TGTKPaned.SetChild2(Value: TGTKControl); @@ -346,14 +349,66 @@ begin gtk_paned_pack2(PGtkPaned(FWidget), Value.FWidget, True, False); end; +// Returns -1 if position has not been changed yet function TGTKPaned.GetPosition: integer; +var position_set: gboolean; begin - Result := gtk_paned_get_position(PGtkPaned(FWidget)); + Result := -1; + position_set := False; + g_object_get(PGObject(FWidget), 'position-set', [@position_set, nil]); + if position_set then + Result := gtk_paned_get_position(PGtkPaned(FWidget)); end; procedure TGTKPaned.SetPosition(Value: integer); begin + if FPositionChangedSignalHandler > 0 then + g_signal_handler_block(FWidget, FPositionChangedSignalHandler); gtk_paned_set_position(PGtkPaned(FWidget), Value); + if FPositionChangedSignalHandler > 0 then + g_signal_handler_unblock(FWidget, FPositionChangedSignalHandler); +end; + +procedure TGTKPaned_resize(widget : PGtkWidget; pspec: PGParamSpec; user_data : gpointer); cdecl; +begin + if Assigned(TGTKPaned(user_data).FOnPositionChanged) then TGTKPaned(user_data).FOnPositionChanged(TGTKPaned(user_data)); +end; + +procedure TGTKPaned.SetOnPositionChanged(Value: TNotifyEvent); +begin + if @FOnPositionChanged <> @Value then begin + FOnPositionChanged := Value; + if Assigned(Value) then begin + if FPositionChangedSignalHandler = 0 then + FPositionChangedSignalHandler := g_signal_connect_data(PGObject(FWidget), 'notify::position', TGCallback(@TGTKPaned_resize), Self, nil, G_CONNECT_DEFAULT); + end else begin + g_signal_handler_disconnect(PGObject(FWidget), FPositionChangedSignalHandler); + FPositionChangedSignalHandler := 0; + end; + end; +end; + +function TGTKPaned_button_press_event(widget: PGtkWidget; event: PGdkEventButton; user_data: gpointer):gboolean; cdecl; +begin + if (event^.button = 3) and Assigned(TGTKPaned(user_data).FHandlePopupMenu) and + (event^.window = gtk_paned_get_handle_window(PGtkPaned(widget))) + then begin + gtk_menu_popup(PGtkMenu(TGTKMenuItem(TGTKPaned(user_data).FHandlePopupMenu).FMenu), nil, nil, nil, nil, event^.button, event^.time); + Result := True; + end; +end; + +procedure TGTKPaned.SetHandlePopupMenu(Value: TGTKControl); +begin + if FHandlePopupMenu <> Value then begin + FHandlePopupMenu := Value; + if not Assigned(Value) then begin + g_signal_handler_disconnect(PGObject(FWidget), FButtonPressSignalHandler); + FButtonPressSignalHandler := 0; + end else + if FButtonPressSignalHandler = 0 + then FButtonPressSignalHandler := g_signal_connect_data(PGObject(FWidget), 'button-press-event', TGCallback(@TGTKPaned_button_press_event), Self, nil, G_CONNECT_DEFAULT) + end; end; (********************************************************************************************************************************) diff --git a/libgtk_kylix/GTKForms.pas b/libgtk_kylix/GTKForms.pas index 0dc1691..3b159de 100644 --- a/libgtk_kylix/GTKForms.pas +++ b/libgtk_kylix/GTKForms.pas @@ -66,13 +66,11 @@ type // Some basic types private FOnClose: TCloseEvent; FOnCloseQuery: TCloseQueryEvent; - FOnResize: TNotifyEvent; FOnShow: TNotifyEvent; FCaption: string; FOnDestroy: TNotifyEvent; - FDeleteEventSignalHandlerID: gulong; - FSizeAllocateSignalHandlerID: gulong; - FShowSignalHandlerID: gulong; + FDeleteEventSignalHandler: gulong; + FShowSignalHandler: gulong; function GetWindowPosition: TWindowPosition; function GetResizeable: boolean; function GetWindowTypeHint: TGDKWindowTypeHint; @@ -97,7 +95,6 @@ type // Some basic types property Visible write SetVisible default False; property OnClose: TCloseEvent read FOnClose write FOnClose; property OnCloseQuery: TCloseQueryEvent read FOnCloseQuery write FOnCloseQuery; - property OnResize: TNotifyEvent read FOnResize write FOnResize; property OnShow: TNotifyEvent read FOnShow write FOnShow; property Caption: string read FCaption write SetCaption; property WindowPosition: TWindowPosition read GetWindowPosition write SetWindowPosition; @@ -277,20 +274,14 @@ begin if Assigned(TCustomGTKForm(user_data).FOnShow) then TCustomGTKForm(user_data).FOnShow(TCustomGTKForm(user_data)); end; -procedure TCustomGTKForm_size_allocate(widget : PGtkWidget; allocation : PGtkAllocation; user_data : gpointer); cdecl; -begin - if Assigned(TCustomGTKForm(user_data).FOnResize) then TCustomGTKForm(user_data).FOnResize(TCustomGTKForm(user_data)); -end; - constructor TCustomGTKForm.Create(AOwner: TComponent); begin inherited Create(AOwner); FOnClose := nil; FOnCloseQuery := nil; FOnDestroy := nil; - FDeleteEventSignalHandlerID := 0; - FSizeAllocateSignalHandlerID := 0; - FShowSignalHandlerID := 0; + FDeleteEventSignalHandler := 0; + FShowSignalHandler := 0; FCaption := ''; FAccelGroup := gtk_accel_group_new; Screen.AddForm(Self); @@ -300,18 +291,16 @@ destructor TCustomGTKForm.Destroy; begin Screen.RemoveForm(Self); if Assigned(FOnDestroy) then FOnDestroy(Self); -// if FDeleteEventSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FDeleteEventSignalHandlerID); -// if FSizeAllocateSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FSizeAllocateSignalHandlerID); -// if FShowSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FShowSignalHandlerID); +// if FDeleteEventSignalHandler > 0 then g_signal_handler_disconnect(PGObject(FWidget), FDeleteEventSignalHandler); +// if FShowSignalHandler > 0 then g_signal_handler_disconnect(PGObject(FWidget), FShowSignalHandler); if not Application.Terminated then gtk_widget_destroy(FWidget); inherited Destroy; end; procedure TCustomGTKForm.ConnectDefaultSignals; begin - FDeleteEventSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'delete-event', TGCallback(@TCustomGTKForm_delete_event), Self, nil, G_CONNECT_DEFAULT); - FSizeAllocateSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'size-allocate', TGCallback(@TCustomGTKForm_size_allocate), Self, nil, G_CONNECT_DEFAULT); - FShowSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'show', TGCallback(@TCustomGTKForm_show), Self, nil, G_CONNECT_DEFAULT); + FDeleteEventSignalHandler := g_signal_connect_data(PGObject(FWidget), 'delete-event', TGCallback(@TCustomGTKForm_delete_event), Self, nil, G_CONNECT_DEFAULT); + FShowSignalHandler := g_signal_connect_data(PGObject(FWidget), 'show', TGCallback(@TCustomGTKForm_show), Self, nil, G_CONNECT_DEFAULT); end; procedure TCustomGTKForm.SetVisible(Value: Boolean); diff --git a/libgtk_kylix/GTKView.pas b/libgtk_kylix/GTKView.pas index 1ac742b..bf940df 100644 --- a/libgtk_kylix/GTKView.pas +++ b/libgtk_kylix/GTKView.pas @@ -258,9 +258,9 @@ type FSortable: boolean; FCompareFunc: TGTKTreeViewCompareFunc; FOnColumnsChanged: TNotifyEvent; - FChangedSignalHandlerID: gulong; - FRowActivatedSignalHandlerID: gulong; - FColumnsChangedSignalHandlerID: gulong; + FChangedSignalHandler: gulong; + FRowActivatedSignalHandler: gulong; + FColumnsChangedSignalHandler: gulong; protected FListItems: TGTKListItems; procedure Recreate; @@ -488,9 +488,9 @@ end; constructor TGTKListView.Create(AOwner: TComponent); begin inherited Create(AOwner); - FChangedSignalHandlerID := 0; - FRowActivatedSignalHandlerID := 0; - FColumnsChangedSignalHandlerID := 0; + FChangedSignalHandler := 0; + FRowActivatedSignalHandler := 0; + FColumnsChangedSignalHandler := 0; FListItems := TGTKListItems.Create(Self); FSortable := False; FCompareFunc := nil; @@ -499,9 +499,9 @@ end; destructor TGTKListView.Destroy; begin -// if FChangedSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FSelection), FChangedSignalHandlerID); -// if FRowActivatedSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FRowActivatedSignalHandlerID); -// if FColumnsChangedSignalHandlerID > 0 then g_signal_handler_disconnect(PGObject(FWidget), FColumnsChangedSignalHandlerID); +// if FChangedSignalHandler > 0 then g_signal_handler_disconnect(PGObject(FSelection), FChangedSignalHandler); +// if FRowActivatedSignalHandler > 0 then g_signal_handler_disconnect(PGObject(FWidget), FRowActivatedSignalHandler); +// if FColumnsChangedSignalHandler > 0 then g_signal_handler_disconnect(PGObject(FWidget), FColumnsChangedSignalHandler); FListItems.Free; inherited Destroy; end; @@ -540,9 +540,9 @@ begin FWidget := gtk_tree_view_new_with_model(PGtkTreeModel(FTreeModelSort)); end; FSelection := gtk_tree_view_get_selection(PGtkTreeView(FWidget)); - FChangedSignalHandlerID := g_signal_connect_data(PGObject(FSelection), 'changed', TGCallback(@TGTKListView_changed), Self, nil, G_CONNECT_DEFAULT); - FRowActivatedSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'row-activated', TGCallback(@TGTKListView_row_activated), Self, nil, G_CONNECT_DEFAULT); - FColumnsChangedSignalHandlerID := g_signal_connect_data(PGObject(FWidget), 'columns-changed', TGCallback(@TGTKListView_columns_changed), Self, nil, [G_CONNECT_AFTER]); + FChangedSignalHandler := g_signal_connect_data(PGObject(FSelection), 'changed', TGCallback(@TGTKListView_changed), Self, nil, G_CONNECT_DEFAULT); + FRowActivatedSignalHandler := g_signal_connect_data(PGObject(FWidget), 'row-activated', TGCallback(@TGTKListView_row_activated), Self, nil, G_CONNECT_DEFAULT); + FColumnsChangedSignalHandler := g_signal_connect_data(PGObject(FWidget), 'columns-changed', TGCallback(@TGTKListView_columns_changed), Self, nil, [G_CONNECT_AFTER]); FTreeModel := gtk_tree_view_get_model(PGtkTreeView(FWidget)); Show; end; |
