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

« back to all changes in this revision

Viewing changes to lcl/include/icon.inc

  • 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:
20
20
 
21
21
const
22
22
  IconSignature: array [0..3] of char = #0#0#1#0;
23
 
  CursorSignature: array [0..3] of char = #0#0#2#0;
24
 
  
 
23
 
25
24
type
26
25
  TIconHeader = {packed} record // packed it not needed
27
26
    idReserved: Word; // 0
54
53
  PIconDirEntry = ^TIconDirEntry;
55
54
 
56
55
  // executables and libraries has the next structures for icons and cursors
 
56
  PGrpIconDirEntry = ^TGrpIconDirEntry;
57
57
  TGrpIconDirEntry = packed record
58
 
    bWidth: Byte;               // Width, in pixels, of the image
59
 
    bHeight: Byte;              // Height, in pixels, of the image
60
 
    bColorCount: Byte;          // Number of colors in image (0 if >=8bpp)
61
 
    bReserved: Byte;            // Reserved
62
 
    case Byte of
63
 
      1: (
64
 
        // icon
65
 
        wPlanes: Word;          // color planes
66
 
        wBpp: Word;             // bits per pixel
67
 
        // common
68
 
        dwBytesInRes: Dword;    // how many bytes in this resource?
69
 
        nID: Word;              // the ID
70
 
      );
71
 
      2:(
72
 
        // cursor
73
 
        wXHotSpot: Word;
74
 
        wYHotSpot: Word;
75
 
      );
76
 
  end;
77
 
 
78
 
  TGrpIconDir = packed record
 
58
    bWidth: Byte;           // Width, in pixels, of the image
 
59
    bHeight: Byte;          // Height, in pixels, of the image
 
60
    bColorCount: Byte;      // Number of colors in image (0 if >=8bpp)
 
61
    bReserved: Byte;        // Reserved
 
62
    wPlanes: Word;          // color planes
 
63
    wBpp: Word;             // bits per pixel
 
64
    dwBytesInRes: Dword;    // how many bytes in this resource?
 
65
    nID: Word;              // the ID
 
66
  end;
 
67
 
 
68
  PGrpCursorDirEntry = ^TGrpCursorDirEntry;
 
69
  TGrpCursorDirEntry = packed record
 
70
    wWidth: Word;           // Width, in pixels, of the image
 
71
    wHeight: Word;          // Height, in pixels, of the image
 
72
    wPlanes: Word;          // color planes
 
73
    wBitCount: Word;        // bits per pixel
 
74
    dwBytesInRes: Dword;    // how many bytes in this resource?
 
75
    nID: Word;              // the ID
 
76
  end;
 
77
 
 
78
  TLocalHeader = packed record
 
79
    xHotSpot: Word;
 
80
    yHotSpot: Word;
 
81
  end;
 
82
 
 
83
  PNewHeader = ^TNewHeader;
 
84
  TNewHeader = packed record
79
85
    idReserved: Word; // Reserved (must be 0)
80
86
    idType: Word;     // Resource type (1 for icons)
81
87
    idCount: Word;    //  How many images?
82
 
    idEntries: array[0..0] of TGrpIconDirEntry; // The entries for each image
83
88
  end;
84
89
 
85
90
function TestStreamIsIcon(const AStream: TStream): boolean;
94
99
  AStream.Position:=OldPosition;
95
100
end;
96
101
 
97
 
function TestStreamIsCursor(const AStream: TStream): boolean;
98
 
var
99
 
  Signature: array[0..3] of char;
100
 
  ReadSize: Integer;
101
 
  OldPosition: TStreamSeekType;
102
 
begin
103
 
  OldPosition:=AStream.Position;
104
 
  ReadSize:=AStream.Read(Signature, SizeOf(Signature));
105
 
  Result:=(ReadSize=SizeOf(Signature)) and CompareMem(@Signature,@CursorSignature,4);
106
 
  AStream.Position:=OldPosition;
107
 
end;
108
 
 
109
102
////////////////////////////////////////////////////////////////////////////////
110
103
 
111
104
{ TSharedIcon }
134
127
  Result := inherited IsEmpty and (Count = 0);
135
128
end;
136
129
 
 
130
function TSharedIcon.GetImage(const AIndex: Integer): TIconImage;
 
131
begin
 
132
  Result := TIconImage(FImages[AIndex]);
 
133
end;
 
134
 
137
135
class function TSharedIcon.GetImagesClass: TIconImageClass;
138
136
begin
139
137
  Result := TIconImage;
150
148
  FImages := TFPList.Create;
151
149
end;
152
150
 
153
 
procedure TSharedIcon.Delete(Aindex: Integer);
 
151
procedure TSharedIcon.Delete(AIndex: Integer);
154
152
var
155
153
  Image: TIconImage;
156
154
begin
157
 
  Image := TIconImage(FImages[Aindex]);
 
155
  Image := TIconImage(FImages[AIndex]);
158
156
  FImages.Delete(AIndex);
159
157
  Image.Free;
160
158
end;
501
499
  inherited Create;
502
500
  FCurrent := -1;
503
501
  FRequestedSize := Size(0, 0);
 
502
  // per definition an icon is masked, but maybe we should make it settable for alpha images
 
503
  FMasked := True;
504
504
end;
505
505
 
506
506
procedure TCustomIcon.Delete(Aindex: Integer);
558
558
  Result := TSharedIcon(FSharedImage).GetIndex(AFormat, AHeight, AWidth);
559
559
end;
560
560
 
561
 
function TCustomIcon.GetMasked: Boolean;
562
 
begin
563
 
  // per definition an icon is masked, but maybe we should make it settable for alpha images
564
 
  Result := True;
565
 
end;
566
 
 
567
561
function TCustomIcon.GetMaskHandle: HBITMAP;
568
562
begin
569
563
  if FCurrent = -1
616
610
  Result := True;
617
611
end;
618
612
 
 
613
class function TCustomIcon.GetStreamSignature: Cardinal;
 
614
begin
 
615
  Result := 0;
 
616
end;
 
617
 
619
618
class function TCustomIcon.GetTypeID: Word;
620
619
begin
621
620
  Result := 0;
678
677
 
679
678
  ResHandle := FindResource(Instance, PChar(ResName), PChar(ResType));
680
679
  if ResHandle = 0 then
681
 
    raise EResNotFound.Create(ResName); // todo: valid exception
 
680
    raise EResNotFound.Create(Format('[TCustomIcon.LoadFromResourceName] The resource "%s" was not found', [ResName])); // todo: valid exception
682
681
  LoadFromResourceHandle(Instance, ResHandle);
683
682
end;
684
683
 
692
691
 
693
692
  ResHandle := FindResource(Instance, PChar(ResID), PChar(ResType));
694
693
  if ResHandle = 0 then
695
 
    raise EResNotFound.Create(''); // todo: valid exception
 
694
    raise EResNotFound.Create(Format('[TCustomIcon.LoadFromResourceID] The resource #%d was not found', [ResID])); // todo: valid exception
696
695
  LoadFromResourceHandle(Instance, ResHandle);
697
696
end;
698
697
 
699
698
procedure TCustomIcon.LoadFromResourceHandle(Instance: THandle; ResHandle: TFPResourceHandle);
700
 
var
701
 
  GlobalHandle: TFPResourceHGlobal;
702
 
  Dir: ^TGrpIconDir;
703
 
  DirEntry: ^TGrpIconDirEntry;
704
 
  IconEntry: TIconDirEntry;
705
 
  i, offset: integer;
706
 
  Stream: TMemoryStream;
707
 
  IconStream: TResourceStream;
708
699
begin
709
 
  // build a usual ico/cur stream using several RT_ICON resources
710
 
  GlobalHandle := LoadResource(Instance, ResHandle);
711
 
  if GlobalHandle = 0 then
712
 
    Exit;
713
 
  Dir := LockResource(GlobalHandle);
714
 
  if Dir = nil then
715
 
    Exit;
716
 
 
717
 
  Stream := TMemoryStream.Create;
718
 
  try
719
 
    // write icon header
720
 
    Stream.Write(Dir^, SizeOf(TIconHeader));
721
 
    // write icon entries headers
722
 
    offset := Stream.Position + SizeOf(IconEntry) * LEtoN(Dir^.idCount);
723
 
    DirEntry := @Dir^.idEntries[0];
724
 
    for i := 0 to LEtoN(Dir^.idCount) - 1 do
725
 
    begin
726
 
      Move(DirEntry^, IconEntry, SizeOf(DirEntry^));
727
 
      IconEntry.dwImageOffset := NtoLE(offset);
728
 
      inc(offset, LEtoN(IconEntry.dwBytesInRes));
729
 
      Stream.Write(IconEntry, SizeOf(IconEntry));
730
 
      Inc(DirEntry);
731
 
    end;
732
 
    // write icons data
733
 
    DirEntry := @Dir^.idEntries[0];
734
 
    for i := 0 to LEtoN(Dir^.idCount) - 1 do
735
 
    begin
736
 
      IconStream := TResourceStream.CreateFromID(Instance, LEtoN(DirEntry^.nID), RT_ICON);
737
 
      try
738
 
        Stream.CopyFrom(IconStream, IconStream.Size);
739
 
      finally
740
 
        IconStream.Free;
741
 
      end;
742
 
      Inc(DirEntry);
743
 
    end;
744
 
    Stream.Position := 0;
745
 
    ReadData(Stream);
746
 
  finally
747
 
    Stream.Free;
748
 
    UnLockResource(GlobalHandle);
749
 
    FreeResource(GlobalHandle);
750
 
  end;
751
700
end;
752
701
 
753
702
function TCustomIcon.MaskHandleAllocated: boolean;
836
785
  Position := Stream.Position;
837
786
  Stream.Read(Signature, SizeOf(Signature));
838
787
  Stream.Position := Position;
839
 
  if Cardinal(Signature) = Cardinal(IconSignature)
 
788
  if Cardinal(Signature) = GetStreamSignature
840
789
  then begin
841
790
    // Assume Icon - stream without explicit size
842
791
    LoadFromStream(Stream);
1397
1346
  SetHandle(AValue);
1398
1347
end;
1399
1348
 
 
1349
class function TIcon.GetStreamSignature: Cardinal;
 
1350
begin
 
1351
  Result := Cardinal(IconSignature);
 
1352
end;
 
1353
 
1400
1354
procedure TIcon.HandleNeeded;
1401
1355
var
1402
1356
  IconInfo: TIconInfo;
1409
1363
  FSharedImage.FHandle := WidgetSet.CreateIconIndirect(@IconInfo);
1410
1364
end;
1411
1365
 
 
1366
procedure TIcon.LoadFromResourceHandle(Instance: THandle; ResHandle: TFPResourceHandle);
 
1367
var
 
1368
  GlobalHandle: TFPResourceHGlobal;
 
1369
  Dir: PNewHeader;
 
1370
  DirEntry: PGrpIconDirEntry;
 
1371
  IconEntry: TIconDirEntry;
 
1372
  i, offset: integer;
 
1373
  Stream: TMemoryStream;
 
1374
  IconStream: TResourceStream;
 
1375
begin
 
1376
  // build a usual ico stream using several RT_ICON resources
 
1377
  GlobalHandle := LoadResource(Instance, ResHandle);
 
1378
  if GlobalHandle = 0 then
 
1379
    Exit;
 
1380
  Dir := LockResource(GlobalHandle);
 
1381
  if Dir = nil then
 
1382
    Exit;
 
1383
 
 
1384
  Stream := TMemoryStream.Create;
 
1385
  try
 
1386
    // write icon header
 
1387
    Stream.Write(Dir^, SizeOf(TIconHeader));
 
1388
    // write icon entries headers
 
1389
    offset := Stream.Position + SizeOf(IconEntry) * LEtoN(Dir^.idCount);
 
1390
    DirEntry := PGrpIconDirEntry(PChar(Dir) + SizeOf(Dir^));
 
1391
    for i := 0 to LEtoN(Dir^.idCount) - 1 do
 
1392
    begin
 
1393
      Move(DirEntry^, IconEntry, SizeOf(DirEntry^));
 
1394
      IconEntry.dwImageOffset := NtoLE(offset);
 
1395
      inc(offset, LEtoN(IconEntry.dwBytesInRes));
 
1396
      Stream.Write(IconEntry, SizeOf(IconEntry));
 
1397
      Inc(DirEntry);
 
1398
    end;
 
1399
    // write icons data
 
1400
    DirEntry := PGrpIconDirEntry(PChar(Dir) + SizeOf(Dir^));
 
1401
    for i := 0 to LEtoN(Dir^.idCount) - 1 do
 
1402
    begin
 
1403
      IconStream := TResourceStream.CreateFromID(Instance, LEtoN(DirEntry^.nID), RT_ICON);
 
1404
      try
 
1405
        Stream.CopyFrom(IconStream, IconStream.Size);
 
1406
      finally
 
1407
        IconStream.Free;
 
1408
      end;
 
1409
      Inc(DirEntry);
 
1410
    end;
 
1411
    Stream.Position := 0;
 
1412
    ReadData(Stream);
 
1413
  finally
 
1414
    Stream.Free;
 
1415
    UnLockResource(GlobalHandle);
 
1416
    FreeResource(GlobalHandle);
 
1417
  end;
 
1418
end;
 
1419
 
1412
1420