From e8883e24afeafa54cd84a8f8ae784e510ffa7ee3 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Fri, 14 Jun 2013 18:44:58 +0000 Subject: [PATCH] RxMDI - fix MDIForm.ActiveControl on change MDI windows git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2752 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/curredit.pas | 32 ++++++++-------- components/rx/dateutil.pas | 4 +- components/rx/pickdate.pas | 15 ++++---- components/rx/rxclock.pas | 10 ++--- components/rx/rxmdi.pas | 71 +++++++++++++++++++++++++---------- components/rx/rxsortmemds.pas | 2 +- components/rx/rxspin.pas | 4 +- components/rx/rxtimeedit.pas | 4 +- components/rx/rxtoolbar.pas | 31 --------------- 9 files changed, 87 insertions(+), 86 deletions(-) diff --git a/components/rx/curredit.pas b/components/rx/curredit.pas index d7244a927..50980260f 100644 --- a/components/rx/curredit.pas +++ b/components/rx/curredit.pas @@ -207,7 +207,7 @@ var begin Result := False; for I := 1 to Length(Value) do - if not (Value[I] in [DecimalSeparator, '-', '+', '0'..'9', 'e', 'E']) then + if not (Value[I] in [DefaultFormatSettings.DecimalSeparator, '-', '+', '0'..'9', 'e', 'E']) then Exit; Result := TextToFloat(StrPLCopy(Buffer, Value, SizeOf(Buffer) - 1), RetValue, fvExtended); @@ -223,7 +223,7 @@ begin IsSign := (MaxSym > 0) and (S[1] in ['-', '+']); if IsSign then MinSym := 2 else MinSym := 1; - I := Pos(DecimalSeparator, S); + I := Pos(DefaultFormatSettings.DecimalSeparator, S); if I > 0 then MaxSym := I - 1; I := Pos('E', AnsiUpperCase(S)); if I > 0 then MaxSym := Min(I - 1, MaxSym); @@ -234,7 +234,7 @@ begin Inc(Group); if (Group = 3) and Thousands and (I > MinSym) then begin Group := 0; - Result := ThousandSeparator + Result; + Result := DefaultFormatSettings.ThousandSeparator + Result; end; end; if IsSign then Result := S[1] + Result; @@ -415,13 +415,13 @@ end; function TCustomNumEdit.TextToValText(const AValue: string): string; begin Result := Trim(AValue); - if DecimalSeparator <> ThousandSeparator then begin + if DefaultFormatSettings.DecimalSeparator <> DefaultFormatSettings.ThousandSeparator then begin Result := DelChars(Result, ThousandSeparator); end; - if (DecimalSeparator <> '.') and (ThousandSeparator <> '.') then - Result := StringReplace(Result, '.', DecimalSeparator, [rfReplaceAll]); - if (DecimalSeparator <> ',') and (ThousandSeparator <> ',') then - Result := StringReplace(Result, ',', DecimalSeparator, [rfReplaceAll]); + if (DefaultFormatSettings.DecimalSeparator <> '.') and (DefaultFormatSettings.ThousandSeparator <> '.') then + Result := StringReplace(Result, '.', DefaultFormatSettings.DecimalSeparator, [rfReplaceAll]); + if (DefaultFormatSettings.DecimalSeparator <> ',') and (DefaultFormatSettings.ThousandSeparator <> ',') then + Result := StringReplace(Result, ',', DefaultFormatSettings.DecimalSeparator, [rfReplaceAll]); if Result = '' then Result := '0' else if Result = '-' then Result := '-0'; end; @@ -623,8 +623,8 @@ begin THack(FPopup).KeyPress(Key); Key := #0; end;} - if Key in ['.', ','] - [ThousandSeparator] then - Key := DecimalSeparator; + if Key in ['.', ','] - [DefaultFormatSettings.ThousandSeparator] then + Key := DefaultFormatSettings.DecimalSeparator; inherited KeyPress(Key); if (Key in [#32..#255]) and not IsValidChar(Key) then begin @@ -650,7 +650,7 @@ begin System.Delete(S, ASelStart + 1, SelStop - ASelStart); System.Insert(Key, S, ASelStart + 1); S := TextToValText(S); - DecPos := Pos(DecimalSeparator, S); + DecPos := Pos(DefaultFormatSettings.DecimalSeparator, S); if (DecPos > 0) then begin ASelStart := Pos('E', UpperCase(S)); @@ -661,7 +661,7 @@ begin if DecPos > Integer(FDecimalPlaces) then Exit; - if S[1] = DecimalSeparator then + if S[1] = DefaultFormatSettings.DecimalSeparator then s := '0' + s; end; Result := IsValidFloat(S, RetValue); @@ -690,11 +690,11 @@ var I: Integer; C: Char; begin - Result := ',0.' + DupeString('0', CurrencyDecimals); + Result := ',0.' + DupeString('0', DefaultFormatSettings.CurrencyDecimals); CurrStr := ''; - for I := 1 to Length(CurrencyString) do + for I := 1 to Length(DefaultFormatSettings.CurrencyString) do begin - C := CurrencyString[I]; + C := DefaultFormatSettings.CurrencyString[I]; if C in [',', '.'] then begin CurrStr := CurrStr + '''' + C + '''' @@ -702,7 +702,7 @@ begin else CurrStr := CurrStr + C; end; if Length(CurrStr) > 0 then - case CurrencyFormat of + case DefaultFormatSettings.CurrencyFormat of 0: Result := CurrStr + Result; { '$1' } 1: Result := Result + CurrStr; { '1$' } 2: Result := CurrStr + ' ' + Result; { '$ 1' } diff --git a/components/rx/dateutil.pas b/components/rx/dateutil.pas index 848656543..1c0633027 100644 --- a/components/rx/dateutil.pas +++ b/components/rx/dateutil.pas @@ -434,10 +434,8 @@ begin Result := False; Y := 0; M := 0; D := 0; DateOrder := GetDateOrder(DateFormat); -{$IFDEF RX_D3} - if ShortDateFormat[1] = 'g' then { skip over prefix text } + if DefaultFormatSettings.ShortDateFormat[1] = 'g' then { skip over prefix text } ScanToNumber(S, Pos); -{$ENDIF RX_D3} if not (ScanNumber(S, MaxInt, Pos, N1) and ScanChar(S, Pos, DateSeparator) and ScanNumber(S, MaxInt, Pos, N2)) then Exit; if ScanChar(S, Pos, DateSeparator) then begin diff --git a/components/rx/pickdate.pas b/components/rx/pickdate.pas index 810daae9c..808351529 100644 --- a/components/rx/pickdate.pas +++ b/components/rx/pickdate.pas @@ -636,7 +636,7 @@ begin OldNotify := TStringList(FShortDaysOfWeek).OnChange; TStringList(FShortDaysOfWeek).OnChange := nil; for Ind := 1 to 7 do - FShortDaysOfWeek.Add(SysUtils.ShortDayNames[Ind]); + FShortDaysOfWeek.Add(DefaultFormatSettings.ShortDayNames[Ind]); TStringList(FShortDaysOfWeek).OnChange := OldNotify; end; end; @@ -953,8 +953,8 @@ begin FMonthNames := TStringList.Create; if FMonthNames.Count = 0 then begin - for i := Low(LongMonthNames) to High(LongMonthNames) do - FMonthNames.Add(LongMonthNames[i]); + for i := Low(DefaultFormatSettings.LongMonthNames) to High(DefaultFormatSettings.LongMonthNames) do + FMonthNames.Add(DefaultFormatSettings.LongMonthNames[i]); end; BackPanel := TPanel.Create(Self); @@ -1204,7 +1204,7 @@ var AYear, AMonth, ADay: Word; begin DecodeDate(FCalendar.CalendarDate, AYear, AMonth, ADay); - FTitleLabel.Caption := Format('%s, %d', [LongMonthNames[AMonth], AYear]); + FTitleLabel.Caption := Format('%s, %d', [DefaultFormatSettings.LongMonthNames[AMonth], AYear]); end; procedure TPopupCalendar.SetDate(const AValue: TDateTime); @@ -1214,7 +1214,8 @@ end; procedure TPopupCalendar.SetMonthNames(const AValue: TStrings); begin - if AValue.Text <> FMonthNames.Text then begin + if AValue.Text <> FMonthNames.Text then + begin FMonthNames.Assign(AValue); CalendarChange(Self); end; @@ -1558,7 +1559,7 @@ var begin if StrDate <> '' then begin try - DateValue := StrToDateFmt(ShortDateFormat, StrDate); + DateValue := StrToDateFmt(DefaultFormatSettings.ShortDateFormat, StrDate); except DateValue := Date; end; @@ -1566,7 +1567,7 @@ begin else DateValue := Date; Result := SelectDate(DateValue, DlgCaption, AStartOfWeek, AWeekends, AWeekendColor, BtnHints); - if Result then StrDate := FormatDateTime(ShortDateFormat, DateValue); + if Result then StrDate := FormatDateTime(DefaultFormatSettings.ShortDateFormat, DateValue); end; { TRxCalendarGrid } diff --git a/components/rx/rxclock.pas b/components/rx/rxclock.pas index 710cbf09f..2b4bd4534 100644 --- a/components/rx/rxclock.pas +++ b/components/rx/rxclock.pas @@ -244,8 +244,8 @@ procedure InvalidTime(Hour, Min, Sec: Word); var sTime: string[50]; begin - sTime := IntToStr(Hour) + TimeSeparator + IntToStr(Min) + - TimeSeparator + IntToStr(Sec); + sTime := IntToStr(Hour) + DefaultFormatSettings.TimeSeparator + IntToStr(Min) + + DefaultFormatSettings.TimeSeparator + IntToStr(Sec); raise EConvertError.CreateFmt(SInvalidTime, [sTime]); end; @@ -488,9 +488,9 @@ begin TimeStr := '88888'; if FShowSeconds then TimeStr := TimeStr + '888'; if FTwelveHour then begin - if Canvas.TextWidth(TimeAMString) > Canvas.TextWidth(TimePMString) then - TimeStr := TimeStr + ' ' + TimeAMString - else TimeStr := TimeStr + ' ' + TimePMString; + if Canvas.TextWidth(DefaultFormatSettings.TimeAMString) > Canvas.TextWidth(DefaultFormatSettings.TimePMString) then + TimeStr := TimeStr + ' ' + DefaultFormatSettings.TimeAMString + else TimeStr := TimeStr + ' ' + DefaultFormatSettings.TimePMString; end; SetNewFontSize(Canvas, TimeStr, H, W); Font := Canvas.Font; diff --git a/components/rx/rxmdi.pas b/components/rx/rxmdi.pas index 567762ba4..5610afc3b 100644 --- a/components/rx/rxmdi.pas +++ b/components/rx/rxmdi.pas @@ -35,6 +35,7 @@ type TRxMDIButton = class(TSpeedButton) private FNavForm: TForm; + FActiveControl:TWinControl; FNavPanel:TRxMDITasks; FSaveClose:TCloseEvent; procedure SetRxMDIForm(AValue: TForm); @@ -115,11 +116,14 @@ type procedure navCloseButtonClick(Sender: TObject); procedure SetRxMDICloseButton(AValue: TRxMDICloseButton); procedure SetTaskPanel(AValue: TRxMDITasks); + function MDIButtonByForm(AForm:TForm):TRxMDIButton; + procedure HideCurrentWindow; protected procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Loaded; override; public constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; procedure ShowWindow(F:TForm); procedure ChildWindowsAdd(F:TForm); @@ -244,7 +248,7 @@ begin FCurrentChildWindow.Close; end; -procedure TRxMDIPanel.SeTRxMDICloseButton(AValue: TRxMDICloseButton); +procedure TRxMDIPanel.SetRxMDICloseButton(AValue: TRxMDICloseButton); begin if FCloseButton=AValue then Exit; if Assigned(FCloseButton) then @@ -270,6 +274,36 @@ begin FTaskPanel.FMainPanel:=Self; end; +function TRxMDIPanel.MDIButtonByForm(AForm: TForm): TRxMDIButton; +var + i:integer; +begin + Result:=nil; + if not Assigned(FTaskPanel) then + exit; + for i:=0 to FTaskPanel.ComponentCount -1 do + begin + if (FTaskPanel.Components[i] is TRxMDIButton) and (TRxMDIButton(FTaskPanel.Components[i]).NavForm = AForm) then + begin + Result:=TRxMDIButton(FTaskPanel.Components[i]); + exit; + end; + end; +end; + +procedure TRxMDIPanel.HideCurrentWindow; +var + MB:TRxMDIButton; +begin + if Assigned(FCurrentChildWindow) and (FCurrentChildWindow.Visible) then + begin + MB:=MDIButtonByForm(FCurrentChildWindow); + if Assigned(MB) then + MB.FActiveControl:=Application.MainForm.ActiveControl; + FCurrentChildWindow.Hide; + end; +end; + procedure TRxMDIPanel.Notification(AComponent: TComponent; Operation: TOperation ); begin @@ -295,6 +329,11 @@ begin BevelOuter:=bvLowered; end; +destructor TRxMDIPanel.Destroy; +begin + inherited Destroy; +end; + procedure TRxMDIPanel.ShowWindow(F: TForm); begin TaskPanel.ShowWindow(F); @@ -304,6 +343,7 @@ procedure TRxMDIPanel.ChildWindowsAdd(F: TForm); var B:TRxMDIButton; begin + HideCurrentWindow; F.BorderStyle:=bsNone; F.Align:=alClient; F.Parent:=Self; @@ -312,6 +352,7 @@ begin Application.MainForm.ActiveControl:=F; B:=TRxMDIButton.CreateButton(TaskPanel, F); + end; procedure TRxMDIPanel.ChildWindowsCreate(var AForm; FC: TFormClass); @@ -320,6 +361,7 @@ var begin if not Assigned(FForm) then begin + HideCurrentWindow; FForm:=FC.Create(Self); ChildWindowsAdd(FForm); end @@ -568,29 +610,16 @@ begin if Assigned(FNavForm) then begin FSaveClose:=FNavForm.OnClose; + //FSaveDeactivate:=FNavForm.OnDeactivate; FNavForm.OnClose:=@FormClose; + //FNavForm.OnDeactivate:=@FormDeactivate; + Caption:=' '+FNavForm.Caption+' '; DoCreateButtonImage; if Assigned(FNavPanel) then FNavPanel.FMainPanel.CurrentChildWindow:=NavForm; end; - -{ if NavForm is TfbmDBObjectEditorForm then - begin - B:=TBitmap.Create; - try - B.Width:=fbManagerMainForm.ImageList2.Width; - B.Height:=fbManagerMainForm.ImageList2.Height; - B.Canvas.Brush.Color:=Color; - B.Canvas.FillRect(0,0, B.Width, B.Height); - FImageIndex:=ord(TfbmDBObjectEditorForm(NavForm).DBObject.DBObjectKind) + 2; - fbManagerMainForm.ImageList2.Draw(B.Canvas, 0,0,FImageIndex); - Glyph.Assign(B); - finally - B.Free; - end; - end;} end; procedure TRxMDIButton.DoCreateMenuItems; @@ -704,9 +733,13 @@ begin inherited Click; if Assigned(FNavForm) then begin - FNavForm.BringToFront; + FNavPanel.FMainPanel.HideCurrentWindow; + FNavForm.Show; + //FNavForm.BringToFront; FNavPanel.FMainPanel.CurrentChildWindow:=NavForm; - Application.MainForm.ActiveControl:=NavForm.ActiveControl; + //Application.MainForm.ActiveControl:=NavForm.ActiveControl; + if Assigned(FActiveControl) then + FActiveControl.SetFocus; end; Down:=true; end; diff --git a/components/rx/rxsortmemds.pas b/components/rx/rxsortmemds.pas index 222dafdd3..b90e3640c 100644 --- a/components/rx/rxsortmemds.pas +++ b/components/rx/rxsortmemds.pas @@ -64,7 +64,7 @@ type procedure TRxMemoryDataSortEngine.UpdateFooterRows(ADataSet: TDataSet; AGrid: TRxDBGrid); var - i, j:integer; + i:integer; Col:TRxColumn; DHL:THackDataLink; diff --git a/components/rx/rxspin.pas b/components/rx/rxspin.pas index 234cba8a3..1a6f60b74 100644 --- a/components/rx/rxspin.pas +++ b/components/rx/rxspin.pas @@ -692,8 +692,8 @@ var begin ValidChars := ['+', '-', '0'..'9']; if ValueType = vtFloat then begin - if Pos(DecimalSeparator, Text) = 0 then - ValidChars := ValidChars + [DecimalSeparator]; + if Pos(DefaultFormatSettings.DecimalSeparator, Text) = 0 then + ValidChars := ValidChars + [DefaultFormatSettings.DecimalSeparator]; if Pos('E', AnsiUpperCase(Text)) = 0 then ValidChars := ValidChars + ['e', 'E']; end diff --git a/components/rx/rxtimeedit.pas b/components/rx/rxtimeedit.pas index 3c71aac69..ae1ee0cea 100644 --- a/components/rx/rxtimeedit.pas +++ b/components/rx/rxtimeedit.pas @@ -224,7 +224,7 @@ begin else if P < 6 then IncMin else IncSec; - Text:=Format('%2.2d'+ TimeSeparator +'%2.2d'+ TimeSeparator +'%2.2d', [H1, M2, S3]); + Text:=Format('%2.2d'+ DefaultFormatSettings.TimeSeparator +'%2.2d'+ DefaultFormatSettings.TimeSeparator +'%2.2d', [H1, M2, S3]); SetSelStart(P); end; @@ -293,7 +293,7 @@ begin FButton.OnTopClick := @UpClick; FButton.OnBottomClick := @DownClick; - EditMask:='!#0'+TimeSeparator + '00'+TimeSeparator + '00;1;_'; + EditMask:='!#0'+DefaultFormatSettings.TimeSeparator + '00'+DefaultFormatSettings.TimeSeparator + '00;1;_'; end; destructor TCustomRxTimeEdit.Destroy; diff --git a/components/rx/rxtoolbar.pas b/components/rx/rxtoolbar.pas index e70c1e15e..e7a637d5c 100644 --- a/components/rx/rxtoolbar.pas +++ b/components/rx/rxtoolbar.pas @@ -215,7 +215,6 @@ type procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure SetCustomizing(AValue:boolean); - procedure DoAutoSize; Override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure RequestAlign; override; @@ -1086,36 +1085,6 @@ begin FToolbarItems[i].FButton.SetDesign(AValue, FToolbarItems[i]); end; -procedure TToolPanel.DoAutoSize; -var - i, H:integer; - -begin -{ - if not AutoSizeCanStart then exit; - if csDesigning in ComponentState then exit; - - if Items.Count > 0 then - begin - try - H:=0; - for i:=0 to Items.Count-1 do - if Assigned(Items[i].FButton) and Items[i].FButton.HandleObjectShouldBeVisible then - H:=Max(H, Items[i].Height); - if H>0 then - begin - H:=H +BorderWidth * 2; - SetBoundsKeepBase(Left,Top,Width,H,true); - ReAlignToolBtn; - end; - finally - end -// Exclude(FControlFlags,cfAutoSizeNeeded); - end - else } - inherited DoAutoSize; -end; - procedure TToolPanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin