ADD: TfrmViewer.AdjustViewerSize() - корректный метод подбора размера окна для отображения картинки

небольшая оптимизация ShowViewer() в fviewer.pas
This commit is contained in:
zolotov-alex 2007-04-19 13:12:10 +00:00
commit 5ce613d9ed
7 changed files with 220 additions and 180 deletions

View file

@ -32,9 +32,9 @@ Col1=33
Col2=48
Col3=76
Col4=216
Viewer.left=232
Viewer.top=240
Viewer.height=216
Viewer.left=385
Viewer.top=307
Viewer.height=100
Viewer.width=350
Editor.left=0
Editor.top=8
@ -53,7 +53,7 @@ zip=87,X:\DC\svn\doublecmd\plugins\zip\bin\zip.wcx
7z=87,X:\Totalcmd\Plugins\wcx\7zip\7zip.wcx
[left]
path=d:\svn\
path=d:\picture\
[right]
path=D:\\

View file

@ -12,6 +12,7 @@
<IconPath Value="./"/>
<TargetFileExt Value=""/>
<Title Value="Double Commander"/>
<ActiveEditorIndexAtStart Value="3"/>
</General>
<PublishOptions>
<Version Value="2"/>
@ -47,7 +48,7 @@
<PackageName Value="JPEGForLazarus"/>
</Item5>
</RequiredPackages>
<Units Count="31">
<Units Count="32">
<Unit0>
<Filename Value="doublecmd.lpr"/>
<IsPartOfProject Value="True"/>
@ -63,8 +64,8 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="fbtnchangedlg.lrs"/>
<UnitName Value="fbtnchangedlg"/>
<CursorPos X="1" Y="11"/>
<TopLine Value="23"/>
<CursorPos X="22" Y="32"/>
<TopLine Value="11"/>
<UsageCount Value="200"/>
</Unit1>
<Unit2>
@ -85,17 +86,19 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="fmain.lrs"/>
<UnitName Value="fMain"/>
<CursorPos X="29" Y="1525"/>
<TopLine Value="1515"/>
<UsageCount Value="95"/>
<CursorPos X="22" Y="1737"/>
<TopLine Value="1726"/>
<EditorIndex Value="3"/>
<UsageCount Value="99"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="uwcxprototypes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uWCXprototypes"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="163"/>
<TopLine Value="5"/>
<UsageCount Value="167"/>
</Unit4>
<Unit5>
<Filename Value="fviewer.pas"/>
@ -104,9 +107,14 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="fviewer.lrs"/>
<UnitName Value="fViewer"/>
<CursorPos X="36" Y="568"/>
<TopLine Value="559"/>
<UsageCount Value="20"/>
<CursorPos X="13" Y="22"/>
<TopLine Value="185"/>
<EditorIndex Value="0"/>
<UsageCount Value="24"/>
<Bookmarks Count="1">
<Item0 X="3" Y="162" ID="0"/>
</Bookmarks>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="feditor.pas"/>
@ -115,9 +123,11 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="feditor.lrs"/>
<UnitName Value="fEditor"/>
<CursorPos X="30" Y="668"/>
<TopLine Value="664"/>
<UsageCount Value="20"/>
<CursorPos X="20" Y="183"/>
<TopLine Value="292"/>
<EditorIndex Value="2"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
<Filename Value="fLngForm.pas"/>
@ -126,9 +136,9 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="fLngForm.lrs"/>
<UnitName Value="fLngForm"/>
<CursorPos X="48" Y="38"/>
<TopLine Value="34"/>
<UsageCount Value="20"/>
<CursorPos X="31" Y="18"/>
<TopLine Value="13"/>
<UsageCount Value="24"/>
</Unit7>
<Unit8>
<Filename Value="fMsg.pas"/>
@ -139,7 +149,7 @@
<UnitName Value="fMsg"/>
<CursorPos X="18" Y="57"/>
<TopLine Value="55"/>
<UsageCount Value="21"/>
<UsageCount Value="25"/>
</Unit8>
<Unit9>
<Filename Value="dmdialogs.pas"/>
@ -150,7 +160,7 @@
<UnitName Value="dmDialogs"/>
<CursorPos X="27" Y="12"/>
<TopLine Value="5"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit9>
<Unit10>
<Filename Value="dmhigh.pas"/>
@ -161,7 +171,7 @@
<UnitName Value="dmHigh"/>
<CursorPos X="31" Y="51"/>
<TopLine Value="44"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit10>
<Unit11>
<Filename Value="feditorconf.pas"/>
@ -170,9 +180,9 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="feditorconf.lrs"/>
<UnitName Value="fEditorConf"/>
<CursorPos X="21" Y="366"/>
<TopLine Value="361"/>
<UsageCount Value="20"/>
<CursorPos X="47" Y="89"/>
<TopLine Value="82"/>
<UsageCount Value="24"/>
</Unit11>
<Unit12>
<Filename Value="ffindview.pas"/>
@ -183,7 +193,7 @@
<UnitName Value="fFindView"/>
<CursorPos X="32" Y="72"/>
<TopLine Value="67"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit12>
<Unit13>
<Filename Value="fAbout.pas"/>
@ -194,7 +204,7 @@
<UnitName Value="fAbout"/>
<CursorPos X="34" Y="77"/>
<TopLine Value="70"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit13>
<Unit14>
<Filename Value="foptions.pas"/>
@ -205,7 +215,7 @@
<UnitName Value="fOptions"/>
<CursorPos X="33" Y="352"/>
<TopLine Value="346"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit14>
<Unit15>
<Filename Value="fFileOpDlg.pas"/>
@ -216,7 +226,7 @@
<UnitName Value="fFileOpDlg"/>
<CursorPos X="35" Y="133"/>
<TopLine Value="123"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit15>
<Unit16>
<Filename Value="fmkdir.pas"/>
@ -227,7 +237,7 @@
<UnitName Value="fMkDir"/>
<CursorPos X="33" Y="48"/>
<TopLine Value="41"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit16>
<Unit17>
<Filename Value="fCopyDlg.pas"/>
@ -238,7 +248,7 @@
<UnitName Value="fCopyDlg"/>
<CursorPos X="33" Y="41"/>
<TopLine Value="36"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit17>
<Unit18>
<Filename Value="fcomparefiles.pas"/>
@ -249,7 +259,7 @@
<UnitName Value="fCompareFiles"/>
<CursorPos X="35" Y="161"/>
<TopLine Value="152"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit18>
<Unit19>
<Filename Value="fmovedlg.pas"/>
@ -260,7 +270,7 @@
<UnitName Value="fMoveDlg"/>
<CursorPos X="37" Y="48"/>
<TopLine Value="37"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit19>
<Unit20>
<Filename Value="fFindDlg.pas"/>
@ -271,7 +281,7 @@
<UnitName Value="fFindDlg"/>
<CursorPos X="34" Y="514"/>
<TopLine Value="506"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit20>
<Unit21>
<Filename Value="fhotdir.pas"/>
@ -282,7 +292,7 @@
<UnitName Value="fHotDir"/>
<CursorPos X="43" Y="66"/>
<TopLine Value="62"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit21>
<Unit22>
<Filename Value="fsymlink.pas"/>
@ -293,7 +303,7 @@
<UnitName Value="fSymLink"/>
<CursorPos X="41" Y="67"/>
<TopLine Value="61"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit22>
<Unit23>
<Filename Value="fhardlink.pas"/>
@ -304,7 +314,7 @@
<UnitName Value="fHardLink"/>
<CursorPos X="37" Y="65"/>
<TopLine Value="61"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit23>
<Unit24>
<Filename Value="fmultirename.pas"/>
@ -315,7 +325,7 @@
<UnitName Value="fMultiRename"/>
<CursorPos X="35" Y="464"/>
<TopLine Value="461"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit24>
<Unit25>
<Filename Value="fpackdlg.pas"/>
@ -326,7 +336,7 @@
<UnitName Value="fPackDlg"/>
<CursorPos X="46" Y="159"/>
<TopLine Value="149"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit25>
<Unit26>
<Filename Value="flinker.pas"/>
@ -337,7 +347,7 @@
<UnitName Value="fLinker"/>
<CursorPos X="44" Y="168"/>
<TopLine Value="162"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit26>
<Unit27>
<Filename Value="fsplitter.pas"/>
@ -348,7 +358,7 @@
<UnitName Value="fSplitter"/>
<CursorPos X="44" Y="191"/>
<TopLine Value="187"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit27>
<Unit28>
<Filename Value="fattrib.pas"/>
@ -359,7 +369,7 @@
<UnitName Value="fAttrib"/>
<CursorPos X="9" Y="64"/>
<TopLine Value="52"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit28>
<Unit29>
<Filename Value="ffileproperties.pas"/>
@ -370,7 +380,7 @@
<UnitName Value="fFileProperties"/>
<CursorPos X="18" Y="264"/>
<TopLine Value="253"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit29>
<Unit30>
<Filename Value="fchown.pas"/>
@ -381,10 +391,68 @@
<UnitName Value="fChown"/>
<CursorPos X="51" Y="178"/>
<TopLine Value="160"/>
<UsageCount Value="20"/>
<UsageCount Value="24"/>
</Unit30>
<Unit31>
<Filename Value="uglobs.pas"/>
<UnitName Value="uGlobs"/>
<CursorPos X="3" Y="67"/>
<TopLine Value="12"/>
<EditorIndex Value="1"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit31>
</Units>
<JumpHistory Count="0" HistoryIndex="-1"/>
<JumpHistory Count="12" HistoryIndex="11">
<Position1>
<Filename Value="fviewer.pas"/>
<Caret Line="137" Column="16" TopLine="121"/>
</Position1>
<Position2>
<Filename Value="fviewer.pas"/>
<Caret Line="237" Column="14" TopLine="235"/>
</Position2>
<Position3>
<Filename Value="fviewer.pas"/>
<Caret Line="66" Column="27" TopLine="51"/>
</Position3>
<Position4>
<Filename Value="fviewer.pas"/>
<Caret Line="449" Column="27" TopLine="449"/>
</Position4>
<Position5>
<Filename Value="fviewer.pas"/>
<Caret Line="456" Column="20" TopLine="448"/>
</Position5>
<Position6>
<Filename Value="fviewer.pas"/>
<Caret Line="66" Column="24" TopLine="55"/>
</Position6>
<Position7>
<Filename Value="fviewer.pas"/>
<Caret Line="103" Column="21" TopLine="93"/>
</Position7>
<Position8>
<Filename Value="fviewer.pas"/>
<Caret Line="470" Column="8" TopLine="457"/>
</Position8>
<Position9>
<Filename Value="fmain.pas"/>
<Caret Line="1525" Column="29" TopLine="1515"/>
</Position9>
<Position10>
<Filename Value="fviewer.pas"/>
<Caret Line="301" Column="10" TopLine="288"/>
</Position10>
<Position11>
<Filename Value="fviewer.pas"/>
<Caret Line="121" Column="21" TopLine="116"/>
</Position11>
<Position12>
<Filename Value="fmain.pas"/>
<Caret Line="191" Column="26" TopLine="184"/>
</Position12>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>

View file

@ -1,10 +1,10 @@
inherited frmEditor: TfrmEditor
Left = 436
Height = 488
Top = 292
Width = 733
HorzScrollBar.Page = 732
VertScrollBar.Page = 467
Left = 372
Height = 220
Top = 253
Width = 342
HorzScrollBar.Page = 341
VertScrollBar.Page = 199
VertScrollBar.Range = 19
ActiveControl = Editor
Caption = 'frmEditor'
@ -16,8 +16,8 @@ inherited frmEditor: TfrmEditor
Position = poScreenCenter
object StatusBar: TStatusBar
Height = 23
Top = 445
Width = 733
Top = 177
Width = 342
Panels = <
item
Width = 50
@ -34,8 +34,8 @@ inherited frmEditor: TfrmEditor
SimplePanel = False
end
object Editor: TSynEdit
Height = 445
Width = 733
Height = 177
Width = 342
Align = alClient
Anchors = [akTop]
Font.Color = clBlack
@ -460,8 +460,8 @@ inherited frmEditor: TfrmEditor
end
end
object ActListEdit: TActionList
left = 128
top = 232
left = 96
top = 8
object actAbout: TAction
Category = 'Help'
Caption = 'About'

View file

@ -175,26 +175,19 @@ begin
end;
procedure ShowEditor(const sFileName:String);
{var
i:Integer;}
var editor: TfrmEditor;
begin
with TfrmEditor.Create(Application) do
begin
Left:=gEditorPos.Left;
Top:=gEditorPos.Top;
Width:=gEditorPos.Width;
Height:=gEditorPos.Height;
try
LoadAttrFromFile(gpIniDir+csDefaultName);
if sFileName='' then
actFileNew.Execute
else
OpenFile(sFileName);
ShowOnTop;
finally
// Free;
end;
editor := TfrmEditor.Create(Application);
gEditorPos.Restore(editor);
try
LoadAttrFromFile(gpIniDir+csDefaultName);
if sFileName='' then
editor.actFileNew.Execute
else
editor.OpenFile(sFileName);
editor.ShowOnTop;
finally
//editor.Free;
end;
end;
@ -636,11 +629,7 @@ begin
closefile(f);
end;
gEditorPos.Left:= Left;
gEditorPos.Top:= Top;
gEditorPos.Width:= Width;
gEditorPos.Height:= Height;
gEditorPos.Save(Self);
end;

View file

@ -1,13 +1,15 @@
inherited frmViewer: TfrmViewer
Left = 349
Height = 273
Height = 100
Top = 287
Width = 320
HorzScrollBar.Page = 319
VertScrollBar.Page = 252
Width = 200
HorzScrollBar.Page = 199
VertScrollBar.Page = 79
VertScrollBar.Range = 19
ActiveControl = ScrollBarVert
Caption = 'frmViewer'
Constraints.MinHeight = 100
Constraints.MinWidth = 200
KeyPreview = True
Menu = MainMenu
OnClose = frmViewerClose
@ -18,8 +20,8 @@ inherited frmViewer: TfrmViewer
Position = poDefault
object Status: TStatusBar
Height = 23
Top = 230
Width = 320
Top = 57
Width = 200
Panels = <
item
Width = 200
@ -36,16 +38,16 @@ inherited frmViewer: TfrmViewer
SimplePanel = False
end
object nbPages: TNotebook
Height = 230
Width = 320
Height = 57
Width = 200
Align = alClient
PageIndex = 0
ShowTabs = False
object pgText: TPage
Caption = 'pgText'
object ScrollBarVert: TScrollBar
Left = 297
Height = 222
Left = 177
Height = 49
Width = 15
Align = alRight
Anchors = [akTop, akRight]
@ -59,8 +61,8 @@ inherited frmViewer: TfrmViewer
end
object ViewerControl: TViewerControl
Cursor = crIBeam
Height = 222
Width = 297
Height = 49
Width = 177
Font.Height = -14
Font.Name = 'fixed'
Font.Pitch = fpFixed

View file

@ -94,12 +94,13 @@ type
var ScrollPos: Integer);
private
{ Private declarations }
sList:TStringList;
FileList: TStringList;
iActiveFile:Integer;
bImage:Boolean;
FFindDialog:TfrmFindView;
procedure UpDateScrollBar;
Function CheckGraphics(const sFileName:String):Boolean;
procedure AdjustViewerSize(ReqWidth, ReqHeight: Integer);
procedure LoadGraphics(const sFileName:String);
procedure DoSearch;
public
@ -118,38 +119,14 @@ uses
uLng, uShowMsg, uGlobs, lcltype, lazjpeg{$IFNDEF WIN32}, uFindMmap{$ENDIF} ;
procedure ShowViewer(sl:TStringList);
var
x:Integer;
var viewer: TfrmViewer;
begin
// writeln('ShowViewer - Using Internal');
With TfrmViewer.Create(Application) do
begin
// writeln('ShowViewer - Using Internal - created');
Left:=gViewerPos.Left;
Top:=gViewerPos.Top;
Width:=gViewerPos.Width;
Height:=gViewerPos.Height;
try
sList:=TStringList.Create;
// writeln('ShowViewer - Using Internal - before assign');
for x:=0 to sl.Count-1 do
begin
writeln('Viewing:',sl.Strings[x]);
sList.Add(sl.Strings[x]);
end;
// writeln('ShowViewer - Using Internal - after assign');
ViewerControl.ViewerMode:=vmText;
// miProcess.Checked:=False;
LoadFile(0);
Show;//Modal;
finally
// Free;
end;
end;
//writeln('ShowViewer - Using Internal');
viewer := TfrmViewer.Create(Application);
gViewerPos.Restore(viewer);
viewer.FileList.Assign(sl);
viewer.LoadFile(0);
viewer.Show;
end;
procedure TfrmViewer.LoadLng;
@ -186,14 +163,14 @@ procedure TfrmViewer.LoadFile(iIndex:Integer);
begin
// writeln('Viewer: LoadFile:',iIndex);
iActiveFile:=iIndex;
Caption:=sList.Strings[iIndex];
Caption:=FileList.Strings[iIndex];
Screen.Cursor:=crHourGlass;
try
// writeln('View: BeforeCheckGraphics:',iIndex);
if CheckGraphics(sList.Strings[iIndex]) then
if CheckGraphics(FileList.Strings[iIndex]) then
begin
// writeln('View: LoadGraphics:',iIndex);
LoadGraphics(sList.Strings[iIndex]);
LoadGraphics(FileList.Strings[iIndex]);
end
else
begin
@ -205,18 +182,16 @@ begin
nbPages.ActivePageComponent:=pgText;
ViewerControl.UnMapFile; // if any mapped
// miProcess.Click;
ViewerControl.MapFile(sList.Strings[iIndex]); //handled by miProcess.Click
ViewerControl.MapFile(FileList.Strings[iIndex]); //handled by miProcess.Click
UpDateScrollBar;
end;
Status.Panels[0].Text:=sList.Strings[iIndex];
Status.Panels[1].Text:=Format('%d/%d',[iIndex+1,slist.Count]);
Status.Panels[0].Text:=FileList.Strings[iIndex];
Status.Panels[1].Text:=Format('%d/%d',[iIndex+1,FileList.Count]);
finally
Screen.Cursor:=crDefault;
end;
end;
procedure TfrmViewer.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (key='N') or (key='n') then
@ -257,12 +232,7 @@ begin
// TODO: may be better automtic save
// (see also TfrmViewer.miSavePosClick)
CloseAction:=caFree;
gViewerPos.Left := Left;
gViewerPos.Top := Top;
gViewerPos.Width := Width;
gViewerPos.Height := Height;
write('Save to gViewerPos = ');
dbgShowWindowPos(gViewerPos);
if not bImage then gViewerPos.Save(Self);
end;
procedure TfrmViewer.frmViewerKeyDown(Sender: TObject; var Key: Word;
@ -310,7 +280,7 @@ end;
procedure TfrmViewer.miNextClick(Sender: TObject);
begin
inherited;
if iActiveFile+1>=sList.Count then
if iActiveFile+1>=FileList.Count then
LoadFile(0)
else
LoadFile(iActiveFile+1);
@ -322,17 +292,13 @@ begin
if iActiveFile>0 then
LoadFile(iActiveFile-1)
else
LoadFile(sList.Count-1);
LoadFile(FileList.Count-1);
end;
procedure TfrmViewer.miSavePosClick(Sender: TObject);
begin
// TODO: It really need? may be better automtic save
// (see also TfrmViewer.frmViewerClose)
gViewerPos.Left:=Left;
gViewerPos.Top:=Top;
gViewerPos.Width:=Width;
gViewerPos.Height:=Height;
gViewerPos.Save(Self);
msgOK(lngGetString(clngPositionSaved));
end;
@ -342,7 +308,6 @@ begin
Image.Stretch:=miStretch.Checked;
end;
procedure TfrmViewer.miTextClick(Sender: TObject);
begin
ReMmapIfNeed;
@ -383,6 +348,8 @@ procedure TfrmViewer.FormCreate(Sender: TObject);
begin
// writeln('TfrmViewer.FormCreate');
inherited;
FileList := TStringList.Create;
FFindDialog:=nil; // dialog is created in first use
{ Status.Panels[0].Width:=50;
Status.Panels[1].Width:=50;}
@ -392,6 +359,7 @@ end;
procedure TfrmViewer.FormDestroy(Sender: TObject);
begin
FileList.Free;
if assigned(FFindDialog) then
FreeAndNil(FFindDialog);
inherited;
@ -408,12 +376,12 @@ begin
if not miProcess.Checked then
begin
// if ViewerControl.DataAccess=dtNothing then
ViewerControl.MapFile(sList.Strings[iActiveFile]);
ViewerControl.MapFile(FileList.Strings[iActiveFile]);
miProcess.Checked:=not miProcess.Checked;
end
else
begin
sCurrName:=sList.Strings[iActiveFile];
sCurrName:=FileList.Strings[iActiveFile];
sViewCmd:=gExts.GetCommandText(lowercase(ExtractFileExt(sCurrName)),'view');
if (sViewCmd='') then Exit;
sViewCmd:=Copy(sViewCmd, pos('=',sViewCmd)+1, length(sViewCmd));
@ -438,7 +406,7 @@ begin
if bImage then
begin
bImage:=False;
ViewerControl.MapFile(sList.Strings[iActiveFile]);
ViewerControl.MapFile(FileList.Strings[iActiveFile]);
miImage.Visible:=False;
miEdit.Visible:=True;
bImage:=False;
@ -464,8 +432,8 @@ end;
procedure TfrmViewer.miGraphicsClick(Sender: TObject);
begin
inherited;
if CheckGraphics(sList.Strings[iActiveFile]) then
LoadGraphics(sList.Strings[iActiveFile]);
if CheckGraphics(FileList.Strings[iActiveFile]) then
LoadGraphics(FileList.Strings[iActiveFile]);
end;
Function TfrmViewer.CheckGraphics(const sFileName:String):Boolean;
@ -479,19 +447,24 @@ begin
(sExt='.ddw') or (sExt='.tga');
end;
// Adjust Viewer size (width and height) to view image
// with dimensions ReqWidth/ReqHeight
procedure TfrmViewer.AdjustViewerSize(ReqWidth, ReqHeight: Integer);
var
dx, dy: Integer;
begin
dx := Width - ViewerControl.Width;
dy := Height - ViewerControl.Height;
Width := ReqWidth + dx;
Height := ReqHeight + dy;
end;
procedure TfrmViewer.LoadGraphics(const sFileName:String);
begin
// writeln('TfrmViewer.Load graphics');
Image.Stretch:=miStretch.Checked;
Image.Picture.LoadFromFile(sFileName);
if Image.Picture.Width<350 then
Width:=350
else
Width:=Image.Picture.Width+10;
if Image.Picture.Height<100 then
Height:=100
else
Height:=Image.Picture.Height+Status.Height+10; // bulgarian constant
with Image.Picture do AdjustViewerSize(Width, Height);
nbPages.ActivePageComponent:=pgImage;
miImage.Visible:=True;
miEdit.Visible:=False;

View file

@ -16,22 +16,19 @@ unit uGlobs;
interface
uses
Classes, uExts, uColorExt, Graphics, IniFiles;
Classes, Controls, uExts, uColorExt, Graphics, IniFiles;
type
TWindowPos = record
TControlPosition = object
Left: Integer;
Top: Integer;
Width: Integer;
Height: Integer;
procedure Save(Control: TControl);
procedure Restore(Control: TControl);
end;
const
// TODO: It's really need?
// SaveRect and SaveGlobs depends on this
cTopBorder = 23; // px on top is title
cLeftBorder = 6; // px on left
var
gDirSortFirst:Boolean=True; // want to show dir first in panels
gDirHistoryCount:Integer=30; // how many history we remember
@ -67,15 +64,15 @@ var
gViewerFontName:String;
gViewerSize:Integer;
gViewerPos:TWindowPos;
gEditorPos:TWindowPos;
gViewerPos:TControlPosition;
gEditorPos:TControlPosition;
function LoadGlobs : Boolean;
procedure SaveGlobs;
function LoadStringsFromFile(var list:TStringList; const sFileName:String):boolean;
// for debugging only, can be removed
procedure dbgShowWindowPos(const pos: TWindowPos);
procedure dbgShowWindowPos(const pos: TControlPosition);
const
cMaxStringItems=50;
@ -88,7 +85,7 @@ uses
SysUtils, uGlobsPaths, uLng, uShowMsg;
// for debugging only, can be removed
procedure dbgShowWindowPos(const pos: TWindowPos);
procedure dbgShowWindowPos(const pos: TControlPosition);
begin
writeln('TWindowPos');
writeln('Left: ', pos.Left);
@ -98,20 +95,31 @@ begin
writeln('END');
end;
procedure LoadWindowPos(var pos:TWindowPos; sPrefix:String);
procedure TControlPosition.Save(Control: TControl);
begin
writeln('LoadWindowPos(',sPrefix,') enter');
Left := Control.Left;
Top := Control.Top;
Width := Control.Width;
Height := Control.Height;
end;
procedure TControlPosition.Restore(Control: TControl);
begin
Control.Left := Left;
Control.Top := Top;
Control.Width := Width;
Control.Height := Height;
end;
procedure LoadWindowPos(var pos:TControlPosition; sPrefix:String);
begin
pos.Left:=gIni.ReadInteger('Configuration', sPrefix+'left',50);
pos.Top:=gIni.ReadInteger('Configuration', sPrefix+'top',50);
pos.Width:= gIni.ReadInteger('Configuration', sPrefix+'width',300);
pos.Height:= gIni.ReadInteger('Configuration', sPrefix+'height',400);
dbgShowWindowPos(pos);
writeln('LoadWindowPos(',sPrefix,') leave');
end;
procedure SaveWindowPos(pos: TWindowPos; sPrefix:String);
procedure SaveWindowPos(pos: TControlPosition; sPrefix:String);
begin
gIni.WriteInteger('Configuration', sPrefix+'left', pos.Left);
gIni.WriteInteger('Configuration', sPrefix+'top', pos.Top);