Skip to content

Commit

Permalink
Listbox
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Feb 13, 2025
1 parent b7289d2 commit 3adae9f
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 126 deletions.
30 changes: 29 additions & 1 deletion pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,10 +1133,36 @@
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.CreateCheckboxField(true);
let oField = oDoc.CreateRadiobuttonField(true);
oDoc.AddField(oField, oDoc.GetCurPage());
}, AscDFH.historydescription_Pdf_AddField, this);
};
PDFEditorApi.prototype.AddComboboxField = function() {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.CreateComboboxField(true);
oDoc.AddField(oField, oDoc.GetCurPage());
}, AscDFH.historydescription_Pdf_AddField, this);
};
PDFEditorApi.prototype.AddListboxField = function() {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.CreateListboxField(true);
oDoc.AddField(oField, oDoc.GetCurPage());
}, AscDFH.historydescription_Pdf_AddField, this);
};
PDFEditorApi.prototype.AddListFieldOption = function(option, nPos) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;
if (oField && [AscPDF.FIELD_TYPES.combobox, AscPDF.FIELD_TYPES.listbox].includes(oField.GetType())) {
oField.AddOption(option, nPos);
}
}, AscDFH.historydescription_Pdf_AddField, this);
};
/////////////////////////////////////////////////////////////
///////// For drawings
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3179,6 +3205,8 @@
PDFEditorApi.prototype['AddImageField'] = PDFEditorApi.prototype.AddImageField;
PDFEditorApi.prototype['AddCheckboxField'] = PDFEditorApi.prototype.AddCheckboxField;
PDFEditorApi.prototype['AddRadiobuttonField'] = PDFEditorApi.prototype.AddRadiobuttonField;
PDFEditorApi.prototype['AddComboboxField'] = PDFEditorApi.prototype.AddComboboxField;
PDFEditorApi.prototype['AddListboxField'] = PDFEditorApi.prototype.AddListboxField;

// drawings
PDFEditorApi.prototype['AddTextArt'] = PDFEditorApi.prototype.AddTextArt;
Expand Down
41 changes: 31 additions & 10 deletions pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,42 @@ var CPresentation = CPresentation || function(){};

return oButtonField;
};
CPDFDoc.prototype.CreateCheckboxField = function(bRadio) {
CPDFDoc.prototype.CreateCheckboxField = function() {
let sName = 'CheckboxField1';
let nType = bRadio ? AscPDF.FIELD_TYPES.radiobutton : AscPDF.FIELD_TYPES.checkbox;
let aRect = [320, 45, 338, 63];

let oCheckboxField = this.CreateField(sName, nType, aRect);

let oCheckboxField = this.CreateField(sName, AscPDF.FIELD_TYPES.checkbox, aRect);
oCheckboxField.SetBorderColor([0]);

if (bRadio) {
oCheckboxField.SetBorderStyle(AscPDF.BORDER_TYPES.inset);
}

return oCheckboxField;
};
CPDFDoc.prototype.CreateRadiobuttonField = function() {
let sName = 'RadiobuttonField1';
let aRect = [320, 45, 338, 63];

let oRadiobuttonField = this.CreateField(sName, AscPDF.FIELD_TYPES.radiobutton, aRect);

oRadiobuttonField.SetBorderColor([0]);
oRadiobuttonField.SetBorderStyle(AscPDF.BORDER_TYPES.inset);

return oRadiobuttonField;
};
CPDFDoc.prototype.CreateComboboxField = function() {
let sName = 'ComboboxField1';
let aRect = [382, 45, 454, 65];

let oComboboxField = this.CreateField(sName, AscPDF.FIELD_TYPES.combobox, aRect);

return oComboboxField;
};
CPDFDoc.prototype.CreateListboxField = function() {
let sName = 'ListboxField1';
let aRect = [382, 81, 482, 153];

let oListboxField = this.CreateField(sName, AscPDF.FIELD_TYPES.listbox, aRect);

return oListboxField;
};
CPDFDoc.prototype.FillFormsParents = function(aParentsInfo) {
let oChilds = this.GetParentsMap();
let oParents = {};
Expand All @@ -519,8 +540,8 @@ var CPresentation = CPresentation || function(){};
if (aParentsInfo[i]["i"] != null)
oParent.SetApIdx(aParentsInfo[i]["i"]);
if (aParentsInfo[i]["curIdxs"])
oParent.SetApiCurIdxs(aParentsInfo[i]["curIdxs"]);
if (aParentsInfo[i]["Opt"] && oParent instanceof AscPDF.CBaseCheckBoxField)
oParent.SetParentCurIdxs(aParentsInfo[i]["curIdxs"]);
if (aParentsInfo[i]["Opt"])
oParent.SetOptions(aParentsInfo[i]["Opt"]);

oParents[nIdx] = oParent;
Expand Down
22 changes: 16 additions & 6 deletions pdf/src/forms/base/baselist.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@
AscPDF.CBaseField.call(this, sName, sType, nPage, aRect, oDoc);

this._commitOnSelChange = false;
this._currentValueIndices = undefined;
this._currentValueIndices = [];
this._textFont = AscPDF.DEFAULT_FIELD_FONT;
this._options = [];

AscCommon.History.StartNoHistoryMode();
this.content = new AscPDF.CTextBoxContent(this, oDoc);
AscCommon.History.EndNoHistoryMode();
}
CBaseListField.prototype = Object.create(AscPDF.CBaseField.prototype);
CBaseListField.prototype.constructor = CBaseListField;

CBaseListField.prototype.SetApiCurIdxs = function(aIdxs) {
CBaseListField.prototype.SetParentCurIdxs = function(aIdxs) {
let oParent = this.GetParent();
if (oParent && this.IsWidget() && oParent.IsAllKidsWidgets())
oParent.SetApiCurIdxs(aIdxs);
oParent.SetParentCurIdxs(aIdxs);
else {
let oDoc = this.GetDocument();
oDoc.History.Add(new CChangesPDFListFormParentCurIdxs(this, this.GetParentCurIdxs(), aIdxs));
Expand All @@ -86,12 +88,20 @@
return this._commitOnSelChange;
};

CBaseListField.prototype.GetOptions = function() {
return this._options;
CBaseListField.prototype.GetOptions = function(bInherit) {
let oParent = this.GetParent();
if (oParent == null)
return this._options;
else if (bInherit === false || (this.GetPartialName() != null)) {
return this._options;
}

if (oParent)
return oParent.GetOptions();
};
// export
CBaseListField.prototype["getOptions"] = function() {
return this._options;
return this.GetOptions();
};

if (!window["AscPDF"])
Expand Down
Loading

0 comments on commit 3adae9f

Please sign in to comment.