| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: resource.cpp |
| 3 | // Purpose: Resource system |
| 4 | // Author: Julian Smart |
| 5 | // Modified by: |
| 6 | // Created: 04/01/98 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Julian Smart and Markus Holzem |
| 9 | // Licence: wxWindows license |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "resource.h" |
| 14 | #endif |
| 15 | |
| 16 | // For compilers that support precompilation, includes "wx.h". |
| 17 | #include "wx/wxprec.h" |
| 18 | |
| 19 | #ifdef __BORLANDC__ |
| 20 | #pragma hdrstop |
| 21 | #endif |
| 22 | |
| 23 | #if wxUSE_WX_RESOURCES |
| 24 | |
| 25 | #ifdef __VISUALC__ |
| 26 | #pragma warning(disable:4706) // assignment within conditional expression |
| 27 | #endif // VC++ |
| 28 | |
| 29 | #ifndef WX_PRECOMP |
| 30 | #include "wx/defs.h" |
| 31 | #include "wx/setup.h" |
| 32 | #include "wx/list.h" |
| 33 | #include "wx/hash.h" |
| 34 | #include "wx/gdicmn.h" |
| 35 | #include "wx/utils.h" |
| 36 | #include "wx/types.h" |
| 37 | #include "wx/menu.h" |
| 38 | #include "wx/stattext.h" |
| 39 | #include "wx/button.h" |
| 40 | #include "wx/bmpbuttn.h" |
| 41 | #include "wx/radiobox.h" |
| 42 | #include "wx/listbox.h" |
| 43 | #include "wx/choice.h" |
| 44 | #include "wx/checkbox.h" |
| 45 | #include "wx/settings.h" |
| 46 | #include "wx/slider.h" |
| 47 | #include "wx/icon.h" |
| 48 | #include "wx/statbox.h" |
| 49 | #include "wx/statbmp.h" |
| 50 | #include "wx/gauge.h" |
| 51 | #include "wx/textctrl.h" |
| 52 | #include "wx/msgdlg.h" |
| 53 | #include "wx/intl.h" |
| 54 | #endif |
| 55 | |
| 56 | #include "wx/treebase.h" |
| 57 | #include "wx/listctrl.h" |
| 58 | |
| 59 | #if wxUSE_RADIOBTN |
| 60 | #include "wx/radiobut.h" |
| 61 | #endif |
| 62 | |
| 63 | #if wxUSE_SCROLLBAR |
| 64 | #include "wx/scrolbar.h" |
| 65 | #endif |
| 66 | |
| 67 | #if wxUSE_COMBOBOX |
| 68 | #include "wx/combobox.h" |
| 69 | #endif |
| 70 | |
| 71 | #include "wx/validate.h" |
| 72 | |
| 73 | #include "wx/log.h" |
| 74 | |
| 75 | #include <ctype.h> |
| 76 | #include <math.h> |
| 77 | #include <stdlib.h> |
| 78 | #include <string.h> |
| 79 | |
| 80 | #include "wx/resource.h" |
| 81 | #include "wx/string.h" |
| 82 | #include "wx/wxexpr.h" |
| 83 | |
| 84 | #include "wx/settings.h" |
| 85 | #include "wx/stream.h" |
| 86 | |
| 87 | // Forward (private) declarations |
| 88 | bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db); |
| 89 | wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE); |
| 90 | wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr); |
| 91 | wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr); |
| 92 | wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr); |
| 93 | wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr); |
| 94 | wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr); |
| 95 | wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr); |
| 96 | // Interpret list expression |
| 97 | wxFont wxResourceInterpretFontSpec(wxExpr *expr); |
| 98 | |
| 99 | bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL); |
| 100 | bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) ; |
| 101 | bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL); |
| 102 | |
| 103 | wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL; |
| 104 | |
| 105 | char *wxResourceBuffer = (char *) NULL; |
| 106 | long wxResourceBufferSize = 0; |
| 107 | long wxResourceBufferCount = 0; |
| 108 | int wxResourceStringPtr = 0; |
| 109 | |
| 110 | void wxInitializeResourceSystem() |
| 111 | { |
| 112 | wxDefaultResourceTable = new wxResourceTable; |
| 113 | } |
| 114 | |
| 115 | void wxCleanUpResourceSystem() |
| 116 | { |
| 117 | delete wxDefaultResourceTable; |
| 118 | if (wxResourceBuffer) |
| 119 | delete[] wxResourceBuffer; |
| 120 | } |
| 121 | |
| 122 | #if 0 |
| 123 | void wxLogWarning(char *msg) |
| 124 | { |
| 125 | wxMessageBox(msg, _("Warning"), wxOK); |
| 126 | } |
| 127 | #endif |
| 128 | |
| 129 | IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject) |
| 130 | IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable) |
| 131 | |
| 132 | wxItemResource::wxItemResource() |
| 133 | { |
| 134 | m_itemType = wxT(""); |
| 135 | m_title = wxT(""); |
| 136 | m_name = wxT(""); |
| 137 | m_windowStyle = 0; |
| 138 | m_x = m_y = m_width = m_height = 0; |
| 139 | m_value1 = m_value2 = m_value3 = m_value5 = 0; |
| 140 | m_value4 = wxT(""); |
| 141 | m_windowId = 0; |
| 142 | m_exStyle = 0; |
| 143 | } |
| 144 | |
| 145 | wxItemResource::~wxItemResource() |
| 146 | { |
| 147 | wxNode *node = m_children.First(); |
| 148 | while (node) |
| 149 | { |
| 150 | wxItemResource *item = (wxItemResource *)node->Data(); |
| 151 | delete item; |
| 152 | delete node; |
| 153 | node = m_children.First(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Resource table |
| 159 | */ |
| 160 | |
| 161 | wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | wxResourceTable::~wxResourceTable() |
| 166 | { |
| 167 | ClearTable(); |
| 168 | } |
| 169 | |
| 170 | wxItemResource *wxResourceTable::FindResource(const wxString& name) const |
| 171 | { |
| 172 | wxItemResource *item = (wxItemResource *)Get(WXSTRINGCAST name); |
| 173 | return item; |
| 174 | } |
| 175 | |
| 176 | void wxResourceTable::AddResource(wxItemResource *item) |
| 177 | { |
| 178 | wxString name = item->GetName(); |
| 179 | if (name == wxT("")) |
| 180 | name = item->GetTitle(); |
| 181 | if (name == wxT("")) |
| 182 | name = wxT("no name"); |
| 183 | |
| 184 | // Delete existing resource, if any. |
| 185 | Delete(name); |
| 186 | |
| 187 | Put(name, item); |
| 188 | } |
| 189 | |
| 190 | bool wxResourceTable::DeleteResource(const wxString& name) |
| 191 | { |
| 192 | wxItemResource *item = (wxItemResource *)Delete(WXSTRINGCAST name); |
| 193 | if (item) |
| 194 | { |
| 195 | // See if any resource has this as its child; if so, delete from |
| 196 | // parent's child list. |
| 197 | BeginFind(); |
| 198 | wxNode *node = (wxNode *) NULL; |
| 199 | node = Next(); |
| 200 | while (node != NULL) |
| 201 | { |
| 202 | wxItemResource *parent = (wxItemResource *)node->Data(); |
| 203 | if (parent->GetChildren().Member(item)) |
| 204 | { |
| 205 | parent->GetChildren().DeleteObject(item); |
| 206 | break; |
| 207 | } |
| 208 | node = Next(); |
| 209 | } |
| 210 | |
| 211 | delete item; |
| 212 | return TRUE; |
| 213 | } |
| 214 | else |
| 215 | return FALSE; |
| 216 | } |
| 217 | |
| 218 | bool wxResourceTable::ParseResourceFile( wxInputStream *is ) |
| 219 | { |
| 220 | wxExprDatabase db; |
| 221 | int len = is->GetSize() ; |
| 222 | |
| 223 | bool eof = FALSE; |
| 224 | while ( is->TellI() + 10 < len) // it's a hack because the streams dont support EOF |
| 225 | { |
| 226 | wxResourceReadOneResource(is, db, &eof, this) ; |
| 227 | } |
| 228 | return wxResourceInterpretResources(*this, db); |
| 229 | } |
| 230 | |
| 231 | bool wxResourceTable::ParseResourceFile(const wxString& filename) |
| 232 | { |
| 233 | wxExprDatabase db; |
| 234 | |
| 235 | FILE *fd = wxFopen(filename, wxT("r")); |
| 236 | if (!fd) |
| 237 | return FALSE; |
| 238 | bool eof = FALSE; |
| 239 | while (wxResourceReadOneResource(fd, db, &eof, this) && !eof) |
| 240 | { |
| 241 | // Loop |
| 242 | } |
| 243 | fclose(fd); |
| 244 | return wxResourceInterpretResources(*this, db); |
| 245 | } |
| 246 | |
| 247 | bool wxResourceTable::ParseResourceData(const wxString& data) |
| 248 | { |
| 249 | wxExprDatabase db; |
| 250 | if (!db.ReadFromString(data)) |
| 251 | { |
| 252 | wxLogWarning(_("Ill-formed resource file syntax.")); |
| 253 | return FALSE; |
| 254 | } |
| 255 | |
| 256 | return wxResourceInterpretResources(*this, db); |
| 257 | } |
| 258 | |
| 259 | bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height) |
| 260 | { |
| 261 | // Register pre-loaded bitmap data |
| 262 | wxItemResource *item = new wxItemResource; |
| 263 | // item->SetType(wxRESOURCE_TYPE_XBM_DATA); |
| 264 | item->SetType(wxT("wxXBMData")); |
| 265 | item->SetName(name); |
| 266 | item->SetValue1((long)bits); |
| 267 | item->SetValue2((long)width); |
| 268 | item->SetValue3((long)height); |
| 269 | AddResource(item); |
| 270 | return TRUE; |
| 271 | } |
| 272 | |
| 273 | bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char **data) |
| 274 | { |
| 275 | // Register pre-loaded bitmap data |
| 276 | wxItemResource *item = new wxItemResource; |
| 277 | // item->SetType(wxRESOURCE_TYPE_XPM_DATA); |
| 278 | item->SetType(wxT("wxXPMData")); |
| 279 | item->SetName(name); |
| 280 | item->SetValue1((long)data); |
| 281 | AddResource(item); |
| 282 | return TRUE; |
| 283 | } |
| 284 | |
| 285 | bool wxResourceTable::SaveResource(const wxString& WXUNUSED(filename)) |
| 286 | { |
| 287 | return FALSE; |
| 288 | } |
| 289 | |
| 290 | void wxResourceTable::ClearTable() |
| 291 | { |
| 292 | BeginFind(); |
| 293 | wxNode *node = Next(); |
| 294 | while (node) |
| 295 | { |
| 296 | wxNode *next = Next(); |
| 297 | wxItemResource *item = (wxItemResource *)node->Data(); |
| 298 | delete item; |
| 299 | delete node; |
| 300 | node = next; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* childResource, const wxItemResource* parentResource) const |
| 305 | { |
| 306 | int id = childResource->GetId(); |
| 307 | if ( id == 0 ) |
| 308 | id = -1; |
| 309 | |
| 310 | bool dlgUnits = ((parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0); |
| 311 | |
| 312 | wxControl *control = (wxControl *) NULL; |
| 313 | wxString itemType(childResource->GetType()); |
| 314 | |
| 315 | wxPoint pos; |
| 316 | wxSize size; |
| 317 | if (dlgUnits) |
| 318 | { |
| 319 | pos = parent->ConvertDialogToPixels(wxPoint(childResource->GetX(), childResource->GetY())); |
| 320 | size = parent->ConvertDialogToPixels(wxSize(childResource->GetWidth(), childResource->GetHeight())); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | pos = wxPoint(childResource->GetX(), childResource->GetY()); |
| 325 | size = wxSize(childResource->GetWidth(), childResource->GetHeight()); |
| 326 | } |
| 327 | |
| 328 | if (itemType == wxString(wxT("wxButton")) || itemType == wxString(wxT("wxBitmapButton"))) |
| 329 | { |
| 330 | if (childResource->GetValue4() != wxT("")) |
| 331 | { |
| 332 | // Bitmap button |
| 333 | wxBitmap bitmap = childResource->GetBitmap(); |
| 334 | if (!bitmap.Ok()) |
| 335 | { |
| 336 | bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); |
| 337 | ((wxItemResource*) childResource)->SetBitmap(bitmap); |
| 338 | } |
| 339 | if (!bitmap.Ok()) |
| 340 | #if defined(__WXPM__) |
| 341 | // |
| 342 | // OS/2 uses integer id's to access resources, not file name strings |
| 343 | // |
| 344 | bitmap.LoadFile(wxCROSS_BITMAP, wxBITMAP_TYPE_BMP_RESOURCE); |
| 345 | #else |
| 346 | bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); |
| 347 | #endif |
| 348 | control = new wxBitmapButton(parent, id, bitmap, pos, size, |
| 349 | childResource->GetStyle() | wxBU_AUTODRAW, wxDefaultValidator, childResource->GetName()); |
| 350 | } |
| 351 | else |
| 352 | // Normal, text button |
| 353 | control = new wxButton(parent, id, childResource->GetTitle(), pos, size, |
| 354 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 355 | } |
| 356 | else if (itemType == wxString(wxT("wxMessage")) || itemType == wxString(wxT("wxStaticText")) || |
| 357 | itemType == wxString(wxT("wxStaticBitmap"))) |
| 358 | { |
| 359 | if (childResource->GetValue4() != wxT("") || itemType == wxString(wxT("wxStaticBitmap")) ) |
| 360 | { |
| 361 | // Bitmap message |
| 362 | wxBitmap bitmap = childResource->GetBitmap(); |
| 363 | if (!bitmap.Ok()) |
| 364 | { |
| 365 | bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); |
| 366 | ((wxItemResource*) childResource)->SetBitmap(bitmap); |
| 367 | } |
| 368 | #if wxUSE_BITMAP_MESSAGE |
| 369 | #ifdef __WXMSW__ |
| 370 | // Use a default bitmap |
| 371 | if (!bitmap.Ok()) |
| 372 | bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); |
| 373 | #endif |
| 374 | |
| 375 | if (bitmap.Ok()) |
| 376 | control = new wxStaticBitmap(parent, id, bitmap, pos, size, |
| 377 | childResource->GetStyle(), childResource->GetName()); |
| 378 | #endif |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | control = new wxStaticText(parent, id, childResource->GetTitle(), pos, size, |
| 383 | childResource->GetStyle(), childResource->GetName()); |
| 384 | } |
| 385 | } |
| 386 | else if (itemType == wxString(wxT("wxText")) || itemType == wxString(wxT("wxTextCtrl")) || itemType == wxString(wxT("wxMultiText"))) |
| 387 | { |
| 388 | control = new wxTextCtrl(parent, id, childResource->GetValue4(), pos, size, |
| 389 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 390 | } |
| 391 | else if (itemType == wxString(wxT("wxCheckBox"))) |
| 392 | { |
| 393 | control = new wxCheckBox(parent, id, childResource->GetTitle(), pos, size, |
| 394 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 395 | |
| 396 | ((wxCheckBox *)control)->SetValue((childResource->GetValue1() != 0)); |
| 397 | } |
| 398 | #if wxUSE_GAUGE |
| 399 | else if (itemType == wxString(wxT("wxGauge"))) |
| 400 | { |
| 401 | control = new wxGauge(parent, id, (int)childResource->GetValue2(), pos, size, |
| 402 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 403 | |
| 404 | ((wxGauge *)control)->SetValue((int)childResource->GetValue1()); |
| 405 | } |
| 406 | #endif |
| 407 | #if wxUSE_RADIOBTN |
| 408 | else if (itemType == wxString(wxT("wxRadioButton"))) |
| 409 | { |
| 410 | control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(), |
| 411 | pos, size, |
| 412 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 413 | } |
| 414 | #endif |
| 415 | #if wxUSE_SCROLLBAR |
| 416 | else if (itemType == wxString(wxT("wxScrollBar"))) |
| 417 | { |
| 418 | control = new wxScrollBar(parent, id, pos, size, |
| 419 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 420 | /* |
| 421 | ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1()); |
| 422 | ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2()); |
| 423 | ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3()); |
| 424 | ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5()); |
| 425 | */ |
| 426 | ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(), |
| 427 | (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),FALSE); |
| 428 | |
| 429 | } |
| 430 | #endif |
| 431 | else if (itemType == wxString(wxT("wxSlider"))) |
| 432 | { |
| 433 | control = new wxSlider(parent, id, (int)childResource->GetValue1(), |
| 434 | (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size, |
| 435 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 436 | } |
| 437 | else if (itemType == wxString(wxT("wxGroupBox")) || itemType == wxString(wxT("wxStaticBox"))) |
| 438 | { |
| 439 | control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size, |
| 440 | childResource->GetStyle(), childResource->GetName()); |
| 441 | } |
| 442 | else if (itemType == wxString(wxT("wxListBox"))) |
| 443 | { |
| 444 | wxStringList& stringList = childResource->GetStringValues(); |
| 445 | wxString *strings = (wxString *) NULL; |
| 446 | int noStrings = 0; |
| 447 | if (stringList.Number() > 0) |
| 448 | { |
| 449 | noStrings = stringList.Number(); |
| 450 | strings = new wxString[noStrings]; |
| 451 | wxNode *node = stringList.First(); |
| 452 | int i = 0; |
| 453 | while (node) |
| 454 | { |
| 455 | strings[i] = (wxChar *)node->Data(); |
| 456 | i ++; |
| 457 | node = node->Next(); |
| 458 | } |
| 459 | } |
| 460 | control = new wxListBox(parent, id, pos, size, |
| 461 | noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 462 | |
| 463 | if (strings) |
| 464 | delete[] strings; |
| 465 | } |
| 466 | else if (itemType == wxString(wxT("wxChoice"))) |
| 467 | { |
| 468 | wxStringList& stringList = childResource->GetStringValues(); |
| 469 | wxString *strings = (wxString *) NULL; |
| 470 | int noStrings = 0; |
| 471 | if (stringList.Number() > 0) |
| 472 | { |
| 473 | noStrings = stringList.Number(); |
| 474 | strings = new wxString[noStrings]; |
| 475 | wxNode *node = stringList.First(); |
| 476 | int i = 0; |
| 477 | while (node) |
| 478 | { |
| 479 | strings[i] = (wxChar *)node->Data(); |
| 480 | i ++; |
| 481 | node = node->Next(); |
| 482 | } |
| 483 | } |
| 484 | control = new wxChoice(parent, id, pos, size, |
| 485 | noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 486 | |
| 487 | if (strings) |
| 488 | delete[] strings; |
| 489 | } |
| 490 | #if wxUSE_COMBOBOX |
| 491 | else if (itemType == wxString(wxT("wxComboBox"))) |
| 492 | { |
| 493 | wxStringList& stringList = childResource->GetStringValues(); |
| 494 | wxString *strings = (wxString *) NULL; |
| 495 | int noStrings = 0; |
| 496 | if (stringList.Number() > 0) |
| 497 | { |
| 498 | noStrings = stringList.Number(); |
| 499 | strings = new wxString[noStrings]; |
| 500 | wxNode *node = stringList.First(); |
| 501 | int i = 0; |
| 502 | while (node) |
| 503 | { |
| 504 | strings[i] = (wxChar *)node->Data(); |
| 505 | i ++; |
| 506 | node = node->Next(); |
| 507 | } |
| 508 | } |
| 509 | control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size, |
| 510 | noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); |
| 511 | |
| 512 | if (strings) |
| 513 | delete[] strings; |
| 514 | } |
| 515 | #endif |
| 516 | else if (itemType == wxString(wxT("wxRadioBox"))) |
| 517 | { |
| 518 | wxStringList& stringList = childResource->GetStringValues(); |
| 519 | wxString *strings = (wxString *) NULL; |
| 520 | int noStrings = 0; |
| 521 | if (stringList.Number() > 0) |
| 522 | { |
| 523 | noStrings = stringList.Number(); |
| 524 | strings = new wxString[noStrings]; |
| 525 | wxNode *node = stringList.First(); |
| 526 | int i = 0; |
| 527 | while (node) |
| 528 | { |
| 529 | strings[i] = (wxChar *)node->Data(); |
| 530 | i ++; |
| 531 | node = node->Next(); |
| 532 | } |
| 533 | } |
| 534 | control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size, |
| 535 | noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator, |
| 536 | childResource->GetName()); |
| 537 | |
| 538 | if (strings) |
| 539 | delete[] strings; |
| 540 | } |
| 541 | |
| 542 | if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) |
| 543 | { |
| 544 | // Don't set font; will be inherited from parent. |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | if (control && childResource->GetFont().Ok()) |
| 549 | { |
| 550 | control->SetFont(childResource->GetFont()); |
| 551 | |
| 552 | #ifdef __WXMSW__ |
| 553 | // Force the layout algorithm since the size changes the layout |
| 554 | if (control->IsKindOf(CLASSINFO(wxRadioBox))) |
| 555 | { |
| 556 | control->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT); |
| 557 | } |
| 558 | #endif |
| 559 | } |
| 560 | } |
| 561 | return control; |
| 562 | } |
| 563 | |
| 564 | /* |
| 565 | * Interpret database as a series of resources |
| 566 | */ |
| 567 | |
| 568 | bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db) |
| 569 | { |
| 570 | wxNode *node = db.First(); |
| 571 | while (node) |
| 572 | { |
| 573 | wxExpr *clause = (wxExpr *)node->Data(); |
| 574 | wxString functor(clause->Functor()); |
| 575 | |
| 576 | wxItemResource *item = (wxItemResource *) NULL; |
| 577 | if (functor == wxT("dialog")) |
| 578 | item = wxResourceInterpretDialog(table, clause); |
| 579 | else if (functor == wxT("panel")) |
| 580 | item = wxResourceInterpretDialog(table, clause, TRUE); |
| 581 | else if (functor == wxT("menubar")) |
| 582 | item = wxResourceInterpretMenuBar(table, clause); |
| 583 | else if (functor == wxT("menu")) |
| 584 | item = wxResourceInterpretMenu(table, clause); |
| 585 | else if (functor == wxT("string")) |
| 586 | item = wxResourceInterpretString(table, clause); |
| 587 | else if (functor == wxT("bitmap")) |
| 588 | item = wxResourceInterpretBitmap(table, clause); |
| 589 | else if (functor == wxT("icon")) |
| 590 | item = wxResourceInterpretIcon(table, clause); |
| 591 | |
| 592 | if (item) |
| 593 | { |
| 594 | // Remove any existing resource of same name |
| 595 | if (item->GetName() != wxT("")) |
| 596 | table.DeleteResource(item->GetName()); |
| 597 | table.AddResource(item); |
| 598 | } |
| 599 | node = node->Next(); |
| 600 | } |
| 601 | return TRUE; |
| 602 | } |
| 603 | |
| 604 | static const wxChar *g_ValidControlClasses[] = |
| 605 | { |
| 606 | wxT("wxButton"), |
| 607 | wxT("wxBitmapButton"), |
| 608 | wxT("wxMessage"), |
| 609 | wxT("wxStaticText"), |
| 610 | wxT("wxStaticBitmap"), |
| 611 | wxT("wxText"), |
| 612 | wxT("wxTextCtrl"), |
| 613 | wxT("wxMultiText"), |
| 614 | wxT("wxListBox"), |
| 615 | wxT("wxRadioBox"), |
| 616 | wxT("wxRadioButton"), |
| 617 | wxT("wxCheckBox"), |
| 618 | wxT("wxBitmapCheckBox"), |
| 619 | wxT("wxGroupBox"), |
| 620 | wxT("wxStaticBox"), |
| 621 | wxT("wxSlider"), |
| 622 | wxT("wxGauge"), |
| 623 | wxT("wxScrollBar"), |
| 624 | wxT("wxChoice"), |
| 625 | wxT("wxComboBox") |
| 626 | }; |
| 627 | |
| 628 | static bool wxIsValidControlClass(const wxString& c) |
| 629 | { |
| 630 | for ( size_t i = 0; i < WXSIZEOF(g_ValidControlClasses); i++ ) |
| 631 | { |
| 632 | if ( c == g_ValidControlClasses[i] ) |
| 633 | return TRUE; |
| 634 | } |
| 635 | return FALSE; |
| 636 | } |
| 637 | |
| 638 | wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel) |
| 639 | { |
| 640 | wxItemResource *dialogItem = new wxItemResource; |
| 641 | if (isPanel) |
| 642 | dialogItem->SetType(wxT("wxPanel")); |
| 643 | else |
| 644 | dialogItem->SetType(wxT("wxDialog")); |
| 645 | wxString style = wxT(""); |
| 646 | wxString title = wxT(""); |
| 647 | wxString name = wxT(""); |
| 648 | wxString backColourHex = wxT(""); |
| 649 | wxString labelColourHex = wxT(""); |
| 650 | wxString buttonColourHex = wxT(""); |
| 651 | |
| 652 | long windowStyle = wxDEFAULT_DIALOG_STYLE; |
| 653 | if (isPanel) |
| 654 | windowStyle = 0; |
| 655 | |
| 656 | int x = 0; int y = 0; int width = -1; int height = -1; |
| 657 | int isModal = 0; |
| 658 | wxExpr *labelFontExpr = (wxExpr *) NULL; |
| 659 | wxExpr *buttonFontExpr = (wxExpr *) NULL; |
| 660 | wxExpr *fontExpr = (wxExpr *) NULL; |
| 661 | expr->GetAttributeValue(wxT("style"), style); |
| 662 | expr->GetAttributeValue(wxT("name"), name); |
| 663 | expr->GetAttributeValue(wxT("title"), title); |
| 664 | expr->GetAttributeValue(wxT("x"), x); |
| 665 | expr->GetAttributeValue(wxT("y"), y); |
| 666 | expr->GetAttributeValue(wxT("width"), width); |
| 667 | expr->GetAttributeValue(wxT("height"), height); |
| 668 | expr->GetAttributeValue(wxT("modal"), isModal); |
| 669 | expr->GetAttributeValue(wxT("label_font"), &labelFontExpr); |
| 670 | expr->GetAttributeValue(wxT("button_font"), &buttonFontExpr); |
| 671 | expr->GetAttributeValue(wxT("font"), &fontExpr); |
| 672 | expr->GetAttributeValue(wxT("background_colour"), backColourHex); |
| 673 | expr->GetAttributeValue(wxT("label_colour"), labelColourHex); |
| 674 | expr->GetAttributeValue(wxT("button_colour"), buttonColourHex); |
| 675 | |
| 676 | int useDialogUnits = 0; |
| 677 | expr->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits); |
| 678 | if (useDialogUnits != 0) |
| 679 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS); |
| 680 | |
| 681 | int useDefaults = 0; |
| 682 | expr->GetAttributeValue(wxT("use_system_defaults"), useDefaults); |
| 683 | if (useDefaults != 0) |
| 684 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS); |
| 685 | |
| 686 | int id = 0; |
| 687 | expr->GetAttributeValue(wxT("id"), id); |
| 688 | dialogItem->SetId(id); |
| 689 | |
| 690 | if (style != wxT("")) |
| 691 | { |
| 692 | windowStyle = wxParseWindowStyle(style); |
| 693 | } |
| 694 | dialogItem->SetStyle(windowStyle); |
| 695 | dialogItem->SetValue1(isModal); |
| 696 | if (windowStyle & wxDIALOG_MODAL) // Uses style in wxWin 2 |
| 697 | dialogItem->SetValue1(TRUE); |
| 698 | |
| 699 | dialogItem->SetName(name); |
| 700 | dialogItem->SetTitle(title); |
| 701 | dialogItem->SetSize(x, y, width, height); |
| 702 | |
| 703 | // Check for wxWin 1.68-style specifications |
| 704 | if (style.Find(wxT("VERTICAL_LABEL")) != -1) |
| 705 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); |
| 706 | else if (style.Find(wxT("HORIZONTAL_LABEL")) != -1) |
| 707 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); |
| 708 | |
| 709 | if (backColourHex != wxT("")) |
| 710 | { |
| 711 | int r = 0; |
| 712 | int g = 0; |
| 713 | int b = 0; |
| 714 | r = wxHexToDec(backColourHex.Mid(0, 2)); |
| 715 | g = wxHexToDec(backColourHex.Mid(2, 2)); |
| 716 | b = wxHexToDec(backColourHex.Mid(4, 2)); |
| 717 | dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); |
| 718 | } |
| 719 | if (labelColourHex != wxT("")) |
| 720 | { |
| 721 | int r = 0; |
| 722 | int g = 0; |
| 723 | int b = 0; |
| 724 | r = wxHexToDec(labelColourHex.Mid(0, 2)); |
| 725 | g = wxHexToDec(labelColourHex.Mid(2, 2)); |
| 726 | b = wxHexToDec(labelColourHex.Mid(4, 2)); |
| 727 | dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); |
| 728 | } |
| 729 | if (buttonColourHex != wxT("")) |
| 730 | { |
| 731 | int r = 0; |
| 732 | int g = 0; |
| 733 | int b = 0; |
| 734 | r = wxHexToDec(buttonColourHex.Mid(0, 2)); |
| 735 | g = wxHexToDec(buttonColourHex.Mid(2, 2)); |
| 736 | b = wxHexToDec(buttonColourHex.Mid(4, 2)); |
| 737 | dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); |
| 738 | } |
| 739 | |
| 740 | if (fontExpr) |
| 741 | dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr)); |
| 742 | else if (buttonFontExpr) |
| 743 | dialogItem->SetFont(wxResourceInterpretFontSpec(buttonFontExpr)); |
| 744 | else if (labelFontExpr) |
| 745 | dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr)); |
| 746 | |
| 747 | // Now parse all controls |
| 748 | wxExpr *controlExpr = expr->GetFirst(); |
| 749 | while (controlExpr) |
| 750 | { |
| 751 | if (controlExpr->Number() == 3) |
| 752 | { |
| 753 | wxString controlKeyword(controlExpr->Nth(1)->StringValue()); |
| 754 | if (controlKeyword != wxT("") && controlKeyword == wxT("control")) |
| 755 | { |
| 756 | // The value part: always a list. |
| 757 | wxExpr *listExpr = controlExpr->Nth(2); |
| 758 | if (listExpr->Type() == PrologList) |
| 759 | { |
| 760 | wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr); |
| 761 | if (controlItem) |
| 762 | { |
| 763 | dialogItem->GetChildren().Append(controlItem); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | controlExpr = controlExpr->GetNext(); |
| 769 | } |
| 770 | return dialogItem; |
| 771 | } |
| 772 | |
| 773 | wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr) |
| 774 | { |
| 775 | wxItemResource *controlItem = new wxItemResource; |
| 776 | |
| 777 | // First, find the standard features of a control definition: |
| 778 | // [optional integer/string id], control name, title, style, name, x, y, width, height |
| 779 | |
| 780 | wxString controlType; |
| 781 | wxString style; |
| 782 | wxString title; |
| 783 | wxString name; |
| 784 | int id = 0; |
| 785 | long windowStyle = 0; |
| 786 | int x = 0; int y = 0; int width = -1; int height = -1; |
| 787 | int count = 0; |
| 788 | |
| 789 | wxExpr *expr1 = expr->Nth(0); |
| 790 | |
| 791 | if ( expr1->Type() == PrologString || expr1->Type() == PrologWord ) |
| 792 | { |
| 793 | if ( wxIsValidControlClass(expr1->StringValue()) ) |
| 794 | { |
| 795 | count = 1; |
| 796 | controlType = expr1->StringValue(); |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | wxString str(expr1->StringValue()); |
| 801 | id = wxResourceGetIdentifier(str, &table); |
| 802 | if (id == 0) |
| 803 | { |
| 804 | wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"), |
| 805 | (const wxChar*) expr1->StringValue()); |
| 806 | delete controlItem; |
| 807 | return (wxItemResource *) NULL; |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | // Success - we have an id, so the 2nd element must be the control class. |
| 812 | controlType = expr->Nth(1)->StringValue(); |
| 813 | count = 2; |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | else if (expr1->Type() == PrologInteger) |
| 818 | { |
| 819 | id = (int)expr1->IntegerValue(); |
| 820 | // Success - we have an id, so the 2nd element must be the control class. |
| 821 | controlType = expr->Nth(1)->StringValue(); |
| 822 | count = 2; |
| 823 | } |
| 824 | |
| 825 | expr1 = expr->Nth(count); |
| 826 | count ++; |
| 827 | if ( expr1 ) |
| 828 | title = expr1->StringValue(); |
| 829 | |
| 830 | expr1 = expr->Nth(count); |
| 831 | count ++; |
| 832 | if (expr1) |
| 833 | { |
| 834 | style = expr1->StringValue(); |
| 835 | windowStyle = wxParseWindowStyle(style); |
| 836 | } |
| 837 | |
| 838 | expr1 = expr->Nth(count); |
| 839 | count ++; |
| 840 | if (expr1) |
| 841 | name = expr1->StringValue(); |
| 842 | |
| 843 | expr1 = expr->Nth(count); |
| 844 | count ++; |
| 845 | if (expr1) |
| 846 | x = (int)expr1->IntegerValue(); |
| 847 | |
| 848 | expr1 = expr->Nth(count); |
| 849 | count ++; |
| 850 | if (expr1) |
| 851 | y = (int)expr1->IntegerValue(); |
| 852 | |
| 853 | expr1 = expr->Nth(count); |
| 854 | count ++; |
| 855 | if (expr1) |
| 856 | width = (int)expr1->IntegerValue(); |
| 857 | |
| 858 | expr1 = expr->Nth(count); |
| 859 | count ++; |
| 860 | if (expr1) |
| 861 | height = (int)expr1->IntegerValue(); |
| 862 | |
| 863 | controlItem->SetStyle(windowStyle); |
| 864 | controlItem->SetName(name); |
| 865 | controlItem->SetTitle(title); |
| 866 | controlItem->SetSize(x, y, width, height); |
| 867 | controlItem->SetType(controlType); |
| 868 | controlItem->SetId(id); |
| 869 | |
| 870 | // Check for wxWin 1.68-style specifications |
| 871 | if (style.Find(wxT("VERTICAL_LABEL")) != -1) |
| 872 | controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); |
| 873 | else if (style.Find(wxT("HORIZONTAL_LABEL")) != -1) |
| 874 | controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); |
| 875 | |
| 876 | if (controlType == wxT("wxButton")) |
| 877 | { |
| 878 | // Check for bitmap resource name (in case loading old-style resource file) |
| 879 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) |
| 880 | { |
| 881 | wxString str(expr->Nth(count)->StringValue()); |
| 882 | count ++; |
| 883 | |
| 884 | if (str != wxT("")) |
| 885 | { |
| 886 | controlItem->SetValue4(str); |
| 887 | controlItem->SetType(wxT("wxBitmapButton")); |
| 888 | } |
| 889 | } |
| 890 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 891 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 892 | } |
| 893 | else if (controlType == wxT("wxBitmapButton")) |
| 894 | { |
| 895 | // Check for bitmap resource name |
| 896 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) |
| 897 | { |
| 898 | wxString str(expr->Nth(count)->StringValue()); |
| 899 | controlItem->SetValue4(str); |
| 900 | count ++; |
| 901 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 902 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 903 | } |
| 904 | } |
| 905 | else if (controlType == wxT("wxCheckBox")) |
| 906 | { |
| 907 | // Check for default value |
| 908 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 909 | { |
| 910 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); |
| 911 | count ++; |
| 912 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 913 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 914 | } |
| 915 | } |
| 916 | #if wxUSE_RADIOBTN |
| 917 | else if (controlType == wxT("wxRadioButton")) |
| 918 | { |
| 919 | // Check for default value |
| 920 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 921 | { |
| 922 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); |
| 923 | count ++; |
| 924 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 925 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 926 | } |
| 927 | } |
| 928 | #endif |
| 929 | else if (controlType == wxT("wxText") || controlType == wxT("wxTextCtrl") || controlType == wxT("wxMultiText")) |
| 930 | { |
| 931 | // Check for default value |
| 932 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) |
| 933 | { |
| 934 | wxString str(expr->Nth(count)->StringValue()); |
| 935 | controlItem->SetValue4(str); |
| 936 | count ++; |
| 937 | |
| 938 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 939 | { |
| 940 | // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 941 | // Skip past the obsolete label font spec if there are two consecutive specs |
| 942 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) |
| 943 | count ++; |
| 944 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | else if (controlType == wxT("wxMessage") || controlType == wxT("wxStaticText")) |
| 949 | { |
| 950 | // Check for bitmap resource name (in case it's an old-style .wxr file) |
| 951 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) |
| 952 | { |
| 953 | wxString str(expr->Nth(count)->StringValue()); |
| 954 | controlItem->SetValue4(str); |
| 955 | count ++; |
| 956 | controlItem->SetType(wxT("wxStaticText")); |
| 957 | } |
| 958 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 959 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 960 | } |
| 961 | else if (controlType == wxT("wxStaticBitmap")) |
| 962 | { |
| 963 | // Check for bitmap resource name |
| 964 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) |
| 965 | { |
| 966 | wxString str(expr->Nth(count)->StringValue()); |
| 967 | controlItem->SetValue4(str); |
| 968 | count ++; |
| 969 | } |
| 970 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 971 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 972 | } |
| 973 | else if (controlType == wxT("wxGroupBox") || controlType == wxT("wxStaticBox")) |
| 974 | { |
| 975 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 976 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 977 | } |
| 978 | else if (controlType == wxT("wxGauge")) |
| 979 | { |
| 980 | // Check for default value |
| 981 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 982 | { |
| 983 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); |
| 984 | count ++; |
| 985 | |
| 986 | // Check for range |
| 987 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 988 | { |
| 989 | controlItem->SetValue2(expr->Nth(count)->IntegerValue()); |
| 990 | count ++; |
| 991 | |
| 992 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 993 | { |
| 994 | // Skip past the obsolete label font spec if there are two consecutive specs |
| 995 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) |
| 996 | count ++; |
| 997 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | else if (controlType == wxT("wxSlider")) |
| 1003 | { |
| 1004 | // Check for default value |
| 1005 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1006 | { |
| 1007 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); |
| 1008 | count ++; |
| 1009 | |
| 1010 | // Check for min |
| 1011 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1012 | { |
| 1013 | controlItem->SetValue2(expr->Nth(count)->IntegerValue()); |
| 1014 | count ++; |
| 1015 | |
| 1016 | // Check for max |
| 1017 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1018 | { |
| 1019 | controlItem->SetValue3(expr->Nth(count)->IntegerValue()); |
| 1020 | count ++; |
| 1021 | |
| 1022 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 1023 | { |
| 1024 | // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 1025 | // do nothing |
| 1026 | count ++; |
| 1027 | |
| 1028 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 1029 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | else if (controlType == wxT("wxScrollBar")) |
| 1036 | { |
| 1037 | // DEFAULT VALUE |
| 1038 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1039 | { |
| 1040 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); |
| 1041 | count ++; |
| 1042 | |
| 1043 | // PAGE LENGTH |
| 1044 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1045 | { |
| 1046 | controlItem->SetValue2(expr->Nth(count)->IntegerValue()); |
| 1047 | count ++; |
| 1048 | |
| 1049 | // OBJECT LENGTH |
| 1050 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1051 | { |
| 1052 | controlItem->SetValue3(expr->Nth(count)->IntegerValue()); |
| 1053 | count ++; |
| 1054 | |
| 1055 | // VIEW LENGTH |
| 1056 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1057 | controlItem->SetValue5(expr->Nth(count)->IntegerValue()); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | else if (controlType == wxT("wxListBox")) |
| 1063 | { |
| 1064 | wxExpr *valueList = (wxExpr *) NULL; |
| 1065 | |
| 1066 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) |
| 1067 | { |
| 1068 | wxStringList stringList; |
| 1069 | wxExpr *stringExpr = valueList->GetFirst(); |
| 1070 | while (stringExpr) |
| 1071 | { |
| 1072 | stringList.Add(stringExpr->StringValue()); |
| 1073 | stringExpr = stringExpr->GetNext(); |
| 1074 | } |
| 1075 | controlItem->SetStringValues(stringList); |
| 1076 | count ++; |
| 1077 | // This is now obsolete: it's in the window style. |
| 1078 | // Check for wxSINGLE/wxMULTIPLE |
| 1079 | wxExpr *mult = (wxExpr *) NULL; |
| 1080 | /* |
| 1081 | controlItem->SetValue1(wxLB_SINGLE); |
| 1082 | */ |
| 1083 | if (((mult = expr->Nth(count)) != 0) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord))) |
| 1084 | { |
| 1085 | /* |
| 1086 | wxString m(mult->StringValue()); |
| 1087 | if (m == "wxLB_MULTIPLE") |
| 1088 | controlItem->SetValue1(wxLB_MULTIPLE); |
| 1089 | else if (m == "wxLB_EXTENDED") |
| 1090 | controlItem->SetValue1(wxLB_EXTENDED); |
| 1091 | */ |
| 1092 | // Ignore the value |
| 1093 | count ++; |
| 1094 | } |
| 1095 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 1096 | { |
| 1097 | // Skip past the obsolete label font spec if there are two consecutive specs |
| 1098 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) |
| 1099 | count ++; |
| 1100 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | else if (controlType == wxT("wxChoice")) |
| 1105 | { |
| 1106 | wxExpr *valueList = (wxExpr *) NULL; |
| 1107 | // Check for default value list |
| 1108 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) |
| 1109 | { |
| 1110 | wxStringList stringList; |
| 1111 | wxExpr *stringExpr = valueList->GetFirst(); |
| 1112 | while (stringExpr) |
| 1113 | { |
| 1114 | stringList.Add(stringExpr->StringValue()); |
| 1115 | stringExpr = stringExpr->GetNext(); |
| 1116 | } |
| 1117 | controlItem->SetStringValues(stringList); |
| 1118 | |
| 1119 | count ++; |
| 1120 | |
| 1121 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 1122 | { |
| 1123 | // Skip past the obsolete label font spec if there are two consecutive specs |
| 1124 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) |
| 1125 | count ++; |
| 1126 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | #if wxUSE_COMBOBOX |
| 1131 | else if (controlType == wxT("wxComboBox")) |
| 1132 | { |
| 1133 | wxExpr *textValue = expr->Nth(count); |
| 1134 | if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord)) |
| 1135 | { |
| 1136 | wxString str(textValue->StringValue()); |
| 1137 | controlItem->SetValue4(str); |
| 1138 | |
| 1139 | count ++; |
| 1140 | |
| 1141 | wxExpr *valueList = (wxExpr *) NULL; |
| 1142 | // Check for default value list |
| 1143 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) |
| 1144 | { |
| 1145 | wxStringList stringList; |
| 1146 | wxExpr *stringExpr = valueList->GetFirst(); |
| 1147 | while (stringExpr) |
| 1148 | { |
| 1149 | stringList.Add(stringExpr->StringValue()); |
| 1150 | stringExpr = stringExpr->GetNext(); |
| 1151 | } |
| 1152 | controlItem->SetStringValues(stringList); |
| 1153 | |
| 1154 | count ++; |
| 1155 | |
| 1156 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 1157 | { |
| 1158 | // Skip past the obsolete label font spec if there are two consecutive specs |
| 1159 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) |
| 1160 | count ++; |
| 1161 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | #endif |
| 1167 | #if 1 |
| 1168 | else if (controlType == wxT("wxRadioBox")) |
| 1169 | { |
| 1170 | wxExpr *valueList = (wxExpr *) NULL; |
| 1171 | // Check for default value list |
| 1172 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) |
| 1173 | { |
| 1174 | wxStringList stringList; |
| 1175 | wxExpr *stringExpr = valueList->GetFirst(); |
| 1176 | while (stringExpr) |
| 1177 | { |
| 1178 | stringList.Add(stringExpr->StringValue()); |
| 1179 | stringExpr = stringExpr->GetNext(); |
| 1180 | } |
| 1181 | controlItem->SetStringValues(stringList); |
| 1182 | count ++; |
| 1183 | |
| 1184 | // majorDim (number of rows or cols) |
| 1185 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) |
| 1186 | { |
| 1187 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); |
| 1188 | count ++; |
| 1189 | } |
| 1190 | else |
| 1191 | controlItem->SetValue1(0); |
| 1192 | |
| 1193 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) |
| 1194 | { |
| 1195 | // Skip past the obsolete label font spec if there are two consecutive specs |
| 1196 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) |
| 1197 | count ++; |
| 1198 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | #endif |
| 1203 | else |
| 1204 | { |
| 1205 | delete controlItem; |
| 1206 | return (wxItemResource *) NULL; |
| 1207 | } |
| 1208 | return controlItem; |
| 1209 | } |
| 1210 | |
| 1211 | // Forward declaration |
| 1212 | wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr); |
| 1213 | |
| 1214 | /* |
| 1215 | * Interpet a menu item |
| 1216 | */ |
| 1217 | |
| 1218 | wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr) |
| 1219 | { |
| 1220 | wxItemResource *item = new wxItemResource; |
| 1221 | |
| 1222 | wxExpr *labelExpr = expr->Nth(0); |
| 1223 | wxExpr *idExpr = expr->Nth(1); |
| 1224 | wxExpr *helpExpr = expr->Nth(2); |
| 1225 | wxExpr *checkableExpr = expr->Nth(3); |
| 1226 | |
| 1227 | // Further keywords/attributes to follow sometime... |
| 1228 | if (expr->Number() == 0) |
| 1229 | { |
| 1230 | // item->SetType(wxRESOURCE_TYPE_SEPARATOR); |
| 1231 | item->SetType(wxT("wxMenuSeparator")); |
| 1232 | return item; |
| 1233 | } |
| 1234 | else |
| 1235 | { |
| 1236 | // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter. |
| 1237 | item->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter. |
| 1238 | if (labelExpr) |
| 1239 | { |
| 1240 | wxString str(labelExpr->StringValue()); |
| 1241 | item->SetTitle(str); |
| 1242 | } |
| 1243 | if (idExpr) |
| 1244 | { |
| 1245 | int id = 0; |
| 1246 | // If a string or word, must look up in identifier table. |
| 1247 | if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord)) |
| 1248 | { |
| 1249 | wxString str(idExpr->StringValue()); |
| 1250 | id = wxResourceGetIdentifier(str, &table); |
| 1251 | if (id == 0) |
| 1252 | { |
| 1253 | wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"), |
| 1254 | (const wxChar*) idExpr->StringValue()); |
| 1255 | } |
| 1256 | } |
| 1257 | else if (idExpr->Type() == PrologInteger) |
| 1258 | id = (int)idExpr->IntegerValue(); |
| 1259 | item->SetValue1(id); |
| 1260 | } |
| 1261 | if (helpExpr) |
| 1262 | { |
| 1263 | wxString str(helpExpr->StringValue()); |
| 1264 | item->SetValue4(str); |
| 1265 | } |
| 1266 | if (checkableExpr) |
| 1267 | item->SetValue2(checkableExpr->IntegerValue()); |
| 1268 | |
| 1269 | // Find the first expression that's a list, for submenu |
| 1270 | wxExpr *subMenuExpr = expr->GetFirst(); |
| 1271 | while (subMenuExpr && (subMenuExpr->Type() != PrologList)) |
| 1272 | subMenuExpr = subMenuExpr->GetNext(); |
| 1273 | |
| 1274 | while (subMenuExpr) |
| 1275 | { |
| 1276 | wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr); |
| 1277 | item->GetChildren().Append(child); |
| 1278 | subMenuExpr = subMenuExpr->GetNext(); |
| 1279 | } |
| 1280 | } |
| 1281 | return item; |
| 1282 | } |
| 1283 | |
| 1284 | /* |
| 1285 | * Interpret a nested list as a menu |
| 1286 | */ |
| 1287 | /* |
| 1288 | wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr) |
| 1289 | { |
| 1290 | wxItemResource *menu = new wxItemResource; |
| 1291 | // menu->SetType(wxTYPE_MENU); |
| 1292 | menu->SetType("wxMenu"); |
| 1293 | wxExpr *element = expr->GetFirst(); |
| 1294 | while (element) |
| 1295 | { |
| 1296 | wxItemResource *item = wxResourceInterpretMenuItem(table, element); |
| 1297 | if (item) |
| 1298 | menu->GetChildren().Append(item); |
| 1299 | element = element->GetNext(); |
| 1300 | } |
| 1301 | return menu; |
| 1302 | } |
| 1303 | */ |
| 1304 | |
| 1305 | wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr) |
| 1306 | { |
| 1307 | wxExpr *listExpr = (wxExpr *) NULL; |
| 1308 | expr->GetAttributeValue(wxT("menu"), &listExpr); |
| 1309 | if (!listExpr) |
| 1310 | return (wxItemResource *) NULL; |
| 1311 | |
| 1312 | wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); |
| 1313 | |
| 1314 | if (!menuResource) |
| 1315 | return (wxItemResource *) NULL; |
| 1316 | |
| 1317 | wxString name; |
| 1318 | if (expr->GetAttributeValue(wxT("name"), name)) |
| 1319 | { |
| 1320 | menuResource->SetName(name); |
| 1321 | } |
| 1322 | |
| 1323 | return menuResource; |
| 1324 | } |
| 1325 | |
| 1326 | wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr) |
| 1327 | { |
| 1328 | wxExpr *listExpr = (wxExpr *) NULL; |
| 1329 | expr->GetAttributeValue(wxT("menu"), &listExpr); |
| 1330 | if (!listExpr) |
| 1331 | return (wxItemResource *) NULL; |
| 1332 | |
| 1333 | wxItemResource *resource = new wxItemResource; |
| 1334 | resource->SetType(wxT("wxMenu")); |
| 1335 | // resource->SetType(wxTYPE_MENU); |
| 1336 | |
| 1337 | wxExpr *element = listExpr->GetFirst(); |
| 1338 | while (element) |
| 1339 | { |
| 1340 | wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); |
| 1341 | resource->GetChildren().Append(menuResource); |
| 1342 | element = element->GetNext(); |
| 1343 | } |
| 1344 | |
| 1345 | wxString name; |
| 1346 | if (expr->GetAttributeValue(wxT("name"), name)) |
| 1347 | { |
| 1348 | resource->SetName(name); |
| 1349 | } |
| 1350 | |
| 1351 | return resource; |
| 1352 | } |
| 1353 | |
| 1354 | wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr)) |
| 1355 | { |
| 1356 | return (wxItemResource *) NULL; |
| 1357 | } |
| 1358 | |
| 1359 | wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr) |
| 1360 | { |
| 1361 | wxItemResource *bitmapItem = new wxItemResource; |
| 1362 | // bitmapItem->SetType(wxTYPE_BITMAP); |
| 1363 | bitmapItem->SetType(wxT("wxBitmap")); |
| 1364 | wxString name; |
| 1365 | if (expr->GetAttributeValue(wxT("name"), name)) |
| 1366 | { |
| 1367 | bitmapItem->SetName(name); |
| 1368 | } |
| 1369 | // Now parse all bitmap specifications |
| 1370 | wxExpr *bitmapExpr = expr->GetFirst(); |
| 1371 | while (bitmapExpr) |
| 1372 | { |
| 1373 | if (bitmapExpr->Number() == 3) |
| 1374 | { |
| 1375 | wxString bitmapKeyword(bitmapExpr->Nth(1)->StringValue()); |
| 1376 | if (bitmapKeyword == wxT("bitmap") || bitmapKeyword == wxT("icon")) |
| 1377 | { |
| 1378 | // The value part: always a list. |
| 1379 | wxExpr *listExpr = bitmapExpr->Nth(2); |
| 1380 | if (listExpr->Type() == PrologList) |
| 1381 | { |
| 1382 | wxItemResource *bitmapSpec = new wxItemResource; |
| 1383 | // bitmapSpec->SetType(wxTYPE_BITMAP); |
| 1384 | bitmapSpec->SetType(wxT("wxBitmap")); |
| 1385 | |
| 1386 | // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution] |
| 1387 | // where everything after 'filename' is optional. |
| 1388 | wxExpr *nameExpr = listExpr->Nth(0); |
| 1389 | wxExpr *typeExpr = listExpr->Nth(1); |
| 1390 | wxExpr *platformExpr = listExpr->Nth(2); |
| 1391 | wxExpr *coloursExpr = listExpr->Nth(3); |
| 1392 | wxExpr *xresExpr = listExpr->Nth(4); |
| 1393 | wxExpr *yresExpr = listExpr->Nth(5); |
| 1394 | if (nameExpr && nameExpr->StringValue() != wxT("")) |
| 1395 | { |
| 1396 | bitmapSpec->SetName(nameExpr->StringValue()); |
| 1397 | } |
| 1398 | if (typeExpr && typeExpr->StringValue() != wxT("")) |
| 1399 | { |
| 1400 | bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue())); |
| 1401 | } |
| 1402 | else |
| 1403 | bitmapSpec->SetValue1(0); |
| 1404 | |
| 1405 | if (platformExpr && platformExpr->StringValue() != wxT("")) |
| 1406 | { |
| 1407 | wxString plat(platformExpr->StringValue()); |
| 1408 | if (plat == wxT("windows") || plat == wxT("WINDOWS")) |
| 1409 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_WINDOWS); |
| 1410 | else if (plat == wxT("x") || plat == wxT("X")) |
| 1411 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_X); |
| 1412 | else if (plat == wxT("mac") || plat == wxT("MAC")) |
| 1413 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_MAC); |
| 1414 | else |
| 1415 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY); |
| 1416 | } |
| 1417 | else |
| 1418 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY); |
| 1419 | |
| 1420 | if (coloursExpr) |
| 1421 | bitmapSpec->SetValue3(coloursExpr->IntegerValue()); |
| 1422 | int xres = 0; |
| 1423 | int yres = 0; |
| 1424 | if (xresExpr) |
| 1425 | xres = (int)xresExpr->IntegerValue(); |
| 1426 | if (yresExpr) |
| 1427 | yres = (int)yresExpr->IntegerValue(); |
| 1428 | bitmapSpec->SetSize(0, 0, xres, yres); |
| 1429 | |
| 1430 | bitmapItem->GetChildren().Append(bitmapSpec); |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | bitmapExpr = bitmapExpr->GetNext(); |
| 1435 | } |
| 1436 | |
| 1437 | return bitmapItem; |
| 1438 | } |
| 1439 | |
| 1440 | wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr) |
| 1441 | { |
| 1442 | wxItemResource *item = wxResourceInterpretBitmap(table, expr); |
| 1443 | if (item) |
| 1444 | { |
| 1445 | // item->SetType(wxTYPE_ICON); |
| 1446 | item->SetType(wxT("wxIcon")); |
| 1447 | return item; |
| 1448 | } |
| 1449 | else |
| 1450 | return (wxItemResource *) NULL; |
| 1451 | } |
| 1452 | |
| 1453 | // Interpret list expression as a font |
| 1454 | wxFont wxResourceInterpretFontSpec(wxExpr *expr) |
| 1455 | { |
| 1456 | if (expr->Type() != PrologList) |
| 1457 | return wxNullFont; |
| 1458 | |
| 1459 | int point = 10; |
| 1460 | int family = wxSWISS; |
| 1461 | int style = wxNORMAL; |
| 1462 | int weight = wxNORMAL; |
| 1463 | int underline = 0; |
| 1464 | wxString faceName(wxT("")); |
| 1465 | |
| 1466 | wxExpr *pointExpr = expr->Nth(0); |
| 1467 | wxExpr *familyExpr = expr->Nth(1); |
| 1468 | wxExpr *styleExpr = expr->Nth(2); |
| 1469 | wxExpr *weightExpr = expr->Nth(3); |
| 1470 | wxExpr *underlineExpr = expr->Nth(4); |
| 1471 | wxExpr *faceNameExpr = expr->Nth(5); |
| 1472 | if (pointExpr) |
| 1473 | point = (int)pointExpr->IntegerValue(); |
| 1474 | |
| 1475 | wxString str; |
| 1476 | if (familyExpr) |
| 1477 | { |
| 1478 | str = familyExpr->StringValue(); |
| 1479 | family = (int)wxParseWindowStyle(str); |
| 1480 | } |
| 1481 | if (styleExpr) |
| 1482 | { |
| 1483 | str = styleExpr->StringValue(); |
| 1484 | style = (int)wxParseWindowStyle(str); |
| 1485 | } |
| 1486 | if (weightExpr) |
| 1487 | { |
| 1488 | str = weightExpr->StringValue(); |
| 1489 | weight = (int)wxParseWindowStyle(str); |
| 1490 | } |
| 1491 | if (underlineExpr) |
| 1492 | underline = (int)underlineExpr->IntegerValue(); |
| 1493 | if (faceNameExpr) |
| 1494 | faceName = faceNameExpr->StringValue(); |
| 1495 | |
| 1496 | return *wxTheFontList->FindOrCreateFont(point, family, style, weight, |
| 1497 | (underline != 0), faceName); |
| 1498 | } |
| 1499 | |
| 1500 | // Separate file for the remainder of this, for BC++/Win16 |
| 1501 | |
| 1502 | #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__)) |
| 1503 | /* |
| 1504 | * (Re)allocate buffer for reading in from resource file |
| 1505 | */ |
| 1506 | |
| 1507 | bool wxReallocateResourceBuffer() |
| 1508 | { |
| 1509 | if (!wxResourceBuffer) |
| 1510 | { |
| 1511 | wxResourceBufferSize = 1000; |
| 1512 | wxResourceBuffer = new char[wxResourceBufferSize]; |
| 1513 | return TRUE; |
| 1514 | } |
| 1515 | if (wxResourceBuffer) |
| 1516 | { |
| 1517 | long newSize = wxResourceBufferSize + 1000; |
| 1518 | char *tmp = new char[(int)newSize]; |
| 1519 | strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount); |
| 1520 | delete[] wxResourceBuffer; |
| 1521 | wxResourceBuffer = tmp; |
| 1522 | wxResourceBufferSize = newSize; |
| 1523 | } |
| 1524 | return TRUE; |
| 1525 | } |
| 1526 | |
| 1527 | static bool wxEatWhiteSpace(FILE *fd) |
| 1528 | { |
| 1529 | int ch = 0; |
| 1530 | |
| 1531 | while ((ch = getc(fd)) != EOF) |
| 1532 | { |
| 1533 | switch (ch) |
| 1534 | { |
| 1535 | case ' ': |
| 1536 | case 0x0a: |
| 1537 | case 0x0d: |
| 1538 | case 0x09: |
| 1539 | break; |
| 1540 | case '/': |
| 1541 | { |
| 1542 | int prev_ch = ch; |
| 1543 | ch = getc(fd); |
| 1544 | if (ch == EOF) |
| 1545 | { |
| 1546 | ungetc(prev_ch, fd); |
| 1547 | return TRUE; |
| 1548 | } |
| 1549 | |
| 1550 | if (ch == '*') |
| 1551 | { |
| 1552 | // Eat C comment |
| 1553 | prev_ch = 0; |
| 1554 | while ((ch = getc(fd)) != EOF) |
| 1555 | { |
| 1556 | if (ch == '/' && prev_ch == '*') |
| 1557 | break; |
| 1558 | prev_ch = ch; |
| 1559 | } |
| 1560 | } |
| 1561 | else if (ch == '/') |
| 1562 | { |
| 1563 | // Eat C++ comment |
| 1564 | static char buffer[255]; |
| 1565 | fgets(buffer, 255, fd); |
| 1566 | } |
| 1567 | else |
| 1568 | { |
| 1569 | ungetc(prev_ch, fd); |
| 1570 | ungetc(ch, fd); |
| 1571 | return TRUE; |
| 1572 | } |
| 1573 | } |
| 1574 | break; |
| 1575 | default: |
| 1576 | ungetc(ch, fd); |
| 1577 | return TRUE; |
| 1578 | |
| 1579 | } |
| 1580 | } |
| 1581 | return FALSE; |
| 1582 | } |
| 1583 | static bool wxEatWhiteSpace(wxInputStream *is) |
| 1584 | { |
| 1585 | int ch = is->GetC() ; |
| 1586 | if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9)) |
| 1587 | { |
| 1588 | is->Ungetch(ch); |
| 1589 | return TRUE; |
| 1590 | } |
| 1591 | |
| 1592 | // Eat whitespace |
| 1593 | while (ch == ' ' || ch == 10 || ch == 13 || ch == 9) |
| 1594 | ch = is->GetC(); |
| 1595 | // Check for comment |
| 1596 | if (ch == '/') |
| 1597 | { |
| 1598 | ch = is->GetC(); |
| 1599 | if (ch == '*') |
| 1600 | { |
| 1601 | bool finished = FALSE; |
| 1602 | while (!finished) |
| 1603 | { |
| 1604 | ch = is->GetC(); |
| 1605 | if (ch == EOF) |
| 1606 | return FALSE; |
| 1607 | if (ch == '*') |
| 1608 | { |
| 1609 | int newCh = is->GetC(); |
| 1610 | if (newCh == '/') |
| 1611 | finished = TRUE; |
| 1612 | else |
| 1613 | { |
| 1614 | is->Ungetch(ch); |
| 1615 | } |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | else // False alarm |
| 1620 | return FALSE; |
| 1621 | } |
| 1622 | else |
| 1623 | is->Ungetch(ch); |
| 1624 | return wxEatWhiteSpace(is); |
| 1625 | } |
| 1626 | |
| 1627 | bool wxGetResourceToken(FILE *fd) |
| 1628 | { |
| 1629 | if (!wxResourceBuffer) |
| 1630 | wxReallocateResourceBuffer(); |
| 1631 | wxResourceBuffer[0] = 0; |
| 1632 | wxEatWhiteSpace(fd); |
| 1633 | |
| 1634 | int ch = getc(fd); |
| 1635 | if (ch == '"') |
| 1636 | { |
| 1637 | // Get string |
| 1638 | wxResourceBufferCount = 0; |
| 1639 | ch = getc(fd); |
| 1640 | while (ch != '"') |
| 1641 | { |
| 1642 | int actualCh = ch; |
| 1643 | if (ch == EOF) |
| 1644 | { |
| 1645 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 1646 | return FALSE; |
| 1647 | } |
| 1648 | // Escaped characters |
| 1649 | else if (ch == '\\') |
| 1650 | { |
| 1651 | int newCh = getc(fd); |
| 1652 | if (newCh == '"') |
| 1653 | actualCh = '"'; |
| 1654 | else if (newCh == 10) |
| 1655 | actualCh = 10; |
| 1656 | else |
| 1657 | { |
| 1658 | ungetc(newCh, fd); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | if (wxResourceBufferCount >= wxResourceBufferSize-1) |
| 1663 | wxReallocateResourceBuffer(); |
| 1664 | wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; |
| 1665 | wxResourceBufferCount ++; |
| 1666 | ch = getc(fd); |
| 1667 | } |
| 1668 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 1669 | } |
| 1670 | else |
| 1671 | { |
| 1672 | wxResourceBufferCount = 0; |
| 1673 | // Any other token |
| 1674 | while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) |
| 1675 | { |
| 1676 | if (wxResourceBufferCount >= wxResourceBufferSize-1) |
| 1677 | wxReallocateResourceBuffer(); |
| 1678 | wxResourceBuffer[wxResourceBufferCount] = (char)ch; |
| 1679 | wxResourceBufferCount ++; |
| 1680 | |
| 1681 | ch = getc(fd); |
| 1682 | } |
| 1683 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 1684 | if (ch == EOF) |
| 1685 | return FALSE; |
| 1686 | } |
| 1687 | return TRUE; |
| 1688 | } |
| 1689 | |
| 1690 | bool wxGetResourceToken(wxInputStream *is) |
| 1691 | { |
| 1692 | if (!wxResourceBuffer) |
| 1693 | wxReallocateResourceBuffer(); |
| 1694 | wxResourceBuffer[0] = 0; |
| 1695 | wxEatWhiteSpace(is); |
| 1696 | |
| 1697 | int ch = is->GetC() ; |
| 1698 | if (ch == '"') |
| 1699 | { |
| 1700 | // Get string |
| 1701 | wxResourceBufferCount = 0; |
| 1702 | ch = is->GetC(); |
| 1703 | while (ch != '"') |
| 1704 | { |
| 1705 | int actualCh = ch; |
| 1706 | if (ch == EOF) |
| 1707 | { |
| 1708 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 1709 | return FALSE; |
| 1710 | } |
| 1711 | // Escaped characters |
| 1712 | else if (ch == '\\') |
| 1713 | { |
| 1714 | int newCh = is->GetC(); |
| 1715 | if (newCh == '"') |
| 1716 | actualCh = '"'; |
| 1717 | else if (newCh == 10) |
| 1718 | actualCh = 10; |
| 1719 | else if (newCh == 13) // mac |
| 1720 | actualCh = 10; |
| 1721 | else |
| 1722 | { |
| 1723 | is->Ungetch(newCh); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | if (wxResourceBufferCount >= wxResourceBufferSize-1) |
| 1728 | wxReallocateResourceBuffer(); |
| 1729 | wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; |
| 1730 | wxResourceBufferCount ++; |
| 1731 | ch = is->GetC(); |
| 1732 | } |
| 1733 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 1734 | } |
| 1735 | else |
| 1736 | { |
| 1737 | wxResourceBufferCount = 0; |
| 1738 | // Any other token |
| 1739 | while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) |
| 1740 | { |
| 1741 | if (wxResourceBufferCount >= wxResourceBufferSize-1) |
| 1742 | wxReallocateResourceBuffer(); |
| 1743 | wxResourceBuffer[wxResourceBufferCount] = (char)ch; |
| 1744 | wxResourceBufferCount ++; |
| 1745 | |
| 1746 | ch = is->GetC(); |
| 1747 | } |
| 1748 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 1749 | if (ch == EOF) |
| 1750 | return FALSE; |
| 1751 | } |
| 1752 | return TRUE; |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | * Files are in form: |
| 1757 | static char *name = "...."; |
| 1758 | with possible comments. |
| 1759 | */ |
| 1760 | |
| 1761 | bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) |
| 1762 | { |
| 1763 | if (!table) |
| 1764 | table = wxDefaultResourceTable; |
| 1765 | |
| 1766 | // static or #define |
| 1767 | if (!wxGetResourceToken(fd)) |
| 1768 | { |
| 1769 | *eof = TRUE; |
| 1770 | return FALSE; |
| 1771 | } |
| 1772 | |
| 1773 | if (strcmp(wxResourceBuffer, "#define") == 0) |
| 1774 | { |
| 1775 | wxGetResourceToken(fd); |
| 1776 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 1777 | wxGetResourceToken(fd); |
| 1778 | wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 1779 | if (wxIsdigit(value[0])) |
| 1780 | { |
| 1781 | int val = (int)wxAtol(value); |
| 1782 | wxResourceAddIdentifier(name, val, table); |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | wxLogWarning(_("#define %s must be an integer."), name); |
| 1787 | delete[] name; |
| 1788 | delete[] value; |
| 1789 | return FALSE; |
| 1790 | } |
| 1791 | delete[] name; |
| 1792 | delete[] value; |
| 1793 | |
| 1794 | return TRUE; |
| 1795 | } |
| 1796 | else if (strcmp(wxResourceBuffer, "#include") == 0) |
| 1797 | { |
| 1798 | wxGetResourceToken(fd); |
| 1799 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 1800 | wxChar *actualName = name; |
| 1801 | if (name[0] == wxT('"')) |
| 1802 | actualName = name + 1; |
| 1803 | int len = wxStrlen(name); |
| 1804 | if ((len > 0) && (name[len-1] == wxT('"'))) |
| 1805 | name[len-1] = 0; |
| 1806 | if (!wxResourceParseIncludeFile(actualName, table)) |
| 1807 | { |
| 1808 | wxLogWarning(_("Could not find resource include file %s."), actualName); |
| 1809 | } |
| 1810 | delete[] name; |
| 1811 | return TRUE; |
| 1812 | } |
| 1813 | else if (strcmp(wxResourceBuffer, "static") != 0) |
| 1814 | { |
| 1815 | wxChar buf[300]; |
| 1816 | wxStrcpy(buf, _("Found ")); |
| 1817 | wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); |
| 1818 | wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); |
| 1819 | wxLogWarning(buf); |
| 1820 | return FALSE; |
| 1821 | } |
| 1822 | |
| 1823 | // char |
| 1824 | if (!wxGetResourceToken(fd)) |
| 1825 | { |
| 1826 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1827 | *eof = TRUE; |
| 1828 | return FALSE; |
| 1829 | } |
| 1830 | |
| 1831 | if (strcmp(wxResourceBuffer, "char") != 0) |
| 1832 | { |
| 1833 | wxLogWarning(_("Expected 'char' whilst parsing resource.")); |
| 1834 | return FALSE; |
| 1835 | } |
| 1836 | |
| 1837 | // *name |
| 1838 | if (!wxGetResourceToken(fd)) |
| 1839 | { |
| 1840 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1841 | *eof = TRUE; |
| 1842 | return FALSE; |
| 1843 | } |
| 1844 | |
| 1845 | if (wxResourceBuffer[0] != '*') |
| 1846 | { |
| 1847 | wxLogWarning(_("Expected '*' whilst parsing resource.")); |
| 1848 | return FALSE; |
| 1849 | } |
| 1850 | wxChar nameBuf[100]; |
| 1851 | wxMB2WX(nameBuf, wxResourceBuffer+1, 99); |
| 1852 | nameBuf[99] = 0; |
| 1853 | |
| 1854 | // = |
| 1855 | if (!wxGetResourceToken(fd)) |
| 1856 | { |
| 1857 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1858 | *eof = TRUE; |
| 1859 | return FALSE; |
| 1860 | } |
| 1861 | |
| 1862 | if (strcmp(wxResourceBuffer, "=") != 0) |
| 1863 | { |
| 1864 | wxLogWarning(_("Expected '=' whilst parsing resource.")); |
| 1865 | return FALSE; |
| 1866 | } |
| 1867 | |
| 1868 | // String |
| 1869 | if (!wxGetResourceToken(fd)) |
| 1870 | { |
| 1871 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1872 | *eof = TRUE; |
| 1873 | return FALSE; |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | if (!db.ReadPrologFromString(wxResourceBuffer)) |
| 1878 | { |
| 1879 | wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); |
| 1880 | return FALSE; |
| 1881 | } |
| 1882 | } |
| 1883 | // Semicolon |
| 1884 | if (!wxGetResourceToken(fd)) |
| 1885 | { |
| 1886 | *eof = TRUE; |
| 1887 | } |
| 1888 | return TRUE; |
| 1889 | } |
| 1890 | |
| 1891 | bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) |
| 1892 | { |
| 1893 | if (!table) |
| 1894 | table = wxDefaultResourceTable; |
| 1895 | |
| 1896 | // static or #define |
| 1897 | if (!wxGetResourceToken(fd)) |
| 1898 | { |
| 1899 | *eof = TRUE; |
| 1900 | return FALSE; |
| 1901 | } |
| 1902 | |
| 1903 | if (strcmp(wxResourceBuffer, "#define") == 0) |
| 1904 | { |
| 1905 | wxGetResourceToken(fd); |
| 1906 | wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); |
| 1907 | wxGetResourceToken(fd); |
| 1908 | wxChar *value = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); |
| 1909 | if (wxIsalpha(value[0])) |
| 1910 | { |
| 1911 | int val = (int)wxAtol(value); |
| 1912 | wxResourceAddIdentifier(name, val, table); |
| 1913 | } |
| 1914 | else |
| 1915 | { |
| 1916 | wxLogWarning(_("#define %s must be an integer."), name); |
| 1917 | delete[] name; |
| 1918 | delete[] value; |
| 1919 | return FALSE; |
| 1920 | } |
| 1921 | delete[] name; |
| 1922 | delete[] value; |
| 1923 | |
| 1924 | return TRUE; |
| 1925 | } |
| 1926 | else if (strcmp(wxResourceBuffer, "#include") == 0) |
| 1927 | { |
| 1928 | wxGetResourceToken(fd); |
| 1929 | wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); |
| 1930 | wxChar *actualName = name; |
| 1931 | if (name[0] == wxT('"')) |
| 1932 | actualName = name + 1; |
| 1933 | int len = wxStrlen(name); |
| 1934 | if ((len > 0) && (name[len-1] == wxT('"'))) |
| 1935 | name[len-1] = 0; |
| 1936 | if (!wxResourceParseIncludeFile(actualName, table)) |
| 1937 | { |
| 1938 | wxLogWarning(_("Could not find resource include file %s."), actualName); |
| 1939 | } |
| 1940 | delete[] name; |
| 1941 | return TRUE; |
| 1942 | } |
| 1943 | else if (strcmp(wxResourceBuffer, "static") != 0) |
| 1944 | { |
| 1945 | wxChar buf[300]; |
| 1946 | wxStrcpy(buf, _("Found ")); |
| 1947 | wxStrncat(buf, wxConvLibc.cMB2WX(wxResourceBuffer), 30); |
| 1948 | wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); |
| 1949 | wxLogWarning(buf); |
| 1950 | return FALSE; |
| 1951 | } |
| 1952 | |
| 1953 | // char |
| 1954 | if (!wxGetResourceToken(fd)) |
| 1955 | { |
| 1956 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1957 | *eof = TRUE; |
| 1958 | return FALSE; |
| 1959 | } |
| 1960 | |
| 1961 | if (strcmp(wxResourceBuffer, "char") != 0) |
| 1962 | { |
| 1963 | wxLogWarning(_("Expected 'char' whilst parsing resource.")); |
| 1964 | return FALSE; |
| 1965 | } |
| 1966 | |
| 1967 | // *name |
| 1968 | if (!wxGetResourceToken(fd)) |
| 1969 | { |
| 1970 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1971 | *eof = TRUE; |
| 1972 | return FALSE; |
| 1973 | } |
| 1974 | |
| 1975 | if (wxResourceBuffer[0] != '*') |
| 1976 | { |
| 1977 | wxLogWarning(_("Expected '*' whilst parsing resource.")); |
| 1978 | return FALSE; |
| 1979 | } |
| 1980 | char nameBuf[100]; |
| 1981 | strncpy(nameBuf, wxResourceBuffer+1, 99); |
| 1982 | |
| 1983 | // = |
| 1984 | if (!wxGetResourceToken(fd)) |
| 1985 | { |
| 1986 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 1987 | *eof = TRUE; |
| 1988 | return FALSE; |
| 1989 | } |
| 1990 | |
| 1991 | if (strcmp(wxResourceBuffer, "=") != 0) |
| 1992 | { |
| 1993 | wxLogWarning(_("Expected '=' whilst parsing resource.")); |
| 1994 | return FALSE; |
| 1995 | } |
| 1996 | |
| 1997 | // String |
| 1998 | if (!wxGetResourceToken(fd)) |
| 1999 | { |
| 2000 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 2001 | *eof = TRUE; |
| 2002 | return FALSE; |
| 2003 | } |
| 2004 | else |
| 2005 | { |
| 2006 | if (!db.ReadPrologFromString(wxResourceBuffer)) |
| 2007 | { |
| 2008 | wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); |
| 2009 | return FALSE; |
| 2010 | } |
| 2011 | } |
| 2012 | // Semicolon |
| 2013 | if (!wxGetResourceToken(fd)) |
| 2014 | { |
| 2015 | *eof = TRUE; |
| 2016 | } |
| 2017 | return TRUE; |
| 2018 | } |
| 2019 | |
| 2020 | /* |
| 2021 | * Parses string window style into integer window style |
| 2022 | */ |
| 2023 | |
| 2024 | /* |
| 2025 | * Style flag parsing, e.g. |
| 2026 | * "wxSYSTEM_MENU | wxBORDER" -> integer |
| 2027 | */ |
| 2028 | |
| 2029 | wxChar* wxResourceParseWord(wxChar*s, int *i) |
| 2030 | { |
| 2031 | if (!s) |
| 2032 | return (wxChar*) NULL; |
| 2033 | |
| 2034 | static wxChar buf[150]; |
| 2035 | int len = wxStrlen(s); |
| 2036 | int j = 0; |
| 2037 | int ii = *i; |
| 2038 | while ((ii < len) && (wxIsalpha(s[ii]) || (s[ii] == wxT('_')))) |
| 2039 | { |
| 2040 | buf[j] = s[ii]; |
| 2041 | j ++; |
| 2042 | ii ++; |
| 2043 | } |
| 2044 | buf[j] = 0; |
| 2045 | |
| 2046 | // Eat whitespace and conjunction characters |
| 2047 | while ((ii < len) && |
| 2048 | ((s[ii] == wxT(' ')) || (s[ii] == wxT('|')) || (s[ii] == wxT(',')))) |
| 2049 | { |
| 2050 | ii ++; |
| 2051 | } |
| 2052 | *i = ii; |
| 2053 | if (j == 0) |
| 2054 | return (wxChar*) NULL; |
| 2055 | else |
| 2056 | return buf; |
| 2057 | } |
| 2058 | |
| 2059 | struct wxResourceBitListStruct |
| 2060 | { |
| 2061 | const wxChar *word; |
| 2062 | long bits; |
| 2063 | }; |
| 2064 | |
| 2065 | static wxResourceBitListStruct wxResourceBitListTable[] = |
| 2066 | { |
| 2067 | /* wxListBox */ |
| 2068 | { wxT("wxSINGLE"), wxLB_SINGLE }, |
| 2069 | { wxT("wxMULTIPLE"), wxLB_MULTIPLE }, |
| 2070 | { wxT("wxEXTENDED"), wxLB_EXTENDED }, |
| 2071 | { wxT("wxLB_SINGLE"), wxLB_SINGLE }, |
| 2072 | { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE }, |
| 2073 | { wxT("wxLB_EXTENDED"), wxLB_EXTENDED }, |
| 2074 | { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB }, |
| 2075 | { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB }, |
| 2076 | { wxT("wxLB_SORT"), wxLB_SORT }, |
| 2077 | { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW }, |
| 2078 | { wxT("wxLB_HSCROLL"), wxLB_HSCROLL }, |
| 2079 | |
| 2080 | /* wxComboxBox */ |
| 2081 | { wxT("wxCB_SIMPLE"), wxCB_SIMPLE }, |
| 2082 | { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN }, |
| 2083 | { wxT("wxCB_READONLY"), wxCB_READONLY }, |
| 2084 | { wxT("wxCB_SORT"), wxCB_SORT }, |
| 2085 | |
| 2086 | /* wxGauge */ |
| 2087 | { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR }, |
| 2088 | { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL }, |
| 2089 | { wxT("wxGA_VERTICAL"), wxGA_VERTICAL }, |
| 2090 | |
| 2091 | /* wxTextCtrl */ |
| 2092 | { wxT("wxPASSWORD"), wxPASSWORD}, |
| 2093 | { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER}, |
| 2094 | { wxT("wxTE_PASSWORD"), wxTE_PASSWORD}, |
| 2095 | { wxT("wxTE_READONLY"), wxTE_READONLY}, |
| 2096 | { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER}, |
| 2097 | { wxT("wxTE_MULTILINE"), wxTE_MULTILINE}, |
| 2098 | { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL}, |
| 2099 | |
| 2100 | /* wxRadioBox/wxRadioButton */ |
| 2101 | { wxT("wxRB_GROUP"), wxRB_GROUP }, |
| 2102 | { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS }, |
| 2103 | { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS }, |
| 2104 | { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL }, |
| 2105 | { wxT("wxRA_VERTICAL"), wxRA_VERTICAL }, |
| 2106 | |
| 2107 | /* wxSlider */ |
| 2108 | { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL }, |
| 2109 | { wxT("wxSL_VERTICAL"), wxSL_VERTICAL }, |
| 2110 | { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS }, |
| 2111 | { wxT("wxSL_LABELS"), wxSL_LABELS }, |
| 2112 | { wxT("wxSL_LEFT"), wxSL_LEFT }, |
| 2113 | { wxT("wxSL_TOP"), wxSL_TOP }, |
| 2114 | { wxT("wxSL_RIGHT"), wxSL_RIGHT }, |
| 2115 | { wxT("wxSL_BOTTOM"), wxSL_BOTTOM }, |
| 2116 | { wxT("wxSL_BOTH"), wxSL_BOTH }, |
| 2117 | { wxT("wxSL_SELRANGE"), wxSL_SELRANGE }, |
| 2118 | |
| 2119 | /* wxScrollBar */ |
| 2120 | { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL }, |
| 2121 | { wxT("wxSB_VERTICAL"), wxSB_VERTICAL }, |
| 2122 | |
| 2123 | /* wxButton */ |
| 2124 | { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW }, |
| 2125 | { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW }, |
| 2126 | |
| 2127 | /* wxTreeCtrl */ |
| 2128 | { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS }, |
| 2129 | { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS }, |
| 2130 | { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT }, |
| 2131 | |
| 2132 | /* wxListCtrl */ |
| 2133 | { wxT("wxLC_ICON"), wxLC_ICON }, |
| 2134 | { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON }, |
| 2135 | { wxT("wxLC_LIST"), wxLC_LIST }, |
| 2136 | { wxT("wxLC_REPORT"), wxLC_REPORT }, |
| 2137 | { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP }, |
| 2138 | { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT }, |
| 2139 | { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE }, |
| 2140 | { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT }, |
| 2141 | { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS }, |
| 2142 | { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER }, |
| 2143 | { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER }, |
| 2144 | { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL }, |
| 2145 | { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING }, |
| 2146 | { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING }, |
| 2147 | |
| 2148 | /* wxSpinButton */ |
| 2149 | { wxT("wxSP_VERTICAL"), wxSP_VERTICAL}, |
| 2150 | { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL}, |
| 2151 | { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS}, |
| 2152 | { wxT("wxSP_WRAP"), wxSP_WRAP}, |
| 2153 | |
| 2154 | /* wxSplitterWnd */ |
| 2155 | { wxT("wxSP_NOBORDER"), wxSP_NOBORDER}, |
| 2156 | { wxT("wxSP_3D"), wxSP_3D}, |
| 2157 | { wxT("wxSP_BORDER"), wxSP_BORDER}, |
| 2158 | |
| 2159 | /* wxTabCtrl */ |
| 2160 | { wxT("wxTC_MULTILINE"), wxTC_MULTILINE}, |
| 2161 | { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY}, |
| 2162 | { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH}, |
| 2163 | { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW}, |
| 2164 | |
| 2165 | /* wxStatusBar95 */ |
| 2166 | { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP}, |
| 2167 | |
| 2168 | /* wxControl */ |
| 2169 | { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH}, |
| 2170 | { wxT("wxALIGN_LEFT"), wxALIGN_LEFT}, |
| 2171 | { wxT("wxALIGN_CENTER"), wxALIGN_CENTER}, |
| 2172 | { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE}, |
| 2173 | { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT}, |
| 2174 | { wxT("wxCOLOURED"), wxCOLOURED}, |
| 2175 | |
| 2176 | /* wxToolBar */ |
| 2177 | { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS}, |
| 2178 | { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL}, |
| 2179 | { wxT("wxTB_VERTICAL"), wxTB_VERTICAL}, |
| 2180 | { wxT("wxTB_FLAT"), wxTB_FLAT}, |
| 2181 | |
| 2182 | /* wxDialog */ |
| 2183 | { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL }, |
| 2184 | |
| 2185 | /* Generic */ |
| 2186 | { wxT("wxVSCROLL"), wxVSCROLL }, |
| 2187 | { wxT("wxHSCROLL"), wxHSCROLL }, |
| 2188 | { wxT("wxCAPTION"), wxCAPTION }, |
| 2189 | { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP}, |
| 2190 | { wxT("wxICONIZE"), wxICONIZE}, |
| 2191 | { wxT("wxMINIMIZE"), wxICONIZE}, |
| 2192 | { wxT("wxMAXIMIZE"), wxMAXIMIZE}, |
| 2193 | { wxT("wxSDI"), 0}, |
| 2194 | { wxT("wxMDI_PARENT"), 0}, |
| 2195 | { wxT("wxMDI_CHILD"), 0}, |
| 2196 | { wxT("wxTHICK_FRAME"), wxTHICK_FRAME}, |
| 2197 | { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER}, |
| 2198 | { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU}, |
| 2199 | { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX}, |
| 2200 | { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX}, |
| 2201 | { wxT("wxRESIZE_BOX"), wxRESIZE_BOX}, |
| 2202 | { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE}, |
| 2203 | { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE}, |
| 2204 | { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE}, |
| 2205 | { wxT("wxBORDER"), wxBORDER}, |
| 2206 | { wxT("wxRETAINED"), wxRETAINED}, |
| 2207 | { wxT("wxNATIVE_IMPL"), 0}, |
| 2208 | { wxT("wxEXTENDED_IMPL"), 0}, |
| 2209 | { wxT("wxBACKINGSTORE"), wxBACKINGSTORE}, |
| 2210 | // { wxT("wxFLAT"), wxFLAT}, |
| 2211 | // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE}, |
| 2212 | { wxT("wxFIXED_LENGTH"), 0}, |
| 2213 | { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER}, |
| 2214 | { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER}, |
| 2215 | { wxT("wxRAISED_BORDER"), wxRAISED_BORDER}, |
| 2216 | { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER}, |
| 2217 | { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER}, |
| 2218 | { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW}, |
| 2219 | { wxT("wxNO_BORDER"), wxNO_BORDER}, |
| 2220 | { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN}, |
| 2221 | { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS}, |
| 2222 | { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only |
| 2223 | |
| 2224 | { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ}, |
| 2225 | { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT}, |
| 2226 | |
| 2227 | // Text font families |
| 2228 | { wxT("wxDEFAULT"), wxDEFAULT}, |
| 2229 | { wxT("wxDECORATIVE"), wxDECORATIVE}, |
| 2230 | { wxT("wxROMAN"), wxROMAN}, |
| 2231 | { wxT("wxSCRIPT"), wxSCRIPT}, |
| 2232 | { wxT("wxSWISS"), wxSWISS}, |
| 2233 | { wxT("wxMODERN"), wxMODERN}, |
| 2234 | { wxT("wxTELETYPE"), wxTELETYPE}, |
| 2235 | { wxT("wxVARIABLE"), wxVARIABLE}, |
| 2236 | { wxT("wxFIXED"), wxFIXED}, |
| 2237 | { wxT("wxNORMAL"), wxNORMAL}, |
| 2238 | { wxT("wxLIGHT"), wxLIGHT}, |
| 2239 | { wxT("wxBOLD"), wxBOLD}, |
| 2240 | { wxT("wxITALIC"), wxITALIC}, |
| 2241 | { wxT("wxSLANT"), wxSLANT}, |
| 2242 | { wxT("wxSOLID"), wxSOLID}, |
| 2243 | { wxT("wxDOT"), wxDOT}, |
| 2244 | { wxT("wxLONG_DASH"), wxLONG_DASH}, |
| 2245 | { wxT("wxSHORT_DASH"), wxSHORT_DASH}, |
| 2246 | { wxT("wxDOT_DASH"), wxDOT_DASH}, |
| 2247 | { wxT("wxUSER_DASH"), wxUSER_DASH}, |
| 2248 | { wxT("wxTRANSPARENT"), wxTRANSPARENT}, |
| 2249 | { wxT("wxSTIPPLE"), wxSTIPPLE}, |
| 2250 | { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH}, |
| 2251 | { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH}, |
| 2252 | { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH}, |
| 2253 | { wxT("wxCROSS_HATCH"), wxCROSS_HATCH}, |
| 2254 | { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH}, |
| 2255 | { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH}, |
| 2256 | { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL}, |
| 2257 | { wxT("wxJOIN_MITER"), wxJOIN_MITER}, |
| 2258 | { wxT("wxJOIN_ROUND"), wxJOIN_ROUND}, |
| 2259 | { wxT("wxCAP_ROUND"), wxCAP_ROUND}, |
| 2260 | { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING}, |
| 2261 | { wxT("wxCAP_BUTT"), wxCAP_BUTT}, |
| 2262 | |
| 2263 | // Logical ops |
| 2264 | { wxT("wxCLEAR"), wxCLEAR}, |
| 2265 | { wxT("wxXOR"), wxXOR}, |
| 2266 | { wxT("wxINVERT"), wxINVERT}, |
| 2267 | { wxT("wxOR_REVERSE"), wxOR_REVERSE}, |
| 2268 | { wxT("wxAND_REVERSE"), wxAND_REVERSE}, |
| 2269 | { wxT("wxCOPY"), wxCOPY}, |
| 2270 | { wxT("wxAND"), wxAND}, |
| 2271 | { wxT("wxAND_INVERT"), wxAND_INVERT}, |
| 2272 | { wxT("wxNO_OP"), wxNO_OP}, |
| 2273 | { wxT("wxNOR"), wxNOR}, |
| 2274 | { wxT("wxEQUIV"), wxEQUIV}, |
| 2275 | { wxT("wxSRC_INVERT"), wxSRC_INVERT}, |
| 2276 | { wxT("wxOR_INVERT"), wxOR_INVERT}, |
| 2277 | { wxT("wxNAND"), wxNAND}, |
| 2278 | { wxT("wxOR"), wxOR}, |
| 2279 | { wxT("wxSET"), wxSET}, |
| 2280 | |
| 2281 | { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE}, |
| 2282 | { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER}, |
| 2283 | { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE}, |
| 2284 | { wxT("wxWINDING_RULE"), wxWINDING_RULE}, |
| 2285 | { wxT("wxHORIZONTAL"), wxHORIZONTAL}, |
| 2286 | { wxT("wxVERTICAL"), wxVERTICAL}, |
| 2287 | { wxT("wxBOTH"), wxBOTH}, |
| 2288 | { wxT("wxCENTER_FRAME"), wxCENTER_FRAME}, |
| 2289 | { wxT("wxOK"), wxOK}, |
| 2290 | { wxT("wxYES_NO"), wxYES_NO}, |
| 2291 | { wxT("wxCANCEL"), wxCANCEL}, |
| 2292 | { wxT("wxYES"), wxYES}, |
| 2293 | { wxT("wxNO"), wxNO}, |
| 2294 | { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION}, |
| 2295 | { wxT("wxICON_HAND"), wxICON_HAND}, |
| 2296 | { wxT("wxICON_QUESTION"), wxICON_QUESTION}, |
| 2297 | { wxT("wxICON_INFORMATION"), wxICON_INFORMATION}, |
| 2298 | { wxT("wxICON_STOP"), wxICON_STOP}, |
| 2299 | { wxT("wxICON_ASTERISK"), wxICON_ASTERISK}, |
| 2300 | { wxT("wxICON_MASK"), wxICON_MASK}, |
| 2301 | { wxT("wxCENTRE"), wxCENTRE}, |
| 2302 | { wxT("wxCENTER"), wxCENTRE}, |
| 2303 | { wxT("wxUSER_COLOURS"), wxUSER_COLOURS}, |
| 2304 | { wxT("wxVERTICAL_LABEL"), 0}, |
| 2305 | { wxT("wxHORIZONTAL_LABEL"), 0}, |
| 2306 | |
| 2307 | // Bitmap types (not strictly styles) |
| 2308 | { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM}, |
| 2309 | { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM}, |
| 2310 | { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP}, |
| 2311 | { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE}, |
| 2312 | { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE}, |
| 2313 | { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF}, |
| 2314 | { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF}, |
| 2315 | { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO}, |
| 2316 | { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE}, |
| 2317 | { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR}, |
| 2318 | { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE}, |
| 2319 | { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA}, |
| 2320 | { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA}, |
| 2321 | { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY} |
| 2322 | }; |
| 2323 | |
| 2324 | static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct)); |
| 2325 | |
| 2326 | long wxParseWindowStyle(const wxString& bitListString) |
| 2327 | { |
| 2328 | int i = 0; |
| 2329 | wxChar *word; |
| 2330 | long bitList = 0; |
| 2331 | word = wxResourceParseWord(WXSTRINGCAST bitListString, &i); |
| 2332 | while (word != NULL) |
| 2333 | { |
| 2334 | bool found = FALSE; |
| 2335 | int j; |
| 2336 | for (j = 0; j < wxResourceBitListCount; j++) |
| 2337 | if (wxStrcmp(wxResourceBitListTable[j].word, word) == 0) |
| 2338 | { |
| 2339 | bitList |= wxResourceBitListTable[j].bits; |
| 2340 | found = TRUE; |
| 2341 | break; |
| 2342 | } |
| 2343 | if (!found) |
| 2344 | { |
| 2345 | wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word); |
| 2346 | return 0; |
| 2347 | } |
| 2348 | word = wxResourceParseWord(WXSTRINGCAST bitListString, &i); |
| 2349 | } |
| 2350 | return bitList; |
| 2351 | } |
| 2352 | |
| 2353 | /* |
| 2354 | * Load a bitmap from a wxWindows resource, choosing an optimum |
| 2355 | * depth and appropriate type. |
| 2356 | */ |
| 2357 | |
| 2358 | wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table) |
| 2359 | { |
| 2360 | if (!table) |
| 2361 | table = wxDefaultResourceTable; |
| 2362 | |
| 2363 | wxItemResource *item = table->FindResource(resource); |
| 2364 | if (item) |
| 2365 | { |
| 2366 | if ((item->GetType() == wxT("")) || (item->GetType() != wxT("wxBitmap"))) |
| 2367 | { |
| 2368 | wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar*) resource); |
| 2369 | return wxNullBitmap; |
| 2370 | } |
| 2371 | int thisDepth = wxDisplayDepth(); |
| 2372 | long thisNoColours = (long)pow(2.0, (double)thisDepth); |
| 2373 | |
| 2374 | wxItemResource *optResource = (wxItemResource *) NULL; |
| 2375 | |
| 2376 | // Try to find optimum bitmap for this platform/colour depth |
| 2377 | wxNode *node = item->GetChildren().First(); |
| 2378 | while (node) |
| 2379 | { |
| 2380 | wxItemResource *child = (wxItemResource *)node->Data(); |
| 2381 | int platform = (int)child->GetValue2(); |
| 2382 | int noColours = (int)child->GetValue3(); |
| 2383 | /* |
| 2384 | char *name = child->GetName(); |
| 2385 | int bitmapType = (int)child->GetValue1(); |
| 2386 | int xRes = child->GetWidth(); |
| 2387 | int yRes = child->GetHeight(); |
| 2388 | */ |
| 2389 | |
| 2390 | switch (platform) |
| 2391 | { |
| 2392 | case RESOURCE_PLATFORM_ANY: |
| 2393 | { |
| 2394 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2395 | optResource = child; |
| 2396 | else |
| 2397 | { |
| 2398 | // Maximise the number of colours. |
| 2399 | // If noColours is zero (unspecified), then assume this |
| 2400 | // is the right one. |
| 2401 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2402 | optResource = child; |
| 2403 | } |
| 2404 | break; |
| 2405 | } |
| 2406 | #ifdef __WXMSW__ |
| 2407 | case RESOURCE_PLATFORM_WINDOWS: |
| 2408 | { |
| 2409 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2410 | optResource = child; |
| 2411 | else |
| 2412 | { |
| 2413 | // Maximise the number of colours |
| 2414 | if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2415 | optResource = child; |
| 2416 | } |
| 2417 | break; |
| 2418 | } |
| 2419 | #endif |
| 2420 | #ifdef __WXGTK__ |
| 2421 | case RESOURCE_PLATFORM_X: |
| 2422 | { |
| 2423 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2424 | optResource = child; |
| 2425 | else |
| 2426 | { |
| 2427 | // Maximise the number of colours |
| 2428 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2429 | optResource = child; |
| 2430 | } |
| 2431 | break; |
| 2432 | } |
| 2433 | #endif |
| 2434 | #ifdef wx_max |
| 2435 | case RESOURCE_PLATFORM_MAC: |
| 2436 | { |
| 2437 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2438 | optResource = child; |
| 2439 | else |
| 2440 | { |
| 2441 | // Maximise the number of colours |
| 2442 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2443 | optResource = child; |
| 2444 | } |
| 2445 | break; |
| 2446 | } |
| 2447 | #endif |
| 2448 | default: |
| 2449 | break; |
| 2450 | } |
| 2451 | node = node->Next(); |
| 2452 | } |
| 2453 | // If no matching resource, fail. |
| 2454 | if (!optResource) |
| 2455 | return wxNullBitmap; |
| 2456 | |
| 2457 | wxString name = optResource->GetName(); |
| 2458 | int bitmapType = (int)optResource->GetValue1(); |
| 2459 | switch (bitmapType) |
| 2460 | { |
| 2461 | case wxBITMAP_TYPE_XBM_DATA: |
| 2462 | { |
| 2463 | #ifdef __WXGTK__ |
| 2464 | wxItemResource *item = table->FindResource(name); |
| 2465 | if (!item) |
| 2466 | { |
| 2467 | wxLogWarning(_("Failed to find XBM resource %s.\n" |
| 2468 | "Forgot to use wxResourceLoadBitmapData?"), (const wxChar*) name); |
| 2469 | return wxNullBitmap; |
| 2470 | } |
| 2471 | return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ; |
| 2472 | #else |
| 2473 | wxLogWarning(_("No XBM facility available!")); |
| 2474 | break; |
| 2475 | #endif |
| 2476 | } |
| 2477 | case wxBITMAP_TYPE_XPM_DATA: |
| 2478 | { |
| 2479 | wxItemResource *item = table->FindResource(name); |
| 2480 | if (!item) |
| 2481 | { |
| 2482 | wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar*) name); |
| 2483 | return wxNullBitmap; |
| 2484 | } |
| 2485 | return wxBitmap((char **)item->GetValue1()); |
| 2486 | } |
| 2487 | default: |
| 2488 | { |
| 2489 | #if defined(__WXPM__) |
| 2490 | return wxNullBitmap; |
| 2491 | #else |
| 2492 | return wxBitmap(name, (wxBitmapType)bitmapType); |
| 2493 | #endif |
| 2494 | } |
| 2495 | } |
| 2496 | #ifndef __WXGTK__ |
| 2497 | return wxNullBitmap; |
| 2498 | #endif |
| 2499 | } |
| 2500 | else |
| 2501 | { |
| 2502 | wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar*) resource); |
| 2503 | return wxNullBitmap; |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | /* |
| 2508 | * Load an icon from a wxWindows resource, choosing an optimum |
| 2509 | * depth and appropriate type. |
| 2510 | */ |
| 2511 | |
| 2512 | wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) |
| 2513 | { |
| 2514 | if (!table) |
| 2515 | table = wxDefaultResourceTable; |
| 2516 | |
| 2517 | wxItemResource *item = table->FindResource(resource); |
| 2518 | if (item) |
| 2519 | { |
| 2520 | if ((item->GetType() == wxT("")) || wxStrcmp(item->GetType(), wxT("wxIcon")) != 0) |
| 2521 | { |
| 2522 | wxLogWarning(_("%s not an icon resource specification."), (const wxChar*) resource); |
| 2523 | return wxNullIcon; |
| 2524 | } |
| 2525 | int thisDepth = wxDisplayDepth(); |
| 2526 | long thisNoColours = (long)pow(2.0, (double)thisDepth); |
| 2527 | |
| 2528 | wxItemResource *optResource = (wxItemResource *) NULL; |
| 2529 | |
| 2530 | // Try to find optimum icon for this platform/colour depth |
| 2531 | wxNode *node = item->GetChildren().First(); |
| 2532 | while (node) |
| 2533 | { |
| 2534 | wxItemResource *child = (wxItemResource *)node->Data(); |
| 2535 | int platform = (int)child->GetValue2(); |
| 2536 | int noColours = (int)child->GetValue3(); |
| 2537 | /* |
| 2538 | char *name = child->GetName(); |
| 2539 | int bitmapType = (int)child->GetValue1(); |
| 2540 | int xRes = child->GetWidth(); |
| 2541 | int yRes = child->GetHeight(); |
| 2542 | */ |
| 2543 | |
| 2544 | switch (platform) |
| 2545 | { |
| 2546 | case RESOURCE_PLATFORM_ANY: |
| 2547 | { |
| 2548 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2549 | optResource = child; |
| 2550 | else |
| 2551 | { |
| 2552 | // Maximise the number of colours. |
| 2553 | // If noColours is zero (unspecified), then assume this |
| 2554 | // is the right one. |
| 2555 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2556 | optResource = child; |
| 2557 | } |
| 2558 | break; |
| 2559 | } |
| 2560 | #ifdef __WXMSW__ |
| 2561 | case RESOURCE_PLATFORM_WINDOWS: |
| 2562 | { |
| 2563 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2564 | optResource = child; |
| 2565 | else |
| 2566 | { |
| 2567 | // Maximise the number of colours |
| 2568 | if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2569 | optResource = child; |
| 2570 | } |
| 2571 | break; |
| 2572 | } |
| 2573 | #endif |
| 2574 | #ifdef __WXGTK__ |
| 2575 | case RESOURCE_PLATFORM_X: |
| 2576 | { |
| 2577 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2578 | optResource = child; |
| 2579 | else |
| 2580 | { |
| 2581 | // Maximise the number of colours |
| 2582 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2583 | optResource = child; |
| 2584 | } |
| 2585 | break; |
| 2586 | } |
| 2587 | #endif |
| 2588 | #ifdef wx_max |
| 2589 | case RESOURCE_PLATFORM_MAC: |
| 2590 | { |
| 2591 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) |
| 2592 | optResource = child; |
| 2593 | else |
| 2594 | { |
| 2595 | // Maximise the number of colours |
| 2596 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) |
| 2597 | optResource = child; |
| 2598 | } |
| 2599 | break; |
| 2600 | } |
| 2601 | #endif |
| 2602 | default: |
| 2603 | break; |
| 2604 | } |
| 2605 | node = node->Next(); |
| 2606 | } |
| 2607 | // If no matching resource, fail. |
| 2608 | if (!optResource) |
| 2609 | return wxNullIcon; |
| 2610 | |
| 2611 | wxString name = optResource->GetName(); |
| 2612 | int bitmapType = (int)optResource->GetValue1(); |
| 2613 | switch (bitmapType) |
| 2614 | { |
| 2615 | case wxBITMAP_TYPE_XBM_DATA: |
| 2616 | { |
| 2617 | #ifdef __WXGTK__ |
| 2618 | wxItemResource *item = table->FindResource(name); |
| 2619 | if (!item) |
| 2620 | { |
| 2621 | wxLogWarning(_("Failed to find XBM resource %s.\n" |
| 2622 | "Forgot to use wxResourceLoadIconData?"), (const wxChar*) name); |
| 2623 | return wxNullIcon; |
| 2624 | } |
| 2625 | return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); |
| 2626 | #else |
| 2627 | wxLogWarning(_("No XBM facility available!")); |
| 2628 | break; |
| 2629 | #endif |
| 2630 | } |
| 2631 | case wxBITMAP_TYPE_XPM_DATA: |
| 2632 | { |
| 2633 | // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS *** |
| 2634 | /* |
| 2635 | wxItemResource *item = table->FindResource(name); |
| 2636 | if (!item) |
| 2637 | { |
| 2638 | char buf[400]; |
| 2639 | sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name); |
| 2640 | wxLogWarning(buf); |
| 2641 | return NULL; |
| 2642 | } |
| 2643 | return wxIcon((char **)item->GetValue1()); |
| 2644 | */ |
| 2645 | wxLogWarning(_("No XPM icon facility available!")); |
| 2646 | break; |
| 2647 | } |
| 2648 | default: |
| 2649 | { |
| 2650 | #if defined( __WXGTK__ ) || defined( __WXMOTIF__ ) |
| 2651 | wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); |
| 2652 | break; |
| 2653 | #else |
| 2654 | return wxIcon(name, bitmapType); |
| 2655 | #endif |
| 2656 | } |
| 2657 | } |
| 2658 | return wxNullIcon; |
| 2659 | } |
| 2660 | else |
| 2661 | { |
| 2662 | wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); |
| 2663 | return wxNullIcon; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | #if wxUSE_MENUS |
| 2668 | |
| 2669 | wxMenu *wxResourceCreateMenu(wxItemResource *item) |
| 2670 | { |
| 2671 | wxMenu *menu = new wxMenu; |
| 2672 | wxNode *node = item->GetChildren().First(); |
| 2673 | while (node) |
| 2674 | { |
| 2675 | wxItemResource *child = (wxItemResource *)node->Data(); |
| 2676 | if ((child->GetType() != wxT("")) && (child->GetType() == wxT("wxMenuSeparator"))) |
| 2677 | menu->AppendSeparator(); |
| 2678 | else if (child->GetChildren().Number() > 0) |
| 2679 | { |
| 2680 | wxMenu *subMenu = wxResourceCreateMenu(child); |
| 2681 | if (subMenu) |
| 2682 | menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4()); |
| 2683 | } |
| 2684 | else |
| 2685 | { |
| 2686 | menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0)); |
| 2687 | } |
| 2688 | node = node->Next(); |
| 2689 | } |
| 2690 | return menu; |
| 2691 | } |
| 2692 | |
| 2693 | wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar) |
| 2694 | { |
| 2695 | if (!table) |
| 2696 | table = wxDefaultResourceTable; |
| 2697 | |
| 2698 | wxItemResource *menuResource = table->FindResource(resource); |
| 2699 | if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu"))) |
| 2700 | { |
| 2701 | if (!menuBar) |
| 2702 | menuBar = new wxMenuBar; |
| 2703 | wxNode *node = menuResource->GetChildren().First(); |
| 2704 | while (node) |
| 2705 | { |
| 2706 | wxItemResource *child = (wxItemResource *)node->Data(); |
| 2707 | wxMenu *menu = wxResourceCreateMenu(child); |
| 2708 | if (menu) |
| 2709 | menuBar->Append(menu, child->GetTitle()); |
| 2710 | node = node->Next(); |
| 2711 | } |
| 2712 | return menuBar; |
| 2713 | } |
| 2714 | return (wxMenuBar *) NULL; |
| 2715 | } |
| 2716 | |
| 2717 | wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table) |
| 2718 | { |
| 2719 | if (!table) |
| 2720 | table = wxDefaultResourceTable; |
| 2721 | |
| 2722 | wxItemResource *menuResource = table->FindResource(resource); |
| 2723 | if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu"))) |
| 2724 | // if (menuResource && (menuResource->GetType() == wxTYPE_MENU)) |
| 2725 | return wxResourceCreateMenu(menuResource); |
| 2726 | return (wxMenu *) NULL; |
| 2727 | } |
| 2728 | |
| 2729 | #endif // wxUSE_MENUS |
| 2730 | |
| 2731 | // Global equivalents (so don't have to refer to default table explicitly) |
| 2732 | bool wxResourceParseData(const wxString& resource, wxResourceTable *table) |
| 2733 | { |
| 2734 | if (!table) |
| 2735 | table = wxDefaultResourceTable; |
| 2736 | |
| 2737 | return table->ParseResourceData(resource); |
| 2738 | } |
| 2739 | |
| 2740 | bool wxResourceParseData(const char* resource, wxResourceTable *table) |
| 2741 | { |
| 2742 | wxString str(resource, wxConvLibc); |
| 2743 | if (!table) |
| 2744 | table = wxDefaultResourceTable; |
| 2745 | |
| 2746 | return table->ParseResourceData(str); |
| 2747 | } |
| 2748 | |
| 2749 | bool wxResourceParseFile(const wxString& filename, wxResourceTable *table) |
| 2750 | { |
| 2751 | if (!table) |
| 2752 | table = wxDefaultResourceTable; |
| 2753 | |
| 2754 | return table->ParseResourceFile(filename); |
| 2755 | } |
| 2756 | |
| 2757 | // Register XBM/XPM data |
| 2758 | bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table) |
| 2759 | { |
| 2760 | if (!table) |
| 2761 | table = wxDefaultResourceTable; |
| 2762 | |
| 2763 | return table->RegisterResourceBitmapData(name, bits, width, height); |
| 2764 | } |
| 2765 | |
| 2766 | bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table) |
| 2767 | { |
| 2768 | if (!table) |
| 2769 | table = wxDefaultResourceTable; |
| 2770 | |
| 2771 | return table->RegisterResourceBitmapData(name, data); |
| 2772 | } |
| 2773 | |
| 2774 | void wxResourceClear(wxResourceTable *table) |
| 2775 | { |
| 2776 | if (!table) |
| 2777 | table = wxDefaultResourceTable; |
| 2778 | |
| 2779 | table->ClearTable(); |
| 2780 | } |
| 2781 | |
| 2782 | /* |
| 2783 | * Identifiers |
| 2784 | */ |
| 2785 | |
| 2786 | bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table) |
| 2787 | { |
| 2788 | if (!table) |
| 2789 | table = wxDefaultResourceTable; |
| 2790 | |
| 2791 | table->identifiers.Put(name, (wxObject *)(long)value); |
| 2792 | return TRUE; |
| 2793 | } |
| 2794 | |
| 2795 | int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table) |
| 2796 | { |
| 2797 | if (!table) |
| 2798 | table = wxDefaultResourceTable; |
| 2799 | |
| 2800 | return (int)(long)table->identifiers.Get(name); |
| 2801 | } |
| 2802 | |
| 2803 | /* |
| 2804 | * Parse #include file for #defines (only) |
| 2805 | */ |
| 2806 | |
| 2807 | bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table) |
| 2808 | { |
| 2809 | if (!table) |
| 2810 | table = wxDefaultResourceTable; |
| 2811 | |
| 2812 | FILE *fd = wxFopen(f, wxT("r")); |
| 2813 | if (!fd) |
| 2814 | { |
| 2815 | return FALSE; |
| 2816 | } |
| 2817 | while (wxGetResourceToken(fd)) |
| 2818 | { |
| 2819 | if (strcmp(wxResourceBuffer, "#define") == 0) |
| 2820 | { |
| 2821 | wxGetResourceToken(fd); |
| 2822 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 2823 | wxGetResourceToken(fd); |
| 2824 | wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 2825 | if (wxIsdigit(value[0])) |
| 2826 | { |
| 2827 | int val = (int)wxAtol(value); |
| 2828 | wxResourceAddIdentifier(name, val, table); |
| 2829 | } |
| 2830 | delete[] name; |
| 2831 | delete[] value; |
| 2832 | } |
| 2833 | } |
| 2834 | fclose(fd); |
| 2835 | return TRUE; |
| 2836 | } |
| 2837 | |
| 2838 | /* |
| 2839 | * Reading strings as if they were .wxr files |
| 2840 | */ |
| 2841 | |
| 2842 | static int getc_string(char *s) |
| 2843 | { |
| 2844 | int ch = s[wxResourceStringPtr]; |
| 2845 | if (ch == 0) |
| 2846 | return EOF; |
| 2847 | else |
| 2848 | { |
| 2849 | wxResourceStringPtr ++; |
| 2850 | return ch; |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | static int ungetc_string() |
| 2855 | { |
| 2856 | wxResourceStringPtr --; |
| 2857 | return 0; |
| 2858 | } |
| 2859 | |
| 2860 | bool wxEatWhiteSpaceString(char *s) |
| 2861 | { |
| 2862 | int ch = 0; |
| 2863 | |
| 2864 | while ((ch = getc_string(s)) != EOF) |
| 2865 | { |
| 2866 | switch (ch) |
| 2867 | { |
| 2868 | case ' ': |
| 2869 | case 0x0a: |
| 2870 | case 0x0d: |
| 2871 | case 0x09: |
| 2872 | break; |
| 2873 | case '/': |
| 2874 | { |
| 2875 | int prev_ch = ch; |
| 2876 | ch = getc_string(s); |
| 2877 | if (ch == EOF) |
| 2878 | { |
| 2879 | ungetc_string(); |
| 2880 | return TRUE; |
| 2881 | } |
| 2882 | |
| 2883 | if (ch == '*') |
| 2884 | { |
| 2885 | // Eat C comment |
| 2886 | prev_ch = 0; |
| 2887 | while ((ch = getc_string(s)) != EOF) |
| 2888 | { |
| 2889 | if (ch == '/' && prev_ch == '*') |
| 2890 | break; |
| 2891 | prev_ch = ch; |
| 2892 | } |
| 2893 | } |
| 2894 | else |
| 2895 | { |
| 2896 | ungetc_string(); |
| 2897 | ungetc_string(); |
| 2898 | return TRUE; |
| 2899 | } |
| 2900 | } |
| 2901 | break; |
| 2902 | default: |
| 2903 | ungetc_string(); |
| 2904 | return TRUE; |
| 2905 | |
| 2906 | } |
| 2907 | } |
| 2908 | return FALSE; |
| 2909 | } |
| 2910 | |
| 2911 | bool wxGetResourceTokenString(char *s) |
| 2912 | { |
| 2913 | if (!wxResourceBuffer) |
| 2914 | wxReallocateResourceBuffer(); |
| 2915 | wxResourceBuffer[0] = 0; |
| 2916 | wxEatWhiteSpaceString(s); |
| 2917 | |
| 2918 | int ch = getc_string(s); |
| 2919 | if (ch == '"') |
| 2920 | { |
| 2921 | // Get string |
| 2922 | wxResourceBufferCount = 0; |
| 2923 | ch = getc_string(s); |
| 2924 | while (ch != '"') |
| 2925 | { |
| 2926 | int actualCh = ch; |
| 2927 | if (ch == EOF) |
| 2928 | { |
| 2929 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 2930 | return FALSE; |
| 2931 | } |
| 2932 | // Escaped characters |
| 2933 | else if (ch == '\\') |
| 2934 | { |
| 2935 | int newCh = getc_string(s); |
| 2936 | if (newCh == '"') |
| 2937 | actualCh = '"'; |
| 2938 | else if (newCh == 10) |
| 2939 | actualCh = 10; |
| 2940 | else |
| 2941 | { |
| 2942 | ungetc_string(); |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | if (wxResourceBufferCount >= wxResourceBufferSize-1) |
| 2947 | wxReallocateResourceBuffer(); |
| 2948 | wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; |
| 2949 | wxResourceBufferCount ++; |
| 2950 | ch = getc_string(s); |
| 2951 | } |
| 2952 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 2953 | } |
| 2954 | else |
| 2955 | { |
| 2956 | wxResourceBufferCount = 0; |
| 2957 | // Any other token |
| 2958 | while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) |
| 2959 | { |
| 2960 | if (wxResourceBufferCount >= wxResourceBufferSize-1) |
| 2961 | wxReallocateResourceBuffer(); |
| 2962 | wxResourceBuffer[wxResourceBufferCount] = (char)ch; |
| 2963 | wxResourceBufferCount ++; |
| 2964 | |
| 2965 | ch = getc_string(s); |
| 2966 | } |
| 2967 | wxResourceBuffer[wxResourceBufferCount] = 0; |
| 2968 | if (ch == EOF) |
| 2969 | return FALSE; |
| 2970 | } |
| 2971 | return TRUE; |
| 2972 | } |
| 2973 | |
| 2974 | /* |
| 2975 | * Files are in form: |
| 2976 | static char *name = "...."; |
| 2977 | with possible comments. |
| 2978 | */ |
| 2979 | |
| 2980 | bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table) |
| 2981 | { |
| 2982 | if (!table) |
| 2983 | table = wxDefaultResourceTable; |
| 2984 | |
| 2985 | // static or #define |
| 2986 | if (!wxGetResourceTokenString(s)) |
| 2987 | { |
| 2988 | *eof = TRUE; |
| 2989 | return FALSE; |
| 2990 | } |
| 2991 | |
| 2992 | if (strcmp(wxResourceBuffer, "#define") == 0) |
| 2993 | { |
| 2994 | wxGetResourceTokenString(s); |
| 2995 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 2996 | wxGetResourceTokenString(s); |
| 2997 | wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); |
| 2998 | if (wxIsdigit(value[0])) |
| 2999 | { |
| 3000 | int val = (int)wxAtol(value); |
| 3001 | wxResourceAddIdentifier(name, val, table); |
| 3002 | } |
| 3003 | else |
| 3004 | { |
| 3005 | wxLogWarning(_("#define %s must be an integer."), name); |
| 3006 | delete[] name; |
| 3007 | delete[] value; |
| 3008 | return FALSE; |
| 3009 | } |
| 3010 | delete[] name; |
| 3011 | delete[] value; |
| 3012 | |
| 3013 | return TRUE; |
| 3014 | } |
| 3015 | /* |
| 3016 | else if (strcmp(wxResourceBuffer, "#include") == 0) |
| 3017 | { |
| 3018 | wxGetResourceTokenString(s); |
| 3019 | char *name = copystring(wxResourceBuffer); |
| 3020 | char *actualName = name; |
| 3021 | if (name[0] == '"') |
| 3022 | actualName = name + 1; |
| 3023 | int len = strlen(name); |
| 3024 | if ((len > 0) && (name[len-1] == '"')) |
| 3025 | name[len-1] = 0; |
| 3026 | if (!wxResourceParseIncludeFile(actualName, table)) |
| 3027 | { |
| 3028 | char buf[400]; |
| 3029 | sprintf(buf, _("Could not find resource include file %s."), actualName); |
| 3030 | wxLogWarning(buf); |
| 3031 | } |
| 3032 | delete[] name; |
| 3033 | return TRUE; |
| 3034 | } |
| 3035 | */ |
| 3036 | else if (strcmp(wxResourceBuffer, "static") != 0) |
| 3037 | { |
| 3038 | wxChar buf[300]; |
| 3039 | wxStrcpy(buf, _("Found ")); |
| 3040 | wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); |
| 3041 | wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); |
| 3042 | wxLogWarning(buf); |
| 3043 | return FALSE; |
| 3044 | } |
| 3045 | |
| 3046 | // char |
| 3047 | if (!wxGetResourceTokenString(s)) |
| 3048 | { |
| 3049 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 3050 | *eof = TRUE; |
| 3051 | return FALSE; |
| 3052 | } |
| 3053 | |
| 3054 | if (strcmp(wxResourceBuffer, "char") != 0) |
| 3055 | { |
| 3056 | wxLogWarning(_("Expected 'char' whilst parsing resource.")); |
| 3057 | return FALSE; |
| 3058 | } |
| 3059 | |
| 3060 | // *name |
| 3061 | if (!wxGetResourceTokenString(s)) |
| 3062 | { |
| 3063 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 3064 | *eof = TRUE; |
| 3065 | return FALSE; |
| 3066 | } |
| 3067 | |
| 3068 | if (wxResourceBuffer[0] != '*') |
| 3069 | { |
| 3070 | wxLogWarning(_("Expected '*' whilst parsing resource.")); |
| 3071 | return FALSE; |
| 3072 | } |
| 3073 | wxChar nameBuf[100]; |
| 3074 | wxMB2WX(nameBuf, wxResourceBuffer+1, 99); |
| 3075 | nameBuf[99] = 0; |
| 3076 | |
| 3077 | // = |
| 3078 | if (!wxGetResourceTokenString(s)) |
| 3079 | { |
| 3080 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 3081 | *eof = TRUE; |
| 3082 | return FALSE; |
| 3083 | } |
| 3084 | |
| 3085 | if (strcmp(wxResourceBuffer, "=") != 0) |
| 3086 | { |
| 3087 | wxLogWarning(_("Expected '=' whilst parsing resource.")); |
| 3088 | return FALSE; |
| 3089 | } |
| 3090 | |
| 3091 | // String |
| 3092 | if (!wxGetResourceTokenString(s)) |
| 3093 | { |
| 3094 | wxLogWarning(_("Unexpected end of file whilst parsing resource.")); |
| 3095 | *eof = TRUE; |
| 3096 | return FALSE; |
| 3097 | } |
| 3098 | else |
| 3099 | { |
| 3100 | if (!db.ReadPrologFromString(wxResourceBuffer)) |
| 3101 | { |
| 3102 | wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); |
| 3103 | return FALSE; |
| 3104 | } |
| 3105 | } |
| 3106 | // Semicolon |
| 3107 | if (!wxGetResourceTokenString(s)) |
| 3108 | { |
| 3109 | *eof = TRUE; |
| 3110 | } |
| 3111 | return TRUE; |
| 3112 | } |
| 3113 | |
| 3114 | bool wxResourceParseString(const wxString& s, wxResourceTable *table) |
| 3115 | { |
| 3116 | #if wxUSE_UNICODE |
| 3117 | return wxResourceParseString( (char*)s.mb_str().data() ); |
| 3118 | #else |
| 3119 | return wxResourceParseString( (char*)s.c_str() ); |
| 3120 | #endif |
| 3121 | } |
| 3122 | |
| 3123 | bool wxResourceParseString(char *s, wxResourceTable *table) |
| 3124 | { |
| 3125 | if (!table) |
| 3126 | table = wxDefaultResourceTable; |
| 3127 | |
| 3128 | if (!s) |
| 3129 | return FALSE; |
| 3130 | |
| 3131 | // Turn backslashes into spaces |
| 3132 | if (s) |
| 3133 | { |
| 3134 | int len = strlen(s); |
| 3135 | int i; |
| 3136 | for (i = 0; i < len; i++) |
| 3137 | if (s[i] == 92 && s[i+1] == 13) |
| 3138 | { |
| 3139 | s[i] = ' '; |
| 3140 | s[i+1] = ' '; |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | wxExprDatabase db; |
| 3145 | wxResourceStringPtr = 0; |
| 3146 | |
| 3147 | bool eof = FALSE; |
| 3148 | while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof) |
| 3149 | { |
| 3150 | // Loop |
| 3151 | } |
| 3152 | return wxResourceInterpretResources(*table, db); |
| 3153 | } |
| 3154 | |
| 3155 | /* |
| 3156 | * resource loading facility |
| 3157 | */ |
| 3158 | |
| 3159 | bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table) |
| 3160 | { |
| 3161 | if (!table) |
| 3162 | table = wxDefaultResourceTable; |
| 3163 | |
| 3164 | wxItemResource *resource = table->FindResource((const wxChar *)resourceName); |
| 3165 | // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX)) |
| 3166 | if (!resource || (resource->GetType() == wxT("")) || |
| 3167 | ! ((resource->GetType() == wxT("wxDialog")) || (resource->GetType() == wxT("wxPanel")))) |
| 3168 | return FALSE; |
| 3169 | |
| 3170 | wxString title(resource->GetTitle()); |
| 3171 | long theWindowStyle = resource->GetStyle(); |
| 3172 | bool isModal = (resource->GetValue1() != 0) ; |
| 3173 | int x = resource->GetX(); |
| 3174 | int y = resource->GetY(); |
| 3175 | int width = resource->GetWidth(); |
| 3176 | int height = resource->GetHeight(); |
| 3177 | wxString name = resource->GetName(); |
| 3178 | |
| 3179 | // this is used for loading wxWizard pages from WXR |
| 3180 | if ( parent != this ) |
| 3181 | { |
| 3182 | if (IsKindOf(CLASSINFO(wxDialog))) |
| 3183 | { |
| 3184 | wxDialog *dialogBox = (wxDialog *)this; |
| 3185 | long modalStyle = isModal ? wxDIALOG_MODAL : 0; |
| 3186 | if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name)) |
| 3187 | return FALSE; |
| 3188 | |
| 3189 | // Only reset the client size if we know we're not going to do it again below. |
| 3190 | if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0) |
| 3191 | dialogBox->SetClientSize(width, height); |
| 3192 | } |
| 3193 | else if (IsKindOf(CLASSINFO(wxPanel))) |
| 3194 | { |
| 3195 | wxPanel* panel = (wxPanel *)this; |
| 3196 | if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle | wxTAB_TRAVERSAL, name)) |
| 3197 | return FALSE; |
| 3198 | } |
| 3199 | else |
| 3200 | { |
| 3201 | if (!((wxWindow *)this)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) |
| 3202 | return FALSE; |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) |
| 3207 | { |
| 3208 | // No need to do this since it's done in wxPanel or wxDialog constructor. |
| 3209 | // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
| 3210 | } |
| 3211 | else |
| 3212 | { |
| 3213 | if (resource->GetFont().Ok()) |
| 3214 | SetFont(resource->GetFont()); |
| 3215 | if (resource->GetBackgroundColour().Ok()) |
| 3216 | SetBackgroundColour(resource->GetBackgroundColour()); |
| 3217 | } |
| 3218 | |
| 3219 | // Should have some kind of font at this point |
| 3220 | if (!GetFont().Ok()) |
| 3221 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
| 3222 | if (!GetBackgroundColour().Ok()) |
| 3223 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
| 3224 | |
| 3225 | // Only when we've created the window and set the font can we set the correct size, |
| 3226 | // if based on dialog units. |
| 3227 | if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) |
| 3228 | { |
| 3229 | wxSize sz = ConvertDialogToPixels(wxSize(width, height)); |
| 3230 | SetClientSize(sz.x, sz.y); |
| 3231 | |
| 3232 | wxPoint pt = ConvertDialogToPixels(wxPoint(x, y)); |
| 3233 | Move(pt.x, pt.y); |
| 3234 | } |
| 3235 | |
| 3236 | // Now create children |
| 3237 | wxNode *node = resource->GetChildren().First(); |
| 3238 | while (node) |
| 3239 | { |
| 3240 | wxItemResource *childResource = (wxItemResource *)node->Data(); |
| 3241 | |
| 3242 | (void) CreateItem(childResource, resource, table); |
| 3243 | |
| 3244 | node = node->Next(); |
| 3245 | } |
| 3246 | return TRUE; |
| 3247 | } |
| 3248 | |
| 3249 | wxControl *wxWindowBase::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table) |
| 3250 | { |
| 3251 | if (!table) |
| 3252 | table = wxDefaultResourceTable; |
| 3253 | return table->CreateItem((wxWindow *)this, resource, parentResource); |
| 3254 | } |
| 3255 | |
| 3256 | #ifdef __VISUALC__ |
| 3257 | #pragma warning(default:4706) // assignment within conditional expression |
| 3258 | #endif // VC++ |
| 3259 | |
| 3260 | #endif |
| 3261 | // BC++/Win16 |
| 3262 | |
| 3263 | #endif // wxUSE_WX_RESOURCES |