UT_array* CharSelectDataFind(CharSelectData* charselect, const char* needle) { UnicodeSet *result = NULL; UT_array* returnRes; utarray_new(returnRes, fcitx_int32_icd); char* simplified = Simplified(needle); UT_array* searchStrings = SplitString(simplified); if (strlen(simplified) == 1) { // search for hex representation of the character utarray_clear(searchStrings); char* format = FormatCode(simplified[0], 4, "U+"); utarray_push_back(searchStrings, &format); free(format); } free(simplified); if (utarray_len(searchStrings) == 0) { return returnRes; } utarray_foreach(s, searchStrings, char*) { char* end = NULL; if(IsHexString(*s)) { end = NULL; uint32_t uni = (uint32_t) strtoul(*s + 2, &end, 16); utarray_push_back(returnRes, &uni); // search for "1234" instead of "0x1234" char* news = strdup(*s + 2); free(*s); *s = news; } // try to parse string as decimal number end = NULL; uint32_t unicode = (uint32_t) strtoul(*s, &end, 10); if (*end == '\0') { utarray_push_back(returnRes, &unicode); } }
void TopLevelWinWrapper::GenerateCode(const wxcProjectMetadata& project, bool promptUser, bool baseOnly, wxString& baseCpp, wxString& baseHeader, wxArrayString& headers, wxStringMap_t& additionalFiles) { wxString size = PropertyString(PROP_SIZE); wxString filename = PropertyFile(PROP_FILE); if(promptUser && (GetType() != ID_WXIMAGELIST)) { // By design we dont provide a subclass for wxImageList if(filename.IsEmpty() && !wxcSettings::Get().HasFlag(wxcSettings::DONT_PROMPT_ABOUT_MISSING_SUBCLASS)) { wxString message; message << _("You did not set the 'Inherited C++ Class Properties -> File name' property for the top level " "window: '") << GetName() << "'\n" << _("This means that only base class code will be generated\nTo fix this, select the toplevel " "entry from the tree-view and provide an Inherited class name and file name"); wxRichMessageDialog dlg(NULL, message, "wxCrafter", wxOK | wxOK_DEFAULT | wxCENTER | wxICON_WARNING); dlg.SetOKLabel("OK, continue with code generation"); dlg.ShowCheckBox(_("Don't show this message again")); if(dlg.ShowModal() == wxID_CANCEL) { return; } if(dlg.IsCheckBoxChecked()) { wxcSettings::Get().EnableFlag(wxcSettings::DONT_PROMPT_ABOUT_MISSING_SUBCLASS, true); } } } /// Clear all window IDs related to this top level window m_auiDropDownMenuHelperRegistered = false; wxcCodeGeneratorHelper::Get().ClearWindowIds(); wxcCodeGeneratorHelper::Get().ClearIcons(); // Icons should be cleared between top-level windows wxcNotebookCodeHelper::Get().Clear(); wxString ctorBody, dtorCode, membersChunk, eventFunctions, eventConnectCode, eventDisconnectCode, extraFunctionsCodeImpl, extraFunctionsCodeDecl; headers.Add(wxT("#include <wx/settings.h>")); headers.Add(wxT("#include <wx/xrc/xmlres.h>")); headers.Add(wxT("#include <wx/xrc/xh_bmp.h>")); DoTraverseAndGenCode(headers, ctorBody, membersChunk, eventFunctions, eventConnectCode, additionalFiles, dtorCode, extraFunctionsCodeImpl, extraFunctionsCodeDecl); // Format the code a bit ctorBody = FormatCode(ctorBody); // Window colors if(IsWindow()) { wxString bgcol = wxCrafter::ColourToCpp(PropertyString(PROP_BG)); wxString fgcol = wxCrafter::ColourToCpp(PropertyString(PROP_FG)); // Add colors and fonts here if(bgcol.IsEmpty() == false) { ctorBody << wxT(" SetBackgroundColour(") << bgcol << wxT(");\n"); } if(fgcol.IsEmpty() == false) { ctorBody << wxT(" SetForegroundColour(") << fgcol << wxT(");\n"); } } ctorBody << FormatCode(wxcNotebookCodeHelper::Get().Code()); wxcNotebookCodeHelper::Get().Clear(); if(IsWindow()) { // Set the window name ctorBody << " SetName(" << wxCrafter::WXT(GetName()) << ");\n"; wxSize sz = wxCrafter::DecodeSize(PropertyString(PROP_MINSIZE)); if(sz != wxDefaultSize) { ctorBody << wxT(" SetMinClientSize(wxSize(" << wxCrafter::EncodeSize(sz) << "));\n"); } if(GetType() != ID_WXAUITOOLBARTOPLEVEL) { ctorBody << " SetSize(" << wxCrafter::GetSizeAsDlgUnits(GetSize(), "this") << wxT(");\n"); ctorBody << " if (GetSizer()) {\n"; ctorBody << " GetSizer()->Fit(this);\n"; ctorBody << " }\n"; if(IsWxTopLevelWindow()) { ctorBody << " if(GetParent()) {\n"; ctorBody << " CentreOnParent(" << PropertyString(PROP_CENTRE_ON_SCREEN) << ");\n"; ctorBody << " } else {\n"; ctorBody << " CentreOnScreen(" << PropertyString(PROP_CENTRE_ON_SCREEN) << ");\n"; ctorBody << " }\n"; } // Add support for wxPersistenceManager object if(wxcSettings::Get().IsLicensed() && IsWxTopLevelWindow() && IsPropertyChecked(PROP_PERSISTENT)) { ctorBody << wxCrafter::WX29_BLOCK_START(); ctorBody << " if(!wxPersistenceManager::Get().Find(this)) {\n"; ctorBody << " wxPersistenceManager::Get().RegisterAndRestore(this);\n"; ctorBody << " } else {\n"; ctorBody << " wxPersistenceManager::Get().Restore(this);\n"; ctorBody << " }\n"; ctorBody << "#endif\n"; } } } // Format the function code eventFunctions = FormatCode(eventFunctions); eventConnectCode = FormatCode(eventConnectCode); eventDisconnectCode = eventConnectCode; eventDisconnectCode.Replace(wxT("->Connect("), wxT("->Disconnect(")); wxString baseClassName = CreateBaseclassName(); wxString cppDecorator = PropertyString(PROP_CLASS_DECORATOR); cppDecorator.Trim().Trim(false); wxString superclass = GetRealClassName(); wxString derivedSuperclass = baseClassName; if(baseClassName.IsEmpty()) { // meaning that it was empty until BASE_CLASS_SUFFIX was appended wxString msg; msg << wxT("Can not generate code.\nMake sure that all toplevel windows have a valid C++ class name"); wxMessageBox(msg, wxT("wxCrafter"), wxOK | wxICON_WARNING | wxCENTER); return; } if(filename.IsEmpty()) { baseOnly = true; } wxFileName headerFile, sourceFile; wxFileName baseFile(wxcProjectMetadata::Get().GetGeneratedFilesDir(), wxcProjectMetadata::Get().GetOutputFileName()); // If the files are relative make them abs if(baseFile.IsRelative()) { baseFile.MakeAbsolute(project.GetProjectPath()); } wxString dbg = baseFile.GetFullPath(); headerFile = baseFile; sourceFile = baseFile; headerFile.SetExt(wxT("h")); sourceFile.SetExt(wxT("cpp")); dtorCode.Prepend(eventDisconnectCode); // Write the C++ file baseCpp << wxT("\n") << BaseCtorImplPrefix() << wxT("{\n") << wxcCodeGeneratorHelper::Get().GenerateInitCode(this) << ctorBody; if(eventConnectCode.IsEmpty() == false) { baseCpp << wxT(" // Connect events\n") << eventConnectCode; } // Now Connect() any auitoolbar dropdown menu; it must be *after* the normal Connect()s, otherwise it won't be // called if the user-code forgets to event.Skip() if(IsAuiToolBarDropDownHelpersRegistered()) { baseCpp << " this->Connect(" << "wxID_ANY, " << "wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEventHandler(" << GetName() << "::" << DEFAULT_AUI_DROPDOWN_FUNCTION << "), NULL, this);\n"; // We need to disconnect it too dtorCode << " this->Disconnect(" << "wxID_ANY, " << "wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEventHandler(" << GetName() << "::" << DEFAULT_AUI_DROPDOWN_FUNCTION << "), NULL, this);\n"; } baseCpp << wxT("}\n\n") << baseClassName << wxT("::~") << baseClassName << wxT("()\n") << wxT("{\n") << dtorCode << wxT("}\n"); // Write any extra (i.e. not ctor/dtor) functions if(!extraFunctionsCodeImpl.empty()) { baseCpp << extraFunctionsCodeImpl; // Don't use FormatCode() here; it'd indent the signature etc too } // prepare the enum block for the // Write the header file baseHeader << wxT("\n") << wxT("class ") << (cppDecorator.IsEmpty() ? "" : cppDecorator + " ") << baseClassName << wxT(" : public ") << superclass << wxT("\n") << wxT("{\n") << wxcCodeGeneratorHelper::Get().GenerateWinIdEnum() << wxT("protected:\n") << membersChunk << wxT("\n") << wxT("protected:\n") << eventFunctions << wxT("\n") << wxT("public:\n") << extraFunctionsCodeDecl << BaseCtorDecl() << wxT(" virtual ~") << baseClassName << wxT("();\n") << wxT("};\n\n"); if(baseOnly) { return; } wxString inheritedClass = PropertyString(PROP_INHERITED_CLASS); inheritedClass.Trim().Trim(false); if(inheritedClass.IsEmpty()) { return; } if(inheritedClass == baseClassName) { ::wxMessageBox(_("Base class and inherited class have the same name"), "wxCrafter", wxOK | wxICON_WARNING | wxCENTER); return; } ///////////////////////////////////////////////////////////////////////////////////////// // Create the derived classes files ///////////////////////////////////////////////////////////////////////////////////////// wxFileName derivedClassFileCPP(filename); wxFileName derivedClassFileH(filename); derivedClassFileCPP.SetExt(wxT("cpp")); derivedClassFileH.SetExt(wxT("h")); // Fix the paths if needed // i.e. if the derived classes are relative, make them use the same // path as the base classes file if(derivedClassFileCPP.IsRelative()) { derivedClassFileCPP.SetPath(headerFile.GetPath()); } if(derivedClassFileH.IsRelative()) { derivedClassFileH.SetPath(headerFile.GetPath()); } wxString dCpp, dH, dBlockGuard; dBlockGuard << inheritedClass; dBlockGuard.MakeUpper(); dBlockGuard << wxT("_H"); // Prepare the Header file content dH << wxT("#ifndef ") << dBlockGuard << wxT("\n") << wxT("#define ") << dBlockGuard << wxT("\n") << wxT("#include \"") << headerFile.GetFullName() << wxT("\"\n") << wxT("\n") << wxT("class ") << (cppDecorator.IsEmpty() ? "" : cppDecorator + " ") << inheritedClass << wxT(" : public ") << derivedSuperclass << wxT("\n") << wxT("{\n") << wxT("public:\n") << wxT(" ") << inheritedClass << GetDerivedClassCtorSignature() << ";\n" << wxT(" virtual ~") << inheritedClass << wxT("();\n") << wxT("};\n") << wxT("#endif // ") << dBlockGuard << wxT("\n"); // Prepare the CPP file content dCpp << wxT("#include \"") << derivedClassFileH.GetFullName() << wxT("\"\n\n") << inheritedClass << wxT("::") << inheritedClass << GetDerivedClassCtorSignature() << "\n" << wxT(" : ") << baseClassName << GetParentCtorInitArgumentList() << "\n" << wxT("{\n") << wxT("}\n\n") << inheritedClass << wxT("::~") << inheritedClass << wxT("()\n") << wxT("{\n") << wxT("}\n\n"); // Keep track of the generated files if(WantsSubclass()) { wxcProjectMetadata::Get().SetGeneratedHeader(derivedClassFileH); wxcProjectMetadata::Get().SetGeneratedSource(derivedClassFileCPP); } wxcProjectMetadata::Get().SetGeneratedClassName(inheritedClass); wxcProjectMetadata::Get().SetVirtualFolder(GetVirtualFolder()); if(WantsSubclass() && wxCrafter::IsTheSame(derivedClassFileH, dH) == false) { wxCrafter::WriteFile(derivedClassFileH, dH, false); } if(WantsSubclass() && wxCrafter::IsTheSame(derivedClassFileCPP, dCpp) == false) { wxCrafter::WriteFile(derivedClassFileCPP, dCpp, false); } // Tell CodeLite to reload externall modified files EventNotifier::Get()->PostReloadExternallyModifiedEvent(true); }