]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/mmsolve.cpp
Corrected link error for missing wxRegTipProvider::GetTip by giving it
[wxWidgets.git] / utils / wxMMedia / mmsolve.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 // Name: mmsolve.h
3 // Purpose: wxMMedia
4 // Author: Guilhem Lavaux
5 // Created: 1997
6 // Updated: 1998
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13 #include "mmsolve.h"
14
15 wxMMediaFile *wxMediaFileSolve::ByExtension(const wxString& filename)
16 {
17 wxMFileList *list = m_first;
18 wxString tmp, f_ext;
19 int pos = filename.Find('.', TRUE)+1;
20
21 tmp = filename;
22 f_ext = tmp(pos, filename.Length()-pos);
23
24 printf("f_ext = %s\n", f_ext.GetData());
25 while (list) {
26 printf("list->ext = %s\n", list->ext.GetData());
27 if (list->ext.CompareTo(f_ext) == 0) {
28 wxMMediaFile *mmf = list->creator();
29 return mmf;
30 }
31 list = list->next;
32 }
33 return NULL;
34 }
35
36 wxMMediaFile *wxMediaFileSolve::ByName(const wxString& name)
37 {
38 wxMFileList *list = m_first;
39
40 while (list) {
41 if (list->name == name)
42 return (wxMMediaFile *)(list->creator());
43 list = list->next;
44 }
45 return NULL;
46 }
47
48 bool wxMatchMimeType(const wxString& mime_obj, const wxString& type)
49 {
50 #ifdef USE_GNU_WXSTRING
51 wxString mime2_obj = mime_obj;
52 wxString type2 = type;
53 #define mime_obj mime2_obj
54 #define type type2
55 #endif
56
57 if (mime_obj.Find('*') != -1) {
58 wxString part_str1[2], part_str2[2];
59
60 part_str1[0] = mime_obj.BeforeFirst('/');
61 part_str1[1] = mime_obj.AfterFirst('/');
62
63 part_str2[0] = type.BeforeFirst('/');
64 part_str2[1] = type.AfterFirst('/');
65
66 if (part_str1[0] == "*" && part_str1[1] == "*")
67 return TRUE;
68
69 if (part_str1[0] == "*" && part_str1[1] == part_str2[1])
70 return TRUE;
71
72 if (part_str1[1] == "*" && part_str1[0] == part_str2[1])
73 return TRUE;
74
75 return FALSE;
76 }
77 if (mime_obj == type)
78 return TRUE;
79 return FALSE;
80 }
81
82 wxMMediaFile *wxMediaFileSolve::ByType(const wxString& type)
83 {
84 wxMFileList *list = m_first;
85
86 while (list) {
87 if (wxMatchMimeType(*(list->mime_type), type))
88 return (wxMMediaFile *)(list->creator());
89 list = list->next;
90 }
91 return NULL;
92 }
93
94 void wxMediaFileSolve::ListMDevice(wxString*& names, wxUint8& devices)
95 {
96 wxMFileList *list = m_first;
97 wxUint8 d = 0;
98
99 if (!m_devnum) {
100 names = NULL;
101 return;
102 }
103 devices = m_devnum;
104 names = new wxString[devices];
105
106 while (list) {
107 names[d++] = list->name;
108 list = list->next;
109 }
110 }
111
112 wxMMDfileRegister::wxMMDfileRegister(wxMediaFileCreator cbk,
113 char *mtype, char *ext, char *name)
114 {
115 wxMediaFileSolve::wxMFileList *entry = new wxMediaFileSolve::wxMFileList;
116
117 entry->next = wxMediaFileSolve::m_first;
118 entry->creator = cbk;
119 entry->mime_type = wxString(mtype);
120 entry->name = wxString(name);
121 entry->ext = wxString(ext);
122 wxMediaFileSolve::m_devnum++;
123 wxMediaFileSolve::m_first = entry;
124 }