Skip to content

Commit

Permalink
handlers for edit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Feb 14, 2025
1 parent 02be4e4 commit 7c09cb1
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
14 changes: 11 additions & 3 deletions pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ var CPresentation = CPresentation || function(){};
}

oField.SetDocument(this);
if (this.IsEditFieldsMode()) {
oField.SetEditMode(true);
}

return oField;
};
CPDFDoc.prototype.SetEditFieldsMode = function(bEdit) {
Expand Down Expand Up @@ -3217,7 +3221,13 @@ var CPresentation = CPresentation || function(){};
let oDrawing = this.activeDrawing;

let oContent;
if (oForm && oForm.IsCanEditText()) {
if (this.IsEditFieldsMode()) {
oController.selectedObjects.forEach(function(shape) {
let field = shape.GetEditField();
oThis.RemoveField(field.GetId());
});
}
else if (oForm && oForm.IsCanEditText()) {
oForm.Remove(nDirection, isCtrlKey);
oContent = oForm.GetDocContent();
}
Expand Down Expand Up @@ -3354,8 +3364,6 @@ var CPresentation = CPresentation || function(){};

CPDFDoc.prototype.RemoveField = function(sId) {
let oController = this.GetController();
this.BlurActiveObject();

let oForm = this.widgets.find(function(form) {
return form.GetId() == sId;
});
Expand Down
9 changes: 8 additions & 1 deletion pdf/src/drawings/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@
};
CPdfShape.prototype.GetEditField = function() {
return this.editField;
}
};
CPdfShape.prototype.hitInTextRect = function(x, y) {
if (this.IsEditFieldShape()) {
return false;
}

return this.hitInTextRectWord(x, y);
};
CPdfShape.prototype.GetDocument = function() {
if (this.IsEditFieldShape()) {
return this.editField.GetDocument();
Expand Down
2 changes: 2 additions & 0 deletions pdf/src/forms/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,8 @@
return this._textSize;
};
CBaseField.prototype.SetRect = function(aOrigRect) {
AscCommon.History.Add(new CChangesPDFFormRect(this, this.GetRect(), aOrigRect));

this._origRect = aOrigRect;
this.SetWasChanged(true);
this.SetNeedRecalc(true);
Expand Down
10 changes: 9 additions & 1 deletion pdf/src/forms/base/basecheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
CBaseCheckBoxField.prototype = Object.create(AscPDF.CBaseField.prototype);
CBaseCheckBoxField.prototype.constructor = CBaseCheckBoxField;

CBaseCheckBoxField.prototype.Draw = function(oGraphicsPDF) {
CBaseCheckBoxField.prototype.Draw = function(oGraphicsPDF, oGraphicsWord) {
if (this.IsHidden() == true)
return;

Expand All @@ -75,6 +75,7 @@
this.DrawCheckedSymbol(oGraphicsPDF);

this.DrawLocks(oGraphicsPDF);
this.DrawEdit(oGraphicsWord);
};
CBaseCheckBoxField.prototype.IsChecked = function() {
return this._checked;
Expand Down Expand Up @@ -341,6 +342,13 @@
let isInFocus = oDoc.activeForm === this;
oDoc.activeForm = this;

if (oDoc.IsEditFieldsMode()) {
let oController = oDoc.GetController();
this.editShape.select(oController, this.GetPage());
this.editShape.onMouseDown(x, y, e);
return;
}

function callbackAfterFocus() {
this.SetInForm(true);
}
Expand Down
8 changes: 8 additions & 0 deletions pdf/src/forms/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
this.DrawBorders(oGraphicsPDF);

this.DrawLocks(oGraphicsPDF);
this.DrawEdit(oGraphicsWord);
};
CComboBoxField.prototype.Recalculate = function() {
if (this.IsNeedRecalc() == false)
Expand Down Expand Up @@ -262,6 +263,13 @@

oDoc.activeForm = this;

if (oDoc.IsEditFieldsMode()) {
let oController = oDoc.GetController();
this.editShape.select(oController, this.GetPage());
this.editShape.onMouseDown(x, y, e);
return;
}

function callbackAfterFocus(x, y, e) {
oDoc.SetLocalHistory();
if (false == e.ShiftKey) {
Expand Down
8 changes: 8 additions & 0 deletions pdf/src/forms/listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
this.DrawBorders(oGraphicsPDF);

this.DrawLocks(oGraphicsPDF);
this.DrawEdit(oGraphicsWord);
};
CListBoxField.prototype.Recalculate = function() {
if (this.IsNeedRecalc() == false)
Expand Down Expand Up @@ -488,6 +489,13 @@

oDoc.activeForm = this;

if (oDoc.IsEditFieldsMode()) {
let oController = oDoc.GetController();
this.editShape.select(oController, this.GetPage());
this.editShape.onMouseDown(x, y, e);
return;
}

function callbackAfterFocus(x, y, e) {
this.SetInForm(true);
this.SetDrawHighlight(false);
Expand Down
9 changes: 9 additions & 0 deletions pdf/src/forms/pushbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@
}

this.DrawLocks(oGraphicsPDF);
this.DrawEdit(oGraphicsWord);
};
CPushButtonField.prototype.SetImageRasterId = function(sRasterId, nAPType) {
let sPrevRasterId;
Expand Down Expand Up @@ -1252,6 +1253,7 @@
}

this.DrawLocks(oGraphicsPDF);
this.DrawEdit(oGraphicsWord);
};
CPushButtonField.prototype.SetPressed = function(bValue) {
this._pressed = bValue;
Expand All @@ -1275,6 +1277,13 @@
let isInFocus = oDoc.activeForm === this;
oDoc.activeForm = this;

if (oDoc.IsEditFieldsMode()) {
let oController = oDoc.GetController();
this.editShape.select(oController, this.GetPage());
this.editShape.onMouseDown(x, y, e);
return;
}

function callbackAfterFocus() {
this.SetInForm(true);
}
Expand Down
17 changes: 17 additions & 0 deletions pdf/src/history/formsChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,23 @@ CChangesPDFFormBorderStyle.prototype.private_SetValue = function(Value)
oField.SetBorderStyle(Value);
};

/**
* @constructor
* @extends {AscDFH.CChangesAnnotArrayOfDoubleProperty}
*/
function CChangesPDFFormRect(Class, Old, New, Color)
{
AscDFH.CChangesAnnotArrayOfDoubleProperty.call(this, Class, Old, New, Color);
}
CChangesPDFFormRect.prototype = Object.create(AscDFH.CChangesAnnotArrayOfDoubleProperty.prototype);
CChangesPDFFormRect.prototype.constructor = CChangesPDFFormRect;
CChangesPDFFormRect.prototype.Type = AscDFH.historyitem_Pdf_Form_Rect;
CChangesPDFFormRect.prototype.private_SetValue = function(Value)
{
let oField = this.Class;
oField.SetRect(Value);
};

/**
* @constructor
* @extends {AscDFH.CChangesBaseProperty}
Expand Down
13 changes: 11 additions & 2 deletions pdf/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2142,12 +2142,21 @@
this.getPageFieldByCoords = function(x, y, pageIndex, bGetHidden)
{
var pageFields = this.pagesInfo.pages[pageIndex];

if (pageFields.fields)
{
for (var i = 0, len = pageFields.fields.length; i < len; i++)
{
if (x >= pageFields.fields[i]._origRect[0] && x <= pageFields.fields[i]._origRect[2] &&
y >= pageFields.fields[i]._origRect[1] && y <= pageFields.fields[i]._origRect[3]) {
let oField = pageFields.fields[i];
let aRect = oField.GetRect();
let oFieldEditShape = oField.GetEditShape();
let bHitToHandles = false;
if (oFieldEditShape) {
bHitToHandles = oFieldEditShape.hitToHandles(x * g_dKoef_pt_to_mm, y * g_dKoef_pt_to_mm) !== -1;
}

if (x >= aRect[0] && x <= aRect[2] &&
y >= aRect[1] && y <= aRect[3] || bHitToHandles) {
if (bGetHidden) {
return pageFields.fields[i];
}
Expand Down

0 comments on commit 7c09cb1

Please sign in to comment.