using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using foxit;
using foxit.pdf;
using foxit.addon.xfa;
using foxit.common.fxcrt;
using foxit.pdf.actions;
using foxit.common;
using System.Drawing;
using System.Web;

namespace PDFReader_Demo_CSharp.UI
{
    public class ActionHander : foxit.pdf.actions.ActionCallback
    {
        public MainForm mainForm = null;
        public string selectedMenuItemName;
        public ActionHander() { }
        public override int Alert(string msg, string title, int type, int icon)
        {
            if (mainForm != null && mainForm.Viewer != null) {
                mainForm.Viewer.setAlerted(true);
            }
            
            MessageBoxButtons btnType = MessageBoxButtons.OK;
            switch (type)
            {
                case 0:
                    btnType = MessageBoxButtons.OK;
                    break;
                case 1:
                    btnType = MessageBoxButtons.OKCancel;
                    break;
                case 2:
                    btnType = MessageBoxButtons.YesNo;
                    break;
                case 3:
                    btnType = MessageBoxButtons.YesNoCancel;
                    break;
            }
            MessageBoxIcon btnIcon = MessageBoxIcon.None;
            switch (icon)
            {
                case 0:
                    btnIcon = MessageBoxIcon.Error;
                    break;
                case 1:
                    btnIcon = MessageBoxIcon.Warning;
                    break;
                case 2:
                    btnIcon = MessageBoxIcon.Question;
                    break;
                case 3:
                    btnIcon = MessageBoxIcon.Hand;
                    break;
            }
            DialogResult ret = System.Windows.Forms.MessageBox.Show(msg, title, btnType, btnIcon);
            if (DialogResult.Yes == ret)
                return 4;
            return 0;
        }
        public override bool Beep(int type) 
        { 
            string funname = "Beep\n\n";
            string strType;
            switch (type)
            {
            case 0:
                strType = ("Error");
            break;
            case 1:
                strType = ("Warning");
            break;
            case 2:
                strType = ("Question");
            break;
            case 3:
                strType = ("Status");
            break;
            case 4:
                strType = ("Default");
            break;
            default:
                strType = ("not defined");
            break;
            }
            string msg = funname + strType;

            System.Windows.Forms.MessageBox.Show(msg, "PDFReader Demo");
            return true; 
        }
        public override string BrowseFile() {  return "";}
        public override string BrowseFile(bool is_open_dialog, string file_format, string file_filter) {
            mainForm.Viewer.setAlerted(true);
            string strFile = "";
            if(is_open_dialog)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                  Filter = file_filter,
                  DefaultExt = file_format
                };
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    strFile = openFileDialog.FileName;
                    return strFile;
                }
            }
            else
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog
                {
                  Filter = file_filter,
                  DefaultExt = file_format
                };
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    strFile = saveFileDialog.FileName;
                    return strFile;
                }
            }
            return "";
        }

        public override void Dispose() { }
        public override bool ExecuteNamedAction(PDFDoc document, string named_action) { return false; }
        public override string GetAppInfo(ActionCallback.AppInfoType type) {
            switch (type) {
                case ActionCallback.AppInfoType.e_AppInfoTypeFormsVersion:
                    return "7.3";
                case ActionCallback.AppInfoType.e_AppInfoTypeViewerType:
                    return "Exchange-Pro";
                case ActionCallback.AppInfoType.e_AppInfoTypeViewerVariation:
                    return "full expired";
                case ActionCallback.AppInfoType.e_AppInfoTypeViewerVersion:
                    return "11.007";
                case ActionCallback.AppInfoType.e_AppInfoTypeAppVersion:
                    return "5.6";
            }
            return "FoxitSDK";
        }
        public override int GetCurrentPage(PDFDoc document) { return 0; }
        public override bool GetDocChangeMark(PDFDoc document) { return false; }
        public override string GetFilePath(PDFDoc document) {
            if(mainForm!=null)
            {
                string path = mainForm.GetCurDocument().GetFilePath();
                return path;
            }
      
            return "getFilePath";
        }
        public override IdentityProperties GetIdentityProperties() 
        {
            return new IdentityProperties("Blanc&Eclare", "miao@neko.com", "Sooyoen", "Jessica", "", "", "", "");
        }

        public override bool SetIdentityProperties(IdentityProperties identity_properties)
        {
            return false;
        }
        public override ActionCallback.Language GetLanguage()
        {
            return ActionCallback.Language.e_LanguageCHS;
        }
        public override PDFDoc GetOpenedDoc(int index) { return mainForm.reader_doc_.pdf_doc_; }
        public override int GetOpenedDocCount() { return -1; }
        public override PDFDoc GetCurrentDoc() 
        {
            return mainForm.reader_doc_.pdf_doc_;
        }
        public override PDFDoc CreateBlankDoc() 
        {
            return new PDFDoc();
        }
        public override PDFDoc OpenDoc(string file_path, string password) 
        {
            return new PDFDoc();
        }
        public override Rotation GetPageRotation(PDFDoc document, int page_index)
        {
            return Rotation.e_RotationUnknown;
        }
        public override bool InvalidateRect(PDFDoc document, int page_index, RectF pdf_rect) { return false; }
        public override bool LaunchURL(string url)
        {
            string msg = "LaunchURL\n\n" + url;
            System.Windows.Forms.MessageBox.Show(msg,"PDFReader Demo");
            return true;
        }
        public override bool MailData(IntPtr data, ActionCallback.MailType data_type, bool is_ui, string to, string subject, string cc, string bcc, string message)
        {
            return false;
        }
        string ParsePopupMenu(MenuListArray menus, ref string str) {
          string select_name = "";
          for (uint i = 0; i<menus.GetSize(); i++) {
            MenuList menu = menus.GetAt(i);
            str += menu.name + "\r\n";
            if (menu.sub_menu_list_array.GetSize() > 0) {
              select_name = ParsePopupMenu(menu.sub_menu_list_array, ref str);
            } else {
              if (i == 0) select_name = menu.name;
            }
          }
          return select_name;
        }

        public ToolStripMenuItem AddContextMenu(string text, ToolStripItemCollection cms, EventHandler callback, bool is_checked, bool is_enabled)
        {
            if (text == "-")
            {
                ToolStripSeparator tsp = new ToolStripSeparator();
                cms.Add(tsp);
                return null;
            }
            else if (!string.IsNullOrEmpty(text))
            {
                ToolStripMenuItem tsmi = new ToolStripMenuItem(text);
                tsmi.Checked = is_checked;
                tsmi.Enabled = is_enabled;
                if (callback != null) tsmi.Click += callback;
                cms.Add(tsmi);
                return tsmi;
            }

            return null;
        }

        void menuStrip_ItemClicked(object sender, EventArgs e)
        {
            ToolStripMenuItem tsMenumItem = sender as ToolStripMenuItem;
            tsMenumItem.Click -= new EventHandler(menuStrip_ItemClicked);
            selectedMenuItemName = tsMenumItem.Text;
        }

        public void AppendMenuWithArray(ContextMenuStrip menuStrip, MenuListArray menus, ToolStripItemCollection cms)
        {
            for (uint i = 0; i < menus.GetSize(); i++)
            {
                MenuList menu = menus.GetAt(i);
                ToolStripMenuItem subItem = null;
                if (menu.name == "-")
                {
                    AddContextMenu(menu.name, cms, null, false, true);
                }
                else
                {
                    if (menu.sub_menu_list_array.GetSize() > 0)
                    {
                        subItem = AddContextMenu(menu.name, cms, null, false, true);
                        AppendMenuWithArray(menuStrip, menu.sub_menu_list_array, subItem.DropDownItems);
                    }
                    else
                    {
                        AddContextMenu(menu.name, cms, menuStrip_ItemClicked, false, true);
                    }
                }

            }
        }

        public void AppendMenuWithArrayEx(ContextMenuStrip menuStrip, MenuItemExArray menus, ToolStripItemCollection cms)
        {
            for (uint i = 0; i < menus.GetSize(); i++)
            {
                MenuItemEx menu = menus.GetAt(i);
                ToolStripMenuItem subItem = null;
                if (menu.item_name == "-")
                {
                    AddContextMenu(menu.item_name, cms, null, false, true);
                }
                else
                {
                    if (menu.sub_menu_item_array.GetSize() > 0)
                    {
                        subItem = AddContextMenu(menu.item_name, cms, null, menu.is_checked, menu.is_enabled);
                        AppendMenuWithArrayEx(menuStrip, menu.sub_menu_item_array, subItem.DropDownItems);
                    }
                    else
                    {
                        AddContextMenu(menu.item_name, cms, menuStrip_ItemClicked, menu.is_checked, menu.is_enabled);
                    }
                }
            }
        }

        public override string PopupMenu(MenuListArray menus, ref bool is_selected_item)
        {
            selectedMenuItemName = "";
            ContextMenuStrip menuStrip = new ContextMenuStrip();
            AppendMenuWithArray(menuStrip, menus, menuStrip.Items);
            System.Drawing.Point p1 = Control.MousePosition;
            System.Drawing.Point p2 = mainForm.ActiveControl.PointToClient(p1);
            menuStrip.Show(mainForm.ActiveControl, p2);
            menuStrip.Focus();
            while (menuStrip.Visible)
            {
                Application.DoEvents();
            }
            is_selected_item = (selectedMenuItemName == null || selectedMenuItemName.Equals("")) ? false : true;
            return selectedMenuItemName;
        }

        public void GetSelectedItemWithArray(MenuItemExArray menus, string item_name, ref MenuItemEx selected_item) {
            for (uint i = 0; i < menus.GetSize(); i++)
            {
                MenuItemEx menu_item = menus.GetAt(i);
                if (menu_item.item_name.Equals(selectedMenuItemName))
                {
                    selected_item = menu_item;
                    break;
                }
                if (menu_item.sub_menu_item_array.GetSize() > 0) {
                    GetSelectedItemWithArray(menu_item.sub_menu_item_array, item_name, ref selected_item);
                }
            }
        }

        public override MenuItemEx PopupMenuEx(MenuItemExArray menus, ref bool is_selected_item)
        {
            selectedMenuItemName = "";
            ContextMenuStrip menuStrip = new ContextMenuStrip();
            AppendMenuWithArrayEx(menuStrip, menus, menuStrip.Items);
            System.Drawing.Point p1 = Control.MousePosition;
            System.Drawing.Point p2 = mainForm.ActiveControl.PointToClient(p1);
            menuStrip.Show(mainForm.ActiveControl, p2);
            menuStrip.Focus();
            while (menuStrip.Visible)
            {
                Application.DoEvents();
            }
            is_selected_item = (selectedMenuItemName == null || selectedMenuItemName.Equals("")) ? false : true;
            if (!is_selected_item)
                return new MenuItemEx();
            MenuItemEx selected_item = new MenuItemEx();
            GetSelectedItemWithArray(menus, selectedMenuItemName, ref selected_item);
            return selected_item;
        }

        public override bool Print(PDFDoc document, bool is_ui, Range page_range, bool is_silent, bool is_shrunk_to_fit, bool is_printed_as_image, bool is_reversed, bool is_to_print_annots)
        {
            return true;
        }
        public override void Release()
        {
           
        }
        public override string Response(string question, string title, string default_value, string label, bool is_password)
        {
            ResponseForm response_form = new ResponseForm();
            response_form.SetQuestion(question);
            response_form.SetTitle(title);
            response_form.SetDefaultValue(default_value);
            response_form.SetLabel(label);
            response_form.SetIsPassword(is_password);
            DialogResult dlg_result = response_form.ShowDialog();
            mainForm.reader_doc_.SetPageView(mainForm);
            if (dlg_result != DialogResult.OK) {
                return "";
            }
            return response_form.GetResponse();
        }
        public override void SetCurrentPage(PDFDoc document, int page_index) { }
        public override bool SetDocChangeMark(PDFDoc document, bool change_mark) { return false; }
        public override bool SetPageRotation(PDFDoc document, int page_index, Rotation rotation) { return false; }

        public override bool SubmitForm(PDFDoc document, IntPtr form_data, int length, string url, FileFormatType file_format_type) 
        {
            string msg = "SubmitForm URL\n\n" + url;
            string strType = "";
            switch (file_format_type)
            {
                case foxit.common.FileFormatType.e_FileFormatTypeFDF:
                    strType = "\n\nSubmit form as FDF.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypeXFDF:
                    strType = "\n\nSubmit form as XFDF.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypeHTML:
                    strType = "\n\nSubmit form as HTML.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypeXDP:
                    strType = "\n\nSubmit form as XDP.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypeXML:
                    strType = "\n\nSubmit form as XML.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypeXFD:
                    strType = "\n\nSubmit form as XFD.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypePDF:
                    strType = "\n\nSubmit form as PDF.";
                    break;
                case foxit.common.FileFormatType.e_FileFormatTypeTXT:
                    strType = "\n\nSubmit form as TXT.";
                    break;
                default:
                    break;
            }
            msg += strType;
            System.Windows.Forms.MessageBox.Show(msg, "PDFReader Demo");
            return true; 
        }

        public override uint VerifySignature(PDFDoc document, Signature pdf_signature)
        {
            using (LTVVerifier ltv_verifier = new LTVVerifier(document, true, true, false, LTVVerifier.TimeType.e_SignatureCreationTime))
            {
                ltv_verifier.SetVerifyMode(LTVVerifier.VerifyMode.e_VerifyModeAcrobat);
                SignatureVerifyResultArray sig_verify_result_array = ltv_verifier.Verify();
                SignatureVerifyResult sig_verify_result = sig_verify_result_array.GetAt(0);
                uint sig_state = sig_verify_result.GetSignatureState();
                return sig_state;
            }
        }
        public override string GetUntitledBookmarkName()
        {
            return "Untitled";
        }
        public override WStringArray GetPrinterNameList()
        {
            return new WStringArray();
        }
        public override bool AddToolButton(ButtonItem button_item)
        {
            return false;
        }
        public override bool RemoveToolButtom(string button_name)
        {
            return false;
        }
        public override MenuListArray GetMenuItemNameList()
        {
            return new MenuListArray();
        }
        public override bool AddMenuItem(MenuItemConfig menu_item_config, bool is_prepend)
        {
            return false;
        }
        public override bool AddSubMenu(MenuItemConfig menu_item_config)
        {
            return false;
        }
        public override bool ShowDialog(DialogDescriptionConfig dlg_config)
        {
            return false;
        }
        public override bool GetFullScreen()
        {
            return false;
        }
        public override void SetFullScreen(bool is_full_scree){}

        public override void OnFieldValueChanged(string field_name, JSFieldValueChangeType type, WStringArray value_before_changed, WStringArray value_after_changed) { }

        public override MediaPlayerCallback OpenMediaPlayer(PlayerArgs player_args) { return null; }
        public override void CloseDoc(PDFDoc document, bool is_prompt_to_save) { }
        public override string GetAttachmentsFilePath(PDFDoc pdf_doc, string name) { return ""; }
        public override string GetExtractedEmbeddedFilePath(PDFDoc pdf_doc, string name) { return ""; }
        public override LayoutMode GetLayoutMode() { return LayoutMode.e_LayoutModeSinglePage; }
        public override foxit.common.fxcrt.PointF GetMousePosition() { return new foxit.common.fxcrt.PointF(); }
        public override float GetPageScale() { return 0; }
        public override RectF GetPageWindowRect(PDFDoc pdf_doc, int page_index) { return new RectF(); }
        public override Destination.ZoomMode GetPageZoomMode() { return 0; }
        public override string GetTemporaryDirectory() { return ""; }
        public override string GetTemporaryFileName(PDFDoc document, string file_name) { return ""; }
        public override bool IsLocalFile(PDFDoc document) { return false; }
        public override JsMailResult MailDoc(PDFDoc document, string to_address, string cc_address, string bcc_address, string subject, string message, bool is_ui) { return 0; }
        public override bool Print(PDFDoc document, PrintParams print_params) { return false; }
        public override void Scroll(foxit.common.fxcrt.PointF point) { }
        public override void SelectPageNthWord(int page_index, int start_offset, int end_offset, bool is_show_selection) { }
        public override void SetCurrentPage(PDFDoc document, Destination destination) { }
        public override void SetLayoutMode(LayoutMode layout_mode, bool is_cover_mode) { }
        public override void SetPageScale(Destination.ZoomMode zoom_mode, Destination dest) { }
        public override void UpdateLogicalLabel() { }
        public override void Query(string keywords, SearchScope search_scope, SearchOption search_option, string di_path) { }
        public override SearchIndexConfig AddSearchIndex(string di_path, bool is_selected) { return new SearchIndexConfig(); }
        public override bool RemoveSearchIndex(SearchIndexConfig search_index_config) { return false; }
        public override WStringArray GetSignatureAPStyleNameList() { return new WStringArray();}

        public override SOAPResponseInfo SoapRequest(SOAPRequestProperties request_params)
        {
            return new SOAPResponseInfo();
        }

        public override void EnablePageLoop(bool is_loop)
        {
        }

        public override bool IsPageLoop()
        {
            return false;
        }

        public override void SetDefaultPageTransitionMode(string trans_type, string trans_di)
        {
        }

        public override bool IsCurrentDocOpenedInBrowser()
        {
            return false;
        }

        public override void PostMessageToHtml(WStringArray message)
        {
        }

        public override void NotifyBeginDoJob(PDFDoc document, JavascriptModifyItemInfo.JavascriptEventType event_type)
        {
        }

        public override void NotifyAfterDataChange(PDFDoc document, JavascriptModifyItemInfo modify_item_info)
        {
        }

        public override void NotifyEndDoJob(PDFDoc document, JavascriptModifyItemInfo.JavascriptEventType event_type)
        {
        }

        public override bool InitModifyItem(PDFDoc document, ActionCallback.ModifyItemType item_type, int page_index, string dict_name)
        {
            return false;
        }

        public override void ResetModifyItem(PDFDoc document)
        {
        }
		
		public override int GetVisiblePageCount(PDFDoc document) { return 0;}
        public override int GetVisiblePage(PDFDoc document, int index) { return -1;}
    };
    public class XFAAppProviderHandler : foxit.addon.xfa.AppProviderCallback
    {
        public XFAAppProviderHandler()
        {

        }

        public override void Beep(AppProviderCallback.BeepType type)
        {
            string funname = "XFA Beep\n\n";
            string type_string = "";
            switch (type)
            {
                case AppProviderCallback.BeepType.e_BeepTypeError:
                    type_string = "Error";
                    break;
                case AppProviderCallback.BeepType.e_BeepTypeWarning:
                    type_string = "Warning";
                    break;
                case AppProviderCallback.BeepType.e_BeepTypeQuestion:
                    type_string = "Question";
                    break;
                case AppProviderCallback.BeepType.e_BeepTypeStatus:
                    type_string = "Status";
                    break;
                case AppProviderCallback.BeepType.e_BeepTypeDefault:
                    type_string = "Default";
                    break;
                default:
                    type_string = "not defined";
                    break;
            }
            string message_string = funname + type_string;

            System.Windows.Forms.MessageBox.Show(message_string);
        }

        public override void Dispose()
        {
            base.Dispose();
        }

        public override FileReaderCallback DownLoadUrl(string url)
        {
            System.Windows.Forms.MessageBox.Show(string.Format("DownLoadUrl {0}", url));

            return null;
        }

        public override string GetAppInfo(AppProviderCallback.AppInfo app_info)
        {
            switch (app_info) {
                case AppProviderCallback.AppInfo.e_AppInfoVersion:
                    return "11.0";
                case AppProviderCallback.AppInfo.e_AppInfoLanguage:
                    return "en-US";
                case AppProviderCallback.AppInfo.e_AppInfoName:
                    return "Acrobat";
                case AppProviderCallback.AppInfo.e_AppInfoType:
                    return "Exchange-Pro";
                case AppProviderCallback.AppInfo.e_AppInfoVariation:
                    return "Full";
                case AppProviderCallback.AppInfo.e_AppInfoPlatform:
                    return "WIN";
                default:
                    return "";
            }
        }

        public override string LoadString(AppProviderCallback.StringID string_id)
        {
            string ret_string = "";
            switch (string_id)
            {
                case AppProviderCallback.StringID.e_StringIDValidateFailed:
                    ret_string = "%s validate failed";
                    break;
                case AppProviderCallback.StringID.e_StringIDCalcOverride:
                    ret_string = "Calculate Override";
                    break;
                case AppProviderCallback.StringID.e_StringIDModifyField:
                    ret_string = "Are you sure you want to modify this field?";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotModifyField:
                    ret_string = "You are not allowed to modify this field.";
                    break;
                case AppProviderCallback.StringID.e_StringIDAppName:
                    ret_string = "Foxit SDK";
                    break;
                case AppProviderCallback.StringID.e_StringIDImageFilter:
                    ret_string = "Image Files(*.bmp;*.jpg;*.png;*.gif;*.tif)|*.bmp;*.jpg;*.png;*.gif;*.tif|All Files(*.*)|*.*||";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnknownCaught:
                    ret_string = "unknown error is catched!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableToSet:
                    ret_string = "Unable to set ";
                    break;
                case AppProviderCallback.StringID.e_StringIDValueExcalmatory:
                    ret_string = " value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidEnumValue:
                    ret_string = "Invalid enumerated value: ";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnsupportMethod:
                    ret_string = "Unsupport %s method.";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnsupportProperty:
                    ret_string = "Usupport %s property.";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidPropertySetOperation:
                    ret_string = "Invalid property set operation;";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotDefaultValue:
                    ret_string = " doesn't have a default property";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetLanguage:
                    ret_string = "Unable to set language value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetNumPages:
                    ret_string = "Unable to set numPages value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetPlatformValue:
                    ret_string = "Unable to set platform value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetValidationsEnabledValue:
                    ret_string = "Unable to set validationsEnabled value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetValidationsValue:
                    ret_string = "Unable to set variation value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetVersion:
                    ret_string = "Unable to set version value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetReady:
                    ret_string = "Unable to set ready value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDNumberOfOccur:
                    ret_string = "The element [%s] has violated its allowable number of occurrences";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetClassName:
                    ret_string = "Unable to set className value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnableSetLengthValue:
                    ret_string = "Unable to set length value!";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnsupportChar:
                    ret_string = "unsupported char '%c'";
                    break;
                case AppProviderCallback.StringID.e_StringIDBadSuffix:
                    ret_string = "bad suffix on number";
                    break;
                case AppProviderCallback.StringID.e_StringIDExpectedIdent:
                    ret_string = "expected identifier instead of '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDExpectedString:
                    ret_string = "expected '%s' instead of '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidateChar:
                    ret_string = "invalidate char '%c'";
                    break;
                case AppProviderCallback.StringID.e_StringIDRedefinition:
                    ret_string = "'%s' redefinition ";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidToken:
                    ret_string = "invalidate token '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidExpression:
                    ret_string = "invalidate expression '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDUndefineIdentifier:
                    ret_string = "undefined identifier '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidateLeftValue:
                    ret_string = "invalidate left-value '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDCompilerError:
                    ret_string = "compiler error";
                    break;
                case AppProviderCallback.StringID.e_StringIDCannotModifyValue:
                    ret_string = "can't modify the '%s' value";
                    break;
                case AppProviderCallback.StringID.e_StringIDParametersError:
                    ret_string = "function '%s' has not %d parameters";
                    break;
                case AppProviderCallback.StringID.e_StringIDExpectedEndIf:
                    ret_string = "expected 'endif' instead of '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDUnexpectedExpression:
                    ret_string = "unexpected expression '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDConditionIsNull:
                    ret_string = "condition is null";
                    break;
                case AppProviderCallback.StringID.e_StringIDIllegalBreak:
                    ret_string = "illegal break";
                    break;
                case AppProviderCallback.StringID.e_StringIDIllegalContinue:
                    ret_string = "illegal continue";
                    break;
                case AppProviderCallback.StringID.e_StringIDExpectedOperator:
                    ret_string = "expected operator '%s' instead of '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDDivideZero:
                    ret_string = "divide by zero";
                    break;
                case AppProviderCallback.StringID.e_StringIDCannotCovertToObject:
                    ret_string = "%s.%s can not covert to object";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotFoundContainer:
                    ret_string = "can not found container '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotFoundProperty:
                    ret_string = "can not found property '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotFoundMethod:
                    ret_string = "can not found method '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotFoundConst:
                    ret_string = "can not found const '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotAssignObject:
                    ret_string = "can not direct assign value to object";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidateInstruction:
                    ret_string = "invalidate instruction";
                    break;
                case AppProviderCallback.StringID.e_StringIDExpectedNumber:
                    ret_string = "expected number instead of '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateOutOfArray:
                    ret_string = "validate access index '%s' out of array";
                    break;
                case AppProviderCallback.StringID.e_StringIDCannotAssign:
                    ret_string = "can not assign to %s";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotFoundFunction:
                    ret_string = "can not found '%s' function";
                    break;
                case AppProviderCallback.StringID.e_StringIDIsNotArray:
                    ret_string = "'%s' doesn't an array";
                    break;
                case AppProviderCallback.StringID.e_StringIDOutOfArrayRange:
                    ret_string = "out of range of '%s' array";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotSupportArrayCalculate:
                    ret_string = "'%s' operator can not support array calculate";
                    break;
                case AppProviderCallback.StringID.e_StringIDArgumentNotArray:
                    ret_string = "'%s' function's %d argument can not be array";
                    break;
                case AppProviderCallback.StringID.e_StringIDArgumentExpectContainer:
                    ret_string = "'%s' argument expected a container";
                    break;
                case AppProviderCallback.StringID.e_StringIDAccessProertyInNotObject:
                    ret_string = "an attempt was made to reference property '%s' of a non-object in SOM expression %s";
                    break;
                case AppProviderCallback.StringID.e_StringIDFunctionBuildIn:
                    ret_string = "function '%s' is buildin";
                    break;
                case AppProviderCallback.StringID.e_StringIDErrorMessage:
                    ret_string = "%s : %s";
                    break;
                case AppProviderCallback.StringID.e_StringIDIndexValueOutOfBounds:
                    ret_string = "Index value is out of bounds";
                    break;
                case AppProviderCallback.StringID.e_StringIDIncorrectNumberOfMethod:
                    ret_string = "Incorrect number of parameters calling method '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDArgumentMismatch:
                    ret_string = "Argument mismatch in property or function argument";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidEnumerate:
                    ret_string = "Invalid enumerated value: %s";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidAppend:
                    ret_string = "Invalid append operation: %s cannot have a child element of %s";
                    break;
                case AppProviderCallback.StringID.e_StringIDSOMExpectedList:
                    ret_string = "SOM expression breaked list when single result was expected";
                    break;
                case AppProviderCallback.StringID.e_StringIDNotHaveProperty:
                    ret_string = "'%s' doesn't have property '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidNodeType:
                    ret_string = "Invalid node type : '%s'";
                    break;
                case AppProviderCallback.StringID.e_StringIDViolateBoundary:
                    ret_string = "The element [%s] has violated its allowable number of occurrences";
                    break;
                case AppProviderCallback.StringID.e_StringIDServerDeny:
                    ret_string = "Server does not permit";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDaySun:
                    ret_string = "Sunday";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDayMon:
                    ret_string = "Monday";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDayTue:
                    ret_string = "Tuesday";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDayWed:
                    ret_string = "Wednesday";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDayThu:
                    ret_string = "Thursday";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDayFri:
                    ret_string = "Friday";
                    break;
                case AppProviderCallback.StringID.e_StringIDWeekDaySat:
                    ret_string = "Saturday";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthJan:
                    ret_string = "January";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthFeb:
                    ret_string = "February";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthMarch:
                    ret_string = "March";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthApril:
                    ret_string = "April";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthMay:
                    ret_string = "May";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthJune:
                    ret_string = "June";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthJuly:
                    ret_string = "July";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthAug:
                    ret_string = "August";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthSep:
                    ret_string = "September";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthOct:
                    ret_string = "October";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthNov:
                    ret_string = "November";
                    break;
                case AppProviderCallback.StringID.e_StringIDMonthDec:
                    ret_string = "December";
                    break;
                case AppProviderCallback.StringID.e_StringIDToday:
                    ret_string = "Today";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateLimit:
                    ret_string = "Message limit exceeded. Remaining %d validation errors not reported.";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateNullWarning:
                    ret_string = "%s cannot be left blank. To ignore validations for %s, click Ignore.";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateNullError:
                    ret_string = "%s cannot be left blank.";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateWarning:
                    ret_string = "The value you entered for %s is invalid. To ignore validations for %s, click Ignore.";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateError:
                    ret_string = "The value you entered for %s is invalid.";
                    break;
                case AppProviderCallback.StringID.e_StringIDValidateNumberError:
                    ret_string = "Illegal value:cannot assign '%s' to %s.";
                    break;
                case AppProviderCallback.StringID.e_StringIDScriptFailedError:
                    ret_string = "Script failed(language is %s;context is %s) script=%s ";
                    break;
                case AppProviderCallback.StringID.e_StringIDScriptInvalidValue:
                    ret_string = "Error:Invalid enumerated value:%s";
                    break;
                case AppProviderCallback.StringID.e_StringIDSubmitValidateNullError:
                    ret_string = "At least one required field was empty.Please fill in the required fields(highlighted) before continuing.";
                    break;
                case AppProviderCallback.StringID.e_StringIDInvalidBarcodeValue:
                    ret_string = "Invalid Barcode Value: %s is an invalid value for barcodes of type %s.";
                    break;
                case AppProviderCallback.StringID.e_StringIDScriptArgumentMismatch:
                    ret_string = "Error:Argument mismatch in property or function argument.";
                    break;
            }

            return ret_string;
        }

        public override AppProviderCallback.MsgBoxButtonID MsgBox(string message, string title, AppProviderCallback.MsgBoxIconType icon_type, AppProviderCallback.MsgBoxButtonType button_type)
        {
            return GetSdkMsgBoxButtonID(System.Windows.Forms.MessageBox.Show(message, title, GetMsgBoxButtonType(button_type), GetMsgBoxIconType(icon_type)));
        }

        public override string PostRequestURL(string url, string data, string content_type, string encode, string header)
        {
            return "PostRequestUrl";
        }

        public override bool PutRequestURL(string url, string data, string encode)
        {
            return false;
        }

        public override void Release()
        {

        }

        public override string Response(string question, string title, string default_answer, bool is_mask)
        {
            string message_string = string.Format("question: {0}\r\ntitle:{1}\r\ndefault_answer:{2}\r\nis mask:{3}", question, title, default_answer, is_mask);
            System.Windows.Forms.MessageBox.Show(message_string);

            return "answer";
        }

        public override foxit.common.WStringArray ShowFileDialog(string string_title, string string_filter, bool is_openfile_dialog)
        {
            return new foxit.common.WStringArray();
        }

        private MessageBoxButtons GetMsgBoxButtonType(AppProviderCallback.MsgBoxButtonType button_type)
        {
            MessageBoxButtons msg_box_button = MessageBoxButtons.OK;
            switch (button_type)
            {
                case AppProviderCallback.MsgBoxButtonType.e_MsgBtnTypeOK:
                    msg_box_button = MessageBoxButtons.OK;
                    break;
                case AppProviderCallback.MsgBoxButtonType.e_MsgBtnTypeOKCancel:
                    msg_box_button = MessageBoxButtons.OKCancel;
                    break;
                case AppProviderCallback.MsgBoxButtonType.e_MsgBtnTypeYesNo:
                    msg_box_button = MessageBoxButtons.YesNo;
                    break;
                case AppProviderCallback.MsgBoxButtonType.e_MsgBtnTypeYesNoCancel:
                    msg_box_button = MessageBoxButtons.YesNoCancel;
                    break;
            }

            return msg_box_button;
        }

        private MessageBoxIcon GetMsgBoxIconType(AppProviderCallback.MsgBoxIconType icon_type)
        {
            MessageBoxIcon msg_box_icon = MessageBoxIcon.None;
            switch (icon_type)
            {
                case AppProviderCallback.MsgBoxIconType.e_MsgBoxIconError:
                    msg_box_icon = MessageBoxIcon.Error;
                    break;
                case AppProviderCallback.MsgBoxIconType.e_MsgBoxIconWarning:
                    msg_box_icon = MessageBoxIcon.Warning;
                    break;
                case AppProviderCallback.MsgBoxIconType.e_MsgBoxIconQuestion:
                    msg_box_icon = MessageBoxIcon.Question;
                    break;
                case AppProviderCallback.MsgBoxIconType.e_MsgBoxIconStatus:
                    msg_box_icon = MessageBoxIcon.Information;
                    break;
            }

            return msg_box_icon;
        }

        private AppProviderCallback.MsgBoxButtonID GetSdkMsgBoxButtonID(DialogResult id)
        {
            AppProviderCallback.MsgBoxButtonID msg_box_button_id = AppProviderCallback.MsgBoxButtonID.e_MsgBtnIDOK;
            switch (id)
            {
                case DialogResult.OK:
                    msg_box_button_id = AppProviderCallback.MsgBoxButtonID.e_MsgBtnIDOK;
                    break;
                case DialogResult.Cancel:
                    msg_box_button_id = AppProviderCallback.MsgBoxButtonID.e_MsgBtnIDCancel;
                    break;
                case DialogResult.Yes:
                    msg_box_button_id = AppProviderCallback.MsgBoxButtonID.e_MsgBtnIDYes;
                    break;
                case DialogResult.No:
                    msg_box_button_id = AppProviderCallback.MsgBoxButtonID.e_MsgBtnIDNo;
                    break;
                default:
                    break;
            }

            return msg_box_button_id;
        }
    }
}
