File: wx_rdlg.cpp

package info (click to toggle)
wxxt 1.67c-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 9,176 kB
  • ctags: 12,722
  • sloc: cpp: 89,350; sh: 5,110; ansic: 4,510; makefile: 596; lex: 184; yacc: 105
file content (325 lines) | stat: -rw-r--r-- 8,761 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
 * File:	wx_rdlg.cpp
 * Purpose:	Resource editor: dialog handler implementation
 * Author:	Julian Smart
 * Created:	1995
 * Updated:	
 * Copyright:	(c) 1995, AIAI, University of Edinburgh
 */

#ifdef __GNUG__
#pragma implementation
#endif

// For compilers that support precompilation, includes "wx.h".
#include "wx_prec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx.h"
#endif

#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#if defined(wx_msw) && !defined(GNUWIN32)
#include <strstrea.h>
#else
#include <strstream.h>
#endif

// #include "wx_scrol.h"
// #include "wx_help.h"

#include "wx_resed.h"
#include "wx_rprop.h"
#include "wx_repal.h"

extern void wxResourceEditWindow(wxWindow *win);

/*
 * Dialog box event handler
 */

wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel *dialog, wxItemResource *resource,
   wxEvtHandler *oldHandler, wxResourceManager *manager)
{
  handlerDialog = dialog;
  handlerResource = resource;
  handlerOldHandler = oldHandler;
  resourceManager = manager;
}

void wxResourceEditorDialogHandler::OnSize(int w, int h)
{
}

void wxResourceEditorDialogHandler::OnItemSelect(wxItem *item, Bool select)
{
  if (select)
    resourceManager->AddSelection(item);
  else
    resourceManager->RemoveSelection(item);
}


Bool wxResourceEditorDialogHandler::OnClose(void)
{
  handlerDialog->SetEventHandler(handlerOldHandler);
  
  // Save the information before deleting the dialog.
  resourceManager->InstantiateResourceFromWindow(handlerResource, handlerDialog, TRUE);
  
  resourceManager->DisassociateResource(handlerDialog, FALSE);

  handlerDialog->Show(FALSE);
  delete this;
  return TRUE;
}

// There's default behaviour in wxbPanel, so forward the event
// to that code: it'll eventually call OnLeftClick, etc.
void wxResourceEditorDialogHandler::OnEvent(wxMouseEvent& event)
{
  handlerOldHandler->OnEvent(event);
}

void wxResourceEditorDialogHandler::OnPaint(void)
{
  handlerOldHandler->OnPaint();
}

void wxResourceEditorDialogHandler::OnItemEvent(wxItem *item, wxMouseEvent& event)
{
  handlerOldHandler->OnItemEvent(item, event);
}

void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
{
  if (keys & wxKEY_CTRL)
  {
    wxResourceEditWindow(handlerDialog);
    return;
  }

  // Deselect all items if click on panel
  if (resourceManager->GetEditorPalette()->currentlySelected == PALETTE_ARROW)
  {
    Bool needsRefresh = 0;
    wxNode *node = handlerDialog->GetChildren()->First();
    while (node)
    {
      wxItem *item = (wxItem *)node->Data();
      if (item->IsSelected())
      {
        needsRefresh ++;
        OnItemSelect(item, FALSE);
        item->SelectItem(FALSE);
      }
      node = node->Next();
    }
    if (needsRefresh > 0)
    {
      handlerDialog->GetPanelDC()->Clear();
      handlerDialog->Refresh();
    }
    return;
  }

  switch (resourceManager->GetEditorPalette()->currentlySelected)
  {
        case PALETTE_FRAME:
          break;
        case PALETTE_DIALOG_BOX:
          break;
        case PALETTE_PANEL:
          break;
        case PALETTE_CANVAS:
          break;
        case PALETTE_TEXT_WINDOW:
          break;
        case PALETTE_BUTTON:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y);
          break;
        case PALETTE_BITMAP_BUTTON:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y, TRUE);
          break;
        case PALETTE_MESSAGE:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxMessage", x, y);
          break;
        case PALETTE_BITMAP_MESSAGE:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxMessage", x, y, TRUE);
          break;
        case PALETTE_TEXT:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxText", x, y);
          break;
        case PALETTE_MULTITEXT:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxMultiText", x, y);
          break;
        case PALETTE_CHOICE:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxChoice", x, y);
          break;
        case PALETTE_CHECKBOX:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxCheckBox", x, y);
          break;
        case PALETTE_RADIOBOX:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioBox", x, y);
          break;
        case PALETTE_LISTBOX:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxListBox", x, y);
          break;
        case PALETTE_SLIDER:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxSlider", x, y);
          break;
        case PALETTE_GAUGE:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxGauge", x, y);
          break;
        case PALETTE_GROUPBOX:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxGroupBox", x, y);
          break;
        case PALETTE_SCROLLBAR:
          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxScrollBar", x, y);
          break;
        default:
          break;
  }

  // Now switch pointer on.
  if (resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
  {
    resourceManager->GetEditorPalette()->ToggleTool(resourceManager->GetEditorPalette()->currentlySelected, FALSE);
    resourceManager->GetEditorPalette()->ToggleTool(PALETTE_ARROW, TRUE);
    resourceManager->GetEditorPalette()->currentlySelected = PALETTE_ARROW;
  }
}

void wxResourceEditorDialogHandler::OnRightClick(int x, int y, int keys)
{
  wxMenu *menu = resourceManager->GetPopupMenu();
  menu->SetClientData((char *)handlerDialog);
#ifdef wx_motif
  handlerDialog->FakePopupMenu(menu, (float)x, (float)y);
#else
  handlerDialog->PopupMenu(menu, (float)x, (float)y);
#endif
}

void wxResourceEditorDialogHandler::OnItemLeftClick(wxItem *item, int x, int y, int keys)
{
  if (keys & wxKEY_CTRL)
  {
    wxResourceEditWindow(item);
    return;
  }
  
  // If this is a wxGroupBox and the pointer isn't an arrow, chances
  // are that we really meant to place an item on the panel.
  // Fake this event.
  if ((item->GetClassInfo() == CLASSINFO(wxGroupBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
  {
    OnLeftClick(x,  y, keys);
    return;
  }
  
//  wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());

  if (item->IsSelected())
  {
    item->SelectItem(FALSE);
    item->GetParent()->GetEventHandler()->OnItemSelect(item, FALSE);
    handlerDialog->GetPanelDC()->Clear();
    handlerDialog->Refresh();
  }
  else
  {
    item->SelectItem(TRUE);
    item->GetParent()->GetEventHandler()->OnItemSelect(item, TRUE);
    
    // Deselect other items if shift is not pressed
    int needsRefresh = 0;
    if (!(keys & wxKEY_SHIFT))
    {
      wxNode *node = item->GetParent()->GetChildren()->First();
      while (node)
      {
        wxItem *child = (wxItem *)node->Data();
        if (child->IsSelected() && child != item)
        {
          child->SelectItem(FALSE);
          child->GetParent()->GetEventHandler()->OnItemSelect(child, FALSE);
          needsRefresh ++;
        }
        node = node->Next();
      }
    }

    handlerDialog->GetPanelDC()->BeginDrawing();
    item->DrawSelectionHandles(handlerDialog->GetPanelDC());
    handlerDialog->GetPanelDC()->EndDrawing();

    if (needsRefresh > 0)
    {
      handlerDialog->GetPanelDC()->Clear();
      handlerDialog->Refresh();
    }
  }
}

void wxResourceEditorDialogHandler::OnItemRightClick(wxItem *item, int x, int y, int keys)
{
/*
  if (keys & wxKEY_CTRL)
  {
    wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
    return;
  }
*/

  wxMenu *menu = resourceManager->GetPopupMenu();
  menu->SetClientData((char *)item);
#ifdef wx_motif
  handlerDialog->FakePopupMenu(menu, (float)x, (float)y);
#else
  handlerDialog->PopupMenu(menu, (float)x, (float)y);
#endif
}

void wxResourceEditorDialogHandler::OnItemMove(wxItem *item, int x, int y)
{
/*
  BuildWindowData *child = buildWindow->FindChildWindow(item);
  if (child)
  {
    child->x = x;
    child->y = y;
  }
*/
}

void wxResourceEditorDialogHandler::OnItemSize(wxItem *item, int w, int h)
{
/*
  BuildWindowData *child = buildWindow->FindChildWindow(item);
  if (child)
  {
    child->width = w;
    child->height = h;
  }
*/
}

/*
 * Frame for editing a panel in
 */
 
Bool DialogEditorPanelFrame::OnClose(void)
{
  wxWindow *child = (wxWindow *)GetChildren()->First()->Data();
  wxEvtHandler *handler = child->GetEventHandler();
  return handler->OnClose();
}