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.
30 #ifndef SWELL_PROVIDED_BY_APP
36 void BrowseFile_SetTemplate(int dlgid
, DLGPROC dlgProc
, struct SWELL_DialogResourceIndex
*reshead
)
41 bool BrowseForSaveFile(const char *text
, const char *initialdir
, const char *initialfile
, const char *extlist
,
47 bool BrowseForDirectory(const char *text
, const char *initialdir
, char *fn
, int fnsize
)
54 char *BrowseForFiles(const char *text
, const char *initialdir
,
55 const char *initialfile
, bool allowmul
, const char *extlist
)
61 static void messagebox_callback( GtkWidget
*widget
, gpointer data
)
63 if (data
) *(char*)data
=1;
67 int MessageBox(HWND hwndParent
, const char *text
, const char *caption
, int type
)
69 char has_clicks
[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";
90 ids
[0]=IDOK
; lbls
[0]="OK";
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();
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
);
133 for(x
=0;x
<3 && ids
[x
]; x
++)
135 if (has_clicks
[x
]) return ids
[x
];