~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/modules/plugin/tools/tester/windows/dlgman.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the NPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include <windows.h>
 
39
#include <windowsx.h>
 
40
#include <assert.h>
 
41
 
 
42
#include "resource.h"
 
43
 
 
44
#include "plugin.h"
 
45
#include "helpers.h"
 
46
#include "guihlp.h"
 
47
#include "guiprefs.h"
 
48
#include "winutils.h"
 
49
#include "xp.h"
 
50
 
 
51
extern CLogger * pLogger;
 
52
 
 
53
static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
 
54
{
 
55
  CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_USER);
 
56
  if (!pPlugin)
 
57
    return;
 
58
 
 
59
  switch (id)
 
60
  {
 
61
    case IDC_COMBO_API_CALL:
 
62
      if(codeNotify != CBN_SELCHANGE)
 
63
        break;
 
64
      updateUI(hWnd);
 
65
      break;
 
66
    case IDC_BUTTON_GO:
 
67
      pLogger->blockDumpToFile(FALSE);
 
68
      onGo(hWnd);
 
69
      break;
 
70
    case IDC_EDIT_ARG1:
 
71
    case IDC_EDIT_ARG2:
 
72
    case IDC_EDIT_ARG3:
 
73
    case IDC_EDIT_ARG4:
 
74
    case IDC_EDIT_ARG5:
 
75
    case IDC_EDIT_ARG6:
 
76
    case IDC_EDIT_ARG7:
 
77
    {
 
78
      if(codeNotify == EN_SETFOCUS)
 
79
        pPlugin->m_hWndLastEditFocus = hWndCtl;
 
80
 
 
81
      char szString[80];
 
82
      char szEdit[128];
 
83
      int iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL));
 
84
      ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_API_CALL), iIndex, szString);
 
85
      if(   ((strcmp(szString, STRING_NPN_POSTURL) == 0) || (strcmp(szString, STRING_NPN_POSTURLNOTIFY) == 0))
 
86
         && (id == IDC_EDIT_ARG5)
 
87
         && (codeNotify == EN_CHANGE))
 
88
      {
 
89
        Edit_GetText(hWndCtl, szEdit, sizeof(szEdit));
 
90
        int iLength = strlen(szEdit);
 
91
        SetDlgItemInt(hWnd, IDC_EDIT_ARG4, iLength, FALSE);
 
92
      }
 
93
      if(   ((strcmp(szString, STRING_NPN_WRITE) == 0))
 
94
         && (id == IDC_EDIT_ARG4)
 
95
         && (codeNotify == EN_CHANGE))
 
96
      {
 
97
        Edit_GetText(hWndCtl, szEdit, sizeof(szEdit));
 
98
        int iLength = strlen(szEdit);
 
99
        SetDlgItemInt(hWnd, IDC_EDIT_ARG3, iLength, FALSE);
 
100
      }
 
101
 
 
102
      // save values of window size on the fly as we type it
 
103
      if(    (strcmp(szString, STRING_NPN_SETVALUE) == 0)
 
104
          && ((id == IDC_EDIT_ARG3) || (id == IDC_EDIT_ARG4)) 
 
105
          && (codeNotify == EN_CHANGE)
 
106
          && (hWndCtl == GetFocus()))
 
107
      {
 
108
        iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_ARG2));
 
109
        ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_ARG2), iIndex, szString);
 
110
        if(strcmp(szString, "NPPVpluginWindowSize") == 0)
 
111
        {
 
112
          BOOL bTranslated = FALSE;
 
113
          int iWidth = GetDlgItemInt(hWnd, IDC_EDIT_ARG3, &bTranslated, TRUE);
 
114
          int iHeight = GetDlgItemInt(hWnd, IDC_EDIT_ARG4, &bTranslated, TRUE);
 
115
 
 
116
          if(pPlugin->m_iWidth != iWidth)
 
117
            pPlugin->m_iWidth = iWidth;
 
118
          if(pPlugin->m_iHeight != iHeight)
 
119
            pPlugin->m_iHeight = iHeight;
 
120
        }
 
121
      }
 
122
      break;
 
123
    }
 
124
    case IDC_COMBO_ARG2:
 
125
    {
 
126
      if(codeNotify != CBN_SELCHANGE)
 
127
        break;
 
128
 
 
129
      ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARG4), SW_HIDE);
 
130
      ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG4), SW_HIDE);
 
131
      Static_SetText(GetDlgItem(hWnd, IDC_STATIC_ARG3), "*value:");
 
132
      Edit_SetText(GetDlgItem(hWnd, IDC_EDIT_ARG3), "");
 
133
 
 
134
      char szString[80];
 
135
      int iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL));
 
136
      ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_API_CALL), iIndex, szString);
 
137
      if(strcmp(szString, STRING_NPN_SETVALUE) == 0)
 
138
      {
 
139
        iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_ARG2));
 
140
        ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_ARG2), iIndex, szString);
 
141
        if((strcmp(szString, "NPPVpluginWindowBool") == 0) ||
 
142
           (strcmp(szString, "NPPVpluginTransparentBool") == 0) ||
 
143
           (strcmp(szString, "NPPVpluginKeepLibraryInMemory") == 0))
 
144
        {
 
145
          HWND hWndCombo = GetDlgItem(hWnd, IDC_COMBO_ARG3);
 
146
          ComboBox_ResetContent(hWndCombo);
 
147
          ComboBox_AddString(hWndCombo, "TRUE");
 
148
          ComboBox_AddString(hWndCombo, "FALSE");
 
149
          ComboBox_SetCurSel(hWndCombo, 0);
 
150
          ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG3), SW_HIDE);
 
151
          ShowWindow(hWndCombo, SW_SHOW);
 
152
        }
 
153
        else
 
154
        {
 
155
          ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG3), SW_SHOW);
 
156
          ShowWindow(GetDlgItem(hWnd, IDC_COMBO_ARG3), SW_HIDE);
 
157
          if(strcmp(szString, "NPPVpluginWindowSize") == 0)
 
158
          {
 
159
            EnableWindow(GetDlgItem(hWnd, IDC_EDIT_ARG4), TRUE);
 
160
            ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG4), SW_SHOW);
 
161
            ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARG4), SW_SHOW);
 
162
            Static_SetText(GetDlgItem(hWnd, IDC_STATIC_ARG3), "width:");
 
163
            Static_SetText(GetDlgItem(hWnd, IDC_STATIC_ARG4), "height:");
 
164
            SetDlgItemInt(hWnd, IDC_EDIT_ARG3, pPlugin->m_iWidth, TRUE);
 
165
            SetDlgItemInt(hWnd, IDC_EDIT_ARG4, pPlugin->m_iHeight, TRUE);
 
166
          }
 
167
        }
 
168
      }
 
169
      break;
 
170
    }
 
171
    case IDC_BUTTON_PASTE:
 
172
      onPaste(pPlugin->m_hWndLastEditFocus);
 
173
      break;
 
174
    default:
 
175
      break;
 
176
  }
 
177
}
 
178
 
 
179
static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 
180
{
 
181
  CPlugin * pPlugin = (CPlugin *)lParam;
 
182
  SetWindowLong(hWnd, DWL_USER, (long)pPlugin);
 
183
 
 
184
  // look at the last used API call if needed
 
185
  int iSel = 0;
 
186
  if (pPlugin && pPlugin->m_Pref_bRememberLastCall) {
 
187
    char szFileName[_MAX_PATH];
 
188
    GetINIFileName(pPlugin->getInstance(), szFileName, sizeof(szFileName));
 
189
    iSel = XP_GetPrivateProfileInt(SECTION_PREFERENCES, KEY_LAST_API_CALL, 0, szFileName);
 
190
  }
 
191
  fillAPIComboBoxAndSetSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL), iSel);
 
192
  updateUI(hWnd);
 
193
 
 
194
  int iTopMargin = 188;
 
195
  SetWindowPos(hWnd, NULL, 0,iTopMargin, 0,0, SWP_NOZORDER | SWP_NOSIZE);
 
196
  return TRUE;
 
197
}
 
198
 
 
199
static void onDestroy(HWND hWnd)
 
200
{
 
201
  CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_USER);
 
202
  if(pPlugin && pPlugin->m_Pref_bRememberLastCall) {
 
203
    // save last API call if needed
 
204
    char szFileName[_MAX_PATH];
 
205
    GetINIFileName(pPlugin->getInstance(), szFileName, sizeof(szFileName));
 
206
    int iSel = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL));
 
207
    XP_WritePrivateProfileInt(SECTION_PREFERENCES, KEY_LAST_API_CALL, iSel, szFileName);
 
208
  }
 
209
}
 
210
 
 
211
BOOL CALLBACK NP_LOADDS ManualDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
212
{
 
213
  switch(msg)
 
214
  {
 
215
    case WM_INITDIALOG:
 
216
      return (BOOL)HANDLE_WM_INITDIALOG(hWnd, wParam, lParam, onInitDialog);
 
217
    case WM_COMMAND:
 
218
      HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand);
 
219
      break;
 
220
    case WM_DESTROY:
 
221
      HANDLE_WM_DESTROY(hWnd, wParam, lParam, onDestroy);
 
222
      break;
 
223
 
 
224
    default:
 
225
      return FALSE;
 
226
  }
 
227
  return TRUE;
 
228
}