File: cupslcl.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (125 lines) | stat: -rw-r--r-- 3,077 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
 *****************************************************************************
  This file is part of the Printer4Lazarus package

  See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************
}
unit cupslcl;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils,
  // LCL
  {$ifdef DebugCUPS}LCLProc,{$endif}
  StdCtrls, Printers,
  // Printers
  OsPrinters, CupsDyn;

const
  C_SPACE       = 6;
  C_GROUPSPACE  = 4*C_SPACE;
  C_BOTHSPACES  = 2*C_SPACE;

  procedure SetupCupsCombo(Combo: TComboBox; Option:Pppd_option_t;
                           OptionStr:String='');
  procedure CheckCupsComboChanges(Combo: TComboBox);
  function  GetCupsComboKeyValue(Combo: TComboBox; AIndex:Integer=-1): string;

implementation

Type
  THackCUPSPrinter=Class(TCUPSPrinter);

procedure SetupCupsCombo(Combo: TCombobox; Option: Pppd_option_t;
  OptionStr: String);
var
  c,j: Integer;
  choice: Pppd_choice_t;
  St: string;
begin

  combo.Tag:=-1;
  combo.Enabled:=false;

  if THackCUPSPrinter(Printer).CupsPPD=nil then
    exit;
  if Option=nil then
  begin
    if OptionStr='' then
      exit;
    Option := ppdFindOption(THackCUPSPrinter(Printer).CupsPPD,pchar(OptionStr));
    if Option=nil then
      exit;
  end;

  c := 0;
  Choice := Option^.choices;
  St := THackCUPSPrinter(Printer).cupsGetOption(Option^.keyword);
  {$IFDEF DebugCUPS}
  DbgOut('Combo: Keyword="%s" Default="%s" CurValue="%s"',
                                        [Option^.keyword,Option^.defchoice,St]);
  {$ENDIF}
  if St='' then
    St := Option^.defchoice;
  while (Choice<>nil) and (c<Option^.num_choices) do
  begin
    j := combo.items.AddObject(choice^.Text, TObject(Choice));
    if strcomp(choice^.choice, pchar(St))=0 then
      combo.Tag := j;
    inc(Choice);
    inc(c);
  end;
  combo.ItemIndex := combo.Tag;
  combo.Enabled:=combo.Tag<>-1;
  {$IFDEF DebugCUPS}
  DebugLn(' SelValue="%s" ItemIndex=%d',[St,combo.ItemIndex]);
  {$ENDIF}
end;

procedure CheckCupsComboChanges(Combo: TCombobox);
var
  choice   : Pppd_choice_t;
begin
  if Combo.Enabled and (Combo.ItemIndex<>Combo.Tag) then
  begin
    Choice := Pppd_choice_t(Combo.Items.Objects[Combo.ItemIndex]);
    if (Choice<>nil) and (Choice^.option<>nil) then
      THackCUPSPrinter(Printer).cupsAddOption(
                    Pppd_option_t(Choice^.option)^.keyword, Choice^.choice);
  end;
end;

function GetCupsComboKeyValue(Combo: TComboBox; AIndex:Integer=-1): string;
var
  choice   : Pppd_choice_t;
  option   : Pppd_option_t;
begin
  result := '';

  if AIndex<0 then
    AIndex := Combo.ItemIndex;

  if Combo.Enabled then
  begin
    if AIndex>=0 then
    begin
      Choice := Pppd_choice_t(Combo.Items.Objects[AIndex]);
      if Choice<>nil then
        result := Choice^.choice;
    end else
    begin
      Choice := Pppd_choice_t(Combo.Items.Objects[0]);
      Option := Pppd_option_t(Choice^.option);
      if Option<>nil then
        result := Option^.defchoice;
    end;
  end;
end;

end.