Example #1
0
/* Test al_ustr_to_buffer */
static void t51(void)
{
   char str[256];
   const ALLEGRO_USTR *us;
   ALLEGRO_USTR_INFO info;

   us = al_ref_buffer(&info, "Allegro", 3);
   al_ustr_to_buffer(us, str, 10);
   CHECK(0 == memcmp(str, "All", 4));
   al_ustr_to_buffer(us, str, 4);
   CHECK(0 == memcmp(str, "All", 4));
   al_ustr_to_buffer(us, str, 3);
   CHECK(0 == memcmp(str, "Al", 3));
}
Example #2
0
/* [gtk thread] */
static gboolean create_native_message_box(gpointer data)
{
   Msg *msg = data;
   ALLEGRO_DISPLAY *display = msg->display;
   ALLEGRO_NATIVE_DIALOG *fd = msg->dialog;
   GtkWidget *window;

   /* Create a new file selection widget */
   GtkMessageType type = GTK_MESSAGE_INFO;
   GtkButtonsType buttons = GTK_BUTTONS_OK;
   if (fd->flags & ALLEGRO_MESSAGEBOX_YES_NO) type = GTK_MESSAGE_QUESTION;
   if (fd->flags & ALLEGRO_MESSAGEBOX_QUESTION) type = GTK_MESSAGE_QUESTION;
   if (fd->flags & ALLEGRO_MESSAGEBOX_WARN) type = GTK_MESSAGE_WARNING;
   if (fd->flags & ALLEGRO_MESSAGEBOX_ERROR) type = GTK_MESSAGE_ERROR;
   if (fd->flags & ALLEGRO_MESSAGEBOX_YES_NO) buttons = GTK_BUTTONS_YES_NO;
   if (fd->flags & ALLEGRO_MESSAGEBOX_OK_CANCEL) buttons = GTK_BUTTONS_OK_CANCEL;
   if (fd->mb_buttons) buttons = GTK_BUTTONS_NONE;

   window = gtk_message_dialog_new(NULL, 0, type, buttons, "%s",
      al_cstr(fd->mb_heading));
    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(window), "%s",
      al_cstr(fd->mb_text));

   make_transient(display, window);

   if (fd->mb_buttons) {
      int i = 1;
      int pos = 0;
      while (1) {
         int next = al_ustr_find_chr(fd->mb_buttons, pos, '|');
         int pos2 = next;
         if (next == -1)
	     pos2 = al_ustr_size(fd->mb_buttons);
         ALLEGRO_USTR_INFO info;
         const ALLEGRO_USTR *button_text;
         button_text = al_ref_ustr(&info, fd->mb_buttons, pos, pos2);
         pos = pos2 + 1;
         char buffer[256];
         al_ustr_to_buffer(button_text, buffer, sizeof buffer);
         gtk_dialog_add_button(GTK_DIALOG(window), buffer, i++);
         if (next == -1)
	     break;
      }
   }

   gtk_window_set_title(GTK_WINDOW(window), al_cstr(fd->title));

   g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(dialog_destroy), fd);

   g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(msgbox_response), fd);
   g_signal_connect_swapped(G_OBJECT(window), "response", G_CALLBACK(gtk_widget_destroy), window);

   gtk_widget_show(window);
   return FALSE;
}
Example #3
0
static bool fs_apk_change_directory(const char *path)
{
   ALLEGRO_USTR *us;
   bool ret;

   /* Figure out which directory we are trying to change to. */
   if (path_is_absolute(path))
      us = al_ustr_new(path);
   else
      us = apply_cwd(path);

   ensure_trailing_slash(us);

   if ((size_t) al_ustr_size(us) < sizeof(fs_apk_cwd)) {
      al_ustr_to_buffer(us, fs_apk_cwd, sizeof(fs_apk_cwd));
      ret = true;
   }

   al_ustr_free(us);

   return ret;
}
Example #4
0
/* _al_win_get_path:
 *  Returns full path to various system and user diretories
 */
ALLEGRO_PATH *_al_win_get_path(int id)
{
    char path[MAX_PATH];
    wchar_t pathw[MAX_PATH];
    ALLEGRO_USTR *pathu;
    uint32_t csidl = 0;
    HRESULT ret = 0;
    ALLEGRO_PATH *cisdl_path = NULL;

    switch (id) {
    case ALLEGRO_TEMP_PATH: {
        /* Check: TMP, TMPDIR, TEMP or TEMPDIR */

        DWORD ret = GetTempPathW(MAX_PATH, pathw);
        if (ret > MAX_PATH) {
            /* should this ever happen, windows is more broken than I ever thought */
            return NULL;
        }
        pathu = al_ustr_new_from_utf16(pathw);
        al_ustr_to_buffer(pathu, path, sizeof path);
        al_ustr_free(pathu);
        return al_create_path_for_directory(path);

    }
    break;

    case ALLEGRO_RESOURCES_PATH: { /* where the program is in */
        HANDLE process = GetCurrentProcess();
        char *ptr;

        GetModuleFileNameExW(process, NULL, pathw, MAX_PATH);
        pathu = al_ustr_new_from_utf16(pathw);
        al_ustr_to_buffer(pathu, path, sizeof path);
        al_ustr_free(pathu);
        ptr = strrchr(path, '\\');
        if (!ptr) { /* shouldn't happen */
            return NULL;
        }

        /* chop off everything including and after the last slash */
        /* should this not chop the slash? */
        *ptr = '\0';

        return al_create_path_for_directory(path);
    }
    break;

    case ALLEGRO_USER_DATA_PATH: /* CSIDL_APPDATA */
    case ALLEGRO_USER_SETTINGS_PATH:
        csidl = CSIDL_APPDATA;
        break;

    case ALLEGRO_USER_HOME_PATH: /* CSIDL_PROFILE */
        csidl = CSIDL_PROFILE;
        break;

    case ALLEGRO_USER_DOCUMENTS_PATH: /* CSIDL_PERSONAL */
        csidl = CSIDL_PERSONAL;
        break;

    case ALLEGRO_EXENAME_PATH: { /* full path to the exe including its name */
        HANDLE process = GetCurrentProcess();

        GetModuleFileNameExW(process, NULL, pathw, MAX_PATH);
        pathu = al_ustr_new_from_utf16(pathw);
        al_ustr_to_buffer(pathu, path, sizeof path);
        al_ustr_free(pathu);

        return al_create_path(path);
    }
    break;

    default:
        return NULL;
    }

    ret = SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, pathw);
    if (ret != S_OK) {
        return NULL;
    }

    pathu = al_ustr_new_from_utf16(pathw);
    al_ustr_to_buffer(pathu, path, sizeof path);
    al_ustr_free(pathu);

    cisdl_path = al_create_path_for_directory(path);
    if (!cisdl_path)
        return NULL;

    if (csidl == CSIDL_APPDATA) {
        const char *org_name = al_get_org_name();
        const char *app_name = al_get_app_name();

        if (!app_name || !app_name[0]) {
            /* this shouldn't ever happen. */
            al_destroy_path(cisdl_path);
            return NULL;
        }

        if (org_name && org_name[0]) {
            al_append_path_component(cisdl_path, org_name);
        }

        al_append_path_component(cisdl_path, app_name);
    }

    return cisdl_path;
}