merging cockos wdl
[wdl/wdl-ol.git] / WDL / swell / swell-miscdlg-gtk.cpp
blob523ac2c73978f0e5d9f66b722f25f18af4a09549
1 /* Cockos SWELL (Simple/Small Win32 Emulation Layer for Linux
2 Copyright (C) 2006-2008, Cockos, Inc.
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
21 This file provides basic APIs for browsing for files, directories, and messageboxes.
23 These APIs don't all match the Windows equivelents, but are close enough to make it not too much trouble.
26 (GTK version)
30 #ifndef SWELL_PROVIDED_BY_APP
32 #include <gtk/gtk.h>
34 #include "swell.h"
36 void BrowseFile_SetTemplate(int dlgid, DLGPROC dlgProc, struct SWELL_DialogResourceIndex *reshead)
40 // return true
41 bool BrowseForSaveFile(const char *text, const char *initialdir, const char *initialfile, const char *extlist,
42 char *fn, int fnsize)
44 return false;
47 bool BrowseForDirectory(const char *text, const char *initialdir, char *fn, int fnsize)
49 return false;
54 char *BrowseForFiles(const char *text, const char *initialdir,
55 const char *initialfile, bool allowmul, const char *extlist)
57 return NULL;
61 static void messagebox_callback( GtkWidget *widget, gpointer data )
63 if (data) *(char*)data=1;
64 gtk_main_quit ();
67 int MessageBox(HWND hwndParent, const char *text, const char *caption, int type)
69 char has_clicks[3]={0,};
70 int ids[3]={0,};
71 const char *lbls[3]={0,};
72 if (type == MB_OKCANCEL)
74 ids[0]=IDOK; lbls[0]="OK";
75 ids[1]=IDCANCEL; lbls[1]="Cancel";
77 else if (type == MB_YESNO)
79 ids[0]=IDYES; lbls[0]="Yes";
80 ids[1]=IDNO; lbls[1]="No";
82 else if (type == MB_YESNOCANCEL)
84 ids[0]=IDYES; lbls[0]="Yes";
85 ids[1]=IDNO; lbls[1]="No";
86 ids[2]=IDCANCEL; lbls[2]="Cancel";
88 else // MB_OK?
90 ids[0]=IDOK; lbls[0]="OK";
93 GtkWidget *window;
94 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
95 gtk_window_set_modal(GTK_WINDOW(window), true);
96 gtk_window_set_destroy_with_parent(GTK_WINDOW(window), true);
97 gtk_window_set_resizable(GTK_WINDOW(window), false);
98 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
99 gtk_window_set_title(GTK_WINDOW(window), caption);
100 g_signal_connect (G_OBJECT (window), "destroy",
101 G_CALLBACK (messagebox_callback), NULL);
103 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
105 GtkWidget *outer_container = gtk_vbox_new(false, 4);
107 GtkWidget *label = gtk_label_new(text);
108 gtk_container_add(GTK_CONTAINER(outer_container),label);
109 gtk_widget_show(label);
112 GtkWidget *con = gtk_hbutton_box_new();
113 int x;
114 for(x=0;x<3&&ids[x];x++)
116 GtkWidget *but = gtk_button_new_with_label(lbls[x]);
117 g_signal_connect(G_OBJECT(but), "clicked", G_CALLBACK(messagebox_callback), &has_clicks[x]);
118 gtk_container_add(GTK_CONTAINER(con), but);
119 gtk_widget_show(but);
121 gtk_container_add(GTK_CONTAINER(outer_container),con);
122 gtk_widget_show(con);
126 gtk_container_add(GTK_CONTAINER(window), outer_container);
127 gtk_widget_show(outer_container);
128 gtk_widget_show(window);
130 gtk_main ();
132 int x;
133 for(x=0;x<3 && ids[x]; x++)
135 if (has_clicks[x]) return ids[x];
137 if (x>0) x--;
138 return ids[x];
141 #endif