Cleanup: Get this rid of "this->" in fpdfsdk/
[pdfium.git] / fpdfsdk / src / formfiller / FFL_ListBox.cpp
index 9ddb6a0..6ee608a 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/formfiller/FormFiller.h"\r
-#include "../../include/formfiller/FFL_FormFiller.h"\r
-#include "../../include/formfiller/FFL_ListBox.h"\r
-//#include "../../include/formfiller/FFL_Module.h"\r
-#include "../../include/formfiller/FFL_IFormFiller.h"\r
-//#include "../../include/formfiller/FFL_Undo.h"\r
-#include "../../include/formfiller/FFL_CBA_Fontmap.h"\r
-\r
-\r
-#define        FFL_DEFAULTLISTBOXFONTSIZE              12.0f\r
-\r
-\r
-/* ------------------------------- CFFL_ListBox ------------------------------- */\r
-\r
-CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :\r
-       CFFL_FormFiller(pApp, pWidget),\r
-       m_pFontMap(NULL)\r
-{\r
-}\r
-\r
-CFFL_ListBox::~CFFL_ListBox()\r
-{\r
-       if (m_pFontMap)\r
-       {\r
-               delete m_pFontMap;\r
-               m_pFontMap = NULL;\r
-       }\r
-}\r
-\r
-PWL_CREATEPARAM        CFFL_ListBox::GetCreateParam()\r
-{\r
-       PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();\r
-\r
-       ASSERT(m_pWidget != NULL);\r
-       FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();\r
-               \r
-       if (dwFieldFlag & FIELDFLAG_MULTISELECT)\r
-       {               \r
-               cp.dwFlags |= PLBS_MULTIPLESEL;\r
-       }\r
-\r
-       if (dwFieldFlag & FIELDFLAG_COMMITONSELCHANGE)\r
-       {\r
-               //cp.dwFlags |= PLBS_COMMITSELECTEDVALUE;\r
-       }\r
-\r
-       cp.dwFlags |= PWS_VSCROLL;\r
-\r
-       if (cp.dwFlags & PWS_AUTOFONTSIZE)\r
-               cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;\r
-\r
-       if (!m_pFontMap)\r
-       {\r
-               ASSERT(this->m_pApp != NULL);\r
-               m_pFontMap = new CBA_FontMap(m_pWidget,m_pApp->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pApp));\r
-               m_pFontMap->Initial();\r
-       }\r
-       cp.pFontMap = m_pFontMap;\r
-\r
-       return cp;\r
-}\r
-\r
-CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)\r
-{\r
-       CPWL_ListBox* pWnd = new CPWL_ListBox();\r
-       pWnd->AttachFFLData(this);\r
-       pWnd->Create(cp);\r
-\r
-       ASSERT(m_pApp != NULL);\r
-       CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();\r
-       pWnd->SetFillerNotify(pIFormFiller);\r
-\r
-       ASSERT(m_pWidget != NULL);\r
-       \r
-       for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)\r
-               pWnd->AddString(m_pWidget->GetOptionLabel(i));\r
-       \r
-       if (pWnd->HasFlag(PLBS_MULTIPLESEL))\r
-       {\r
-               m_OriginSelections.RemoveAll();\r
-               \r
-               FX_BOOL bSetCaret = FALSE;\r
-               for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)\r
-               {\r
-                       if (m_pWidget->IsOptionSelected(i))\r
-                       {\r
-                               if (!bSetCaret)\r
-                               {\r
-                                       pWnd->SetCaret(i);\r
-                                       bSetCaret = TRUE;\r
-                               }\r
-                               pWnd->Select(i);\r
-                               m_OriginSelections.SetAt(i, NULL);\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)\r
-               {\r
-                       if (m_pWidget->IsOptionSelected(i))\r
-                       {\r
-                               pWnd->Select(i);\r
-                               break;\r
-                       }\r
-               }\r
-       }\r
-       \r
-       pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex());\r
-       \r
-       return pWnd;\r
-}\r
-\r
-\r
-FX_BOOL        CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)\r
-{\r
-       return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);\r
-}\r
-\r
-FX_BOOL        CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView)\r
-{\r
-       ASSERT(m_pWidget != NULL);\r
-\r
-       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))\r
-       {\r
-               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)\r
-               {\r
-                       int nSelCount = 0;\r
-                       for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)\r
-                       {\r
-                               if (pListBox->IsItemSelected(i))\r
-                               {\r
-                                       void* p = NULL;\r
-                                       if (!m_OriginSelections.Lookup(i, p))\r
-                                               return TRUE;\r
-\r
-                                       nSelCount++;\r
-                               }\r
-                       }\r
-\r
-                       return nSelCount != m_OriginSelections.GetCount();\r
-               }\r
-               else\r
-               {\r
-                       return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);\r
-               }\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView)\r
-{\r
-       ASSERT(m_pWidget != NULL);\r
-\r
-       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))\r
-       {\r
-               CFX_IntArray aOldSelect, aNewSelect;\r
-\r
-               {\r
-                       for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)\r
-                       {\r
-                               if (m_pWidget->IsOptionSelected(i))\r
-                               {\r
-                                       aOldSelect.Add(i);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               \r
-               FX_INT32 nNewTopIndex = pListBox->GetTopVisibleIndex();\r
-\r
-               m_pWidget->ClearSelection(FALSE);       \r
-\r
-               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)\r
-               {\r
-                       for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)\r
-                       {\r
-                               if (pListBox->IsItemSelected(i))\r
-                               {\r
-                                       m_pWidget->SetOptionSelection(i, TRUE, FALSE);\r
-                                       aNewSelect.Add(i);\r
-                               }\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE);\r
-                       aNewSelect.Add(pListBox->GetCurSel());\r
-               }\r
-\r
-               m_pWidget->SetTopVisibleIndex(nNewTopIndex);\r
-               m_pWidget->ResetFieldAppearance(TRUE);\r
-               m_pWidget->UpdateField();\r
-               SetChangeMark();\r
-       }\r
-}\r
-\r
-void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,\r
-                                               PDFSDK_FieldAction& fa)\r
-{\r
-       switch (type)\r
-       {\r
-       case CPDF_AAction::Validate:\r
-               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)\r
-               {\r
-                       fa.sValue = L"";\r
-               }\r
-               else\r
-               {\r
-                       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))\r
-                       {\r
-                               ASSERT(m_pWidget != NULL);\r
-                               FX_INT32 nCurSel = pListBox->GetCurSel();\r
-                               if (nCurSel >= 0)\r
-                                       fa.sValue = m_pWidget->GetOptionLabel(nCurSel);\r
-                       }\r
-               }\r
-               break;\r
-       case CPDF_AAction::LoseFocus:\r
-       case CPDF_AAction::GetFocus:\r
-               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)\r
-               {\r
-                       fa.sValue = L"";\r
-               }\r
-               else\r
-               {\r
-                       ASSERT(m_pWidget != NULL);\r
-                       FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0);\r
-                       if (nCurSel >= 0)\r
-                               fa.sValue = m_pWidget->GetOptionLabel(nCurSel);\r
-               }\r
-               break;\r
-       default:\r
-               break;\r
-       }\r
-}\r
-\r
-\r
-void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, \r
-                                                               const PDFSDK_FieldAction& fa)\r
-{\r
-}\r
-\r
-void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView)\r
-{\r
-       ASSERT(pPageView != NULL);\r
-\r
-       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))\r
-       {\r
-               for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)\r
-               {\r
-                       if (pListBox->IsItemSelected(i))\r
-                       {\r
-                               m_State.Add(i);\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView)\r
-{\r
-       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))\r
-       {\r
-               for (int i=0,sz=m_State.GetSize(); i<sz; i++)\r
-                       pListBox->Select(m_State[i]);\r
-       }\r
-}\r
-\r
-CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)\r
-{\r
-       if (bRestoreValue)\r
-               SaveState(pPageView);\r
-       \r
-       DestroyPDFWindow(pPageView);\r
-       \r
-       CPWL_Wnd* pRet = NULL;\r
-       \r
-       if (bRestoreValue)\r
-       {\r
-               RestoreState(pPageView);\r
-               pRet = this->GetPDFWindow(pPageView, FALSE);\r
-       }\r
-       else\r
-               pRet = this->GetPDFWindow(pPageView, TRUE);\r
-       \r
-       m_pWidget->UpdateField();\r
-       \r
-       return pRet;\r
-}\r
-\r
-void CFFL_ListBox::OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag)\r
-{\r
-       ASSERT(m_pWidget != NULL);\r
-\r
-       int nFlags = m_pWidget->GetFieldFlags();\r
-       \r
-       if (nFlags & FIELDFLAG_COMMITONSELCHANGE)\r
-       {\r
-               if (m_bValid)\r
-               {\r
-                       CPDFSDK_PageView* pPageView = this->GetCurPageView();\r
-                       ASSERT(pPageView != NULL);\r
-\r
-                       if (CommitData(pPageView, nFlag))\r
-                       {\r
-                               DestroyPDFWindow(pPageView);\r
-                               m_bValid = FALSE;\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_ListBox.h"
+//#include "../../include/formfiller/FFL_Module.h"
+#include "../../include/formfiller/FFL_IFormFiller.h"
+//#include "../../include/formfiller/FFL_Undo.h"
+#include "../../include/formfiller/FFL_CBA_Fontmap.h"
+
+
+#define        FFL_DEFAULTLISTBOXFONTSIZE              12.0f
+
+
+/* ------------------------------- CFFL_ListBox ------------------------------- */
+
+CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
+       CFFL_FormFiller(pApp, pWidget),
+       m_pFontMap(NULL)
+{
+}
+
+CFFL_ListBox::~CFFL_ListBox()
+{
+       if (m_pFontMap)
+       {
+               delete m_pFontMap;
+               m_pFontMap = NULL;
+       }
+}
+
+PWL_CREATEPARAM        CFFL_ListBox::GetCreateParam()
+{
+       PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
+
+       ASSERT(m_pWidget != NULL);
+       FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
+               
+       if (dwFieldFlag & FIELDFLAG_MULTISELECT)
+       {               
+               cp.dwFlags |= PLBS_MULTIPLESEL;
+       }
+
+       cp.dwFlags |= PWS_VSCROLL;
+
+       if (cp.dwFlags & PWS_AUTOFONTSIZE)
+               cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;
+
+       if (!m_pFontMap)
+       {
+               m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler());
+               m_pFontMap->Initial();
+       }
+       cp.pFontMap = m_pFontMap;
+
+       return cp;
+}
+
+CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+       CPWL_ListBox* pWnd = new CPWL_ListBox();
+       pWnd->AttachFFLData(this);
+       pWnd->Create(cp);
+
+       ASSERT(m_pApp != NULL);
+       CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
+       pWnd->SetFillerNotify(pIFormFiller);
+
+       for (int32_t i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+               pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str());
+
+       if (pWnd->HasFlag(PLBS_MULTIPLESEL))
+       {
+               m_OriginSelections.RemoveAll();
+               
+               FX_BOOL bSetCaret = FALSE;
+               for (int32_t i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+               {
+                       if (m_pWidget->IsOptionSelected(i))
+                       {
+                               if (!bSetCaret)
+                               {
+                                       pWnd->SetCaret(i);
+                                       bSetCaret = TRUE;
+                               }
+                               pWnd->Select(i);
+                               m_OriginSelections.SetAt(i, NULL);
+                       }
+               }
+       }
+       else
+       {
+               for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+               {
+                       if (m_pWidget->IsOptionSelected(i))
+                       {
+                               pWnd->Select(i);
+                               break;
+                       }
+               }
+       }
+       
+       pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex());
+       
+       return pWnd;
+}
+
+
+FX_BOOL        CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+       return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+}
+
+FX_BOOL        CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+       ASSERT(m_pWidget != NULL);
+
+       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+       {
+               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+               {
+                       int nSelCount = 0;
+                       for (int32_t i=0,sz=pListBox->GetCount(); i<sz; i++)
+                       {
+                               if (pListBox->IsItemSelected(i))
+                               {
+                                       void* p = NULL;
+                                       if (!m_OriginSelections.Lookup(i, p))
+                                               return TRUE;
+
+                                       nSelCount++;
+                               }
+                       }
+
+                       return nSelCount != m_OriginSelections.GetCount();
+               }
+               else
+               {
+                       return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
+               }
+       }
+       
+       return FALSE;
+}
+
+void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView)
+{
+       ASSERT(m_pWidget != NULL);
+
+       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+       {
+               CFX_IntArray aOldSelect, aNewSelect;
+
+               {
+                       for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+                       {
+                               if (m_pWidget->IsOptionSelected(i))
+                               {
+                                       aOldSelect.Add(i);
+                               }
+                       }
+               }
+
+               
+               int32_t nNewTopIndex = pListBox->GetTopVisibleIndex();
+
+               m_pWidget->ClearSelection(FALSE);       
+
+               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+               {
+                       for (int32_t i=0,sz=pListBox->GetCount(); i<sz; i++)
+                       {
+                               if (pListBox->IsItemSelected(i))
+                               {
+                                       m_pWidget->SetOptionSelection(i, TRUE, FALSE);
+                                       aNewSelect.Add(i);
+                               }
+                       }
+               }
+               else
+               {
+                       m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE);
+                       aNewSelect.Add(pListBox->GetCurSel());
+               }
+
+               m_pWidget->SetTopVisibleIndex(nNewTopIndex);
+               m_pWidget->ResetFieldAppearance(TRUE);
+               m_pWidget->UpdateField();
+               SetChangeMark();
+       }
+}
+
+void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+                                               PDFSDK_FieldAction& fa)
+{
+       switch (type)
+       {
+       case CPDF_AAction::Validate:
+               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+               {
+                       fa.sValue = L"";
+               }
+               else
+               {
+                       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+                       {
+                               ASSERT(m_pWidget != NULL);
+                               int32_t nCurSel = pListBox->GetCurSel();
+                               if (nCurSel >= 0)
+                                       fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
+                       }
+               }
+               break;
+       case CPDF_AAction::LoseFocus:
+       case CPDF_AAction::GetFocus:
+               if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+               {
+                       fa.sValue = L"";
+               }
+               else
+               {
+                       ASSERT(m_pWidget != NULL);
+                       int32_t nCurSel = m_pWidget->GetSelectedIndex(0);
+                       if (nCurSel >= 0)
+                               fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
+               }
+               break;
+       default:
+               break;
+       }
+}
+
+
+void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, 
+                                                               const PDFSDK_FieldAction& fa)
+{
+}
+
+void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView)
+{
+       ASSERT(pPageView != NULL);
+
+       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+       {
+               for (int32_t i=0,sz=pListBox->GetCount(); i<sz; i++)
+               {
+                       if (pListBox->IsItemSelected(i))
+                       {
+                               m_State.Add(i);
+                       }
+               }
+       }
+}
+
+void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView)
+{
+       if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+       {
+               for (int i=0,sz=m_State.GetSize(); i<sz; i++)
+                       pListBox->Select(m_State[i]);
+       }
+}
+
+CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
+{
+       if (bRestoreValue)
+               SaveState(pPageView);
+       
+       DestroyPDFWindow(pPageView);
+       
+       CPWL_Wnd* pRet = NULL;
+       
+       if (bRestoreValue)
+       {
+               RestoreState(pPageView);
+               pRet = GetPDFWindow(pPageView, FALSE);
+       }
+       else
+               pRet = GetPDFWindow(pPageView, TRUE);
+       
+       m_pWidget->UpdateField();
+       
+       return pRet;
+}
+
+void CFFL_ListBox::OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag)
+{
+       ASSERT(m_pWidget != NULL);
+
+       int nFlags = m_pWidget->GetFieldFlags();
+       
+       if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
+       {
+               if (m_bValid)
+               {
+                       CPDFSDK_PageView* pPageView = GetCurPageView();
+                       ASSERT(pPageView != NULL);
+
+                       if (CommitData(pPageView, nFlag))
+                       {
+                               DestroyPDFWindow(pPageView);
+                               m_bValid = FALSE;
+                       }
+               }
+       }
+}
+