1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Definitions of miscelaneous functions and classes that need
4 // to know about wxWindow. (So they can't be in misc.i or an
5 // import loop will happen.)
9 // Created: 18-June-1999
11 // Copyright: (c) 1998 by Total Control Software
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
19 #include <wx/resource.h>
20 #include <wx/tooltip.h>
22 #include <wx/fontenum.h>
23 #include <wx/tipdlg.h>
24 #include <wx/process.h>
26 #if wxUSE_JOYSTICK || defined(__WXMSW__)
27 #include <wx/joystick.h>
30 #if wxUSE_WAVE || defined(__WXMSW__)
34 #include <wx/mimetype.h>
37 //----------------------------------------------------------------------
40 %include my_typemaps.i
42 // Import some definitions of other classes, etc.
52 //---------------------------------------------------------------------------
55 wxString wxFileSelector(char* message,
56 char* default_path = NULL,
57 char* default_filename = NULL,
58 char* default_extension = NULL,
59 char* wildcard = "*.*",
61 wxWindow *parent = NULL,
62 int x = -1, int y = -1);
64 wxString wxGetTextFromUser(const wxString& message,
65 const wxString& caption = wxEmptyString,
66 const wxString& default_value = wxEmptyString,
67 wxWindow *parent = NULL,
68 int x = -1, int y = -1,
71 wxString wxGetPasswordFromUser(const wxString& message,
72 const wxString& caption = wxEmptyString,
73 const wxString& default_value = wxEmptyString,
74 wxWindow *parent = NULL);
77 // TODO: Need to custom wrap this one...
78 // int wxGetMultipleChoice(char* message, char* caption,
79 // int LCOUNT, char** choices,
80 // int nsel, int *selection,
81 // wxWindow *parent = NULL, int x = -1, int y = -1,
82 // bool centre = TRUE, int width=150, int height=200);
85 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
86 int LCOUNT, wxString* choices,
87 wxWindow *parent = NULL,
88 int x = -1, int y = -1,
90 int width=150, int height=200);
92 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
93 int LCOUNT, wxString* choices,
94 wxWindow *parent = NULL,
95 int x = -1, int y = -1,
97 int width=150, int height=200);
100 int wxMessageBox(const wxString& message,
101 const wxString& caption = wxEmptyString,
102 int style = wxOK | wxCENTRE,
103 wxWindow *parent = NULL,
104 int x = -1, int y = -1);
106 long wxGetNumberFromUser(const wxString& message,
107 const wxString& prompt,
108 const wxString& caption,
110 long min = 0, long max = 100,
111 wxWindow *parent = NULL,
112 const wxPoint& pos = wxDefaultPosition);
114 //---------------------------------------------------------------------------
117 bool wxColourDisplay();
119 int wxDisplayDepth();
120 int wxGetDisplayDepth();
122 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
123 wxSize wxGetDisplaySize();
125 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
126 wxSize wxGetDisplaySizeMM();
128 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
129 wxRect wxGetClientDisplayRect();
131 void wxSetCursor(wxCursor& cursor);
133 //----------------------------------------------------------------------
134 // Miscellaneous functions
136 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
137 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
139 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
140 wxWindow * wxGetActiveWindow();
142 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
143 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
146 bool wxCheckForInterrupt(wxWindow *wnd);
147 void wxFlushEvents();
150 //---------------------------------------------------------------------------
153 bool wxResourceAddIdentifier(char *name, int value);
154 void wxResourceClear(void);
155 wxBitmap wxResourceCreateBitmap(char *resource);
156 wxIcon wxResourceCreateIcon(char *resource);
157 wxMenuBar * wxResourceCreateMenuBar(char *resource);
158 int wxResourceGetIdentifier(char *name);
159 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
160 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
161 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
163 //---------------------------------------------------------------------------
166 // possible values for wxSystemSettings::GetFont() parameter
170 wxSYS_OEM_FIXED_FONT = 10,
171 wxSYS_ANSI_FIXED_FONT,
174 wxSYS_DEVICE_DEFAULT_FONT,
175 wxSYS_DEFAULT_PALETTE,
176 wxSYS_SYSTEM_FIXED_FONT,
177 wxSYS_DEFAULT_GUI_FONT
180 // possible values for wxSystemSettings::GetColour() parameter
184 wxSYS_COLOUR_SCROLLBAR,
185 wxSYS_COLOUR_BACKGROUND,
186 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
187 wxSYS_COLOUR_ACTIVECAPTION,
188 wxSYS_COLOUR_INACTIVECAPTION,
191 wxSYS_COLOUR_WINDOWFRAME,
192 wxSYS_COLOUR_MENUTEXT,
193 wxSYS_COLOUR_WINDOWTEXT,
194 wxSYS_COLOUR_CAPTIONTEXT,
195 wxSYS_COLOUR_ACTIVEBORDER,
196 wxSYS_COLOUR_INACTIVEBORDER,
197 wxSYS_COLOUR_APPWORKSPACE,
198 wxSYS_COLOUR_HIGHLIGHT,
199 wxSYS_COLOUR_HIGHLIGHTTEXT,
200 wxSYS_COLOUR_BTNFACE,
201 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
202 wxSYS_COLOUR_BTNSHADOW,
203 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
204 wxSYS_COLOUR_GRAYTEXT,
205 wxSYS_COLOUR_BTNTEXT,
206 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
207 wxSYS_COLOUR_BTNHIGHLIGHT,
208 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
209 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
210 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
211 wxSYS_COLOUR_3DDKSHADOW,
212 wxSYS_COLOUR_3DLIGHT,
213 wxSYS_COLOUR_INFOTEXT,
215 wxSYS_COLOUR_LISTBOX,
216 wxSYS_COLOUR_HOTLIGHT,
217 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
218 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
219 wxSYS_COLOUR_MENUHILIGHT,
220 wxSYS_COLOUR_MENUBAR,
225 // possible values for wxSystemSettings::GetMetric() parameter
229 wxSYS_MOUSE_BUTTONS = 1,
240 wxSYS_HSCROLL_ARROW_X,
241 wxSYS_HSCROLL_ARROW_Y,
257 wxSYS_VSCROLL_ARROW_X,
258 wxSYS_VSCROLL_ARROW_Y,
262 wxSYS_NETWORK_PRESENT,
263 wxSYS_PENWINDOWS_PRESENT,
268 // possible values for wxSystemSettings::HasFeature() parameter
271 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
272 wxSYS_CAN_ICONIZE_FRAME
277 class wxSystemSettings {
279 // get a standard system colour
280 static wxColour GetColour(wxSystemColour index);
282 // get a standard system font
283 static wxFont GetFont(wxSystemFont index);
285 // get a system-dependent metric
286 static int GetMetric(wxSystemMetric index);
288 // return true if the port has certain feature
289 static bool HasFeature(wxSystemFeature index);
295 //---------------------------------------------------------------------------
298 class wxToolTip : public wxObject {
300 wxToolTip(const wxString &tip);
302 void SetTip(const wxString& tip);
304 // *** Not in the "public" interface void SetWindow(wxWindow *win);
305 wxWindow *GetWindow();
307 static void Enable(bool flag);
308 static void SetDelay(long milliseconds);
311 //----------------------------------------------------------------------
315 wxCaret(wxWindow* window, const wxSize& size);
320 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
321 wxPoint GetPosition();
322 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
324 wxWindow *GetWindow();
325 %name(MoveXY)void Move(int x, int y);
326 void Move(const wxPoint& pt);
327 %name(SetSizeWH) void SetSize(int width, int height);
328 void SetSize(const wxSize& size);
329 void Show(int show = TRUE);
334 int wxCaret_GetBlinkTime() {
335 return wxCaret::GetBlinkTime();
338 void wxCaret_SetBlinkTime(int milliseconds) {
339 wxCaret::SetBlinkTime(milliseconds);
343 //----------------------------------------------------------------------
346 class wxPyFontEnumerator : public wxFontEnumerator {
348 wxPyFontEnumerator() {}
349 ~wxPyFontEnumerator() {}
351 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
352 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
357 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
358 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
362 %name(wxFontEnumerator) class wxPyFontEnumerator {
364 wxPyFontEnumerator();
365 ~wxPyFontEnumerator();
366 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
367 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
369 bool EnumerateFacenames(
370 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
371 bool fixedWidthOnly = FALSE);
372 bool EnumerateEncodings(const char* facename = "");
374 //wxArrayString* GetEncodings();
375 //wxArrayString* GetFacenames();
377 PyObject* GetEncodings() {
378 wxArrayString* arr = self->GetEncodings();
379 return wxArrayString2PyList_helper(*arr);
382 PyObject* GetFacenames() {
383 wxArrayString* arr = self->GetFacenames();
384 return wxArrayString2PyList_helper(*arr);
389 //----------------------------------------------------------------------
393 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
397 //----------------------------------------------------------------------
399 class wxWindowDisabler {
401 wxWindowDisabler(wxWindow *winToSkip = NULL);
405 //----------------------------------------------------------------------
407 bool wxSafeYield(wxWindow* win=NULL);
408 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
413 void wxWakeUpMainThread();
416 void wxMutexGuiEnter();
417 void wxMutexGuiLeave();
420 class wxMutexGuiLocker {
428 bool wxThread_IsMain() {
429 #ifdef WXP_WITH_THREAD
430 return wxThread::IsMain();
437 //----------------------------------------------------------------------
443 // wxTipProvider(size_t currentTip); **** Abstract base class
446 virtual wxString GetTip() = 0;
447 size_t GetCurrentTip();
452 // The C++ version of wxPyTipProvider
454 class wxPyTipProvider : public wxTipProvider {
456 wxPyTipProvider(size_t currentTip)
457 : wxTipProvider(currentTip) {}
459 DEC_PYCALLBACK_STRING__pure(GetTip);
464 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
469 // Now let SWIG know about it
470 class wxPyTipProvider : public wxTipProvider {
472 wxPyTipProvider(size_t currentTip);
477 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
478 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
481 //----------------------------------------------------------------------
484 #include <wx/generic/dragimgg.h>
487 %name (wxDragImage) class wxGenericDragImage : public wxObject
491 wxGenericDragImage(const wxBitmap& image,
492 const wxCursor& cursor = wxNullCursor);
493 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
494 const wxCursor& cursor = wxNullCursor);
495 %name(wxDragString)wxGenericDragImage(const wxString& str,
496 const wxCursor& cursor = wxNullCursor);
497 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
498 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
500 ~wxGenericDragImage();
502 void SetBackingBitmap(wxBitmap* bitmap);
503 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
504 bool fullScreen = FALSE, wxRect* rect = NULL);
506 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
507 wxWindow* fullScreenRect);
510 bool Move(const wxPoint& pt);
514 wxRect GetImageRect(const wxPoint& pos) const;
515 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
516 bool eraseOld, bool drawNew);
520 //----------------------------------------------------------------------
522 class wxPyTimer : public wxObject {
524 wxPyTimer(PyObject* notify);
529 void SetOwner(wxEvtHandler *owner, int id = -1);
530 void Start(int milliseconds=-1, int oneShot=FALSE);
538 // ctor starts the stop watch
541 void Start(long t = 0);
545 // get elapsed time since the last Start() or Pause() in milliseconds
550 //----------------------------------------------------------------------
551 //----------------------------------------------------------------------
556 wxLOG_FatalError, // program can't continue, abort immediately
557 wxLOG_Error, // a serious error, user must be informed about it
558 wxLOG_Warning, // user is normally informed about it but may be ignored
559 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
560 wxLOG_Info, // informational message (a.k.a. 'Verbose')
561 wxLOG_Status, // informational: might go to the status line of GUI app
562 wxLOG_Debug, // never shown to the user, disabled in release mode
563 wxLOG_Trace, // trace messages are also only enabled in debug mode
564 wxLOG_Progress, // used for progress indicator (not yet)
565 wxLOG_User = 100 // user defined levels start here
574 static bool IsEnabled();
575 static bool EnableLogging(bool doIt = TRUE);
576 static void OnLog(wxLogLevel level, const char *szString, int t=0);
578 virtual void Flush();
579 bool HasPendingMessages() const;
581 static void FlushActive();
582 static wxLog *GetActiveTarget();
583 static wxLog *SetActiveTarget(wxLog *pLogger);
585 static void Suspend();
586 static void Resume();
588 void SetVerbose(bool bVerbose = TRUE);
590 static void DontCreateOnDemand();
591 static void SetTraceMask(wxTraceMask ulMask);
592 static void AddTraceMask(const wxString& str);
593 static void RemoveTraceMask(const wxString& str);
594 static void ClearTraceMasks();
596 static void SetTimestamp(const wxChar *ts);
597 static const wxChar *GetTimestamp();
599 bool GetVerbose() const { return m_bVerbose; }
601 static wxTraceMask GetTraceMask();
602 static bool IsAllowedTraceMask(const char *mask);
604 // static void TimeStamp(wxString *str);
606 wxString TimeStamp() {
608 wxLog::TimeStamp(&msg);
615 class wxLogStderr : public wxLog
618 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
622 class wxLogTextCtrl : public wxLog
625 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
629 class wxLogGui : public wxLog
635 class wxLogWindow : public wxLog
638 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
639 const char *szTitle, // the title of the frame
640 bool bShow = TRUE, // show window immediately?
641 bool bPassToOld = TRUE); // pass log messages to the old target?
643 void Show(bool bShow = TRUE);
644 wxFrame *GetFrame() const;
645 wxLog *GetOldLog() const;
646 bool IsPassingMessages() const;
647 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
659 class wxLogChain : public wxLog
662 wxLogChain(wxLog *logger);
663 void SetLog(wxLog *logger);
664 void PassMessages(bool bDoPass);
665 bool IsPassingMessages();
670 unsigned long wxSysErrorCode();
671 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
672 void wxLogFatalError(const char *szFormat);
673 void wxLogError(const char *szFormat);
674 void wxLogWarning(const char *szFormat);
675 void wxLogMessage(const char *szFormat);
676 void wxLogInfo(const char *szFormat);
677 void wxLogVerbose(const char *szFormat);
678 void wxLogStatus(const char *szFormat);
679 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
680 void wxLogSysError(const char *szFormat);
684 // A Log class that can be derived from in wxPython
685 class wxPyLog : public wxLog {
687 wxPyLog() : wxLog() {}
689 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
691 wxPyBeginBlockThreads();
692 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
693 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
694 wxPyEndBlockThreads();
696 wxLog::DoLog(level, szString, t);
699 virtual void DoLogString(const wxChar *szString, time_t t) {
701 wxPyBeginBlockThreads();
702 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
703 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
704 wxPyEndBlockThreads();
706 wxLog::DoLogString(szString, t);
713 // Now tell SWIG about it
714 class wxPyLog : public wxLog {
717 void _setCallbackInfo(PyObject* self, PyObject* _class);
718 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
719 %addmethods { void Destroy() { delete self; } }
724 //----------------------------------------------------------------------
733 class wxProcessEvent : public wxEvent {
735 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
738 int m_pid, m_exitcode;
744 %{ // C++ version of wxProcess derived class
746 class wxPyProcess : public wxProcess {
748 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
749 : wxProcess(parent, id)
752 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
757 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
762 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
764 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
765 %addmethods { void Destroy() { delete self; } }
767 void _setCallbackInfo(PyObject* self, PyObject* _class);
768 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
770 void base_OnTerminate(int pid, int status);
776 wxInputStream *GetInputStream();
777 wxInputStream *GetErrorStream();
778 wxOutputStream *GetOutputStream();
785 long wxExecute(const wxString& command,
787 wxPyProcess *process = NULL);
789 //----------------------------------------------------------------------
792 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
793 // A C++ stub class for wxJoystick for platforms that don't have it.
794 class wxJoystick : public wxObject {
796 wxJoystick(int joystick = wxJOYSTICK1) {
797 wxPyBeginBlockThreads();
798 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
799 wxPyEndBlockThreads();
801 wxPoint GetPosition() { return wxPoint(-1,-1); }
802 int GetZPosition() { return -1; }
803 int GetButtonState() { return -1; }
804 int GetPOVPosition() { return -1; }
805 int GetPOVCTSPosition() { return -1; }
806 int GetRudderPosition() { return -1; }
807 int GetUPosition() { return -1; }
808 int GetVPosition() { return -1; }
809 int GetMovementThreshold() { return -1; }
810 void SetMovementThreshold(int threshold) {}
812 bool IsOk(void) { return FALSE; }
813 int GetNumberJoysticks() { return -1; }
814 int GetManufacturerId() { return -1; }
815 int GetProductId() { return -1; }
816 wxString GetProductName() { return ""; }
817 int GetXMin() { return -1; }
818 int GetYMin() { return -1; }
819 int GetZMin() { return -1; }
820 int GetXMax() { return -1; }
821 int GetYMax() { return -1; }
822 int GetZMax() { return -1; }
823 int GetNumberButtons() { return -1; }
824 int GetNumberAxes() { return -1; }
825 int GetMaxButtons() { return -1; }
826 int GetMaxAxes() { return -1; }
827 int GetPollingMin() { return -1; }
828 int GetPollingMax() { return -1; }
829 int GetRudderMin() { return -1; }
830 int GetRudderMax() { return -1; }
831 int GetUMin() { return -1; }
832 int GetUMax() { return -1; }
833 int GetVMin() { return -1; }
834 int GetVMax() { return -1; }
836 bool HasRudder() { return FALSE; }
837 bool HasZ() { return FALSE; }
838 bool HasU() { return FALSE; }
839 bool HasV() { return FALSE; }
840 bool HasPOV() { return FALSE; }
841 bool HasPOV4Dir() { return FALSE; }
842 bool HasPOVCTS() { return FALSE; }
844 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
845 bool ReleaseCapture() { return FALSE; }
851 class wxJoystick : public wxObject {
853 wxJoystick(int joystick = wxJOYSTICK1);
856 wxPoint GetPosition();
858 int GetButtonState();
859 int GetPOVPosition();
860 int GetPOVCTSPosition();
861 int GetRudderPosition();
864 int GetMovementThreshold();
865 void SetMovementThreshold(int threshold) ;
868 int GetNumberJoysticks();
869 int GetManufacturerId();
871 wxString GetProductName();
878 int GetNumberButtons();
899 bool SetCapture(wxWindow* win, int pollingFreq = 0);
900 bool ReleaseCapture();
903 //----------------------------------------------------------------------
907 // A C++ stub class for wxWave for platforms that don't have it.
908 class wxWave : public wxObject
911 wxWave(const wxString& fileName, bool isResource = FALSE) {
912 wxPyBeginBlockThreads();
913 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
914 wxPyEndBlockThreads();
916 wxWave(int size, const wxByte* data) {
917 wxPyBeginBlockThreads();
918 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
919 wxPyEndBlockThreads();
924 bool IsOk() const { return FALSE; }
925 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
931 class wxWave : public wxObject
934 wxWave(const wxString& fileName, bool isResource = FALSE);
938 bool Play(bool async = TRUE, bool looped = FALSE) const;
941 %new wxWave* wxWaveData(const wxString& data);
942 %{ // Implementations of some alternate "constructors"
943 wxWave* wxWaveData(const wxString& data) {
944 return new wxWave(data.Len(), (wxByte*)data.c_str());
949 //----------------------------------------------------------------------
953 wxMAILCAP_STANDARD = 1,
954 wxMAILCAP_NETSCAPE = 2,
968 wxFileTypeInfo(const char *mimeType,
970 const char *printCmd,
974 // the array elements correspond to the parameters of the ctor above in
976 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
978 // invalid item - use this to terminate the array passed to
979 // wxMimeTypesManager::AddFallbacks
980 %name(wxNullFileTypeInfo)wxFileTypeInfo();
983 // test if this object can be used
984 bool IsValid() const;
988 void SetIcon(const wxString& iconFile, int iconIndex = 0);
990 // set the short desc
991 void SetShortDesc(const wxString& shortDesc);
995 const wxString& GetMimeType() const;
996 // get the open command
997 const wxString& GetOpenCommand() const;
998 // get the print command
999 const wxString& GetPrintCommand() const;
1000 // get the short description (only used under Win32 so far)
1001 const wxString& GetShortDesc() const;
1002 // get the long, user visible description
1003 const wxString& GetDescription() const;
1006 // get the array of all extensions
1007 //const wxArrayString& GetExtensions() const;
1009 PyObject* GetExtensions() {
1010 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1011 return wxArrayString2PyList_helper(arr);
1015 int GetExtensionsCount() const;
1017 // get the icon info
1018 const wxString& GetIconFile() const;
1019 int GetIconIndex() const;
1029 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1031 // An object of this class must be passed to Get{Open|Print}Command. The
1032 // default implementation is trivial and doesn't know anything at all about
1033 // parameters, only filename and MIME type are used (so it's probably ok for
1034 // Windows where %{param} is not used anyhow)
1035 class MessageParameters
1039 MessageParameters(const wxString& filename=wxEmptyString,
1040 const wxString& mimetype=wxEmptyString);
1042 // accessors (called by GetOpenCommand)
1044 const wxString& GetFileName() const;
1046 const wxString& GetMimeType() const;;
1048 // override this function in derived class
1049 virtual wxString GetParamValue(const wxString& name) const;
1051 // virtual dtor as in any base class
1052 virtual ~MessageParameters();
1056 // ctor from static data
1057 wxFileType(const wxFileTypeInfo& ftInfo);
1059 // return the MIME type for this file type
1061 PyObject* GetMimeType() {
1063 if (self->GetMimeType(&str))
1064 return PyString_FromString(str.c_str());
1068 PyObject* GetMimeTypes() {
1070 if (self->GetMimeTypes(arr))
1071 return wxArrayString2PyList_helper(arr);
1078 // Get all extensions associated with this file type
1080 PyObject* GetExtensions() {
1082 if (self->GetExtensions(arr))
1083 return wxArrayString2PyList_helper(arr);
1091 // Get the icon corresponding to this file type
1092 %new wxIcon* GetIcon() {
1094 if (self->GetIcon(&icon))
1095 return new wxIcon(icon);
1100 // Get the icon corresponding to this file type, the name of the file
1101 // where this icon resides, and its index in this file if applicable.
1102 PyObject* GetIconInfo() {
1106 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1107 wxPyBeginBlockThreads();
1108 PyObject* tuple = PyTuple_New(3);
1109 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1111 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1112 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1113 wxPyEndBlockThreads();
1122 // get a brief file type description ("*.txt" => "text document")
1123 PyObject* GetDescription() {
1125 if (self->GetDescription(&str))
1126 return PyString_FromString(str.c_str());
1133 // get the command to open/execute the file of given type
1135 PyObject* GetOpenCommand(const wxString& filename,
1136 const wxString& mimetype=wxEmptyString) {
1138 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1139 return PyString_FromString(str.c_str());
1146 // get the command to print the file of given type
1148 PyObject* GetPrintCommand(const wxString& filename,
1149 const wxString& mimetype=wxEmptyString) {
1151 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1152 return PyString_FromString(str.c_str());
1159 // Get all commands defined for this file type
1161 PyObject* GetAllCommands(const wxString& filename,
1162 const wxString& mimetype=wxEmptyString) {
1163 wxArrayString verbs;
1164 wxArrayString commands;
1165 if (self->GetAllCommands(&verbs, &commands,
1166 wxFileType::MessageParameters(filename, mimetype))) {
1167 wxPyBeginBlockThreads();
1168 PyObject* tuple = PyTuple_New(2);
1169 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1170 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1171 wxPyEndBlockThreads();
1180 // set an arbitrary command, ask confirmation if it already exists and
1181 // overwriteprompt is TRUE
1182 bool SetCommand(const wxString& cmd, const wxString& verb,
1183 bool overwriteprompt = TRUE);
1185 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1188 // remove the association for this filetype from the system MIME database:
1189 // notice that it will only work if the association is defined in the user
1190 // file/registry part, we will never modify the system-wide settings
1194 // expand a string in the format of GetOpenCommand (which may contain
1195 // '%s' and '%t' format specificators for the file name and mime type
1196 // and %{param} constructions).
1197 static wxString ExpandCommand(const wxString& command,
1198 const MessageParameters& params);
1200 // dtor (not virtual, shouldn't be derived from)
1208 class wxMimeTypesManager
1211 // static helper functions
1212 // -----------------------
1214 // check if the given MIME type is the same as the other one: the
1215 // second argument may contain wildcards ('*'), but not the first. If
1216 // the types are equal or if the mimeType matches wildcard the function
1217 // returns TRUE, otherwise it returns FALSE
1218 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1221 wxMimeTypesManager();
1223 // loads data from standard files according to the mailcap styles
1224 // specified: this is a bitwise OR of wxMailcapStyle values
1226 // use the extraDir parameter if you want to look for files in another
1228 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1229 const wxString& extraDir = wxEmptyString);
1231 // and this function clears all the data from the manager
1234 // Database lookup: all functions return a pointer to wxFileType object
1235 // whose methods may be used to query it for the information you're
1236 // interested in. If the return value is !NULL, caller is responsible for
1238 // get file type from file extension
1239 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1241 // get file type from MIME type (in format <category>/<format>)
1242 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1244 // other operations: return TRUE if there were no errors or FALSE if there
1245 // were some unreckognized entries (the good entries are always read anyhow)
1248 // read in additional file (the standard ones are read automatically)
1249 // in mailcap format (see mimetype.cpp for description)
1251 // 'fallback' parameter may be set to TRUE to avoid overriding the
1252 // settings from other, previously parsed, files by this one: normally,
1253 // the files read most recently would override the older files, but with
1254 // fallback == TRUE this won't happen
1255 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1257 // read in additional file in mime.types format
1258 bool ReadMimeTypes(const wxString& filename);
1260 // enumerate all known MIME types
1262 PyObject* EnumAllFileTypes() {
1264 self->EnumAllFileTypes(arr);
1265 return wxArrayString2PyList_helper(arr);
1269 // these functions can be used to provide default values for some of the
1270 // MIME types inside the program itself (you may also use
1271 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1272 // achieve the same goal, but this requires having this info in a file).
1274 void AddFallback(const wxFileTypeInfo& ft);
1277 // create or remove associations
1279 // create a new association using the fields of wxFileTypeInfo (at least
1280 // the MIME type and the extension should be set)
1281 // if the other fields are empty, the existing values should be left alone
1282 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1285 bool Unassociate(wxFileType *ft) ;
1287 // dtor (not virtual, shouldn't be derived from)
1288 ~wxMimeTypesManager();
1296 extern wxMimeTypesManager* wxTheMimeTypesManager;
1302 //----------------------------------------------------------------------
1305 #include <wx/docview.h>
1308 class wxFileHistory : public wxObject
1311 wxFileHistory(int maxFiles = 9);
1315 void AddFileToHistory(const wxString& file);
1316 void RemoveFileFromHistory(int i);
1317 int GetMaxFiles() const;
1318 void UseMenu(wxMenu *menu);
1320 // Remove menu from the list (MDI child may be closing)
1321 void RemoveMenu(wxMenu *menu);
1323 void Load(wxConfigBase& config);
1324 void Save(wxConfigBase& config);
1326 void AddFilesToMenu();
1327 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1330 wxString GetHistoryFile(int i) const;
1332 // A synonym for GetNoHistoryFiles
1333 int GetCount() const;
1334 int GetNoHistoryFiles() const;
1338 //----------------------------------------------------------------------
1339 //----------------------------------------------------------------------
1343 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1344 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1345 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1348 //----------------------------------------------------------------------