1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.Atom; 26 27 private import gdk.Display; 28 private import gdk.Window; 29 private import glib.Str; 30 private import gtkc.gdk; 31 public import gtkc.gdktypes; 32 33 34 /** 35 * An opaque type representing a string as an index into a table 36 * of strings on the X server. 37 */ 38 39 /** 40 * Determines the string corresponding to an atom. 41 * 42 * Return: a newly-allocated string containing the string 43 * corresponding to @atom. When you are done with the 44 * return value, you should free it using g_free(). 45 */ 46 public string name(GdkAtom atom) 47 { 48 return Str.toString(gdk_atom_name(atom)); 49 } 50 51 /** 52 * Finds or creates an atom corresponding to a given string. 53 * 54 * Params: 55 * atomName = a string. 56 * onlyIfExists = if %TRUE, GDK is allowed to not create a new atom, but 57 * just return %GDK_NONE if the requested atom doesn’t already 58 * exists. Currently, the flag is ignored, since checking the 59 * existance of an atom is as expensive as creating it. 60 * 61 * Return: the atom corresponding to @atom_name. 62 */ 63 public GdkAtom intern(string atomName, bool onlyIfExists) 64 { 65 return gdk_atom_intern(Str.toStringz(atomName), onlyIfExists); 66 } 67 68 /** 69 * Finds or creates an atom corresponding to a given string. 70 * 71 * Note that this function is identical to gdk_atom_intern() except 72 * that if a new #GdkAtom is created the string itself is used rather 73 * than a copy. This saves memory, but can only be used if the string 74 * will always exist. It can be used with statically 75 * allocated strings in the main program, but not with statically 76 * allocated memory in dynamically loaded modules, if you expect to 77 * ever unload the module again (e.g. do not use this function in 78 * GTK+ theme engines). 79 * 80 * Params: 81 * atomName = a static string 82 * 83 * Return: the atom corresponding to @atom_name 84 * 85 * Since: 2.10 86 */ 87 public GdkAtom internStaticString(string atomName) 88 { 89 return gdk_atom_intern_static_string(Str.toStringz(atomName)); 90 } 91 92 /** 93 * Changes the contents of a property on a window. 94 * 95 * Params: 96 * window = a #GdkWindow 97 * property = the property to change 98 * type = the new type for the property. If @mode is 99 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this 100 * must match the existing type or an error will occur. 101 * format = the new format for the property. If @mode is 102 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this 103 * must match the existing format or an error will occur. 104 * mode = a value describing how the new data is to be combined 105 * with the current data. 106 * data = the data (a `guchar *` 107 * `gushort *`, or `gulong *`, 108 * depending on @format), cast to a `guchar *`. 109 * nelements = the number of elements of size determined by the format, 110 * contained in @data. 111 */ 112 public void propertyChange(Window window, GdkAtom property, GdkAtom type, int format, GdkPropMode mode, char[] data) 113 { 114 gdk_property_change((window is null) ? null : window.getWindowStruct(), property, type, format, mode, data.ptr, cast(int)data.length); 115 } 116 117 /** 118 * Deletes a property from a window. 119 * 120 * Params: 121 * window = a #GdkWindow 122 * property = the property to delete 123 */ 124 public void propertyDelete(Window window, GdkAtom property) 125 { 126 gdk_property_delete((window is null) ? null : window.getWindowStruct(), property); 127 } 128 129 /** 130 * Retrieves a portion of the contents of a property. If the 131 * property does not exist, then the function returns %FALSE, 132 * and %GDK_NONE will be stored in @actual_property_type. 133 * 134 * The XGetWindowProperty() function that gdk_property_get() 135 * uses has a very confusing and complicated set of semantics. 136 * Unfortunately, gdk_property_get() makes the situation 137 * worse instead of better (the semantics should be considered 138 * undefined), and also prints warnings to stderr in cases where it 139 * should return a useful error to the program. You are advised to use 140 * XGetWindowProperty() directly until a replacement function for 141 * gdk_property_get() is provided. 142 * 143 * Params: 144 * window = a #GdkWindow 145 * property = the property to retrieve 146 * type = the desired property type, or %GDK_NONE, if any type of data 147 * is acceptable. If this does not match the actual 148 * type, then @actual_format and @actual_length will 149 * be filled in, a warning will be printed to stderr 150 * and no data will be returned. 151 * offset = the offset into the property at which to begin 152 * retrieving data, in 4 byte units. 153 * length = the length of the data to retrieve in bytes. Data is 154 * considered to be retrieved in 4 byte chunks, so @length 155 * will be rounded up to the next highest 4 byte boundary 156 * (so be careful not to pass a value that might overflow 157 * when rounded up). 158 * pdelete = if %TRUE, delete the property after retrieving the 159 * data. 160 * actualPropertyType = location to store the 161 * actual type of the property. 162 * actualFormat = location to store the actual return format of the 163 * data; either 8, 16 or 32 bits. 164 * actualLength = location to store the length of the retrieved data, in 165 * bytes. Data returned in the 32 bit format is stored 166 * in a long variable, so the actual number of 32 bit 167 * elements should be be calculated via 168 * @actual_length / sizeof(glong) to ensure portability to 169 * 64 bit systems. 170 * data = location 171 * to store a pointer to the data. The retrieved data should be 172 * freed with g_free() when you are finished using it. 173 * 174 * Return: %TRUE if data was successfully received and stored 175 * in @data, otherwise %FALSE. 176 */ 177 public bool propertyGet(Window window, GdkAtom property, GdkAtom type, gulong offset, gulong length, int pdelete, out GdkAtom actualPropertyType, out int actualFormat, out char[] data) 178 { 179 int actualLength; 180 char* outdata = null; 181 182 auto p = gdk_property_get((window is null) ? null : window.getWindowStruct(), property, type, offset, length, pdelete, &actualPropertyType, &actualFormat, &actualLength, &outdata) != 0; 183 184 data = outdata[0 .. actualLength]; 185 186 return p; 187 } 188 189 /** 190 * Converts a text property in the given encoding to 191 * a list of UTF-8 strings. 192 * 193 * Params: 194 * display = a #GdkDisplay 195 * encoding = an atom representing the encoding of the text 196 * format = the format of the property 197 * text = the text to convert 198 * length = the length of @text, in bytes 199 * list = location to store the list 200 * of strings or %NULL. The list should be freed with 201 * g_strfreev(). 202 * 203 * Return: the number of strings in the resulting list 204 * 205 * Since: 2.2 206 */ 207 public int textPropertyToUtf8ListForDisplay(Display display, GdkAtom encoding, int format, char[] text, out string[] list) 208 { 209 char** outlist = null; 210 211 auto p = gdk_text_property_to_utf8_list_for_display((display is null) ? null : display.getDisplayStruct(), encoding, format, text.ptr, cast(int)text.length, &outlist); 212 213 list = Str.toStringArray(outlist); 214 215 return p; 216 } 217 218 /** 219 * Converts an UTF-8 string into the best possible representation 220 * as a STRING. The representation of characters not in STRING 221 * is not specified; it may be as pseudo-escape sequences 222 * \x{ABCD}, or it may be in some other form of approximation. 223 * 224 * Params: 225 * str = a UTF-8 string 226 * 227 * Return: the newly-allocated string, or %NULL if the 228 * conversion failed. (It should not fail for any properly 229 * formed UTF-8 string unless system limits like memory or 230 * file descriptors are exceeded.) 231 */ 232 public string utf8ToStringTarget(string str) 233 { 234 return Str.toString(gdk_utf8_to_string_target(Str.toStringz(str))); 235 }