~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to lcl/lazdialogs.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit lazdialogs;
 
2
 
 
3
{$mode delphi}
 
4
 
 
5
interface
 
6
 
 
7
uses
 
8
  // RTL
 
9
  Classes, SysUtils,
 
10
  // LCL
 
11
  Forms, ShellCtrls, Buttons, StdCtrls, ExtCtrls, FileCtrl, ComCtrls,
 
12
  Dialogs, ButtonPanel, lclstrconsts, FileUtil, Controls;
 
13
 
 
14
type
 
15
  TLazFileDialogKind = (
 
16
    ldkOpenDesktop, ldkSaveDesktop, ldkOpenPDA, ldkSavePDA, ldkSelectDirectory);
 
17
 
 
18
  { TLazarusFileDialogForm }
 
19
 
 
20
  TLazarusFileDialogForm = class(TForm)
 
21
  private
 
22
    FKind: TLazFileDialogKind;
 
23
    procedure SetFilter(AFilter: string);
 
24
  public
 
25
    // User interface
 
26
    ButtonPanel: TButtonPanel;
 
27
    ShellTreeView: TShellTreeView;
 
28
    ShellListView: TShellListView;
 
29
    SaveEdit: TEdit;
 
30
    FilterComboBox: TFilterComboBox;
 
31
    // input/output
 
32
    FileName: string;
 
33
    Filter: string;
 
34
    InitialDir: string;
 
35
    Title: string;
 
36
    //
 
37
    constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;
 
38
    procedure Initialize(AKind: TLazFileDialogKind);
 
39
    procedure HandleOkClick(ASender: TObject);
 
40
    procedure HandleCancelClick(ASender: TObject);
 
41
    procedure HandleCloseQuery(Sender : TObject; var CanClose : boolean);
 
42
    procedure HandleEditChange(ASender: TObject);
 
43
    procedure HandleSelectItem(Sender: TObject;
 
44
     Item: TListItem; Selected: Boolean);
 
45
    procedure HandleTreeViewSelectionChanged(ASender: TObject);
 
46
  end;
 
47
 
 
48
  { TLazOpenDialog }
 
49
 
 
50
  TLazOpenDialog = class(TOpenDialog)
 
51
  protected
 
52
    FForm: TLazarusFileDialogForm;
 
53
    class procedure WSRegisterClass; override;
 
54
    function DoExecute: boolean; override;
 
55
    procedure DoInitialize; virtual;
 
56
  public
 
57
    constructor Create(TheOwner: TComponent); override;
 
58
  end;
 
59
 
 
60
  { TLazSaveDialog }
 
61
 
 
62
  TLazSaveDialog = class(TLazOpenDialog)
 
63
  protected
 
64
    procedure DoInitialize; override;
 
65
  end;
 
66
 
 
67
  { TLazSelectDirectoryDialog }
 
68
 
 
69
  TLazSelectDirectoryDialog = class(TLazOpenDialog)
 
70
  protected
 
71
    procedure DoInitialize; override;
 
72
  end;
 
73
 
 
74
implementation
 
75
 
 
76
{ TLazarusFileDialogForm }
 
77
 
 
78
procedure TLazarusFileDialogForm.SetFilter(AFilter: string);
 
79
begin
 
80
  if AFilter = '' then
 
81
    FilterComboBox.Filter := Format(rsAllFiles,[GetAllFilesMask, GetAllFilesMask,''])
 
82
  else
 
83
    FilterComboBox.Filter := AFilter;
 
84
end;
 
85
 
 
86
{
 
87
  The size of the window is determined only when creating the
 
88
  handle, so any reference to TForm.Width and TForm.Height
 
89
  here doesnt correspond to the final value.
 
90
}
 
91
constructor TLazarusFileDialogForm.CreateNew(AOwner: TComponent; Num: Integer = 0);
 
92
begin
 
93
  inherited CreateNew(AOwner, Num);
 
94
 
 
95
  Self.Position := poScreenCenter;
 
96
end;
 
97
 
 
98
procedure TLazarusFileDialogForm.Initialize(AKind: TLazFileDialogKind);
 
99
begin
 
100
  FKind := AKind;
 
101
 
 
102
  ButtonPanel := TButtonPanel.Create(Self);
 
103
  ButtonPanel.Parent := Self;
 
104
  ButtonPanel.Left := 0;
 
105
  ButtonPanel.Height := 20;
 
106
  ButtonPanel.Top := Height - ButtonPanel.Height;
 
107
  ButtonPanel.Width := Width;
 
108
  ButtonPanel.Align := alBottom;
 
109
  ButtonPanel.ShowButtons := [pbOK, pbCancel];
 
110
  ButtonPanel.OKButton.OnClick := HandleOkClick;
 
111
  ButtonPanel.CancelButton.OnClick := HandleCancelClick;
 
112
 
 
113
  if AKind in [ldkOpenDesktop, ldkSaveDesktop, ldkOpenPDA, ldkSavePDA] then
 
114
  begin
 
115
    // Add the ShellTreeView to the dialog
 
116
    ShellTreeView := TShellTreeView.Create(Self);
 
117
    ShellTreeView.Parent := Self;
 
118
    ShellTreeView.Left := 0;
 
119
    ShellTreeView.Top := 0;
 
120
    ShellTreeView.Width := Width;
 
121
    ShellTreeView.Height := 100;
 
122
    ShellTreeView.Align := alTop;
 
123
 
 
124
    // Add the ShellListView to the dialog
 
125
    ShellListView := TShellListView.Create(Self);
 
126
    ShellListView.Parent := Self;
 
127
    ShellListView.Left := 0;
 
128
    ShellListView.Top := ShellTreeView.Height;
 
129
    ShellListView.Width := Width;
 
130
    ShellListView.Height := Height - ShellTreeView.Height - ButtonPanel.Height;
 
131
    ShellListView.Align := alClient;
 
132
    ShellListView.ShellTreeView := ShellTreeView;
 
133
    ShellListView.ScrollBars := ssVertical;
 
134
    ShellListView.OnSelectItem := HandleSelectItem;
 
135
 
 
136
    // TEdit for save dialog
 
137
    if AKind in [ldkSaveDesktop, ldkSavePDA] then
 
138
    begin
 
139
      SaveEdit := TEdit.Create(Self);
 
140
      SaveEdit.Parent := Self;
 
141
      SaveEdit.Left := 0;
 
142
      SaveEdit.Height := 20;
 
143
      SaveEdit.Top := Height - ButtonPanel.Height - SaveEdit.Height;
 
144
      SaveEdit.Width := Width;
 
145
      SaveEdit.Align := alBottom;
 
146
      SaveEdit.Text := SysUtils.ExtractFileName(FileName);
 
147
      SaveEdit.OnChange := HandleEditChange;
 
148
    end;
 
149
 
 
150
    // TFilterComboBox
 
151
    FilterComboBox := TFilterComboBox.Create(Self);
 
152
    FilterComboBox.Parent := Self;
 
153
    FilterComboBox.Left := 0;
 
154
    FilterComboBox.Height := 20;
 
155
    FilterComboBox.Top := Height - ButtonPanel.Height - FilterComboBox.Height;
 
156
    if SaveEdit <> nil then
 
157
      FilterComboBox.Top := FilterComboBox.Top - SaveEdit.Height;
 
158
    FilterComboBox.Width := Width;
 
159
    FilterComboBox.Align := alBottom;
 
160
    SetFilter(Filter);
 
161
    FilterComboBox.ShellListView := ShellListView;
 
162
 
 
163
    // In the save dialog it is enabled when there is a text in the TEdit
 
164
    if AKind in [ldkSaveDesktop, ldkSavePDA] then
 
165
      ButtonPanel.OKButton.Enabled := SaveEdit.Text <> ''
 
166
    // In a TOpenDialog the Ok button is only enabled when a file is selected
 
167
    else
 
168
      ButtonPanel.OkButton.Enabled := False;
 
169
  end
 
170
  else if FKind = ldkSelectDirectory then
 
171
  begin
 
172
    // Add the ShellTreeView to the dialog
 
173
    ShellTreeView := TShellTreeView.Create(Self);
 
174
    ShellTreeView.Parent := Self;
 
175
    ShellTreeView.Left := 0;
 
176
    ShellTreeView.Top := 0;
 
177
    ShellTreeView.Align := alClient;
 
178
    ShellTreeView.OnSelectionChanged := HandleTreeViewSelectionChanged;
 
179
 
 
180
    ButtonPanel.OKButton.Enabled := False;
 
181
  end;
 
182
 
 
183
  // Form events
 
184
  OnCloseQuery := HandleCloseQuery;
 
185
end;
 
186
 
 
187
// The Ok button code should be only a simple mrOk,
 
188
// because there is the dialog Ok button, which will
 
189
// always be active and will set the ModalResult to mrOk
 
190
// so the code needs to affect it too, and this can be
 
191
// done in CloseQuery
 
192
procedure TLazarusFileDialogForm.HandleOkClick(ASender: TObject);
 
193
begin
 
194
  ModalResult := mrOk;
 
195
end;
 
196
 
 
197
procedure TLazarusFileDialogForm.HandleCancelClick(ASender: TObject);
 
198
begin
 
199
  ModalResult := mrCancel;
 
200
end;
 
201
 
 
202
procedure TLazarusFileDialogForm.HandleCloseQuery(Sender: TObject;
 
203
  var CanClose: boolean);
 
204
begin
 
205
  if ModalResult = mrCancel then
 
206
  begin
 
207
    CanClose := True;
 
208
    Exit;
 
209
  end;
 
210
 
 
211
  CanClose := False;
 
212
 
 
213
  if FKind in [ldkSaveDesktop, ldkSavePDA] then
 
214
  begin
 
215
    if SaveEdit.Text = '' then Exit;
 
216
 
 
217
    FileName := ShellTreeView.GetPathFromNode(ShellTreeView.Selected);
 
218
    FileName := IncludeTrailingPathDelimiter(FileName);
 
219
    FileName := FileName + SaveEdit.Text;
 
220
    CanClose := True;
 
221
  end
 
222
  else if FKind in [ldkOpenDesktop, ldkOpenPDA] then
 
223
  begin
 
224
    if ShellListView.Selected = nil then Exit;
 
225
 
 
226
    FileName := ShellListView.GetPathFromItem(ShellListView.Selected);
 
227
    CanClose := True;
 
228
  end
 
229
  else
 
230
  begin
 
231
    if ShellTreeView.Selected = nil then Exit;
 
232
 
 
233
    FileName := ShellTreeView.GetPathFromNode(ShellTreeView.Selected);
 
234
    CanClose := True;
 
235
  end;
 
236
end;
 
237
 
 
238
procedure TLazarusFileDialogForm.HandleEditChange(ASender: TObject);
 
239
begin
 
240
  ButtonPanel.OkButton.Enabled := SaveEdit.Text <> '';
 
241
end;
 
242
 
 
243
procedure TLazarusFileDialogForm.HandleSelectItem(Sender: TObject;
 
244
  Item: TListItem; Selected: Boolean);
 
245
begin
 
246
  // Selecting an item changes the filename in the TEdit
 
247
  // in save dialogs
 
248
  if (FKind in [ldkSaveDesktop, ldkSavePDA]) and Selected then
 
249
  begin
 
250
    SaveEdit.Text := Item.Caption;
 
251
  end
 
252
  // In the OpenDialog the state of the Ok button is dependent
 
253
  // on the selection of an item
 
254
  else
 
255
  begin
 
256
    ButtonPanel.OkButton.Enabled := Selected;
 
257
  end;
 
258
end;
 
259
 
 
260
// Used only in the TLazSelectDirectoryDialog
 
261
procedure TLazarusFileDialogForm.HandleTreeViewSelectionChanged(ASender: TObject);
 
262
begin
 
263
  ButtonPanel.OKButton.Enabled := True;
 
264
end;
 
265
 
 
266
{ TLazOpenDialog }
 
267
 
 
268
class procedure TLazOpenDialog.WSRegisterClass;
 
269
begin
 
270
  // Do nothing, because this dialog doesn't require a WS implementation
 
271
end;
 
272
 
 
273
function TLazOpenDialog.DoExecute: boolean;
 
274
begin
 
275
  Result := FForm.ShowModal <> mrCancel;
 
276
  FileName := FForm.FileName;
 
277
end;
 
278
 
 
279
procedure TLazOpenDialog.DoInitialize;
 
280
begin
 
281
  FForm.Initialize(ldkOpenDesktop);
 
282
end;
 
283
 
 
284
constructor TLazOpenDialog.Create(TheOwner: TComponent);
 
285
begin
 
286
  inherited Create(TheOwner);
 
287
  FForm := TLazarusFileDialogForm.CreateNew(Self);
 
288
  FForm.FileName := FileName;
 
289
  FForm.Filter := Filter;
 
290
  FForm.Title := Title;
 
291
  DoInitialize;
 
292
  FForm.Hide;
 
293
end;
 
294
 
 
295
{ TLazSaveDialog }
 
296
 
 
297
procedure TLazSaveDialog.DoInitialize;
 
298
begin
 
299
  FForm.Initialize(ldkSaveDesktop);
 
300
end;
 
301
 
 
302
{ TLazSelectDirectoryDialog }
 
303
 
 
304
procedure TLazSelectDirectoryDialog.DoInitialize;
 
305
begin
 
306
  FForm.Initialize(ldkSelectDirectory);
 
307
end;
 
308
 
 
309
end.
 
310